Allow double clicking int he customize viewer toolbar dialog

This commit is contained in:
Kovid Goyal 2021-04-29 19:48:09 +05:30
parent 9e34e107ab
commit e5654c1c4f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -356,13 +356,16 @@ class ActionsList(QListWidget):
for name in names: for name in names:
self.add_item_from_name(name) 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): def remove_selected(self):
ans = [] ans = []
for item in tuple(self.selectedItems()): for item in tuple(self.selectedItems()):
action = item.data(Qt.ItemDataRole.UserRole) ans.append(self.remove_item(item))
if action is not None or not self.is_source:
self.takeItem(self.row(item))
ans.append(action)
return ans return ans
def add_names(self, names): def add_names(self, names):
@ -388,7 +391,9 @@ class ConfigureToolBar(Dialog):
def setup_ui(self): def setup_ui(self):
acnames = all_actions().all_action_names acnames = all_actions().all_action_names
self.available_actions = ActionsList(acnames - frozenset(current_actions()), parent=self) 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 = ActionsList(current_actions(), parent=self, is_source=False)
self.current_actions.itemDoubleClicked.connect(self.remove_item)
self.l = l = QVBoxLayout(self) self.l = l = QVBoxLayout(self)
self.la = la = QLabel(_('Choose the actions you want on the toolbar.' 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.')) ' 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() names = self.current_actions.remove_selected()
self.available_actions.add_names(names) 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): def add_actions(self):
names = self.available_actions.remove_selected() names = self.available_actions.remove_selected()
self.current_actions.add_names(names) 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): def restore_defaults(self):
self.current_actions.set_names(DEFAULT_ACTIONS) self.current_actions.set_names(DEFAULT_ACTIONS)
acnames = all_actions().all_action_names acnames = all_actions().all_action_names