Changeset 7233 for code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
- Timestamp:
- Aug 28, 2010, 12:02:03 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
r7232 r7233 38 38 #include "core/ConfigFileManager.h" 39 39 #include "core/ConfigValueContainer.h" 40 #include "CommandExecutor.h" 41 #include "ConsoleCommand.h" 40 42 #include "TclThreadManager.h" 41 #include "ConsoleCommand.h"42 43 43 44 // Boost 1.36 has some issues with deprecated functions that have been omitted … … 57 58 } 58 59 59 bool groupIsVisible(const std::map<std::string, _ConsoleCommand*>& group) 60 { 61 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command) 62 if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden()) 63 return true; 64 65 return false; 60 namespace detail 61 { 62 bool groupIsVisible(const std::map<std::string, _ConsoleCommand*>& group, bool bOnlyShowHidden) 63 { 64 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = group.begin(); it_command != group.end(); ++it_command) 65 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden) 66 return true; 67 68 return false; 69 } 70 71 ArgumentCompletionList _groupsandcommands(bool bOnlyShowHidden) 72 { 73 ArgumentCompletionList groupList; 74 75 const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands(); 76 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) 77 if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "") 78 groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); 79 80 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find(""); 81 if (it_group != commands.end()) 82 { 83 groupList.push_back(ArgumentCompletionListElement("", "", "\n")); 84 85 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 86 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden) 87 groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 88 } 89 90 return groupList; 91 } 92 93 ArgumentCompletionList _subcommands(const std::string& fragment, const std::string& group, bool bOnlyShowHidden) 94 { 95 ArgumentCompletionList commandList; 96 97 std::string groupLC = getLowercase(group); 98 99 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin(); 100 for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group) 101 if (getLowercase(it_group->first) == groupLC) 102 break; 103 104 if (it_group != _ConsoleCommand::getCommands().end()) 105 { 106 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 107 if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden) 108 commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 109 } 110 111 return commandList; 112 } 66 113 } 67 114 68 115 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)() 69 116 { 70 ArgumentCompletionList groupList; 71 72 const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands(); 73 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) 74 if (groupIsVisible(it_group->second)) 75 groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); 76 77 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find(""); 78 if (it_group != commands.end()) 79 { 80 groupList.push_back(ArgumentCompletionListElement("\n")); 81 82 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 83 if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden()) 84 groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 85 } 86 87 return groupList; 117 return detail::_groupsandcommands(false); 88 118 } 89 119 90 120 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group) 91 121 { 92 ArgumentCompletionList commandList; 93 94 std::string groupLC = getLowercase(group); 95 96 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin(); 97 for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group) 98 if (getLowercase(it_group->first) == groupLC) 99 break; 100 101 if (it_group != _ConsoleCommand::getCommands().end()) 102 { 103 for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) 104 if (it_command->second->isActive() && it_command->second->hasAccess() && !it_command->second->isHidden()) 105 commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); 106 } 107 108 return commandList; 122 return detail::_subcommands(fragment, group, false); 123 } 124 125 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(hiddengroupsandcommands)() 126 { 127 return detail::_groupsandcommands(true); 128 } 129 130 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(hiddensubcommands)(const std::string& fragment, const std::string& group) 131 { 132 return detail::_subcommands(fragment, group, true); 133 } 134 135 ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI(command)(const std::string& fragment) 136 { 137 CommandEvaluation evaluation = CommandExecutor::evaluate(fragment); 138 const std::string& hint = evaluation.hint(); 139 140 if (evaluation.getPossibleArguments().size() > 0) 141 { 142 return evaluation.getPossibleArguments(); 143 } 144 else 145 { 146 ArgumentCompletionList list; 147 list.push_back(ArgumentCompletionListElement("", "", hint)); 148 return list; 149 } 109 150 } 110 151
Note: See TracChangeset
for help on using the changeset viewer.