Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7235


Ignore:
Timestamp:
Aug 28, 2010, 1:25:04 AM (14 years ago)
Author:
landauf
Message:
  • 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
Location:
code/branches/consolecommands3/src/libraries/core/command
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.cc

    r7234 r7235  
    6969            }
    7070
    71             ArgumentCompletionList _groupsandcommands(bool bOnlyShowHidden)
     71            ArgumentCompletionList _groupsandcommands(const std::string& fragment, bool bOnlyShowHidden)
    7272            {
    7373                ArgumentCompletionList groupList;
     74                std::string fragmentLC = getLowercase(fragment);
    7475
    7576                const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& commands = _ConsoleCommand::getCommands();
    7677                for (std::map<std::string, std::map<std::string, _ConsoleCommand*> >::const_iterator it_group = commands.begin(); it_group != commands.end(); ++it_group)
    77                     if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "")
     78                    if (groupIsVisible(it_group->second, bOnlyShowHidden) && it_group->first != "" && (fragmentLC == "" || getLowercase(it_group->first).find_first_of(fragmentLC) == 0))
    7879                        groupList.push_back(ArgumentCompletionListElement(it_group->first, getLowercase(it_group->first)));
    7980
     
    8182                if (it_group != commands.end())
    8283                {
    83                     groupList.push_back(ArgumentCompletionListElement("", "", "\n"));
     84                    if (!groupList.empty())
     85                        groupList.push_back(ArgumentCompletionListElement("", "", "\n"));
    8486
    8587                    for (std::map<std::string, _ConsoleCommand*>::const_iterator it_command = it_group->second.begin(); it_command != it_group->second.end(); ++it_command)
    86                         if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden)
     88                        if (it_command->second->isActive() && it_command->second->hasAccess() && (!it_command->second->isHidden())^bOnlyShowHidden && (fragmentLC == "" || getLowercase(it_command->first).find_first_of(fragmentLC) == 0))
    8789                            groupList.push_back(ArgumentCompletionListElement(it_command->first, getLowercase(it_command->first)));
    8890                }
     91
     92                if (!groupList.empty() && groupList.back().getDisplay() == "\n")
     93                    groupList.pop_back();
    8994
    9095                return groupList;
     
    113118        }
    114119
    115         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)()
    116         {
    117             return detail::_groupsandcommands(false);
     120        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(groupsandcommands)(const std::string& fragment)
     121        {
     122            return detail::_groupsandcommands(fragment, false);
    118123        }
    119124
     
    128133            const std::string& hint = evaluation.hint();
    129134
    130             if (evaluation.getPossibleArguments().size() > 0)
     135            if (evaluation.getPossibleArguments().size() > 0 && evaluation.getPossibleArgumentsSize() > 0)
    131136            {
    132137                return evaluation.getPossibleArguments();
     
    145150
    146151            if (tokens.size() == 0)
    147                 return detail::_groupsandcommands(true);
     152                return detail::_groupsandcommands(fragment, true);
    148153
    149154            if (_ConsoleCommand::getCommandLC(getLowercase(tokens[0])))
     
    156161                    return detail::_subcommands(fragment, tokens[0], true);
    157162                else
    158                     return detail::_groupsandcommands(true);
     163                    return detail::_groupsandcommands(fragment, true);
    159164            }
    160165
  • code/branches/consolecommands3/src/libraries/core/command/ArgumentCompletionFunctions.h

    r7234 r7235  
    6060    {
    6161        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
    62         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)();
     62        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(groupsandcommands)(const std::string& fragment);
    6363        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(subcommands)(const std::string& fragment, const std::string& group);
    6464        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(command)(const std::string& fragment);
  • code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.cc

    r7233 r7235  
    197197            this->retrievePossibleArguments();
    198198
    199         if (!this->possibleArguments_.empty())
     199        if (CommandEvaluation::getSize(this->possibleArguments_) > 0 || (!this->possibleArguments_.empty() && this->isValid()))
    200200            return CommandEvaluation::dump(this->possibleArguments_);
    201201
     
    256256            }
    257257        }
     258    }
     259
     260    /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list)
     261    {
     262        size_t count = 0;
     263        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
     264            if (it->getComparable() != "")
     265                ++count;
     266        return count;
    258267    }
    259268
     
    294303            }
    295304        }
    296     }
    297 
    298     /* static */ size_t CommandEvaluation::getSize(const ArgumentCompletionList& list)
    299     {
    300         size_t count = 0;
    301         for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    302             if (it->getComparable() != "")
    303                 ++count;
    304         return count;
    305     }
    306 
    307     /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
    308     {
    309         std::string output;
    310         for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    311         {
    312             output += it->getDisplay();
    313 
    314             if (it->getComparable() != "")
    315                 output += ' ';
    316         }
    317         return output;
    318     }
    319 
    320     /* static */ std::string CommandEvaluation::dump(const _ConsoleCommand* command)
    321     {
    322         std::string output = command->getName();
    323         if (command->getExecutor()->getParamCount() > 0)
    324             output += ": ";
    325 
    326         for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++)
    327         {
    328             if (i != 0)
    329                 output += ' ';
    330 
    331             if (command->getExecutor()->defaultValueSet(i))
    332                 output += '[';
    333             else
    334                 output += '{';
    335 
    336             output += command->getExecutor()->getTypenameParam(i);
    337 
    338             if (command->getExecutor()->defaultValueSet(i))
    339                 output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']';
    340             else
    341                 output += '}';
    342         }
    343         return output;
    344305    }
    345306
     
    405366        }
    406367    }
     368
     369    /* static */ std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
     370    {
     371        std::string output;
     372        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
     373        {
     374            output += it->getDisplay();
     375
     376            if (it->getComparable() != "")
     377                output += ' ';
     378        }
     379        return output;
     380    }
     381
     382    /* static */ std::string CommandEvaluation::dump(const _ConsoleCommand* command)
     383    {
     384        std::string output = command->getName();
     385        if (command->getExecutor()->getParamCount() > 0)
     386            output += ": ";
     387
     388        for (unsigned int i = 0; i < command->getExecutor()->getParamCount(); i++)
     389        {
     390            if (i != 0)
     391                output += ' ';
     392
     393            if (command->getExecutor()->defaultValueSet(i))
     394                output += '[';
     395            else
     396                output += '{';
     397
     398            output += command->getExecutor()->getTypenameParam(i);
     399
     400            if (command->getExecutor()->defaultValueSet(i))
     401                output += '=' + command->getExecutor()->getDefaultValue(i).getString() + ']';
     402            else
     403                output += '}';
     404        }
     405        return output;
     406    }
    407407}
  • code/branches/consolecommands3/src/libraries/core/command/CommandEvaluation.h

    r7233 r7235  
    6868                { return this->possibleArguments_; }
    6969
     70            size_t getPossibleArgumentsSize() const
     71                { return CommandEvaluation::getSize(this->possibleArguments_); }
     72
    7073        private:
    7174            void initialize(const std::string& command);
Note: See TracChangeset for help on using the changeset viewer.