[1390] | 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 | |
---|
[1402] | 29 | #include <iostream> |
---|
[1434] | 30 | #include <map> |
---|
[1402] | 31 | |
---|
[1442] | 32 | #include "boost/filesystem.hpp" |
---|
[1436] | 33 | |
---|
[1390] | 34 | #include "ArgumentCompletionFunctions.h" |
---|
[1434] | 35 | #include "CoreIncludes.h" |
---|
| 36 | #include "Identifier.h" |
---|
| 37 | #include "ConfigValueContainer.h" |
---|
| 38 | #include "TclThreadManager.h" |
---|
[1441] | 39 | #include "util/Convert.h" |
---|
[1434] | 40 | #include "util/String.h" |
---|
[1390] | 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | namespace autocompletion |
---|
| 45 | { |
---|
[1430] | 46 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() |
---|
[1390] | 47 | { |
---|
[1441] | 48 | return ArgumentCompletionList(); |
---|
[1390] | 49 | } |
---|
[1434] | 50 | |
---|
[1436] | 51 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) |
---|
| 52 | { |
---|
[1441] | 53 | ArgumentCompletionList dirlist; |
---|
| 54 | ArgumentCompletionList filelist; |
---|
[1436] | 55 | |
---|
[1442] | 56 | try |
---|
| 57 | { |
---|
| 58 | boost::filesystem::path input(fragment); |
---|
| 59 | boost::filesystem::path startdirectory(input.branch_path()); |
---|
[1436] | 60 | |
---|
[1442] | 61 | if (!boost::filesystem::exists(startdirectory)) |
---|
| 62 | { |
---|
| 63 | startdirectory = "."; |
---|
| 64 | } |
---|
| 65 | #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 |
---|
| 66 | else |
---|
| 67 | { |
---|
| 68 | std::string dir = startdirectory.string(); |
---|
| 69 | if (dir.size() > 0 && dir[dir.size() - 1] == ':') |
---|
| 70 | startdirectory = dir + "/"; |
---|
| 71 | } |
---|
| 72 | #endif |
---|
[1436] | 73 | |
---|
[1442] | 74 | boost::filesystem::directory_iterator file(startdirectory); |
---|
| 75 | boost::filesystem::directory_iterator end; |
---|
[1436] | 76 | |
---|
[1442] | 77 | while (file != end) |
---|
[1436] | 78 | { |
---|
[1442] | 79 | if (boost::filesystem::is_directory(*file)) |
---|
| 80 | dirlist.push_back(ArgumentCompletionListElement((*file).string() + "/", getLowercase((*file).string()) + "/", (*file).leaf() + "/")); |
---|
| 81 | else |
---|
| 82 | filelist.push_back(ArgumentCompletionListElement((*file).string(), getLowercase((*file).string()), (*file).leaf())); |
---|
| 83 | ++file; |
---|
[1436] | 84 | } |
---|
| 85 | } |
---|
[1442] | 86 | catch (...) {} |
---|
[1436] | 87 | |
---|
| 88 | filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end()); |
---|
| 89 | return filelist; |
---|
| 90 | } |
---|
| 91 | |
---|
[1434] | 92 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)() |
---|
| 93 | { |
---|
[1441] | 94 | ArgumentCompletionList classlist; |
---|
[1434] | 95 | |
---|
| 96 | for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it) |
---|
| 97 | if ((*it).second->hasConfigValues()) |
---|
[1441] | 98 | classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); |
---|
[1434] | 99 | |
---|
| 100 | return classlist; |
---|
| 101 | } |
---|
| 102 | |
---|
[1436] | 103 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname) |
---|
[1434] | 104 | { |
---|
[1441] | 105 | ArgumentCompletionList configvalues; |
---|
[1434] | 106 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname); |
---|
| 107 | |
---|
| 108 | if (identifier != Identifier::getIdentifierMapEnd() && (*identifier).second->hasConfigValues()) |
---|
| 109 | { |
---|
| 110 | for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it) |
---|
[1441] | 111 | configvalues.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); |
---|
[1434] | 112 | } |
---|
| 113 | |
---|
| 114 | return configvalues; |
---|
| 115 | } |
---|
| 116 | |
---|
[1436] | 117 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname) |
---|
[1434] | 118 | { |
---|
[1441] | 119 | ArgumentCompletionList oldvalue; |
---|
[1434] | 120 | std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname)); |
---|
| 121 | if (identifier != Identifier::getLowercaseIdentifierMapEnd()) |
---|
| 122 | { |
---|
| 123 | std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); |
---|
| 124 | if (variable != (*identifier).second->getLowercaseConfigValueMapEnd()) |
---|
| 125 | { |
---|
| 126 | std::string valuestring = (*variable).second->toString(); |
---|
[1441] | 127 | oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); |
---|
[1434] | 128 | } |
---|
| 129 | } |
---|
| 130 | return oldvalue; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() |
---|
| 134 | { |
---|
[1441] | 135 | std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList(); |
---|
| 136 | ArgumentCompletionList threads; |
---|
| 137 | |
---|
| 138 | for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it) |
---|
| 139 | threads.push_back(ArgumentCompletionListElement(getConvertedValue<unsigned int, std::string>(*it))); |
---|
| 140 | |
---|
| 141 | return threads; |
---|
[1434] | 142 | } |
---|
[1390] | 143 | } |
---|
| 144 | } |
---|