Skip to content

Commit

Permalink
Merge pull request #177 from akaadream/akadream
Browse files Browse the repository at this point in the history
Text search and search item hierarchy
  • Loading branch information
vchelaru authored Aug 22, 2024
2 parents 1e663c4 + cbfd09f commit 3018489
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 12 deletions.
106 changes: 95 additions & 11 deletions Gum/Plugins/InternalPlugins/TreeView/ElementTreeViewManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
using Gum.Mvvm;
using Gum.Plugins.InternalPlugins.TreeView;
using Gum.Plugins.InternalPlugins.TreeView.ViewModels;
using RenderingLibrary.Graphics;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
using System.Management.Instrumentation;

namespace Gum.Managers
{
Expand Down Expand Up @@ -110,6 +113,7 @@ public partial class ElementTreeViewManager
object mRecordedSelectedObject;

TextBox searchTextBox;
CheckBox deepSearchCheckBox;
#endregion

#region Properties
Expand Down Expand Up @@ -406,6 +410,9 @@ public void Initialize(IContainer components, ImageList ElementTreeImages,
grid.RowDefinitions.Add(
new System.Windows.Controls.RowDefinition()
{ Height = new System.Windows.GridLength(22, System.Windows.GridUnitType.Pixel) });
grid.RowDefinitions.Add(
new System.Windows.Controls.RowDefinition()
{ Height = new System.Windows.GridLength(22, System.Windows.GridUnitType.Pixel) });
grid.RowDefinitions.Add(
new System.Windows.Controls.RowDefinition()
{ Height = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star) });
Expand All @@ -416,7 +423,7 @@ public void Initialize(IContainer components, ImageList ElementTreeImages,
//panel.Controls.Add(ObjectTreeView);
TreeViewHost = new System.Windows.Forms.Integration.WindowsFormsHost();
TreeViewHost.Child = ObjectTreeView;
Grid.SetRow(TreeViewHost, 1);
Grid.SetRow(TreeViewHost, 2);
grid.Children.Add(TreeViewHost);


Expand All @@ -426,11 +433,17 @@ public void Initialize(IContainer components, ImageList ElementTreeImages,
Grid.SetRow(searchBarHost, 0);
grid.Children.Add(searchBarHost);

var checkBoxUi = CreateSearchCheckBoxUi();
var checkBoxHost = new System.Windows.Forms.Integration.WindowsFormsHost();
checkBoxHost.Child = checkBoxUi;
Grid.SetRow(checkBoxHost, 1);
grid.Children.Add(checkBoxHost);

FlatList = CreateFlatSearchList();
FlatList.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
FlatList.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

Grid.SetRow(FlatList, 1);
Grid.SetRow(FlatList, 2);
grid.Children.Add(FlatList);


Expand Down Expand Up @@ -1509,27 +1522,64 @@ private void ReactToFilterTextChanged()
{
if (screen.Name.ToLower().Contains(filterTextLower))
{
var vm = new SearchItemViewModel();
vm.BackingObject = screen;
FlatList.FlatList.Items.Add(vm);
AddToFlatList(screen);
}

if (deepSearchCheckBox.Checked)
{
foreach (var state in screen.States)
{
foreach (var variable in state.Variables)
{
if (variable == null)
{
continue;
}

if (variable.Value != null && (variable.Value is string str) && str.ToLower().Contains(filterTextLower))
{
var instance = screen.Instances.FirstOrDefault(item => item.Name == variable.SourceObject);
AddToFlatList(instance, $"{screen.Name}/{variable.SourceObject} ({variable.GetRootName()})");
}
}
}
}
}
foreach (var component in project.Components)
{
if (component.Name.ToLower().Contains(filterTextLower))
{
var vm = new SearchItemViewModel();
vm.BackingObject = component;
FlatList.FlatList.Items.Add(vm);
AddToFlatList(component);
}

foreach (var instance in component.Instances)
{
if (instance.Name.ToLower().Contains(filterTextLower))
{
AddToFlatList(instance, $"{component.Name}/{instance.Name} ({instance.BaseType})");
}
}

if (deepSearchCheckBox.Checked)
{
var textVariable = component.GetVariableFromThisOrBase("Text");

if (textVariable == null)
{
continue;
}

if (textVariable.Value != null && (textVariable.Value as string).ToLower().Contains(filterTextLower))
{
AddToFlatList(component);
}
}
}
foreach (var standard in project.StandardElements)
{
if (standard.Name.ToLower().Contains(filterTextLower))
{
var vm = new SearchItemViewModel();
vm.BackingObject = standard;
FlatList.FlatList.Items.Add(vm);
AddToFlatList(standard);
}
}

Expand Down Expand Up @@ -1562,6 +1612,18 @@ private void ReactToFilterTextChanged()
//}
}

private void AddToFlatList(object element, string customName = "")
{
if (element == null)
{
throw new ArgumentNullException($"{nameof(element)}");
}
var vm = new SearchItemViewModel();
vm.BackingObject = element;
vm.CustomText = customName;
FlatList.FlatList.Items.Add(vm);
}

private Control CreateSearchBoxUi()
{
var panel = new Panel();
Expand Down Expand Up @@ -1627,6 +1689,24 @@ private Control CreateSearchBoxUi()
xButton.Width = 24;
panel.Controls.Add(xButton);
panel.Height = 20;

return panel;
}

private Control CreateSearchCheckBoxUi()
{
var panel = new Panel();

deepSearchCheckBox = new CheckBox();
deepSearchCheckBox.Checked = false;
deepSearchCheckBox.Text = "Search instance properties";
deepSearchCheckBox.CheckedChanged += (object sender, EventArgs args) =>
{
ReactToFilterTextChanged();
};

panel.Controls.Add(deepSearchCheckBox);

return panel;
}

Expand All @@ -1641,6 +1721,10 @@ private void HandleSelectedSearchNode(SearchItemViewModel vm)
GumState.Self.SelectedState.SelectedElement = asComponent;
else if (backingObject is StandardElementSave asStandard)
GumState.Self.SelectedState.SelectedElement = asStandard;
else if (backingObject is InstanceSave asInstance)
GumState.Self.SelectedState.SelectedInstance = asInstance;
else if (backingObject is VariableSave asVariable)
GumState.Self.SelectedState.SelectedBehaviorVariable = asVariable;

searchTextBox.Text = null;
FilterText = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ BitmapImage LoadIcon(string iconName)

public object BackingObject { get; set; }

public string Display => BackingObject?.ToString();
public string CustomText { get; set; }

public string Display => !string.IsNullOrWhiteSpace(CustomText) ? CustomText : BackingObject?.ToString();

public BitmapImage Image =>
BackingObject is ScreenSave ? ScreenIcon
Expand Down

0 comments on commit 3018489

Please sign in to comment.