/// Defines key maps and actions for key sequences
class KeyMap {
public:
+ enum ItemType {
+ System, //< loaded from a bind file
+ UserBind, //< \bind 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.
+ };
/**
* Bind/Unbind a key sequence to an action.
* @return 0 on success, or position in string seq where error
* @param unbind use \unbind instead of \bind, indicating this KeyMap
* actually record unbind maps.
*/
- void write(std::string const & bind_file, bool append, bool unbind=false) const;
+ void write(std::string const & bind_file, bool append, bool unbind = false) const;
/**
* print all available keysyms
* @return the action / LFUN_COMMAND_PREFIX / LFUN_UNKNOWN_ACTION
*/
FuncRequest const &
- lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
+ lookup(KeySymbol const & key, KeyModifier mod, KeySequence * seq) const;
///
typedef std::vector<KeySequence> Bindings;
docstring printBindings(FuncRequest const & func) const;
struct Binding {
- Binding(FuncRequest const & r, KeySequence const & s, int t)
+ Binding(FuncRequest const & r, KeySequence const & s, ItemType t)
: request(r), sequence(s), tag(t) {}
FuncRequest request;
KeySequence sequence;
- int tag;
+ KeyMap::ItemType tag;
};
typedef std::vector<Binding> BindingList;
/**
* @param unbound list unbound (func without any keybinding) as well
* @param tag an optional tag to indicate the source of the bindinglist
*/
- BindingList listBindings(bool unbound, int tag = 0) const;
+ BindingList listBindings(bool unbound, ItemType tag = System) const;
/**
* Given an action, find the first 1-key binding (if it exists).
* [only used by the Qt/Mac frontend]
*/
std::pair<KeySymbol, KeyModifier>
- find1keybinding(FuncRequest const & func) const;
+ find1keybinding(FuncRequest const & func) const;
/**
* Returns a string of the given keysym, with modifiers.
* @param prefix a sequence to prepend the results
*/
Bindings findBindings(FuncRequest const & func,
- KeySequence const & prefix) const;
+ KeySequence const & prefix) const;
void listBindings(BindingList & list, KeySequence const & prefix,
- int tag) const;
+ ItemType tag) const;
/// is the table empty ?
bool empty() const { return table.empty(); }
// listBindings(unbound=true) lists all bound and unbound lfuns
// Items in this list is tagged by its source.
KeyMap::BindingList bindinglist = system_bind_.listBindings(true,
- static_cast<int>(System));
+ KeyMap::System);
KeyMap::BindingList user_bindinglist = user_bind_.listBindings(false,
- static_cast<int>(UserBind));
+ KeyMap::UserBind);
KeyMap::BindingList user_unbindinglist = user_unbind_.listBindings(false,
- static_cast<int>(UserUnbind));
+ KeyMap::UserUnbind);
bindinglist.insert(bindinglist.end(), user_bindinglist.begin(),
user_bindinglist.end());
bindinglist.insert(bindinglist.end(), user_unbindinglist.begin(),
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, ItemType(it->tag));
+ insertShortcutItem(it->request, it->sequence, KeyMap::ItemType(it->tag));
shortcutsTW->sortItems(0, Qt::AscendingOrder);
QList<QTreeWidgetItem*> items = shortcutsTW->selectedItems();
}
-void PrefShortcuts::setItemType(QTreeWidgetItem * item, ItemType tag)
+void PrefShortcuts::setItemType(QTreeWidgetItem * item, KeyMap::ItemType tag)
{
item->setData(0, Qt::UserRole, QVariant(tag));
QFont font;
switch (tag) {
- case System:
+ case KeyMap::System:
break;
- case UserBind:
+ case KeyMap::UserBind:
font.setBold(true);
break;
- case UserUnbind:
+ case KeyMap::UserUnbind:
font.setStrikeOut(true);
break;
// this item is not displayed now.
- case UserExtraUnbind:
+ case KeyMap::UserExtraUnbind:
font.setStrikeOut(true);
break;
}
QTreeWidgetItem * PrefShortcuts::insertShortcutItem(FuncRequest const & lfun,
- KeySequence const & seq, ItemType tag)
+ KeySequence const & seq, KeyMap::ItemType tag)
{
FuncCode 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));
- ItemType item_tag = tag;
+ KeyMap::ItemType item_tag = tag;
QTreeWidgetItem * newItem = 0;
// for unbind items, try to find an existing item in the system bind list
- if (tag == UserUnbind) {
+ if (tag == KeyMap::UserUnbind) {
QList<QTreeWidgetItem*> const items = shortcutsTW->findItems(lfun_name,
Qt::MatchFlags(Qt::MatchExactly | Qt::MatchRecursive), 0);
for (int i = 0; i < items.size(); ++i) {
newItem = items[i];
break;
}
- // if not found, this unbind item is UserExtraUnbind
+ // if not found, this unbind item is KeyMap::UserExtraUnbind
// Such an item is not displayed to avoid confusion (what is
// unmatched removed?).
if (!newItem) {
- item_tag = UserExtraUnbind;
+ item_tag = KeyMap::UserExtraUnbind;
return 0;
}
}
if (items.isEmpty())
return;
- ItemType tag = static_cast<ItemType>(items[0]->data(0, Qt::UserRole).toInt());
- if (tag == UserUnbind)
+ KeyMap::ItemType tag =
+ static_cast<KeyMap::ItemType>(items[0]->data(0, Qt::UserRole).toInt());
+ if (tag == KeyMap::UserUnbind)
removePB->setText(qt_("Res&tore"));
else
removePB->setText(qt_("Remo&ve"));
string shortcut = fromqstr(items[i]->data(1, Qt::UserRole).toString());
string lfun = fromqstr(items[i]->text(0));
FuncRequest func = lyxaction.lookupFunc(lfun);
- ItemType tag = static_cast<ItemType>(items[i]->data(0, Qt::UserRole).toInt());
+ KeyMap::ItemType tag =
+ static_cast<KeyMap::ItemType>(items[i]->data(0, Qt::UserRole).toInt());
switch (tag) {
- case System: {
+ case KeyMap::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);
+ setItemType(items[i], KeyMap::UserUnbind);
removePB->setText(qt_("Res&tore"));
break;
}
- case UserBind: {
+ case KeyMap::UserBind: {
// for user_bind, we remove this bind
QTreeWidgetItem * parent = items[i]->parent();
int itemIdx = parent->indexOfChild(items[i]);
user_bind_.unbind(shortcut, func);
break;
}
- case UserUnbind: {
+ case KeyMap::UserUnbind: {
// for user_unbind, we remove the unbind, and the item
- // become System again.
+ // become KeyMap::System again.
user_unbind_.unbind(shortcut, func);
- setItemType(items[i], System);
+ setItemType(items[i], KeyMap::System);
removePB->setText(qt_("Remo&ve"));
break;
}
- case UserExtraUnbind: {
+ case KeyMap::UserExtraUnbind: {
// for user unbind that is not in system bind file,
// remove this unbind file
QTreeWidgetItem * parent = items[i]->parent();
// so remove the previous one
removeShortcut();
- QTreeWidgetItem * item = insertShortcutItem(func, k, UserBind);
+ QTreeWidgetItem * item = insertShortcutItem(func, k, KeyMap::UserBind);
if (item) {
user_bind_.bind(&k, func);
shortcutsTW->sortItems(0, Qt::AscendingOrder);