[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 | |
---|
[7228] | 59 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)() |
---|
| 60 | { |
---|
| 61 | ArgumentCompletionList groupList; |
---|
| 62 | |
---|
| 63 | const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands(); |
---|
| 64 | for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group) |
---|
| 65 | // todo: check if active / not hidden / not denied |
---|
| 66 | groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first))); |
---|
| 67 | |
---|
| 68 | std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find(""); |
---|
| 69 | if (it_group != commands.end()) |
---|
| 70 | { |
---|
| 71 | groupList.push_back(ArgumentCompletionListElement("\n")); |
---|
| 72 | |
---|
| 73 | for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) |
---|
| 74 | // todo: check if active / not hidden / not denied |
---|
| 75 | groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | return groupList; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group) |
---|
| 82 | { |
---|
| 83 | ArgumentCompletionList commandList; |
---|
| 84 | |
---|
| 85 | std::string groupLC = getLowercase(group); |
---|
| 86 | |
---|
| 87 | std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = _ConsoleCommand::getCommands().begin(); |
---|
| 88 | for ( ; it_group != _ConsoleCommand::getCommands().end(); ++it_group) |
---|
| 89 | if (getLowercase(it_group->first) == groupLC) |
---|
| 90 | break; |
---|
| 91 | |
---|
| 92 | if (it_group != _ConsoleCommand::getCommands().end()) |
---|
| 93 | { |
---|
| 94 | for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command) |
---|
| 95 | // todo: check if active / not hidden / not denied |
---|
| 96 | commandList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first))); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | return commandList; |
---|
| 100 | } |
---|
| 101 | |
---|
[1505] | 102 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) |
---|
| 103 | { |
---|
| 104 | ArgumentCompletionList dirlist; |
---|
| 105 | ArgumentCompletionList filelist; |
---|
| 106 | |
---|
| 107 | try |
---|
| 108 | { |
---|
| 109 | boost::filesystem::path input(fragment); |
---|
| 110 | boost::filesystem::path startdirectory(input.branch_path()); |
---|
| 111 | |
---|
| 112 | if (!boost::filesystem::exists(startdirectory)) |
---|
| 113 | { |
---|
| 114 | startdirectory = "."; |
---|
| 115 | } |
---|
[2710] | 116 | #ifdef ORXONOX_PLATFORM_WINDOWS |
---|
[1505] | 117 | else |
---|
| 118 | { |
---|
[6417] | 119 | const std::string& dir = startdirectory.string(); |
---|
[1505] | 120 | if (dir.size() > 0 && dir[dir.size() - 1] == ':') |
---|
[2759] | 121 | startdirectory = dir + '/'; |
---|
[1505] | 122 | } |
---|
| 123 | #endif |
---|
| 124 | |
---|
| 125 | boost::filesystem::directory_iterator file(startdirectory); |
---|
| 126 | boost::filesystem::directory_iterator end; |
---|
| 127 | |
---|
| 128 | while (file != end) |
---|
| 129 | { |
---|
| 130 | if (boost::filesystem::is_directory(*file)) |
---|
[6417] | 131 | dirlist.push_back(ArgumentCompletionListElement(file->string() + '/', getLowercase(file->string()) + '/', file->BOOST_LEAF_FUNCTION() + '/')); |
---|
[1505] | 132 | else |
---|
[6417] | 133 | filelist.push_back(ArgumentCompletionListElement(file->string(), getLowercase(file->string()), file->BOOST_LEAF_FUNCTION())); |
---|
[1505] | 134 | ++file; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | catch (...) {} |
---|
| 138 | |
---|
| 139 | filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end()); |
---|
| 140 | return filelist; |
---|
| 141 | } |
---|
| 142 | |
---|
[6536] | 143 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)() |
---|
[1505] | 144 | { |
---|
[6536] | 145 | ArgumentCompletionList sectionList; |
---|
[1505] | 146 | |
---|
[6536] | 147 | const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames(); |
---|
| 148 | for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it) |
---|
| 149 | sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it))); |
---|
[1505] | 150 | |
---|
[6536] | 151 | return sectionList; |
---|
[1505] | 152 | } |
---|
| 153 | |
---|
[6536] | 154 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section) |
---|
[1505] | 155 | { |
---|
[6536] | 156 | ArgumentCompletionList entryList; |
---|
| 157 | SettingsConfigFile& settings = SettingsConfigFile::getInstance(); |
---|
| 158 | const std::string& sectionLC = getLowercase(section); |
---|
[1505] | 159 | |
---|
[6536] | 160 | SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); |
---|
| 161 | for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) |
---|
| 162 | entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first)); |
---|
[1505] | 163 | |
---|
[6536] | 164 | return entryList; |
---|
[1505] | 165 | } |
---|
| 166 | |
---|
[6536] | 167 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section) |
---|
[1505] | 168 | { |
---|
[6536] | 169 | ArgumentCompletionList oldValue; |
---|
| 170 | SettingsConfigFile& settings = SettingsConfigFile::getInstance(); |
---|
| 171 | const std::string& sectionLC = getLowercase(section); |
---|
| 172 | const std::string& entryLC = getLowercase(entry); |
---|
| 173 | |
---|
| 174 | SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC); |
---|
| 175 | for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it) |
---|
[1505] | 176 | { |
---|
[6536] | 177 | if (it->second.first == entryLC) |
---|
[1505] | 178 | { |
---|
[6536] | 179 | const std::string& valuestring = it->second.second->toString(); |
---|
| 180 | oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); |
---|
[1505] | 181 | } |
---|
| 182 | } |
---|
[6536] | 183 | |
---|
| 184 | return oldValue; |
---|
[1505] | 185 | } |
---|
| 186 | |
---|
| 187 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() |
---|
| 188 | { |
---|
| 189 | std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList(); |
---|
| 190 | ArgumentCompletionList threads; |
---|
| 191 | |
---|
| 192 | for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it) |
---|
[3280] | 193 | threads.push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it))); |
---|
[1505] | 194 | |
---|
| 195 | return threads; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | } |
---|