mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 01:59:08 +02:00
* Compact display mode
git-svn-id: trunk@50009 -
This commit is contained in:
parent
a387dabeab
commit
50585ddd56
@ -4,7 +4,7 @@ object MainForm: TMainForm
|
|||||||
Top = 225
|
Top = 225
|
||||||
Width = 695
|
Width = 695
|
||||||
Caption = 'JSON Viewer'
|
Caption = 'JSON Viewer'
|
||||||
ClientHeight = 489
|
ClientHeight = 480
|
||||||
ClientWidth = 695
|
ClientWidth = 695
|
||||||
Icon.Data = {
|
Icon.Data = {
|
||||||
7E04000000000100010010100000010020006804000016000000280000001000
|
7E04000000000100010010100000010020006804000016000000280000001000
|
||||||
@ -49,8 +49,8 @@ object MainForm: TMainForm
|
|||||||
OnCloseQuery = FormCloseQuery
|
OnCloseQuery = FormCloseQuery
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnShow = FormShow
|
OnShow = FormShow
|
||||||
SessionProperties = 'MIStrict.Checked;MIdocument.Checked;Top;Width;Left;Height'
|
SessionProperties = 'Height;Left;MIdocument.Checked;MIStrict.Checked;Top;Width;MICompact.Checked'
|
||||||
LCLVersion = '0.9.29'
|
LCLVersion = '1.5'
|
||||||
object TBJSON: TToolBar
|
object TBJSON: TToolBar
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 26
|
Height = 26
|
||||||
@ -78,6 +78,7 @@ object MainForm: TMainForm
|
|||||||
end
|
end
|
||||||
object ToolButton4: TToolButton
|
object ToolButton4: TToolButton
|
||||||
Left = 70
|
Left = 70
|
||||||
|
Height = 22
|
||||||
Top = 2
|
Top = 2
|
||||||
Width = 8
|
Width = 8
|
||||||
Caption = 'ToolButton4'
|
Caption = 'ToolButton4'
|
||||||
@ -115,6 +116,7 @@ object MainForm: TMainForm
|
|||||||
end
|
end
|
||||||
object ToolButton1: TToolButton
|
object ToolButton1: TToolButton
|
||||||
Left = 216
|
Left = 216
|
||||||
|
Height = 22
|
||||||
Top = 2
|
Top = 2
|
||||||
Width = 8
|
Width = 8
|
||||||
Caption = 'ToolButton1'
|
Caption = 'ToolButton1'
|
||||||
@ -128,11 +130,11 @@ object MainForm: TMainForm
|
|||||||
end
|
end
|
||||||
object TVJSON: TTreeView
|
object TVJSON: TTreeView
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 463
|
Height = 454
|
||||||
Top = 26
|
Top = 26
|
||||||
Width = 695
|
Width = 695
|
||||||
Align = alClient
|
Align = alClient
|
||||||
DefaultItemHeight = 16
|
DefaultItemHeight = 28
|
||||||
HideSelection = False
|
HideSelection = False
|
||||||
Images = ILJSON
|
Images = ILJSON
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
@ -143,7 +145,7 @@ object MainForm: TMainForm
|
|||||||
object ActionList1: TActionList
|
object ActionList1: TActionList
|
||||||
Images = ILJSON
|
Images = ILJSON
|
||||||
left = 88
|
left = 88
|
||||||
top = 104
|
top = 128
|
||||||
object ANew: TAction
|
object ANew: TAction
|
||||||
Category = 'File'
|
Category = 'File'
|
||||||
Caption = '&New'
|
Caption = '&New'
|
||||||
@ -307,8 +309,8 @@ object MainForm: TMainForm
|
|||||||
end
|
end
|
||||||
object MMJSON: TMainMenu
|
object MMJSON: TMainMenu
|
||||||
Images = ILJSON
|
Images = ILJSON
|
||||||
left = 13
|
left = 40
|
||||||
top = 19
|
top = 56
|
||||||
object MFile: TMenuItem
|
object MFile: TMenuItem
|
||||||
Caption = '&File'
|
Caption = '&File'
|
||||||
object MINew: TMenuItem
|
object MINew: TMenuItem
|
||||||
@ -981,11 +983,16 @@ object MainForm: TMainForm
|
|||||||
Caption = 'Sort object members'
|
Caption = 'Sort object members'
|
||||||
OnClick = MISortMembersClick
|
OnClick = MISortMembersClick
|
||||||
end
|
end
|
||||||
|
object MICompact: TMenuItem
|
||||||
|
AutoCheck = True
|
||||||
|
Caption = 'Compact display'
|
||||||
|
OnClick = MICompactClick
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object ILJSON: TImageList
|
object ILJSON: TImageList
|
||||||
left = 112
|
left = 176
|
||||||
top = 61
|
top = 56
|
||||||
Bitmap = {
|
Bitmap = {
|
||||||
4C69100000001000000010000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
|
4C69100000001000000010000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
|
||||||
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
|
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
|
||||||
@ -1507,16 +1514,16 @@ object MainForm: TMainForm
|
|||||||
DefaultExt = '.json'
|
DefaultExt = '.json'
|
||||||
Filter = 'JSON files|*.json|Javascript files|*.js|All files|*.*'
|
Filter = 'JSON files|*.json|Javascript files|*.js|All files|*.*'
|
||||||
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail]
|
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail]
|
||||||
left = 156
|
left = 280
|
||||||
top = 79
|
top = 56
|
||||||
end
|
end
|
||||||
object SDJSON: TSaveDialog
|
object SDJSON: TSaveDialog
|
||||||
Title = 'Save JSON document to file'
|
Title = 'Save JSON document to file'
|
||||||
DefaultExt = '.json'
|
DefaultExt = '.json'
|
||||||
Filter = 'JSON files|*.json|Javascript files|*.js|All files|*.*'
|
Filter = 'JSON files|*.json|Javascript files|*.js|All files|*.*'
|
||||||
Options = [ofPathMustExist, ofEnableSizing, ofViewDetail]
|
Options = [ofPathMustExist, ofEnableSizing, ofViewDetail]
|
||||||
left = 161
|
left = 488
|
||||||
top = 118
|
top = 56
|
||||||
end
|
end
|
||||||
object PSMain: TIniPropStorage
|
object PSMain: TIniPropStorage
|
||||||
StoredValues = <
|
StoredValues = <
|
||||||
@ -1534,15 +1541,19 @@ object MainForm: TMainForm
|
|||||||
Name = 'Sort'
|
Name = 'Sort'
|
||||||
Value = '0'
|
Value = '0'
|
||||||
OnRestore = PSMainStoredValues2Restore
|
OnRestore = PSMainStoredValues2Restore
|
||||||
|
end
|
||||||
|
item
|
||||||
|
Name = 'compact'
|
||||||
|
OnRestore = PSMainStoredValues3Restore
|
||||||
end>
|
end>
|
||||||
Active = False
|
Active = False
|
||||||
left = 196
|
left = 384
|
||||||
top = 96
|
top = 56
|
||||||
end
|
end
|
||||||
object FDJSON: TFindDialog
|
object FDJSON: TFindDialog
|
||||||
Options = [frDown, frHideUpDown, frDisableUpDown]
|
Options = [frDown, frHideUpDown, frDisableUpDown]
|
||||||
OnFind = FDJSONFind
|
OnFind = FDJSONFind
|
||||||
left = 264
|
left = 376
|
||||||
top = 109
|
top = 128
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,6 +59,7 @@ type
|
|||||||
MEDit: TMenuItem;
|
MEDit: TMenuItem;
|
||||||
MenuItem2: TMenuItem;
|
MenuItem2: TMenuItem;
|
||||||
MenuItem3: TMenuItem;
|
MenuItem3: TMenuItem;
|
||||||
|
MICompact: TMenuItem;
|
||||||
MIFInd: TMenuItem;
|
MIFInd: TMenuItem;
|
||||||
MIExpandCurrent: TMenuItem;
|
MIExpandCurrent: TMenuItem;
|
||||||
MIExpandAll: TMenuItem;
|
MIExpandAll: TMenuItem;
|
||||||
@ -136,6 +137,7 @@ type
|
|||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormShow(Sender: TObject);
|
procedure FormShow(Sender: TObject);
|
||||||
procedure HaveData(Sender: TObject);
|
procedure HaveData(Sender: TObject);
|
||||||
|
procedure MICompactClick(Sender: TObject);
|
||||||
procedure MIdocumentClick(Sender: TObject);
|
procedure MIdocumentClick(Sender: TObject);
|
||||||
procedure MISortMembersClick(Sender: TObject);
|
procedure MISortMembersClick(Sender: TObject);
|
||||||
procedure MIStrictClick(Sender: TObject);
|
procedure MIStrictClick(Sender: TObject);
|
||||||
@ -145,6 +147,8 @@ type
|
|||||||
var Value: TStoredType);
|
var Value: TStoredType);
|
||||||
procedure PSMainStoredValues2Restore(Sender: TStoredValue;
|
procedure PSMainStoredValues2Restore(Sender: TStoredValue;
|
||||||
var Value: TStoredType);
|
var Value: TStoredType);
|
||||||
|
procedure PSMainStoredValues3Restore(Sender: TStoredValue;
|
||||||
|
var Value: TStoredType);
|
||||||
procedure TVJSONEdited(Sender: TObject; Node: TTreeNode; var S: string);
|
procedure TVJSONEdited(Sender: TObject; Node: TTreeNode; var S: string);
|
||||||
procedure TVJSONEditing(Sender: TObject; Node: TTreeNode;
|
procedure TVJSONEditing(Sender: TObject; Node: TTreeNode;
|
||||||
var AllowEdit: Boolean);
|
var AllowEdit: Boolean);
|
||||||
@ -154,6 +158,7 @@ type
|
|||||||
FSortObjectMembers,
|
FSortObjectMembers,
|
||||||
FStrict,
|
FStrict,
|
||||||
FNewObject,
|
FNewObject,
|
||||||
|
FCompact,
|
||||||
FModified : Boolean;
|
FModified : Boolean;
|
||||||
FCurrentFind : TTreeNode;
|
FCurrentFind : TTreeNode;
|
||||||
procedure AddDataToContainer(const AMemberName: String; D: TJSONData);
|
procedure AddDataToContainer(const AMemberName: String; D: TJSONData);
|
||||||
@ -225,6 +230,12 @@ begin
|
|||||||
FSortObjectMembers:=StrToIntDef(Value,0)=1;
|
FSortObjectMembers:=StrToIntDef(Value,0)=1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.PSMainStoredValues3Restore(Sender: TStoredValue;
|
||||||
|
var Value: TStoredType);
|
||||||
|
begin
|
||||||
|
FCompact:=StrToIntDef(Value,0)=1;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainForm.TVJSONEdited(Sender: TObject; Node: TTreeNode; var S: string);
|
procedure TMainForm.TVJSONEdited(Sender: TObject; Node: TTreeNode; var S: string);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -424,23 +435,17 @@ begin
|
|||||||
begin
|
begin
|
||||||
P:=TJSONData(PN.Data);
|
P:=TJSONData(PN.Data);
|
||||||
If P.JSONType=jtArray then
|
If P.JSONType=jtArray then
|
||||||
|
TJSONArray(P).Remove(D)
|
||||||
|
else If P.JSONType=jtObject then
|
||||||
|
TJSONObject(P).Remove(D);
|
||||||
|
PN:=PN.Parent;
|
||||||
|
If PN<>Nil then
|
||||||
begin
|
begin
|
||||||
TJSONArray(P).Remove(D);
|
PN.DeleteChildren;
|
||||||
PN:=PN.Parent;
|
|
||||||
If PN<>Nil then
|
|
||||||
PN.DeleteChildren
|
|
||||||
else
|
|
||||||
TVJSON.Items.Clear;
|
|
||||||
ShowJSONData(PN,P);
|
ShowJSONData(PN,P);
|
||||||
end
|
end
|
||||||
else If P.JSONType=jtObject then
|
else
|
||||||
begin
|
ShowJSONDocument;
|
||||||
TJSONObject(P).Remove(D);
|
|
||||||
PN:=PN.Parent;
|
|
||||||
If PN<>Nil then
|
|
||||||
PN.DeleteChildren;
|
|
||||||
ShowJSONData(PN,P);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
Modify;
|
Modify;
|
||||||
end;
|
end;
|
||||||
@ -733,14 +738,18 @@ end;
|
|||||||
|
|
||||||
Function TMainForm.CurrentData : TJSONData;
|
Function TMainForm.CurrentData : TJSONData;
|
||||||
|
|
||||||
|
Var
|
||||||
|
N : TTreeNode;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
If (CurrentNode=Nil) then
|
N:=CurrentNode;
|
||||||
|
If (N=Nil) then
|
||||||
Result:=Nil
|
Result:=Nil
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Result:=TJSONData(CurrentNode.Data);
|
Result:=TJSONData(N.Data);
|
||||||
If (Result=Nil) and (CurrentNode.Count=1) then
|
If (Result=Nil) and (N.Count=1) then
|
||||||
Result:=TJSONData(CurrentNode.Items[0].Data);
|
Result:=TJSONData(N.Items[0].Data);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -920,6 +929,13 @@ begin
|
|||||||
(Sender as TAction).Enabled:=(FRoot<>Nil);
|
(Sender as TAction).Enabled:=(FRoot<>Nil);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TMainForm.MICompactClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FCompact:=MICompact.Checked;
|
||||||
|
PSMain.StoredValue['compact']:=IntToStr(Ord(Fstrict));
|
||||||
|
ShowJSONDocument;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TMainForm.MIdocumentClick(Sender: TObject);
|
procedure TMainForm.MIdocumentClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FNewObject:=(Sender as TMenuItem).Checked;
|
FNewObject:=(Sender as TMenuItem).Checked;
|
||||||
@ -966,7 +982,7 @@ begin
|
|||||||
BeginUpdate;
|
BeginUpdate;
|
||||||
try
|
try
|
||||||
TVJSON.Items.Clear;
|
TVJSON.Items.Clear;
|
||||||
SHowJSONData(Nil,FRoot);
|
ShowJSONData(Nil,FRoot);
|
||||||
With TVJSON do
|
With TVJSON do
|
||||||
If (Items.Count>0) and Assigned(Items[0]) then
|
If (Items.Count>0) and Assigned(Items[0]) then
|
||||||
begin
|
begin
|
||||||
@ -989,50 +1005,58 @@ Var
|
|||||||
S : TStringList;
|
S : TStringList;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
N:=Nil;
|
if Not Assigned(Data) then
|
||||||
if Assigned(Data) then
|
exit;
|
||||||
begin
|
if FCompact and (AParent<>Nil) then
|
||||||
Case Data.JSONType of
|
N:=AParent
|
||||||
jtArray,
|
else
|
||||||
jtObject:
|
N:=TVJSON.Items.AddChild(AParent,'');
|
||||||
begin
|
Case Data.JSONType of
|
||||||
If (Data.JSONType=jtArray) then
|
jtArray,
|
||||||
C:=SArray
|
jtObject:
|
||||||
else
|
|
||||||
C:=SObject;
|
|
||||||
N:=TVJSON.Items.AddChild(AParent,Format(C,[Data.Count]));
|
|
||||||
S:=TstringList.Create;
|
|
||||||
try
|
|
||||||
For I:=0 to Data.Count-1 do
|
|
||||||
If Data.JSONtype=jtArray then
|
|
||||||
S.AddObject(IntToStr(I),Data.items[i])
|
|
||||||
else
|
|
||||||
S.AddObject(TJSONObject(Data).Names[i],Data.items[i]);
|
|
||||||
If FSortObjectMembers and (Data.JSONType=jtObject) then
|
|
||||||
S.Sort;
|
|
||||||
For I:=0 to S.Count-1 do
|
|
||||||
begin
|
|
||||||
N2:=TVJSON.Items.AddChild(N,S[i]);
|
|
||||||
D:=TJSONData(S.Objects[i]);
|
|
||||||
N2.ImageIndex:=ImageTypeMap[D.JSONType];
|
|
||||||
N2.SelectedIndex:=ImageTypeMap[D.JSONType];
|
|
||||||
ShowJSONData(N2,D);
|
|
||||||
end
|
|
||||||
finally
|
|
||||||
S.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
jtNull:
|
|
||||||
N:=TVJSON.Items.AddChild(AParent,SNull);
|
|
||||||
else
|
|
||||||
N:=TVJSON.Items.AddChild(AParent,Data.AsString);
|
|
||||||
end;
|
|
||||||
If Assigned(N) then
|
|
||||||
begin
|
begin
|
||||||
N.ImageIndex:=ImageTypeMap[Data.JSONType];
|
If (Data.JSONType=jtArray) then
|
||||||
N.SelectedIndex:=ImageTypeMap[Data.JSONType];
|
C:=SArray
|
||||||
N.Data:=Data;
|
else
|
||||||
|
C:=SObject;
|
||||||
|
C:=Format(C,[Data.Count]);
|
||||||
|
S:=TstringList.Create;
|
||||||
|
try
|
||||||
|
For I:=0 to Data.Count-1 do
|
||||||
|
If Data.JSONtype=jtArray then
|
||||||
|
S.AddObject(IntToStr(I),Data.items[i])
|
||||||
|
else
|
||||||
|
S.AddObject(TJSONObject(Data).Names[i],Data.items[i]);
|
||||||
|
If FSortObjectMembers and (Data.JSONType=jtObject) then
|
||||||
|
S.Sort;
|
||||||
|
For I:=0 to S.Count-1 do
|
||||||
|
begin
|
||||||
|
N2:=TVJSON.Items.AddChild(N,S[i]);
|
||||||
|
D:=TJSONData(S.Objects[i]);
|
||||||
|
N2.ImageIndex:=ImageTypeMap[D.JSONType];
|
||||||
|
N2.SelectedIndex:=ImageTypeMap[D.JSONType];
|
||||||
|
ShowJSONData(N2,D);
|
||||||
|
end
|
||||||
|
finally
|
||||||
|
S.Free;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
jtNull:
|
||||||
|
C:=SNull;
|
||||||
|
else
|
||||||
|
C:=Data.AsString;
|
||||||
|
if (Data.JSONType=jtString) then
|
||||||
|
C:='"'+C+'"';
|
||||||
|
end;
|
||||||
|
If Assigned(N) then
|
||||||
|
begin
|
||||||
|
If N.Text='' then
|
||||||
|
N.Text:=C
|
||||||
|
else
|
||||||
|
N.Text:=N.Text+': '+C;
|
||||||
|
N.ImageIndex:=ImageTypeMap[Data.JSONType];
|
||||||
|
N.SelectedIndex:=ImageTypeMap[Data.JSONType];
|
||||||
|
N.Data:=Data;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user