Force document save when manually calling save document

This commit is contained in:
Veronica Berglyd Olsen
2024-05-02 22:30:58 +02:00
parent 2b8338f537
commit 917977ae13
3 changed files with 18 additions and 10 deletions
+5 -5
View File
@@ -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"))
+11 -5
View File
@@ -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:
+2
View File
@@ -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