Improve handling of title in doc headers

This commit is contained in:
Veronica Berglyd Olsen
2024-03-03 16:30:48 +01:00
parent 79513bcbe5
commit 57b3aa2032
3 changed files with 18 additions and 34 deletions
+6 -6
View File
@@ -351,16 +351,16 @@ class NWTree:
return False return False
return tItem.itemType == itemType return tItem.itemType == itemType
def getItemPath(self, tHandle: str) -> list[str]: def getItemPath(self, tHandle: str, asName: bool = False) -> list[str]:
"""Iterate upwards in the tree until we find the item with """Iterate upwards in the tree until we find the item with
parent None, the root item, and return the list of handles. parent None, the root item, and return the list of handles, or
We do this with a for loop with a maximum depth to make alternatively item names. We do this with a for loop with a
infinite loops impossible. maximum depth to make infinite loops impossible.
""" """
tTree = [] tTree = []
tItem = self.__getitem__(tHandle) tItem = self.__getitem__(tHandle)
if tItem is not None: if tItem is not None:
tTree.append(tHandle) tTree.append(tItem.itemName if asName else tHandle)
for _ in range(MAX_DEPTH): for _ in range(MAX_DEPTH):
if tItem.itemParent is None: if tItem.itemParent is None:
return tTree return tTree
@@ -370,7 +370,7 @@ class NWTree:
if tItem is None: if tItem is None:
return tTree return tTree
else: else:
tTree.append(tHandle) tTree.append(tItem.itemName if asName else tHandle)
else: else:
raise RecursionError("Critical internal error") raise RecursionError("Critical internal error")
+8 -17
View File
@@ -2927,7 +2927,7 @@ class GuiDocEditHeader(QWidget):
return return
def setTitleFromHandle(self, tHandle: str | None) -> bool: def setTitleFromHandle(self, tHandle: str | None) -> None:
"""Set the document title from the handle, or alternatively, set """Set the document title from the handle, or alternatively, set
the whole document path within the project. the whole document path within the project.
""" """
@@ -2938,30 +2938,21 @@ class GuiDocEditHeader(QWidget):
self.searchButton.setVisible(False) self.searchButton.setVisible(False)
self.closeButton.setVisible(False) self.closeButton.setVisible(False)
self.minmaxButton.setVisible(False) self.minmaxButton.setVisible(False)
return True return
pTree = SHARED.project.tree
if CONFIG.showFullPath: if CONFIG.showFullPath:
tTitle = [] self.itemTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed(
tTree = pTree.getItemPath(tHandle) [name for name in SHARED.project.tree.getItemPath(tHandle, asName=True)]
for aHandle in reversed(tTree): )))
nwItem = pTree[aHandle]
if nwItem is not None:
tTitle.append(nwItem.itemName)
sSep = " %s " % nwUnicode.U_RSAQUO
self.itemTitle.setText(sSep.join(tTitle))
else: else:
nwItem = pTree[tHandle] self.itemTitle.setText(i.itemName if (i := SHARED.project.tree[tHandle]) else "")
if nwItem is None:
return False
self.itemTitle.setText(nwItem.itemName)
self.tbButton.setVisible(True) self.tbButton.setVisible(True)
self.searchButton.setVisible(True) self.searchButton.setVisible(True)
self.closeButton.setVisible(True) self.closeButton.setVisible(True)
self.minmaxButton.setVisible(True) self.minmaxButton.setVisible(True)
return True return
def updateFocusMode(self) -> None: def updateFocusMode(self) -> None:
"""Update the minimise/maximise icon of the Focus Mode button. """Update the minimise/maximise icon of the Focus Mode button.
@@ -2997,7 +2988,7 @@ class GuiDocEditHeader(QWidget):
selected in the project tree. selected in the project tree.
""" """
if event.button() == Qt.MouseButton.LeftButton: if event.button() == Qt.MouseButton.LeftButton:
self.docEditor.requestProjectItemSelected.emit(self._docHandle, True) self.docEditor.requestProjectItemSelected.emit(self._docHandle or "", True)
return return
# END Class GuiDocEditHeader # END Class GuiDocEditHeader
+4 -11
View File
@@ -763,19 +763,12 @@ class GuiDocViewHeader(QWidget):
self.refreshButton.setVisible(False) self.refreshButton.setVisible(False)
return return
pTree = SHARED.project.tree
if CONFIG.showFullPath: if CONFIG.showFullPath:
tTitle = [] self.docTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed(
tTree = pTree.getItemPath(tHandle) [name for name in SHARED.project.tree.getItemPath(tHandle, asName=True)]
for aHandle in reversed(tTree): )))
nwItem = pTree[aHandle]
if nwItem is not None:
tTitle.append(nwItem.itemName)
sSep = " %s " % nwUnicode.U_RSAQUO
self.docTitle.setText(sSep.join(tTitle))
else: else:
if nwItem := pTree[tHandle]: self.docTitle.setText(i.itemName if (i := SHARED.project.tree[tHandle]) else "")
self.docTitle.setText(nwItem.itemName)
self.backButton.setVisible(True) self.backButton.setVisible(True)
self.forwardButton.setVisible(True) self.forwardButton.setVisible(True)