Skip to content

Commit

Permalink
Do not close files if there are any unconfirmed changes (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonBogun authored Aug 9, 2023
1 parent 0719849 commit 991b22d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,14 @@ struct Document {
return false;
}

void RemoveTmpFile() {
if (!filename.empty() && ::wxFileExists(sys->TmpName(filename)))
::wxRemoveFile(sys->TmpName(filename));
}

bool CloseDocument() {
bool keep = CheckForChanges();
if (!keep && !filename.empty() && ::wxFileExists(sys->TmpName(filename)))
::wxRemoveFile(sys->TmpName(filename));
if (!keep) RemoveTmpFile();
return keep;
}

Expand Down
24 changes: 17 additions & 7 deletions src/myframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -1202,16 +1202,26 @@ struct MyFrame : wxFrame {
return;
}
sys->RememberOpenFiles();
int n = (int)nb->GetPageCount();
if (ce.CanVeto())
while (nb->GetPageCount()) {
if (GetCurTab()->doc->CloseDocument()) {
ce.Veto();
sys->RememberOpenFiles(); // may have closed some, but not all
return;
} else {
nb->DeletePage(nb->GetSelection());
{
// ask to save/discard all files before closing any
for (int i = 0; i < n; i++) {
TSCanvas* p = (TSCanvas*)nb->GetPage(i);
if (p->doc->modified) {
nb->SetSelection(i);
if (p->doc->CheckForChanges()) {
ce.Veto();
return;
}
}
}
// all files have been saved/discarded
while (nb->GetPageCount()) {
GetCurTab()->doc->RemoveTmpFile();
nb->DeletePage(nb->GetSelection());
}
}
bt.Stop();
sys->every_second_timer.Stop();
Destroy();
Expand Down

0 comments on commit 991b22d

Please sign in to comment.