Skip to content

Commit

Permalink
feat: Drag-and-Drop files implemented.
Browse files Browse the repository at this point in the history
- Also, for windows, create App Config Dir if non existent.

Closes: #11
  • Loading branch information
gcarreno committed Feb 2, 2021
1 parent 199ee21 commit ba6cafa
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/application/ljv.application.version.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
interface

const
cVersion = '0.1.5.27';
cVersion = '0.1.6.28';
cVersionMajor = 0;
cVersionMinor = 1;
cVersionRevision = 5;
cVersionBuild = 27;
cVersionRevision = 6;
cVersionBuild = 28;

implementation

Expand Down
35 changes: 22 additions & 13 deletions src/forms/ljv.forms.main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ object frmMain: TfrmMain
Left = 338
Height = 563
Top = 250
Width = 1017
Width = 1021
AllowDropFiles = True
Caption = 'frmMain'
ClientHeight = 563
ClientWidth = 1017
ClientWidth = 1021
OnCreate = FormCreate
OnDestroy = FormDestroy
OnDropFiles = FormDropFiles
SessionProperties = 'Top;Left;Height;Width;WindowState'
object psMain: TPairSplitter
Cursor = crDefault
Left = 224
Height = 563
Top = 0
Width = 793
Width = 797
Align = alClient
Position = 400
object pssTree: TPairSplitterSide
Expand Down Expand Up @@ -51,17 +53,17 @@ object frmMain: TfrmMain
Left = 405
Height = 563
Top = 0
Width = 388
ClientWidth = 388
Width = 392
ClientWidth = 392
ClientHeight = 563
object panItem: TPanel
Left = 0
Height = 80
Top = 0
Width = 388
Width = 392
Align = alTop
ClientHeight = 80
ClientWidth = 388
ClientWidth = 392
TabOrder = 0
object lblType: TLabel
Left = 8
Expand Down Expand Up @@ -90,13 +92,20 @@ object frmMain: TfrmMain
end
object panValue: TPanel
Left = 0
Height = 475
Top = 88
Width = 388
Align = alBottom
Height = 451
Top = 112
Width = 392
Anchors = [akTop, akLeft, akRight, akBottom]
TabOrder = 1
end
object lblValue: TLabel
Left = 0
Height = 17
Top = 88
Width = 54
Caption = 'lblValue'
ParentColor = False
end
end
end
object lbFiles: TListBox
Expand All @@ -123,7 +132,7 @@ object frmMain: TfrmMain
StoredValues = <>
Formatted = False
Active = False
Left = 768
Top = 400
Left = 80
Top = 464
end
end
3 changes: 2 additions & 1 deletion src/forms/ljv.forms.main.lrj
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
{"hash":227686302,"name":"tfrmmain.caption","sourcebytes":[102,114,109,77,97,105,110],"value":"frmMain"},
{"hash":43106325,"name":"tfrmmain.lbltype.caption","sourcebytes":[108,98,108,84,121,112,101],"value":"lblType"},
{"hash":43075653,"name":"tfrmmain.lblname.caption","sourcebytes":[108,98,108,78,97,109,101],"value":"lblName"},
{"hash":151678324,"name":"tfrmmain.lblcount.caption","sourcebytes":[108,98,108,67,111,117,110,116],"value":"lblCount"}
{"hash":151678324,"name":"tfrmmain.lblcount.caption","sourcebytes":[108,98,108,67,111,117,110,116],"value":"lblCount"},
{"hash":152863893,"name":"tfrmmain.lblvalue.caption","sourcebytes":[108,98,108,86,97,108,117,101],"value":"lblValue"}
]}
74 changes: 59 additions & 15 deletions src/forms/ljv.forms.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ interface
{ TfrmMain }

