]> git.lyx.org Git - lyx.git/commitdiff
More work on the Shortcuts UI:
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 22 Jul 2008 09:35:46 +0000 (09:35 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 22 Jul 2008 09:35:46 +0000 (09:35 +0000)
-  modifying a shortcut removes the previous one
   (if it's not a system shortcut)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25789 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h

index 90f338c28701c4e2869576c77690cea12029d608..0352dcf327c7dbc2dabe73772fa1a2028aebe2f2 100644 (file)
@@ -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);
index b2e6813199901e6de60a62e9098ba9c087d3081f..0eebd86f04d4f62fc78f059a5284265b3cd40057 100644 (file)
@@ -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_;
 };