[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[2710] | 29 | #include "ArgumentCompletionFunctions.h" |
---|
| 30 | |
---|
[1505] | 31 | #include <map> |
---|
[2728] | 32 | #include <boost/version.hpp> |
---|
[2087] | 33 | #include <boost/filesystem.hpp> |
---|
[1505] | 34 | |
---|
[3196] | 35 | #include "util/Convert.h" |
---|
[3280] | 36 | #include "util/StringUtils.h" |
---|
[7203] | 37 | #include "core/Identifier.h" |
---|
| 38 | #include "core/ConfigFileManager.h" |
---|
| 39 | #include "core/ConfigValueContainer.h" |
---|
[1505] | 40 | #include "TclThreadManager.h" |
---|
[7228] | 41 | #include "ConsoleCommand.h" |
---|
[1505] | 42 | |
---|
[2728] | 43 | // Boost 1.36 has some issues with deprecated functions that have been omitted |
---|
| 44 | #if (BOOST_VERSION == 103600) |
---|
| 45 | # define BOOST_LEAF_FUNCTION filename |
---|
| 46 | #else |
---|
| 47 | # define BOOST_LEAF_FUNCTION leaf |
---|
| 48 | #endif |
---|
| 49 | |
---|
[1505] | 50 | namespace orxonox |
---|
| 51 | { |
---|
| 52 | namespace autocompletion |
---|
| 53 | { |
---|
| 54 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() |
---|
| 55 | { |
---|
| 56 | return ArgumentCompletionList(); |
---|
| 57 | } |
---|
| 58 | |
---|
[7232] | 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; |
---|
| 66 | } |
---|
| 67 | |
---|
[7228] | 68 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)() |
---|
| 69 | { |
---|
| 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) |
---|
[7232] | 74 | if (groupIsVisible(it_group->second)) |
---|
| 75 | groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); |
---|
[7228] | 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) |
---|
[7232] | 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))); |
---|
[7228] | 85 | } |
---|
| 86 | |
---|
| 87 | return groupList; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group) |
---|
| 91 | { |
---|
| 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) |
---|
[7232] | 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))); |
---|
[7228] | 106 | } |
---|
| 107 | |
---|
| 108 | return commandList; |
---|
| 109 | } |
---|
| 110 | |
---|
[1505] | 111 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) |
---|
| 112 | { |
---|
| 113 | ArgumentCompletionList dirlist; |
---|
| 114 | ArgumentCompletionList filelist; |
---|
| 115 | |
---|
| 116 | try |
---|
| 117 | { |
---|
| 118 | boost::filesystem::path input(fragment); |
---|
| 119 | boost::filesystem::path startdirectory(input.branch_path()); |
---|
| 120 | |
---|
| 121 | if (!boost::filesystem::exists(startdirectory)) |
---|
| 122 | { |
---|
| 123 | startdirectory = "."; |
---|
| 124 | } |
---|
[2710] | 125 | #ifdef ORXONOX_PLATFORM_WINDOWS |
---|
[1505] | 126 | else |
---|
| 127 | { |
---|
[6417] | 128 | const std::string& dir = startdirectory.string(); |
---|
[1505] | 129 | if (dir.size() > 0 && dir[dir.size() - 1] == ':') |
---|
[2759] | 130 | startdirectory = dir + '/'; |
---|
[1505] | 131 | } |
---|
| 132 | #endif |
---|
| 133 | |
---|
| 134 | boost::filesystem::directory_iterator file(startdirectory); |
---|
| 135 | boost::filesystem::directory_iterator end; |
---|
| 136 | |
---|
| 137 | while (file != end) |
---|
| 138 | { |
---|
| 139 | if (boost::filesystem::is_directory(*file)) |
---|
[6417] | 140 | dirlist.push_back(ArgumentCompletionListElement(file->string() + '/', getLowercase(file->string()) + '/', file->BOOST_LEAF_FUNCTION() + '/')); |
---|
[1505] | 141 | else |
---|
[6417] | 142 | filelist.push_back(ArgumentCompletionListElement(file->string(), getLowercase(file->string()), file->BOOST_LEAF_FUNCTION())); |
---|
[1505] | 143 | ++file; |
---|
| 144 | } |
---|
| 145 | } |
---|
| 146 | catch (...) {} |
---|
| 147 | |
---|
| 148 | filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end()); |
---|
| 149 | return filelist; |
---|
| 150 | } |
---|
| 151 | |
---|
[6536] | 152 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)() |
---|
[1505] | 153 | { |
---|
[6536] | 154 | ArgumentCompletionList sectionList; |
---|
[1505] | 155 | |
---|
[6536] | 156 | const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames(); |
---|
| 157 | for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it) |
---|
| 158 | sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it))); |
---|
[1505] | 159 | |
---|
[6536] | 160 | return sectionList; |
---|
[1505] | 161 | } |
---|
| 162 | |
---|
[6536] | 163 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section) |
---|
[1505] | 164 | { |
---|
[6536] | 165 | ArgumentCompletionList entryList; |
---|
| 166 | SettingsConfigFile& settings = SettingsConfigFile::getInstance(); |
---|
| 167 | const std::string& sectionLC = getLowercase(section); |
---|
[1505] | 168 | |
---|
[6536] | 169 | SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); |
---|
| 170 | for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) |
---|
| 171 | entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first)); |
---|
[1505] | 172 | |
---|
[6536] | 173 | return entryList; |
---|
[1505] | 174 | } |
---|
| 175 | |
---|
[6536] | 176 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section) |
---|
[1505] | 177 | { |
---|
[6536] | 178 | ArgumentCompletionList oldValue; |
---|
| 179 | SettingsConfigFile& settings = SettingsConfigFile::getInstance(); |
---|
| 180 | const std::string& sectionLC = getLowercase(section); |
---|
| 181 | const std::string& entryLC = getLowercase(entry); |
---|
| 182 | |
---|
| 183 | SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); |
---|
| 184 | for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) |
---|
[1505] | 185 | { |
---|
[6536] | 186 | if (it->second.first == entryLC) |
---|
[1505] | 187 | { |
---|
[6536] | 188 | const std::string& valuestring = it->second.second->toString(); |
---|
| 189 | oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); |
---|
[1505] | 190 | } |
---|
| 191 | } |
---|
[6536] | 192 | |
---|
| 193 | return oldValue; |
---|
[1505] | 194 | } |
---|
| 195 | |
---|
| 196 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() |
---|
| 197 | { |
---|
| 198 | std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList(); |
---|
| 199 | ArgumentCompletionList threads; |
---|
| 200 | |
---|
| 201 | for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it) |
---|
[3280] | 202 | threads.push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it))); |
---|
[1505] | 203 | |
---|
| 204 | return threads; |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | } |
---|