+void PrefShortcuts::on_newPB_pressed()
+{
+ shortcut_->lfunLE->clear();
+ shortcut_->shortcutLE->reset();
+ shortcut_->exec();
+}
+
+
+void PrefShortcuts::on_removePB_pressed()
+{
+ // it seems that only one item can be selected, but I am
+ // removing all selected items anyway.
+ QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
+ for (int i = 0; i < items.size(); ++i) {
+ string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
+ string lfun = fromqstr(items[i]->text(0));
+ FuncRequest func = lyxaction.lookupFunc(lfun);
+ item_type tag = static_cast<item_type>(items[i]->data(0, Qt::UserRole).toInt());
+
+ switch (tag) {
+ case System: {
+ // for system bind, we do not touch the item
+ // but add an user unbind item
+ user_unbind_.bind(shortcut, func);
+ setItemType(items[i], UserUnbind);
+ removePB->setText(toqstr("Restore"));
+ break;
+ }
+ case UserBind: {
+ // for user_bind, we remove this bind
+ QTreeWidgetItem * parent = items[i]->parent();
+ int itemIdx = parent->indexOfChild(items[i]);
+ parent->takeChild(itemIdx);
+ if (itemIdx > 0)
+ shortcutsTW->scrollToItem(parent->child(itemIdx - 1));
+ else
+ shortcutsTW->scrollToItem(parent);
+ user_bind_.unbind(shortcut, func);
+ break;
+ }
+ case UserUnbind: {
+ // for user_unbind, we remove the unbind, and the item
+ // become System again.
+ user_unbind_.unbind(shortcut, func);
+ setItemType(items[i], System);
+ removePB->setText(toqstr("Remove"));
+ 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);
+ }
+ }
+ }
+}
+
+
+void PrefShortcuts::on_searchLE_textEdited()
+{
+ if (searchLE->text().isEmpty()) {
+ // show all hidden items
+ QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Hidden);
+ while (*it)
+ shortcutsTW->setItemHidden(*it++, false);
+ return;
+ }
+ // search both columns
+ QList<QTreeWidgetItem *> matched = shortcutsTW->findItems(searchLE->text(),
+ Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 0);
+ matched += shortcutsTW->findItems(searchLE->text(),
+ Qt::MatchFlags(Qt::MatchContains | Qt::MatchRecursive), 1);
+
+ // hide everyone (to avoid searching in matched QList repeatedly
+ QTreeWidgetItemIterator it(shortcutsTW, QTreeWidgetItemIterator::Selectable);
+ 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);
+ }
+}
+
+
+void PrefShortcuts::shortcut_okPB_pressed()
+{
+ string lfun = fromqstr(shortcut_->lfunLE->text());
+ FuncRequest func = lyxaction.lookupFunc(lfun);
+
+ if (func.action == LFUN_UNKNOWN_ACTION) {
+ Alert::error(_("Failed to create shortcut"),
+ _("Unknown or invalid LyX function"));
+ return;
+ }
+
+ KeySequence k = shortcut_->shortcutLE->getKeySequence();
+ if (k.length() == 0) {
+ Alert::error(_("Failed to create shortcut"),
+ _("Invalid or empty key sequence"));
+ return;
+ }
+
+ // if both lfun and shortcut is valid
+ if (user_bind_.hasBinding(k, func) || system_bind_.hasBinding(k, func)) {
+ Alert::error(_("Failed to create shortcut"),
+ _("Shortcut is already defined"));
+ return;
+ }
+
+ QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
+ if (item) {
+ user_bind_.bind(&k, func);
+ shortcutsTW->sortItems(0, Qt::AscendingOrder);
+ shortcutsTW->setItemExpanded(item->parent(), true);
+ shortcutsTW->scrollToItem(item);
+ } else {
+ Alert::error(_("Failed to create shortcut"),
+ _("Can not insert shortcut to the list"));
+ return;
+ }
+}
+
+
+void PrefShortcuts::shortcut_clearPB_pressed()
+{
+ shortcut_->shortcutLE->reset();
+ shortcut_->shortcutLE->setFocus();
+}
+
+
+/////////////////////////////////////////////////////////////////////
+//
+// PrefIdentity
+//
+/////////////////////////////////////////////////////////////////////
+