Skip to content

Commit

Permalink
feat: Display a path of the current selected node
Browse files Browse the repository at this point in the history
Closes: #3
  • Loading branch information
gcarreno committed Feb 2, 2021
1 parent b61a6f3 commit 80296ef
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
36 changes: 27 additions & 9 deletions src/forms/ljv.forms.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ object frmMain: TfrmMain
object psMain: TPairSplitter
Cursor = crDefault
Left = 224
Height = 563
Height = 528
Top = 0
Width = 797
Align = alClient
Position = 400
object pssTree: TPairSplitterSide
Cursor = crArrow
Left = 0
Height = 563
Height = 528
Top = 0
Width = 400
ClientWidth = 400
ClientHeight = 563
ClientHeight = 528
object vstJSON: TVirtualStringTree
Left = 0
Height = 563
Height = 528
Top = 0
Width = 400
Align = alClient
Expand All @@ -51,11 +51,11 @@ object frmMain: TfrmMain
object pssNode: TPairSplitterSide
Cursor = crArrow
Left = 405
Height = 563
Height = 528
Top = 0
Width = 392
ClientWidth = 392
ClientHeight = 563
ClientHeight = 528
object panItem: TPanel
Left = 0
Height = 80
Expand Down Expand Up @@ -92,7 +92,7 @@ object frmMain: TfrmMain
end
object panValue: TPanel
Left = 0
Height = 451
Height = 416
Top = 112
Width = 392
Anchors = [akTop, akLeft, akRight, akBottom]
Expand All @@ -110,7 +110,7 @@ object frmMain: TfrmMain
end
object lbFiles: TListBox
Left = 0
Height = 563
Height = 528
Top = 0
Width = 219
Align = alLeft
Expand All @@ -124,10 +124,28 @@ object frmMain: TfrmMain
end
object Splitter1: TSplitter
Left = 219
Height = 563
Height = 528
Top = 0
Width = 5
end
object panPath: TPanel
Left = 0
Height = 35
Top = 528
Width = 1021
Align = alBottom
ClientHeight = 35
ClientWidth = 1021
TabOrder = 3
object lblPath: TLabel
Left = 8
Height = 17
Top = 8
Width = 48
Caption = 'lblPath'
ParentColor = False
end
end
object JSONPropStorage: TJSONPropStorage
StoredValues = <>
Formatted = False
Expand Down
3 changes: 2 additions & 1 deletion src/forms/ljv.forms.main.lrj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
{"hash":43106325,"name":"tfrmmain.lbltype.caption","sourcebytes":[108,98,108,84,121,112,101],"value":"lblType"},
{"hash":43075653,"name":"tfrmmain.lblname.caption","sourcebytes":[108,98,108,78,97,109,101],"value":"lblName"},
{"hash":151678324,"name":"tfrmmain.lblcount.caption","sourcebytes":[108,98,108,67,111,117,110,116],"value":"lblCount"},
{"hash":152863893,"name":"tfrmmain.lblvalue.caption","sourcebytes":[108,98,108,86,97,108,117,101],"value":"lblValue"}
{"hash":152863893,"name":"tfrmmain.lblvalue.caption","sourcebytes":[108,98,108,86,97,108,117,101],"value":"lblValue"},
{"hash":43083992,"name":"tfrmmain.lblpath.caption","sourcebytes":[108,98,108,80,97,116,104],"value":"lblPath"}
]}
19 changes: 14 additions & 5 deletions src/forms/ljv.forms.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ interface
{ TfrmMain }

TfrmMain = class(TForm)
lblPath: TLabel;
lblValue: TLabel;
panPath: TPanel;
panValue: TPanel;
JSONPropStorage: TJSONPropStorage;
lblCount: TLabel;
Expand Down Expand Up @@ -85,7 +87,7 @@ TfrmMain = class(TForm)
procedure LoadFile(const AFilename: String);
procedure UpdateTree;
procedure UpdateTreeFromNode(const ANode: PVirtualNode;
const AJSONData: TJSONData);
const AJSONData: TJSONData; const APath: String);
procedure ShowValue(const AJSONData: TJSONData);
public

Expand Down Expand Up @@ -130,6 +132,7 @@ implementation
rsLabelDateTime = 'Date';
rsLabelBytes = 'Bytes';
rsLabelScientific = 'Scientific';
rsCaptionPath = 'Path';

rsBytes = ' B';
rsKiloBytes = ' KB';
Expand Down Expand Up @@ -232,6 +235,7 @@ procedure TfrmMain.vstJSONChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
treeNode:= vstJSON.GetNodeData(Node);
if Assigned(treeNode) then
begin
lblPath.Caption:= Format('%s: %s', [rsCaptionPath, treeNode^.NodePath]);
sName:= treeNode^.NodeName;
iIndex:= treeNode^.NodeIndex;
if Length(sName) > 0 then
Expand Down Expand Up @@ -576,6 +580,7 @@ procedure TfrmMain.ClearLabels;
lblName.Caption:= rsLabelNameEmpty;
lblType.Caption:= rsLabelTypeEmpty;
lblCount.Caption:= rsLabelCountEmpty;
lblPath.Caption:= '';
end;

