Skip to content

Commit 97cbd37

Browse files
committed
Add import and export for individual indenter settings.
1 parent 981998b commit 97cbd37

File tree

5 files changed

+184
-40
lines changed

5 files changed

+184
-40
lines changed

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 57 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
44
Microsoft ResX Schema
@@ -59,7 +59,7 @@
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
62-
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
6363
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
6464
<xsd:element name="root" msdata:IsDataSet="true">
6565
<xsd:complexType>
@@ -1840,4 +1840,19 @@ End If 'More Tools? Suggestions http://github.com/rubberduck-vba/Rubberduck
18401840

18411841
End Sub</value>
18421842
</data>
1843-
</root>
1843+
<data name="DialogCaption_LoadIndenterSettings" xml:space="preserve">
1844+
<value>Load Indenter Settings</value>
1845+
</data>
1846+
<data name="DialogCaption_SaveIndenterSettings" xml:space="preserve">
1847+
<value>Save Indenter Settings</value>
1848+
</data>
1849+
<data name="DialogMask_XmlFilesOnly" xml:space="preserve">
1850+
<value>XML file|*.xml</value>
1851+
</data>
1852+
<data name="SettingsCaption_ExportSettings" xml:space="preserve">
1853+
<value>Export</value>
1854+
</data>
1855+
<data name="SettingsCaption_ImportSettings" xml:space="preserve">
1856+
<value>Import</value>
1857+
</data>
1858+
</root>

RetailCoder.VBE/UI/Settings/IndenterSettings.xaml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@
3030
<RowDefinition Height="5" />
3131
<RowDefinition />
3232
</Grid.RowDefinitions>
33-
<ScrollViewer>
33+
<ScrollViewer Margin="0,0,10,0">
3434
<StackPanel Margin="5">
35-
<Label DockPanel.Dock="Top"
36-
Background="DarkGray"
37-
Foreground="White"
38-
FontWeight="SemiBold"
39-
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_IndenterSettings}"
35+
<Label Background="DarkGray"
36+
HorizontalContentAlignment="Stretch"
4037
Margin="0,0,0,3">
4138
<Label.Style>
4239
<Style>
@@ -47,6 +44,35 @@
4744
</Style.Resources>
4845
</Style>
4946
</Label.Style>
47+
<DockPanel Background="DarkGray" FlowDirection="LeftToRight">
48+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
49+
<Label Foreground="White"
50+
FontWeight="SemiBold"
51+
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_IndenterSettings}">
52+
53+
</Label>
54+
</StackPanel>
55+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right">
56+
<Grid>
57+
<Grid.ColumnDefinitions>
58+
<ColumnDefinition Width="Auto"/>
59+
<ColumnDefinition MaxWidth="75"/>
60+
<ColumnDefinition MaxWidth="75"/>
61+
</Grid.ColumnDefinitions>
62+
<Button Foreground="Blue" Grid.Column="1"
63+
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
64+
Command="{Binding ImportButtonCommand}" >
65+
<TextBlock TextDecorations="Underline" Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_ImportSettings}" />
66+
</Button>
67+
<Button Foreground="Blue" Grid.Column="2"
68+
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
69+
Command="{Binding ExportButtonCommand}" >
70+
<TextBlock TextDecorations="Underline" Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_ExportSettings}" />
71+
</Button>
72+
</Grid>
73+
</StackPanel>
74+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right"/>
75+
</DockPanel>
5076
</Label>
5177
<Grid>
5278
<Grid.ColumnDefinitions>

RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
using System;
22
using System.Linq;
3+
using NLog;
34
using Rubberduck.Settings;
5+
using Rubberduck.SettingsProvider;
46
using Rubberduck.SmartIndenter;
7+
using Rubberduck.UI.Command;
58

69
namespace Rubberduck.UI.Settings
710
{
811
public class IndenterSettingsViewModel : ViewModelBase, ISettingsViewModel
912
{
13+
private readonly CommandBase _importButtonCommand;
14+
private readonly CommandBase _exportButtonCommand;
15+
1016
public IndenterSettingsViewModel(Configuration config)
1117
{
1218
_alignCommentsWithCode = config.UserSettings.IndenterSettings.AlignCommentsWithCode;
@@ -27,6 +33,25 @@ public IndenterSettingsViewModel(Configuration config)
2733
_indentSpaces = config.UserSettings.IndenterSettings.IndentSpaces;
2834

2935
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+
}
3055
}
3156

3257
void IndenterSettingsViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -323,22 +348,58 @@ public void UpdateConfig(Configuration config)
323348

324349
public void SetToDefaults(Configuration config)
325350
{
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+
}
342403
}
343404
}
344405
}

Rubberduck.SmartIndenter/Indenter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using System;
2-
using System.CodeDom.Compiler;
32
using System.Collections.Generic;
43
using System.Linq;
5-
using System.Net.Configuration;
64
using Rubberduck.VBEditor;
75
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
8-
using Rubberduck.VBEditor.SafeComWrappers.VBA;
96

107
namespace Rubberduck.SmartIndenter
118
{

0 commit comments

Comments
 (0)