]> git.lyx.org Git - features.git/commitdiff
ShortcutPrefs: hide empty lfuns for which there is already a binding
authorGuillaume Munch <gm@lyx.org>
Tue, 23 Feb 2016 22:02:02 +0000 (22:02 +0000)
committerGuillaume Munch <gm@lyx.org>
Mon, 30 May 2016 23:14:13 +0000 (00:14 +0100)
src/frontends/qt4/GuiPrefs.cpp
src/frontends/qt4/GuiPrefs.h

index 91f872090b94f89709283e1b2f7602519364463e..109de9351ea4a178869b43c36baf0acbdc53ccb1 100644 (file)
@@ -2813,7 +2813,7 @@ void PrefShortcuts::updateShortcutsTW()
        KeyMap::BindingList::const_iterator it = bindinglist.begin();
        KeyMap::BindingList::const_iterator it_end = bindinglist.end();
        for (; it != it_end; ++it)
-               insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
+               insertShortcutItem(it->request, it->sequence, it->tag);
 
        shortcutsTW->sortItems(0, Qt::AscendingOrder);
        on_shortcutsTW_itemSelectionChanged();
@@ -2829,6 +2829,14 @@ KeyMap::ItemType PrefShortcuts::itemType(QTreeWidgetItem & item)
 }
 
 
+//static
+bool PrefShortcuts::isAlwaysHidden(QTreeWidgetItem & item)
+{
+       // Hide rebound system settings that are empty
+       return itemType(item) == KeyMap::UserUnbind && item.text(1).isEmpty();
+}
+
+
 void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
 {
        item->setData(0, Qt::UserRole, QVariant(tag));
@@ -2848,7 +2856,7 @@ void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
                font.setStrikeOut(true);
                break;
        }
-
+       item->setHidden(isAlwaysHidden(*item));
        item->setFont(1, font);
 }
 
@@ -2951,6 +2959,23 @@ void PrefShortcuts::modifyShortcut()
 }
 
 
+void PrefShortcuts::unhideEmpty(QString const & lfun, bool select)
+{
+       // list of items that match lfun
+       QList<QTreeWidgetItem*> items = shortcutsTW->findItems(lfun,
+            Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
+       for (int i = 0; i < items.size(); ++i) {
+               QTreeWidgetItem * item = items[i];
+               if (isAlwaysHidden(*item)) {
+                       setItemType(item, KeyMap::System);
+                       if (select)
+                               shortcutsTW->setCurrentItem(item);
+                       return;
+               }
+       }
+}
+
+
 void PrefShortcuts::removeShortcut()
 {
        // it seems that only one item can be selected, but I am
@@ -2980,6 +3005,9 @@ void PrefShortcuts::removeShortcut()
                        else
                                shortcutsTW->scrollToItem(parent);
                        user_bind_.unbind(shortcut, func);
+                       // If this user binding hid an empty system binding, unhide the
+                       // latter and select it.
+                       unhideEmpty(items[i]->text(0), true);
                        break;
                }
                case KeyMap::UserUnbind: {
@@ -3028,6 +3056,7 @@ void PrefShortcuts::deactivateShortcuts(QList<QTreeWidgetItem*> const & items)
                        int itemIdx = parent->indexOfChild(items[i]);
                        parent->takeChild(itemIdx);
                        user_bind_.unbind(shortcut, func);
+                       unhideEmpty(items[i]->text(0), false);
                        break;
                }
                default:
@@ -3076,8 +3105,11 @@ void PrefShortcuts::on_searchLE_textEdited()
        if (searchLE->text().isEmpty()) {
                // show all hidden items
                QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
-               while (*it)
-                       shortcutsTW->setItemHidden(*it++, false);
+               for (; *it; ++it)
+                       shortcutsTW->setItemHidden(*it, isAlwaysHidden(**it));
+               // close all categories
+               for (int i = 0; i < shortcutsTW->topLevelItemCount(); ++i)
+                       shortcutsTW->collapseItem(shortcutsTW->topLevelItem(i));
                return;
        }
        // search both columns
@@ -3091,10 +3123,11 @@ void PrefShortcuts::on_searchLE_textEdited()
        while (*it)
                shortcutsTW->setItemHidden(*it++, true);
        // show matched items
-       for (int i = 0; i < matched.size(); ++i) {
-               shortcutsTW->setItemHidden(matched[i], false);
-               shortcutsTW->setItemExpanded(matched[i]->parent(), true);
-       }
+       for (int i = 0; i < matched.size(); ++i)
+               if (!isAlwaysHidden(*matched[i])) {
+                       shortcutsTW->setItemHidden(matched[i], false);
+                       shortcutsTW->setItemExpanded(matched[i]->parent(), true);
+               }
 }
 
 
index 9f6c35e712c2924a8c0d3e1e51c12a71f2c8ed26..1b37b323e3d01d57176709c653a1b389239f1818 100644 (file)
@@ -491,6 +491,12 @@ private:
        void setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag);
        ///
        static KeyMap::ItemType itemType(QTreeWidgetItem & item);
+       /// some items need to be always hidden, for instance empty rebound
+       /// system keys
+       static bool isAlwaysHidden(QTreeWidgetItem & item);
+       /// unhide an empty system binding that may have been hidden
+       /// returns either null or the unhidden shortcut
+       void unhideEmpty(QString const & lfun, bool select);
        ///
        QTreeWidgetItem * insertShortcutItem(FuncRequest const & lfun,
                KeySequence const & shortcut, KeyMap::ItemType tag);