[Orxonox-commit 2530] r7235 - code/branches/consolecommands3/src/libraries/core/command

landauf at orxonox.net landauf at orxonox.net
Sat Aug 28 01:25:04 CEST 2010


Author: landauf
Date: 2010-08-28 01:25:04 +0200 (Sat, 28 Aug 2010)
New Revision: 7235

Modified:
   code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
   code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h
   code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
   code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
Log:
 - fixed error if a command doesn't exist not being shown while using auto-completion
 - fixed error if a command doesn't exist not being redirected to sub-command auto-completion
 - fixed unneeded line-breaks in auto-completion list

Modified: code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc	2010-08-27 22:37:38 UTC (rev 7234)
+++ code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc	2010-08-27 23:25:04 UTC (rev 7235)
@@ -68,25 +68,30 @@
                 return false;
             }
 
-            ArgumentCompletionList _groupsandcommands(bool bOnlyShowHidden)
+            ArgumentCompletionList _groupsandcommands(const std::string& fragment, bool bOnlyShowHidden)
             {
                 ArgumentCompletionList groupList;
+                std::string fragmentLC = getLowercase(fragment);
 
                 const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands();
                 for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
-                    if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "")
+                    if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find_first_of(fragmentLC) == 0))
                         groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first)));
 
                 std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.find("");
                 if (it_group != commands.end())
                 {
-                    groupList.push_back(ArgumentCompletionListElement("", "", "\n"));
+                    if (!groupList.empty())
+                        groupList.push_back(ArgumentCompletionListElement("", "", "\n"));
 
                     for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
-                        if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
+                        if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(it_command->first).find_first_of(fragmentLC) == 0))
                             groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
                 }
 
+                if (!groupList.empty() && groupList.back().getDisplay() == "\n")
+                    groupList.pop_back();
+
                 return groupList;
             }
 
@@ -112,9 +117,9 @@
             }
         }
 
-        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)()
+        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)(const std::string& fragment)
         {
-            return detail::_groupsandcommands(false);
+            return detail::_groupsandcommands(fragment, false);
         }
 
         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(subcommands)(const std::string& fragment, const std::string& group)
@@ -127,7 +132,7 @@
             CommandEvaluation evaluation = CommandExecutor::evaluate(fragment);
             const std::string& hint = evaluation.hint();
 
-            if (evaluation.getPossibleArguments().size() > 0)
+            if (evaluation.getPossibleArguments().size() > 0 && evaluation.getPossibleArgumentsSize() > 0)
             {
                 return evaluation.getPossibleArguments();
             }
@@ -144,7 +149,7 @@
             SubString tokens(fragment, " ", SubString::WhiteSpaces, false, '\\', true, '"', true, '(', ')', true, '\0');
 
             if (tokens.size() == 0)
-                return detail::_groupsandcommands(true);
+                return detail::_groupsandcommands(fragment, true);
 
             if (_ConsoleCommand::getCommandLC(getLowercase(tokens[0])))
                 return ARGUMENT_COMPLETION_FUNCTION_CALL(command)(fragment);
@@ -155,7 +160,7 @@
                 if (it_group != _ConsoleCommand::getCommands().end())
                     return detail::_subcommands(fragment, tokens[0], true);
                 else
-                    return detail::_groupsandcommands(true);
+                    return detail::_groupsandcommands(fragment, true);
             }
 
             if (_ConsoleCommand::getCommandLC(getLowercase(tokens[0]), getLowercase(tokens[1])))

Modified: code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h	2010-08-27 22:37:38 UTC (rev 7234)
+++ code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h	2010-08-27 23:25:04 UTC (rev 7235)
@@ -59,7 +59,7 @@
     namespace autocompletion
     {
         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
-        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)();
+        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)(const std::string& fragment);
         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(subcommands)(const std::string& fragment, const std::string& group);
         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(command)(const std::string& fragment);
         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(hiddencommand)(const std::string& fragment);

Modified: code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc	2010-08-27 22:37:38 UTC (rev 7234)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc	2010-08-27 23:25:04 UTC (rev 7235)
@@ -196,7 +196,7 @@
         if (!this->bPossibleArgumentsRetrieved_)
             this->retrievePossibleArguments();
 
-        if (!this->possibleArguments_.empty())
+        if (CommandEvaluation::getSize(this->possibleArguments_) > 0 || (!this->possibleArguments_.empty() && this->isValid()))
             return CommandEvaluation::dump(this->possibleArguments_);
 
         if (this->isValid())
@@ -257,6 +257,15 @@
         }
     }
 
+    /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list)
+    {
+        size_t count = 0;
+        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
+            if (it->getComparable() != "")
+                ++count;
+        return count;
+    }
+
     /* static */ void CommandEvaluation::strip(ArgumentCompletionList& list, const std::string& fragment)
     {
         std::string fragmentLC = getLowercase(fragment);
@@ -295,54 +304,6 @@
         }
     }
 
-    /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list)
-    {
-        size_t count = 0;
-        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
-            if (it->getComparable() != "")
-                ++count;
-        return count;
-    }
-
-    /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
-    {
-        std::string output;
-        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
-        {
-            output += it->getDisplay();
-
-            if (it->getComparable() != "")
-                output += ' ';
-        }
-        return output;
-    }
-
-    /* static */ std::string CommandEvaluation::dump(const _ConsoleCommand* command)
-    {
-        std::string output = command->getName();
-        if (command->getExecutor()->getParamCount() > 0)
-            output += ": ";
-
-        for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++)
-        {
-            if (i != 0)
-                output += ' ';
-
-            if (command->getExecutor()->defaultValueSet(i))
-                output += '[';
-            else
-                output += '{';
-
-            output += command->getExecutor()->getTypenameParam(i);
-
-            if (command->getExecutor()->defaultValueSet(i))
-                output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']';
-            else
-                output += '}';
-        }
-        return output;
-    }
-
     /* static */ std::string CommandEvaluation::getCommonBegin(const ArgumentCompletionList& list)
     {
         if (CommandEvaluation::getSize(list) == 0)
@@ -404,4 +365,43 @@
             return output;
         }
     }
+
+    /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
+    {
+        std::string output;
+        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
+        {
+            output += it->getDisplay();
+
+            if (it->getComparable() != "")
+                output += ' ';
+        }
+        return output;
+    }
+
+    /* static */ std::string CommandEvaluation::dump(const _ConsoleCommand* command)
+    {
+        std::string output = command->getName();
+        if (command->getExecutor()->getParamCount() > 0)
+            output += ": ";
+
+        for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++)
+        {
+            if (i != 0)
+                output += ' ';
+
+            if (command->getExecutor()->defaultValueSet(i))
+                output += '[';
+            else
+                output += '{';
+
+            output += command->getExecutor()->getTypenameParam(i);
+
+            if (command->getExecutor()->defaultValueSet(i))
+                output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']';
+            else
+                output += '}';
+        }
+        return output;
+    }
 }

Modified: code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h
===================================================================
--- code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h	2010-08-27 22:37:38 UTC (rev 7234)
+++ code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h	2010-08-27 23:25:04 UTC (rev 7235)
@@ -67,6 +67,9 @@
             const ArgumentCompletionList& getPossibleArguments() const
                 { return this->possibleArguments_; }
 
+            size_t getPossibleArgumentsSize() const
+                { return CommandEvaluation::getSize(this->possibleArguments_); }
+
         private:
             void initialize(const std::string& command);
 




More information about the Orxonox-commit mailing list