* Allow to view JSON as raw text

git-svn-id: trunk@57917 -
This commit is contained in:
michael 2018-05-13 11:32:30 +00:00
parent c4ea1b6963
commit c7d41c8b0d
20 changed files with 184 additions and 27 deletions

View File

@ -816,6 +816,7 @@ object CreateCodeForm: TCreateCodeForm
ShowButtons = [pbOK, pbCancel] ShowButtons = [pbOK, pbCancel]
end end
object SynFPC: TSynFreePascalSyn object SynFPC: TSynFreePascalSyn
Enabled = False
CompilerMode = pcmObjFPC CompilerMode = pcmObjFPC
NestedComments = True NestedComments = True
left = 127 left = 127

View File

@ -27,7 +27,7 @@ interface
uses uses
Classes, SysUtils, fpJSON, jsonscanner, JSONParser, Classes, SysUtils, fpJSON, jsonscanner, JSONParser,
Forms, Controls, Dialogs, ActnList, Menus, ComCtrls, IniPropStorage, PropertyStorage, Forms, Controls, Dialogs, ActnList, Menus, ComCtrls, IniPropStorage, PropertyStorage,
DefaultTranslator; DefaultTranslator, SynEdit, SynHighlighterJScript;
type type
@ -55,6 +55,10 @@ type
FModified: Boolean; FModified: Boolean;
FOptions: TViewerOptions; FOptions: TViewerOptions;
FTreeView: TTreeview; FTreeView: TTreeview;
FPageControl : TPageControl;
FSyn : TSynEdit;
procedure CreatePageControl;
procedure DoTabChange(Sender: TObject);
procedure SetCurrentFind(AValue: TTreeNode); procedure SetCurrentFind(AValue: TTreeNode);
procedure SetFileName(AValue: String); procedure SetFileName(AValue: String);
procedure SetJSONData(AValue: TJSONData); procedure SetJSONData(AValue: TJSONData);
@ -66,6 +70,7 @@ type
Destructor Destroy; override; Destructor Destroy; override;
procedure ShowJSONData(AParent: TTreeNode; Data: TJSONData); procedure ShowJSONData(AParent: TTreeNode; Data: TJSONData);
procedure ShowJSONDocument; procedure ShowJSONDocument;
Procedure ShowJSONDocumentText;
Property FileName : String read FFileName Write SetFileName; Property FileName : String read FFileName Write SetFileName;
Property TVJSON : TTreeview Read FTreeView; Property TVJSON : TTreeview Read FTreeView;
// We own JSON // We own JSON
@ -317,14 +322,48 @@ begin
FCurrentFind:=AValue; FCurrentFind:=AValue;
end; end;
procedure TJSONTab.DoTabChange(Sender: TObject);
begin
If (PageControl.ActivePageIndex=1) then
ShowJSONDocumentText;
end;
constructor TJSONTab.Create(AOwner: TComponent); constructor TJSONTab.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
FTreeView:=TTreeview.Create(Self); CreatePageControl;
FTreeView.Parent:=Self; end;
Procedure TJSONTab.CreatePageControl;
Var
TS : TTabSheet;
begin
FPageControl:=TPageControl.Create(Self.Owner);
FPageControl.Parent:=Self;
FPageControl.Align:=alClient;
FPageControl.TabPosition:=tpBottom;
FPageControl.OnChange:=@DoTabChange;
// Visual
TS:=TTabsheet.Create(Self.Owner);
TS.Caption:=STabCaptionVisual;
TS.Parent:=FPageControl;
FTreeView:=TTreeview.Create(Self.Owner);
FTreeView.Parent:=TS;
FTreeView.Options:= [tvoAutoItemHeight,tvoKeepCollapsedNodes,tvoRightClickSelect,tvoShowButtons,tvoShowLines,tvoShowRoot,tvoToolTips,tvoThemedDraw]; FTreeView.Options:= [tvoAutoItemHeight,tvoKeepCollapsedNodes,tvoRightClickSelect,tvoShowButtons,tvoShowLines,tvoShowRoot,tvoToolTips,tvoThemedDraw];
FTreeView.Align:=alClient; FTreeView.Align:=alClient;
// Raw
TS:=TTabsheet.Create(Self.Owner);
TS.Caption:=STabCaptionRaw;
TS.Parent:=FPageControl;
FSyn:=TSynEdit.Create(Self.Owner);
FSyn.align:=alClient;
FSyn.Parent:=TS;
FSyn.Highlighter:=TSynJScriptSyn.Create(Self.Owner);
FSyn.ReadOnly:=True;
SetCaption; SetCaption;
end; end;
@ -1150,7 +1189,8 @@ procedure TMainForm.AOpenExecute(Sender: TObject);
begin begin
With ODJSON do With ODJSON do
begin begin
FileName:=CurrentJSONTab.FileName; if Assigned(CurrentJSONTab) then
FileName:=CurrentJSONTab.FileName;
If Execute then If Execute then
OpenFile(FileName) OpenFile(FileName)
end; end;
@ -1285,8 +1325,8 @@ procedure TMainForm.FormShow(Sender: TObject);
begin begin
if (ParamCount>0) and FileExists(ParamStr(1)) then if (ParamCount>0) and FileExists(ParamStr(1)) then
OpenFile(ParamStr(1)) OpenFile(ParamStr(1))
else // else
NewDocument; // NewDocument;
end; end;
procedure TMainForm.HaveData(Sender: TObject); procedure TMainForm.HaveData(Sender: TObject);
@ -1372,8 +1412,12 @@ begin
finally finally
S.Free; S.Free;
end; end;
NewDocument.FileName:=AFileName; With NewDocument do
NewDocument.Root:=D; begin
FileName:=AFileName;
Root:=D;
Modified:=False;
end;
SetCaption; SetCaption;
// NewDocument.ShowJSONDocument; // NewDocument.ShowJSONDocument;
end; end;
@ -1381,6 +1425,7 @@ end;
procedure TJSONTab.ShowJSONDocument; procedure TJSONTab.ShowJSONDocument;
begin begin
ShowJSONDocumentText;
With TVJSON.Items do With TVJSON.Items do
begin begin
BeginUpdate; BeginUpdate;
@ -1399,6 +1444,11 @@ begin
end; end;
end; end;
procedure TJSONTab.ShowJSONDocumentText;
begin
FSyn.Text:=Root.FormatJSON();
end;
procedure TJSONTab.ShowJSONData(AParent : TTreeNode; Data : TJSONData); procedure TJSONTab.ShowJSONData(AParent : TTreeNode; Data : TJSONData);
Var Var

