/** Parse a key binding. */ void ParseKey(const TokenNode *tp) { const char *key; const char *code; const char *mask; const char *action; const char *command; KeyType k; int x; Assert(tp); mask = FindAttribute(tp->attributes, "mask"); key = FindAttribute(tp->attributes, "key"); code = FindAttribute(tp->attributes, "keycode"); action = tp->value; if(JUNLIKELY(action == NULL)) { ParseError(tp, "no action specified for Key"); return; } command = NULL; k = KEY_NONE; if(!strncmp(action, "exec:", 5)) { k = KEY_EXEC; command = action + 5; } else if(!strncmp(action, "root:", 5)) { k = KEY_ROOT; command = action + 5; } else { for(x = 0; KEY_MAP[x].name; x++) { if(!strcmp(action, KEY_MAP[x].name)) { k = KEY_MAP[x].key; break; } } } /* Insert the binding if it's valid. */ if(JUNLIKELY(k == KEY_NONE)) { ParseError(tp, "invalid Key action: \"%s\"", action); } else { InsertBinding(k, mask, key, code, command); } }
/** Parse a key binding. */ void ParseKey(const TokenNode *tp) { const char *key; const char *code; const char *mask; const char *action; const char *command; KeyType k; Assert(tp); mask = FindAttribute(tp->attributes, "mask"); key = FindAttribute(tp->attributes, "key"); code = FindAttribute(tp->attributes, "keycode"); action = tp->value; if(JUNLIKELY(action == NULL)) { ParseError(tp, "no action specified for Key"); return; } command = NULL; k = KEY_NONE; if(!strncmp(action, "exec:", 5)) { k = KEY_EXEC; command = action + 5; } else if(!strncmp(action, "root:", 5)) { k = KEY_ROOT; command = action + 5; } else { /* Look up the option in the key map using binary search. */ const int x = FindValue(KEY_MAP, KEY_MAP_COUNT, action); if(x >= 0) { k = (KeyType)x; } } /* Insert the binding if it's valid. */ if(JUNLIKELY(k == KEY_NONE)) { ParseError(tp, "invalid Key action: \"%s\"", action); } else { InsertBinding(k, mask, key, code, command); } }
void Accelerators::ParseMenu(wxMenuItem* item) { if(item->IsSeparator()) return; // read the data from the menu item wxString text = item->GetText(); int tab = text.Find('\t'); wxString label, accel = wxT(""); if(tab == wxNOT_FOUND) { label = text; } else { label = text.Mid(0, tab); accel = text.Mid(tab+1); if(m_needDefault) { m_defaultBindings[label] = accel; } else { // When reloading the accelerators, if the user removes a custom accelerator, it needs to reset to the original value map<wxString, wxString>::iterator iterator; iterator = m_defaultBindings.find(normalize(label)); if(iterator != m_defaultBindings.end()) { accel = iterator->second; } } } // now check if there is a custom shortcut map<wxString, wxString>::iterator iterator; iterator = m_customBindings.find(normalize(label)); if(iterator != m_customBindings.end()) { accel = iterator->second; text = label; if(accel.Len() > 0) { text += '\t'; text += accel; } item->SetText(text); } accel = accel.Trim(); InsertBinding(item, accel); }
/** * Traverses the menubar. * For each menu item, it grabs the binding from the menu * and it checks if there is a custom binding for that menu item. */ void Accelerators::ParseMenu() { std::map<int, KeyChord*>::iterator iterator; for(iterator = m_chords.begin(); iterator != m_chords.end(); iterator++) { KeyChord* chord = iterator->second; std::map<int, KeyBinding*>::iterator iterator2; for(iterator2 = chord->bindings.begin(); iterator2 != chord->bindings.end(); iterator2++) { KeyBinding* binding = iterator2->second; delete binding; } delete chord; } std::map<int, KeyBinding*>::iterator iterator2; for(iterator2 = m_bindings.begin(); iterator2 != m_bindings.end(); iterator2++) { KeyBinding* binding = iterator2->second; delete binding; } m_chords.clear(); m_bindings.clear(); for(unsigned int c = 0; c < m_definedBindings.size(); c++) { // If the original binding is inserted, and it also appears on the menu, it will be deleted when the menu is reparsed and lead to a later segfault InsertBinding(new KeyBinding(m_definedBindings[c]->accel, m_definedBindings[c]->id)); } m_needDefault = m_defaultBindings.size() == 0; wxMenuBar* menuBar = m_editorFrame->GetMenuBar(); if(!menuBar) return; const unsigned int bundles = menuBar->FindMenu(_("&Bundles")); for(unsigned int c = 0; c < menuBar->GetMenuCount(); c++) { if(c == bundles) ParseBundlesMenu(menuBar->GetMenu(c)); else ParseMenu(menuBar->GetMenu(c)); } }
void Accelerators::InsertBinding(wxMenuItem* item, wxString& accel) { if(accel.Len() == 0) return; KeyBinding* binding = new KeyBinding(item, accel); InsertBinding(binding); }