Skip to content

Commit

Permalink
Backups refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jul 22, 2023
1 parent 748b8d0 commit 76086a6
Show file tree
Hide file tree
Showing 12 changed files with 386 additions and 237 deletions.
9 changes: 8 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
<PackageName Value="LCL"/>
</Item4>
</RequiredPackages>
<Units Count="133">
<Units Count="134">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -934,6 +934,13 @@
<Filename Value="components/simba.component_buttonpanel.pas"/>
<IsPartOfProject Value="True"/>
</Unit132>
<Unit133>
<Filename Value="forms/simba.backupsform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SimbaBackupsForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
</Unit133>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
30 changes: 9 additions & 21 deletions Source/Simba.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,15 @@

uses
simba.init,
classes, sysutils, interfaces, forms, lazlogger,
simba.settings, simba.main, simba.aboutform, simba.debugimageform,
simba.bitmaptostringform, simba.functionlistform, simba.scripttabsform,
simba.outputform, simba.colorpickerhistoryform, simba.filebrowserform,
simba.notesform, simba.settingsform, simba.associate, simba.openexampleform,
simba.scriptthread, simba.package_form, simba.mufasatypes, simba.shapeboxform,
Classes, SysUtils, Interfaces, Forms, LazLogger,
simba.mufasatypes, simba.main,
simba.aboutform, simba.debugimageform, simba.bitmaptostringform,
simba.functionlistform, simba.scripttabsform, simba.outputform,
simba.colorpickerhistoryform, simba.filebrowserform, simba.notesform,
simba.settingsform, simba.associate, simba.openexampleform,
simba.package_form, simba.shapeboxform, simba.backupsform,
simba.compiler_dump, simba.plugin_dump,
simba.ide_analytics, simba.ide_codetools_setup, simba.ide_codetools_insight;

type
TApplicationHelper = class helper for TApplication
procedure DebugLnSilent(Sender: TObject; S: string; var Handled: Boolean);
end;

procedure TApplicationHelper.DebugLnSilent(Sender: TObject; S: string; var Handled: Boolean);
begin
Handled := True;
end;
simba.scriptthread;

begin
{$IF DECLARED(SetHeapTraceOutput)}
Expand Down Expand Up @@ -83,10 +74,6 @@ procedure TApplicationHelper.DebugLnSilent(Sender: TObject; S: string; var Handl
Halt();
end;

//DebugLogger.CloseLogFileBetweenWrites := True;
//if Application.HasOption('silent') then
// DebugLogger.OnDebugLn := @Application.DebugLnSilent;

if (not Application.HasOption('open')) and (Application.HasOption('run') or Application.HasOption('compile')) then
begin
if not FileExists(Application.Params[Application.ParamCount]) then
Expand Down Expand Up @@ -126,6 +113,7 @@ procedure TApplicationHelper.DebugLnSilent(Sender: TObject; S: string; var Handl
Application.CreateForm(TSimbaColorPickerHistoryForm, SimbaColorPickerHistoryForm);
Application.CreateForm(TSimbaPackageForm, SimbaPackageForm);
Application.CreateForm(TSimbaShapeBoxForm, SimbaShapeBoxForm);
Application.CreateForm(TSimbaBackupsForm, SimbaBackupsForm);

Application.QueueAsyncCall(@SimbaForm.Setup, 0);
end;
Expand Down
41 changes: 41 additions & 0 deletions Source/forms/simba.backupsform.lfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
object SimbaBackupsForm: TSimbaBackupsForm
Left = 1333
Height = 450
Top = 543
Width = 739
Caption = 'SimbaBackupsForm'
ClientHeight = 450
ClientWidth = 739
DesignTimePPI = 120
OnCreate = FormCreate
OnShow = FormShow
Position = poMainFormCenter
ShowInTaskBar = stAlways
LCLVersion = '2.2.4.0'
object LeftPanel: TPanel
Left = 0
Height = 450
Top = 0
Width = 213
Align = alLeft
BevelOuter = bvNone
TabOrder = 0
end
object Splitter: TSplitter
Left = 213
Height = 450
Top = 0
Width = 6
OnPaint = SplitterPaint
end
object RightPanel: TPanel
Left = 219
Height = 450
Top = 0
Width = 520
Align = alClient
BevelOuter = bvNone
Caption = '(no file selected)'
TabOrder = 2
end
end
168 changes: 168 additions & 0 deletions Source/forms/simba.backupsform.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.backupsform;

{$i simba.inc}

interface

uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, Zipper,
simba.editor, simba.component_treeview, simba.component_buttonpanel;

type
TSimbaBackupsForm = class(TForm)
LeftPanel: TPanel;
RightPanel: TPanel;
Splitter: TSplitter;
ButtonPanel: TSimbaButtonPanel;

procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SplitterPaint(Sender: TObject);
procedure DoSplitterEnterExit(Sender: TObject);
procedure DoTreeViewSelectionChanged(Sender: TObject);
procedure DoButtonOkClick(Sender: TObject);
procedure DoCreateStream(Sender : TObject; var AStream: TStream; AItem: TFullZipFileEntry);
procedure DoDoneStream(Sender : TObject; var AStream : TStream; AItem : TFullZipFileEntry);
procedure AddBackups;
private
TreeView: TSimbaTreeView;
Editor: TSimbaEditor;
CurrentNode: TTreeNode;
end;

var
SimbaBackupsForm: TSimbaBackupsForm;

implementation

{$R *.lfm}

uses
AnchorDocking,
simba.env, simba.files, simba.theme, simba.main, simba.scripttabsform;

type
TBackupNode = class(TTreeNode)
public
Contents: String;
end;

procedure TSimbaBackupsForm.FormShow(Sender: TObject);
begin
Splitter.Width := DockMaster.SplitterWidth;
TreeView.Clear();
AddBackups();
end;

procedure TSimbaBackupsForm.SplitterPaint(Sender: TObject);
begin
with TSplitter(Sender) do
begin
Canvas.Brush.Color := SimbaTheme.ColorFrame;
Canvas.FillRect(ClientRect);

if MouseInClient then
begin
Canvas.Brush.Color := SimbaTheme.ColorActive;
Canvas.FillRect(3, 3, Width-3, Height-3);
end;
end;
end;

procedure TSimbaBackupsForm.DoSplitterEnterExit(Sender: TObject);
begin
TSplitter(Sender).Invalidate();
end;

procedure TSimbaBackupsForm.DoTreeViewSelectionChanged(Sender: TObject);
var
Node: TBackupNode;
begin
Node := TBackupNode(TreeView.Selected);
if (Node is TBackupNode) then
begin
Editor.Text := Node.Contents;
Editor.Visible := True;
end else
Editor.Visible := False;
end;

procedure TSimbaBackupsForm.DoButtonOkClick(Sender: TObject);
begin
if Editor.Visible then
begin
SimbaScriptTabsForm.AddTab().Editor.Text := Editor.Text;
if (Sender is TTreeView) then
Close();
end;
end;

procedure TSimbaBackupsForm.DoCreateStream(Sender: TObject; var AStream: TStream; AItem: TFullZipFileEntry);
begin
AStream := TStringStream.Create();
end;

procedure TSimbaBackupsForm.DoDoneStream(Sender: TObject; var AStream: TStream; AItem: TFullZipFileEntry);
begin
with TreeView.AddNode(CurrentNode, FormatDateTime('c', AItem.DateTime), IMAGE_FILE) as TBackupNode do
Contents := TStringStream(AStream).DataString;

AStream.Free();
end;

procedure TSimbaBackupsForm.AddBackups;
var
FileName: String;
UnZipper: TUnZipper;
begin
for FileName in TSimbaDir.DirSearch(SimbaEnv.BackupsPath, '*.zip') do
begin
CurrentNode := TreeView.AddNode(TSimbaPath.PathExtractNameWithoutExt(FileName), IMAGE_DIRECTORY);

UnZipper := TUnZipper.Create();
try
UnZipper.FileName := FileName;
UnZipper.Examine();
UnZipper.OnCreateStream := @DoCreateStream;
UnZipper.OnDoneStream := @DoDoneStream;
UnZipper.UnZipAllFiles();
except
end;
UnZipper.Free();
end;
end;

procedure TSimbaBackupsForm.FormCreate(Sender: TObject);
begin
Width := Scale96ToScreen(800);
Height := Scale96ToScreen(600);

Editor := TSimbaEditor.Create(Self);
Editor.Parent := RightPanel;
Editor.Align := alClient;
Editor.Visible := False;

TreeView := TSimbaTreeView.Create(Self, TBackupNode);
TreeView.Parent := LeftPanel;
TreeView.Align := alClient;
TreeView.OnSelectionChange := @DoTreeViewSelectionChanged;
TreeView.OnDoubleClick := @DoButtonOkClick;

RightPanel.Color := SimbaTheme.ColorBackground;
RightPanel.Font.Color := SimbaTheme.ColorFont;

ButtonPanel := TSimbaButtonPanel.Create(Self);
ButtonPanel.Parent := Self;
ButtonPanel.ButtonOk.OnClick := @DoButtonOkClick;

Splitter.OnEnter := @DoSplitterEnterExit;
Splitter.OnExit := @DoSplitterEnterExit;
end;

end.

8 changes: 6 additions & 2 deletions Source/forms/simba.main.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object SimbaForm: TSimbaForm
Left = 4202
Left = 1238
Height = 578
Top = 175
Top = 594
Width = 910
Caption = 'Simba'
ClientHeight = 578
Expand Down Expand Up @@ -2689,6 +2689,10 @@ object SimbaForm: TSimbaForm
Caption = 'Open Example ...'
OnClick = MenuNewTemplateClick
end
object MenuItemBackups: TMenuItem
Caption = 'Open Backup ...'
OnClick = MenuItemBackupsClick
end
object MenuItem8: TMenuItem
Caption = '-'
end
Expand Down
13 changes: 11 additions & 2 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ TSimbaForm = class(TForm)
MainMenuTools: TPopupMenu;
MainMenuView: TPopupMenu;
MainMenuHelp: TPopupMenu;
MenuItemBackups: TMenuItem;
MenuItemShapeBox: TMenuItem;
MenuItemDocumentation: TMenuItem;
MenuItemGithub: TMenuItem;
Expand Down Expand Up @@ -177,6 +178,7 @@ TSimbaForm = class(TForm)
procedure MenuFileClick(Sender: TObject);
procedure MenuFindClick(Sender: TObject);
procedure MenuGotoClick(Sender: TObject);
procedure MenuItemBackupsClick(Sender: TObject);
procedure MenuItemShapeBoxClick(Sender: TObject);
procedure MenuItemAboutClick(Sender: TObject);
procedure MenuItemACAClick(Sender: TObject);
Expand Down Expand Up @@ -284,7 +286,8 @@ implementation

simba.openssl, simba.env, simba.process,
simba.dockinghelpers, simba.nativeinterface,
simba.scriptformatter, simba.windowhandle, simba.scripttab, simba.theme;
simba.scriptformatter, simba.windowhandle, simba.scripttab, simba.theme,
simba.backupsform;

procedure TSimbaForm.HandleException(Sender: TObject; E: Exception);

Expand Down Expand Up @@ -605,7 +608,6 @@ procedure TSimbaForm.Setup(Data: PtrInt);
SimbaScriptTabsForm.AddTab();

SetupDocking();
SetupCompleted();

FMouseLogger := TSimbaMouseLogger.Create();
FMouseLogger.Hotkey := VK_F1;
Expand Down Expand Up @@ -640,6 +642,8 @@ procedure TSimbaForm.Setup(Data: PtrInt);
if Assigned(SimbaScriptTabsForm.CurrentEditor) then
if SimbaScriptTabsForm.CurrentEditor.CanSetFocus() then
SimbaScriptTabsForm.CurrentEditor.SetFocus();

SetupCompleted();
end;

procedure TSimbaForm.FormCreate(Sender: TObject);
Expand Down Expand Up @@ -839,6 +843,11 @@ procedure TSimbaForm.MenuGotoClick(Sender: TObject);
end;
end;

procedure TSimbaForm.MenuItemBackupsClick(Sender: TObject);
begin
SimbaBackupsForm.ShowModal();
end;

procedure TSimbaForm.MenuItemShapeBoxClick(Sender: TObject);
begin
SimbaShapeBoxForm.Show();
Expand Down
27 changes: 2 additions & 25 deletions Source/package/simba.package_autoupdater.pas
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,8 @@ procedure UpdatePackages;
implementation

uses
Menus,
simba.mufasatypes, simba.package, simba.scripttabsform, simba.main,
simba.outputform, simba.package_installer, simba.package_menubuilder;

type
TPackageMenuItem = class(TMenuItem)
public
Hash: UInt32;
end;

TPackageMenuItem_File = class(TMenuItem)
public
FileName: String;

procedure Click; override;
end;

procedure TPackageMenuItem_File.Click;
begin
if (FileName = '') then
Exit;

if SimbaScriptTabsForm.Open(FileName, True) and (Caption = 'Run') then
SimbaForm.MenuItemRun.Click();
end;
simba.mufasatypes, simba.package, simba.package_installer,
simba.main, simba.outputform, simba.package_menubuilder;

type
TPackageUpdater = class(TThread)
Expand Down
Loading

0 comments on commit 76086a6

Please sign in to comment.