* 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]
end
object SynFPC: TSynFreePascalSyn
Enabled = False
CompilerMode = pcmObjFPC
NestedComments = True
left = 127

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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