Permalink
Browse files

Expect regular expression in filter text on right panel, not a simple…

… string. Keep searching case insensitive, as in prior logic. Add text hint to filter box so the user knows he can enter a regular expression here. Closes #45.
  • Loading branch information...
ansgarbecker committed Dec 16, 2017
1 parent 4101350 commit e8ed608a566a6e0a697b461e9201f01f87d2989b
Showing with 31 additions and 12 deletions.
  1. +1 −0 source/main.dfm
  2. +30 −12 source/main.pas
View
@@ -374,6 +374,7 @@ object MainForm: TMainForm
RightButton.ImageIndex = 26
RightButton.Visible = True
TabOrder = 0
TextHint = 'Regular expression'
OnChange = editFilterVTChange
OnRightButtonClick = editFilterVTRightButtonClick
end
View
@@ -7396,10 +7396,12 @@ procedure TMainForm.ApplyVTFilter(FromTimer: Boolean);
VT: TVirtualStringTree;
i: Integer;
match: Boolean;
search: String;
tab: TTabSheet;
VisibleCount: Cardinal;
CellText: String;
rx: TRegExpr;
OldDataLocalNumberFormat: Boolean;
OldImageIndex: Integer;
begin
// Find the correct VirtualTree that shall be filtered
tab := PageControlMain.ActivePage;
@@ -7439,30 +7441,43 @@ procedure TMainForm.ApplyVTFilter(FromTimer: Boolean);
Exit;
// Loop through all nodes and hide non matching
Node := VT.GetFirst;
search := LowerCase( editFilterVT.Text );
rx := TRegExpr.Create;
rx.ModifierI := True;
rx.Expression := editFilterVT.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;
VisibleCount := 0;
OldDataLocalNumberFormat := DataLocalNumberFormat;
DataLocalNumberFormat := False;
// Display hour glass instead of X icon
OldImageIndex := editFilterVT.RightButton.ImageIndex;
editFilterVT.RightButton.ImageIndex := 150;
editFilterVT.Repaint;
while Assigned(Node) do begin
// Don't filter anything if the filter text is empty
match := search = '';
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];
if Pos( search, LowerCase(CellText)) > 0 then begin
match := True;
break;
end;
// Search for unformatted numbers. Only if text to find is a number, to reduce CPU load for other cases.
if IsNumeric(search) then if Pos(search, UnformatNumber(CellText)) > 0 then begin
match := True;
match := rx.Exec(CellText);
if match then
break;
end;
end;
VT.IsVisible[Node] := match;
if match then
inc(VisibleCount);
Node := VT.GetNext(Node);
end;
if search <> '' then begin
if rx.Expression <> '' then begin
lblFilterVTInfo.Caption := IntToStr(VisibleCount)+' out of '+IntToStr(VT.RootNodeCount)+' matching. '
+ IntToStr(VT.RootNodeCount - VisibleCount) + ' hidden.';
end else
@@ -7472,6 +7487,9 @@ procedure TMainForm.ApplyVTFilter(FromTimer: Boolean);
VT.Invalidate
else
InvalidateVT(VT, VTREE_LOADED, true);
DataLocalNumberFormat := OldDataLocalNumberFormat;
editFilterVT.RightButton.ImageIndex := OldImageIndex;
rx.Free;
end;

0 comments on commit e8ed608

Please sign in to comment.