diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index 90f338c287..0352dcf327 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -2269,6 +2269,7 @@ void PrefShortcuts::modifyShortcut() QTreeWidgetItem * item = shortcutsTW->currentItem(); if (item->flags() & Qt::ItemIsSelectable) { shortcut_->lfunLE->setText(item->text(0)); + save_lfun_ = item->text(0); shortcut_->shortcutWG->setText(item->text(1)); KeySequence seq; seq.parse(fromqstr(item->data(1, Qt::UserRole).toString())); @@ -2279,33 +2280,7 @@ void PrefShortcuts::modifyShortcut() } -void PrefShortcuts::select_bind() -{ - QString file = form_->browsebind(internalPath(bindFileED->text())); - if (!file.isEmpty()) { - bindFileED->setText(file); - system_bind_ = KeyMap(); - system_bind_.read(fromqstr(file)); - updateShortcutsTW(); - } -} - - -void PrefShortcuts::on_modifyPB_pressed() -{ - modifyShortcut(); -} - - -void PrefShortcuts::on_newPB_pressed() -{ - shortcut_->lfunLE->clear(); - shortcut_->shortcutWG->reset(); - shortcut_->exec(); -} - - -void PrefShortcuts::on_removePB_pressed() +void PrefShortcuts::removeShortcut() { // it seems that only one item can be selected, but I am // removing all selected items anyway. @@ -2357,6 +2332,39 @@ void PrefShortcuts::on_removePB_pressed() } +void PrefShortcuts::select_bind() +{ + QString file = form_->browsebind(internalPath(bindFileED->text())); + if (!file.isEmpty()) { + bindFileED->setText(file); + system_bind_ = KeyMap(); + system_bind_.read(fromqstr(file)); + updateShortcutsTW(); + } +} + + +void PrefShortcuts::on_modifyPB_pressed() +{ + modifyShortcut(); +} + + +void PrefShortcuts::on_newPB_pressed() +{ + shortcut_->lfunLE->clear(); + shortcut_->shortcutWG->reset(); + save_lfun_ = QString(); + shortcut_->exec(); +} + + +void PrefShortcuts::on_removePB_pressed() +{ + removeShortcut(); +} + + void PrefShortcuts::on_searchLE_textEdited() { if (searchLE->text().isEmpty()) { @@ -2386,8 +2394,8 @@ void PrefShortcuts::on_searchLE_textEdited() void PrefShortcuts::shortcut_okPB_pressed() { - string lfun = fromqstr(shortcut_->lfunLE->text()); - FuncRequest func = lyxaction.lookupFunc(lfun); + QString const new_lfun = shortcut_->lfunLE->text(); + FuncRequest func = lyxaction.lookupFunc(fromqstr(new_lfun)); if (func.action == LFUN_UNKNOWN_ACTION) { Alert::error(_("Failed to create shortcut"), @@ -2409,6 +2417,11 @@ void PrefShortcuts::shortcut_okPB_pressed() return; } + if (!save_lfun_.isEmpty() && new_lfun == save_lfun_) + // real modification of the lfun's shortcut, + // so remove the previous one + removeShortcut(); + QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind); if (item) { user_bind_.bind(&k, func); diff --git a/src/frontends/qt4/GuiPrefs.h b/src/frontends/qt4/GuiPrefs.h index b2e6813199..0eebd86f04 100644 --- a/src/frontends/qt4/GuiPrefs.h +++ b/src/frontends/qt4/GuiPrefs.h @@ -436,6 +436,7 @@ public: void update(LyXRC const & rc); void updateShortcutsTW(); void modifyShortcut(); + void removeShortcut(); /// void setItemType(QTreeWidgetItem * item, ItemType tag); QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun, @@ -476,6 +477,8 @@ private: KeyMap system_bind_; KeyMap user_bind_; KeyMap user_unbind_; + /// + QString save_lfun_; };