Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1441


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

Location:
code/branches/console/src/core
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/ArgumentCompleter.h

    r1436 r1441  
    3030#define _ArgumentCompleter_H__
    3131
    32 #include <list>
    33 #include <string>
    34 
    3532#include "CorePrereqs.h"
     33#include "ArgumentCompletionListElement.h"
    3634
    3735namespace orxonox
     
    4038    {
    4139        public:
    42             ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (void)) : paramCount_(0), function_0_(function) {}
    43             ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1)) : paramCount_(1), function_1_(function) {}
    44             ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2)) : paramCount_(2), function_2_(function) {}
    45             ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3)) : paramCount_(3), function_3_(function) {}
    46             ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4)) : paramCount_(4), function_4_(function) {}
    47             ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)) : paramCount_(5), function_5_(function) {}
     40            ArgumentCompleter(ArgumentCompletionList (*function) (void)) : paramCount_(0), function_0_(function) {}
     41            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1)) : paramCount_(1), function_1_(function) {}
     42            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2)) : paramCount_(2), function_2_(function) {}
     43            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3)) : paramCount_(3), function_3_(function) {}
     44            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4)) : paramCount_(4), function_4_(function) {}
     45            ArgumentCompleter(ArgumentCompletionList (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)) : paramCount_(5), function_5_(function) {}
    4846
    49             std::list<std::pair<std::string, std::string> > operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
     47            ArgumentCompletionList operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
    5048            {
    5149                switch (this->paramCount_)
     
    6462                        return (*this->function_5_)(param1, param2, param3, param4, param5);
    6563                    default:
    66                         return std::list<std::pair<std::string, std::string> >();
     64                        return ArgumentCompletionList();
    6765                }
    6866            }
     
    7068        private:
    7169            unsigned char paramCount_;
    72             std::list<std::pair<std::string, std::string> > (*function_0_) (void);
    73             std::list<std::pair<std::string, std::string> > (*function_1_) (const std::string& param1);
    74             std::list<std::pair<std::string, std::string> > (*function_2_) (const std::string& param1, const std::string& param2);
    75             std::list<std::pair<std::string, std::string> > (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);
    76             std::list<std::pair<std::string, std::string> > (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);
    77             std::list<std::pair<std::string, std::string> > (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);
     70            ArgumentCompletionList (*function_0_) (void);
     71            ArgumentCompletionList (*function_1_) (const std::string& param1);
     72            ArgumentCompletionList (*function_2_) (const std::string& param1, const std::string& param2);
     73            ArgumentCompletionList (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);
     74            ArgumentCompletionList (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);
     75            ArgumentCompletionList (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);
    7876    };
    7977}
  • code/branches/console/src/core/ArgumentCompletionFunctions.cc

    r1439 r1441  
    3030#include <map>
    3131
    32 //#include <stdio.h>
    33 //#include <stdlib.h>
    34 //#include <errno.h>
    35 //#include <sys/types.h>
    36 //#include <sys/stat.h>
    3732#include <dirent.h>
    3833
     
    4237#include "ConfigValueContainer.h"
    4338#include "TclThreadManager.h"
     39#include "util/Convert.h"
    4440#include "util/String.h"
    4541#include "util/SubString.h"
     
    5147        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)()
    5248        {
    53             return std::list<std::pair<std::string, std::string> >();
     49            return ArgumentCompletionList();
    5450        }
    5551
    5652        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment)
    5753        {
    58             std::list<std::pair<std::string, std::string> > dirlist;
    59             std::list<std::pair<std::string, std::string> > filelist;
     54            ArgumentCompletionList dirlist;
     55            ArgumentCompletionList filelist;
    6056
    6157            SubString tokens(fragment, "/", "", false, '\0', false, '\0', false, '\0', '\0', false, '\0');
     
    8682
    8783                        if (S_ISREG(fileInfo.st_mode)) // normal file
    88                             filelist.push_back(std::pair<std::string, std::string>(getLowercase(path), path));
     84                            filelist.push_back(ArgumentCompletionListElement(path, getLowercase(path), currentFile->d_name));
    8985                        else if (S_ISDIR(fileInfo.st_mode)) // directory
    90                             dirlist.push_back(std::pair<std::string, std::string>(getLowercase(path) + "/", path + "/"));
     86                            dirlist.push_back(ArgumentCompletionListElement(path + "/", getLowercase(path) + "/", std::string(currentFile->d_name) + "/"));
    9187                        else // special file
    92                             filelist.push_back(std::pair<std::string, std::string>(getLowercase(path), path));
     88                            filelist.push_back(ArgumentCompletionListElement(path, getLowercase(path), currentFile->d_name));
    9389                    }
    9490                }
     
    10399        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalueclasses)()
    104100        {
    105             std::list<std::pair<std::string, std::string> > classlist;
     101            ArgumentCompletionList classlist;
    106102
    107103            for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getIdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)
    108104                if ((*it).second->hasConfigValues())
    109                     classlist.push_back(std::pair<std::string, std::string>(getLowercase((*it).first), (*it).second->getName()));
     105                    classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first)));
    110106
    111107            return classlist;
     
    114110        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname)
    115111        {
    116             std::list<std::pair<std::string, std::string> > configvalues;
     112            ArgumentCompletionList configvalues;
    117113            std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getIdentifierMap().find(classname);
    118114
     
    120116            {
    121117                for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it)
    122                     configvalues.push_back(std::pair<std::string, std::string>(getLowercase((*it).first), (*it).second->getName()));
     118                    configvalues.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first)));
    123119            }
    124120
     
    128124        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname)
    129125        {
    130             std::list<std::pair<std::string, std::string> > oldvalue;
     126            ArgumentCompletionList oldvalue;
    131127            std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseIdentifierMap().find(getLowercase(classname));
    132128            if (identifier != Identifier::getLowercaseIdentifierMapEnd())
     
    136132                {
    137133                    std::string valuestring = (*variable).second->toString();
    138                     oldvalue.push_back(std::pair<std::string, std::string>(valuestring, valuestring));
     134                    oldvalue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
    139135                }
    140136            }
     
    144140        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)()
    145141        {
    146             return TclThreadManager::getInstance().getThreadList();
     142            std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList();
     143            ArgumentCompletionList threads;
     144
     145            for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it)
     146                threads.push_back(ArgumentCompletionListElement(getConvertedValue<unsigned int, std::string>(*it)));
     147
     148            return threads;
    147149        }
    148150    }
  • code/branches/console/src/core/ArgumentCompletionFunctions.h

    r1436 r1441  
    3030#define _ArgumentCompletionFunctions_H__
    3131
    32 #include <list>
    33 #include <string>
    34 
     32#include "CorePrereqs.h"
    3533#include "ArgumentCompleter.h"
    36 #include "CorePrereqs.h"
    3734
    3835
    3936#define ARGUMENT_COMPLETION_FUNCTION_DECLARATION(functionname) \
    4037    ArgumentCompleter* functionname(); \
    41     _CoreExport std::list<std::pair<std::string, std::string> > acf_##functionname
     38    _CoreExport ArgumentCompletionList acf_##functionname
    4239
    4340#define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(functionname) \
     
    4845    } \
    4946    \
    50     std::list<std::pair<std::string, std::string> > acf_##functionname
     47    ArgumentCompletionList acf_##functionname
    5148
    5249
  • code/branches/console/src/core/CommandEvaluation.cc

    r1435 r1441  
    271271    }
    272272
    273     std::string CommandEvaluation::dump(const std::list<std::pair<std::string, std::string> >& list)
     273    std::string CommandEvaluation::dump(const ArgumentCompletionList& list)
    274274    {
    275275        std::string output = "";
    276         for (std::list<std::pair<std::string, std::string> >::const_iterator it = list.begin(); it != list.end(); ++it)
     276        for (ArgumentCompletionList::const_iterator it = list.begin(); it != list.end(); ++it)
    277277        {
    278278            if (it != list.begin())
    279279                output += " ";
    280280
    281             output += (*it).second;
     281            output += (*it).getDisplay();
    282282        }
    283283        return output;
  • code/branches/console/src/core/CommandEvaluation.h

    r1434 r1441  
    3535#include <list>
    3636
     37#include "ArgumentCompletionListElement.h"
    3738#include "util/SubString.h"
    3839#include "util/MultiTypeMath.h"
     
    8283            unsigned int getStartindex() const;
    8384            static std::string dump(const std::list<std::pair<const std::string*, const std::string*> >& list);
    84             static std::string dump(const std::list<std::pair<std::string, std::string> >& list);
     85            static std::string dump(const ArgumentCompletionList& list);
    8586            static std::string dump(const ConsoleCommand* command);
    8687
     
    9697            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleIdentifiers_;
    9798            std::list<std::pair<const std::string*, const std::string*> > listOfPossibleFunctions_;
    98             std::list<std::pair<std::string, std::string> > listOfPossibleArguments_;
     99            ArgumentCompletionList listOfPossibleArguments_;
    99100
    100101            Identifier* functionclass_;
  • 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}
  • code/branches/console/src/core/CommandExecutor.h

    r1434 r1441  
    3535
    3636#include "CommandEvaluation.h"
    37 
    38 #define COMMAND_EXECUTOR_CURSOR "$"
    3937
    4038namespace orxonox
     
    9593            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
    9694            static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
    97             static std::string getCommonBegin(const std::list<std::pair<std::string, std::string> >& list);
    98             static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second);
    99             static bool compareStringsInList2(const std::pair<std::string, std::string>& first, const std::pair<std::string, std::string>& second);
    100 
     95            static std::string getCommonBegin(const ArgumentCompletionList& list);
    10196
    10297            CommandEvaluation evaluation_;
  • code/branches/console/src/core/ConsoleCommand.h

    r1434 r1441  
    3434#include "Executor.h"
    3535#include "ClassManager.h"
    36 #include "Identifier.h"
    3736#include "CommandExecutor.h"
    3837#include "ArgumentCompletionFunctions.h"
     
    104103
    105104            void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");
    106             const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList() const
     105            const ArgumentCompletionList& getArgumentCompletionList() const
    107106                { return this->argumentList_; }
    108             std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin() const
     107            ArgumentCompletionList::const_iterator getArgumentCompletionListBegin() const
    109108                { return this->argumentList_.begin(); }
    110             std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd() const
     109            ArgumentCompletionList::const_iterator getArgumentCompletionListEnd() const
    111110                { return this->argumentList_.end(); }
    112111
     
    114113            AccessLevel::Level accessLevel_;
    115114            ArgumentCompleter* argumentCompleter_[5];
    116             std::list<std::pair<std::string, std::string> > argumentList_;
     115            ArgumentCompletionList argumentList_;
    117116    };
    118117
  • code/branches/console/src/core/CorePrereqs.h

    r1430 r1441  
    7878
    7979  class ArgumentCompleter;
     80  class ArgumentCompletionListElement;
    8081  class BaseFactory;
    8182  class BaseMetaObjectListElement;
  • code/branches/console/src/core/TclThreadManager.cc

    r1434 r1441  
    632632    }
    633633
    634     std::list<std::pair<std::string, std::string> > TclThreadManager::getThreadList() const
     634    std::list<unsigned int> TclThreadManager::getThreadList() const
    635635    {
    636636        boost::mutex::scoped_lock bundles_lock(TclThreadManager::getInstance().bundlesMutex_);
    637         std::list<std::pair<std::string, std::string> > threads;
     637        std::list<unsigned int> threads;
    638638        for (std::map<unsigned int, TclInterpreterBundle*>::const_iterator it = this->interpreterBundles_.begin(); it != this->interpreterBundles_.end(); ++it)
    639         {
    640             std::string number = getConvertedValue<unsigned int, std::string>((*it).first);
    641             threads.push_back(std::pair<std::string, std::string>(number, number));
    642         }
     639            threads.push_back((*it).first);
    643640        return threads;
    644641    }
  • code/branches/console/src/core/TclThreadManager.h

    r1434 r1441  
    109109            virtual void tick(float dt);
    110110
    111             std::list<std::pair<std::string, std::string> > getThreadList() const;
     111            std::list<unsigned int> getThreadList() const;
    112112
    113113        private:
Note: See TracChangeset for help on using the changeset viewer.