Added a hidden handle column to the outline tree, and connected the double click to open a document

This commit is contained in:
Veronica K. B. Olsen
2020-04-26 17:48:14 +02:00
parent 7c2ca13e4f
commit 946331145f
5 changed files with 67 additions and 23 deletions
+1
View File
@@ -121,6 +121,7 @@ class nwLabels():
} }
OUTLINE_COLS = { OUTLINE_COLS = {
nwOutline.TITLE : "Title", nwOutline.TITLE : "Title",
nwOutline.HANDLE : "Handle",
nwOutline.LEVEL : "Level", nwOutline.LEVEL : "Level",
nwOutline.LABEL : "Document", nwOutline.LABEL : "Document",
nwOutline.LINE : "Line", nwOutline.LINE : "Line",
+16 -15
View File
@@ -107,20 +107,21 @@ class nwAlert(Enum):
class nwOutline(Enum): class nwOutline(Enum):
TITLE = 0 TITLE = 0
LEVEL = 1 HANDLE = 1
LABEL = 2 LEVEL = 2
LINE = 3 LABEL = 3
CCOUNT = 4 LINE = 4
WCOUNT = 5 CCOUNT = 5
PCOUNT = 6 WCOUNT = 6
POV = 7 PCOUNT = 7
CHAR = 8 POV = 8
PLOT = 9 CHAR = 9
TIME = 10 PLOT = 10
WORLD = 11 TIME = 11
OBJECT = 12 WORLD = 12
ENTITY = 13 OBJECT = 13
CUSTOM = 14 ENTITY = 14
SYNOP = 15 CUSTOM = 15
SYNOP = 16
# END Enum nwOutline # END Enum nwOutline
+20 -2
View File
@@ -218,7 +218,7 @@ class GuiDocEditor(QTextEdit):
return True return True
def loadText(self, tHandle): def loadText(self, tHandle, tLine=None):
"""Load text from a document into the editor. If we have an io """Load text from a document into the editor. If we have an io
error, we must handle this and clear the editor so that we don't error, we must handle this and clear the editor so that we don't
risk overwriting the file if it exists. This can for instance risk overwriting the file if it exists. This can for instance
@@ -249,7 +249,10 @@ class GuiDocEditor(QTextEdit):
afTime = time() afTime = time()
logger.debug("Document highlighted in %.3f milliseconds" % (1000*(afTime-bfTime))) logger.debug("Document highlighted in %.3f milliseconds" % (1000*(afTime-bfTime)))
self.setCursorPosition(self.nwDocument.theItem.cursorPos) if tLine is None:
self.setCursorPosition(self.nwDocument.theItem.cursorPos)
else:
self.setCursorLine(tLine)
self.lastEdit = time() self.lastEdit = time()
self._runCounter() self._runCounter()
self.wcTimer.start() self.wcTimer.start()
@@ -353,6 +356,8 @@ class GuiDocEditor(QTextEdit):
return theText return theText
def setCursorPosition(self, thePosition): def setCursorPosition(self, thePosition):
"""Move the cursor to a given position in the document.
"""
if thePosition >= 0: if thePosition >= 0:
theCursor = self.textCursor() theCursor = self.textCursor()
theCursor.setPosition(thePosition) theCursor.setPosition(thePosition)
@@ -360,9 +365,22 @@ class GuiDocEditor(QTextEdit):
return True return True
def getCursorPosition(self): def getCursorPosition(self):
"""Find the cursor position in the document.
"""
theCursor = self.textCursor() theCursor = self.textCursor()
return theCursor.position() return theCursor.position()
def setCursorLine(self, theLine):
"""Move the cursor to a given line in the document.
"""
if theLine is None:
return False
if theLine >= 0:
theBlock = self.qDocument.findBlockByLineNumber(theLine)
if theBlock:
self.setCursorPosition(theBlock.position())
return True
## ##
# Spell Checking # Spell Checking
## ##
+26 -4
View File
@@ -43,6 +43,7 @@ class GuiProjectOutline(QTreeWidget):
DEF_WIDTH = { DEF_WIDTH = {
nwOutline.TITLE : 200, nwOutline.TITLE : 200,
nwOutline.HANDLE : 0,
nwOutline.LEVEL : 40, nwOutline.LEVEL : 40,
nwOutline.LABEL : 150, nwOutline.LABEL : 150,
nwOutline.LINE : 40, nwOutline.LINE : 40,
@@ -62,6 +63,7 @@ class GuiProjectOutline(QTreeWidget):
DEF_HIDDEN = { DEF_HIDDEN = {
nwOutline.TITLE : False, nwOutline.TITLE : False,
nwOutline.HANDLE : True,
nwOutline.LEVEL : True, nwOutline.LEVEL : True,
nwOutline.LABEL : False, nwOutline.LABEL : False,
nwOutline.LINE : True, nwOutline.LINE : True,
@@ -182,7 +184,17 @@ class GuiProjectOutline(QTreeWidget):
## ##
def _treeDoubleClick(self, tItem, tCol): def _treeDoubleClick(self, tItem, tCol):
print(tItem, tCol) """Extract the handle and line number of the title double-
clicked, and send it to the main gui class for opening in the
document editor.
"""
tHandle = tItem.text(self.colIndex[nwOutline.HANDLE])
try:
tLine = int(tItem.text(self.colIndex[nwOutline.LINE]))
except:
tLine = 1
logger.verbose("User selected entry with handle %s on line %s" % (tHandle, tLine))
self.theParent.openDocument(tHandle, tLine - 1)
return return
def _headerRightClick(self, clickPos): def _headerRightClick(self, clickPos):
@@ -301,7 +313,11 @@ class GuiProjectOutline(QTreeWidget):
return return
def _populateTree(self): def _populateTree(self):
"""Build the tree based on the project index. """Build the tree based on the project index, and the header
based on the defined constants, default values and user selected
width, order and hidden state. All columns are populated, even
if they are hidden. This ensures that showing and hiding columns
is fast and doesn't require a rebuild of the tree.
""" """
self.clear() self.clear()
@@ -317,6 +333,11 @@ class GuiProjectOutline(QTreeWidget):
self.setColumnWidth(self.colIndex[hItem], self.colWidth[hItem]) self.setColumnWidth(self.colIndex[hItem], self.colWidth[hItem])
self.setColumnHidden(self.colIndex[hItem], self.colHidden[hItem]) self.setColumnHidden(self.colIndex[hItem], self.colHidden[hItem])
# Make sure title column is always visible,
# and handle column always hidden
self.setColumnHidden(self.colIndex[nwOutline.TITLE], False)
self.setColumnHidden(self.colIndex[nwOutline.HANDLE], True)
headItem = self.headerItem() headItem = self.headerItem()
headItem.setTextAlignment(self.colIndex[nwOutline.CCOUNT], Qt.AlignRight) headItem.setTextAlignment(self.colIndex[nwOutline.CCOUNT], Qt.AlignRight)
headItem.setTextAlignment(self.colIndex[nwOutline.WCOUNT], Qt.AlignRight) headItem.setTextAlignment(self.colIndex[nwOutline.WCOUNT], Qt.AlignRight)
@@ -390,6 +411,7 @@ class GuiProjectOutline(QTreeWidget):
newItem = QTreeWidgetItem() newItem = QTreeWidgetItem()
newItem.setText(self.colIndex[nwOutline.TITLE], novIdx["title"]) newItem.setText(self.colIndex[nwOutline.TITLE], novIdx["title"])
newItem.setText(self.colIndex[nwOutline.HANDLE], tHandle)
newItem.setText(self.colIndex[nwOutline.LEVEL], novIdx["level"]) newItem.setText(self.colIndex[nwOutline.LEVEL], novIdx["level"])
newItem.setText(self.colIndex[nwOutline.LABEL], nwItem.itemName) newItem.setText(self.colIndex[nwOutline.LABEL], nwItem.itemName)
newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:]) newItem.setText(self.colIndex[nwOutline.LINE], sTitle[1:])
@@ -429,7 +451,7 @@ class GuiOutlineHeaderMenu(QMenu):
self.actionMap = {} self.actionMap = {}
for hItem in nwOutline: for hItem in nwOutline:
if hItem == nwOutline.TITLE: if hItem == nwOutline.TITLE or hItem == nwOutline.HANDLE:
continue continue
self.actionMap[hItem] = QAction(nwLabels.OUTLINE_COLS[hItem], self) self.actionMap[hItem] = QAction(nwLabels.OUTLINE_COLS[hItem], self)
self.actionMap[hItem].setCheckable(True) self.actionMap[hItem].setCheckable(True)
@@ -447,7 +469,7 @@ class GuiOutlineHeaderMenu(QMenu):
self.acceptToggle = False self.acceptToggle = False
for hItem in nwOutline: for hItem in nwOutline:
if hItem == nwOutline.TITLE or hItem not in hiddenState: if hItem == nwOutline.TITLE or hItem == nwOutline.HANDLE or hItem not in hiddenState:
continue continue
self.actionMap[hItem].setChecked(not hiddenState[hItem]) self.actionMap[hItem].setChecked(not hiddenState[hItem])
+4 -2
View File
@@ -452,11 +452,13 @@ class GuiMain(QMainWindow):
self.docEditor.clearEditor() self.docEditor.clearEditor()
return True return True
def openDocument(self, tHandle): def openDocument(self, tHandle, tLine=None):
"""Open a specific document, optionally at a given line.
"""
if self.hasProject: if self.hasProject:
self.closeDocument() self.closeDocument()
self.tabWidget.setCurrentWidget(self.splitView) self.tabWidget.setCurrentWidget(self.splitView)
if self.docEditor.loadText(tHandle): if self.docEditor.loadText(tHandle, tLine):
self.docEditor.setFocus() self.docEditor.setFocus()
self.theProject.setLastEdited(tHandle) self.theProject.setLastEdited(tHandle)
else: else: