From acc76f923a238c45b89615df19aa303efd001605 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 20 Jun 2017 09:58:39 +0530 Subject: [PATCH] Fix regression in previous release that caused the Tag browser view to jump around when renaming items --- src/calibre/gui2/tag_browser/model.py | 5 +++++ src/calibre/gui2/tag_browser/view.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 10ffc91f29..686c3db862 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -297,6 +297,7 @@ class TagsModel(QAbstractItemModel): # {{{ def __init__(self, parent, prefs=gprefs): QAbstractItemModel.__init__(self, parent) + self.use_position_based_index_on_next_recount = False self.prefs = prefs self.node_map = {} self.category_nodes = [] @@ -1090,6 +1091,7 @@ class TagsModel(QAbstractItemModel): # {{{ nkey_lower = icu_lower(nkey) if ckey == nkey: + self.use_position_based_index_on_next_recount = True return True for c in sorted(user_cats.keys(), key=sort_key): @@ -1112,6 +1114,7 @@ class TagsModel(QAbstractItemModel): # {{{ user_cats[nkey + rest] = user_cats[ckey + rest] del user_cats[ckey + rest] self.user_categories_edited.emit(user_cats, nkey) # Does a refresh + self.use_position_based_index_on_next_recount = True return True key = item.tag.category @@ -1129,10 +1132,12 @@ class TagsModel(QAbstractItemModel): # {{{ error_dialog(self.gui_parent, _('Duplicate search name'), _('The saved search name %s is already used.')%val).exec_() return False + self.use_position_based_index_on_next_recount = True self.db.saved_search_rename(unicode(item.data(role) or ''), val) item.tag.name = val self.search_item_renamed.emit() # Does a refresh else: + self.use_position_based_index_on_next_recount = True restrict_to_book_ids=self.get_book_ids_to_use() if item.use_vl else None self.db.new_api.rename_items(key, {item.tag.id: val}, restrict_to_book_ids=restrict_to_book_ids) diff --git a/src/calibre/gui2/tag_browser/view.py b/src/calibre/gui2/tag_browser/view.py index d1daac1aa8..f45231b7af 100644 --- a/src/calibre/gui2/tag_browser/view.py +++ b/src/calibre/gui2/tag_browser/view.py @@ -780,7 +780,12 @@ class TagsView(QTreeView): # {{{ ci = self.currentIndex() if not ci.isValid(): ci = self.indexAt(QPoint(10, 10)) - path = self.model().named_path_for_index(ci) if self.is_visible(ci) else None + use_pos = self._model.use_position_based_index_on_next_recount + self._model.use_position_based_index_on_next_recount = False + if use_pos: + path = self._model.path_for_index(ci) if self.is_visible(ci) else None + else: + path = self._model.named_path_for_index(ci) if self.is_visible(ci) else None expanded_categories, state_map = self.get_state() self._model.rebuild_node_tree(state_map=state_map) self.blockSignals(True) @@ -789,9 +794,12 @@ class TagsView(QTreeView): # {{{ if idx is not None and idx.isValid(): self.expand(idx) if path is not None: - index = self._model.index_for_named_path(path) - if index.isValid(): - self.show_item_at_index(index) + if use_pos: + self.show_item_at_path(path) + else: + index = self._model.index_for_named_path(path) + if index.isValid(): + self.show_item_at_index(index) self.blockSignals(False) def show_item_at_path(self, path, box=False,