1
1
using System ;
2
2
using System . Linq ;
3
+ using NLog ;
3
4
using Rubberduck . Settings ;
5
+ using Rubberduck . SettingsProvider ;
4
6
using Rubberduck . SmartIndenter ;
7
+ using Rubberduck . UI . Command ;
5
8
6
9
namespace Rubberduck . UI . Settings
7
10
{
8
11
public class IndenterSettingsViewModel : ViewModelBase , ISettingsViewModel
9
12
{
13
+ private readonly CommandBase _importButtonCommand ;
14
+ private readonly CommandBase _exportButtonCommand ;
15
+
10
16
public IndenterSettingsViewModel ( Configuration config )
11
17
{
12
18
_alignCommentsWithCode = config . UserSettings . IndenterSettings . AlignCommentsWithCode ;
@@ -27,6 +33,25 @@ public IndenterSettingsViewModel(Configuration config)
27
33
_indentSpaces = config . UserSettings . IndenterSettings . IndentSpaces ;
28
34
29
35
PropertyChanged += IndenterSettingsViewModel_PropertyChanged ;
36
+ _exportButtonCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ => ExportSettings ( ) ) ;
37
+ _importButtonCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , _ => ImportSettings ( ) ) ;
38
+ }
39
+
40
+ public CommandBase ExportButtonCommand
41
+ {
42
+ get
43
+ {
44
+ return _exportButtonCommand ;
45
+ }
46
+ }
47
+
48
+
49
+ public CommandBase ImportButtonCommand
50
+ {
51
+ get
52
+ {
53
+ return _importButtonCommand ;
54
+ }
30
55
}
31
56
32
57
void IndenterSettingsViewModel_PropertyChanged ( object sender , System . ComponentModel . PropertyChangedEventArgs e )
@@ -323,22 +348,58 @@ public void UpdateConfig(Configuration config)
323
348
324
349
public void SetToDefaults ( Configuration config )
325
350
{
326
- AlignCommentsWithCode = config . UserSettings . IndenterSettings . AlignCommentsWithCode ;
327
- AlignContinuations = config . UserSettings . IndenterSettings . AlignContinuations ;
328
- AlignDimColumn = config . UserSettings . IndenterSettings . AlignDimColumn ;
329
- AlignDims = config . UserSettings . IndenterSettings . AlignDims ;
330
- EndOfLineCommentColumnSpaceAlignment = config . UserSettings . IndenterSettings . EndOfLineCommentColumnSpaceAlignment ;
331
- EndOfLineCommentStyle = config . UserSettings . IndenterSettings . EndOfLineCommentStyle ;
332
- ForceCompilerDirectivesInColumn1 = config . UserSettings . IndenterSettings . ForceCompilerDirectivesInColumn1 ;
333
- ForceDebugStatementsInColumn1 = config . UserSettings . IndenterSettings . ForceDebugStatementsInColumn1 ;
334
- IgnoreOperatorsInContinuations = config . UserSettings . IndenterSettings . IgnoreOperatorsInContinuations ;
335
- IndentCase = config . UserSettings . IndenterSettings . IndentCase ;
336
- IndentEnumTypeAsProcedure = config . UserSettings . IndenterSettings . IndentEnumTypeAsProcedure ;
337
- IndentCompilerDirectives = config . UserSettings . IndenterSettings . IndentCompilerDirectives ;
338
- IndentEntireProcedureBody = config . UserSettings . IndenterSettings . IndentEntireProcedureBody ;
339
- IndentFirstCommentBlock = config . UserSettings . IndenterSettings . IndentFirstCommentBlock ;
340
- IndentFirstDeclarationBlock = config . UserSettings . IndenterSettings . IndentFirstDeclarationBlock ;
341
- IndentSpaces = config . UserSettings . IndenterSettings . IndentSpaces ;
351
+ TransferSettingsToView ( config . UserSettings . IndenterSettings ) ;
352
+ }
353
+
354
+ private void TransferSettingsToView ( IIndenterSettings toLoad )
355
+ {
356
+ AlignCommentsWithCode = toLoad . AlignCommentsWithCode ;
357
+ AlignContinuations = toLoad . AlignContinuations ;
358
+ AlignDimColumn = toLoad . AlignDimColumn ;
359
+ AlignDims = toLoad . AlignDims ;
360
+ EndOfLineCommentColumnSpaceAlignment = toLoad . EndOfLineCommentColumnSpaceAlignment ;
361
+ EndOfLineCommentStyle = toLoad . EndOfLineCommentStyle ;
362
+ ForceCompilerDirectivesInColumn1 = toLoad . ForceCompilerDirectivesInColumn1 ;
363
+ ForceDebugStatementsInColumn1 = toLoad . ForceDebugStatementsInColumn1 ;
364
+ IgnoreOperatorsInContinuations = toLoad . IgnoreOperatorsInContinuations ;
365
+ IndentCase = toLoad . IndentCase ;
366
+ IndentEnumTypeAsProcedure = toLoad . IndentEnumTypeAsProcedure ;
367
+ IndentCompilerDirectives = toLoad . IndentCompilerDirectives ;
368
+ IndentEntireProcedureBody = toLoad . IndentEntireProcedureBody ;
369
+ IndentFirstCommentBlock = toLoad . IndentFirstCommentBlock ;
370
+ IndentFirstDeclarationBlock = toLoad . IndentFirstDeclarationBlock ;
371
+ IndentSpaces = toLoad . IndentSpaces ;
372
+ }
373
+
374
+ private void ImportSettings ( )
375
+ {
376
+ using ( var dialog = new OpenFileDialog
377
+ {
378
+ Filter = RubberduckUI . DialogMask_XmlFilesOnly ,
379
+ Title = RubberduckUI . DialogCaption_LoadIndenterSettings
380
+ } )
381
+ {
382
+ dialog . ShowDialog ( ) ;
383
+ if ( string . IsNullOrEmpty ( dialog . FileName ) ) return ;
384
+ var service = new XmlPersistanceService < SmartIndenter . IndenterSettings > { FilePath = dialog . FileName } ;
385
+ var loaded = service . Load ( new SmartIndenter . IndenterSettings ( ) ) ;
386
+ TransferSettingsToView ( loaded ) ;
387
+ }
388
+ }
389
+
390
+ private void ExportSettings ( )
391
+ {
392
+ using ( var dialog = new SaveFileDialog
393
+ {
394
+ Filter = RubberduckUI . DialogMask_XmlFilesOnly ,
395
+ Title = RubberduckUI . DialogCaption_SaveIndenterSettings
396
+ } )
397
+ {
398
+ dialog . ShowDialog ( ) ;
399
+ if ( string . IsNullOrEmpty ( dialog . FileName ) ) return ;
400
+ var service = new XmlPersistanceService < SmartIndenter . IndenterSettings > { FilePath = dialog . FileName } ;
401
+ service . Save ( ( SmartIndenter . IndenterSettings ) GetCurrentSettings ( ) ) ;
402
+ }
342
403
}
343
404
}
344
405
}
0 commit comments