bool CommandManager::HandleXMLTag(const wxChar *tag, const wxChar **attrs) { if (!wxStrcmp(tag, wxT("audacitykeyboard"))) { mXMLKeysRead = 0; } if (!wxStrcmp(tag, wxT("command"))) { wxString name; wxString key; while(*attrs) { const wxChar *attr = *attrs++; const wxChar *value = *attrs++; if (!value) break; if (!wxStrcmp(attr, wxT("name")) && XMLValueChecker::IsGoodString(value)) name = value; if (!wxStrcmp(attr, wxT("key")) && XMLValueChecker::IsGoodString(value)) key = KeyStringNormalize(value); } if (mCommandNameHash[name]) { if (GetDefaultKeyFromName(name) != key) { mCommandNameHash[name]->key = KeyStringNormalize(key); mXMLKeysRead++; } } } return true; }
void CommandManager::SetKeyFromName(wxString name, wxString key) { CommandListEntry *entry = mCommandNameHash[name]; if (entry) { entry->key = KeyStringNormalize(key); } }
wxString CommandManager::GetKey(wxString label) { wxString key = label.AfterFirst(wxT('\t')).BeforeFirst(wxT('\t')); if (key.IsEmpty()) { return key; } return KeyStringNormalize(key); }
wxString KeyStringDisplay(const wxString & key) { wxString newkey = KeyStringNormalize(key); #if defined(__WXMAC__) newkey.Replace(wxT("XCtrl+"), wxT("Control+")); newkey.Replace(wxT("Alt+"), wxT("Option+")); newkey.Replace(wxT("Ctrl+"), wxT("Command+")); #endif return newkey; }
bool KeyConfigPrefs::Apply() { // On the Mac, preferences may be changed without any active // projects. This means that the CommandManager isn't availabe // either. So we can't attempt to save preferences, otherwise // NULL ptr dereferences will happen in ShuttleGui because the // radio buttons are never created. (See Populate() above.) if (!GetActiveProject()) { return true; } ShuttleGui S(this, eIsSavingToPrefs); PopulateOrExchange(S); for (size_t i = 0; i < mNames.GetCount(); i++) { wxString dkey = KeyStringNormalize(mDefaultKeys[i]); wxString name = wxT("/NewKeys/") + mNames[i]; wxString key = KeyStringNormalize(mNewKeys[i]); if (gPrefs->HasEntry(name)) { if (key != KeyStringNormalize(gPrefs->Read(name, key))) { gPrefs->Write(name, key); } if (key == dkey) { gPrefs->DeleteEntry(name); } } else { if (key != dkey) { gPrefs->Write(name, key); } } } return gPrefs->Flush(); }
wxString KeyEventToKeyString(const wxKeyEvent & event) { wxString newStr = wxT(""); long key = event.GetKeyCode(); if (event.ControlDown()) newStr += wxT("Ctrl+"); if (event.AltDown()) newStr += wxT("Alt+"); if (event.ShiftDown()) newStr += wxT("Shift+"); #if defined(__WXMAC__) if (event.RawControlDown()) newStr += wxT("XCtrl+"); #endif if (event.RawControlDown() && key >= 1 && key <= 26) newStr += (wxChar)(64 + key); else if (key >= 33 && key <= 126) newStr += (wxChar)key; else { switch(key) { case WXK_BACK: newStr += wxT("Backspace"); break; case WXK_DELETE: newStr += wxT("Delete"); break; case WXK_SPACE: newStr += wxT("Space"); break; case WXK_TAB: newStr += wxT("Tab"); break; case WXK_RETURN: newStr += wxT("Return"); break; case WXK_PAGEUP: newStr += wxT("PageUp"); break; case WXK_PAGEDOWN: newStr += wxT("PageDown"); break; case WXK_END: newStr += wxT("End"); break; case WXK_HOME: newStr += wxT("Home"); break; case WXK_LEFT: newStr += wxT("Left"); break; case WXK_UP: newStr += wxT("Up"); break; case WXK_RIGHT: newStr += wxT("Right"); break; case WXK_DOWN: newStr += wxT("Down"); break; case WXK_ESCAPE: newStr += wxT("Escape"); break; case WXK_INSERT: newStr += wxT("Insert"); break; case WXK_NUMPAD0: newStr += wxT("NUMPAD0"); break; case WXK_NUMPAD1: newStr += wxT("NUMPAD1"); break; case WXK_NUMPAD2: newStr += wxT("NUMPAD2"); break; case WXK_NUMPAD3: newStr += wxT("NUMPAD3"); break; case WXK_NUMPAD4: newStr += wxT("NUMPAD4"); break; case WXK_NUMPAD5: newStr += wxT("NUMPAD5"); break; case WXK_NUMPAD6: newStr += wxT("NUMPAD6"); break; case WXK_NUMPAD7: newStr += wxT("NUMPAD7"); break; case WXK_NUMPAD8: newStr += wxT("NUMPAD8"); break; case WXK_NUMPAD9: newStr += wxT("NUMPAD9"); break; case WXK_MULTIPLY: newStr += wxT("*"); break; case WXK_ADD: newStr += wxT("+"); break; case WXK_SUBTRACT: newStr += wxT("-"); break; case WXK_DECIMAL: newStr += wxT("."); break; case WXK_DIVIDE: newStr += wxT("/"); break; case WXK_F1: newStr += wxT("F1"); break; case WXK_F2: newStr += wxT("F2"); break; case WXK_F3: newStr += wxT("F3"); break; case WXK_F4: newStr += wxT("F4"); break; case WXK_F5: newStr += wxT("F5"); break; case WXK_F6: newStr += wxT("F6"); break; case WXK_F7: newStr += wxT("F7"); break; case WXK_F8: newStr += wxT("F8"); break; case WXK_F9: newStr += wxT("F9"); break; case WXK_F10: newStr += wxT("F10"); break; case WXK_F11: newStr += wxT("F11"); break; case WXK_F12: newStr += wxT("F12"); break; case WXK_F13: newStr += wxT("F13"); break; case WXK_F14: newStr += wxT("F14"); break; case WXK_F15: newStr += wxT("F15"); break; case WXK_F16: newStr += wxT("F16"); break; case WXK_F17: newStr += wxT("F17"); break; case WXK_F18: newStr += wxT("F18"); break; case WXK_F19: newStr += wxT("F19"); break; case WXK_F20: newStr += wxT("F20"); break; case WXK_F21: newStr += wxT("F21"); break; case WXK_F22: newStr += wxT("F22"); break; case WXK_F23: newStr += wxT("F23"); break; case WXK_F24: newStr += wxT("F24"); break; case WXK_NUMPAD_ENTER: newStr += wxT("NUMPAD_ENTER"); break; case WXK_NUMPAD_F1: newStr += wxT("NUMPAD_F1"); break; case WXK_NUMPAD_F2: newStr += wxT("NUMPAD_F2"); break; case WXK_NUMPAD_F3: newStr += wxT("NUMPAD_F3"); break; case WXK_NUMPAD_F4: newStr += wxT("NUMPAD_F4"); break; case WXK_NUMPAD_HOME: newStr += wxT("NUMPAD_HOME"); break; case WXK_NUMPAD_LEFT: newStr += wxT("NUMPAD_LEFT"); break; case WXK_NUMPAD_UP: newStr += wxT("NUMPAD_UP"); break; case WXK_NUMPAD_RIGHT: newStr += wxT("NUMPAD_RIGHT"); break; case WXK_NUMPAD_DOWN: newStr += wxT("NUMPAD_DOWN"); break; case WXK_NUMPAD_PAGEUP: newStr += wxT("NUMPAD_PAGEUP"); break; case WXK_NUMPAD_PAGEDOWN: newStr += wxT("NUMPAD_PAGEDOWN"); break; case WXK_NUMPAD_END: newStr += wxT("NUMPAD_END"); break; case WXK_NUMPAD_BEGIN: newStr += wxT("NUMPAD_HOME"); break; case WXK_NUMPAD_INSERT: newStr += wxT("NUMPAD_INSERT"); break; case WXK_NUMPAD_DELETE: newStr += wxT("NUMPAD_DELETE"); break; case WXK_NUMPAD_EQUAL: newStr += wxT("NUMPAD_EQUAL"); break; case WXK_NUMPAD_MULTIPLY: newStr += wxT("NUMPAD_MULTIPLY"); break; case WXK_NUMPAD_ADD: newStr += wxT("NUMPAD_ADD"); break; case WXK_NUMPAD_SUBTRACT: newStr += wxT("NUMPAD_SUBTRACT"); break; case WXK_NUMPAD_DECIMAL: newStr += wxT("NUMPAD_DECIMAL"); break; case WXK_NUMPAD_DIVIDE: newStr += wxT("NUMPAD_DIVIDE"); break; default: return wxT(""); // Don't do anything if we don't recognize the key } } return KeyStringNormalize(newStr); }
///Given all of the information for a command, comes up with a new unique ///ID, adds it to a list, and returns the ID. ///WARNING: Does this conflict with the identifiers set for controls/windows? ///If it does, a workaround may be to keep controls below wxID_LOWEST ///and keep menus above wxID_HIGHEST int CommandManager::NewIdentifier(wxString name, wxString label, wxMenu *menu, CommandFunctor *callback, bool multi, int index, int count) { CommandListEntry *tmpEntry = new CommandListEntry; wxString labelPrefix; if (!mSubMenuList.IsEmpty()) { labelPrefix = mSubMenuList[mSubMenuList.GetCount() - 1]->name; } // wxMac 2.5 and higher will do special things with the // Preferences, Exit (Quit), and About menu items, // if we give them the right IDs. // Otherwise we just pick increasing ID numbers for each new // command. Note that the name string we are comparing // ("About", "Preferences") is the internal command name // (untranslated), not the label that actually appears in the // menu (which might be translated). mCurrentID = NextIdentifier(mCurrentID); tmpEntry->id = mCurrentID; tmpEntry->key = GetKey(label); #if defined(__WXMAC__) if (name == wxT("Preferences")) tmpEntry->id = wxID_PREFERENCES; else if (name == wxT("Exit")) tmpEntry->id = wxID_EXIT; else if (name == wxT("About")) tmpEntry->id = wxID_ABOUT; #endif tmpEntry->defaultKey = tmpEntry->key; tmpEntry->name = name; tmpEntry->label = label; tmpEntry->labelPrefix = labelPrefix; tmpEntry->labelTop = wxMenuItem::GetLabelFromText(mCurrentMenuName); tmpEntry->menu = menu; tmpEntry->callback = callback; tmpEntry->multi = multi; tmpEntry->index = index; tmpEntry->count = count; tmpEntry->flags = mDefaultFlags; tmpEntry->mask = mDefaultMask; tmpEntry->enabled = true; // Key from preferences overridse the default key given gPrefs->SetPath(wxT("/NewKeys")); if (gPrefs->HasEntry(name)) { tmpEntry->key = KeyStringNormalize(gPrefs->Read(name, tmpEntry->key)); } gPrefs->SetPath(wxT("/")); mCommandList.Add(tmpEntry); mCommandIDHash[tmpEntry->id] = tmpEntry; if (index == 0 || !multi) { #if defined(__WXDEBUG__) CommandListEntry *prev = mCommandNameHash[name]; if (prev) { wxLogDebug(wxT("Command '%s' defined by '%s' and '%s'"), name.c_str(), prev->label.BeforeFirst(wxT('\t')).c_str(), tmpEntry->label.BeforeFirst(wxT('\t')).c_str()); wxASSERT(!prev); } #endif mCommandNameHash[name] = tmpEntry; } if (tmpEntry->key != wxT("")) { mCommandKeyHash[tmpEntry->key] = tmpEntry; } return tmpEntry->id; }
void CommandManager::SetKeyFromIndex(int i, wxString key) { CommandListEntry *entry = mCommandList[i]; entry->key = KeyStringNormalize(key); }
///Given all of the information for a command, comes up with a new unique ///ID, adds it to a list, and returns the ID. ///WARNING: Does this conflict with the identifiers set for controls/windows? ///If it does, a workaround may be to keep controls below wxID_LOWEST ///and keep menus above wxID_HIGHEST int CommandManager::NewIdentifier(wxString name, wxString label, wxMenu *menu, CommandFunctor *callback, bool multi, int index, int count) { CommandListEntry *tmpEntry = new CommandListEntry; wxString labelPrefix; if (!mSubMenuList.IsEmpty()) { labelPrefix = mSubMenuList[mSubMenuList.GetCount() - 1]->name; } // wxMac 2.5 and higher will do special things with the // Preferences, Exit (Quit), and About menu items, // if we give them the right IDs. // Otherwise we just pick increasing ID numbers for each new // command. Note that the name string we are comparing // ("About", "Preferences") is the internal command name // (untranslated), not the label that actually appears in the // menu (which might be translated). mCurrentID = NextIdentifier(mCurrentID); tmpEntry->id = mCurrentID; tmpEntry->key = GetKey(label); #if defined(__WXMAC__) if (name == wxT("Preferences")) tmpEntry->id = wxID_PREFERENCES; else if (name == wxT("Exit")) tmpEntry->id = wxID_EXIT; else if (name == wxT("About")) tmpEntry->id = wxID_ABOUT; #endif tmpEntry->defaultKey = tmpEntry->key; // For key bindings for commands with a list, such as effects, // the name in prefs is the category name plus the effect name. if( multi ) name= wxString::Format( wxT("%s:%s"), name.c_str(), label.c_str() ); tmpEntry->name = name; tmpEntry->label = label; tmpEntry->labelPrefix = labelPrefix; tmpEntry->labelTop = wxMenuItem::GetLabelFromText(mCurrentMenuName); tmpEntry->menu = menu; tmpEntry->callback = callback; tmpEntry->multi = multi; tmpEntry->index = index; tmpEntry->count = count; tmpEntry->flags = mDefaultFlags; tmpEntry->mask = mDefaultMask; tmpEntry->enabled = true; tmpEntry->wantevent = (label.Find(wxT("\twantevent")) != wxNOT_FOUND); // Key from preferences overridse the default key given gPrefs->SetPath(wxT("/NewKeys")); if (gPrefs->HasEntry(name)) { tmpEntry->key = KeyStringNormalize(gPrefs->Read(name, tmpEntry->key)); } gPrefs->SetPath(wxT("/")); mCommandList.Add(tmpEntry); mCommandIDHash[tmpEntry->id] = tmpEntry; #if defined(__WXDEBUG__) CommandListEntry *prev = mCommandNameHash[name]; if (prev) { // Under Linux it looks as if we may ask for a newID for the same command // more than once. So it's only an error if two different commands // have the exact same name. if( prev->label != tmpEntry->label ) { wxLogDebug(wxT("Command '%s' defined by '%s' and '%s'"), name.c_str(), prev->label.BeforeFirst(wxT('\t')).c_str(), tmpEntry->label.BeforeFirst(wxT('\t')).c_str()); wxFAIL_MSG( wxString::Format(wxT("Command '%s' defined by '%s' and '%s'"), name.c_str(), prev->label.BeforeFirst(wxT('\t')).c_str(), tmpEntry->label.BeforeFirst(wxT('\t')).c_str())); } } #endif mCommandNameHash[name] = tmpEntry; if (tmpEntry->key != wxT("")) { mCommandKeyHash[tmpEntry->key] = tmpEntry; } return tmpEntry->id; }