Update the file info dialog box
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
"<br>".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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user