Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell_completion_plugin.cc @ 10555

Last change on this file since 10555 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 4.7 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[5254]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[7374]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL
[1853]17
[7374]18#include "shell_completion_plugin.h"
[5639]19#include "shell_command_class.h"
[1853]20
[5194]21#include "shell_command.h"
[5181]22
[9869]23#include "helper_functions.h"
[7422]24#include "loading/resource_manager.h"
25
[8330]26#include "filesys/directory.h"
[5178]27#include "debug.h"
28
[7374]29namespace OrxShell
[5178]30{
[7407]31  CompletorDefault::CompletorDefault(const MultiType* value)
[7423]32      :_value(value)
[7407]33  { }
34
35  void CompletorDefault::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
[5184]36  {
[7409]37    PRINT(0)("Requires '%s'\n", MultiType::MultiTypeToString(this->_value->getType()).c_str());
[7407]38  }
39
40  CompletorPlugin* CompletorDefault::clone() const
41  {
42    return new CompletorDefault(this->_value);
43  }
44
45
46
47
48
49  void CompletorStringArray::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
50  {
[7412]51    printf("TEST\n");
[7374]52    unsigned int inputLen = completionBegin.size();
53    for (unsigned int i = 0; i < this->_size; ++i)
[7412]54    {
55      printf("%s\n", this->_stringArray[i].c_str());
[7374]56      if (!nocaseCmp(this->_stringArray[i], completionBegin, inputLen))
57        completionList.push_back(this->_stringArray[i]);
[7412]58    }
[5184]59  }
60
[7407]61  CompletorPlugin* CompletorStringArray::clone() const
62  {
63    return new CompletorStringArray(this->_stringArray, this->_size);
64  }
[7387]65
66
67  CompletorList::CompletorList(const std::list<std::string>* list)
68  {
69    this->_list = list;
70  }
71
[7407]72  void CompletorList::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
[7387]73  {
74    unsigned int inputLen = completionBegin.size();
75    std::list<std::string>::const_iterator it;
76    for (it = this->_list->begin(); it != this->_list->end(); ++it)
77      if (!nocaseCmp((*it), completionBegin, inputLen))
78        completionList.push_back(*it);
79  }
80
[7407]81  CompletorPlugin* CompletorList::clone() const
82  {
83    return new CompletorList(this->_list);
84  }
[7387]85
86
[7377]87  CompletorFileSystem::CompletorFileSystem(const std::string& fileExtension,
[7423]88      const std::string& subDir)
89      : _fileExtension(fileExtension), _subDir(subDir)
[7377]90  {  }
91
[7387]92
[7407]93  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
[7377]94  {
[7661]95    Directory dir;
[7423]96
[7377]97    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
98    {
[9869]99      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + this->_subDir);
[7661]100      dir.open();
[8276]101      for(unsigned int i = 0; i < dir.fileCount(); i++ )
[7422]102      {
[8276]103        completionList.push_back(this->_subDir + "/" + dir[i]);
[7422]104      }
[7423]105    }
106    else
107    {
[7424]108      bool grabbedDir = false;
[7423]109      std::string directoryName;
110      std::string::size_type pos = completionBegin.find_last_of("/");
111      if (pos != std::string::npos)
112        directoryName = completionBegin.substr(0, pos);
[7377]113
[9869]114      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + directoryName);
[7661]115      dir.open();
[7377]116
[7423]117      std::string fileName;
118      std::string currFile;
[8276]119      for(unsigned int i = 0; i < dir.fileCount(); i++)
[7422]120      {
[8276]121        currFile = dir[i];
[7423]122        if (currFile[0] == '.')
123         continue;
124
125        if (directoryName.empty())
126          fileName = currFile;
127        else
128          fileName = directoryName + '/' + currFile;
129
130        if (!nocaseCmp(completionBegin, fileName, completionBegin.size())  &&
131             (this->_fileExtension.empty() || fileName.find(this->_fileExtension) != std::string::npos))
132        {
133          printf ("File %s\n", fileName.c_str());
134          completionList.push_back(fileName);
135          continue;
136        }
[9869]137        printf("%s\n", (Resources::ResourceManager::getInstance()->mainGlobalPath().name() + fileName).c_str());
[7423]138        if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) &&
[9869]139             Resources::ResourceManager::getInstance()->checkFileInMainPath(fileName))
[7423]140        {
141          printf("Dir %s\n", fileName.c_str());
[7424]142          grabbedDir = true;
[7423]143          completionList.push_back(fileName + "/");
144        }
[7422]145      }
[7424]146
147      if (completionList.size() == 1 && grabbedDir)
148      {
149        std::string dir = completionList[0];
150        completionList.clear();
151        this->addToCompleteList(completionList, dir);
152      }
[7377]153    }
154  }
[7423]155
[7407]156  CompletorPlugin* CompletorFileSystem::clone() const
157  {
[7423]158    return new CompletorFileSystem(this->_fileExtension, this->_subDir);
[7407]159  }
[7377]160
[7407]161
[7377]162}
163
Note: See TracBrowser for help on using the repository browser.