Skip to content

Commit

Permalink
Inspector: Fix event filter checkboxes on WPF and fix logic
Browse files Browse the repository at this point in the history
Works around an Eto issue with missing events:
picoe/Eto#1981
  • Loading branch information
Sejsel committed Jul 9, 2021
1 parent 8fe1aeb commit 52e56b1
Showing 1 changed file with 56 additions and 28 deletions.
84 changes: 56 additions & 28 deletions EVTCInspector/EventListControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class TypeFilterItem : TreeGridItem
public Type Type { get; }

private bool? shown;
private int settingRecursionLevel = 0;

public bool? Checked
{
Expand All @@ -29,19 +30,21 @@ public class TypeFilterItem : TreeGridItem
foreach (var item in Children)
{
var child = (TypeFilterItem) item;
child.settingRecursionLevel += 1;
child.Checked = shown.Value;
child.settingRecursionLevel -= 1;
}
}

if (Parent != null)
{
var parent = (TypeFilterItem) Parent;
bool? newValue;
if (parent.Children.All(x => ((TypeFilterItem) x.Parent).Checked == true))
if (parent.Children.All(x => ((TypeFilterItem) x).Checked == true))
{
newValue = true;
}
else if (parent.Children.All(x => ((TypeFilterItem) x.Parent).Checked == false))
else if (parent.Children.All(x => ((TypeFilterItem) x).Checked == false))
{
newValue = false;
}
Expand All @@ -50,11 +53,23 @@ public class TypeFilterItem : TreeGridItem
newValue = null;
}

parent.Checked = newValue;
if (newValue != null)
{
parent.settingRecursionLevel += 1;
parent.Checked = newValue;
parent.settingRecursionLevel -= 1;
}
}

if (settingRecursionLevel == 0)
{
UsedDirectly?.Invoke(this, EventArgs.Empty);
}
}
}

public event EventHandler<EventArgs> UsedDirectly;

private int count = -1;

public new int Count
Expand Down Expand Up @@ -115,22 +130,18 @@ public ICollection<Agent> Agents
private readonly GridView<Event> eventGridView;
private readonly TreeGridView typeFilterTree;
private readonly JsonSerializationControl eventJsonControl = new JsonSerializationControl();
private readonly TabControl tabs = new TabControl();
private readonly TabPage filterPage;
private readonly TabPage eventDataPage;

public EventListControl()
{
eventGridView = new GridView<Event>();
eventGridView.Columns.Add(new GridColumn()
{
HeaderText = "Time",
DataCell = new TextBoxCell("Time")
});
eventGridView.Columns.Add(new GridColumn() {HeaderText = "Time", DataCell = new TextBoxCell("Time")});
eventGridView.Columns.Add(new GridColumn()
{
HeaderText = "Event Type",
DataCell = new TextBoxCell()
{
Binding = new DelegateBinding<object, string>(x => x.GetType().Name)
}
DataCell = new TextBoxCell() {Binding = new DelegateBinding<object, string>(x => x.GetType().Name)}
});
eventGridView.SelectionChanged += (sender, args) => eventJsonControl.Object = eventGridView.SelectedItem;
eventGridView.Width = 250;
Expand All @@ -152,7 +163,9 @@ public EventListControl()
typeFilterTree.Columns.Add(new GridColumn()
{
DataCell = new TextBoxCell()
{Binding = Binding.Property<TypeFilterItem, string>(x => x.Count.ToString())},
{
Binding = Binding.Property<TypeFilterItem, string>(x => x.Count.ToString())
},
HeaderText = "Event Count",
Editable = false
});
Expand All @@ -174,24 +187,11 @@ public EventListControl()
filterTabs.Pages.Add(new TabPage {Text = "By Event Type", Content = typeFilterTree});
filterTabs.Pages.Add(new TabPage {Text = "By Content", Content = filterLayout});

var tabs = new TabControl();
var filterPage = new TabPage {Text = "Filters", Content = filterTabs};
var eventDataPage = new TabPage {Text = "Event data", Content = eventJsonControl};
filterPage = new TabPage {Text = "Filters", Content = filterTabs};
eventDataPage = new TabPage {Text = "Event data", Content = eventJsonControl};
tabs.Pages.Add(filterPage);
tabs.Pages.Add(eventDataPage);

typeFilterTree.CellEdited += (sender, args) =>
{
typeFilterTree.Invalidate();
// HACK: Invalidate doesn't redraw the tree on the Gtk3 platform
// TODO: Disable on other platforms if not necessary, may look significantly worse there
tabs.SelectedPage = eventDataPage;
tabs.SelectedPage = filterPage;
ApplyFilters();
};

var eventsSplitter = new Splitter {Panel1 = eventGridView, Panel2 = tabs, Position = 300};
Content = eventsSplitter;
}
Expand Down Expand Up @@ -281,6 +281,34 @@ private void UpdateFilterView()
}

typeFilterTree.DataStore = rootItem;
AddDirectUseHandlerRecursively(rootItem);

void AddDirectUseHandlerRecursively(TypeFilterItem item)
{
item.UsedDirectly += (sender, args) =>
{
InvalidateTree();
ApplyFilters();
};
foreach (var child in item.Children)
{
if (child is TypeFilterItem filterChild)
{
AddDirectUseHandlerRecursively(filterChild);
}
}
}
}

private void InvalidateTree()
{
typeFilterTree.Invalidate();
// HACK: Invalidate doesn't redraw the tree on the Gtk3 platform
// issue: https://github.com/picoe/Eto/issues/1982
// TODO: Disable on other platforms if not necessary, may look significantly worse there

tabs.SelectedPage = eventDataPage;
tabs.SelectedPage = filterPage;
}

private void ApplyFilters()
Expand Down

0 comments on commit 52e56b1

Please sign in to comment.