diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 7ed3fab7..97b336c1 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -477,7 +477,6 @@ class GuiDocEditor(QPlainTextEdit): cC, wC, pC = standardCounter(docText) self._updateDocCounts(cC, wC, pC) - self.saveCursorPosition() if not self._nwDocument.writeDocument(docText): saveOk = False if self._nwDocument.hashError: diff --git a/novelwriter/gui/projtree.py b/novelwriter/gui/projtree.py index 8074325b..ddb03f5e 100644 --- a/novelwriter/gui/projtree.py +++ b/novelwriter/gui/projtree.py @@ -32,10 +32,8 @@ from enum import Enum from time import time from typing import TYPE_CHECKING -from PyQt5.QtCore import QPoint, QTimer, Qt, pyqtSignal, pyqtSlot -from PyQt5.QtGui import ( - QDragEnterEvent, QDragMoveEvent, QDropEvent, QIcon, QMouseEvent, QPalette -) +from PyQt5.QtCore import QPoint, Qt, QTimer, pyqtSignal, pyqtSlot +from PyQt5.QtGui import QDragEnterEvent, QDragMoveEvent, QDropEvent, QIcon, QMouseEvent, QPalette from PyQt5.QtWidgets import ( QAbstractItemView, QAction, QDialog, QFrame, QHBoxLayout, QHeaderView, QLabel, QMenu, QShortcut, QTreeWidget, QTreeWidgetItem, QVBoxLayout, @@ -44,19 +42,19 @@ from PyQt5.QtWidgets import ( from novelwriter import CONFIG, SHARED from novelwriter.common import minmax -from novelwriter.constants import nwHeaders, nwUnicode, trConst, nwLabels +from novelwriter.constants import nwHeaders, nwLabels, nwUnicode, trConst from novelwriter.core.coretools import DocDuplicator, DocMerger, DocSplitter from novelwriter.core.item import NWItem from novelwriter.dialogs.docmerge import GuiDocMerge from novelwriter.dialogs.docsplit import GuiDocSplit from novelwriter.dialogs.editlabel import GuiEditLabel from novelwriter.dialogs.projectsettings import GuiProjectSettings -from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout +from novelwriter.enum import nwDocMode, nwItemClass, nwItemLayout, nwItemType from novelwriter.extensions.modified import NIconToolButton from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON from novelwriter.types import ( QtAlignLeft, QtAlignRight, QtMouseLeft, QtMouseMiddle, QtSizeExpanding, - QtUserRole, + QtUserRole ) if TYPE_CHECKING: # pragma: no cover @@ -1424,7 +1422,7 @@ class GuiProjectTree(QTreeWidget): return False # Save the open document first, in case it's part of merge - self.mainGui.saveDocument() + SHARED.saveDocument() # Create merge object, and append docs docMerger = DocMerger(SHARED.project) diff --git a/novelwriter/gui/search.py b/novelwriter/gui/search.py index 93ee759b..17d18f53 100644 --- a/novelwriter/gui/search.py +++ b/novelwriter/gui/search.py @@ -259,7 +259,7 @@ class GuiProjectSearch(QWidget): if not self._blocked: QApplication.setOverrideCursor(QCursor(Qt.CursorShape.WaitCursor)) start = time() - SHARED.mainGui.saveDocument() + SHARED.saveDocument() self._blocked = True self._map = {} self.searchResult.clear() diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index afe7966d..533de19e 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -369,9 +369,7 @@ class GuiMain(QMainWindow): if not msgYes: return False - if self.docEditor.docChanged: - self.saveDocument() - + self.saveDocument() saveOK = self.saveProject() doBackup = False if SHARED.project.data.doBackup and CONFIG.backupOnClose: @@ -514,9 +512,7 @@ class GuiMain(QMainWindow): # Disable focus mode if it is active if SHARED.focusMode: SHARED.setFocusMode(False) - self.docEditor.saveCursorPosition() - if self.docEditor.docChanged: - self.saveDocument() + self.saveDocument() self.docEditor.clearEditor() if not beforeOpen: self.novelView.setActiveHandle(None) @@ -587,7 +583,8 @@ class GuiMain(QMainWindow): @pyqtSlot() def saveDocument(self) -> None: """Save the current documents.""" - if SHARED.hasProject: + self.docEditor.saveCursorPosition() + if SHARED.hasProject and self.docEditor.docChanged: self.docEditor.saveText() return @@ -1133,7 +1130,7 @@ class GuiMain(QMainWindow): @pyqtSlot() def _reloadViewer(self) -> None: """Reload the document in the viewer.""" - if self.docEditor.docChanged and self.docEditor.docHandle == self.docViewer.docHandle: + if self.docEditor.docHandle == self.docViewer.docHandle: # If the two panels have the same document, save any changes in the editor self.saveDocument() self.docViewer.reloadText() @@ -1213,7 +1210,7 @@ class GuiMain(QMainWindow): doSave &= SHARED.project.projChanged doSave &= SHARED.project.storage.isOpen() if doSave: - logger.debug("Autosaving project") + logger.debug("Auto-saving project") self.saveProject(autoSave=True) return @@ -1221,7 +1218,7 @@ class GuiMain(QMainWindow): def _autoSaveDocument(self) -> None: """Autosave of the document. This is a timer-activated slot.""" if SHARED.hasProject and self.docEditor.docChanged: - logger.debug("Autosaving document") + logger.debug("Auto-saving document") self.saveDocument() return diff --git a/novelwriter/shared.py b/novelwriter/shared.py index dced61a6..40d08c1f 100644 --- a/novelwriter/shared.py +++ b/novelwriter/shared.py @@ -171,6 +171,11 @@ class SharedData(QObject): logger.debug("Thread Pool Max Count: %d", QThreadPool.globalInstance().maxThreadCount()) return + def saveDocument(self) -> None: + """Forward save document call to main GUI.""" + self.mainGui.saveDocument() + return + def openProject(self, path: str | Path, clearLock: bool = False) -> bool: """Open a project.""" if self.project.isValid: diff --git a/novelwriter/tools/manusbuild.py b/novelwriter/tools/manusbuild.py index e27e8b6a..8b6cdb0e 100644 --- a/novelwriter/tools/manusbuild.py +++ b/novelwriter/tools/manusbuild.py @@ -327,7 +327,7 @@ class GuiManuscriptBuild(QDialog): return False # Make sure editor content is saved before we start - SHARED.mainGui.saveDocument() + SHARED.saveDocument() docBuild = NWBuildDocument(SHARED.project, self._build) docBuild.queueAll() diff --git a/novelwriter/tools/manuscript.py b/novelwriter/tools/manuscript.py index 15ff0d30..47bbdc10 100644 --- a/novelwriter/tools/manuscript.py +++ b/novelwriter/tools/manuscript.py @@ -339,7 +339,7 @@ class GuiManuscript(NToolDialog): return # Make sure editor content is saved before we start - SHARED.mainGui.saveDocument() + SHARED.saveDocument() docBuild = NWBuildDocument(SHARED.project, build) docBuild.setPreviewMode(True) diff --git a/sample/nwProject.nwx b/sample/nwProject.nwx index 40d46cee..5aa8cdba 100644 --- a/sample/nwProject.nwx +++ b/sample/nwProject.nwx @@ -1,6 +1,6 @@ - - + + Sample Project Jane Smith @@ -58,7 +58,7 @@ Chapter One - + Making a Scene