From dfb790e73d19fc1a4f84479b9904f4b84abd7973 Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Sat, 2 Nov 2019 22:14:57 +0100
Subject: [PATCH] Added a menu option to show storage details about the
currently open file
---
nw/gui/elements/doceditor.py | 17 +++++++++++++++--
nw/gui/elements/docviewer.py | 2 +-
nw/gui/elements/viewdetails.py | 4 ++--
nw/gui/mainmenu.py | 10 ++++++++++
nw/gui/winmain.py | 4 ++--
nw/project/document.py | 4 +++-
6 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py
index e8bc23b7..852d3272 100644
--- a/nw/gui/elements/doceditor.py
+++ b/nw/gui/elements/doceditor.py
@@ -16,9 +16,9 @@ import nw
from time import time
from PyQt5.QtCore import Qt, QTimer, QSizeF
-from PyQt5.QtWidgets import qApp, QTextEdit, QAction, QMenu, QShortcut
+from PyQt5.QtWidgets import qApp, QTextEdit, QAction, QMenu, QShortcut, QMessageBox
from PyQt5.QtGui import (
- QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor, QPalette, QTextDocument
+ QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor, QPalette, QTextDocument,
)
from nw.project.document import NWDoc
@@ -332,6 +332,19 @@ class GuiDocEditor(QTextEdit):
def isEmpty(self):
return self.qDocument.isEmpty()
+ def revealLocation(self):
+ if self.theHandle is not None:
+ msgBox = QMessageBox()
+ msgBox.information(self, "File Location", (
+ "File details for the currently open file
"
+ "Handle: {handle:s}
"
+ "Location: {fileLoc:s}"
+ ).format(
+ handle = self.theHandle,
+ fileLoc = str(self.nwDocument.fileLoc)
+ ))
+ return
+
##
# Document Events and Maintenance
##
diff --git a/nw/gui/elements/docviewer.py b/nw/gui/elements/docviewer.py
index 612416df..468f4f2b 100644
--- a/nw/gui/elements/docviewer.py
+++ b/nw/gui/elements/docviewer.py
@@ -117,7 +117,7 @@ class GuiDocViewer(QTextBrowser):
self.theHandle = tHandle
self.theProject.setLastViewed(tHandle)
- self.theParent.docMeta.refreshReferences(tHandle)
+ self.theParent.viewMeta.refreshReferences(tHandle)
return True
diff --git a/nw/gui/elements/viewdetails.py b/nw/gui/elements/viewdetails.py
index a4eb4bc1..d283cd20 100644
--- a/nw/gui/elements/viewdetails.py
+++ b/nw/gui/elements/viewdetails.py
@@ -6,7 +6,7 @@
Class holding the document view details panel
File History:
- Created: 2019-09-31 [0.3.2]
+ Created: 2019-10-31 [0.3.2]
"""
@@ -20,7 +20,7 @@ from PyQt5.QtWidgets import (
QSizePolicy, QCheckBox, QGridLayout
)
-from nw.constants import nwLabels
+from nw.constants import nwLabels
logger = logging.getLogger(__name__)
diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py
index 000865a3..23dff355 100644
--- a/nw/gui/mainmenu.py
+++ b/nw/gui/mainmenu.py
@@ -168,6 +168,10 @@ class GuiMainMenu(QMenuBar):
self.updateRecentProjects()
return True
+ def _showDocumentLocation(self):
+ self.theParent.docEditor.revealLocation()
+ return True
+
##
# Menu Builders
##
@@ -347,6 +351,12 @@ class GuiMainMenu(QMenuBar):
# Document > Separator
self.docuMenu.addSeparator()
+ # Document > Show File Details
+ menuItem = QAction("Show File Details", self)
+ menuItem.setStatusTip("Shows a message box with the document location in the project folder")
+ menuItem.triggered.connect(self._showDocumentLocation)
+ self.docuMenu.addAction(menuItem)
+
# Document > Import From File
menuItem = QAction("Import from File", self)
menuItem.setStatusTip("Import document from a text or markdown file")
diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py
index 0d86f84b..c64c095d 100644
--- a/nw/gui/winmain.py
+++ b/nw/gui/winmain.py
@@ -77,7 +77,7 @@ class GuiMain(QMainWindow):
self.noticeBar = GuiNoticeBar(self)
self.docEditor = GuiDocEditor(self, self.theProject)
self.docViewer = GuiDocViewer(self, self.theProject)
- self.docMeta = GuiDocViewDetails(self, self.theProject)
+ self.viewMeta = GuiDocViewDetails(self, self.theProject)
self.searchBar = GuiSearchBar(self)
self.treeMeta = GuiDocDetails(self, self.theProject)
self.treeView = GuiDocTree(self, self.theProject)
@@ -107,7 +107,7 @@ class GuiMain(QMainWindow):
self.docView = QVBoxLayout()
self.docView.setContentsMargins(0,0,0,0)
self.docView.addWidget(self.docViewer)
- self.docView.addWidget(self.docMeta)
+ self.docView.addWidget(self.viewMeta)
self.docView.setStretch(0, 1)
self.viewPane.setLayout(self.docView)
diff --git a/nw/project/document.py b/nw/project/document.py
index 0a3fa126..ad531fb3 100644
--- a/nw/project/document.py
+++ b/nw/project/document.py
@@ -31,6 +31,7 @@ class NWDoc():
self.theItem = None
self.docHandle = None
self.docEditable = False
+ self.fileLoc = None
# Internal Mapping
self.makeAlert = self.theParent.makeAlert
@@ -58,7 +59,8 @@ class NWDoc():
self.docEditable = False
docDir, docFile = self._assemblePath(self.FILE_MN)
- logger.debug("Opening document %s" % path.join(docDir,docFile))
+ self.fileLoc = path.join(docDir,docFile)
+ logger.debug("Opening document %s" % self.fileLoc)
dataDir = path.join(self.theProject.projPath, docDir)
docPath = path.join(dataDir, docFile)