Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7423 in orxonox.OLD for trunk


Ignore:
Timestamp:
Apr 28, 2006, 5:54:50 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: Completing works

Location:
trunk/src/lib/shell
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/shell/shell_completion_plugin.cc

    r7422 r7423  
    3131{
    3232  CompletorDefault::CompletorDefault(const MultiType* value)
    33   :_value(value)
     33      :_value(value)
    3434  { }
    3535
     
    8787
    8888  CompletorFileSystem::CompletorFileSystem(const std::string& fileExtension,
    89                                            const std::string& subDir,
    90                                            StartDirectory startDir)
    91   : _fileExtension(fileExtension), _startDir(startDir), _subDir(subDir)
     89      const std::string& subDir)
     90      : _fileExtension(fileExtension), _subDir(subDir)
    9291  {  }
    9392
     
    9594  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
    9695  {
     96    OS::Directory dir;
     97
    9798    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
    9899    {
    99       OS::Directory dir;
    100       if (this->_startDir == StartAtDataDir)
    101       {
    102         dir.open(ResourceManager::getInstance()->getDataDir());
    103       }
    104 
    105       else if(this->_startDir == StartAtRoot)
    106         dir.open("/");
    107       else
    108         dir.open(ResourceManager::homeDirCheck("~/"));
    109 
     100      dir.open(ResourceManager::getInstance()->getDataDir() + this->_subDir);
    110101      while(dir)
    111102      {
    112         printf("%s\n", "one\n");
    113         completionList.push_back(dir.next());
     103        completionList.push_back(this->_subDir + "/" + dir.next());
     104      }
     105    }
     106    else
     107    {
     108      std::string directoryName;
     109      std::string::size_type pos = completionBegin.find_last_of("/");
     110      if (pos != std::string::npos)
     111        directoryName = completionBegin.substr(0, pos);
     112
     113      dir.open(ResourceManager::getInstance()->getDataDir() + directoryName);
     114
     115      std::string fileName;
     116      std::string currFile;
     117      while(dir)
     118      {
     119        currFile = dir.next();
     120        if (currFile[0] == '.')
     121         continue;
     122
     123        if (directoryName.empty())
     124          fileName = currFile;
     125        else
     126          fileName = directoryName + '/' + currFile;
     127
     128        if (!nocaseCmp(completionBegin, fileName, completionBegin.size())  &&
     129             (this->_fileExtension.empty() || fileName.find(this->_fileExtension) != std::string::npos))
     130        {
     131          printf ("File %s\n", fileName.c_str());
     132          completionList.push_back(fileName);
     133          continue;
     134        }
     135        printf("%s\n", (ResourceManager::getInstance()->getDataDir() + fileName).c_str());
     136        if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) &&
     137             ResourceManager::isDir(ResourceManager::getInstance()->getDataDir() + fileName))
     138        {
     139          printf("Dir %s\n", fileName.c_str());
     140          completionList.push_back(fileName + "/");
     141        }
    114142      }
    115143    }
    116144  }
     145
    117146  CompletorPlugin* CompletorFileSystem::clone() const
    118147  {
    119     return new CompletorFileSystem(this->_fileExtension, this->_subDir, this->_startDir);
     148    return new CompletorFileSystem(this->_fileExtension, this->_subDir);
    120149  }
    121150
  • trunk/src/lib/shell/shell_completion_plugin.h

    r7422 r7423  
    1717  class CompletorPlugin
    1818  {
    19   public:
    20     virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const = 0;
    21     virtual ~CompletorPlugin() { };
     19    public:
     20      virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const = 0;
     21      virtual ~CompletorPlugin() { };
    2222
    23     virtual CompletorPlugin* clone() const = 0;
    24   protected:
    25     CompletorPlugin() {};
     23      virtual CompletorPlugin* clone() const = 0;
     24    protected:
     25      CompletorPlugin() {};
    2626  };
    2727
    2828  class CompletorDefault : public CompletorPlugin
    2929  {
    30   public:
    31     CompletorDefault(const MultiType* value);
    32     virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     30    public:
     31      CompletorDefault(const MultiType* value);
     32      virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
    3333
    34     virtual CompletorPlugin* clone() const;
    35   private:
    36     const MultiType*    _value;
     34      virtual CompletorPlugin* clone() const;
     35    private:
     36      const MultiType*    _value;
    3737  };
    3838
     
    4141  class CompletorStringArray : public CompletorPlugin
    4242  {
    43   public:
    44     CompletorStringArray(const std::string* stringArray, unsigned int size)
    45         : _stringArray(stringArray), _size(size) {};
    46     virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     43    public:
     44      CompletorStringArray(const std::string* stringArray, unsigned int size)
     45          : _stringArray(stringArray), _size(size) {};
     46      virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
    4747
    48     virtual CompletorPlugin* clone() const;
    49   private:
    50     const std::string*   _stringArray;
    51     unsigned int         _size;
     48      virtual CompletorPlugin* clone() const;
     49    private:
     50      const std::string*   _stringArray;
     51      unsigned int         _size;
    5252  };
    5353
     
    5555  class CompletorList : public CompletorPlugin
    5656  {
    57   public:
    58     CompletorList(const std::list<std::string>* list);
    59     virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
    60     virtual CompletorPlugin* clone() const;
     57    public:
     58      CompletorList(const std::list<std::string>* list);
     59      virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     60      virtual CompletorPlugin* clone() const;
    6161
    62   private:
    63     const std::list<std::string>* _list;
     62    private:
     63      const std::list<std::string>* _list;
    6464  };
    6565
     
    6969  class CompletorFileSystem : public CompletorPlugin
    7070  {
    71   public:
    72     // Where to search if the completionString is empty.
    73     typedef enum
    74     {
    75       StartAtRoot,
    76       StartAtHome,
    77       StartAtDataDir,
    78     } StartDirectory;
     71    public:
     72      CompletorFileSystem(const std::string& fileExtension = "",
     73                          const std::string& subDir = "");
     74      virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
     75      virtual CompletorPlugin* clone() const;
    7976
    80     CompletorFileSystem(const std::string& fileExtension = "",
    81                         const std::string& subDir = "",
    82                         StartDirectory startDir = StartAtDataDir);
    83     virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;
    84     virtual CompletorPlugin* clone() const;
    85 
    86   private:
    87     std::string             _fileExtension;
    88     std::string             _subDir;
    89     StartDirectory          _startDir;
     77    private:
     78      std::string             _fileExtension;
     79      std::string             _subDir;
    9080  };
    9181
     
    9686  template<typename CLASS> class CompletorTList : public CompletorPlugin
    9787  {
    98   public:
    99     CompletorTList(const std::list<CLASS*>& completionList);
    100     virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
    101     {};
    102     virtual CompletorPlugin* clone() const;
     88    public:
     89      CompletorTList(const std::list<CLASS*>& completionList);
     90      virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)
     91      {};
     92      virtual CompletorPlugin* clone() const;
    10393  };
    10494
Note: See TracChangeset for help on using the changeset viewer.