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 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
parent None, the root item, and return the list of handles.
We do this with a for loop with a maximum depth to make
infinite loops impossible.
parent None, the root item, and return the list of handles, or
alternatively item names. We do this with a for loop with a
maximum depth to make infinite loops impossible.
"""
tTree = []
tItem = self.__getitem__(tHandle)
if tItem is not None:
tTree.append(tHandle)
tTree.append(tItem.itemName if asName else tHandle)
for _ in range(MAX_DEPTH):
if tItem.itemParent is None:
return tTree
@@ -370,7 +370,7 @@ class NWTree:
if tItem is None:
return tTree
else:
tTree.append(tHandle)
tTree.append(tItem.itemName if asName else tHandle)
else:
raise RecursionError("Critical internal error")
+8 -17
View File
@@ -2927,7 +2927,7 @@ class GuiDocEditHeader(QWidget):
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
the whole document path within the project.
"""
@@ -2938,30 +2938,21 @@ class GuiDocEditHeader(QWidget):
self.searchButton.setVisible(False)
self.closeButton.setVisible(False)
self.minmaxButton.setVisible(False)
return True
return
pTree = SHARED.project.tree
if CONFIG.showFullPath:
tTitle = []
tTree = pTree.getItemPath(tHandle)
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))
self.itemTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed(
[name for name in SHARED.project.tree.getItemPath(tHandle, asName=True)]
)))
else:
nwItem = pTree[tHandle]
if nwItem is None:
return False
self.itemTitle.setText(nwItem.itemName)
self.itemTitle.setText(i.itemName if (i := SHARED.project.tree[tHandle]) else "")
self.tbButton.setVisible(True)
self.searchButton.setVisible(True)
self.closeButton.setVisible(True)
self.minmaxButton.setVisible(True)
return True
return
def updateFocusMode(self) -> None:
"""Update the minimise/maximise icon of the Focus Mode button.
@@ -2997,7 +2988,7 @@ class GuiDocEditHeader(QWidget):
selected in the project tree.
"""
if event.button() == Qt.MouseButton.LeftButton:
self.docEditor.requestProjectItemSelected.emit(self._docHandle, True)
self.docEditor.requestProjectItemSelected.emit(self._docHandle or "", True)
return
# END Class GuiDocEditHeader
+4 -11
View File
@@ -763,19 +763,12 @@ class GuiDocViewHeader(QWidget):
self.refreshButton.setVisible(False)
return
pTree = SHARED.project.tree
if CONFIG.showFullPath:
tTitle = []
tTree = pTree.getItemPath(tHandle)
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))
self.docTitle.setText(f" {nwUnicode.U_RSAQUO} ".join(reversed(
[name for name in SHARED.project.tree.getItemPath(tHandle, asName=True)]
)))
else:
if nwItem := pTree[tHandle]:
self.docTitle.setText(nwItem.itemName)
self.docTitle.setText(i.itemName if (i := SHARED.project.tree[tHandle]) else "")
self.backButton.setVisible(True)
self.forwardButton.setVisible(True)