Skip to content

Commit

Permalink
implemented settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Jun 5, 2018
1 parent c992238 commit e8e5cb8
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Rubberduck.Core/Rubberduck.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@
</Compile>
<Compile Include="UI\Refactorings\ReorderParameters\ReorderParametersViewModel.cs" />
<Compile Include="UI\SelectionChangeService.cs" />
<Compile Include="UI\Settings\AutoCompleteSettings.xaml.cs">
<DependentUpon>AutoCompleteSettings.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Settings\AutoCompleteSettingsViewModel.cs" />
<Compile Include="UnitTesting\IFakes.cs" />
<Compile Include="UnitTesting\ReturnTypeConverter.cs" />
<Compile Include="UnitTesting\PermissiveObjectComparer.cs" />
Expand Down Expand Up @@ -1053,6 +1057,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Settings\AutoCompleteSettings.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\Settings\GeneralSettings.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
116 changes: 116 additions & 0 deletions Rubberduck.Core/UI/Settings/AutoCompleteSettings.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<UserControl x:Class="Rubberduck.UI.Settings.AutoCompleteSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:core="clr-namespace:System;assembly=mscorlib"
xmlns:settings="clr-namespace:Rubberduck.UI.Settings"
xmlns:converters="clr-namespace:Rubberduck.UI.Settings.Converters"
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance {x:Type settings:AutoCompleteSettingsViewModel}, IsDesignTimeCreatable=False}"
d:DesignWidth="500"
d:DesignHeight="350">
<UserControl.Resources>
<Style x:Key="PrettifyRow" TargetType="{x:Type DataGridRow}">
<Style.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="2"/>
</Style>
</Style.Resources>
<Setter Property="BorderThickness" Value="0,.5,0,0" />
<Setter Property="BorderBrush" Value="DarkGray" />
<Setter Property="Height" Value="26" />
<Setter Property="TextBlock.FontWeight" Value="Normal" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderThickness" Value="1.5" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="Selector.IsSelectionActive" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="#adc6e5"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True" />
<Condition Property="Selector.IsSelectionActive" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}" />
</MultiTrigger>
</Style.Triggers>
</Style>

</UserControl.Resources>
<Grid>
<ScrollViewer>
<StackPanel Margin="5,5,5,0" ScrollViewer.VerticalScrollBarVisibility="Auto">
<Label Background="DarkGray"
HorizontalContentAlignment="Stretch"
Margin="0,5,0,5">
<Label.Style>
<Style>
<Style.Resources>
<Style TargetType="{x:Type Border}">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Style.Resources>
</Style>
</Label.Style>
<DockPanel Background="DarkGray" FlowDirection="LeftToRight">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
<Label Foreground="White"
FontWeight="SemiBold"
Content="{Resx ResxName=Rubberduck.Resources.Settings.AutoCompletePage, Key=PageHeader}">
</Label>
</StackPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right" HorizontalAlignment="Right">
<controls:LinkButton
Margin="2"
Command="{Binding ImportButtonCommand}"
Content="{Resx ResxName=Rubberduck.Resources.Settings.SettingsUI, Key=ImportPageSettingsButton}"/>
<controls:LinkButton
Margin="2"
Command="{Binding ExportButtonCommand}"
Content="{Resx ResxName=Rubberduck.Resources.Settings.SettingsUI, Key=ExportPageSettingsButton}"/>
</StackPanel>
</DockPanel>
</Label>
<Border BorderBrush="DarkGray" BorderThickness="1" CornerRadius="2">
<DataGrid Name="AutoCompleteSettingsGrid"
ItemsSource="{Binding Settings}"
AutoGenerateColumns="False"
CanUserReorderColumns="False"
IsReadOnly="False"
SelectionMode="Single"
CanUserAddRows="False"
CanUserSortColumns="False"
HorizontalGridLinesBrush="Transparent"
VerticalGridLinesBrush="Transparent"
HeadersVisibility="None"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemContainerStyle="{StaticResource PrettifyRow}"
ColumnHeaderHeight="22"
BorderThickness="0"
Height="200">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Background" Value="Transparent" />
</Style>
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Width="Auto" Binding="{Binding Description}" IsReadOnly="True" />
<DataGridCheckBoxColumn Width="*" Binding="{Binding IsEnabled}" />
</DataGrid.Columns>
</DataGrid>
</Border>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>
35 changes: 35 additions & 0 deletions Rubberduck.Core/UI/Settings/AutoCompleteSettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Rubberduck.UI.Settings
{
/// <summary>
/// Interaction logic for AutoCompleteSettings.xaml
/// </summary>
public partial class AutoCompleteSettings : UserControl, ISettingsView
{
public AutoCompleteSettings()
{
InitializeComponent();
}

public AutoCompleteSettings(ISettingsViewModel vm) : this()
{
DataContext = vm;
}

public ISettingsViewModel ViewModel => DataContext as ISettingsViewModel;
}
}
86 changes: 86 additions & 0 deletions Rubberduck.Core/UI/Settings/AutoCompleteSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using NLog;
using Rubberduck.Resources;
using Rubberduck.Settings;
using Rubberduck.SettingsProvider;
using Rubberduck.UI.Command;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;

namespace Rubberduck.UI.Settings
{
public class AutoCompleteSettingsViewModel : SettingsViewModelBase, ISettingsViewModel
{
public AutoCompleteSettingsViewModel(Configuration config)
{
Settings = new ListCollectionView(
config.UserSettings.AutoCompleteSettings.AutoCompletes.ToList());

ExportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ExportSettings());
ImportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ImportSettings());
}

