| 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 | |
|---|
| 29 | #include <iostream> |
|---|
| 30 | #include <map> |
|---|
| 31 | |
|---|
| 32 | #include <boost/filesystem.hpp> |
|---|
| 33 | |
|---|
| 34 | #include "ArgumentCompletionFunctions.h" |
|---|
| 35 | #include "CoreIncludes.h" |
|---|
| 36 | #include "Identifier.h" |
|---|
| 37 | #include "ConfigValueContainer.h" |
|---|
| 38 | #include "TclThreadManager.h" |
|---|
| 39 | #include "util/Convert.h" |
|---|
| 40 | #include "util/String.h" |
|---|
| 41 | |
|---|
| 42 | namespace orxonox |
|---|
| 43 | { |
|---|
| 44 | namespace autocompletion |
|---|
| 45 | { |
|---|
| 46 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)() |
|---|
| 47 | { |
|---|
| 48 | return ArgumentCompletionList(); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment) |
|---|
| 52 | { |
|---|
| 53 | ArgumentCompletionList dirlist; |
|---|
| 54 | ArgumentCompletionList filelist; |
|---|
| 55 | |
|---|
| 56 | try |
|---|
| 57 | { |
|---|
| 58 | boost::filesystem::path input(fragment); |
|---|
| 59 | boost::filesystem::path startdirectory(input.branch_path()); |
|---|
| 60 | |
|---|
| 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 |
|---|
| 73 | |
|---|
| 74 | boost::filesystem::directory_iterator file(startdirectory); |
|---|
| 75 | boost::filesystem::directory_iterator end; |
|---|
| 76 | |
|---|
| 77 | while (file != end) |
|---|
| 78 | { |
|---|
| 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; |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | catch (...) {} |
|---|
| 87 | |
|---|
| 88 | filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end()); |
|---|
| 89 | return filelist; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)() |
|---|
| 93 | { |
|---|
| 94 | ArgumentCompletionList classlist; |
|---|
| 95 | |
|---|
| 96 | for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it) |
|---|
| 97 | if ((*it).second->hasConfigValues()) |
|---|
| 98 | classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); |
|---|
| 99 | |
|---|
| 100 | return classlist; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname) |
|---|
| 104 | { |
|---|
| 105 | ArgumentCompletionList configvalues; |
|---|
| 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) |
|---|
| 111 | configvalues.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | return configvalues; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname) |
|---|
| 118 | { |
|---|
| 119 | ArgumentCompletionList oldvalue; |
|---|
| 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(); |
|---|
| 127 | oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring)); |
|---|
| 128 | } |
|---|
| 129 | } |
|---|
| 130 | return oldvalue; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)() |
|---|
| 134 | { |
|---|
| 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; |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | } |
|---|