diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index f4cec4ae7..d0f6338e3 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -761,7 +761,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ Show the shortcuts dialog """ - self.shortcutForm.exec_() + if self.shortcutForm.exec_(): + self.shortcutForm.saveShortcuts() def onModeDefaultItemClicked(self): """ diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index 4e0d7d144..467fb0534 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -39,15 +39,8 @@ class Ui_ShortcutListDialog(object): self.treeWidget.setObjectName(u'treeWidget') self.treeWidget.setColumnCount(3) self.dialogLayout.addWidget(self.treeWidget) - self.defaultButton = QtGui.QRadioButton(shortcutListDialog) - self.defaultButton.setChecked(True) - self.defaultButton.setObjectName(u'defaultButton') - self.dialogLayout.addWidget(self.defaultButton) self.customLayout = QtGui.QHBoxLayout() self.customLayout.setObjectName(u'customLayout') - self.customButton = QtGui.QRadioButton(shortcutListDialog) - self.customButton.setObjectName(u'customButton') - self.customLayout.addWidget(self.customButton) self.shortcutButton = QtGui.QPushButton(shortcutListDialog) self.shortcutButton.setIcon( build_icon(u':/system/system_configure_shortcuts.png')) @@ -82,9 +75,5 @@ class Ui_ShortcutListDialog(object): translate('OpenLP.ShortcutListDialog', 'Action'), translate('OpenLP.ShortcutListDialog', 'Shortcut'), translate('OpenLP.ShortcutListDialog', 'Alternate')]) - self.defaultButton.setText( - translate('OpenLP.ShortcutListDialog', 'Default: %s')) - self.customButton.setText( - translate('OpenLP.ShortcutListDialog', 'Custom:')) self.shortcutButton.setText( translate('OpenLP.ShortcutListDialog', 'None')) diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index fd5a53813..127569f24 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -49,6 +49,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.assingedShortcuts = [] + self.column = -1 self.shortcutButton.setText(u'') QtCore.QObject.connect(self.shortcutButton, QtCore.SIGNAL(u'toggled(bool)'), self.onShortcutButtonClicked) @@ -119,25 +120,40 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): action = item.data(0, QtCore.Qt.UserRole).toPyObject() if action is None: return - # TODO: Sort out which shortcuts should be kept. - action.setShortcuts(QtGui.QKeySequence(self.shortcutButton.text())) - item.setText(1, self.shortcutButton.text()) - self.refreshActionList() + shortcuts = [] + if self.column == 1: + # We are changing the primary shortcut. + shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text())) + if len(action.shortcuts()) == 2: + shortcuts.append(action.shortcuts()[1]) + else: + shortcuts.append(0) + item.setText(1, self.shortcutButton.text()) + elif self.column == 2: + # We are changing the secondary shortcut. + if len(action.shortcuts()) == 1: + shortcuts.append(action.shortcuts()[0]) + else: + shortcuts.append(0) + shortcuts.append(QtGui.QKeySequence(self.shortcutButton.text())) + item.setText(2, self.shortcutButton.text()) + else: + return + action.setShortcuts(shortcuts) def onItemPressed(self, item, column): + self.column = column item = self.treeWidget.currentItem() action = item.data(0, QtCore.Qt.UserRole).toPyObject() - self.shortcutButton.setEnabled(action is not None) - if action is None: - text = u'' - self.shortcutButton.setChecked(False) - else: - if len(action.shortcuts()) == 0: - text = u'' - elif len(action.shortcuts()) == 2 and column == 2: - text = action.shortcuts()[1].toString() - else: - text = action.shortcuts()[0].toString() + self.shortcutButton.setEnabled(True) + text = u'' + if action is None or column not in [1, 2] or \ + len(action.shortcuts()) == 0: + self.shortcutButton.setEnabled(False) + elif column == 1: + text = action.shortcuts()[0].toString() + elif len(action.shortcuts()) == 2: + text = action.shortcuts()[1].toString() self.shortcutButton.setText(text) def saveShortcuts(self): @@ -146,7 +162,12 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): """ settings = QtCore.QSettings() settings.beginGroup(u'shortcuts') - # TODO: Save shortcuts + for category in actionList.categories: + break + for action in category.actions: + if action.defaultShortcuts != action.shortcuts(): + settings.setValue(action.text(), + QtCore.QVariant(action.shortcuts())) settings.endGroup() def loadShortcuts(self): @@ -155,5 +176,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): """ settings = QtCore.QSettings() settings.beginGroup(u'shortcuts') + for shortcut in settings.allKeys(): + pass # TODO: Load shortcuts settings.endGroup() diff --git a/openlp/core/utils/actions.py b/openlp/core/utils/actions.py index 8887a7e30..d94ee1511 100644 --- a/openlp/core/utils/actions.py +++ b/openlp/core/utils/actions.py @@ -27,9 +27,9 @@ The :mod:`~openlp.core.utils.actions` module provides action list classes used by the shortcuts system. """ -class Category(object): +class ActionCategory(object): """ - The :class:`~openlp.core.utils.Category` class encapsulates a + The :class:`~openlp.core.utils.ActionCategory` class encapsulates a category for the :class:`~openlp.core.utils.CategoryList` class. """ def __init__(self, name, weight=0): @@ -161,7 +161,7 @@ class CategoryList(object): self.add(name, weight) def add(self, name, weight=0, actions=None): - category = Category(name, weight) + category = ActionCategory(name, weight) if actions: for action in actions: if isinstance(action, tuple): @@ -185,6 +185,7 @@ class ActionList(object): def add_action(self, action, category, weight=None): if category not in self.categories: self.categories.append(category) + action.defaultShortcuts = action.shortcuts() if weight is None: self.categories[category].actions.append(action) else: