Skip to content
Permalink
Browse files

Issue #140:

* store tab setup when application exits, as the TimerStoreTabs interval may not yet be reached
* remember startup value of asRestoreTabs option, which may change while the application runs, which in turn may cause problems when RestoreTabs wasn't called
  • Loading branch information...
ansgarbecker committed Apr 13, 2019
1 parent f5734fe commit e9cc528632551b298e246836dc9fce9e19a31be8
Showing with 15 additions and 3 deletions.
  1. +7 −0 source/apphelpers.pas
  2. +8 −3 source/main.pas
@@ -200,6 +200,7 @@ TAppSettings = class(TObject)
FSessionPath: String;
FRegistry: TRegistry;
FPortableMode: Boolean;
FRestoreTabsInitValue: Boolean;
FSettingsFile: String;
FSettings: Array[TAppSettingIndex] of TAppSetting;
procedure InitSetting(Index: TAppSettingIndex; Name: String;
@@ -250,6 +251,8 @@ TAppSettings = class(TObject)
function DirnameUserDocuments: String;
function DirnameSnippets: String;
function DirnameBackups: String;
// "Static" options, initialized in OnCreate only. For settings which need a restart to take effect.
property RestoreTabsInitValue: Boolean read FRestoreTabsInitValue;
end;


@@ -3683,6 +3686,10 @@ constructor TAppSettings.Create;
InitSetting(asPreferencesWindowWidth, 'PreferencesWindowWidth', 740);
InitSetting(asPreferencesWindowHeight, 'PreferencesWindowHeight', 500);
InitSetting(asFileDialogEncoding, 'FileDialogEncoding_%s', 0);

// Initialization values
FRestoreTabsInitValue := ReadBool(asRestoreTabs);

end;


@@ -1537,6 +1537,11 @@ procedure TMainForm.FormDestroy(Sender: TObject);

StoreLastSessions;

// Store tab setup for the last time, before tabs are destroyed
if TimerStoreTabs.Enabled then begin
TimerStoreTabs.OnTimer(Sender);
end;

// Some grid editors access the registry - be sure these are gone before freeing AppSettings
QueryTabs.Clear;
DataGrid.EndEditNode;
@@ -2105,7 +2110,7 @@ procedure TMainForm.AfterFormCreate;
end;

// Restore backup'ed query tabs
if AppSettings.ReadBool(asRestoreTabs) then begin
if AppSettings.RestoreTabsInitValue then begin
RestoreTabs;
TimerStoreTabs.Enabled := True;
end;
@@ -11165,7 +11170,7 @@ function TMainForm.ConfirmTabClear(PageIndex: Integer; AppIsClosing: Boolean): B
msg := f_('Save changes to file %s ?', [Tab.MemoFilename])
else
msg := f_('Save content of tab "%s"?', [Trim(Tab.TabSheet.Caption)]);
if AppSettings.ReadBool(asRestoreTabs) and AppIsClosing then begin
if AppSettings.RestoreTabsInitValue and AppIsClosing then begin
msg := msg + CRLF + CRLF + _('Your code is saved anyway, as auto-restoring is activated.');
end;

@@ -11193,7 +11198,7 @@ function TMainForm.ConfirmTabClear(PageIndex: Integer; AppIsClosing: Boolean): B
end;

// Auto-backup logic
if AppSettings.ReadBool(asRestoreTabs) then begin
if AppSettings.RestoreTabsInitValue then begin
if AppIsClosing then begin
// Do last backup before app closes
Tab.BackupUnsavedContent;

0 comments on commit e9cc528

Please sign in to comment.
You can’t perform that action at this time.