⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandmanager.cpp

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   // (untranslated), not the label that actually appears in the   // menu (which might be translated).   mCurrentID = NextIdentifier(mCurrentID);   tmpEntry->id = mCurrentID;  #ifdef __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->name = name;   tmpEntry->label = label;   tmpEntry->menu = menu;   tmpEntry->callback = callback;   tmpEntry->multi = multi;   tmpEntry->index = index;   tmpEntry->count = count;   tmpEntry->key = GetKey(label);   tmpEntry->defaultKey = GetKey(label);   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 = gPrefs->Read(name, GetKey(label));   }   gPrefs->SetPath(wxT("/"));      mCommandList.Add(tmpEntry);   mCommandIDHash[tmpEntry->id] = tmpEntry;      if (index==0 || !multi)      mCommandNameHash[name] = tmpEntry;   if (tmpEntry->key != wxT(""))      mCommandKeyHash[tmpEntry->key] = tmpEntry;   return tmpEntry->id;}wxString CommandManager::GetKey(wxString label){   int loc = -1;   loc = label.Find(wxT('\t'));   if (loc == -1)      loc = label.Find(wxT("\\t"));   if (loc == -1)      return wxT("");   return label.Right(label.Length() - (loc+1));}///Enables or disables a menu item based on its name (not the///label in the menu bar, but the name of the command.)///If you give it the name of a multi-item (one that was///added using AddItemList(), it will enable or disable all///of them at oncevoid CommandManager::Enable(CommandListEntry *entry, bool enabled){   // Don't do anything if the command's enabled state   // is already the same   if (entry->enabled == enabled)      return;   entry->enabled = enabled;   if (!entry->menu)      return;         entry->menu->Enable(entry->id, enabled);   if (entry->multi) {      int i;      int ID = entry->id;            for(i=1; i<entry->count; i++) {         ID = NextIdentifier(ID);         wxMenuItem *item = entry->menu->FindItem(ID);         if (item) {            item->Enable(enabled);         } else {            wxLogDebug(wxT("Warning: Menu entry with id %i in %s not found"),                ID, (const wxChar*)entry->name);         }      }   }}void CommandManager::Enable(wxString name, bool enabled){   CommandListEntry *entry = mCommandNameHash[name];   if (!entry || !entry->menu) {      //printf("WARNING: Unknown command enabled: '%s'\n", (const char *)name.mb_str());      return;   }   Enable(entry, enabled);}void CommandManager::EnableUsingFlags(wxUint32 flags, wxUint32 mask){   unsigned int i;   for(i=0; i<mCommandList.GetCount(); i++) {      CommandListEntry *entry = mCommandList[i];      if (entry->multi && entry->index != 0)         continue;      wxUint32 combinedMask = (mask & entry->mask);      if (combinedMask) {         bool enable = ((flags & combinedMask) ==                        (entry->flags & combinedMask));         Enable(entry, enable);      }   }}///Changes the label text of a menu itemvoid CommandManager::Modify(wxString name, wxString newLabel){   CommandListEntry *entry = mCommandNameHash[name];   if (entry && entry->menu) {      newLabel = newLabel.BeforeFirst(wxT('\t'));      if (entry->key)        newLabel = newLabel + wxT("\t") + entry->key;      entry->menu->SetLabel(entry->id, newLabel);   }}/// HandleCommandEntry() takes a CommandListEntry and executes it/// returning true iff successful.  If you pass any flags,///the command won't be executed unless the flags are compatible///with the command's flags.bool CommandManager::HandleCommandEntry(CommandListEntry * entry, wxUint32 flags, wxUint32 mask){   if (!entry)      return false;   wxUint32 combinedMask = (mask & entry->mask);   if (combinedMask) {      bool allowed = ((flags & combinedMask) ==                      (entry->flags & combinedMask));      if (!allowed)         return true;   }      (*(entry->callback))(entry->index);   return true;}///Call this when a menu event is received.///If it matches a command, it will call the appropriate///CommandManagerListener function.  If you pass any flags,///the command won't be executed unless the flags are compatible///with the command's flags.bool CommandManager::HandleMenuID(int id, wxUint32 flags, wxUint32 mask){   CommandListEntry *entry = mCommandIDHash[id];   return HandleCommandEntry( entry, flags, mask );}///Call this when a key event is received.///If it matches a command, it will call the appropriate///CommandManagerListener function.  If you pass any flags,///the command won't be executed unless the flags are compatible///with the command's flags.bool CommandManager::HandleKey(wxKeyEvent &evt, wxUint32 flags, wxUint32 mask){   wxString keyStr = KeyEventToKeyString(evt);	CommandListEntry *entry = mCommandKeyHash[keyStr];   return HandleCommandEntry( entry, flags, mask );}/// HandleTextualCommand() allows us a limitted version of script/batch/// behavior, since we can get from a string command name to the actual/// code to run.bool CommandManager::HandleTextualCommand(wxString & Str, wxUint32 flags, wxUint32 mask){   unsigned int i;   // Linear search for now...   for(i=0; i<mCommandList.GetCount(); i++) {      if (!mCommandList[i]->multi)      {         if( Str.IsSameAs( mCommandList[i]->name ))         {            return HandleCommandEntry( mCommandList[i], flags, mask);   }      }   }   // Not one of the singleton commands.   // We could/should try all the list-style commands.   // instead we only try the effects.   EffectArray *effects;   AudacityProject * proj;   proj = GetActiveProject();   if( !proj )      return false;   int effectFlags = ALL_EFFECTS | CONFIGURED_EFFECT;   effects = Effect::GetEffects(effectFlags);   for(i=0; i<effects->GetCount(); i++) {      wxString effectName = (*effects)[i]->GetEffectName();      if( Str.IsSameAs( effectName ))      {         return proj->OnEffect( effectFlags, (*effects)[i] );       }   }   return false;}void CommandManager::GetAllCommandNames(wxArrayString &names,                                        bool includeMultis){   unsigned int i;   for(i=0; i<mCommandList.GetCount(); i++) {      if (includeMultis || !mCommandList[i]->multi)         names.Add(mCommandList[i]->name);   }}wxString CommandManager::GetLabelFromName(wxString name){   CommandListEntry *entry = mCommandNameHash[name];   if (!entry)      return wxT("");   return entry->label;}wxString CommandManager::GetKeyFromName(wxString name){   CommandListEntry *entry = mCommandNameHash[name];   if (!entry)      return wxT("");    return entry->key;}wxString CommandManager::GetDefaultKeyFromName(wxString name){   CommandListEntry *entry = mCommandNameHash[name];   if (!entry)      return wxT("");    return entry->defaultKey;}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")))            name = value;         if (!wxStrcmp(attr, wxT("key")))            key = value;      }      if (mCommandNameHash[name]) {         mCommandNameHash[name]->key = key;         mXMLKeysRead++;      }   }   return true;}void CommandManager::HandleXMLEndTag(const wxChar *tag){   if (!wxStrcmp(tag, wxT("audacitykeyboard"))) {      wxMessageBox(wxString::Format(_("Loaded %d keyboard shortcuts\n"),                                    mXMLKeysRead),                   _("Loading keyboard shortcuts"),                   wxOK | wxCENTRE);   }}XMLTagHandler *CommandManager::HandleXMLChild(const wxChar *tag){   return this;}void CommandManager::WriteXML(int depth, FILE *fp){   int i;   unsigned int j;   for(i=0; i<depth; i++)      fprintf(fp, "\t");   fprintf(fp, "<audacitykeyboard audacityversion=\"%s\">\n",           AUDACITY_VERSION_STRING);   for(j=0; j<mCommandList.GetCount(); j++)      if (!mCommandList[j]->multi) {         for(i=0; i<depth+1; i++)            fprintf(fp, "\t");                  wxString label = mCommandList[j]->label;         label = wxMenuItem::GetLabelFromText(label.BeforeFirst(wxT('\t')));                  fprintf(fp, "<command name=\"%s\" label=\"%s\" key=\"%s\" />\n",                 (const char *)XMLEsc(mCommandList[j]->name).mb_str(),                 (const char *)XMLEsc(label).mb_str(),                 (const char *)XMLEsc(mCommandList[j]->key).mb_str());      }   for(i=0; i<depth; i++)      fprintf(fp, "\t");   fprintf(fp, "</audacitykeyboard>\n");}void CommandManager::SetDefaultFlags(wxUint32 flags, wxUint32 mask){   mDefaultFlags = flags;   mDefaultMask = mask;}void CommandManager::SetCommandFlags(wxString name,                                     wxUint32 flags, wxUint32 mask){   CommandListEntry *entry = mCommandNameHash[name];   if (entry) {      entry->flags = flags;      entry->mask = mask;   }}void CommandManager::SetCommandFlags(const wxChar **names,                                     wxUint32 flags, wxUint32 mask){   const wxChar **nptr = names;   while(*nptr) {      SetCommandFlags(wxString(*nptr), flags, mask);      nptr++;   }}void CommandManager::SetCommandFlags(wxUint32 flags, wxUint32 mask, ...){   va_list list;   va_start(list, mask);    for(;;) {      const wxChar *name = va_arg(list, const wxChar *);      if (!name)         break;      SetCommandFlags(wxString(name), flags, mask);   }   va_end(list);}// Indentation settings for Vim and Emacs and unique identifier for Arch, a// version control system. Please do not modify past this point.//// Local Variables:// c-basic-offset: 3// indent-tabs-mode: nil// End://// vim: et sts=3 sw=3// arch-tag: 7202d707-9bf3-4735-bdf4-a45b7e004d9a

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -