From bbd11ff153734c5cbf96900878c3ebee3e480852 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sat, 6 May 2023 12:20:23 +0100 Subject: [PATCH] Enhancement: add preference (in Search) to disable QTableView keyboardSearch(). --- src/calibre/gui2/__init__.py | 1 + src/calibre/gui2/library/views.py | 4 ++++ src/calibre/gui2/preferences/search.py | 1 + src/calibre/gui2/preferences/search.ui | 14 ++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 768312bd1b..89754a0245 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -398,6 +398,7 @@ def create_defs(): # JSON dumps converts integer keys to strings, so do it explicitly defs['tb_search_order'] = {'0': 1, '1': 2, '2': 3, '3': 4, '4': 0} defs['search_tool_bar_shows_text'] = True + defs['allow_keyboard_search_in_library_views'] = True def migrate_tweak(tweak_name, pref_name): # If the tweak has been changed then leave the tweak in the file so diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 0c40fa3bd4..4199a044f9 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -756,6 +756,10 @@ class BooksView(QTableView): # {{{ gprefs[pname] = previous self.sort_by_named_field(field, previous[field]) + def keyboardSearch(self, search): + if gprefs.get('allow_keyboard_search_in_library_views', True): + super().keyboardSearch(search) + def sort_by_named_field(self, field, order, reset=True): if isinstance(order, Qt.SortOrder): order = order == Qt.SortOrder.AscendingOrder diff --git a/src/calibre/gui2/preferences/search.py b/src/calibre/gui2/preferences/search.py index 2899861a2a..961c7cc1a6 100644 --- a/src/calibre/gui2/preferences/search.py +++ b/src/calibre/gui2/preferences/search.py @@ -33,6 +33,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('limit_search_columns', prefs) r('use_primary_find_in_search', prefs) r('search_tool_bar_shows_text', gprefs) + r('allow_keyboard_search_in_library_views', gprefs) ossm = self.opt_saved_search_menu_is_hierarchical ossm.setChecked('search' in db.new_api.pref('categories_using_hierarchy', [])) ossm.stateChanged.connect(self.changed_signal) diff --git a/src/calibre/gui2/preferences/search.ui b/src/calibre/gui2/preferences/search.ui index a646297174..e2f6bd99db 100644 --- a/src/calibre/gui2/preferences/search.ui +++ b/src/calibre/gui2/preferences/search.ui @@ -160,6 +160,20 @@ + + + + Use keyboard searching in the book list + + + <p>If enabled then pressing a key in the library view + will search for the next cell in the current column where the + value starts with the letter pressed. If there is no such cell + then nothing happens. If the letter is a shortcut then the + shortcut takes precedence.</p> + + +