From be2bdb8650ddc71bf9708d86fb22a31f35d3d6d8 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Sat, 2 Apr 2022 17:39:38 +0200 Subject: [PATCH] undo: Clear undo stack on file close The undo stack is only relevant to the dives that were loaded at the time the command was executed. If a file is closed, by specifically closing it or opening another file, then the undo commands will reference dives that aren't available anymore. Clearing the undo stack ensures that we don't crash or accidentally do some undefined modifications to the currently open file. Signed-off-by: Michael Andreen --- CHANGELOG.md | 1 + commands/command_base.cpp | 2 ++ desktop-widgets/mainwindow.cpp | 1 - 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d62abe272..ff1e802f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ - Desktop: Allow more than one media file to be imported from web +- undo: Clear undo stack when the current file is closed --- * Always add new entries at the very top of this file above other existing entries and this note. * Use this layout for new entries: `[Area]: [Details about the change] [reference thread / issue]` diff --git a/commands/command_base.cpp b/commands/command_base.cpp index 26855f0e6..745797643 100644 --- a/commands/command_base.cpp +++ b/commands/command_base.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#include "command.h" #include "command_base.h" #include "core/globals.h" #include "core/qthelper.h" // for updateWindowTitle() @@ -18,6 +19,7 @@ void init() { undoStack = make_global(); QObject::connect(undoStack, &QUndoStack::cleanChanged, &updateWindowTitle); + QObject::connect(&diveListNotifier, &DiveListNotifier::dataReset, &Command::clear); changesCallback = &changesMade; } diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 310148003..139d2fa68 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -513,7 +513,6 @@ void MainWindow::closeCurrentFile() if (!existing_filename) setTitle(); disableShortcuts(); - Command::setClean(); } void MainWindow::updateCloudOnlineStatus()