diff --git a/novelwriter/gui/mainmenu.py b/novelwriter/gui/mainmenu.py index 7d6b05cf..6ac50c19 100644 --- a/novelwriter/gui/mainmenu.py +++ b/novelwriter/gui/mainmenu.py @@ -25,16 +25,16 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING from pathlib import Path +from typing import TYPE_CHECKING -from PyQt5.QtGui import QDesktopServices from PyQt5.QtCore import QUrl, pyqtSignal, pyqtSlot -from PyQt5.QtWidgets import QMenuBar, QAction +from PyQt5.QtGui import QDesktopServices +from PyQt5.QtWidgets import QAction, QMenuBar from novelwriter import CONFIG, SHARED from novelwriter.common import openExternalPath -from novelwriter.constants import nwConst, trConst, nwKeyWords, nwLabels, nwUnicode +from novelwriter.constants import nwConst, nwKeyWords, nwLabels, nwUnicode, trConst from novelwriter.enum import nwDocAction, nwDocInsert, nwView, nwWidget from novelwriter.extensions.eventfilters import StatusTipFilter @@ -202,7 +202,7 @@ class GuiMainMenu(QMenuBar): # Document > Save self.aSaveDoc = self.docuMenu.addAction(self.tr("Save Document")) self.aSaveDoc.setShortcut("Ctrl+S") - self.aSaveDoc.triggered.connect(self.mainGui.saveDocument) + self.aSaveDoc.triggered.connect(self.mainGui.forceSaveDocument) # Document > Close self.aCloseDoc = self.docuMenu.addAction(self.tr("Close Document")) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index 71b061b2..e35699e8 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -575,12 +575,18 @@ class GuiMain(QMainWindow): self.openDocument(fHandle, tLine=1, doScroll=True) return - @pyqtSlot() - def saveDocument(self) -> None: + def saveDocument(self, force: bool = False) -> None: """Save the current documents.""" - self.docEditor.saveCursorPosition() - if SHARED.hasProject and self.docEditor.docChanged: - self.docEditor.saveText() + if SHARED.hasProject: + self.docEditor.saveCursorPosition() + if force or self.docEditor.docChanged: + self.docEditor.saveText() + return + + @pyqtSlot() + def forceSaveDocument(self) -> None: + """Save document even of it has not changed.""" + self.saveDocument(force=True) return def viewDocument(self, tHandle: str | None = None, sTitle: str | None = None) -> bool: diff --git a/tests/test_gui/test_gui_guimain.py b/tests/test_gui/test_gui_guimain.py index 202d829b..2a2205e8 100644 --- a/tests/test_gui/test_gui_guimain.py +++ b/tests/test_gui/test_gui_guimain.py @@ -522,6 +522,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd): assert docEditor.docChanged nwGUI.saveDocument() assert docEditor.docChanged is False + nwGUI.forceSaveDocument() + assert docEditor.docChanged is False nwGUI.rebuildIndex() # Open and view the edited document