10
10
using Rubberduck . Parsing . Symbols ;
11
11
using Rubberduck . Parsing . VBA ;
12
12
using Rubberduck . Settings ;
13
+ using Rubberduck . SettingsProvider ;
13
14
using Rubberduck . UI ;
14
15
using Rubberduck . UI . CodeExplorer . Commands ;
15
16
using Rubberduck . UI . Command ;
@@ -27,15 +28,30 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
27
28
{
28
29
private readonly FolderHelper _folderHelper ;
29
30
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 ;
31
35
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 )
33
38
{
34
39
_folderHelper = folderHelper ;
35
40
_state = state ;
36
41
_state . StateChanged += HandleStateChanged ;
37
42
_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
+ }
39
55
40
56
var reparseCommand = commands . OfType < ReparseCommand > ( ) . SingleOrDefault ( ) ;
41
57
@@ -114,36 +130,38 @@ public CodeExplorerItemViewModel SelectedItem
114
130
}
115
131
}
116
132
117
- private bool _sortByName = true ;
118
133
public bool SortByName
119
134
{
120
- get { return _sortByName ; }
135
+ get { return _windowSettings . CodeExplorer_SortByName ; }
121
136
set
122
137
{
123
- if ( _sortByName == value )
138
+ if ( _windowSettings . CodeExplorer_SortByName == value )
124
139
{
125
140
return ;
126
141
}
127
142
128
- _sortByName = value ;
143
+ _windowSettings . CodeExplorer_SortByName = value ;
144
+ _windowSettings . CodeExplorer_SortByLocation = ! value ;
145
+ _windowSettingsProvider . Save ( _windowSettings ) ;
129
146
OnPropertyChanged ( ) ;
130
147
131
148
ReorderChildNodes ( Projects ) ;
132
149
}
133
150
}
134
151
135
- private bool _sortBySelection ;
136
152
public bool SortBySelection
137
153
{
138
- get { return _sortBySelection ; }
154
+ get { return _windowSettings . CodeExplorer_SortByLocation ; }
139
155
set
140
156
{
141
- if ( _sortBySelection == value )
157
+ if ( _windowSettings . CodeExplorer_SortByLocation == value )
142
158
{
143
159
return ;
144
160
}
145
161
146
- _sortBySelection = value ;
162
+ _windowSettings . CodeExplorer_SortByLocation = value ;
163
+ _windowSettings . CodeExplorer_SortByName = ! value ;
164
+ _windowSettingsProvider . Save ( _windowSettings ) ;
147
165
OnPropertyChanged ( ) ;
148
166
149
167
ReorderChildNodes ( Projects ) ;
@@ -156,15 +174,16 @@ public bool SortBySelection
156
174
157
175
public CommandBase SetSelectionSortCommand { get ; }
158
176
159
- private bool _sortByType = true ;
160
177
public bool SortByType
161
178
{
162
- get { return _sortByType ; }
179
+ get { return _windowSettings . CodeExplorer_GroupByType ; }
163
180
set
164
181
{
165
- if ( _sortByType != value )
182
+ if ( _windowSettings . CodeExplorer_GroupByType != value )
166
183
{
167
- _sortByType = value ;
184
+ _windowSettings . CodeExplorer_GroupByType = value ;
185
+ _windowSettingsProvider . Save ( _windowSettings ) ;
186
+
168
187
OnPropertyChanged ( ) ;
169
188
170
189
ReorderChildNodes ( Projects ) ;
@@ -522,7 +541,7 @@ public Visibility ExportAllVisibility
522
541
523
542
public bool IsSourceControlEnabled
524
543
{
525
- get { return _sourceControlEnabled ; }
544
+ get { return _generalSettings . SourceControlEnabled ; }
526
545
}
527
546
528
547
public Visibility TreeViewVisibility
0 commit comments