Fix #2018630 [Menu item duplication glitch](https://bugs.launchpad.net/calibre/+bug/2018630)
This commit is contained in:
Kovid Goyal 2023-05-06 16:51:47 +05:30
commit 9f5244da9e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 41 additions and 11 deletions

View File

@ -398,6 +398,7 @@ def create_defs():
# JSON dumps converts integer keys to strings, so do it explicitly # 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['tb_search_order'] = {'0': 1, '1': 2, '2': 3, '3': 4, '4': 0}
defs['search_tool_bar_shows_text'] = True defs['search_tool_bar_shows_text'] = True
defs['allow_keyboard_search_in_library_views'] = True
def migrate_tweak(tweak_name, pref_name): def migrate_tweak(tweak_name, pref_name):
# If the tweak has been changed then leave the tweak in the file so # If the tweak has been changed then leave the tweak in the file so

View File

@ -680,23 +680,33 @@ class BooksView(QTableView): # {{{
view.column_header_context_menu = self.create_context_menu(col, name, view) view.column_header_context_menu = self.create_context_menu(col, name, view)
has_context_menu = hasattr(view, 'column_header_context_menu') has_context_menu = hasattr(view, 'column_header_context_menu')
if self.is_library_view and has_context_menu: if self.is_library_view and has_context_menu:
view.column_header_context_menu.addSeparator() m = view.column_header_context_menu
if not hasattr(view.column_header_context_menu, 'bl_split_action'): m.addSeparator()
view.column_header_context_menu.bl_split_action = view.column_header_context_menu.addAction( if not hasattr(m, 'bl_split_action'):
QIcon.ic('split.png'), 'xxx', partial(self.column_header_context_handler, action='split', column='title')) m.bl_split_action = m.addAction(QIcon.ic('split.png'), 'xxx',
ac = view.column_header_context_menu.bl_split_action partial(self.column_header_context_handler, action='split', column='title'))
ac = m.bl_split_action
if self.pin_view.isVisible(): if self.pin_view.isVisible():
ac.setText(_('Un-split the book list')) ac.setText(_('Un-split the book list'))
else: else:
ac.setText(_('Split the book list')) ac.setText(_('Split the book list'))
# QIcon.ic('drm-locked.png'),
if not hasattr(m, 'column_mouse_move_action'):
m.column_mouse_move_action = m.addAction('xxx')
def set_action_attributes(icon, text, slot):
m.column_mouse_move_action.setText(text)
m.column_mouse_move_action.setIcon(icon)
m.column_mouse_move_action.triggered.connect(slot)
if view.column_header.sectionsMovable(): if view.column_header.sectionsMovable():
view.column_header_context_menu.addAction( set_action_attributes(QIcon.ic('drm-locked.png'),
QIcon.ic('drm-locked.png'), _("Don't allow moving columns with the mouse"), _("Don't allow moving columns with the mouse"),
partial(self.column_header_context_handler, action='lock')) partial(self.column_header_context_handler, action='lock'))
else: else:
view.column_header_context_menu.addAction( set_action_attributes(QIcon.ic('drm-unlocked.png'),
QIcon.ic('drm-unlocked.png'), _("Allow moving columns with the mouse"), _("Allow moving columns with the mouse"),
partial(self.column_header_context_handler, action='unlock')) partial(self.column_header_context_handler, action='unlock'))
if has_context_menu: if has_context_menu:
view.column_header_context_menu.popup(view.column_header.mapToGlobal(pos)) view.column_header_context_menu.popup(view.column_header.mapToGlobal(pos))
# }}} # }}}
@ -746,6 +756,10 @@ class BooksView(QTableView): # {{{
gprefs[pname] = previous gprefs[pname] = previous
self.sort_by_named_field(field, previous[field]) 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): def sort_by_named_field(self, field, order, reset=True):
if isinstance(order, Qt.SortOrder): if isinstance(order, Qt.SortOrder):
order = order == Qt.SortOrder.AscendingOrder order = order == Qt.SortOrder.AscendingOrder

View File

@ -33,6 +33,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('limit_search_columns', prefs) r('limit_search_columns', prefs)
r('use_primary_find_in_search', prefs) r('use_primary_find_in_search', prefs)
r('search_tool_bar_shows_text', gprefs) r('search_tool_bar_shows_text', gprefs)
r('allow_keyboard_search_in_library_views', gprefs)
ossm = self.opt_saved_search_menu_is_hierarchical ossm = self.opt_saved_search_menu_is_hierarchical
ossm.setChecked('search' in db.new_api.pref('categories_using_hierarchy', [])) ossm.setChecked('search' in db.new_api.pref('categories_using_hierarchy', []))
ossm.stateChanged.connect(self.changed_signal) ossm.stateChanged.connect(self.changed_signal)

View File

@ -160,6 +160,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0">
<widget class="QCheckBox" name="opt_allow_keyboard_search_in_library_views">
<property name="text">
<string>Use keyboard searching in the book list</string>
</property>
<property name="toolTip">
<string>&lt;p&gt;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.&lt;/p&gt;</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_2"> <widget class="QWidget" name="tab_2">