Remember the state of the highlight_only check box. Scroll to first matching row.

This commit is contained in:
Charles Haley 2011-01-12 17:18:06 +00:00
parent 01b4701253
commit 7e87812027
3 changed files with 15 additions and 3 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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()