Skip to content

Commit 4d2e8a3

Browse files
committed
Avoid having shapes finalized if a document close operation is cancelled
1 parent 9fe48ac commit 4d2e8a3

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

Pinta.Core/Managers/WorkspaceManager.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,14 @@ public void SetActiveDocument (
382382
actions.Window.SetActiveDocument (open_documents[index]);
383383
}
384384

385-
internal void SetActiveDocumentInternal (
386-
ToolManager tools,
387-
Document document)
385+
internal void SetActiveDocumentInternal (
386+
ToolManager tools,
387+
Document document,
388+
bool suppressCommit = false)
388389
{
389390
// Work around a case where we closed a document but haven't updated
390391
// the active_document_index yet and it points to the closed document
391-
if (HasOpenDocuments && active_document_index != -1 && open_documents.Count > active_document_index)
392+
if (!suppressCommit && HasOpenDocuments && active_document_index != -1 && open_documents.Count > active_document_index)
392393
tools.Commit ();
393394

394395
int index = open_documents.IndexOf (document);
@@ -397,6 +398,13 @@ internal void SetActiveDocumentInternal (
397398
OnActiveDocumentChanged (EventArgs.Empty);
398399
}
399400

401+
public void SetActiveDocumentForClose (Document document)
402+
{
403+
// Sets the active document in preparation for closing it. This avoids committing
404+
// tool state when switching, so canceling the close will not finalize editable shapes, for example.
405+
SetActiveDocumentInternal (PintaCore.Tools, document, suppressCommit: true);
406+
}
407+
400408
private void OnActiveDocumentChanged (EventArgs _)
401409
{
402410
ActiveDocumentChanged?.Invoke (this, EventArgs.Empty);

Pinta/MainWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void DockNotebook_TabClosed (object? sender, TabClosedEventArgs e)
150150
if (PintaCore.Workspace.OpenDocuments.IndexOf (view.Document) < 0)
151151
return;
152152

153-
PintaCore.Actions.Window.SetActiveDocument (view.Document);
153+
PintaCore.Workspace.SetActiveDocumentForClose (view.Document);
154154
PintaCore.Actions.File.Close.Activate ();
155155

156156
if (PintaCore.Workspace.OpenDocuments.IndexOf (view.Document) < 0)

0 commit comments

Comments
 (0)