Skip to content

Commit cb55bca

Browse files
committed
Extend import/export to all settings forms, fix stupid button focus.
1 parent 6d120c9 commit cb55bca

14 files changed

+511
-111
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@
775775
</Compile>
776776
<Compile Include="UI\Settings\SettingsControlViewModel.cs" />
777777
<Compile Include="UI\Settings\SettingsView.cs" />
778+
<Compile Include="UI\Settings\SettingsViewModelBase.cs" />
778779
<Compile Include="UI\Settings\SettingsViews.cs" />
779780
<Compile Include="UI\Settings\Converters\SettingsViewToPageConverter.cs" />
780781
<Compile Include="UI\Settings\TodoSettings.xaml.cs">

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 73 additions & 1 deletion
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: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,12 +1847,36 @@ End Sub</value>
18471847
<value>Save Indenter Settings</value>
18481848
</data>
18491849
<data name="DialogMask_XmlFilesOnly" xml:space="preserve">
1850-
<value>XML file|*.xml</value>
1850+
<value>XML file (.xml)|*.xml|Rubberduck config file|*.config</value>
18511851
</data>
18521852
<data name="SettingsCaption_ExportSettings" xml:space="preserve">
18531853
<value>Export</value>
18541854
</data>
18551855
<data name="SettingsCaption_ImportSettings" xml:space="preserve">
18561856
<value>Import</value>
18571857
</data>
1858+
<data name="DialogCaption_LoadGeneralSettings" xml:space="preserve">
1859+
<value>Load General Settings</value>
1860+
</data>
1861+
<data name="DialogCaption_LoadInspectionSettings" xml:space="preserve">
1862+
<value>Load Inspection Settings</value>
1863+
</data>
1864+
<data name="DialogCaption_LoadToDoSettings" xml:space="preserve">
1865+
<value>Load Todo List Settings</value>
1866+
</data>
1867+
<data name="DialogCaption_LoadUnitTestSettings" xml:space="preserve">
1868+
<value>Load Unit Test Settings</value>
1869+
</data>
1870+
<data name="DialogCaption_SaveGeneralSettings" xml:space="preserve">
1871+
<value>Save General Settings</value>
1872+
</data>
1873+
<data name="DialogCaption_SaveInspectionSettings" xml:space="preserve">
1874+
<value>Save Inspection Settings</value>
1875+
</data>
1876+
<data name="DialogCaption_SaveToDoSettings" xml:space="preserve">
1877+
<value>Save Todo List Settings</value>
1878+
</data>
1879+
<data name="DialogCaption_SaveUnitTestSettings" xml:space="preserve">
1880+
<value>Save Unit Test Settings</value>
1881+
</data>
18581882
</root>

RetailCoder.VBE/UI/Settings/GeneralSettings.xaml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@
7171
<ScrollViewer>
7272
<Grid>
7373
<StackPanel Grid.Row="0" Margin="5,5,5,0">
74-
<Label DockPanel.Dock="Top"
75-
Background="DarkGray"
76-
Foreground="White"
77-
FontWeight="SemiBold"
78-
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_GeneralSettings}"
79-
Margin="0,0,0,3">
74+
<Label Background="DarkGray"
75+
HorizontalContentAlignment="Stretch"
76+
Margin="0,0,0,3">
8077
<Label.Style>
8178
<Style>
8279
<Style.Resources>
@@ -86,8 +83,45 @@
8683
</Style.Resources>
8784
</Style>
8885
</Label.Style>
89-
</Label>
90-
86+
<DockPanel Background="DarkGray" FlowDirection="LeftToRight">
87+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
88+
<Label Foreground="White"
89+
FontWeight="SemiBold"
90+
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_GeneralSettings}">
91+
</Label>
92+
</StackPanel>
93+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right">
94+
<Grid>
95+
<Grid.ColumnDefinitions>
96+
<ColumnDefinition Width="Auto"/>
97+
<ColumnDefinition MaxWidth="75"/>
98+
<ColumnDefinition MaxWidth="75"/>
99+
</Grid.ColumnDefinitions>
100+
<TextBlock Foreground="Blue"
101+
Grid.Column="1"
102+
TextDecorations="Underline"
103+
Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_ImportSettings}"
104+
VerticalAlignment="Center"
105+
Margin="5,0,5,0">
106+
<TextBlock.InputBindings>
107+
<MouseBinding Command="{Binding ImportButtonCommand}" MouseAction="LeftClick" />
108+
</TextBlock.InputBindings>
109+
</TextBlock>
110+
<TextBlock Foreground="Blue"
111+
Grid.Column="2"
112+
TextDecorations="Underline"
113+
Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_ExportSettings}"
114+
VerticalAlignment="Center"
115+
Margin="5,0,5,0">
116+
<TextBlock.InputBindings>
117+
<MouseBinding Command="{Binding ExportButtonCommand}" MouseAction="LeftClick" />
118+
</TextBlock.InputBindings>
119+
</TextBlock>
120+
</Grid>
121+
</StackPanel>
122+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right"/>
123+
</DockPanel>
124+
</Label>
91125
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_LanguageLabel}" FontWeight="SemiBold" />
92126
<ComboBox Width="210"
93127
HorizontalAlignment="Left"

