Skip to content

Commit

Permalink
! Unified the behavior of clear filter buttons in member filter controls
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Dec 23, 2018
1 parent 2206814 commit 7ef967b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions Codist/Controls/MemberFilterBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,37 @@ public MemberFilterBox(ItemCollection items) {
});
Children.Add(_FilterButtons = new MemberFilterButtonGroup());
_Items = items;
_FilterButtons.FilterChanged += _FilterBox_Changed;
_FilterBox.TextChanged += _FilterBox_Changed;

void _FilterBox_Changed(object sender, EventArgs e) {
Filter(_FilterBox.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), _FilterButtons.Filters);
FocusTextBox();
}
_FilterButtons.FilterChanged += FilterBox_Changed;
_FilterButtons.FilterCleared += FilterBox_Clear;
_FilterBox.TextChanged += FilterBox_Changed;
}
public bool FocusTextBox() {
if (_FilterBox.IsVisible) {
return _FilterBox.Focus();
}
_FilterBox.IsVisibleChanged -= _FilterBox_IsVisibleChanged;
_FilterBox.IsVisibleChanged += _FilterBox_IsVisibleChanged;
_FilterBox.IsVisibleChanged -= FilterBox_IsVisibleChanged;
_FilterBox.IsVisibleChanged += FilterBox_IsVisibleChanged;
return false;
}

void _FilterBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
void FilterBox_Clear(object sender, EventArgs e) {
if (_FilterBox.Text.Length > 0) {
_FilterBox.Text = String.Empty;
}
else {
FilterBox_Changed(sender, e);
}
}
void FilterBox_Changed(object sender, EventArgs e) {
Filter(_FilterBox.Text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), _FilterButtons.Filters);
FocusTextBox();
}

void FilterBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
if (_FilterBox.IsVisible) {
_FilterBox.Focus();
_FilterBox.SelectAll();
_FilterBox.IsVisibleChanged -= _FilterBox_IsVisibleChanged;
_FilterBox.IsVisibleChanged -= FilterBox_IsVisibleChanged;
}
}

Expand Down Expand Up @@ -265,6 +274,7 @@ sealed class MemberFilterButtonGroup : UserControl
bool _uiLock;

public event EventHandler FilterChanged;
public event EventHandler FilterCleared;

public MemberFilterButtonGroup() {
_FieldFilter = CreateButton(KnownImageIds.Field, "Fields and properties");
Expand Down Expand Up @@ -332,8 +342,8 @@ void ClearFilter() {
_uiLock = false;
if (Filters != MemberFilterTypes.All) {
Filters = MemberFilterTypes.All;
FilterChanged?.Invoke(this, EventArgs.Empty);
}
FilterCleared?.Invoke(this, EventArgs.Empty);
}

ThemedToggleButton CreateButton(int imageId, string toolTip) {
Expand Down

0 comments on commit 7ef967b

Please sign in to comment.