Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 27, 2008, 6:29:08 PM (16 years ago)
Author:
landauf
Message:

you'll love this: separated displayed strings in autocompletion from actually inserted strings, to make fancy things like a really good autocompletion for files and directories.

@bensch: this is the "better system" I was talking about

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CommandExecutor.cc

    r1437 r1441  
    371371                {
    372372                    // There is exactly one possible argument
    373                     CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second;
    374                     CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).second;
     373                    CommandExecutor::getEvaluation().argument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString();
     374                    CommandExecutor::getEvaluation().possibleArgument_ = (*CommandExecutor::getEvaluation().listOfPossibleArguments_.begin()).getString();
    375375                    CommandExecutor::getEvaluation().state_ = CS_ParamPreparation;
    376376                    return;
     
    457457                if ((*it).first.find(lowercase) == 0 || fragment == "")
    458458                    CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    459 
    460         CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.sort(CommandExecutor::compareStringsInList);
    461459    }
    462460
     
    477475                    CommandExecutor::getEvaluation().listOfPossibleFunctions_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second->getName()));
    478476        }
    479 
    480         CommandExecutor::getEvaluation().listOfPossibleFunctions_.sort(CommandExecutor::compareStringsInList);
    481477    }
    482478
     
    487483        CommandExecutor::getEvaluation().listOfPossibleArguments_.clear();
    488484        std::string lowercase = getLowercase(fragment);
    489         for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
    490             if ((*it).first.find(lowercase) == 0 || fragment == "")
    491                 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair<std::string, std::string>((*it).first, (*it).second));
    492 
    493         CommandExecutor::getEvaluation().listOfPossibleArguments_.sort(CommandExecutor::compareStringsInList2);
     485        for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
     486        {
     487            if ((*it).lowercaseComparison())
     488            {
     489                if ((*it).getComparable().find(lowercase) == 0 || fragment == "")
     490                    CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it);
     491            }
     492            else
     493            {
     494                if ((*it).getComparable().find(fragment) == 0 || fragment == "")
     495                    CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(*it);
     496            }
     497        }
    494498    }
    495499
     
    527531
    528532        std::string lowercase = getLowercase(name);
    529         for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
    530         {
    531             if ((*it).first == lowercase)
    532                 return (*it).second;
     533        for (ArgumentCompletionList::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
     534        {
     535            if ((*it).lowercaseComparison())
     536            {
     537                if ((*it).getComparable() == lowercase)
     538                    return (*it).getString();
     539            }
     540            else
     541            {
     542                if ((*it).getComparable() == name)
     543                    return (*it).getString();
     544            }
    533545        }
    534546
     
    595607    }
    596608
    597     std::string CommandExecutor::getCommonBegin(const std::list<std::pair<std::string, std::string> >& list)
     609    std::string CommandExecutor::getCommonBegin(const ArgumentCompletionList& list)
    598610    {
    599611        if (list.size() == 0)
     
    603615        else if (list.size() == 1)
    604616        {
    605             return ((*list.begin()).first + " ");
     617            return ((*list.begin()).getComparable() + " ");
    606618        }
    607619        else
     
    611623            {
    612624                char temp = 0;
    613                 for (std::list<std::pair<std::string, std::string> >::const_iterator it = list.begin(); it != list.end(); ++it)
    614                 {
    615                     if ((*it).first.size() > i)
     625                for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
     626                {
     627                    std::string argument = (*it).getComparable();
     628                    if (argument.size() > i)
    616629                    {
    617630                        if (it == list.begin())
    618631                        {
    619                             temp = (*it).first[i];
     632                            temp = argument[i];
    620633                        }
    621634                        else
    622635                        {
    623                             if (temp != (*it).first[i])
     636                            if (temp != argument[i])
    624637                                return output;
    625638                        }
     
    635648        }
    636649    }
    637 
    638     bool CommandExecutor::compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second)
    639     {
    640         return ((*first.first) < (*second.first));
    641     }
    642 
    643     bool CommandExecutor::compareStringsInList2(const std::pair<std::string, std::string>& first, const std::pair<std::string, std::string>& second)
    644     {
    645         return (first.first < second.first);
    646     }
    647650}
Note: See TracChangeset for help on using the changeset viewer.