Skip to content

Commit a7579fa

Browse files
Use settings the correct(?) way, and save Sort settings across restarts
1 parent 1c815d3 commit a7579fa

File tree

3 files changed

+163
-229
lines changed

3 files changed

+163
-229
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Rubberduck.Parsing.Symbols;
1111
using Rubberduck.Parsing.VBA;
1212
using Rubberduck.Settings;
13+
using Rubberduck.SettingsProvider;
1314
using Rubberduck.UI;
1415
using Rubberduck.UI.CodeExplorer.Commands;
1516
using Rubberduck.UI.Command;
@@ -27,15 +28,30 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
2728
{
2829
private readonly FolderHelper _folderHelper;
2930
private readonly RubberduckParserState _state;
30-
private bool _sourceControlEnabled;
31+
private IConfigProvider<GeneralSettings> _generalSettingsProvider;
32+
private IConfigProvider<WindowSettings> _windowSettingsProvider;
33+
private GeneralSettings _generalSettings;
34+
private WindowSettings _windowSettings;
3135

32-
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<CommandBase> commands, IGeneralConfigService configLoader)
36+
public CodeExplorerViewModel(FolderHelper folderHelper, RubberduckParserState state, List<CommandBase> commands,
37+
IConfigProvider<GeneralSettings> generalSettingsProvider, IConfigProvider<WindowSettings> windowSettingsProvider)
3338
{
3439
_folderHelper = folderHelper;
3540
_state = state;
3641
_state.StateChanged += HandleStateChanged;
3742
_state.ModuleStateChanged += ParserState_ModuleStateChanged;
38-
_sourceControlEnabled = configLoader.LoadConfiguration().UserSettings.GeneralSettings.SourceControlEnabled;
43+
_generalSettingsProvider = generalSettingsProvider;
44+
_windowSettingsProvider = windowSettingsProvider;
45+
46+
if (generalSettingsProvider != null)
47+
{
48+
_generalSettings = generalSettingsProvider.Create();
49+
}
50+
51+
if (windowSettingsProvider != null)
52+
{
53+
_windowSettings = windowSettingsProvider.Create();
54+
}
3955

4056
var reparseCommand = commands.OfType<ReparseCommand>().SingleOrDefault();
4157

@@ -114,36 +130,38 @@ public CodeExplorerItemViewModel SelectedItem
114130
}
115131
}
116132

117-
private bool _sortByName = true;
118133
public bool SortByName
119134
{
120-
get { return _sortByName; }
135+
get { return _windowSettings.CodeExplorer_SortByName; }
121136
set
122137
{
123-
if (_sortByName == value)
138+
if (_windowSettings.CodeExplorer_SortByName == value)
124139
{
125140
return;
126141
}
127142

128-
_sortByName = value;
143+
_windowSettings.CodeExplorer_SortByName = value;
144+
_windowSettings.CodeExplorer_SortByLocation = !value;
145+
_windowSettingsProvider.Save(_windowSettings);
129146
OnPropertyChanged();
130147

131148
ReorderChildNodes(Projects);
132149
}
133150
}
134151

