Skip to content

Commit 2848b6a

Browse files
committed
Feature: Integrate persistent settings storage and sync UI with user preferences.
1 parent 501e3d1 commit 2848b6a

File tree

4 files changed

+137
-24
lines changed

4 files changed

+137
-24
lines changed

CodeIngest.Desktop/MainViewModel.cs

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// about your modifications. Your contributions are valued!
99
//
1010
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11-
using System;
12-
using System.IO;
1311
using System.Threading.Tasks;
1412
using CodeIngestLib;
1513
using CSharp.Core.Extensions;
@@ -22,69 +20,103 @@ namespace CodeIngest.Desktop;
2220
public class MainViewModel : ViewModelBase
2321
{
2422
private readonly IDialogService m_dialogService;
25-
private FolderTreeRoot m_root = new FolderTreeRoot(new DirectoryInfo(Environment.CurrentDirectory));
23+
private FolderTreeRoot m_root = new FolderTreeRoot(Settings.Instance.RootFolder);
2624

27-
private bool m_isCSharp = true;
28-
private bool m_isCppNoHeaders;
29-
private bool m_isCppWithHeaders;
30-
private bool m_includeMarkdown;
31-
private bool m_excludeImports = true;
32-
private bool m_useFullPaths;
33-
private bool m_excludeComments = true;
25+
private bool m_isCSharp = Settings.Instance.IsCSharp;
26+
private bool m_isCppNoHeaders = Settings.Instance.IsCppNoHeaders;
27+
private bool m_isCppWithHeaders = Settings.Instance.IsCppWithHeaders;
28+
private bool m_includeMarkdown = Settings.Instance.IncludeMarkdown;
29+
private bool m_excludeImports = Settings.Instance.ExcludeImports;
30+
private bool m_useFullPaths = Settings.Instance.UseFullPaths;
31+
private bool m_excludeComments = Settings.Instance.ExcludeComments;
3432

3533
public FolderTreeRoot Root
3634
{
3735
get => m_root;
38-
set => SetField(ref m_root, value);
36+
set
37+
{
38+
if (SetField(ref m_root, value))
39+
Settings.Instance.RootFolder = value.Root.Clone();
40+
}
3941
}
4042

4143
public bool IsCSharp
4244
{
4345
get => m_isCSharp;
44-
set => SetField(ref m_isCSharp, value);
46+
set
47+
{
48+
if (SetField(ref m_isCSharp, value))
49+
Settings.Instance.IsCSharp = value;
50+
}
4551
}
4652

4753
public bool IsCppNoHeaders
4854
{
4955
get => m_isCppNoHeaders;
50-
set => SetField(ref m_isCppNoHeaders, value);
56+
set
57+
{
58+
if (SetField(ref m_isCppNoHeaders, value))
59+
Settings.Instance.IsCppNoHeaders = value;
60+
}
5161
}
5262

5363
public bool IsCppWithHeaders
5464
{
5565
get => m_isCppWithHeaders;
56-
set => SetField(ref m_isCppWithHeaders, value);
66+
set
67+
{
68+
if (SetField(ref m_isCppWithHeaders, value))
69+
Settings.Instance.IsCppWithHeaders = value;
70+
}
5771
}
5872

5973
public bool ExcludeImports
6074
{
6175
get => m_excludeImports;
62-
set => SetField(ref m_excludeImports, value);
76+
set
77+
{
78+
if (SetField(ref m_excludeImports, value))
79+
Settings.Instance.ExcludeImports = value;
80+
}
6381
}
6482

6583
public bool ExcludeComments
6684
{
6785
get => m_excludeComments;
68-
set => SetField(ref m_excludeComments, value);
86+
set
87+
{
88+
if (SetField(ref m_excludeComments, value))
89+
Settings.Instance.ExcludeComments = value;
90+
}
6991
}
7092

7193
public bool IncludeMarkdown
7294
{
7395
get => m_includeMarkdown;
74-
set => SetField(ref m_includeMarkdown, value);
96+
set
97+
{
98+
if (SetField(ref m_includeMarkdown, value))
99+
Settings.Instance.IncludeMarkdown = value;
100+
}
75101
}
76102

77103
public bool UseFullPaths
78104
{
79105
get => m_useFullPaths;
80-
set => SetField(ref m_useFullPaths, value);
106+
set
107+
{
108+
if (SetField(ref m_useFullPaths, value))
109+
Settings.Instance.UseFullPaths = value;
110+
}
81111
}
82112

83113
public async Task SelectRoot()
84114
{
85115
var rootFolder = await m_dialogService.SelectFolderAsync("Select a folder to scan for code.");
86-
if (rootFolder != null)
87-
Root = new FolderTreeRoot(rootFolder);
116+
if (rootFolder == null)
117+
return;
118+
119+
Root = new FolderTreeRoot(rootFolder);
88120
}
89121

90122
public MainViewModel(IDialogService dialogService = null)
@@ -142,6 +174,6 @@ public async Task RunIngest()
142174
return;
143175
}
144176

