(GUI): remember last opened section in settings.

This commit is contained in:
morkt
2018-01-10 17:09:29 +04:00
parent 13829ca798
commit a3664adb53
2 changed files with 25 additions and 3 deletions

View File

@@ -169,7 +169,7 @@ IN THE SOFTWARE.
Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"> Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<StackPanel Orientation="Vertical" DataContext="{Binding ElementName=SectionsPane,Path=SelectedItem}"> <StackPanel Orientation="Vertical" DataContext="{Binding ElementName=SectionsPane,Path=SelectedItem}">
<TextBlock Text="{Binding SectionTitle}" Background="{StaticResource SectionTitleBackground}" <TextBlock Text="{Binding SectionTitle}" Background="{StaticResource SectionTitleBackground}"
FontWeight="Bold" FontSize="14" Padding="2,0,2,0"/> FontWeight="Bold" FontSize="14" Padding="2,0,2,0" Margin="0,0,0,4"/>
<StackPanel x:Name="SettingsPane"/> <StackPanel x:Name="SettingsPane"/>
</StackPanel> </StackPanel>
</ScrollViewer> </ScrollViewer>

View File

@@ -48,6 +48,8 @@ namespace GARbro.GUI
SettingsViewModel ViewModel; SettingsViewModel ViewModel;
static string LastSelectedSection = null;
private void OnSectionChanged (object sender, System.Windows.RoutedEventArgs e) private void OnSectionChanged (object sender, System.Windows.RoutedEventArgs e)
{ {
this.SettingsPane.Children.Clear(); this.SettingsPane.Children.Clear();
@@ -65,6 +67,9 @@ namespace GARbro.GUI
{ {
ApplyChanges(); ApplyChanges();
DialogResult = true; DialogResult = true;
var section = SectionsPane.SelectedItem as SettingsSectionView;
if (section != null)
LastSelectedSection = section.Label;
} }
private void ApplyChanges () private void ApplyChanges ()
@@ -84,13 +89,17 @@ namespace GARbro.GUI
Children = EnumerateFormatsSettings() 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 }; return new SettingsViewModel { Root = list };
} }
IEnumerable<SettingsSectionView> EnumerateFormatsSettings () IEnumerable<SettingsSectionView> EnumerateFormatsSettings ()
{ {
var default_margin = new Thickness (2);
var list = new List<SettingsSectionView>(); var list = new List<SettingsSectionView>();
foreach (var format in FormatCatalog.Instance.Formats.Where (f => f.Settings != null && f.Settings.Any())) foreach (var format in FormatCatalog.Instance.Formats.Where (f => f.Settings != null && f.Settings.Any()))
{ {
@@ -123,6 +132,19 @@ namespace GARbro.GUI
return list; return list;
} }
static IEnumerable<SettingsSectionView> EnumerateSections (IEnumerable<SettingsSectionView> 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) private void tvi_MouseRightButtonDown (object sender, MouseButtonEventArgs e)
{ {
var item = sender as TreeViewItem; var item = sender as TreeViewItem;