From 7e878120270381b77cb34f732109219f39ecce66 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 12 Jan 2011 17:18:06 +0000 Subject: [PATCH] Remember the state of the highlight_only check box. Scroll to first matching row. --- src/calibre/gui2/library/models.py | 12 +++++++++--- src/calibre/gui2/library/views.py | 2 ++ src/calibre/gui2/search_box.py | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 98e61acf33..38a4b28744 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -94,6 +94,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.bool_blank_icon = QIcon(I('blank.png')) self.device_connected = False self.rows_matching = set() + self.lowest_row_matching = None self.highlight_only = False self.read_config() @@ -233,7 +234,8 @@ class BooksModel(QAbstractTableModel): # {{{ def set_highlight_only(self, toWhat): self.highlight_only = toWhat - self.research() + if self.last_search: + self.research() def search(self, text, reset=True): try: @@ -241,11 +243,15 @@ class BooksModel(QAbstractTableModel): # {{{ self.db.search('') if not text: self.rows_matching = set() + self.lowest_row_matching = None else: - self.rows_matching = set(self.db.search(text, - return_matches=True)) + self.rows_matching = self.db.search(text, return_matches=True) + if self.rows_matching: + self.lowest_row_matching = self.db.row(self.rows_matching[0]) + self.rows_matching = set(self.rows_matching) else: self.rows_matching = set() + self.lowest_row_matching = None self.db.search(text) except ParseException as e: self.searched.emit(e.msg) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 357b48d1de..07c3cc21e4 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -682,6 +682,8 @@ class BooksView(QTableView): # {{{ def search_proxy(self, txt): self._model.search(txt) + if self._model.lowest_row_matching: + self.scroll_to_row(self._model.lowest_row_matching) self.setFocus(Qt.OtherFocusReason) def connect_to_search_box(self, sb, search_done): diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 5808a2dc46..e4073a01c9 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -16,6 +16,7 @@ from calibre.gui2 import config from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor from calibre.gui2.dialogs.search import SearchDialog +from calibre.utils.config import dynamic from calibre.utils.search_query_parser import saved_searches from calibre.utils.icu import sort_key @@ -376,6 +377,8 @@ class SearchBoxMixin(object): # {{{ self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip()) self.clear_button.setStatusTip(self.clear_button.toolTip()) self.search_highlight_only.stateChanged.connect(self.highlight_only_changed) + self.search_highlight_only.setChecked( + dynamic.get('search_highlight_only', False)) def focus_search_box(self, *args): self.search.setFocus(Qt.OtherFocusReason) @@ -403,6 +406,7 @@ class SearchBoxMixin(object): # {{{ self.current_view().setFocus(Qt.OtherFocusReason) def highlight_only_changed(self, toWhat): + dynamic.set('search_highlight_only', toWhat) self.current_view().model().set_highlight_only(toWhat) self.focus_to_library()