9
9
using Rubberduck . Parsing . Annotations ;
10
10
using Rubberduck . Parsing . Symbols ;
11
11
using Rubberduck . Parsing . VBA ;
12
+ using Rubberduck . Settings ;
13
+ using Rubberduck . SettingsProvider ;
12
14
using Rubberduck . UI ;
13
15
using Rubberduck . UI . CodeExplorer . Commands ;
14
16
using Rubberduck . UI . Command ;
@@ -26,29 +28,46 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
26
28
{
27
29
private readonly FolderHelper _folderHelper ;
28
30
private readonly RubberduckParserState _state ;
31
+ private IConfigProvider < GeneralSettings > _generalSettingsProvider ;
32
+ private IConfigProvider < WindowSettings > _windowSettingsProvider ;
33
+ private GeneralSettings _generalSettings ;
34
+ private WindowSettings _windowSettings ;
29
35
30
- public CodeExplorerViewModel ( FolderHelper folderHelper , RubberduckParserState state , List < CommandBase > commands )
36
+ public CodeExplorerViewModel ( FolderHelper folderHelper , RubberduckParserState state , List < CommandBase > commands ,
37
+ IConfigProvider < GeneralSettings > generalSettingsProvider , IConfigProvider < WindowSettings > windowSettingsProvider )
31
38
{
32
39
_folderHelper = folderHelper ;
33
40
_state = state ;
34
41
_state . StateChanged += HandleStateChanged ;
35
42
_state . ModuleStateChanged += ParserState_ModuleStateChanged ;
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
+ }
36
55
37
56
var reparseCommand = commands . OfType < ReparseCommand > ( ) . SingleOrDefault ( ) ;
38
57
39
58
RefreshCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) ,
40
59
reparseCommand == null ? ( Action < object > ) ( o => { } ) :
41
60
o => reparseCommand . Execute ( o ) ,
42
61
o => ! IsBusy && reparseCommand != null && reparseCommand . CanExecute ( o ) ) ;
43
-
44
- NavigateCommand = commands . OfType < UI . CodeExplorer . Commands . NavigateCommand > ( ) . SingleOrDefault ( ) ;
62
+
63
+ OpenCommand = commands . OfType < UI . CodeExplorer . Commands . OpenCommand > ( ) . SingleOrDefault ( ) ;
64
+ OpenDesignerCommand = commands . OfType < OpenDesignerCommand > ( ) . SingleOrDefault ( ) ;
45
65
46
66
AddTestModuleCommand = commands . OfType < UI . CodeExplorer . Commands . AddTestModuleCommand > ( ) . SingleOrDefault ( ) ;
47
67
AddStdModuleCommand = commands . OfType < AddStdModuleCommand > ( ) . SingleOrDefault ( ) ;
48
68
AddClassModuleCommand = commands . OfType < AddClassModuleCommand > ( ) . SingleOrDefault ( ) ;
49
69
AddUserFormCommand = commands . OfType < AddUserFormCommand > ( ) . SingleOrDefault ( ) ;
50
70
51
- OpenDesignerCommand = commands . OfType < OpenDesignerCommand > ( ) . SingleOrDefault ( ) ;
52
71
OpenProjectPropertiesCommand = commands . OfType < OpenProjectPropertiesCommand > ( ) . SingleOrDefault ( ) ;
53
72
RenameCommand = commands . OfType < RenameCommand > ( ) . SingleOrDefault ( ) ;
54
73
IndenterCommand = commands . OfType < IndentCommand > ( ) . SingleOrDefault ( ) ;
@@ -111,36 +130,38 @@ public CodeExplorerItemViewModel SelectedItem
111
130
}
112
131
}
113
132
114
- private bool _sortByName = true ;
115
133
public bool SortByName
116
134
{
117
- get { return _sortByName ; }
135
+ get { return _windowSettings . CodeExplorer_SortByName ; }
118
136
set
119
137
{
120
- if ( _sortByName == value )
138
+ if ( _windowSettings . CodeExplorer_SortByName == value )
121
139
{
122
140
return ;
123
141
}
124
142
125
- _sortByName = value ;
143
+ _windowSettings . CodeExplorer_SortByName = value ;
144
+ _windowSettings . CodeExplorer_SortByLocation = ! value ;
145
+ _windowSettingsProvider . Save ( _windowSettings ) ;
126
146
OnPropertyChanged ( ) ;
127
147
128
148
ReorderChildNodes ( Projects ) ;
129
149
}
130
150
}
131
151
132
- private bool _sortBySelection ;
133
152
public bool SortBySelection
134
153
{
135
- get { return _sortBySelection ; }
154
+ get { return _windowSettings . CodeExplorer_SortByLocation ; }
136
155
set
137
156
{
138
- if ( _sortBySelection == value )
157
+ if ( _windowSettings . CodeExplorer_SortByLocation == value )
139
158
{
140
159
return ;
141
160
}
142
161
143
- _sortBySelection = value ;
162
+ _windowSettings . CodeExplorer_SortByLocation = value ;
163
+ _windowSettings . CodeExplorer_SortByName = ! value ;
164
+ _windowSettingsProvider . Save ( _windowSettings ) ;
144
165
OnPropertyChanged ( ) ;
145
166
146
167
ReorderChildNodes ( Projects ) ;
@@ -153,15 +174,16 @@ public bool SortBySelection
153
174
154
175
public CommandBase SetSelectionSortCommand { get ; }
155
176
156
- private bool _sortByType = true ;
157
177
public bool SortByType
158
178
{
159
- get { return _sortByType ; }
179
+ get { return _windowSettings . CodeExplorer_GroupByType ; }
160
180
set
161
181
{
162
- if ( _sortByType != value )
182
+ if ( _windowSettings . CodeExplorer_GroupByType != value )
163
183
{
164
- _sortByType = value ;
184
+ _windowSettings . CodeExplorer_GroupByType = value ;
185
+ _windowSettingsProvider . Save ( _windowSettings ) ;
186
+
165
187
OnPropertyChanged ( ) ;
166
188
167
189
ReorderChildNodes ( Projects ) ;
@@ -177,6 +199,8 @@ public bool IsBusy
177
199
{
178
200
_isBusy = value ;
179
201
OnPropertyChanged ( ) ;
202
+ // If the window is "busy" then hide the Refresh message
203
+ OnPropertyChanged ( "EmptyTreeMessageVisibility" ) ;
180
204
}
181
205
}
182
206
@@ -244,6 +268,8 @@ public ObservableCollection<CodeExplorerItemViewModel> Projects
244
268
_projects = new ObservableCollection < CodeExplorerItemViewModel > ( value . OrderBy ( o => o . NameWithSignature ) ) ;
245
269
246
270
OnPropertyChanged ( ) ;
271
+ // Once a Project has been set, show the TreeView
272
+ OnPropertyChanged ( "TreeViewVisibility" ) ;
247
273
}
248
274
}
249
275
@@ -254,7 +280,8 @@ private void HandleStateChanged(object sender, ParserStateEventArgs e)
254
280
Projects = new ObservableCollection < CodeExplorerItemViewModel > ( ) ;
255
281
}
256
282
257
- IsBusy = _state . Status != ParserState . Pending && _state . Status < ParserState . ResolvedDeclarations ;
283
+ IsBusy = _state . Status != ParserState . Pending && _state . Status <= ParserState . ResolvedDeclarations ;
284
+
258
285
if ( e . State != ParserState . ResolvedDeclarations )
259
286
{
260
287
return ;
@@ -447,7 +474,7 @@ private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
447
474
448
475
public CommandBase RefreshCommand { get ; }
449
476
450
- public CommandBase NavigateCommand { get ; }
477
+ public CommandBase OpenCommand { get ; }
451
478
452
479
public CommandBase AddTestModuleCommand { get ; }
453
480
public CommandBase AddStdModuleCommand { get ; }
@@ -512,6 +539,27 @@ public Visibility ExportAllVisibility
512
539
}
513
540
}
514
541
542
+ public bool IsSourceControlEnabled
543
+ {
544
+ get { return _generalSettings . SourceControlEnabled ; }
545
+ }
546
+
547
+ public Visibility TreeViewVisibility
548
+ {
549
+ get
550
+ {
551
+ return Projects == null || Projects . Count == 0 ? Visibility . Collapsed : Visibility . Visible ;
552
+ }
553
+ }
554
+
555
+ public Visibility EmptyTreeMessageVisibility
556
+ {
557
+ get
558
+ {
559
+ return _isBusy ? Visibility . Hidden : Visibility . Visible ;
560
+ }
561
+ }
562
+
515
563
public void Dispose ( )
516
564
{
517
565
if ( _state != null )
0 commit comments