Skip to content

Commit

Permalink
Issue #140: Erase ini section of a closed tab, in which the user load…
Browse files Browse the repository at this point in the history
…ed some physical file. Fixes wrongly restored tabs which were closed in previous session.
  • Loading branch information
ansgarbecker committed Jun 3, 2019
1 parent 6e2bca2 commit 19775ef
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions source/main.pas
Expand Up @@ -2165,16 +2165,15 @@ procedure TMainForm.StoreTabs;
var
Tab: TQueryTab;
Section: String;
Sections: TStringList;
TabsIni: TIniFile;
SectionTabExists: Boolean;
begin
// Store query tab unsaved contents and setup, in tabs.ini

try
TabsIni := InitTabsIniFile;

// Todo: erase sections from closed tabs
// ab: is that really required? Tabs with deleted files don't get restored anyway.

for Tab in QueryTabs do begin
Tab.BackupUnsavedContent;
Section := Tab.Uid;
Expand All @@ -2190,6 +2189,24 @@ procedure TMainForm.StoreTabs;
end;
end;

// Tabs with deleted files don't get restored anyway. But closed tabs with physically existing
// files still need to be erased
Sections := TStringList.Create;
TabsIni.ReadSections(Sections);
for Section in Sections do begin
SectionTabExists := False;
for Tab in QueryTabs do begin
if Tab.Uid = Section then begin
SectionTabExists := True;
Break;
end;
end;
// Delete tab section if no tab was closed
if not SectionTabExists then begin
TabsIni.EraseSection(Section);
end;
end;

// Close file
TabsIni.Free;
except
Expand Down

0 comments on commit 19775ef

Please sign in to comment.