Bug #2018630: Menu item duplication glitch

This commit is contained in:
Charles Haley 2023-05-06 10:51:25 +01:00
parent 6d37f6f21e
commit cc7e2d7662

View File

@ -680,22 +680,32 @@ 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))