Skip to content
Permalink
Browse files

Put a new filter box above query helpers tree, for quickly finding sn…

…ippet or function
  • Loading branch information...
ansgarbecker committed Apr 7, 2019
1 parent 2db3fff commit e56371e9a8740b3b8c816e8703d3ae480056f443
Showing with 157 additions and 57 deletions.
  1. +72 −47 source/main.dfm
  2. +85 −10 source/main.pas
@@ -298,7 +298,7 @@ object MainForm: TMainForm
OnExit = editDatabaseTableFilterExit
OnKeyPress = editDatabaseTableFilterKeyPress
OnLeftButtonClick = editDatabaseTableFilterLeftButtonClick
OnRightButtonClick = editDatabaseTableFilterRightButtonClick
OnRightButtonClick = buttonedEditClear
end
object editTableFilter: TButtonedEdit
Left = 50
@@ -316,7 +316,7 @@ object MainForm: TMainForm
OnExit = editDatabaseTableFilterExit
OnKeyPress = editDatabaseTableFilterKeyPress
OnLeftButtonClick = editDatabaseTableFilterLeftButtonClick
OnRightButtonClick = editDatabaseTableFilterRightButtonClick
OnRightButtonClick = buttonedEditClear
end
object btnTreeFavorites: TToolButton
Left = 100
@@ -1280,7 +1280,7 @@ object MainForm: TMainForm
TabOrder = 0
OnCanResize = pnlQueryMemoCanResize
object spltQueryHelpers: TSplitter
Left = 448
Left = 454
Top = 0
Width = 4
Height = 96
@@ -1291,7 +1291,7 @@ object MainForm: TMainForm
object SynMemoQuery: TSynMemo
Left = 0
Top = 0
Width = 448
Width = 454
Height = 96
SingleLineMode = False
Align = alClient
@@ -1345,53 +1345,78 @@ object MainForm: TMainForm
ShortCut = 16460
end>
end
object treeQueryHelpers: TVirtualStringTree
Left = 452
object pnlQueryHelpers: TPanel
Left = 458
Top = 0
Width = 191
Width = 185
Height = 96
Align = alRight
Constraints.MinWidth = 10
DragMode = dmAutomatic
DragType = dtVCL
Header.AutoSizeIndex = 0
Header.Options = [hoAutoResize, hoColumnResize, hoDrag, hoShowSortGlyphs]
Images = VirtualImageListMain
IncrementalSearch = isAll
PopupMenu = popupQueryHelpers
RootNodeCount = 6
BevelOuter = bvNone
Caption = 'pnlQueryHelpers'
TabOrder = 1
TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScrollOnExpand, toAutoSort, toAutoSpanColumns, toAutoTristateTracking, toAutoDeleteMovedNodes, toAutoChangeScale]
TreeOptions.MiscOptions = [toAcceptOLEDrop, toCheckSupport, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick]
TreeOptions.PaintOptions = [toHotTrack, toShowButtons, toShowDropmark, toShowRoot, toShowTreeLines, toThemeAware, toUseBlendedImages, toUseExplorerTheme, toHideTreeLinesIfThemed]
TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toMultiSelect, toRightClickSelect]
OnBeforeCellPaint = treeQueryHelpersBeforeCellPaint
OnChecking = treeQueryHelpersChecking
OnContextPopup = treeQueryHelpersContextPopup
OnCreateEditor = treeQueryHelpersCreateEditor
OnDblClick = treeQueryHelpersDblClick
OnEditing = treeQueryHelpersEditing
OnFocusChanging = treeQueryHelpersFocusChanging
OnFreeNode = treeQueryHelpersFreeNode
OnGetText = treeQueryHelpersGetText
OnPaintText = treeQueryHelpersPaintText
OnGetImageIndex = treeQueryHelpersGetImageIndex
OnInitChildren = treeQueryHelpersInitChildren
OnInitNode = treeQueryHelpersInitNode
OnNewText = treeQueryHelpersNewText
OnNodeClick = treeQueryHelpersNodeClick
OnResize = treeQueryHelpersResize
Columns = <
item
Position = 0
Text = 'Main column'
Width = 91
end
item
Position = 1
Text = 'Attributes'
Width = 100
end>
object treeQueryHelpers: TVirtualStringTree
Left = 0
Top = 21
Width = 185
Height = 75
Align = alClient
Constraints.MinWidth = 10
DragMode = dmAutomatic
DragType = dtVCL
Header.AutoSizeIndex = 0
Header.Options = [hoAutoResize, hoColumnResize, hoDrag, hoShowSortGlyphs]
Images = VirtualImageListMain
IncrementalSearch = isAll
PopupMenu = popupQueryHelpers
RootNodeCount = 6
TabOrder = 0
TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScrollOnExpand, toAutoSort, toAutoSpanColumns, toAutoTristateTracking, toAutoDeleteMovedNodes, toAutoChangeScale]
TreeOptions.MiscOptions = [toAcceptOLEDrop, toCheckSupport, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick]
TreeOptions.PaintOptions = [toHotTrack, toShowButtons, toShowDropmark, toShowRoot, toShowTreeLines, toThemeAware, toUseBlendedImages, toUseExplorerTheme, toHideTreeLinesIfThemed]
TreeOptions.SelectionOptions = [toExtendedFocus, toFullRowSelect, toMultiSelect, toRightClickSelect]
OnBeforeCellPaint = treeQueryHelpersBeforeCellPaint
OnChecking = treeQueryHelpersChecking
OnContextPopup = treeQueryHelpersContextPopup
OnCreateEditor = treeQueryHelpersCreateEditor
OnDblClick = treeQueryHelpersDblClick
OnEditing = treeQueryHelpersEditing
OnFocusChanging = treeQueryHelpersFocusChanging
OnFreeNode = treeQueryHelpersFreeNode
OnGetText = treeQueryHelpersGetText
OnPaintText = treeQueryHelpersPaintText
OnGetImageIndex = treeQueryHelpersGetImageIndex
OnInitChildren = treeQueryHelpersInitChildren
OnInitNode = treeQueryHelpersInitNode
OnNewText = treeQueryHelpersNewText
OnNodeClick = treeQueryHelpersNodeClick
OnResize = treeQueryHelpersResize
Columns = <
item
Position = 0
Text = 'Main column'
Width = 64
end
item
Position = 1
Text = 'Attributes'
Width = 100
end>
end
object filterQueryHelpers: TButtonedEdit
Left = 0
Top = 0
Width = 185
Height = 21
Align = alTop
Images = VirtualImageListMain
LeftButton.ImageIndex = 30
LeftButton.Visible = True
RightButton.ImageIndex = 193
TabOrder = 1
TextHint = 'Filter ...'
OnChange = filterQueryHelpersChange
OnRightButtonClick = buttonedEditClear
end
end
end
object QueryGrid: TVirtualStringTree
@@ -67,6 +67,7 @@ TQueryTab = class(TComponent)
CloseButton: TSpeedButton;
pnlMemo: TPanel;
pnlHelpers: TPanel;
filterHelpers: TButtonedEdit;
treeHelpers: TVirtualStringTree;
MemoFileRenamed: Boolean;
MemoLineBreaks: TLineBreaks;
@@ -536,7 +537,6 @@ TMainForm = class(TForm)
actDataSaveBlobToFile: TAction;
SaveBLOBtofile1: TMenuItem;
DataUNIXtimestamp: TMenuItem;
treeQueryHelpers: TVirtualStringTree;
popupExecuteQuery: TPopupMenu;
Run1: TMenuItem;
RunSelection1: TMenuItem;
@@ -637,6 +637,9 @@ TMainForm = class(TForm)
ImageCollectionIcons8: TImageCollection;
VirtualImageListMain: TVirtualImageList;
ImageCollectionSilk: TImageCollection;
pnlQueryHelpers: TPanel;
treeQueryHelpers: TVirtualStringTree;
filterQueryHelpers: TButtonedEdit;
procedure actCreateDBObjectExecute(Sender: TObject);
procedure menuConnectionsPopup(Sender: TObject);
procedure actExitApplicationExecute(Sender: TObject);
@@ -991,7 +994,7 @@ TMainForm = class(TForm)
procedure actNextResultExecute(Sender: TObject);
procedure actSaveSynMemoToTextfileExecute(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
procedure editDatabaseTableFilterRightButtonClick(Sender: TObject);
procedure buttonedEditClear(Sender: TObject);
procedure menuDoubleClickInsertsNodeTextClick(Sender: TObject);
procedure DBtreeDblClick(Sender: TObject);
procedure editDatabaseTableFilterKeyPress(Sender: TObject; var Key: Char);
@@ -1002,6 +1005,7 @@ TMainForm = class(TForm)
procedure SynMemoQueryMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure SynMemoQueryKeyPress(Sender: TObject; var Key: Char);
procedure filterQueryHelpersChange(Sender: TObject);
private
// Executable file details
FAppVerMajor: Integer;
@@ -1536,7 +1540,7 @@ procedure TMainForm.FormDestroy(Sender: TObject);
AppSettings.WriteBool(asDisplayBLOBsAsText, actBlobAsText.Checked);
AppSettings.WriteString(asDelimiter, FDelimiter);
AppSettings.WriteInt(asQuerymemoheight, pnlQueryMemo.Height);
AppSettings.WriteInt(asQueryhelperswidth, treeQueryHelpers.Width);
AppSettings.WriteInt(asQueryhelperswidth, pnlQueryHelpers.Width);
AppSettings.WriteInt(asCompletionProposalWidth, SynCompletionProposal.Width);
AppSettings.WriteInt(asCompletionProposalNbLinesInWindow, SynCompletionProposal.NbLinesInWindow);
AppSettings.WriteInt(asDbtreewidth, pnlLeft.width);
@@ -1823,7 +1827,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
actPreferencesData.OnExecute := actPreferences.OnExecute;

pnlQueryMemo.Height := AppSettings.ReadInt(asQuerymemoheight);
treeQueryHelpers.Width := AppSettings.ReadInt(asQueryhelperswidth);
pnlQueryHelpers.Width := AppSettings.ReadInt(asQueryhelperswidth);
pnlLeft.Width := AppSettings.ReadInt(asDbtreewidth);
pnlPreview.Height := AppSettings.ReadInt(asDataPreviewHeight);
if AppSettings.ReadBool(asDataPreviewEnabled) then
@@ -6887,6 +6891,59 @@ procedure TMainForm.btnDataClick(Sender: TObject);
end;


procedure TMainForm.filterQueryHelpersChange(Sender: TObject);
var
rx: TRegExpr;
Node: PVirtualNode;
VT: TVirtualStringTree;
i: Integer;
match: Boolean;
CellText: String;
Edit: TButtonedEdit;
begin
// Filter nodes in query helpers
// Loop through all nodes and hide non matching
VT := ActiveQueryHelpers;
Edit := Sender as TButtonedEdit;
Node := VT.GetFirst;
rx := TRegExpr.Create;
rx.ModifierI := True;
rx.Expression := Edit.Text;
try
rx.Exec('abc');
except
on E:ERegExpr do begin
if rx.Expression <> '' then begin
LogSQL('Filter text is not a valid regular expression: "'+rx.Expression+'"', lcError);
rx.Expression := '';
end;
end;
end;

VT.BeginUpdate;
while Assigned(Node) do begin
if (not VT.HasChildren[Node]) and (VT.GetNodeLevel(Node) > 0) then begin
// Don't filter anything if the filter text is empty
match := rx.Expression = '';
// Search for given text in node's captions
if not match then for i := 0 to VT.Header.Columns.Count - 1 do begin
CellText := VT.Text[Node, i];
match := rx.Exec(CellText);
if match then
break;
end;
VT.IsVisible[Node] := match;
end;
Node := VT.GetNext(Node);
end;
VT.EndUpdate;
VT.Invalidate;
rx.Free;

Edit.RightButton.Visible := IsNotEmpty(Edit.Text);
end;


procedure TMainForm.tabsetQueryMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
idx, i: Integer;
@@ -9483,7 +9540,7 @@ procedure TMainForm.pnlQueryMemoCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
// Ensure visibility of query memo while resizing
Resize := NewWidth >= treeQueryHelpers.Width + spltQueryHelpers.Width + 40;
Resize := NewWidth >= pnlQueryHelpers.Width + spltQueryHelpers.Width + 40;
end;


@@ -10303,11 +10360,29 @@ procedure TMainForm.actNewQueryTabExecute(Sender: TObject);
QueryTab.spltHelpers.ResizeStyle := spltQueryHelpers.ResizeStyle;
QueryTab.spltHelpers.Width := spltQueryHelpers.Width;

QueryTab.treeHelpers := TVirtualStringTree.Create(QueryTab.pnlMemo);
QueryTab.treeHelpers.Parent := QueryTab.pnlMemo;
QueryTab.pnlHelpers := TPanel.Create(QueryTab.pnlMemo);
QueryTab.pnlHelpers.Parent := QueryTab.pnlMemo;
QueryTab.pnlHelpers.Align := pnlQueryHelpers.Align;
QueryTab.pnlHelpers.BevelOuter := pnlQueryHelpers.BevelOuter;
QueryTab.pnlHelpers.Left := pnlQueryHelpers.Left;
QueryTab.pnlHelpers.Width := pnlQueryHelpers.Width;

QueryTab.filterHelpers := TButtonedEdit.Create(QueryTab.pnlHelpers);
QueryTab.filterHelpers.Parent := QueryTab.pnlHelpers;
QueryTab.filterHelpers.Align := filterQueryHelpers.Align;
QueryTab.filterHelpers.TextHint := filterQueryHelpers.TextHint;
QueryTab.filterHelpers.Images := filterQueryHelpers.Images;
QueryTab.filterHelpers.LeftButton.Visible := filterQueryHelpers.LeftButton.Visible;
QueryTab.filterHelpers.LeftButton.ImageIndex := filterQueryHelpers.LeftButton.ImageIndex;
QueryTab.filterHelpers.RightButton.Visible := filterQueryHelpers.RightButton.Visible;
QueryTab.filterHelpers.RightButton.ImageIndex := filterQueryHelpers.RightButton.ImageIndex;
QueryTab.filterHelpers.OnChange := filterQueryHelpers.OnChange;
QueryTab.filterHelpers.OnRightButtonClick := filterQueryHelpers.OnRightButtonClick;

QueryTab.treeHelpers := TVirtualStringTree.Create(QueryTab.pnlHelpers);
QueryTab.treeHelpers.Parent := QueryTab.pnlHelpers;
QueryTab.treeHelpers.Align := treeQueryHelpers.Align;
QueryTab.treeHelpers.Left := treeQueryHelpers.Left;
QueryTab.treeHelpers.Width := treeQueryHelpers.Width;
QueryTab.treeHelpers.Constraints.MinWidth := treeQueryHelpers.Constraints.MinWidth;
QueryTab.treeHelpers.PopupMenu := treeQueryHelpers.PopupMenu;
QueryTab.treeHelpers.Images := treeQueryHelpers.Images;
@@ -10461,9 +10536,9 @@ procedure TMainForm.actFavoriteObjectsOnlyExecute(Sender: TObject);
end;


procedure TMainForm.editDatabaseTableFilterRightButtonClick(Sender: TObject);
procedure TMainForm.buttonedEditClear(Sender: TObject);
begin
// Click on right button of database/table filter
// Click on "clear" button of any TButtonedEdit control
TButtonedEdit(Sender).Clear;
end;

0 comments on commit e56371e

Please sign in to comment.
You can’t perform that action at this time.