From a3664adb538447739ec65e1d0f47a48890989ab4 Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 10 Jan 2018 17:09:29 +0400 Subject: [PATCH] (GUI): remember last opened section in settings. --- GUI/SettingsWindow.xaml | 2 +- GUI/SettingsWindow.xaml.cs | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/GUI/SettingsWindow.xaml b/GUI/SettingsWindow.xaml index f380bf16..f673ed15 100644 --- a/GUI/SettingsWindow.xaml +++ b/GUI/SettingsWindow.xaml @@ -169,7 +169,7 @@ IN THE SOFTWARE. Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"> + FontWeight="Bold" FontSize="14" Padding="2,0,2,0" Margin="0,0,0,4"/> diff --git a/GUI/SettingsWindow.xaml.cs b/GUI/SettingsWindow.xaml.cs index b8b9ce37..f4e6a094 100644 --- a/GUI/SettingsWindow.xaml.cs +++ b/GUI/SettingsWindow.xaml.cs @@ -48,6 +48,8 @@ namespace GARbro.GUI SettingsViewModel ViewModel; + static string LastSelectedSection = null; + private void OnSectionChanged (object sender, System.Windows.RoutedEventArgs e) { this.SettingsPane.Children.Clear(); @@ -65,6 +67,9 @@ namespace GARbro.GUI { ApplyChanges(); DialogResult = true; + var section = SectionsPane.SelectedItem as SettingsSectionView; + if (section != null) + LastSelectedSection = section.Label; } private void ApplyChanges () @@ -84,13 +89,17 @@ namespace GARbro.GUI Children = EnumerateFormatsSettings() }, }; - list[0].IsSelected = true; + SettingsSectionView selected_section = null; + if (LastSelectedSection != null) + selected_section = EnumerateSections (list).FirstOrDefault (s => s.Label == LastSelectedSection); + if (null == selected_section) + selected_section = list[0]; + selected_section.IsSelected = true; return new SettingsViewModel { Root = list }; } IEnumerable EnumerateFormatsSettings () { - var default_margin = new Thickness (2); var list = new List(); foreach (var format in FormatCatalog.Instance.Formats.Where (f => f.Settings != null && f.Settings.Any())) { @@ -123,6 +132,19 @@ namespace GARbro.GUI return list; } + static IEnumerable EnumerateSections (IEnumerable list) + { + foreach (var section in list) + { + yield return section; + if (section.Children != null) + { + foreach (var child in EnumerateSections (section.Children)) + yield return child; + } + } + } + private void tvi_MouseRightButtonDown (object sender, MouseButtonEventArgs e) { var item = sender as TreeViewItem;