]> git.lyx.org Git - features.git/commitdiff
PrefShortcuts: handle user unbind items that have no corresponding item in system...
authorBo Peng <bpeng@lyx.org>
Sun, 21 Oct 2007 05:30:43 +0000 (05:30 +0000)
committerBo Peng <bpeng@lyx.org>
Sun, 21 Oct 2007 05:30:43 +0000 (05:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21096 a592a061-630c-0410-9148-cb99ea01b6c8

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

index e679612d36ec86421760832b0c50fca6d3d1fe48..40b82c1ee6b97941377f1c4debc5a69d16ec9cd1 100644 (file)
@@ -1846,6 +1846,15 @@ void PrefShortcuts::setItemType(QTreeWidgetItem * item, item_type tag)
 #else
                item->setTextColor(QColor("red"));
 #endif
+               break;
+       case UserExtraUnbind:
+#if QT_VERSION >= 0x040200
+               item->setForeground(0, QBrush("purple"));
+               item->setForeground(1, QBrush("purple"));
+#else
+               item->setTextColor(QColor("purple"));
+#endif
+               break;
        }
 }
 
@@ -1861,14 +1870,21 @@ QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
        // if the Shortcut dialog can hide all the bind file stuff,
        // Portable format can be used.
        QString const shortcut = toqstr(seq.print(KeySequence::BindFile));
+       item_type item_tag = tag;
 
        QTreeWidgetItem * newItem = NULL;
        // for unbind items, try to find an existing item in the system bind list
        if (tag == UserUnbind) {
                QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name, 
                        Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
-               if (!items.empty())
-                       newItem = items[0];
+               for (size_t i = 0; i < items.size(); ++i) {
+                       if (items[i]->text(1) == shortcut)
+                               newItem = items[i];
+                               break;
+                       }
+               // if not found, this unbind item is UserExtraUnbind
+               if (!newItem)
+                       item_tag = UserExtraUnbind;
        }
        if (!newItem) {
                switch(lyxaction.getActionType(action)) {
@@ -1897,7 +1913,7 @@ QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
 
        newItem->setText(0, lfun_name);
        newItem->setText(1, shortcut);
-       setItemType(newItem, tag);
+       setItemType(newItem, item_tag);
        return newItem;
 }
 
@@ -1983,6 +1999,13 @@ void PrefShortcuts::on_removePB_pressed()
                        setItemType(items[i], System);
                        break;
                }
+               case UserExtraUnbind: {
+                       // for user unbind that is not in system bind file,
+                       // remove this unbind file
+                       QTreeWidgetItem * parent = items[i]->parent();
+                       parent->takeChild(parent->indexOfChild(items[i]));
+                       user_unbind_.unbind(shortcut, func);
+               }
                }
        }
 }
index b057c26353127a2cd21292c827ebdf5aa74f9cd4..e4b5f19a96b6578f7cebec5fc1f667c0629852bb 100644 (file)
@@ -365,7 +365,10 @@ private:
        enum item_type {
                System,         //< loaded from a bind file
                UserBind,       //< \bind loaded from user.bind
-               UserUnbind      //< \unbind loaded from user.bind
+               UserUnbind,     //< \unbind loaded from user.bind, with corresponding
+                                       //<    entry in system bind file
+               UserExtraUnbind //< \unbind loaded from user.bind, without
+                                               //<    corresponding entry in system bind file.
        };
 public:
        PrefShortcuts(GuiPreferences * form, QWidget * parent = 0);