Skip to content

Commit

Permalink
jsonV basic search
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnsanders committed Dec 17, 2019
1 parent db20a78 commit c8ee27a
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017 Stijn Sanders
Copyright (c) 2015-2019 Stijn Sanders

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions jsonV.dof
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Conditionals=JSONDOC_P2
DebugSourceDirs=
UsePackages=0
[Parameters]
RunParams=D:\Data\2019\feeder\eater\xmls\0163.json
RunParams=D:\Data\2019\feeder\eater\xmls\0218.json
HostApplication=
Launcher=
UseLauncher=0
Expand All @@ -111,7 +111,7 @@ AutoIncBuild=0
MajorVer=1
MinorVer=2
Release=1
Build=600
Build=614
Debug=0
PreRelease=0
Special=0
Expand All @@ -122,7 +122,7 @@ CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=jsonV
FileVersion=1.2.1.600
FileVersion=1.2.1.614
InternalName=
LegalCopyright=
LegalTrademarks=
Expand Down
Binary file modified jsonV.res
Binary file not shown.
63 changes: 62 additions & 1 deletion jsonV1.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object frmJsonViewer: TfrmJsonViewer
Left = 0
Top = 0
Width = 1072
Height = 524
Height = 488
Align = alClient
HideSelection = False
Indent = 19
Expand All @@ -30,6 +30,49 @@ object frmJsonViewer: TfrmJsonViewer
OnDblClick = TreeView1DblClick
OnExpanding = TreeView1Expanding
end
object panSearch: TPanel
Left = 0
Top = 488
Width = 1072
Height = 36
Align = alBottom
BevelOuter = bvNone
TabOrder = 1
Visible = False
object Label1: TLabel
Left = 8
Top = 7
Width = 29
Height = 16
Caption = '&Find:'
end
object txtFind: TEdit
Left = 40
Top = 4
Width = 249
Height = 25
TabOrder = 0
OnKeyPress = txtFindKeyPress
end
object btnFindPrev: TButton
Left = 292
Top = 4
Width = 25
Height = 25
Caption = '<'
TabOrder = 1
OnClick = actSearchPrevExecute
end
object btnFindNext: TButton
Left = 320
Top = 4
Width = 25
Height = 25
Caption = '>'
TabOrder = 2
OnClick = actSearchNextExecute
end
end
object ActionList1: TActionList
Left = 8
Top = 8
Expand All @@ -48,5 +91,23 @@ object frmJsonViewer: TfrmJsonViewer
ShortCut = 24643
OnExecute = EditCopyValue1Execute
end
object actFind: TAction
Category = 'Search'
Caption = 'Find...'
ShortCut = 16454
OnExecute = actFindExecute
end
object actSearchPrev: TAction
Category = 'Search'
Caption = 'Search Previous'
ShortCut = 8306
OnExecute = actSearchPrevExecute
end
object actSearchNext: TAction
Category = 'Search'
Caption = 'Search Next'
ShortCut = 114
OnExecute = actSearchNextExecute
end
end
end
102 changes: 101 additions & 1 deletion jsonV1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ActnList, jsonDoc, StdActns;
Dialogs, ComCtrls, ActnList, jsonDoc, StdActns, StdCtrls, ExtCtrls;

type
TfrmJsonViewer = class(TForm)
ActionList1: TActionList;
TreeView1: TTreeView;
EditCopy1: TEditCopy;
EditCopyValue1: TAction;
panSearch: TPanel;
Label1: TLabel;
txtFind: TEdit;
btnFindPrev: TButton;
btnFindNext: TButton;
actFind: TAction;
actSearchPrev: TAction;
actSearchNext: TAction;
procedure TreeView1CreateNodeClass(Sender: TCustomTreeView;
var NodeClass: TTreeNodeClass);
procedure TreeView1Expanding(Sender: TObject; Node: TTreeNode;
Expand All @@ -20,10 +28,15 @@ TfrmJsonViewer = class(TForm)
procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
procedure TreeView1DblClick(Sender: TObject);
procedure EditCopyValue1Execute(Sender: TObject);
procedure actFindExecute(Sender: TObject);
procedure txtFindKeyPress(Sender: TObject; var Key: Char);
procedure actSearchPrevExecute(Sender: TObject);
procedure actSearchNextExecute(Sender: TObject);
private
function LoadJSON(const FilePath: string): IJSONDocument;
procedure ExpandJSON(Parent: TTreeNode; Data: IJSONDocument);
procedure ExpandString(Parent: TTreeNode; const Data: string);
procedure SearchNode(Sender: TObject; Down: boolean);
protected
procedure DoShow; override;
end;
Expand Down Expand Up @@ -479,4 +492,91 @@ procedure TfrmJsonViewer.TreeView1DblClick(Sender: TObject);
end;
end;

procedure TfrmJsonViewer.actFindExecute(Sender: TObject);
begin
panSearch.Visible:=true;
txtFind.SelectAll;
txtFind.SetFocus;
end;

procedure TfrmJsonViewer.txtFindKeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
begin
btnFindNext.Click;
Key:=#0;
end;
end;

procedure TfrmJsonViewer.actSearchPrevExecute(Sender: TObject);
begin
SearchNode(Sender,false);
end;

procedure TfrmJsonViewer.actSearchNextExecute(Sender: TObject);
begin
SearchNode(Sender,true);
end;

procedure TfrmJsonViewer.SearchNode(Sender:TObject;Down:boolean);
var
n,n1:TTreeNode;
f:string;
b:boolean;

procedure MoveOne;
begin
if Down then
begin
if n<>nil then
begin
b:=true;
TreeView1Expanding(Sender,n,b);
n:=n.GetNext;
end;
if n=nil then
n:=TreeView1.Items.GetFirstNode;
end
else
begin
while (n<>nil) and (n.getPrevSibling=nil) do n:=n.Parent;
if n<>nil then n:=n.getPrevSibling;
if n=nil then n:=TreeView1.Items.GetFirstNode;
b:=true;
while b and (n<>nil) do
begin
b:=true;
TreeView1Expanding(Sender,n,b);
if n.Count=0 then
b:=false
else
begin
b:=true;
n:=n.GetLastChild;
end;
end;
end;
end;

begin
Screen.Cursor:=crHourGlass;
TreeView1.Items.BeginUpdate;
try
n1:=TreeView1.Selected;
n:=n1;
MoveOne;
f:=LowerCase(txtFind.Text);//TODO: regexp? match full node data?
while (n<>n1) and (n<>nil) and (Pos(f,LowerCase(n.Text))=0) do
begin
if n1=nil then n1:=n;
MoveOne;
end;
finally
Screen.Cursor:=crDefault;
TreeView1.Items.EndUpdate;
end;
TreeView1.Selected:=n;
TreeView1.SetFocus;
end;

end.

0 comments on commit c8ee27a

Please sign in to comment.