RetailCoder.VBE/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Rubberduck.Settings;
44
using Rubberduck.Common;
55
using NLog;
6+
using Rubberduck.SettingsProvider;
67
using Rubberduck.UI.Command;
78

89
namespace Rubberduck.UI.Settings
@@ -13,7 +14,7 @@ public enum DelimiterOptions
1314
Slash = 47
1415
}
1516

16-
public class GeneralSettingsViewModel : ViewModelBase, ISettingsViewModel
17+
public class GeneralSettingsViewModel : SettingsViewModelBase, ISettingsViewModel
1718
{
1819
private readonly IOperatingSystem _operatingSystem;
1920

@@ -28,16 +29,12 @@ public GeneralSettingsViewModel(Configuration config, IOperatingSystem operating
2829
new DisplayLanguageSetting("de-DE")
2930
});
3031

31-
SelectedLanguage = Languages.First(l => l.Code == config.UserSettings.GeneralSettings.Language.Code);
32-
Hotkeys = new ObservableCollection<HotkeySetting>(config.UserSettings.HotkeySettings.Settings);
33-
ShowSplashAtStartup = config.UserSettings.GeneralSettings.ShowSplash;
34-
AutoSaveEnabled = config.UserSettings.GeneralSettings.AutoSaveEnabled;
35-
AutoSavePeriod = config.UserSettings.GeneralSettings.AutoSavePeriod;
36-
Delimiter = (DelimiterOptions)config.UserSettings.GeneralSettings.Delimiter;
3732
LogLevels = new ObservableCollection<MinimumLogLevel>(LogLevelHelper.LogLevels.Select(l => new MinimumLogLevel(l.Ordinal, l.Name)));
38-
SelectedLogLevel = LogLevels.First(l => l.Ordinal == config.UserSettings.GeneralSettings.MinimumLogLevel);
33+
TransferSettingsToView(config.UserSettings.GeneralSettings, config.UserSettings.HotkeySettings);
3934

4035
_showLogFolderCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ShowLogFolder());
36+
ExportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ExportSettings());
37+
ImportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ImportSettings());
4138
}
4239

4340
public ObservableCollection<DisplayLanguageSetting> Languages { get; set; }
@@ -154,24 +151,72 @@ private void ShowLogFolder()
154151

155152
public void UpdateConfig(Configuration config)
156153
{
157-
config.UserSettings.GeneralSettings.Language = SelectedLanguage;
154+
config.UserSettings.GeneralSettings = GetCurrentGeneralSettings();
158155
config.UserSettings.HotkeySettings.Settings = Hotkeys.ToArray();
159-
config.UserSettings.GeneralSettings.ShowSplash = ShowSplashAtStartup;
160-
config.UserSettings.GeneralSettings.AutoSaveEnabled = AutoSaveEnabled;
161-
config.UserSettings.GeneralSettings.AutoSavePeriod = AutoSavePeriod;
162-
config.UserSettings.GeneralSettings.Delimiter = (char)Delimiter;
163-
config.UserSettings.GeneralSettings.MinimumLogLevel = SelectedLogLevel.Ordinal;
164156
}
165157

