Skip to content
Permalink
Browse files

Disable tab restore/store when tabs.ini is not writable. See https://…

  • Loading branch information...
ansgarbecker committed Jul 10, 2019
1 parent fae11b7 commit 65102121bc2911d8fc4ba5f27c0cef9dc31292a4
Showing with 20 additions and 11 deletions.
  1. +8 −5 out/locale/en/LC_MESSAGES/default.po
  2. +12 −6 source/main.pas
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2019-07-10 11:01+0200\n"
"PO-Revision-Date: 2019-07-10 11:44+0200\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/language/en/)\n"
"MIME-Version: 1.0\n"
@@ -6377,8 +6377,11 @@ msgstr "Files"
msgid "Reopen previously used SQL files and unsaved content in tabs *"
msgstr "Reopen previously used SQL files and unsaved content in tabs *"

msgid "Auto-storing tab setup failed"
msgstr "Auto-storing tab setup failed"
msgid "Storing tab setup failed"
msgstr "Storing tab setup failed"

msgid "Auto-restoring tab setup failed"
msgstr "Auto-restoring tab setup failed"
msgid "Restoring tab setup failed"
msgstr "Restoring tab setup failed"

msgid "Tabs won't be stored in this session."
msgstr "Tabs won't be stored in this session."
@@ -1113,7 +1113,7 @@ TMainForm = class(TForm)
function HandleUnixTimestampColumn(Sender: TBaseVirtualTree; Column: TColumnIndex): Boolean;
function InitTabsIniFile: TIniFile;
procedure StoreTabs;
procedure RestoreTabs;
function RestoreTabs: Boolean;
public
QueryTabs: TObjectList<TQueryTab>;
ActiveObjectEditor: TDBObjectEditor;
@@ -2124,8 +2124,7 @@ procedure TMainForm.AfterFormCreate;

// Restore backup'ed query tabs
if AppSettings.RestoreTabsInitValue then begin
RestoreTabs;
TimerStoreTabs.Enabled := True;
TimerStoreTabs.Enabled := RestoreTabs;
end;

// Load SQL file(s) by command line
@@ -2163,6 +2162,10 @@ function TMainForm.InitTabsIniFile: TIniFile;
if Attempts > 0 then begin
LogSQL(Format('Had to wait %d ms before opening %s', [GetTickCount64 - WaitingSince, TabsIniFilename]), lcDebug);
end;
// Catch errors when file cannot be created
if not FileExists(TabsIniFilename) then begin
SaveUnicodeFile(TabsIniFilename, '');
end;
Result := TIniFile.Create(TabsIniFilename);
end;

@@ -2221,13 +2224,14 @@ procedure TMainForm.StoreTabs;
TabsIni.Free;
except
on E:Exception do begin
ErrorDialog(_('Auto-storing tab setup failed'), E.Message);
TimerStoreTabs.Enabled := False;
ErrorDialog(_('Storing tab setup failed'), 'Tabs won''t be stored in this session.' + CRLF + CRLF + E.Message);
end;
end;
end;


procedure TMainForm.RestoreTabs;
function TMainForm.RestoreTabs: Boolean;
var
Tab: TQueryTab;
Sections: TStringList;
@@ -2237,6 +2241,7 @@ procedure TMainForm.RestoreTabs;
EditorHeight, HelpersWidth: Integer;
begin
// Restore query tab setup from tabs.ini
Result := True;

try
TabsIni := InitTabsIniFile;
@@ -2297,7 +2302,8 @@ procedure TMainForm.RestoreTabs;
TabsIni.Free;
except
on E:Exception do begin
ErrorDialog(_('Auto-restoring tab setup failed'), E.Message);
Result := False;
ErrorDialog(_('Restoring tab setup failed'), 'Tabs won''t be stored in this session.' + CRLF + CRLF + E.Message);
end;
end;
end;

0 comments on commit 6510212

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