-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathuFormJsonViewer.pas
More file actions
executable file
·133 lines (113 loc) · 3.64 KB
/
uFormJsonViewer.pas
File metadata and controls
executable file
·133 lines (113 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
unit uFormJsonViewer;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ToolWin,
System.ImageList, Vcl.ImgList, Vcl.ExtCtrls, JSONTreeView, JSONDoc, Vcl.Menus,
System.Actions, Vcl.ActnList, Vcl.StdCtrls;
type
TFormJsonView = class(TForm)
ImageListMain: TImageList;
ToolBar1: TToolBar;
ToolButtonURL: TToolButton;
ToolButtonFile: TToolButton;
ToolButtonPaste: TToolButton;
ToolButtonClear: TToolButton;
StatusBarMain: TStatusBar;
JSONDocMain: TJSONDocument;
JSONTreeViewMain: TJSONTreeView;
PopupMenuJsonTreeView: TPopupMenu;
MenuItem_VisibleChildrenCounts: TMenuItem;
MenuItem_VisibleByteSizes: TMenuItem;
ActionListMain: TActionList;
ActionLoadFromURL: TAction;
ActionLoadFromFile: TAction;
ActionPasteFromClipboard: TAction;
ActionClear: TAction;
ActionToggleVisibleCounts: TAction;
ActionToggleVisibleBytes: TAction;
FileOpenDialog1: TFileOpenDialog;
edtURL: TEdit;
procedure FormCreate(Sender: TObject);
procedure ActionLoadFromURLExecute(Sender: TObject);
procedure ActionLoadFromFileExecute(Sender: TObject);
procedure ActionPasteFromClipboardExecute(Sender: TObject);
procedure ActionClearExecute(Sender: TObject);
procedure ActionToggleVisibleCountsExecute(Sender: TObject);
procedure ActionToggleVisibleBytesExecute(Sender: TObject);
private
procedure ShowJson(s: string);
public
{ Public declarations }
end;
var
FormJsonView: TFormJsonView;
implementation
uses
System.IOUtils, Vcl.Clipbrd, uDMHTTP;
{$R *.dfm}
procedure TFormJsonView.FormCreate(Sender: TObject);
begin
ActionToggleVisibleCounts.Checked := JSONTreeViewMain.VisibleChildrenCounts;
ActionToggleVisibleBytes.Checked := JSONTreeViewMain.VisibleByteSizes;
end;
procedure TFormJsonView.ShowJson(s: string);
begin
JSONDocMain.JsonText := s;
JSONTreeViewMain.Items.BeginUpdate;
try
JSONTreeViewMain.LoadJson;
JSONTreeViewMain.FullCollapse;
finally
JSONTreeViewMain.Items.EndUpdate;
end;
end;
procedure TFormJsonView.ActionClearExecute(Sender: TObject);
begin
JSONDocMain.JsonText := '';
JSONTreeViewMain.LoadJson;
end;
procedure TFormJsonView.ActionLoadFromFileExecute(Sender: TObject);
var jsonStr: string;
begin
if FileOpenDialog1.Execute then
begin
jsonStr := TFile.ReadAllText(FileOpenDialog1.FileName);
ShowJson(jsonStr);
end;
end;
procedure TFormJsonView.ActionLoadFromURLExecute(Sender: TObject);
var jsonStr: string;
begin
if edtURL.Text <> '' then
begin
ActionClear.Execute;
ActionLoadFromURL.Enabled := False;
StatusBarMain.SimpleText := 'Loading JSON... Please Wait...';
Application.ProcessMessages;
if DMHTTP = nil then
DMHTTP := TDMHTTP.Create(Application);
jsonStr := DMHTTP.GetRespString(edtURL.Text);
ShowJson(jsonStr);
StatusBarMain.SimpleText := '';
ActionLoadFromURL.Enabled := True;
end
else
begin
ShowMessage('Enter URL to load JSON');
edtURL.SetFocus;
end;
end;
procedure TFormJsonView.ActionPasteFromClipboardExecute(Sender: TObject);
begin
ShowJson(Clipboard.AsText);
end;
procedure TFormJsonView.ActionToggleVisibleBytesExecute(Sender: TObject);
begin
JSONTreeViewMain.VisibleByteSizes := not JSONTreeViewMain.VisibleByteSizes;
end;
procedure TFormJsonView.ActionToggleVisibleCountsExecute(Sender: TObject);
begin
JSONTreeViewMain.VisibleChildrenCounts := not JSONTreeViewMain.VisibleChildrenCounts;
end;
end.