Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #481 - Keep selected filter option between application restarts. #503

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EverythinhSearch.Instance.PropertyChanged could fire prior to the element loading

};
}

public int SelectedDefaultFilterIndex
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to remove these and revert back, it's public because I was going to use it for the binding (which didn't stop the issue), but I figured I'd leave it in case that's actually the better way

{
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During testing this code was reached (and toggles selection) when an item is selected from the dropdown list, there wasn't another reliable property I could find that would indicate that the window is actually open (during the Show() triggering of this event, even though the window wasn't yet visible, both isVisible and isHitBoxVisible were true.

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