Changeset 9869 in orxonox.OLD for trunk/src/lib/shell
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 2 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/Makefile.am
r7428 r9869 6 6 libORXshell_a_SOURCES = \ 7 7 shell.cc \ 8 shell_buffer.cc \9 8 shell_input.cc \ 10 9 shell_command.cc \ … … 16 15 noinst_HEADERS= \ 17 16 shell.h \ 18 shell_buffer.h \19 17 shell_input.h \ 18 shell_command_class.h \ 20 19 shell_command.h \ 21 shell_command_class.h \22 20 shell_completion.h \ 23 21 shell_completion_plugin.h -
trunk/src/lib/shell/shell.cc
r8362 r9869 18 18 #include "shell.h" 19 19 #include "shell_command.h" 20 #include " shell_buffer.h"20 #include "debug_buffer.h" 21 21 #include "shell_input.h" 22 22 … … 54 54 ->completionPlugin(0, OrxShell::CompletorFileSystem(".ttf", "fonts/")); 55 55 56 ObjectListDefinition(Shell); 56 57 57 58 /** … … 60 61 Shell::Shell () 61 62 { 62 this->setClassID(CL_SHELL, "Shell"); 63 this->registerObject(this, Shell::_objectList); 64 63 65 this->setName("Shell"); 64 66 65 this->shellBuffer = ShellBuffer::getInstance();67 this->shellBuffer = DebugBuffer::getInstance(); 66 68 67 69 // EVENT-Handler subscription of '`' to all States. … … 246 248 this->setSizeX2D(width); 247 249 for (std::list<MultiLineText*>::iterator textIt = this->bufferText.begin(); textIt != this->bufferText.end(); ++textIt) 248 {249 250 (*textIt)->setLineWidth(width); 250 }251 251 } 252 252 … … 444 444 { 445 445 this->flush(); 446 ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);446 DebugBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL); 447 447 } 448 448 … … 470 470 this->moveDisplayBuffer(-this->bufferDisplaySize+1); 471 471 } 472 else if (event.type == EV_VIDEO_RESIZE)473 {474 this->updateResolution(event.resize.w);475 this->repositionText();476 }472 } 473 else if (event.type == EV_VIDEO_RESIZE) 474 { 475 this->updateResolution(event.resize.w); 476 this->repositionText(); 477 477 } 478 478 } -
trunk/src/lib/shell/shell.h
r7762 r9869 14 14 15 15 #include "shell_input.h" 16 #include " shell_buffer.h"16 #include "debug_buffer.h" 17 17 #include "material.h" 18 18 … … 48 48 class Shell : public Element2D, public EventListener 49 49 { 50 50 ObjectListDeclaration(Shell); 51 51 public: 52 52 Shell(); … … 93 93 private: 94 94 // GENERAL 95 ShellBuffer* shellBuffer; //!< The local ShellBuffer.95 DebugBuffer* shellBuffer; //!< The local ShellBuffer. 96 96 97 97 bool bActive; //!< If the shell is active. -
trunk/src/lib/shell/shell_command.cc
r9406 r9869 20 20 21 21 #include "compiler.h" 22 #include "helper_functions.h" 22 23 #include "debug.h" 23 #include "class_list.h"24 24 25 25 #include "key_names.h" … … 27 27 namespace OrxShell 28 28 { 29 ObjectListDefinition(ShellCommand); 29 30 SHELL_COMMAND(debug, ShellCommandClass, help); 30 31 … … 36 37 * @param paramCount the count of parameters this command takes 37 38 */ 38 ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor * executor)39 { 40 this-> setClassID(CL_SHELL_COMMAND, "ShellCommand");39 ShellCommand::ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor) 40 { 41 this->registerObject(this, ShellCommand::_objectList); 41 42 PRINTF(4)("create shellcommand '%s' for class '%s'\n", commandName.c_str(), className.c_str()); 42 43 this->setName(commandName); … … 44 45 // copy the executor: 45 46 this->executor = executor; 46 this->executor->setName(commandName);47 47 48 48 for (unsigned int i = 0; i < this->executor->getParamCount(); i++) … … 75 75 * @brief registers a new ShellCommand 76 76 */ 77 ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor * executor)77 ShellCommand* ShellCommand::registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor) 78 78 { 79 79 if (ShellCommand::exists(commandName, className)) … … 94 94 void ShellCommand::unregisterCommand(const std::string& commandName, const std::string& className) 95 95 { 96 97 96 ShellCommandClass* cmdClass = ShellCommandClass::acquireCommandClass(className); 98 97 if (cmdClass != NULL) 99 98 { 100 99 CmdList::iterator cmd; 101 for (cmd = cmdClass-> commandList.begin(); cmd != cmdClass->commandList.end(); cmd++)100 for (cmd = cmdClass->_commandList.begin(); cmd != cmdClass->_commandList.end(); cmd++) 102 101 if (commandName == (*cmd)->getName()) 103 102 { … … 119 118 120 119 CmdList::const_iterator elem; 121 for (unsigned int i = 0; i < cmdClass-> commandList.size(); i++)122 { 123 if (commandName == cmdClass-> commandList[i]->getName())124 return (cmdClass-> commandList[i]);120 for (unsigned int i = 0; i < cmdClass->_commandList.size(); i++) 121 { 122 if (commandName == cmdClass->_commandList[i]->getName()) 123 return (cmdClass->_commandList[i]); 125 124 } 126 125 return NULL; … … 242 241 return false; 243 242 244 const std::list<BaseObject*>* objectList = ClassList::getList(cmd->shellClass->getName());243 const ObjectListBase* const objectList = ObjectListBase::getObjectList(cmd->shellClass->getName()); 245 244 if (objectList != NULL) 246 245 { 247 std::list<BaseObject*>::const_iterator bo; 246 ObjectListBase::base_list list; 247 objectList->getBaseObjectList(&list); 248 ObjectListBase::base_iterator it; 248 249 249 250 // No Description given (only for speedup) 250 251 if (objectDescriptor.empty()) 251 252 { 252 for ( bo = objectList->begin(); bo != objectList->end(); bo++)253 boList->push_back(* bo);253 for (it = list.begin(); it != list.end(); it++) 254 boList->push_back(*it); 254 255 } 255 256 // some description 256 257 else 257 258 { 258 for ( bo = objectList->begin(); bo != objectList->end(); bo++)259 if (!nocaseCmp(objectDescriptor, (* bo)->getName(), objectDescriptor.size()))260 boList->push_back(* bo);259 for (it = list.begin(); it != list.end(); it++) 260 if (!nocaseCmp(objectDescriptor, (*it)->getName(), objectDescriptor.size())) 261 boList->push_back(*it); 261 262 } 262 263 } … … 299 300 if (sc != NULL) 300 301 { 301 for(std::vector<BaseObject*>::const_iterator bo = boList.begin(); bo != boList.end(); ++bo) 302 { 303 PRINT(0)("Command '%s' on '%s::%s'\n", sc->getCName(), (*bo)->getClassCName(), (*bo)->getCName()); 304 (*sc->executor)((*bo), inputSplits.subSet(paramBegin)); 305 } 302 303 if(sc->executor->getType() == Executor<const SubString>::FunctionStatic ) 304 { 305 PRINT(0)("Static Command '%s' of Class '%s' with parameters\n", sc->getCName(), sc->shellClass->getCName()); 306 (*sc->executor)(NULL, inputSplits.subSet(paramBegin)); 307 } 308 else 309 for(std::vector<BaseObject*>::const_iterator bo = boList.begin(); bo != boList.end(); ++bo) 310 { 311 PRINT(0)("Command '%s' on '%s::%s'\n", sc->getCName(), (*bo)->getClassCName(), (*bo)->getCName()); 312 (*sc->executor)((*bo), inputSplits.subSet(paramBegin)); 313 } 306 314 return true; 307 315 } … … 376 384 else 377 385 { 378 // if(this->completors[parameter] == NULL)379 // delete this->completors[parameter];380 // this->completors[parameter] = completorPlugin.clone();386 // if(this->completors[parameter] == NULL) 387 // delete this->completors[parameter]; 388 // this->completors[parameter] = completorPlugin.clone(); 381 389 } 382 390 return this; -
trunk/src/lib/shell/shell_command.h
r8145 r9869 9 9 #include "base_object.h" 10 10 11 #include "executor/executor.h" 11 /// THIS IS USED TO LOAD CONSTANT AND STATIC FUNCTIONS EASILY. 12 #include "executor/executor_substring.h" 13 #include "executor/functor_member.h" 14 #include "executor/functor_const_member.h" 15 #include "executor/functor_static.h" 16 12 17 #include "shell_completion_plugin.h" 13 18 … … 35 40 */ 36 41 #define SHELL_COMMAND(command, class, function) \ 37 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class >(&class::function))42 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(&class::function)) 38 43 39 44 /** … … 51 56 */ 52 57 #define SHELL_COMMAND_STATIC(command, class, function) \ 53 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class >(function))58 OrxShell::ShellCommand* shell_command_##class##_##command = OrxShell::ShellCommand::registerCommand(#command, #class, createExecutor<class, BaseObject>(function)) 54 59 55 60 … … 58 63 class ShellCommand : public BaseObject 59 64 { 65 ObjectListDeclaration(ShellCommand); 66 60 67 friend class ShellCommandClass; 61 68 public: … … 69 76 ShellCommand* completionPlugin(unsigned int parameter, const CompletorPlugin& completorPlugin); 70 77 71 static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor * executor);78 static ShellCommand* registerCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor); 72 79 static void unregisterCommand(const std::string& commandName, const std::string& className); 73 80 static const ShellCommand* const getCommand(const std::string& commandName, const std::string& className); … … 85 92 86 93 protected: 87 ShellCommand(const std::string& commandName, const std::string& className, Executor * executor);94 ShellCommand(const std::string& commandName, const std::string& className, Executor<const SubString>* executor); 88 95 virtual ~ShellCommand(); 89 96 … … 97 104 std::string description; //!< A description for this commnand. (initially ""). Assigned with (create)->describe("blablabla"); 98 105 std::vector<CompletorPlugin*> completors; //!< Completors for the Parameters 99 Executor *executor; //!< The Executor, that really executes the Function.106 Executor<const SubString>* executor; //!< The Executor, that really executes the Function. 100 107 }; 101 108 -
trunk/src/lib/shell/shell_command_class.cc
r9406 r9869 21 21 22 22 #include "debug.h" 23 #include "class_list.h"24 23 #include "compiler.h" 25 24 … … 28 27 namespace OrxShell 29 28 { 30 CmdClassList* ShellCommandClass::commandClassList = NULL; 29 ObjectListDefinition(ShellCommandClass); 30 31 CmdClassList* ShellCommandClass::_commandClassList = NULL; 31 32 32 33 /** … … 35 36 */ 36 37 ShellCommandClass::ShellCommandClass(const std::string& className) 37 : className(className)38 { 39 this-> setClassID(CL_SHELL_COMMAND_CLASS, "ShellCommandClass");38 : _className(className) 39 { 40 this->registerObject(this, ShellCommandClass::_objectList); 40 41 this->setName(className); 41 42 42 this->classID = CL_NULL; 43 44 if (ShellCommandClass::commandClassList == NULL) 45 ShellCommandClass::commandClassList = new CmdClassList; 46 ShellCommandClass::commandClassList->push_back(this); 43 if (ShellCommandClass::_commandClassList == NULL) 44 ShellCommandClass::_commandClassList = new CmdClassList; 45 ShellCommandClass::_commandClassList->push_back(this); 47 46 } 48 47 … … 52 51 ShellCommandClass::~ShellCommandClass() 53 52 { 54 while(!this-> commandList.empty())55 delete this-> commandList.back();56 57 if (ShellCommandClass:: commandClassList != NULL)58 { 59 CmdClassList::iterator delClass = std::find(ShellCommandClass:: commandClassList->begin(), ShellCommandClass::commandClassList->end(), this);60 if (delClass != ShellCommandClass:: commandClassList->end())61 ShellCommandClass:: commandClassList->erase(delClass);53 while(!this->_commandList.empty()) 54 delete this->_commandList.back(); 55 56 if (ShellCommandClass::_commandClassList != NULL) 57 { 58 CmdClassList::iterator delClass = std::find(ShellCommandClass::_commandClassList->begin(), ShellCommandClass::_commandClassList->end(), this); 59 if (delClass != ShellCommandClass::_commandClassList->end()) 60 ShellCommandClass::_commandClassList->erase(delClass); 62 61 } 63 62 } … … 68 67 void ShellCommandClass::registerCommand(ShellCommand* command) 69 68 { 70 this-> commandList.push_back(command);69 this->_commandList.push_back(command); 71 70 } 72 71 … … 77 76 void ShellCommandClass::unregisterCommand(ShellCommand* command) 78 77 { 79 CmdList::iterator delC = std::find(this-> commandList.begin(), this->commandList.end(), command);80 if (delC != this-> commandList.end())81 this-> commandList.erase(delC);78 CmdList::iterator delC = std::find(this->_commandList.begin(), this->_commandList.end(), command); 79 if (delC != this->_commandList.end()) 80 this->_commandList.erase(delC); 82 81 } 83 82 … … 89 88 // unregister all commands and Classes 90 89 CmdClassList::iterator classIT; 91 if (ShellCommandClass:: commandClassList == NULL)90 if (ShellCommandClass::_commandClassList == NULL) 92 91 return; 93 92 94 while (!ShellCommandClass:: commandClassList->empty())95 delete ShellCommandClass:: commandClassList->back();96 delete ShellCommandClass:: commandClassList;97 ShellCommandClass:: commandClassList = NULL;93 while (!ShellCommandClass::_commandClassList->empty()) 94 delete ShellCommandClass::_commandClassList->back(); 95 delete ShellCommandClass::_commandClassList; 96 ShellCommandClass::_commandClassList = NULL; 98 97 } 99 98 … … 107 106 bool ShellCommandClass::getCommandListOfClass(const std::string& className, std::list<std::string>& stringList) 108 107 { 109 if (ShellCommandClass:: commandClassList == NULL)108 if (ShellCommandClass::_commandClassList == NULL) 110 109 return false; 111 110 112 111 113 112 CmdClassList::const_iterator elem; 114 for(elem = ShellCommandClass:: commandClassList->begin(); elem != ShellCommandClass::commandClassList->end(); elem++)113 for(elem = ShellCommandClass::_commandClassList->begin(); elem != ShellCommandClass::_commandClassList->end(); elem++) 115 114 { 116 115 if (className == (*elem)->getName()) 117 116 { 118 117 CmdList::iterator command; 119 for(command = (*elem)-> commandList.begin(); command != (*elem)->commandList.end(); command++)118 for(command = (*elem)->_commandList.begin(); command != (*elem)->_commandList.end(); command++) 120 119 stringList.push_back((*command)->getName()); 121 120 return true; … … 133 132 ShellCommandClass* ShellCommandClass::getCommandClass(const std::string& className) 134 133 { 135 if (ShellCommandClass:: commandClassList == NULL)134 if (ShellCommandClass::_commandClassList == NULL) 136 135 return false; 137 136 138 137 139 138 CmdClassList::const_iterator classIT; 140 for (classIT = ShellCommandClass:: commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)141 if (className == (*classIT)-> className)139 for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++) 140 if (className == (*classIT)->_className) 142 141 return (*classIT); 143 142 return NULL; … … 152 151 { 153 152 return (ShellCommandClass::getCommandClass(className) != NULL); 154 }155 156 ClassID ShellCommandClass::getClassID()157 {158 if (this->classID == CL_NULL)159 this->classID = ClassList::StringToID(this->className);160 return this->classID;161 153 } 162 154 … … 181 173 void ShellCommandClass::help(const std::string& className) 182 174 { 183 if (ShellCommandClass:: commandClassList == NULL)175 if (ShellCommandClass::_commandClassList == NULL) 184 176 { 185 177 PRINT(0)("No Commands Registered\n"); … … 187 179 } 188 180 if (className.empty()) 189 PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass:: commandClassList->size());181 PRINT(0)("===== Displaying %d registered Classes:\n", ShellCommandClass::_commandClassList->size()); 190 182 191 183 192 184 CmdClassList::iterator classIT; 193 for (classIT = ShellCommandClass:: commandClassList->begin(); classIT != ShellCommandClass::commandClassList->end(); classIT++)194 { 195 if (className.empty() || className == (*classIT)-> className)185 for (classIT = ShellCommandClass::_commandClassList->begin(); classIT != ShellCommandClass::_commandClassList->end(); classIT++) 186 { 187 if (className.empty() || className == (*classIT)->_className) 196 188 { 197 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)-> className.c_str(), (*classIT)->commandList.size());189 PRINT(0)("Class:'%s' registered %d commands: \n", (*classIT)->_className.c_str(), (*classIT)->_commandList.size()); 198 190 CmdList::const_iterator cmdIT; 199 for (cmdIT = (*classIT)-> commandList.begin(); cmdIT != (*classIT)->commandList.end(); cmdIT++)191 for (cmdIT = (*classIT)->_commandList.begin(); cmdIT != (*classIT)->_commandList.end(); cmdIT++) 200 192 { 201 193 PRINT(0)(" command:'%s' : params:%d: ", (*cmdIT)->getCName(), (*cmdIT)->executor->getParamCount()); -
trunk/src/lib/shell/shell_command_class.h
r8362 r9869 25 25 class ShellCommandClass : public BaseObject 26 26 { 27 ObjectListDeclaration(ShellCommandClass); 28 27 29 friend class ShellCommand; 28 30 public: 29 31 /** @returns the CommandClassList */ 30 static const CmdClassList& getCommandClassList() { return *ShellCommandClass:: commandClassList; };32 static const CmdClassList& getCommandClassList() { return *ShellCommandClass::_commandClassList; }; 31 33 32 34 static bool getCommandListOfClass(const std::string& className, std::list<std::string>& stringList); … … 51 53 52 54 private: 53 const std::string className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 54 ClassID classID; //!< The classID of this Class 55 CmdList commandList; //!< A list of Commands from this Class 55 const std::string _className; //!< The Name of the Class. This should match the ClassName of the Commands Class. 56 CmdList _commandList; //!< A list of Commands from this Class 56 57 57 static CmdClassList* commandClassList; //!< A list of Classes58 static CmdClassList* _commandClassList; //!< A list of Classes 58 59 }; 59 60 } -
trunk/src/lib/shell/shell_completion.cc
r9406 r9869 22 22 #include "shell_command.h" 23 23 24 #include "substring.h" 25 #include "class_list.h" 24 #include "helper_functions.h" 26 25 #include "debug.h" 27 26 … … 51 50 bool ShellCompletion::autoComplete(std::string& input) 52 51 { 53 long classID = CL_NULL; //< the classID retrieved from the Class.54 const std::list<BaseObject*>* objectList = NULL;//< the list of Objects stored in classID's ClassList52 ClassID classID; 53 const ObjectListBase* objectList = NULL; //< the list of Objects stored in classID's ClassList 55 54 bool emptyComplete = false; //< if the completion input is empty string. e.g "" 56 55 long completeType = NullCompletion; //< the Type we'd like to complete. … … 85 84 (!emptyComplete && inputSplits.size() == 2)) 86 85 { 87 classID = ClassList::StringToID(inputSplits.getString(0)); 88 objectList = ClassList::getList((ClassID)classID); 89 if (classID != CL_NULL) 86 objectList = ObjectListBase::getObjectList(inputSplits[0]); 87 if (objectList != NULL) 88 classID = objectList->identity(); 89 if (classID != NullClass::staticClassID()) 90 90 completeType |= ObjectCompletion; 91 91 completeType |= FunctionCompletion; … … 95 95 (!emptyComplete && inputSplits.size() == 3)) 96 96 { 97 if ( ClassList::exists(inputSplits[0], inputSplits[1]))97 if (ObjectListBase::getBaseObject(inputSplits[0], inputSplits[1])) 98 98 completeType |= FunctionCompletion; 99 99 } … … 113 113 114 114 if (completeType & ClassCompletion) 115 this->objectComplete(completeString, CL_SHELL_COMMAND_CLASS);115 this->objectComplete(completeString, &ShellCommandClass::objectList()); 116 116 if (completeType & ObjectCompletion) 117 this->objectComplete(completeString, classID);117 this->objectComplete(completeString, objectList); 118 118 if (completeType & FunctionCompletion) 119 119 this->commandComplete(completeString, inputSplits[0]); … … 133 133 * @return true on success, false otherwise 134 134 */ 135 bool ShellCompletion::objectComplete(const std::string& objectBegin, long classID) 136 { 137 const std::list<BaseObject*>* boList = ClassList::getList((ClassID)classID); 138 if (boList != NULL) 139 { 140 CompletionType type = ObjectCompletion; 141 if (classID == CL_SHELL_COMMAND_CLASS) 142 type = ClassCompletion; 143 if (!this->addToCompleteList(*boList, objectBegin, type)) 144 return false; 145 } 146 else 147 return false; 135 bool ShellCompletion::objectComplete(const std::string& objectBegin, const ObjectListBase* objectList) 136 { 137 assert (objectList != NULL); 138 139 CompletionType type = ObjectCompletion; 140 if (objectList == &ShellCommandClass::objectList()) 141 type = ClassCompletion; 142 143 ObjectListBase::base_list list; 144 objectList->getBaseObjectList(&list); 145 146 if (!this->addToCompleteList(list, objectBegin, type)) 147 return false; 148 148 149 return true; 149 150 } … … 321 322 switch (type) 322 323 { 323 324 325 326 327 328 329 330 331 332 333 334 324 default:// SHELLC_NONE 325 return typeNames[0]; 326 case ClassCompletion: 327 return typeNames[1]; 328 case ObjectCompletion: 329 return typeNames[2]; 330 case FunctionCompletion: 331 return typeNames[3]; 332 case AliasCompletion: 333 return typeNames[4]; 334 case ParamCompletion: 335 return typeNames[5]; 335 336 } 336 337 } -
trunk/src/lib/shell/shell_completion.h
r7415 r9869 16 16 // FORWARD DECLARATION 17 17 class BaseObject; 18 class ObjectListBase; 18 19 19 20 namespace OrxShell … … 50 51 bool autoComplete(std::string& input); 51 52 52 static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type);53 static const std::string& typeToString(ShellCompletion::CompletionType type); 53 54 54 55 private: 55 bool objectComplete(const std::string& objectBegin, long classID);56 bool objectComplete(const std::string& objectBegin, const ObjectListBase* const objectList); 56 57 bool commandComplete(const std::string& commandBegin, const std::string& className); 57 58 bool aliasComplete(const std::string& aliasBegin); -
trunk/src/lib/shell/shell_completion_plugin.cc
r8330 r9869 21 21 #include "shell_command.h" 22 22 23 #include "substring.h" 24 #include "class_list.h" 23 #include "helper_functions.h" 25 24 #include "loading/resource_manager.h" 26 25 … … 98 97 if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir. 99 98 { 100 dir.setFileName(Resource Manager::getInstance()->getDataDir() + this->_subDir);99 dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + this->_subDir); 101 100 dir.open(); 102 101 for(unsigned int i = 0; i < dir.fileCount(); i++ ) … … 113 112 directoryName = completionBegin.substr(0, pos); 114 113 115 dir.setFileName(Resource Manager::getInstance()->getDataDir() + directoryName);114 dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + directoryName); 116 115 dir.open(); 117 116 … … 136 135 continue; 137 136 } 138 printf("%s\n", (ResourceManager::getInstance()->getDataDir() + fileName).c_str());137 printf("%s\n", (Resources::ResourceManager::getInstance()->mainGlobalPath().name() + fileName).c_str()); 139 138 if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) && 140 ResourceManager::isInDataDir(fileName))139 Resources::ResourceManager::getInstance()->checkFileInMainPath(fileName)) 141 140 { 142 141 printf("Dir %s\n", fileName.c_str()); -
trunk/src/lib/shell/shell_input.cc
r8339 r9869 24 24 #include "compiler.h" 25 25 #include "key_names.h" 26 26 27 27 28 namespace OrxShell … … 31 32 ->setAlias("help"); 32 33 34 ObjectListDefinition(ShellInput); 33 35 34 36 /** … … 39 41 : Text ("") 40 42 { 43 this->registerObject(this, ShellInput::_objectList); 44 41 45 this->pressedKey = SDLK_FIRST; 42 this->setClassID(CL_SHELL_INPUT, "ShellInput"); 43 44 this->inputLine = ""; 46 45 47 this->historyIT = ShellInput::history.begin(); 46 48 this->setHistoryLength(50); … … 53 55 { 54 56 //if (!this->isEventSubscribed(ES_SHELL, i)) 55 57 this->subscribeEvent(ES_SHELL, i); 56 58 } 57 59 // unsubscribe unused TODO improve. … … 60 62 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP); 61 63 this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN); 62 63 64 } 64 65 … … 87 88 void ShellInput::flush() 88 89 { 89 this->inputLine.clear(); 90 this->setText(this->inputLine); 90 this->inputLineBegin.clear(); 91 this->inputLineEnd.clear(); 92 this->clear(); 91 93 } 92 94 … … 97 99 void ShellInput::setInputText(const std::string& text) 98 100 { 99 this->inputLine = text; 100 this->setText(this->inputLine); 101 this->inputLineBegin = text; 102 this->inputLineEnd.clear(); 103 this->setText(text); 101 104 } 102 105 … … 114 117 } 115 118 116 this->inputLine += character;117 this->setText(this->inputLine );119 this->inputLineBegin += character; 120 this->setText(this->inputLineBegin + this->inputLineEnd); 118 121 } 119 122 … … 130 133 } 131 134 132 this->inputLine += characters;133 this->setText(this->inputLine );135 this->inputLineBegin += characters; 136 this->setText(this->inputLineBegin + this->inputLineEnd); 134 137 } 135 138 … … 145 148 this->historyScrolling = false; 146 149 } 147 if (this->inputLine .size() < characterCount)148 characterCount = this->inputLine .size();149 150 this->inputLine .erase(this->inputLine.size() - characterCount, this->inputLine.size());151 this->setText(this->inputLine );150 if (this->inputLineBegin.size() < characterCount) 151 characterCount = this->inputLineBegin.size(); 152 153 this->inputLineBegin.erase(this->inputLineBegin.size() - characterCount, this->inputLineBegin.size()); 154 this->setText(this->inputLineBegin + this->inputLineEnd); 152 155 } 153 156 … … 158 161 bool ShellInput::executeCommand() 159 162 { 160 ShellBuffer::addBufferLineStatic("Execute Command: %s\n", this->inputLine.c_str()); 161 162 if (this->inputLine.empty()) 163 if (this->getInput().empty()) 163 164 return false; 164 165 ShellCommand::execute(this->inputLine); 165 DebugBuffer::addBufferLineStatic("Execute Command: %s\n", this->getInput().c_str()); 166 167 ShellCommand::execute(this->getInput()); 166 168 167 169 // removing the eventually added Entry (from scrolling) to the List … … 173 175 174 176 // adding the new Command to the History 175 if (history.empty() || history.back() != this-> inputLine)176 this->history.push_back(this-> inputLine);177 if (history.empty() || history.back() != this->getInput()) 178 this->history.push_back(this->getInput()); 177 179 if (this->history.size() > this->historyLength) 178 180 { … … 193 195 if (!this->historyScrolling) 194 196 { 195 this->history.push_back(this-> inputLine);197 this->history.push_back(this->getInput()); 196 198 this->historyScrolling = true; 197 199 this->historyIT = --this->history.end(); … … 231 233 } 232 234 235 /** 236 * @brief moves the cursor chars Characters to the right. 237 * @param chars how much to move the cursor. 238 */ 239 void ShellInput::moveCursor(int chars) 240 { 241 if (chars > 0) 242 { 243 PRINTF(5)("move cursor %d to the right\n", chars); 244 if (chars >= (int) this->inputLineEnd.size()) 245 chars = inputLineEnd.size(); 246 this->inputLineBegin += this->inputLineEnd.substr(0, chars); 247 this->inputLineEnd.erase(0, chars); 248 } 249 else if (chars < 0) 250 { 251 chars = -chars; 252 PRINTF(5)("move cursor %d to the left\n", chars); 253 254 if (chars >= (int) this->inputLineBegin.size()) 255 chars = inputLineBegin.size(); 256 this->inputLineEnd = this->inputLineBegin.substr(this->inputLineBegin.size() - chars) + this->inputLineEnd; 257 this->inputLineBegin.erase(this->inputLineBegin.size() - chars); 258 } 259 } 260 233 261 234 262 /** … … 237 265 void ShellInput::help(const std::string& className, const std::string& functionName) 238 266 { 239 printf("%s::%s\n", className.c_str(), functionName.c_str());240 241 267 if (className.empty()) 242 268 { 243 PRINT(0)(" Help for the most important Shell-commands\n");244 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n");245 PRINT(0)(" input order:\n");246 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n");247 PRINT(0)(" Alias [parameter]\n");248 PRINT(0)("- Also try 'help className' ");269 PRINT(0)("== Help for the most important Shell-commands\n"); 270 PRINT(0)(" F1 - HELP; F2 - DEBUG; '`' - open/close shell\n"); 271 PRINT(0)(" input order:\n"); 272 PRINT(0)(" ClassName [objectName] function [parameter1, [parameter2 ...]] or\n"); 273 PRINT(0)(" Alias [parameter]\n"); 274 PRINT(0)("- Also try 'help className' or pushing 'TAB'\n"); 249 275 } 250 276 else if (!className.empty() && functionName.empty()) … … 269 295 { 270 296 case SDLK_BACKSPACE: 271 272 297 this->removeCharacters(1); 298 break; 273 299 case SDLK_UP: 274 275 300 this->historyMoveUp(); 301 break; 276 302 case SDLK_DOWN: 277 278 303 this->historyMoveDown(); 304 break; 279 305 default: 280 281 282 283 306 { 307 if (likely(pressedKey < 127)) 308 this->addCharacter(this->pressedKey); 309 } 284 310 } 285 311 } … … 313 339 this->pressedEvent = event.type; 314 340 } 341 else if (event.type == SDLK_LEFT) 342 { 343 this->moveCursor(-1); 344 this->pressedKey = event.type; 345 this->pressedEvent = event.type; 346 } 347 else if (event.type == SDLK_RIGHT) 348 { 349 this->moveCursor(+1); 350 this->pressedKey = event.type; 351 this->pressedEvent = event.type; 352 } 315 353 else if (event.type == SDLK_TAB) 316 354 { 317 this->completion.autoComplete(this->inputLine );318 this->setText(this-> inputLine);355 this->completion.autoComplete(this->inputLineBegin); 356 this->setText(this->getInput()); 319 357 } 320 358 else if (event.type == SDLK_BACKSPACE) … … 325 363 this->removeCharacters(1); 326 364 } 365 else if (event.type == SDLK_DELETE) 366 { 367 if (!this->inputLineEnd.empty()) 368 { 369 this->inputLineEnd.erase(0, 1); 370 this->setText(this->getInput()); 371 } 372 } 327 373 else if (event.type == SDLK_RETURN) 328 374 { -
trunk/src/lib/shell/shell_input.h
r7858 r9869 30 30 class ShellInput : public Text, public EventListener 31 31 { 32 ObjectListDeclaration(ShellInput); 32 33 33 34 public: … … 36 37 37 38 /** @returns the inputLine */ 38 const std::string& getInput() const { return this->inputLine; };39 std::string getInput() const { return this->inputLineBegin + this->inputLineEnd; }; 39 40 40 41 // InputLine … … 54 55 void historyMoveDown(); 55 56 57 void moveCursor(int chars); 58 56 59 void help(const std::string& className = "", const std::string& function = ""); 57 60 … … 63 66 ShellCompletion completion; //!< The Completion Interface. 64 67 65 std::string inputLine; //!< the Char-Array of the Buffer 68 std::string inputLineBegin; //!< The Line up to the cursor. 69 std::string inputLineEnd; //!< The Line from the cursor on 70 66 71 float repeatRate; //!< The Repeat-Delay. 67 72 float repeatDelay; //!< The delay of the first Character of a given Character. -
trunk/src/lib/shell/some_shell_commands.cc
r8623 r9869 29 29 30 30 #include "network_game_rules.h" 31 31 SHELL_COMMAND(say, NetworkGameRules, shellSay)->setAlias("say"); 32 32 33 33 #include "player_stats.h" 34 34 SHELL_COMMAND(nick, PlayerStats, shellNick)->setAlias("nick"); 35 35 36 #include "class_list.h"37 SHELL_COMMAND(debug, ClassList, ClassList::debugS)38 ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output")39 ->defaultValues(MT_NULL, 1);36 // #include "class_list.h" 37 // SHELL_COMMAND(debug, ClassList, ClassList::debugS) 38 // ->describe("Shows all registered classes, if param1: is a valid ClassName only values of this class are shown. param2: how much output") 39 // ->defaultValues(MT_NULL, 1); 40 40 41 41 #include "p_node.h" 42 43 42 SHELL_COMMAND(debugNode, PNode, debugNode); 43 SHELL_COMMAND(setPosition, PNode, setAbsCoor); 44 44 45 45 #include "render_2d.h" 46 46 SHELL_COMMAND(toggleNodeVisibility, Render2D, toggleNodesVisibility); 47 47 48 48 49 49 #include "material.h" 50 51 52 50 SHELL_COMMAND(setDiffuseTexture, Material, setDiffuseMap) 51 ->defaultValues(MT_NULL, (int)GL_TEXTURE_2D) 52 ->completionPlugin(0, CompletorFileSystem()); 53 53 54 #include "loading/resource_manager.h" 55 namespace Resources { 56 SHELL_COMMAND(debug, ResourceManager, debug); 57 SHELL_COMMAND(load, ResourceManager, loadFromLoadStringHACK); 58 SHELL_COMMAND(unload, ResourceManager, unloadAllBelowKeepLevelINT); 59 } 60 61 #include "loading/load_param_class_description.h" 62 SHELL_COMMAND_STATIC(printAll, LoadParamClassDescription, &LoadParamClassDescription::printAll) 63 ->defaultValues(MT_NULL, true); 64 SHELL_COMMAND_STATIC(capture, LoadParamClassDescription, &LoadParamClassDescription::captureDescriptions) 65 ->defaultValues(true); 66 67 #include "loading/game_loader.h" 68 SHELL_COMMAND(quit, GameLoader, stop) 69 ->describe("quits the game") 70 ->setAlias("orxoquit"); 71 72 #include "object_list.h" 73 SHELL_COMMAND_STATIC(debugAll, ObjectListBase, &ObjectListBase::debugAll);
Note: See TracChangeset
for help on using the changeset viewer.