1 /********************************************************************** 2 3 Audacity - A Digital Audio Editor 4 Copyright 1999-2009 Audacity Team 5 License: wxWidgets 6 7 Dan Horgan 8 9 ******************************************************************//** 10 11 \file CommandDirectory.cpp 12 \brief A dictionary of supported scripting commands, including 13 functions to look up a command by name. 14 15 *//*******************************************************************/ 16 17 18 #include "CommandDirectory.h" 19 20 std::unique_ptr<CommandDirectory> CommandDirectory::mInstance; 21 CommandDirectory()22CommandDirectory::CommandDirectory() 23 { 24 // Create the command map. 25 // First we have commands which return information 26 //AddCommand(std::make_unique<MessageCommandType>()); 27 28 // AddCommand(std::make_unique<BatchEvalCommandType>()); 29 30 31 // Legacy adapter commands that previously was needed to 32 // access menu items. 33 //AddCommand(std::make_unique<ExecMenuCommandType>()); 34 35 // Not needed. Sets selected/solo/mute on multiple tracks. 36 //AddCommand(std::make_unique<SetProjectInfoCommandType>()); 37 38 // Moved to AudacityCommand 39 // AddCommand(std::make_unique<OpenProjectCommandType>()); 40 // AddCommand(std::make_unique<SaveProjectCommandType>()); 41 // AddCommand(std::make_unique<ImportCommandType>()); 42 // AddCommand(std::make_unique<ExportCommandType>()); 43 // AddCommand(std::make_unique<HelpCommandType>()); 44 // AddCommand(std::make_unique<GetInfoCommandType>("GetAll")); 45 // AddCommand(std::make_unique<GetInfoCommandType>("GetCommands")); 46 // AddCommand(std::make_unique<GetInfoCommandType>("GetMenus")); 47 // AddCommand(std::make_unique<GetInfoCommandType>("GetMenusPlus")); 48 // AddCommand(std::make_unique<GetInfoCommandType>("GetBoxes")); 49 // AddCommand(std::make_unique<GetInfoCommandType>("GetClips")); 50 51 // AddCommand(std::make_unique<GetTrackInfoCommandType>()); 52 // AddCommand(std::make_unique<GetProjectInfoCommandType>()); 53 // AddCommand(std::make_unique<CompareAudioCommandType>()); 54 // AddCommand(std::make_unique<GetPreferenceCommandType>()); 55 // AddCommand(std::make_unique<SetPreferenceCommandType>()); 56 // AddCommand(std::make_unique<ScreenshotCommandType>()); 57 // AddCommand(std::make_unique<SelectCommandType>()); 58 // AddCommand(std::make_unique<SetTrackInfoCommandType>()); 59 60 } 61 ~CommandDirectory()62CommandDirectory::~CommandDirectory() 63 { 64 } 65 LookUp(const wxString & cmdName) const66OldStyleCommandType *CommandDirectory::LookUp(const wxString &cmdName) const 67 { 68 auto iter = sCmdMap().find(cmdName); 69 if (iter == sCmdMap().end()) 70 { 71 return nullptr; 72 } 73 return iter->second.get(); 74 } 75 sCmdMap()76CommandMap &CommandDirectory::sCmdMap() 77 { 78 static CommandMap theMap; 79 return theMap; 80 } 81 AddCommand(std::unique_ptr<OldStyleCommandType> type)82void CommandDirectory::AddCommand(std::unique_ptr<OldStyleCommandType> type) 83 { 84 wxASSERT(type != NULL); 85 // Internal string is shown but only in assertion message 86 auto cmdName = type->GetSymbol().Internal(); 87 wxASSERT_MSG(sCmdMap().find(cmdName) == sCmdMap().end() 88 , wxT("A command named ") + cmdName 89 + wxT(" already exists.")); 90 91 sCmdMap()[cmdName] = std::move(type); 92 } 93 Get()94CommandDirectory *CommandDirectory::Get() 95 { 96 if (!mInstance) 97 mInstance.reset(safenew CommandDirectory()); 98 return mInstance.get(); 99 } 100