Skip to content

Commit 5704850

Browse files
committed
Merge branch 'feature/issue#45-move-database-bug' into develop
2 parents d20d9fd + d159398 commit 5704850

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

Src/DB.USnippet.pas

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2011-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2011-2022, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Objects, records etc that encapsulate a code snippet, its data and lists of
99
* code snippets.
@@ -328,10 +328,17 @@ TSnippetList = class(TObject)
328328
{Counts number of snippets in list.
329329
@return Number of snippets in list.
330330
}
331-
function IsEmpty: Boolean; inline;
331+
function IsEmpty: Boolean; overload; inline;
332332
{Checks if list is empty.
333333
@return True if list is empty, False otehrwise.
334334
}
335+
function IsEmpty(const UserDefined: Boolean): Boolean; overload; inline;
336+
{Checks if sub-set of list from either from or not from use defined
337+
database is empty.
338+
@param UserDefined [in] Flags whether to check for snippets in user
339+
database (True) or in main database (False).
340+
@return True if required subset is empty, False if not empty.
341+
}
335342
property Items[Idx: Integer]: TSnippet read GetItem; default;
336343
{List of snippets}
337344
end;
@@ -764,6 +771,11 @@ function TSnippetList.IsEmpty: Boolean;
764771
Result := Count = 0;
765772
end;
766773

774+
function TSnippetList.IsEmpty(const UserDefined: Boolean): Boolean;
775+
begin
776+
Result := Count(UserDefined) = 0;
777+
end;
778+
767779
function TSnippetList.IsEqual(const AList: TSnippetList): Boolean;
768780
{Checks if this list contains same snippets as another list.
769781
@param AList [in] List of snippets to compare.

Src/FmMain.dfm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ inherited MainForm: TMainForm
619619
Hint = 'Backup user database|Backup the user-defined snippet database'
620620
ImageIndex = 33
621621
OnExecute = actBackupDatabaseExecute
622+
OnUpdate = ActNonEmptyUserDBUpdate
622623
end
623624
object actRestoreDatabase: TAction
624625
Category = 'Database'
@@ -849,6 +850,7 @@ inherited MainForm: TMainForm
849850
'Move user database|Move the user-defined snippet database to a n' +
850851
'ew directory'
851852
OnExecute = actMoveUserDatabaseExecute
853+
OnUpdate = ActNonEmptyUserDBUpdate
852854
end
853855
object actSWAGImport: TAction
854856
Category = 'Snippets'
@@ -873,6 +875,7 @@ inherited MainForm: TMainForm
873875
'Delete User Database|Deletes the user'#39's snippets database - USE ' +
874876
'WITH CAUTION'
875877
OnExecute = actDeleteUserDatabaseExecute
878+
OnUpdate = ActNonEmptyUserDBUpdate
876879
end
877880
end
878881
object mnuMain: TMainMenu

Src/FmMain.pas

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ TMainForm = class(THelpAwareForm)
495495
/// position is permitted and blocks the move if not.</summary>
496496
procedure splitVertCanResize(Sender: TObject; var NewSize: Integer;
497497
var Accept: Boolean);
498+
procedure ActNonEmptyUserDBUpdate(Sender: TObject);
498499
strict private
499500
var
500501
/// <summary>Object that notifies user-initiated events by triggering
@@ -621,7 +622,10 @@ procedure TMainForm.actAddSnippetExecute(Sender: TObject);
621622

622623
procedure TMainForm.actBackupDatabaseExecute(Sender: TObject);
623624
begin
625+
if (Database as IDatabaseEdit).Updated then
626+
TUserDBMgr.Save(Self);
624627
TUserDBMgr.BackupDatabase(Self);
628+
fStatusBarMgr.Update;
625629
end;
626630

627631
procedure TMainForm.actBugReportExecute(Sender: TObject);
@@ -721,8 +725,13 @@ procedure TMainForm.actDeleteSnippetExecute(Sender: TObject);
721725

722726
procedure TMainForm.actDeleteUserDatabaseExecute(Sender: TObject);
723727
begin
728+
if (Database as IDatabaseEdit).Updated then
729+
TUserDBMgr.Save(Self);
724730
if TUserDBMgr.DeleteDatabase then
731+
begin
725732
ReloadDatabase;
733+
fStatusBarMgr.Update;
734+
end;
726735
end;
727736

728737
procedure TMainForm.actDuplicateSnippetExecute(Sender: TObject);
@@ -902,6 +911,8 @@ procedure TMainForm.actLoadSelectionExecute(Sender: TObject);
902911

903912
procedure TMainForm.actMoveUserDatabaseExecute(Sender: TObject);
904913
begin
914+
if (Database as IDatabaseEdit).Updated then
915+
TUserDBMgr.Save(Self);
905916
TUserDBMgr.MoveDatabase;
906917
end;
907918

@@ -920,6 +931,11 @@ procedure TMainForm.ActNonEmptyDBUpdate(Sender: TObject);
920931
(Sender as TAction).Enabled := not Database.Snippets.IsEmpty;
921932
end;
922933

934+
procedure TMainForm.ActNonEmptyUserDBUpdate(Sender: TObject);
935+
begin
936+
(Sender as TAction).Enabled := not Database.Snippets.IsEmpty(True);
937+
end;
938+
923939
procedure TMainForm.ActOverviewTabExecute(Sender: TObject);
924940
begin
925941
// Action's Tag property specifies index of tab being selected
@@ -979,7 +995,10 @@ procedure TMainForm.actRenameCategoryUpdate(Sender: TObject);
979995
procedure TMainForm.actRestoreDatabaseExecute(Sender: TObject);
980996
begin
981997
if TUserDBMgr.RestoreDatabase(Self) then
998+
begin
982999
ReloadDatabase;
1000+
fStatusBarMgr.Update;
1001+
end;
9831002
end;
9841003

9851004
procedure TMainForm.actSaveDatabaseExecute(Sender: TObject);

0 commit comments

Comments
 (0)