135-
private bool _sortBySelection;
136152
public bool SortBySelection
137153
{
138-
get { return _sortBySelection; }
154+
get { return _windowSettings.CodeExplorer_SortByLocation; }
139155
set
140156
{
141-
if (_sortBySelection == value)
157+
if (_windowSettings.CodeExplorer_SortByLocation == value)
142158
{
143159
return;
144160
}
145161

146-
_sortBySelection = value;
162+
_windowSettings.CodeExplorer_SortByLocation = value;
163+
_windowSettings.CodeExplorer_SortByName = !value;
164+
_windowSettingsProvider.Save(_windowSettings);
147165
OnPropertyChanged();
148166

149167
ReorderChildNodes(Projects);
@@ -156,15 +174,16 @@ public bool SortBySelection
156174

157175
public CommandBase SetSelectionSortCommand { get; }
158176

159-
private bool _sortByType = true;
160177
public bool SortByType
161178
{
162-
get { return _sortByType; }
179+
get { return _windowSettings.CodeExplorer_GroupByType; }
163180
set
164181
{
165-
if (_sortByType != value)
182+
if (_windowSettings.CodeExplorer_GroupByType != value)
166183
{
167-
_sortByType = value;
184+
_windowSettings.CodeExplorer_GroupByType = value;
185+
_windowSettingsProvider.Save(_windowSettings);
186+
168187
OnPropertyChanged();
169188

170189
ReorderChildNodes(Projects);
@@ -522,7 +541,7 @@ public Visibility ExportAllVisibility
522541

523542
public bool IsSourceControlEnabled
524543
{
525-
get { return _sourceControlEnabled; }
544+
get { return _generalSettings.SourceControlEnabled; }
526545
}
527546

528547
public Visibility TreeViewVisibility

RetailCoder.VBE/Settings/WindowSettings.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,34 @@ public interface IWindowSettings
1717
bool TestExplorerVisibleOnStartup { get; set; }
1818
bool TodoExplorerVisibleOnStartup { get; set; }
1919

20+
bool CodeExplorer_SortByName { get; set; }
21+
bool CodeExplorer_SortByLocation { get; set; }
22+
bool CodeExplorer_GroupByType { get; set; }
23+
2024
bool IsWindowVisible(DockableToolwindowPresenter candidate);
2125
}
2226

2327
[XmlType(AnonymousType = true)]
2428
public class WindowSettings : IWindowSettings, IEquatable<WindowSettings>
2529
{
2630
public WindowSettings()
27-
: this(false, false, false, false, false)
31+
: this(false, false, false, false, false, true, false, false)
32+
// SortByName and SortByLocation are opposites; SortByName should start as True.
2833
{
2934
//empty constructor needed for serialization
3035
}
3136

32-
public WindowSettings(bool codeExplorerVisibleOnStartup, bool codeInspectionsVisibleOnStartup, bool sourceControlVisibleOnStartup, bool testExplorerVisibleOnStartup, bool todoExplorerVisibleOnStartup)
37+
public WindowSettings(bool codeExplorerVisibleOnStartup, bool codeInspectionsVisibleOnStartup, bool sourceControlVisibleOnStartup, bool testExplorerVisibleOnStartup, bool todoExplorerVisibleOnStartup, bool codeExplorer_SortByName, bool codeExplorer_SortByLocation, bool codeExplorer_GroupByType)
3338
{
3439
CodeExplorerVisibleOnStartup = codeExplorerVisibleOnStartup;
3540
CodeInspectionsVisibleOnStartup = codeInspectionsVisibleOnStartup;
3641
SourceControlVisibleOnStartup = sourceControlVisibleOnStartup;
3742
TestExplorerVisibleOnStartup = testExplorerVisibleOnStartup;
3843
TodoExplorerVisibleOnStartup = todoExplorerVisibleOnStartup;
44+
45+
CodeExplorer_SortByName = codeExplorer_SortByName;
46+
CodeExplorer_SortByLocation = codeExplorer_SortByLocation;
47+
CodeExplorer_GroupByType = codeExplorer_GroupByType;
3948
}
4049

4150
public bool CodeExplorerVisibleOnStartup { get; set; }
@@ -44,6 +53,10 @@ public WindowSettings(bool codeExplorerVisibleOnStartup, bool codeInspectionsVis
4453
public bool TestExplorerVisibleOnStartup { get; set; }
4554
public bool TodoExplorerVisibleOnStartup { get; set; }
4655

56+
public bool CodeExplorer_SortByName { get; set; }
57+
public bool CodeExplorer_SortByLocation { get; set; }
58+
public bool CodeExplorer_GroupByType { get; set; }
59+
4760
public bool IsWindowVisible(DockableToolwindowPresenter candidate)
4861
{
4962
//I'm sure there's a better way to do this, because this is a lazy-ass way to do it.
@@ -79,7 +92,10 @@ public bool Equals(WindowSettings other)
7992
CodeInspectionsVisibleOnStartup == other.CodeInspectionsVisibleOnStartup &&
8093
SourceControlVisibleOnStartup == other.SourceControlVisibleOnStartup &&
8194
TestExplorerVisibleOnStartup == other.TestExplorerVisibleOnStartup &&
82-
TodoExplorerVisibleOnStartup == other.TodoExplorerVisibleOnStartup;
95+
TodoExplorerVisibleOnStartup == other.TodoExplorerVisibleOnStartup &&
96+
CodeExplorer_SortByName == other.CodeExplorer_SortByName &&
97+
CodeExplorer_SortByLocation == other.CodeExplorer_SortByLocation &&
98+
CodeExplorer_GroupByType == other.CodeExplorer_GroupByType;
8399
}
84100
}
85101
}

0 commit comments

Comments
 (0)