From e5654c1c4fd46f9259979b7b76ee6d15b362e69c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 29 Apr 2021 19:48:09 +0530 Subject: [PATCH] Allow double clicking int he customize viewer toolbar dialog --- src/calibre/gui2/viewer/toolbars.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/viewer/toolbars.py b/src/calibre/gui2/viewer/toolbars.py index 15a0e873ef..2e36f9158b 100644 --- a/src/calibre/gui2/viewer/toolbars.py +++ b/src/calibre/gui2/viewer/toolbars.py @@ -356,13 +356,16 @@ class ActionsList(QListWidget): for name in names: self.add_item_from_name(name) + def remove_item(self, item): + action = item.data(Qt.ItemDataRole.UserRole) + if action is not None or not self.is_source: + self.takeItem(self.row(item)) + return action + def remove_selected(self): ans = [] for item in tuple(self.selectedItems()): - action = item.data(Qt.ItemDataRole.UserRole) - if action is not None or not self.is_source: - self.takeItem(self.row(item)) - ans.append(action) + ans.append(self.remove_item(item)) return ans def add_names(self, names): @@ -388,7 +391,9 @@ class ConfigureToolBar(Dialog): def setup_ui(self): acnames = all_actions().all_action_names self.available_actions = ActionsList(acnames - frozenset(current_actions()), parent=self) + self.available_actions.itemDoubleClicked.connect(self.add_item) self.current_actions = ActionsList(current_actions(), parent=self, is_source=False) + self.current_actions.itemDoubleClicked.connect(self.remove_item) self.l = l = QVBoxLayout(self) self.la = la = QLabel(_('Choose the actions you want on the toolbar.' ' Drag and drop items in the right hand list to re-arrange the toolbar.')) @@ -423,10 +428,18 @@ class ConfigureToolBar(Dialog): names = self.current_actions.remove_selected() self.available_actions.add_names(names) + def remove_item(self, item): + names = self.current_actions.remove_item(item), + self.available_actions.add_names(names) + def add_actions(self): names = self.available_actions.remove_selected() self.current_actions.add_names(names) + def add_item(self, item): + names = self.available_actions.remove_item(item), + self.current_actions.add_names(names) + def restore_defaults(self): self.current_actions.set_names(DEFAULT_ACTIONS) acnames = all_actions().all_action_names