145-
m_dialogService.ShowMessage("Code file generated successfully.", $@"{result.Value.FileCount:N0} files produced {result.Value.OutputBytes.ToSize()} of output.");
177+
m_dialogService.ShowMessage("Code file generated successfully.", $"{result.Value.FileCount:N0} files produced {result.Value.OutputBytes.ToSize()} of output.");
146178
}
147179
}

CodeIngest.Desktop/MainWindow.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
<CheckBox Content="Export Full Paths" IsChecked="{Binding UseFullPaths}"/>
5959

6060
<RadioButton Content="C#" Margin="0,16,0,0" IsChecked="{Binding IsCSharp}"/>
61-
<RadioButton Content="C/C++ (No Headers)" IsChecked="{Binding IsCppNoHeaders}" />
61+
<RadioButton Content="C/C++ (No Headers)" IsChecked="{Binding IsCppNoHeaders}" Margin="0,4"/>
6262
<RadioButton Content="C/C++ (With Headers)" IsChecked="{Binding IsCppWithHeaders}" />
6363

6464
<CheckBox Content="Exclude Imports" Margin="0,16,0,0"
6565
ToolTip.Tip="Remove using/#include/etc statements from the output."
6666
IsChecked="{Binding ExcludeImports}" />
67-
<CheckBox Content="Exclude comments"
67+
<CheckBox Content="Exclude comments" Margin="0,4"
6868
ToolTip.Tip="Remove // and /*-style comments from the output."
6969
IsChecked="{Binding ExcludeComments}" />
7070
<CheckBox Content="Include Markdown"

CodeIngest.Desktop/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static void Main(string[] args)
2828
}
2929
finally
3030
{
31-
// todo Settings.Instance.Save();
31+
Settings.Instance.Save();
3232
}
3333
}
3434

CodeIngest.Desktop/Settings.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Code authored by Dean Edis (DeanTheCoder).
2+
// Anyone is free to copy, modify, use, compile, or distribute this software,
3+
// either in source code form or as a compiled binary, for any non-commercial
4+
// purpose.
5+
//
6+
// If you modify the code, please retain this copyright header,
7+
// and consider contributing back to the repository or letting us know
8+
// about your modifications. Your contributions are valued!
9+
//
10+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11+
using System;
12+
using System.IO;
13+
using CSharp.Core.Extensions;
14+
using CSharp.Core.Settings;
15+
16+
namespace CodeIngest.Desktop;
17+
18+
public class Settings : UserSettingsBase
19+
{
20+
public static Settings Instance { get; } = new Settings();
21+
22+
public DirectoryInfo RootFolder
23+
{
24+
get => Get<DirectoryInfo>();
25+
set => Set(value);
26+
}
27+
28+
public bool IsCSharp
29+
{
30+
get => Get<bool>();
31+
set => Set(value);
32+
}
33+
34+
public bool IsCppNoHeaders
35+
{
36+
get => Get<bool>();
37+
set => Set(value);
38+
}
39+
40+
public bool IsCppWithHeaders
41+
{
42+
get => Get<bool>();
43+
set => Set(value);
44+
}
45+
46+
public bool ExcludeImports
47+
{
48+
get => Get<bool>();
49+
set => Set(value);
50+
}
51+
52+
public bool ExcludeComments
53+
{
54+
get => Get<bool>();
55+
set => Set(value);
56+
}
57+
58+
public bool IncludeMarkdown
59+
{
60+
get => Get<bool>();
61+
set => Set(value);
62+
}
63+
64+
public bool UseFullPaths
65+
{
66+
get => Get<bool>();
67+
set => Set(value);
68+
}
69+
70+
protected override void ApplyDefaults()
71+
{
72+
RootFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToDir();
73+
IsCSharp = true;
74+
IsCppNoHeaders = false;
75+
IsCppWithHeaders = false;
76+
ExcludeImports = true;
77+
ExcludeComments = true;
78+
IncludeMarkdown = false;
79+
UseFullPaths = false;
80+
}
81+
}

0 commit comments

Comments
 (0)