TfrmMain = class(TForm)
lblValue: TLabel;
panValue: TPanel;
JSONPropStorage: TJSONPropStorage;
lblCount: TLabel;
lblName: TLabel;
Expand All @@ -55,10 +57,10 @@ TfrmMain = class(TForm)
pssNode: TPairSplitterSide;
Splitter1: TSplitter;
vstJSON: TVirtualStringTree;
panValue: TPanel;
panItem: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
procedure lbFilesSelectionChange(Sender: TObject; User: boolean);
procedure vstJSONChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vstJSONGetNodeDataSize(Sender: TBaseVirtualTree;
Expand All @@ -69,6 +71,8 @@ TfrmMain = class(TForm)
FJSON: TJSONData;
FFileList: Array of String;

procedure AddFile(const AFilename: String);
procedure ClearTree;
function FormatBytes(ABytes: Int64): String;

procedure SetupPropStorage;
Expand Down Expand Up @@ -119,6 +123,7 @@ implementation
rsLabelCountObject = 'Members: %d';
rsLabelCountNA = 'N/A';

rsCaptionValue = 'Value';
rsLabelFormated = 'Formated';
rsLabelBinary = 'Binary';
rsLabelHexadecimal = 'Hexadecimal';
Expand Down Expand Up @@ -156,6 +161,7 @@ procedure TfrmMain.FormCreate(Sender: TObject);
begin
SetupPropStorage;
Caption:= Format(rsFormCaption, [cVersion]);
lblValue.Caption:= rsCaptionValue;
ClearLabels;
CorrectPSCursor;
ProcessParams;
Expand All @@ -179,6 +185,20 @@ procedure TfrmMain.FormDestroy(Sender: TObject);
ShutdownPropStorage;
end;

procedure TfrmMain.FormDropFiles(Sender: TObject;
const FileNames: array of string);
var
filename: String;
begin
for filename in FileNames do
begin
AddFile(filename);
end;
UpdateFileList;
ClearTree;
ClearLabels;
end;

procedure TfrmMain.lbFilesSelectionChange(Sender: TObject; User: boolean);
var
index: Integer;
Expand Down Expand Up @@ -499,8 +519,41 @@ function TfrmMain.FormatBytes(ABytes: Int64): String;
end;
end;

procedure TfrmMain.AddFile(const AFilename: String);
var
len: Integer;
begin
if Pos('*', AFilename) > 0 then
begin
// Get all files
end
else
begin
if FileExists(AFilename) then
begin
len:= Length(FFileList);
SetLength(FFileList, len + 1);
FFileList[len]:= AFilename;
end;
end;
end;

procedure TfrmMain.ClearTree;
begin
if vstJSON.RootNodeCount > 0 then
begin
vstJSON.BeginUpdate;
vstJSON.Clear;
vstJSON.EndUpdate;
end;
end;

procedure TfrmMain.SetupPropStorage;
begin
if not DirectoryExists(GetAppConfigDir(False)) then
begin
CreateDir(GetAppConfigDir(False));
end;
JSONPropStorage.JSONFileName:= GetAppConfigFile(False);
JSONPropStorage.RootObjectPath:= 'Application';
JSONPropStorage.Active:= True;
Expand Down Expand Up @@ -528,34 +581,25 @@ procedure TfrmMain.ClearLabels;
procedure TfrmMain.ProcessParams;
var
index: Integer;
len: Integer;
params: Integer;
param: String;
begin
params:= ParamCount;
for index:= 1 to params do
begin
param:=ParamStr(index);
if Pos('*', param) > 0 then
begin
// Get all files
end
else
begin
if FileExists(param) then
begin
len:= Length(FFileList);
SetLength(FFileList, len + 1);
FFileList[len]:= param;
end;
end;
AddFile(param);
end;
end;

procedure TfrmMain.UpdateFileList;
var
filename: String;
begin
if lbFiles.Count > 0 then
begin
lbFiles.Clear;
end;
for filename in FFileList do
begin
lbFiles.Items.Add(ExtractFileName(filename));
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pot
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ msgstr ""
msgid " B"
msgstr ""

#: ljv.forms.main.rscaptionvalue
msgid "Value"
msgstr ""

#: ljv.forms.main.rsformcaption
#, object-pascal-format
msgid "JSON Viewer v%s"
Expand Down Expand Up @@ -171,3 +175,7 @@ msgstr ""
msgid "lblType"
msgstr ""

#: tfrmmain.lblvalue.caption
msgid "lblValue"
msgstr ""

8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pt.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ msgstr ""
msgid " B"
msgstr " B"

#: ljv.forms.main.rscaptionvalue
msgid "Value"
msgstr "Valor"

#: ljv.forms.main.rsformcaption
#, object-pascal-format
msgid "JSON Viewer v%s"
Expand Down Expand Up @@ -172,3 +176,7 @@ msgstr "lblName"
msgid "lblType"
msgstr "lblType"

#: tfrmmain.lblvalue.caption
msgid "lblValue"
msgstr ""

8 changes: 8 additions & 0 deletions src/i18n/lazJSONViewer.pt_PT.po
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ msgstr ""
msgid " B"
msgstr " B"

#: ljv.forms.main.rscaptionvalue
msgid "Value"
msgstr "Valor"

#: ljv.forms.main.rsformcaption
#, object-pascal-format
msgid "JSON Viewer v%s"
Expand Down Expand Up @@ -172,3 +176,7 @@ msgstr "lblName"
msgid "lblType"
msgstr "lblType"

#: tfrmmain.lblvalue.caption
msgid "lblValue"
msgstr ""

6 changes: 4 additions & 2 deletions src/lazJSONViewer.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<VersionInfo>
<UseVersionInfo Value="True"/>
<MinorVersionNr Value="1"/>
<RevisionNr Value="5"/>
<BuildNr Value="27"/>
<RevisionNr Value="6"/>
<BuildNr Value="28"/>
<Language Value="0809"/>
</VersionInfo>
<BuildModes Count="4">
Expand Down Expand Up @@ -170,10 +170,12 @@
<Unit2>
<Filename Value="tree/ljv.tree.nodes.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="LJV.Tree.Nodes"/>
</Unit2>
<Unit3>
<Filename Value="json/ljv.json.utils.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="LJV.JSON.Utils"/>
</Unit3>
<Unit4>
<Filename Value="application/ljv.application.version.pas"/>
Expand Down

0 comments on commit ba6cafa

Please sign in to comment.