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
00e8ac3caa
@ -182,6 +182,8 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.edit_metadata_icon = QIcon(I('edit_input.png'))
|
self.edit_metadata_icon = QIcon(I('edit_input.png'))
|
||||||
self.delete_icon = QIcon(I('list_remove.png'))
|
self.delete_icon = QIcon(I('list_remove.png'))
|
||||||
self.rename_icon = QIcon(I('edit-undo.png'))
|
self.rename_icon = QIcon(I('edit-undo.png'))
|
||||||
|
self.plus_icon = QIcon(I('plus.png'))
|
||||||
|
self.minus_icon = QIcon(I('minus.png'))
|
||||||
|
|
||||||
self._model = TagsModel(self)
|
self._model = TagsModel(self)
|
||||||
self._model.search_item_renamed.connect(self.search_item_renamed)
|
self._model.search_item_renamed.connect(self.search_item_renamed)
|
||||||
@ -573,7 +575,6 @@ class TagsView(QTreeView): # {{{
|
|||||||
|
|
||||||
index = self.indexAt(point)
|
index = self.indexAt(point)
|
||||||
self.context_menu = QMenu(self)
|
self.context_menu = QMenu(self)
|
||||||
parent_index = None
|
|
||||||
added_show_hidden_categories = False
|
added_show_hidden_categories = False
|
||||||
|
|
||||||
def add_show_hidden_categories():
|
def add_show_hidden_categories():
|
||||||
@ -676,10 +677,10 @@ class TagsView(QTreeView): # {{{
|
|||||||
if fm['datatype'] != 'rating':
|
if fm['datatype'] != 'rating':
|
||||||
m = self.context_menu.addMenu(self.edit_metadata_icon,
|
m = self.context_menu.addMenu(self.edit_metadata_icon,
|
||||||
_('Apply %s to selected books')%display_name(tag))
|
_('Apply %s to selected books')%display_name(tag))
|
||||||
m.addAction(QIcon(I('plus.png')),
|
m.addAction(self.plus_icon,
|
||||||
_('Add %s to selected books') % display_name(tag),
|
_('Add %s to selected books') % display_name(tag),
|
||||||
partial(self.context_menu_handler, action='add_tag', index=index))
|
partial(self.context_menu_handler, action='add_tag', index=index))
|
||||||
m.addAction(QIcon(I('minus.png')),
|
m.addAction(self.minus_icon,
|
||||||
_('Remove %s from selected books') % display_name(tag),
|
_('Remove %s from selected books') % display_name(tag),
|
||||||
partial(self.context_menu_handler, action='remove_tag', index=index))
|
partial(self.context_menu_handler, action='remove_tag', index=index))
|
||||||
|
|
||||||
@ -806,19 +807,6 @@ class TagsView(QTreeView): # {{{
|
|||||||
_('Manage User categories'),
|
_('Manage User categories'),
|
||||||
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()
|
||||||
@ -850,47 +838,73 @@ class TagsView(QTreeView): # {{{
|
|||||||
da.setToolTip('*')
|
da.setToolTip('*')
|
||||||
pa.setToolTip('*')
|
pa.setToolTip('*')
|
||||||
|
|
||||||
|
# Add expand menu items
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
if index.isValid() and self.model().rowCount(index) > 0:
|
m = self.context_menu.addMenu(_('Expand and collapse'))
|
||||||
if self.isExpanded(index):
|
node_name = self._model.get_node(index).tag.name
|
||||||
self.context_menu.addAction(_("Collapse {0}").format(node_name),
|
if self.has_children(index) and not self.isExpanded(index):
|
||||||
partial(self.collapse_node, index))
|
m.addAction(self.plus_icon,
|
||||||
else:
|
_('Expand {0}').format(node_name), partial(self.expand, index))
|
||||||
self.context_menu.addAction(_('Expand {0}').format(node_name),
|
if self.has_unexpanded_children(index):
|
||||||
partial(self.expand_node_and_descendants, index))
|
m.addAction(self.plus_icon,
|
||||||
if parent_index is not None and parent_index != index:
|
_('Expand {0} and its children').format(node_name),
|
||||||
if self.isExpanded(parent_index):
|
partial(self.expand_node_and_children, index))
|
||||||
# Don't bother to collapse if it isn't expanded
|
|
||||||
self.context_menu.addAction(_("Collapse {0}").format(parent_name),
|
# Add menu items to collapse parent nodes
|
||||||
partial(self.collapse_node, parent_index))
|
idx = index
|
||||||
if parent_node.parent.type != TagTreeItem.ROOT:
|
paths = []
|
||||||
# Add the top level node if the current parent is an internal node
|
while True:
|
||||||
while parent_node.parent.type != TagTreeItem.ROOT:
|
# First walk up the node tree getting the displayed names of
|
||||||
parent_node = parent_node.parent
|
# expanded parent nodes
|
||||||
idx = self._model.index_for_category(parent_node.category_key)
|
node = self._model.get_node(idx)
|
||||||
self.context_menu.addAction(_("Collapse {0}").format(parent_node.name),
|
if node.type == TagTreeItem.ROOT:
|
||||||
partial(self.collapse_node, idx))
|
break
|
||||||
self.context_menu.addAction(_('Collapse all'), self.collapseAll)
|
if self.has_children(idx) and self.isExpanded(idx):
|
||||||
|
# leaf nodes don't have children so can't be expanded.
|
||||||
|
# Also the leaf node might be collapsed
|
||||||
|
paths.append((node.tag.name, idx))
|
||||||
|
idx = self._model.parent(idx)
|
||||||
|
for p in paths:
|
||||||
|
# Now add the menu items
|
||||||
|
m.addAction(self.minus_icon,
|
||||||
|
_("Collapse {0}").format(p[0]), partial(self.collapse_node, p[1]))
|
||||||
|
m.addAction(self.minus_icon, _('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 has_children(self, idx):
|
||||||
def collapse_node_and_children(idx):
|
return self.model().rowCount(idx) > 0
|
||||||
|
|
||||||
|
def collapse_node_and_children(self, idx):
|
||||||
self.collapse(idx)
|
self.collapse(idx)
|
||||||
for r in range(self.model().rowCount(idx)):
|
for r in range(self.model().rowCount(idx)):
|
||||||
collapse_node_and_children(idx.child(r, 0))
|
self.collapse_node_and_children(idx.child(r, 0))
|
||||||
collapse_node_and_children(idx)
|
|
||||||
|
def collapse_node(self, idx):
|
||||||
|
if not idx.isValid():
|
||||||
|
return
|
||||||
|
self.collapse_node_and_children(idx)
|
||||||
self.setCurrentIndex(idx)
|
self.setCurrentIndex(idx)
|
||||||
self.scrollTo(idx)
|
self.scrollTo(idx)
|
||||||
|
|
||||||
def expand_node_and_descendants(self, index):
|
def expand_node_and_children(self, index):
|
||||||
if not index.isValid():
|
if not index.isValid():
|
||||||
return
|
return
|
||||||
self.expand(index)
|
self.expand(index)
|
||||||
for r in range(self.model().rowCount(index)):
|
for r in range(self.model().rowCount(index)):
|
||||||
self.expand_node_and_descendants(index.child(r, 0))
|
self.expand_node_and_children(index.child(r, 0))
|
||||||
|
|
||||||
|
def has_unexpanded_children(self, index):
|
||||||
|
if not index.isValid():
|
||||||
|
return
|
||||||
|
if self.has_children(index) and not self.isExpanded(index):
|
||||||
|
return True
|
||||||
|
for r in range(self.model().rowCount(index)):
|
||||||
|
if self.has_unexpanded_children(index.child(r, 0)):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def collapse_menu_hovered(self, action):
|
def collapse_menu_hovered(self, action):
|
||||||
tip = action.toolTip()
|
tip = action.toolTip()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user