166158
public void SetToDefaults(Configuration config)
167159
{
168-
SelectedLanguage = Languages.First(l => l.Code == config.UserSettings.GeneralSettings.Language.Code);
169-
Hotkeys = new ObservableCollection<HotkeySetting>(config.UserSettings.HotkeySettings.Settings);
170-
ShowSplashAtStartup = config.UserSettings.GeneralSettings.ShowSplash;
171-
AutoSaveEnabled = config.UserSettings.GeneralSettings.AutoSaveEnabled;
172-
AutoSavePeriod = config.UserSettings.GeneralSettings.AutoSavePeriod;
173-
Delimiter = (DelimiterOptions)config.UserSettings.GeneralSettings.Delimiter;
174-
SelectedLogLevel = LogLevels.First(l => l.Ordinal == config.UserSettings.GeneralSettings.MinimumLogLevel);
160+
TransferSettingsToView(config.UserSettings.GeneralSettings, config.UserSettings.HotkeySettings);
161+
}
162+
163+
private Rubberduck.Settings.GeneralSettings GetCurrentGeneralSettings()
164+
{
165+
return new Rubberduck.Settings.GeneralSettings
166+
{
167+
Language = SelectedLanguage,
168+
ShowSplash = ShowSplashAtStartup,
169+
AutoSaveEnabled = AutoSaveEnabled,
170+
AutoSavePeriod = AutoSavePeriod,
171+
Delimiter = (char)Delimiter,
172+
MinimumLogLevel = SelectedLogLevel.Ordinal
173+
};
174+
}
175+
176+
private void TransferSettingsToView(IGeneralSettings general, IHotkeySettings hottkey)
177+
{
178+
SelectedLanguage = Languages.First(l => l.Code == general.Language.Code);
179+
Hotkeys = new ObservableCollection<HotkeySetting>(hottkey.Settings);
180+
ShowSplashAtStartup = general.ShowSplash;
181+
AutoSaveEnabled = general.AutoSaveEnabled;
182+
AutoSavePeriod = general.AutoSavePeriod;
183+
Delimiter = (DelimiterOptions)general.Delimiter;
184+
SelectedLogLevel = LogLevels.First(l => l.Ordinal == general.MinimumLogLevel);
185+
}
186+
187+
private void ImportSettings()
188+
{
189+
using (var dialog = new OpenFileDialog
190+
{
191+
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
192+
Title = RubberduckUI.DialogCaption_LoadGeneralSettings
193+
})
194+
{
195+
dialog.ShowDialog();
196+
if (string.IsNullOrEmpty(dialog.FileName)) return;
197+
var service = new XmlPersistanceService<Rubberduck.Settings.GeneralSettings> { FilePath = dialog.FileName };
198+
var general = service.Load(new Rubberduck.Settings.GeneralSettings());
199+
var hkService = new XmlPersistanceService<HotkeySettings> { FilePath = dialog.FileName };
200+
var hotkey = hkService.Load(new HotkeySettings());
201+
TransferSettingsToView(general, hotkey);
202+
}
203+
}
204+
205+
private void ExportSettings()
206+
{
207+
using (var dialog = new SaveFileDialog
208+
{
209+
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
210+
Title = RubberduckUI.DialogCaption_SaveGeneralSettings
211+
})
212+
{
213+
dialog.ShowDialog();
214+
if (string.IsNullOrEmpty(dialog.FileName)) return;
215+
var service = new XmlPersistanceService<Rubberduck.Settings.GeneralSettings> { FilePath = dialog.FileName };
216+
service.Save(GetCurrentGeneralSettings());
217+
var hkService = new XmlPersistanceService<HotkeySettings> { FilePath = dialog.FileName };
218+
hkService.Save(new HotkeySettings { Settings = Hotkeys.ToArray() });
219+
}
175220
}
176221
}
177222
}

RetailCoder.VBE/UI/Settings/IndenterSettings.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
<Label Foreground="White"
5050
FontWeight="SemiBold"
5151
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SettingsCaption_IndenterSettings}">
52-
5352
</Label>
5453
</StackPanel>
5554
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right">
@@ -86,10 +85,11 @@
8685
</Label>
8786
<Grid>
8887
<Grid.ColumnDefinitions>
89-
<ColumnDefinition />
90-
<ColumnDefinition />
88+
<ColumnDefinition Width="232*" />
89+
<ColumnDefinition Width="161*" />
90+
<ColumnDefinition Width="70*"/>
9191
</Grid.ColumnDefinitions>
92-
<StackPanel>
92+
<StackPanel Margin="0,0,0,22">
9393
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=IndenterSettings_AlignmentOptionsLabel}"
9494
FontWeight="SemiBold" />
9595
<CheckBox IsChecked="{Binding AlignCommentsWithCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
@@ -157,7 +157,7 @@
157157
</StackPanel>
158158
</StackPanel>
159159

160-
<StackPanel Grid.Column="1">
160+
<StackPanel Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,22">
161161
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=IndenterSettings_IndentOptionsLabel}"
162162
FontWeight="SemiBold" />
163163
<CheckBox Name="IndentProcedureCheckBox"

0 commit comments

Comments
 (0)