@@ -49,9 +49,12 @@ public ToDoExplorerViewModel(
49
49
_uiDispatcher = uiDispatcher ;
50
50
_state . StateChanged += HandleStateChanged ;
51
51
52
- _navigateCommand = new Lazy < NavigateCommand > ( ( ) => new NavigateCommand ( selectionService ) ) ;
52
+ NavigateCommand = new NavigateCommand ( selectionService ) ;
53
+ RemoveCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteRemoveCommand , CanExecuteRemoveCommand ) ;
53
54
CollapseAllCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteCollapseAll ) ;
54
55
ExpandAllCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteExpandAll ) ;
56
+ CopyResultsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteCopyResultsCommand , CanExecuteCopyResultsCommand ) ;
57
+ OpenTodoSettingsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteOpenTodoSettingsCommand ) ;
55
58
56
59
Items = CollectionViewSource . GetDefaultView ( _items ) ;
57
60
OnPropertyChanged ( nameof ( Items ) ) ;
@@ -98,36 +101,17 @@ public bool ExpandedState
98
101
}
99
102
}
100
103
101
- private CommandBase _refreshCommand ;
102
- public CommandBase RefreshCommand
104
+ private ToDoItem _selectedItem ;
105
+ public INavigateSource SelectedItem
103
106
{
104
- get
107
+ get => _selectedItem ;
108
+ set
105
109
{
106
- if ( _refreshCommand != null )
107
- {
108
- return _refreshCommand ;
109
- }
110
- return _refreshCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ =>
111
- {
112
- _state . OnParseRequested ( this ) ;
113
- } ,
114
- _ => _state . IsDirty ( ) ) ;
110
+ _selectedItem = value as ToDoItem ;
111
+ OnPropertyChanged ( ) ;
115
112
}
116
113
}
117
114
118
- public CommandBase CollapseAllCommand { get ; }
119
- public CommandBase ExpandAllCommand { get ; }
120
-
121
- private void ExecuteCollapseAll ( object parameter )
122
- {
123
- ExpandedState = false ;
124
- }
125
-
126
- private void ExecuteExpandAll ( object parameter )
127
- {
128
- ExpandedState = true ;
129
- }
130
-
131
115
private void HandleStateChanged ( object sender , EventArgs e )
132
116
{
133
117
if ( _state . Status != ParserState . ResolvedDeclarations )
@@ -145,119 +129,99 @@ private void HandleStateChanged(object sender, EventArgs e)
145
129
} ) ;
146
130
}
147
131
148
- private ToDoItem _selectedItem ;
149
- public INavigateSource SelectedItem
132
+ public INavigateCommand NavigateCommand { get ; }
133
+
134
+ public ReparseCommand RefreshCommand { get ; set ; }
135
+
136
+ public CommandBase RemoveCommand { get ; }
137
+
138
+ public CommandBase CollapseAllCommand { get ; }
139
+
140
+ public CommandBase ExpandAllCommand { get ; }
141
+
142
+ public CommandBase CopyResultsCommand { get ; }
143
+
144
+ public CommandBase OpenTodoSettingsCommand { get ; }
145
+
146
+ private void ExecuteCollapseAll ( object parameter )
150
147
{
151
- get => _selectedItem ;
152
- set
153
- {
154
- _selectedItem = value as ToDoItem ;
155
- OnPropertyChanged ( ) ;
156
- }
148
+ ExpandedState = false ;
157
149
}
158
150
159
- private CommandBase _removeCommand ;
160
- public CommandBase RemoveCommand
151
+ private void ExecuteExpandAll ( object parameter )
161
152
{
162
- get
163
- {
164
- if ( _removeCommand != null )
165
- {
166
- return _removeCommand ;
167
- }
168
- return _removeCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ =>
169
- {
170
- if ( _selectedItem == null )
171
- {
172
- return ;
173
- }
153
+ ExpandedState = true ;
154
+ }
155
+
156
+ private bool CanExecuteRemoveCommand ( object obj ) => SelectedItem != null && RefreshCommand . CanExecute ( obj ) ;
174
157
175
- var component = _state . ProjectsProvider . Component ( _selectedItem . Selection . QualifiedName ) ;
176
- using ( var module = component . CodeModule )
177
- {
178
- var oldContent = module . GetLines ( _selectedItem . Selection . Selection . StartLine , 1 ) ;
179
- var newContent = oldContent . Remove ( _selectedItem . Selection . Selection . StartColumn - 1 ) ;
158
+ private void ExecuteRemoveCommand ( object obj )
159
+ {
160
+ if ( ! CanExecuteRemoveCommand ( obj ) )
161
+ {
162
+ return ;
163
+ }
180
164
181
- module . ReplaceLine ( _selectedItem . Selection . Selection . StartLine , newContent ) ;
182
- }
165
+ var component = _state . ProjectsProvider . Component ( _selectedItem . Selection . QualifiedName ) ;
166
+ using ( var module = component . CodeModule )
167
+ {
168
+ var oldContent = module . GetLines ( _selectedItem . Selection . Selection . StartLine , 1 ) ;
169
+ var newContent = oldContent . Remove ( _selectedItem . Selection . Selection . StartColumn - 1 ) ;
183
170
184
- RefreshCommand . Execute ( null ) ;
185
- }
186
- ) ;
171
+ module . ReplaceLine ( _selectedItem . Selection . Selection . StartLine , newContent ) ;
187
172
}
173
+
174
+ RefreshCommand . Execute ( null ) ;
188
175
}
189
176
190
- private CommandBase _copyResultsCommand ;
191
- public CommandBase CopyResultsCommand
177
+ private bool CanExecuteCopyResultsCommand ( object obj ) => _items . Any ( ) ;
178
+
179
+ public void ExecuteCopyResultsCommand ( object obj )
192
180
{
193
- get
181
+ const string xmlSpreadsheetDataFormat = "XML Spreadsheet" ;
182
+ if ( ! CanExecuteCopyResultsCommand ( obj ) )
194
183
{
195
- if ( _copyResultsCommand != null )
196
- {
197
- return _copyResultsCommand ;
198
- }
199
- return _copyResultsCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ =>
200
- {
201
- const string xmlSpreadsheetDataFormat = "XML Spreadsheet" ;
202
- if ( _items == null )
203
- {
204
- return ;
205
- }
206
- ColumnInfo [ ] columnInfos = { new ColumnInfo ( "Type" ) , new ColumnInfo ( "Description" ) , new ColumnInfo ( "Project" ) , new ColumnInfo ( "Component" ) , new ColumnInfo ( "Line" , hAlignment . Right ) , new ColumnInfo ( "Column" , hAlignment . Right ) } ;
184
+ return ;
185
+ }
207
186
208
- var resultArray = _items . OfType < IExportable > ( ) . Select ( result => result . ToArray ( ) ) . ToArray ( ) ;
187
+ ColumnInfo [ ] columnInfos = { new ColumnInfo ( "Type" ) , new ColumnInfo ( "Description" ) , new ColumnInfo ( "Project" ) , new ColumnInfo ( "Component" ) , new ColumnInfo ( "Line" , hAlignment . Right ) , new ColumnInfo ( "Column" , hAlignment . Right ) } ;
209
188
210
- var resource = _items . Count == 1
211
- ? ToDoExplorerUI . ToDoExplorer_NumberOfIssuesFound_Singular
212
- : ToDoExplorerUI . ToDoExplorer_NumberOfIssuesFound_Plural ;
189
+ var resultArray = _items . OfType < IExportable > ( ) . Select ( result => result . ToArray ( ) ) . ToArray ( ) ;
213
190
214
- var title = string . Format ( resource , DateTime . Now . ToString ( CultureInfo . InvariantCulture ) , _items . Count ) ;
191
+ var resource = _items . Count == 1
192
+ ? ToDoExplorerUI . ToDoExplorer_NumberOfIssuesFound_Singular
193
+ : ToDoExplorerUI . ToDoExplorer_NumberOfIssuesFound_Plural ;
215
194
216
- var textResults = title + Environment . NewLine + string . Join ( "" , _items . OfType < IExportable > ( ) . Select ( result => result . ToClipboardString ( ) + Environment . NewLine ) . ToArray ( ) ) ;
217
- var csvResults = ExportFormatter . Csv ( resultArray , title , columnInfos ) ;
218
- var htmlResults = ExportFormatter . HtmlClipboardFragment ( resultArray , title , columnInfos ) ;
219
- var rtfResults = ExportFormatter . RTF ( resultArray , title ) ;
195
+ var title = string . Format ( resource , DateTime . Now . ToString ( CultureInfo . InvariantCulture ) , _items . Count ) ;
220
196
221
- // todo: verify that this disposing this stream breaks the xmlSpreadsheetDataFormat
222
- var stream = ExportFormatter . XmlSpreadsheetNew ( resultArray , title , columnInfos ) ;
197
+ var textResults = title + Environment . NewLine + string . Join ( "" , _items . OfType < IExportable > ( ) . Select ( result => result . ToClipboardString ( ) + Environment . NewLine ) . ToArray ( ) ) ;
198
+ var csvResults = ExportFormatter . Csv ( resultArray , title , columnInfos ) ;
199
+ var htmlResults = ExportFormatter . HtmlClipboardFragment ( resultArray , title , columnInfos ) ;
200
+ var rtfResults = ExportFormatter . RTF ( resultArray , title ) ;
223
201
224
- IClipboardWriter _clipboard = new ClipboardWriter ( ) ;
225
- //Add the formats from richest formatting to least formatting
226
- _clipboard . AppendStream ( DataFormats . GetDataFormat ( xmlSpreadsheetDataFormat ) . Name , stream ) ;
227
- _clipboard . AppendString ( DataFormats . Rtf , rtfResults ) ;
228
- _clipboard . AppendString ( DataFormats . Html , htmlResults ) ;
229
- _clipboard . AppendString ( DataFormats . CommaSeparatedValue , csvResults ) ;
230
- _clipboard . AppendString ( DataFormats . UnicodeText , textResults ) ;
202
+ // todo: verify that this disposing this stream breaks the xmlSpreadsheetDataFormat
203
+ var stream = ExportFormatter . XmlSpreadsheetNew ( resultArray , title , columnInfos ) ;
231
204
232
- _clipboard . Flush ( ) ;
205
+ IClipboardWriter _clipboard = new ClipboardWriter ( ) ;
206
+ //Add the formats from richest formatting to least formatting
207
+ _clipboard . AppendStream ( DataFormats . GetDataFormat ( xmlSpreadsheetDataFormat ) . Name , stream ) ;
208
+ _clipboard . AppendString ( DataFormats . Rtf , rtfResults ) ;
209
+ _clipboard . AppendString ( DataFormats . Html , htmlResults ) ;
210
+ _clipboard . AppendString ( DataFormats . CommaSeparatedValue , csvResults ) ;
211
+ _clipboard . AppendString ( DataFormats . UnicodeText , textResults ) ;
233
212
234
- } ) ;
235
- }
213
+ _clipboard . Flush ( ) ;
236
214
}
237
215
238
- private CommandBase _openTodoSettings ;
239
- public CommandBase OpenTodoSettings
216
+ public void ExecuteOpenTodoSettingsCommand ( object obj )
240
217
{
241
- get
218
+ using ( var window = _settingsFormFactory . Create ( SettingsViews . TodoSettings ) )
242
219
{
243
- if ( _openTodoSettings != null )
244
- {
245
- return _openTodoSettings ;
246
- }
247
- return _openTodoSettings = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ =>
248
- {
249
- using ( var window = _settingsFormFactory . Create ( SettingsViews . TodoSettings ) )
250
- {
251
- window . ShowDialog ( ) ;
252
- _settingsFormFactory . Release ( window ) ;
253
- }
254
- } ) ;
220
+ window . ShowDialog ( ) ;
221
+ _settingsFormFactory . Release ( window ) ;
255
222
}
256
223
}
257
224
258
- private readonly Lazy < NavigateCommand > _navigateCommand ;
259
- public INavigateCommand NavigateCommand => _navigateCommand . Value ;
260
-
261
225
private IEnumerable < ToDoItem > GetToDoMarkers ( CommentNode comment )
262
226
{
263
227
var markers = _configService . LoadConfiguration ( ) . UserSettings . ToDoListSettings . ToDoMarkers ;
0 commit comments