mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 01:57:57 +02:00
* Some improvements for JSON Data viewer by Theo
- Fix: Double element creation - Fix: "Raw preview" update. - Fix: "New Document creates Object" option. - New: Visual and Raw is two way now. Changes in "Raw" (Editable now) will be taken over in "Visual" too. - New: Option: Save Formatted (readable) JSON. - Change: Make TSynJScriptSyn global. - New: German translations. git-svn-id: trunk@62326 -
This commit is contained in:
parent
0545e7c3cf
commit
470ce73096
@ -51,8 +51,8 @@ object MainForm: TMainForm
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnShow = FormShow
|
||||
SessionProperties = 'Height;Left;MIdocument.Checked;MIStrict.Checked;Top;Width;MICompact.Checked'
|
||||
LCLVersion = '1.9.0.0'
|
||||
SessionProperties = 'Height;Left;MICompact.Checked;MIdocument.Checked;MIStrict.Checked;Top;Width;MISaveFormatted.Checked'
|
||||
LCLVersion = '2.1.0.0'
|
||||
object TBJSON: TToolBar
|
||||
Left = 0
|
||||
Height = 26
|
||||
@ -464,6 +464,11 @@ object MainForm: TMainForm
|
||||
Caption = 'Quote string values'
|
||||
OnClick = MIQuoteStringsClick
|
||||
end
|
||||
object MISaveFormatted: TMenuItem
|
||||
AutoCheck = True
|
||||
Caption = 'Save Formatted JSON'
|
||||
OnClick = MISaveFormattedClick
|
||||
end
|
||||
end
|
||||
object MFavourites: TMenuItem
|
||||
Caption = 'Favourites'
|
||||
@ -1178,6 +1183,11 @@ object MainForm: TMainForm
|
||||
item
|
||||
Name = 'RestPanelHeight'
|
||||
OnRestore = PSMainStoredValues7Restore
|
||||
end
|
||||
item
|
||||
Name = 'SaveFormatted'
|
||||
Value = '0'
|
||||
OnRestore = PSMainStoredValues8Restore
|
||||
end>
|
||||
Active = False
|
||||
left = 384
|
||||
@ -1224,4 +1234,9 @@ object MainForm: TMainForm
|
||||
Action = AExpandCurrentContainer
|
||||
end
|
||||
end
|
||||
object SynJScriptSyn1: TSynJScriptSyn
|
||||
Enabled = False
|
||||
left = 373
|
||||
top = 220
|
||||
end
|
||||
end
|
||||
|
@ -43,7 +43,8 @@ type
|
||||
FQuoteStrings,
|
||||
FSortObjectMembers,
|
||||
FCompact,
|
||||
FNewObject : Boolean;
|
||||
FNewObject,
|
||||
FSaveFormatted: Boolean;
|
||||
end;
|
||||
|
||||
TJSONTab = Class(TTabsheet)
|
||||
@ -59,6 +60,7 @@ type
|
||||
FPageControl : TPageControl;
|
||||
FSyn : TSynEdit;
|
||||
procedure DoTabChange(Sender: TObject);
|
||||
procedure JSONFromPreview;
|
||||
procedure SetCurrentFind(AValue: TTreeNode);
|
||||
procedure SetDocNo(AValue: Integer);
|
||||
procedure SetFileName(AValue: String);
|
||||
@ -120,6 +122,7 @@ type
|
||||
MenuItem13: TMenuItem;
|
||||
MenuItem14: TMenuItem;
|
||||
MenuItem15: TMenuItem;
|
||||
MISaveFormatted: TMenuItem;
|
||||
MSepFavourites: TMenuItem;
|
||||
MFavourites: TMenuItem;
|
||||
MIGenCode: TMenuItem;
|
||||
@ -167,6 +170,7 @@ type
|
||||
MMJSON: TMainMenu;
|
||||
ODJSON: TOpenDialog;
|
||||
SDJSON: TSaveDialog;
|
||||
SynJScriptSyn1: TSynJScriptSyn;
|
||||
TBJSON: TToolBar;
|
||||
TBNew: TToolButton;
|
||||
TBNewButton: TToolButton;
|
||||
@ -228,6 +232,7 @@ type
|
||||
procedure MICompactClick(Sender: TObject);
|
||||
procedure MIdocumentClick(Sender: TObject);
|
||||
procedure MIQuoteStringsClick(Sender: TObject);
|
||||
procedure MISaveFormattedClick(Sender: TObject);
|
||||
procedure MISortMembersClick(Sender: TObject);
|
||||
procedure MIStrictClick(Sender: TObject);
|
||||
procedure PCJSONCloseTabClicked(Sender: TObject);
|
||||
@ -237,6 +242,7 @@ type
|
||||
procedure PSMainStoredValues3Restore(Sender: TStoredValue; var Value: TStoredType);
|
||||
procedure PSMainStoredValues6Restore(Sender: TStoredValue; var Value: TStoredType);
|
||||
procedure PSMainStoredValues7Restore(Sender: TStoredValue; var Value: TStoredType);
|
||||
procedure PSMainStoredValues8Restore(Sender: TStoredValue; var Value: TStoredType);
|
||||
procedure TBShowRestClick(Sender: TObject);
|
||||
procedure TVJSONEdited(Sender: TObject; Node: TTreeNode; var S: string);
|
||||
procedure TVJSONEditing(Sender: TObject; Node: TTreeNode;
|
||||
@ -358,10 +364,12 @@ begin
|
||||
SetCaption;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TJSONTab.DoTabChange(Sender: TObject);
|
||||
begin
|
||||
If (PageControl.ActivePageIndex=1) then
|
||||
ShowJSONDocumentText;
|
||||
If ((Sender as TPageControl).ActivePageIndex=1) then
|
||||
ShowJSONDocumentText else JSONFromPreview;
|
||||
end;
|
||||
|
||||
constructor TJSONTab.Create(AOwner: TComponent);
|
||||
@ -398,9 +406,8 @@ begin
|
||||
FSyn:=TSynEdit.Create(Self.Owner);
|
||||
FSyn.align:=alClient;
|
||||
FSyn.Parent:=TS;
|
||||
FSyn.Highlighter:=TSynJScriptSyn.Create(Self.Owner);
|
||||
FSyn.Highlighter:=MainForm.SynJScriptSyn1;
|
||||
FSyn.Highlighter.Enabled:=True;
|
||||
FSyn.ReadOnly:=True;
|
||||
SetCaption;
|
||||
end;
|
||||
|
||||
@ -514,6 +521,12 @@ begin
|
||||
FRestPanelHeight:=StrToIntDef(Value,0);
|
||||
end;
|
||||
|
||||
procedure TMainForm.PSMainStoredValues8Restore(Sender: TStoredValue;
|
||||
var Value: TStoredType);
|
||||
begin
|
||||
FOptions.FSaveFormatted:=StrToIntDef(Value,0)=1;
|
||||
end;
|
||||
|
||||
procedure TMainForm.TBShowRestClick(Sender: TObject);
|
||||
begin
|
||||
if TBShowRest.Down then
|
||||
@ -673,6 +686,8 @@ begin
|
||||
Result.DocNo:=DC;
|
||||
Result.FileName:='';
|
||||
Result.ImageIndex:=16;
|
||||
If FOptions.FNewObject then
|
||||
Result.Root:=TJSONObject.Create;
|
||||
end;
|
||||
|
||||
procedure TMainForm.SetCaption;
|
||||
@ -1204,8 +1219,8 @@ begin
|
||||
P.ImageIndex:=ImageTypeMap[D.JSONType];
|
||||
P.SelectedIndex:=ImageTypeMap[D.JSONType];
|
||||
P.MakeVisible;
|
||||
T.ShowJSONData(P,D);
|
||||
end;
|
||||
T.ShowJSONData(P,D);
|
||||
end;
|
||||
|
||||
function TMainForm.CurrentNode: TTreeNode;
|
||||
@ -1245,6 +1260,8 @@ begin
|
||||
F:=TFileStream.Create(AFileName,fmCreate);
|
||||
try
|
||||
If Assigned(CurrentJSONTab.Root) then
|
||||
if FOptions.FSaveFormatted then
|
||||
S:=CurrentJSONTab.Root.FormatJSON else
|
||||
S:=CurrentJSONTab.Root.AsJSON;
|
||||
If length(S)>0 then
|
||||
F.WriteBuffer(S[1],Length(S));
|
||||
@ -1582,6 +1599,13 @@ begin
|
||||
ShowJSONDocument;
|
||||
end;
|
||||
|
||||
procedure TMainForm.MISaveFormattedClick(Sender: TObject);
|
||||
begin
|
||||
FOptions.FSaveFormatted :=(Sender as TMenuItem).Checked;
|
||||
PSMain.StoredValue['SaveFormatted']:=IntToStr(Ord(FOptions.FSaveFormatted));
|
||||
ShowJSONDocument;
|
||||
end;
|
||||
|
||||
procedure TMainForm.MISortMembersClick(Sender: TObject);
|
||||
begin
|
||||
FOptions.FSortObjectMembers:=(Sender as TMenuItem).Checked;
|
||||
@ -1605,8 +1629,6 @@ begin
|
||||
try
|
||||
{$IF FPC_FULLVERSION>=30002}
|
||||
P.Options:=P.Options+[joStrict];
|
||||
{$ELSE}
|
||||
P:=TJSONParser.Create(S);
|
||||
{$ENDIF}
|
||||
D:=P.Parse;
|
||||
finally
|
||||
@ -1647,9 +1669,28 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSONTab.JSONFromPreview;
|
||||
var P : TJSONParser;
|
||||
D : TJSONData;
|
||||
begin
|
||||
try
|
||||
{$IF FPC_FULLVERSION>=30002}
|
||||
P:=TJSONParser.Create(FSyn.Text,[]);
|
||||
P.Options:=P.Options+[joStrict, joComments];
|
||||
{$ELSE}
|
||||
P:=TJSONParser.Create(FSyn.Text);
|
||||
{$ENDIF}
|
||||
D:=P.Parse;
|
||||
Root:=D;
|
||||
Modified:=true;
|
||||
finally
|
||||
P.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJSONTab.ShowJSONDocumentText;
|
||||
begin
|
||||
FSyn.Text:=Root.FormatJSON();
|
||||
IF Assigned(Root) then FSyn.Text:=Root.FormatJSON();
|
||||
end;
|
||||
|
||||
procedure TJSONTab.ShowJSONData(AParent : TTreeNode; Data : TJSONData);
|
||||
|
Binary file not shown.
@ -131,7 +131,7 @@ msgstr ""
|
||||
#: tcreatecodeform.caption
|
||||
msgctxt "tcreatecodeform.caption"
|
||||
msgid "Create pascal code"
|
||||
msgstr ""
|
||||
msgstr "Pascal Code erstellen"
|
||||
|
||||
#: tcreatecodeform.cgoptions.caption
|
||||
msgid "Other options"
|
||||
@ -214,7 +214,7 @@ msgstr ""
|
||||
#: tmainform.acreatecode.caption
|
||||
msgctxt "tmainform.acreatecode.caption"
|
||||
msgid "Create pascal code"
|
||||
msgstr ""
|
||||
msgstr "Pascal Code erstellen"
|
||||
|
||||
#: tmainform.acut.caption
|
||||
msgid "C&ut"
|
||||
|
Loading…
Reference in New Issue
Block a user