mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre into master
This commit is contained in:
commit
72d33ab385
@ -573,6 +573,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
|
|
||||||
index = self.indexAt(point)
|
index = self.indexAt(point)
|
||||||
self.context_menu = QMenu(self)
|
self.context_menu = QMenu(self)
|
||||||
|
parent_index = None
|
||||||
|
|
||||||
if index.isValid():
|
if index.isValid():
|
||||||
item = index.data(Qt.UserRole)
|
item = index.data(Qt.UserRole)
|
||||||
@ -794,6 +795,18 @@ class TagsView(QTreeView): # {{{
|
|||||||
partial(self.context_menu_handler, action='manage_categories',
|
partial(self.context_menu_handler, action='manage_categories',
|
||||||
category=None))
|
category=None))
|
||||||
|
|
||||||
|
node_name = tag_item.tag.name
|
||||||
|
parent = tag_item.parent
|
||||||
|
if parent.type != TagTreeItem.ROOT:
|
||||||
|
# We have an internal node. Find its immediate parent
|
||||||
|
parent_index = self._model.parent(index)
|
||||||
|
parent_node = parent
|
||||||
|
parent_name = parent.tag.name
|
||||||
|
else:
|
||||||
|
# We have a top-level node.
|
||||||
|
parent_index = index
|
||||||
|
parent_node = tag_item
|
||||||
|
parent_name = tag_item.name
|
||||||
if self.hidden_categories:
|
if self.hidden_categories:
|
||||||
if not self.context_menu.isEmpty():
|
if not self.context_menu.isEmpty():
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
@ -826,16 +839,40 @@ class TagsView(QTreeView): # {{{
|
|||||||
da.setToolTip('*')
|
da.setToolTip('*')
|
||||||
pa.setToolTip('*')
|
pa.setToolTip('*')
|
||||||
|
|
||||||
if index.isValid() and self.model().rowCount(index) > 0:
|
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
self.context_menu.addAction(_('E&xpand all children'), partial(self.expand_node_and_descendants, index))
|
if index.isValid() and self.model().rowCount(index) > 0:
|
||||||
|
self.context_menu.addAction(_('Expand {0}').format(node_name),
|
||||||
self.context_menu.addAction(_('Collapse all levels'), self.collapseAll)
|
partial(self.expand_node_and_descendants, index))
|
||||||
|
if self.isExpanded(index):
|
||||||
|
self.context_menu.addAction(_("Collapse {0}").format(node_name),
|
||||||
|
partial(self.collapse_node, index))
|
||||||
|
if parent_index is not None:
|
||||||
|
if self.isExpanded(parent_index):
|
||||||
|
# Don't bother to collapse if it isn't expanded
|
||||||
|
self.context_menu.addAction(_("Collapse {0}").format(parent_name),
|
||||||
|
partial(self.collapse_node, parent_index))
|
||||||
|
if parent_node.parent.type != TagTreeItem.ROOT:
|
||||||
|
# Add the top level node if the current parent is an internal node
|
||||||
|
while parent_node.parent.type != TagTreeItem.ROOT:
|
||||||
|
parent_node = parent_node.parent
|
||||||
|
idx = self._model.index_for_category(parent_node.category_key)
|
||||||
|
self.context_menu.addAction(_("Collapse {0}").format(parent_node.name),
|
||||||
|
partial(self.collapse_node, idx))
|
||||||
|
self.context_menu.addAction(_('Collapse all'), self.collapseAll)
|
||||||
|
|
||||||
if not self.context_menu.isEmpty():
|
if not self.context_menu.isEmpty():
|
||||||
self.context_menu.popup(self.mapToGlobal(point))
|
self.context_menu.popup(self.mapToGlobal(point))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def collapse_node(self, idx):
|
||||||
|
def collapse_node_and_children(idx):
|
||||||
|
self.collapse(idx)
|
||||||
|
for r in range(self.model().rowCount(idx)):
|
||||||
|
collapse_node_and_children(idx.child(r, 0))
|
||||||
|
collapse_node_and_children(idx)
|
||||||
|
self.setCurrentIndex(idx)
|
||||||
|
self.scrollTo(idx)
|
||||||
|
|
||||||
def expand_node_and_descendants(self, index):
|
def expand_node_and_descendants(self, index):
|
||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user