Skip to content

Commit

Permalink
Keep selected filter option between application restarts (#503)
Browse files Browse the repository at this point in the history
* Fixes #481 - Keep selected filter option between application restarts.

* Remove explicit property name in NotifyPropertyChanged() call.
  • Loading branch information
zeyus committed Jun 13, 2024
1 parent 635494c commit 6abbd88
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
8 changes: 4 additions & 4 deletions EverythingToolbar/Controls/FilterSelector.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
BorderThickness="0, 0, 0, 1">
<StackPanel Orientation="Horizontal">
<TabControl x:Name="TabControl"
SelectionChanged="OnTabItemSelected"
ItemsSource="{Binding DefaultFilters}" />
ItemsSource="{Binding DefaultFilters}"
SelectedIndex="-1" />

<ComboBox Name="ComboBox"
SelectionChanged="OnComboBoxItemSelected"
ItemsSource="{Binding UserFilters}"
DisplayMemberPath="Name" />
DisplayMemberPath="Name"
SelectedIndex="-1" />
</StackPanel>
</Border>

Expand Down
29 changes: 25 additions & 4 deletions EverythingToolbar/Controls/FilterSelector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ public FilterSelector()
{
InitializeComponent();
DataContext = FilterLoader.Instance;
EverythingSearch.Instance.PropertyChanged += OnCurrentFilterChanged;
Loaded += (s, e) => { SelectCurrentFilter(); };
Loaded += (s, e) => {
SelectCurrentFilter();
EverythingSearch.Instance.PropertyChanged += OnCurrentFilterChanged;
};
}

public int SelectedDefaultFilterIndex
{
get => FilterLoader.Instance.DefaultFilters.IndexOf(EverythingSearch.Instance.CurrentFilter);
}

public int SelectedUserFilterIndex
{
get => FilterLoader.Instance.UserFilters.IndexOf(EverythingSearch.Instance.CurrentFilter);
}
private void SelectCurrentFilter()
{
TabControl.SelectionChanged -= OnTabItemSelected;
TabControl.SelectedIndex = FilterLoader.Instance.DefaultFilters.IndexOf(EverythingSearch.Instance.CurrentFilter);
TabControl.SelectedIndex = SelectedDefaultFilterIndex;
TabControl.SelectionChanged += OnTabItemSelected;

ComboBox.SelectionChanged -= OnComboBoxItemSelected;
ComboBox.SelectedIndex = FilterLoader.Instance.UserFilters.IndexOf(EverythingSearch.Instance.CurrentFilter);
ComboBox.SelectedIndex = SelectedUserFilterIndex;
ComboBox.SelectionChanged += OnComboBoxItemSelected;
}

Expand All @@ -39,6 +50,11 @@ private void OnTabItemSelected(object sender, SelectionChangedEventArgs e)
if (TabControl.SelectedIndex < 0)
return;

if (!TabControl.IsFocused && !TabControl.IsMouseOver) {
TabControl.SelectedIndex = -1;
return;
}

EverythingSearch.Instance.CurrentFilter = TabControl.SelectedItem as Filter;
}

Expand All @@ -47,6 +63,11 @@ private void OnComboBoxItemSelected(object sender, SelectionChangedEventArgs e)
if (ComboBox.SelectedIndex < 0)
return;

if (!ComboBox.IsFocused && !ComboBox.IsMouseOver) {
ComboBox.SelectedIndex = -1;
return;
}

EverythingSearch.Instance.CurrentFilter = ComboBox.SelectedItem as Filter;
}
}
Expand Down
1 change: 1 addition & 0 deletions EverythingToolbar/EverythingSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public Filter CurrentFilter
return;

_currentFilter = value;
Settings.Default.lastFilter = value.Name;

lock (_lock)
SearchResults.Clear();
Expand Down

0 comments on commit 6abbd88

Please sign in to comment.