From 9bf43aa40f1ae638fc23d5729f081c4e84eba5d5 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Wed, 30 Aug 2023 18:57:48 +0200 Subject: [PATCH] Update the file info dialog box --- novelwriter/core/document.py | 28 +++++++++++++++++++-------- novelwriter/gui/doceditor.py | 12 +++++++++--- novelwriter/shared.py | 15 ++++++++------ tests/test_core/test_core_document.py | 6 +++--- tests/test_gui/test_gui_mainmenu.py | 2 +- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/novelwriter/core/document.py b/novelwriter/core/document.py index 1586ac46..23bfbb19 100644 --- a/novelwriter/core/document.py +++ b/novelwriter/core/document.py @@ -85,6 +85,26 @@ class NWDocument: """Check if the file hash has changed outside of novelWriter.""" return self._hashError + @property + def fileLocation(self) -> str: + """Return the file location of the current document.""" + return str(self._fileLoc) + + @property + def createdDate(self) -> str: + """Return the document creation date.""" + return self._docMeta.get("created", "Unknown") + + @property + def updatedDate(self) -> str: + """Return the document creation date.""" + return self._docMeta.get("updated", "Unknown") + + @property + def nwItem(self) -> NWItem | None: + """Return a pointer to the currently open NWItem.""" + return self._item + ## # Class Methods ## @@ -264,14 +284,6 @@ class NWDocument: # Getters ## - def getFileLocation(self) -> str: - """Return the file location of the current document.""" - return str(self._fileLoc) - - def getCurrentItem(self) -> NWItem | None: - """Return a pointer to the currently open NWItem.""" - return self._item - def getMeta(self) -> tuple[str, str | None, nwItemClass | None, nwItemLayout | None]: """Parse the document meta tag and return the name, parent, class and layout meta values. diff --git a/novelwriter/gui/doceditor.py b/novelwriter/gui/doceditor.py index 8c40f203..5d971ca6 100644 --- a/novelwriter/gui/doceditor.py +++ b/novelwriter/gui/doceditor.py @@ -367,7 +367,7 @@ class GuiDocEditor(QTextEdit): the file. """ self._nwDocument = SHARED.project.storage.getDocument(tHandle) - self._nwItem = self._nwDocument.getCurrentItem() + self._nwItem = self._nwDocument.nwItem theDoc = self._nwDocument.readDocument() if theDoc is None: @@ -846,8 +846,14 @@ class GuiDocEditor(QTextEdit): logger.error("No document open") return False SHARED.info( - self.tr("The currently open file is saved in:"), - info=self._nwDocument.getFileLocation() + "
".join([ + self.tr("Document Details"), + "–"*40, + self.tr("Created: {0}").format(self._nwDocument.createdDate), + self.tr("Updated: {0}").format(self._nwDocument.updatedDate), + ]), + details=self.tr("File Location: {0}").format(self._nwDocument.fileLocation), + log=False ) return diff --git a/novelwriter/shared.py b/novelwriter/shared.py index 9fc91c5e..02b70150 100644 --- a/novelwriter/shared.py +++ b/novelwriter/shared.py @@ -203,25 +203,27 @@ class SharedData(QObject): # Alert Boxes ## - def info(self, text: str, info: str = "", details: str = "") -> None: + def info(self, text: str, info: str = "", details: str = "", log: bool = True) -> None: """Open an information alert box.""" self._alert = _GuiAlert(self.mainGui, self.theme) self._alert.setMessage(text, info, details) self._alert.setAlertType(_GuiAlert.INFO, False) - logger.info(self._alert.logMessage, stacklevel=2) + if log: + logger.info(self._alert.logMessage, stacklevel=2) self._alert.exec_() return - def warn(self, text: str, info: str = "", details: str = "") -> None: + def warn(self, text: str, info: str = "", details: str = "", log: bool = True) -> None: """Open a warning alert box.""" self._alert = _GuiAlert(self.mainGui, self.theme) self._alert.setMessage(text, info, details) self._alert.setAlertType(_GuiAlert.WARN, False) - logger.warning(self._alert.logMessage, stacklevel=2) + if log: + logger.warning(self._alert.logMessage, stacklevel=2) self._alert.exec_() return - def error(self, text: str, info: str = "", details: str = "", + def error(self, text: str, info: str = "", details: str = "", log: bool = True, exc: Exception | None = None) -> None: """Open an error alert box.""" self._alert = _GuiAlert(self.mainGui, self.theme) @@ -229,7 +231,8 @@ class SharedData(QObject): self._alert.setAlertType(_GuiAlert.ERROR, False) if exc: self._alert.setException(exc) - logger.error(self._alert.logMessage, stacklevel=2) + if log: + logger.error(self._alert.logMessage, stacklevel=2) self._alert.exec_() return diff --git a/tests/test_core/test_core_document.py b/tests/test_core/test_core_document.py index e7488668..32f0f258 100644 --- a/tests/test_core/test_core_document.py +++ b/tests/test_core/test_core_document.py @@ -188,11 +188,11 @@ def testCoreDocument_Methods(monkeypatch, mockGUI, fncPath, mockRnd): assert theDoc.readDocument() == "### New Scene\n\n" # Check location - assert theDoc.getFileLocation() == str(docPath) + assert theDoc.fileLocation == str(docPath) # Check the item - assert theDoc.getCurrentItem() is not None - assert theDoc.getCurrentItem().itemHandle == C.hSceneDoc # type: ignore + assert theDoc.nwItem is not None + assert theDoc.nwItem.itemHandle == C.hSceneDoc # type: ignore # Check the meta theName, theParent, theClass, theLayout = theDoc.getMeta() diff --git a/tests/test_gui/test_gui_mainmenu.py b/tests/test_gui/test_gui_mainmenu.py index 626c71aa..1ea0a680 100644 --- a/tests/test_gui/test_gui_mainmenu.py +++ b/tests/test_gui/test_gui_mainmenu.py @@ -656,7 +656,7 @@ def testGuiMenu_Insert(qtbot, monkeypatch, nwGUI, fncPath, projPath, mockRnd): nwGUI.mainMenu.aFileDetails.activate(QAction.Trigger) path = str(projPath / "content" / "000000000000f.nwd") logMsg = SHARED.alert.logMessage if SHARED.alert else "" - assert logMsg == f"The currently open file is saved in: {path}" + assert logMsg.endswith(f"File Location: {path}") # qtbot.stop()