private ListCollectionView _settings;
public ListCollectionView Settings
{
get { return _settings; }
set
{
if (_settings != value)
{
_settings = value;
OnPropertyChanged();
}
}
}

public void SetToDefaults(Configuration config)
{
TransferSettingsToView(config.UserSettings.AutoCompleteSettings);
}

public void UpdateConfig(Configuration config)
{
config.UserSettings.AutoCompleteSettings.AutoCompletes = new HashSet<AutoCompleteSetting>(_settings.OfType<AutoCompleteSetting>());
}

private void TransferSettingsToView(Rubberduck.Settings.AutoCompleteSettings toLoad)
{
Settings = new ListCollectionView(toLoad.AutoCompletes.ToList());
}

private void ImportSettings()
{
using (var dialog = new OpenFileDialog
{
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
Title = RubberduckUI.DialogCaption_LoadInspectionSettings
})
{
dialog.ShowDialog();
if (string.IsNullOrEmpty(dialog.FileName)) return;
var service = new XmlPersistanceService<Rubberduck.Settings.AutoCompleteSettings> { FilePath = dialog.FileName };
var loaded = service.Load(new Rubberduck.Settings.AutoCompleteSettings());
TransferSettingsToView(loaded);
}
}

private void ExportSettings()
{
using (var dialog = new SaveFileDialog
{
Filter = RubberduckUI.DialogMask_XmlFilesOnly,
Title = RubberduckUI.DialogCaption_SaveInspectionSettings
})
{
dialog.ShowDialog();
if (string.IsNullOrEmpty(dialog.FileName)) return;
var service = new XmlPersistanceService<Rubberduck.Settings.AutoCompleteSettings> { FilePath = dialog.FileName };
service.Save(new Rubberduck.Settings.AutoCompleteSettings
{
AutoCompletes = new HashSet<AutoCompleteSetting>(this.Settings.SourceCollection.OfType<AutoCompleteSetting>()),
});
}
}
}
}
3 changes: 2 additions & 1 deletion Rubberduck.Core/UI/Settings/SettingsControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SettingsControlViewModel : ViewModelBase
SettingsView inspectionSettings,
SettingsView unitTestSettings,
SettingsView indenterSettings,
SettingsView autoCompleteSettings,
SettingsView windowSettings,
SettingsViews activeView = UI.Settings.SettingsViews.GeneralSettings)
{
Expand All @@ -32,7 +33,7 @@ public class SettingsControlViewModel : ViewModelBase

SettingsViews = new ObservableCollection<SettingsView>
{
generalSettings, todoSettings, inspectionSettings, unitTestSettings, indenterSettings, windowSettings
generalSettings, todoSettings, inspectionSettings, unitTestSettings, indenterSettings, autoCompleteSettings, windowSettings
};

SelectedSettingsView = SettingsViews.First(v => v.View == activeView);
Expand Down
5 changes: 5 additions & 0 deletions Rubberduck.Core/UI/Settings/SettingsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public SettingsForm(IGeneralConfigService configService, IOperatingSystem operat
View = SettingsViews.IndenterSettings
},
new SettingsView
{
Control = new AutoCompleteSettings(new AutoCompleteSettingsViewModel(config)),
View = SettingsViews.AutoCompleteSettings
},
new SettingsView
{
Control = new WindowSettings(new WindowSettingsViewModel(config)),
View = SettingsViews.WindowSettings
Expand Down
1 change: 1 addition & 0 deletions Rubberduck.Core/UI/Settings/SettingsViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public enum SettingsViews
InspectionSettings,
UnitTestSettings,
IndenterSettings,
AutoCompleteSettings,
WindowSettings
}
}
2 changes: 1 addition & 1 deletion Rubberduck.Resources/Settings/SettingsUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rubberduck.Resources/Settings/SettingsUI.cs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="PageHeader_WindowSettings" xml:space="preserve">
<value>Window Settings</value>
</data>
<data name="PageInstructions_AutoCompleteSettings" xml:space="preserve">
<value>Configure which autocompletions are enabled.</value>
</data>
<data name="PageInstructions_GeneralSettings" xml:space="preserve">
<value>Klikněte [Ok] pro uzavření okna a aplikování změn, nebo [Zrušit] pro jejich zrušení.</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions Rubberduck.Resources/Settings/SettingsUI.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@
<data name="PageHeader_WindowSettings" xml:space="preserve">
<value>Fenstereinstellungen</value>
</data>
<data name="PageInstructions_AutoCompleteSettings" xml:space="preserve">
<value>Configure which autocompletions are enabled.</value>
</data>
<data name="PageInstructions_GeneralSettings" xml:space="preserve">
<value>[Ok] zum Schließen und Speichern oder [Abbrechen] zum Verwerfen der Änderungen.</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions Rubberduck.Resources/Settings/SettingsUI.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,7 @@
<data name="ConfirmResetSettings" xml:space="preserve">
<value>Réinitialiser les paramètres par défaut?</value>
</data>
<data name="PageInstructions_AutoCompleteSettings" xml:space="preserve">
<value>Activer ou désactiver les autocomplétions</value>
</data>
</root>
2 changes: 1 addition & 1 deletion Rubberduck.Resources/Settings/SettingsUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<value>Window Settings</value>
</data>
<data name="PageInstructions_AutoCompleteSettings" xml:space="preserve">
<value>Configure Autocompletion</value>
<value>Configure which autocompletions are enabled.</value>
</data>
<data name="PageInstructions_GeneralSettings" xml:space="preserve">
<value>Click [Ok] to close the window and apply changes, or [Cancel] to discard them.</value>
Expand Down

0 comments on commit e8e5cb8

Please sign in to comment.