+ switch (tag) {
+ case System:
+ break;
+ case UserBind:
+ font.setBold(true);
+ break;
+ case UserUnbind:
+ font.setStrikeOut(true);
+ break;
+ // this item is not displayed now.
+ case UserExtraUnbind:
+ font.setStrikeOut(true);
+ break;
+ }
+
+ item->setFont(1, font);
+}
+
+
+QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
+ KeySequence const & seq, item_type tag)
+{
+ kb_action action = lfun.action;
+ string const action_name = lyxaction.getActionName(action);
+ QString const lfun_name = toqstr(from_utf8(action_name)
+ + " " + lfun.argument());
+ QString const shortcut = toqstr(seq.print(KeySequence::ForGui));
+ 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);
+ for (int i = 0; i < items.size(); ++i) {
+ if (items[i]->text(1) == shortcut)
+ newItem = items[i];
+ break;
+ }
+ // if not found, this unbind item is UserExtraUnbind
+ // Such an item is not displayed to avoid confusion (what is
+ // unmatched removed?).
+ if (!newItem) {
+ item_tag = UserExtraUnbind;
+ return NULL;
+ }
+ }
+ if (!newItem) {
+ switch(lyxaction.getActionType(action)) {
+ case LyXAction::Hidden:
+ return NULL;
+ case LyXAction::Edit:
+ newItem = new QTreeWidgetItem(editItem_);
+ break;
+ case LyXAction::Math:
+ newItem = new QTreeWidgetItem(mathItem_);
+ break;
+ case LyXAction::Buffer:
+ newItem = new QTreeWidgetItem(bufferItem_);
+ break;
+ case LyXAction::Layout:
+ newItem = new QTreeWidgetItem(layoutItem_);
+ break;
+ case LyXAction::System:
+ newItem = new QTreeWidgetItem(systemItem_);
+ break;
+ default:
+ // this should not happen
+ newItem = new QTreeWidgetItem(shortcutsTW);
+ }
+ }
+
+ newItem->setText(0, lfun_name);
+ newItem->setText(1, shortcut);
+ // record BindFile representation to recover KeySequence when needed.
+ newItem->setData(1, Qt::UserRole, toqstr(seq.print(KeySequence::BindFile)));
+ setItemType(newItem, item_tag);
+ return newItem;
+}
+
+
+void PrefShortcuts::on_shortcutsTW_itemSelectionChanged()
+{
+ QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
+ removePB->setEnabled(!items.isEmpty() && !items[0]->text(1).isEmpty());
+ if (items.isEmpty())
+ return;
+
+ item_type tag = static_cast<item_type>(items[0]->data(0, Qt::UserRole).toInt());
+ if (tag == UserUnbind)
+ removePB->setText(toqstr("Restore"));
+ else
+ removePB->setText(toqstr("Remove"));
+}
+
+
+void PrefShortcuts::on_shortcutsTW_itemDoubleClicked()
+{
+ QTreeWidgetItem * item = shortcutsTW->currentItem();
+ if (item->flags() & Qt::ItemIsSelectable) {
+ shortcut_->lfunLE->setText(item->text(0));
+ // clear the shortcut because I assume that a user will enter
+ // a new shortcut.
+ shortcut_->shortcutLE->reset();
+ shortcut_->shortcutLE->setFocus();
+ shortcut_->exec();
+ }