procedure TfrmMain.ProcessParams;
Expand Down Expand Up @@ -635,13 +640,13 @@ procedure TfrmMain.UpdateTree;
vstJSON.Clear;
if Assigned(FJSON) then
begin
UpdateTreeFromNode(vstJSON.RootNode, FJSON);
UpdateTreeFromNode(vstJSON.RootNode, FJSON, 'ROOT');
end;
vstJSON.EndUpdate;
end;

procedure TfrmMain.UpdateTreeFromNode(const ANode: PVirtualNode;
const AJSONData: TJSONData);
const AJSONData: TJSONData; const APath: String);
var
index: Integer;
node: PVirtualNode;
Expand All @@ -657,9 +662,12 @@ procedure TfrmMain.UpdateTreeFromNode(const ANode: PVirtualNode;
begin
treeNode^.NodeType:= AJSONData.Items[index].JSONType;
treeNode^.NodeData:= AJSONData.Items[index];
treeNode^.NodePath:= APath;

if AJSONData.JSONType = jtObject then
begin
treeNode^.NodeName:= TJSONObject(AJSONData).Names[index];
treeNode^.NodePath:= treeNode^.NodePath + '.' + treeNode^.NodeName;
end
else
begin
Expand All @@ -669,6 +677,7 @@ procedure TfrmMain.UpdateTreeFromNode(const ANode: PVirtualNode;
if AJSONData.JSONType = jtArray then
begin
treeNode^.NodeIndex:= index;
treeNode^.NodePath:= treeNode^.NodePath + Format('[%d]', [index]);
end
else
begin
Expand All @@ -677,12 +686,12 @@ procedure TfrmMain.UpdateTreeFromNode(const ANode: PVirtualNode;

if AJSONData.Items[index].JSONType = jtObject then
begin
UpdateTreeFromNode(node, AJSONData.Items[index]);
UpdateTreeFromNode(node, AJSONData.Items[index], treeNode^.NodePath);
end;

if AJSONData.Items[index].JSONType = jtArray then
begin
UpdateTreeFromNode(node, AJSONData.Items[index]);
UpdateTreeFromNode(node, AJSONData.Items[index], treeNode^.NodePath);
end;
end;
end;
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pot
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ msgstr ""
msgid " B"
msgstr ""

#: ljv.forms.main.rscaptionpath
msgid "Path"
msgstr ""

#: ljv.forms.main.rscaptionvalue
msgid "Value"
msgstr ""
Expand Down Expand Up @@ -171,6 +175,10 @@ msgstr ""
msgid "lblName"
msgstr ""

#: tfrmmain.lblpath.caption
msgid "lblPath"
msgstr ""

#: tfrmmain.lbltype.caption
msgid "lblType"
msgstr ""
Expand Down
11 changes: 9 additions & 2 deletions src/i18n/lazJSONViewer.pt.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ msgstr ""
msgid " B"
msgstr " B"

#: ljv.forms.main.rscaptionpath
msgid "Path"
msgstr "Caminho"

#: ljv.forms.main.rscaptionvalue
msgid "Value"
msgstr "Valor"
Expand Down Expand Up @@ -172,11 +176,14 @@ msgstr "lblCount"
msgid "lblName"
msgstr "lblName"

#: tfrmmain.lblpath.caption
msgid "lblPath"
msgstr "lblPath"

#: tfrmmain.lbltype.caption
msgid "lblType"
msgstr "lblType"

#: tfrmmain.lblvalue.caption
msgid "lblValue"
msgstr ""

msgstr "lblValue"
11 changes: 9 additions & 2 deletions src/i18n/lazJSONViewer.pt_PT.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ msgstr ""
msgid " B"
msgstr " B"

#: ljv.forms.main.rscaptionpath
msgid "Path"
msgstr "Caminho"

#: ljv.forms.main.rscaptionvalue
msgid "Value"
msgstr "Valor"
Expand Down Expand Up @@ -172,11 +176,14 @@ msgstr "lblCount"
msgid "lblName"
msgstr "lblName"

#: tfrmmain.lblpath.caption
msgid "lblPath"
msgstr "lblPath"

#: tfrmmain.lbltype.caption
msgid "lblType"
msgstr "lblType"

#: tfrmmain.lblvalue.caption
msgid "lblValue"
msgstr ""

msgstr "lblValue"

0 comments on commit 80296ef

Please sign in to comment.