fix #439 - Better shortcut filter

This commit is contained in:
Basile Burg 2019-02-03 17:58:41 +01:00
parent 3affeca88f
commit 41881be499
2 changed files with 16 additions and 19 deletions

View File

@ -25,7 +25,6 @@ object ShortcutEditor: TShortcutEditor
Height = 27 Height = 27
Top = 2 Top = 2
Width = 420 Width = 420
OnFilterItem = fltItemsFilterItem
ButtonWidth = 28 ButtonWidth = 28
Align = alTop Align = alTop
BorderSpacing.Around = 2 BorderSpacing.Around = 2
@ -33,6 +32,7 @@ object ShortcutEditor: TShortcutEditor
MaxLength = 0 MaxLength = 0
TabOrder = 0 TabOrder = 0
FilteredTreeview = tree FilteredTreeview = tree
OnFilterNode = fltItemsFilterNode
end end
object tree: TTreeView object tree: TTreeView
Left = 2 Left = 2

View File

@ -65,7 +65,7 @@ type
tree: TTreeView; tree: TTreeView;
procedure btnClearClick(Sender: TObject); procedure btnClearClick(Sender: TObject);
procedure btnEditClick(Sender: TObject); procedure btnEditClick(Sender: TObject);
function fltItemsFilterItem(Item: TObject; out Done: Boolean): Boolean; function fltItemsFilterNode(ItemNode: TTreeNode; out Done: Boolean): Boolean;
procedure shortcutCatcherExit(Sender: TObject); procedure shortcutCatcherExit(Sender: TObject);
procedure shortcutCatcherMouseLeave(Sender: TObject); procedure shortcutCatcherMouseLeave(Sender: TObject);
procedure propeditModified(Sender: TObject); procedure propeditModified(Sender: TObject);
@ -377,26 +377,23 @@ begin
propedit.Rows[0].Editor.Edit; propedit.Rows[0].Editor.Edit;
end; end;
function TShortcutEditor.fltItemsFilterItem(Item: TObject; out Done: Boolean): Boolean; function TShortcutEditor.fltItemsFilterNode(ItemNode: TTreeNode; out Done: Boolean): Boolean;
var var
shc: TShortcutItem; s: TShortcutItem;
b: boolean;
begin begin
if fltItems.Filter.isBlank then if fltItems.Filter.isBlank then
begin exit(true);
result := true;
done := true; // keep categories
end if ItemNode.Parent.isNil then
else exit(true);
begin
result := false; b := AnsiContainsText(ItemNode.Text, fltItems.Filter);
done := false; if ItemNode.Data.isNil then
// see TTreeFilterEdit: they pass TObject(TTreeNode.Data) and not a TTreeNode exit(b);
if Pointer(item).isNil then s := TShortcutItem(ItemNode.Data);
exit; result := AnsiContainsText(s.combination, fltItems.Filter) or b;
shc := TShortcutItem(item);
result := AnsiContainsText(shc.combination, fltItems.Filter);
done := true;
end;
end; end;
procedure TShortcutEditor.updateEditCtrls; procedure TShortcutEditor.updateEditCtrls;