View File

@ -11,11 +11,11 @@ object NewBooleanForm: TNewBooleanForm
ClientWidth = 387 ClientWidth = 387
OnCloseQuery = FormCloseQuery OnCloseQuery = FormCloseQuery
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '1.5' LCLVersion = '1.9.0.0'
object BPNewBoolean: TButtonPanel object BPNewBoolean: TButtonPanel
Left = 6 Left = 6
Height = 37 Height = 42
Top = 81 Top = 76
Width = 375 Width = 375
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True
@ -34,16 +34,16 @@ object NewBooleanForm: TNewBooleanForm
Left = 8 Left = 8
Height = 17 Height = 17
Top = 12 Top = 12
Width = 97 Width = 83
Caption = '&Member name' Caption = '&Member name'
FocusControl = Ename FocusControl = Ename
ParentColor = False ParentColor = False
end end
object CBValue: TCheckBox object CBValue: TCheckBox
Left = 128 Left = 128
Height = 24 Height = 22
Top = 44 Top = 44
Width = 97 Width = 82
Caption = 'Set to true' Caption = 'Set to true'
TabOrder = 1 TabOrder = 1
end end

View File

@ -11,11 +11,11 @@ object NewNumberForm: TNewNumberForm
ClientWidth = 305 ClientWidth = 305
OnCloseQuery = FormCloseQuery OnCloseQuery = FormCloseQuery
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '1.5' LCLVersion = '1.9.0.0'
object BPNewNumber: TButtonPanel object BPNewNumber: TButtonPanel
Left = 6 Left = 6
Height = 37 Height = 42
Top = 197 Top = 192
Width = 293 Width = 293
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True
@ -52,8 +52,8 @@ object NewNumberForm: TNewNumberForm
ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1 ChildSizing.ControlsPerLine = 1
ClientHeight = 86 ClientHeight = 87
ClientWidth = 181 ClientWidth = 183
Items.Strings = ( Items.Strings = (
'Float' 'Float'
'Integer' 'Integer'
@ -72,7 +72,7 @@ object NewNumberForm: TNewNumberForm
Left = 12 Left = 12
Height = 17 Height = 17
Top = 10 Top = 10
Width = 40 Width = 34
Caption = '&Name' Caption = '&Name'
FocusControl = EName FocusControl = EName
ParentColor = False ParentColor = False
@ -81,7 +81,7 @@ object NewNumberForm: TNewNumberForm
Left = 12 Left = 12
Height = 17 Height = 17
Top = 159 Top = 159
Width = 38 Width = 31
Caption = 'Value' Caption = 'Value'
ParentColor = False ParentColor = False
end end

View File

@ -11,7 +11,7 @@ object NewStringForm: TNewStringForm
ClientWidth = 320 ClientWidth = 320
OnCloseQuery = FormCloseQuery OnCloseQuery = FormCloseQuery
Position = poMainFormCenter Position = poMainFormCenter
LCLVersion = '1.5' LCLVersion = '1.9.0.0'
object EName: TEdit object EName: TEdit
Left = 88 Left = 88
Height = 27 Height = 27
@ -30,7 +30,7 @@ object NewStringForm: TNewStringForm
Left = 8 Left = 8
Height = 17 Height = 17
Top = 16 Top = 16
Width = 40 Width = 34
Alignment = taRightJustify Alignment = taRightJustify
Caption = '&Name' Caption = '&Name'
FocusControl = EName FocusControl = EName
@ -41,7 +41,7 @@ object NewStringForm: TNewStringForm
Left = 8 Left = 8
Height = 17 Height = 17
Top = 49 Top = 49
Width = 38 Width = 31
Alignment = taRightJustify Alignment = taRightJustify
Caption = '&Value' Caption = '&Value'
FocusControl = EValue FocusControl = EValue
@ -50,8 +50,8 @@ object NewStringForm: TNewStringForm
end end
object BPNewString: TButtonPanel object BPNewString: TButtonPanel
Left = 6 Left = 6
Height = 37 Height = 42
Top = 97 Top = 92
Width = 308 Width = 308
OKButton.Name = 'OKButton' OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True OKButton.DefaultCaption = True

View File

@ -85,6 +85,7 @@
<Filename Value="frmcreatecode.pp"/> <Filename Value="frmcreatecode.pp"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ComponentName Value="CreateCodeForm"/> <ComponentName Value="CreateCodeForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
</Unit6> </Unit6>
</Units> </Units>

View File

@ -101,6 +101,14 @@ msgstr "Objekt (%d prvků)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Uložit změny" msgstr "Uložit změny"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -99,6 +99,14 @@ msgstr ""
msgid "Save the changes" msgid "Save the changes"
msgstr "Änderungen speichern" msgstr "Änderungen speichern"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -98,6 +98,14 @@ msgstr "Objeto (%d miembros)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Guardar los cambios" msgstr "Guardar los cambios"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -90,6 +90,14 @@ msgstr "Olio (%d jäsentä)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Tallenna muutokset" msgstr "Tallenna muutokset"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -97,6 +97,14 @@ msgstr "Objet (%d membres)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Enregistrer les changements" msgstr "Enregistrer les changements"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -100,6 +100,14 @@ msgstr "Objektum (%d tag)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Változások mentése" msgstr "Változások mentése"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -101,6 +101,14 @@ msgstr "Oggetto (%d membri)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Salva i cambiamenti" msgstr "Salva i cambiamenti"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -101,6 +101,14 @@ msgstr "Objektas (narių: %d)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Įrašyti pakeitimus" msgstr "Įrašyti pakeitimus"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -84,6 +84,14 @@ msgstr ""
msgid "Save the changes" msgid "Save the changes"
msgstr "" msgstr ""
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -100,6 +100,14 @@ msgstr "Objeto (%d membros)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Salvar as alterações" msgstr "Salvar as alterações"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -96,6 +96,14 @@ msgstr "Объект (%d элементов)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Сохранить изменения" msgstr "Сохранить изменения"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -98,6 +98,14 @@ msgstr "Об'єкт (%d членів)"
msgid "Save the changes" msgid "Save the changes"
msgstr "Зберегти зміни" msgstr "Зберегти зміни"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -101,6 +101,14 @@ msgstr "对象(%d members成员"
msgid "Save the changes" msgid "Save the changes"
msgstr "保存更改" msgstr "保存更改"
#: msgjsonviewer.stabcaptionraw
msgid "Raw"
msgstr ""
#: msgjsonviewer.stabcaptionvisual
msgid "Visual"
msgstr ""
#: tcreatecodeform.caption #: tcreatecodeform.caption
msgctxt "tcreatecodeform.caption" msgctxt "tcreatecodeform.caption"
msgid "Create pascal code" msgid "Create pascal code"

View File

@ -29,7 +29,8 @@ Resourcestring
SSaveData = 'Save the changes'; SSaveData = 'Save the changes';
SCancelClose = 'Do not close the window'; SCancelClose = 'Do not close the window';
SCancelPaste = 'Do not paste the new data'; SCancelPaste = 'Do not paste the new data';
STabCaptionRaw = 'Raw';
STabCaptionVisual = 'Visual';
implementation implementation
end. end.