Restore Library search functionality
- Reuse new CreateSmallResetButton helper
This commit is contained in:
parent
e8dca6d34e
commit
0a3042dd45
1 changed files with 87 additions and 31 deletions
|
|
@ -99,37 +99,6 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
|
||||
// Create search panel
|
||||
{
|
||||
var searchPanel = new FlowLayoutWidget()
|
||||
{
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
Padding = new BorderDouble(10, 0),
|
||||
};
|
||||
|
||||
searchInput = new MHTextEditWidget(messageWhenEmptyAndNotSelected: "Search Library".Localize())
|
||||
{
|
||||
Name = "Search Library Edit",
|
||||
Margin = new BorderDouble(0, 3, 0, 0),
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
VAnchor = VAnchor.ParentCenter
|
||||
};
|
||||
searchInput.ActualTextEditWidget.EnterPressed += (s, e) => PerformSearch();
|
||||
searchPanel.AddChild(searchInput);
|
||||
|
||||
// TODO: We should describe the intent of setting to zero and immediately restoring to the original value. Not clear, looks pointless
|
||||
double oldWidth = editButtonFactory.FixedWidth;
|
||||
editButtonFactory.FixedWidth = 0;
|
||||
|
||||
Button searchButton = editButtonFactory.Generate("Search".Localize(), centerText: true);
|
||||
searchButton.Name = "Search Library Button";
|
||||
searchButton.Click += (s, e) => PerformSearch();
|
||||
editButtonFactory.FixedWidth = oldWidth;
|
||||
searchPanel.AddChild(searchButton);
|
||||
|
||||
allControls.AddChild(searchPanel);
|
||||
}
|
||||
|
||||
libraryView = new ListView(ApplicationController.Instance.Library)
|
||||
{
|
||||
BackgroundColor = ActiveTheme.Instance.TertiaryBackgroundColor
|
||||
|
|
@ -148,6 +117,55 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
breadCrumbWidget = new FolderBreadCrumbWidget(libraryView);
|
||||
breadCrumbBar.AddChild(breadCrumbWidget);
|
||||
|
||||
var icon = StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16);
|
||||
|
||||
var buttonFactory = ApplicationController.Instance.Theme.BreadCrumbButtonFactory;
|
||||
var initialMargin = buttonFactory.Margin;
|
||||
buttonFactory.Margin = new BorderDouble(8, 0);
|
||||
|
||||
var searchPanel = new SearchInputBox()
|
||||
{
|
||||
Visible = false,
|
||||
Margin = new BorderDouble(10, 0, 5, 0)
|
||||
};
|
||||
searchPanel.searchInput.ActualTextEditWidget.EnterPressed += (s, e) =>
|
||||
{
|
||||
this.PerformSearch();
|
||||
};
|
||||
searchPanel.resetButton.Click += (s, e) =>
|
||||
{
|
||||
breadCrumbWidget.Visible = true;
|
||||
searchPanel.Visible = false;
|
||||
|
||||
searchPanel.searchInput.Text = "";
|
||||
|
||||
this.ClearSearch();
|
||||
};
|
||||
|
||||
// Store a reference to the input field
|
||||
this.searchInput = searchPanel.searchInput;
|
||||
|
||||
breadCrumbBar.AddChild(searchPanel);
|
||||
|
||||
Button searchButton = buttonFactory.Generate("", icon);
|
||||
searchButton.ToolTipText = "Search".Localize();
|
||||
searchButton.Name = "Search Library Button";
|
||||
searchButton.Margin = 0;
|
||||
searchButton.Click += (s, e) =>
|
||||
{
|
||||
if (searchPanel.Visible)
|
||||
{
|
||||
PerformSearch();
|
||||
}
|
||||
else
|
||||
{
|
||||
breadCrumbWidget.Visible = false;
|
||||
searchPanel.Visible = true;
|
||||
}
|
||||
};
|
||||
buttonFactory.Margin = initialMargin;
|
||||
breadCrumbBar.AddChild(searchButton);
|
||||
|
||||
overflowDropdown = new OverflowDropdown(allowLightnessInvert: true)
|
||||
{
|
||||
AlignToRightEdge = true,
|
||||
|
|
@ -697,6 +715,15 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
});
|
||||
}
|
||||
|
||||
private void ClearSearch()
|
||||
{
|
||||
UiThread.RunOnIdle(() =>
|
||||
{
|
||||
libraryView.ActiveContainer.KeywordFilter = "";
|
||||
breadCrumbWidget.SetBreadCrumbs(libraryView.ActiveContainer);
|
||||
});
|
||||
}
|
||||
|
||||
private async void addToQueueButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var selectedItems = libraryView.SelectedItems.Select(o => o.Model);
|
||||
|
|
@ -929,5 +956,34 @@ namespace MatterHackers.MatterControl.PrintLibrary
|
|||
|
||||
base.OnLoad(args);
|
||||
}
|
||||
|
||||
private class SearchInputBox : GuiWidget
|
||||
{
|
||||
internal MHTextEditWidget searchInput;
|
||||
internal Button resetButton;
|
||||
|
||||
public SearchInputBox()
|
||||
{
|
||||
this.VAnchor = VAnchor.ParentCenter | VAnchor.FitToChildren;
|
||||
this.HAnchor = HAnchor.ParentLeftRight;
|
||||
|
||||
searchInput = new MHTextEditWidget(messageWhenEmptyAndNotSelected: "Search Library".Localize())
|
||||
{
|
||||
Name = "Search Library Edit",
|
||||
HAnchor = HAnchor.ParentLeftRight,
|
||||
VAnchor = VAnchor.ParentCenter
|
||||
};
|
||||
this.AddChild(searchInput);
|
||||
|
||||
resetButton = ApplicationController.Instance.Theme.CreateSmallResetButton();
|
||||
resetButton.HAnchor = HAnchor.ParentRight | HAnchor.FitToChildren;
|
||||
resetButton.VAnchor = VAnchor.ParentCenter | VAnchor.FitToChildren;
|
||||
resetButton.Name = "Close Search";
|
||||
resetButton.ToolTipText = "Clear".Localize();
|
||||
|
||||
this.AddChild(resetButton);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue