Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

orxonox/trunk: Completing works

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.