Force document save when manually calling save document
This commit is contained in:
@@ -25,16 +25,16 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5.QtGui import QDesktopServices
|
|
||||||
from PyQt5.QtCore import QUrl, pyqtSignal, pyqtSlot
|
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 import CONFIG, SHARED
|
||||||
from novelwriter.common import openExternalPath
|
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.enum import nwDocAction, nwDocInsert, nwView, nwWidget
|
||||||
from novelwriter.extensions.eventfilters import StatusTipFilter
|
from novelwriter.extensions.eventfilters import StatusTipFilter
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ class GuiMainMenu(QMenuBar):
|
|||||||
# Document > Save
|
# Document > Save
|
||||||
self.aSaveDoc = self.docuMenu.addAction(self.tr("Save Document"))
|
self.aSaveDoc = self.docuMenu.addAction(self.tr("Save Document"))
|
||||||
self.aSaveDoc.setShortcut("Ctrl+S")
|
self.aSaveDoc.setShortcut("Ctrl+S")
|
||||||
self.aSaveDoc.triggered.connect(self.mainGui.saveDocument)
|
self.aSaveDoc.triggered.connect(self.mainGui.forceSaveDocument)
|
||||||
|
|
||||||
# Document > Close
|
# Document > Close
|
||||||
self.aCloseDoc = self.docuMenu.addAction(self.tr("Close Document"))
|
self.aCloseDoc = self.docuMenu.addAction(self.tr("Close Document"))
|
||||||
|
|||||||
+11
-5
@@ -575,12 +575,18 @@ class GuiMain(QMainWindow):
|
|||||||
self.openDocument(fHandle, tLine=1, doScroll=True)
|
self.openDocument(fHandle, tLine=1, doScroll=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot()
|
def saveDocument(self, force: bool = False) -> None:
|
||||||
def saveDocument(self) -> None:
|
|
||||||
"""Save the current documents."""
|
"""Save the current documents."""
|
||||||
self.docEditor.saveCursorPosition()
|
if SHARED.hasProject:
|
||||||
if SHARED.hasProject and self.docEditor.docChanged:
|
self.docEditor.saveCursorPosition()
|
||||||
self.docEditor.saveText()
|
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
|
return
|
||||||
|
|
||||||
def viewDocument(self, tHandle: str | None = None, sTitle: str | None = None) -> bool:
|
def viewDocument(self, tHandle: str | None = None, sTitle: str | None = None) -> bool:
|
||||||
|
|||||||
@@ -522,6 +522,8 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
|||||||
assert docEditor.docChanged
|
assert docEditor.docChanged
|
||||||
nwGUI.saveDocument()
|
nwGUI.saveDocument()
|
||||||
assert docEditor.docChanged is False
|
assert docEditor.docChanged is False
|
||||||
|
nwGUI.forceSaveDocument()
|
||||||
|
assert docEditor.docChanged is False
|
||||||
nwGUI.rebuildIndex()
|
nwGUI.rebuildIndex()
|
||||||
|
|
||||||
# Open and view the edited document
|
# Open and view the edited document
|
||||||
|
|||||||
Reference in New Issue
Block a user