Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7895 was 7661, checked in by bensch, 19 years ago

orxonox/trunk: merged the QT_GUI back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/qt_gui . -r7607:HEAD

absolutely no conflicts :)

File size: 4.6 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
[5183]23#include "substring.h"
[5178]24#include "class_list.h"
[7422]25#include "loading/resource_manager.h"
26
[7661]27#include "directory.h"
[5178]28#include "debug.h"
29
[7374]30namespace OrxShell
[5178]31{
[7407]32  CompletorDefault::CompletorDefault(const MultiType* value)
[7423]33      :_value(value)
[7407]34  { }
35
36  void CompletorDefault::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
[5184]37  {
[7409]38    PRINT(0)("Requires '%s'\n", MultiType::MultiTypeToString(this->_value->getType()).c_str());
[7407]39  }
40
41  CompletorPlugin* CompletorDefault::clone() const
42  {
43    return new CompletorDefault(this->_value);
44  }
45
46
47
48
49
50  void CompletorStringArray::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
51  {
[7412]52    printf("TEST\n");
[7374]53    unsigned int inputLen = completionBegin.size();
54    for (unsigned int i = 0; i < this->_size; ++i)
[7412]55    {
56      printf("%s\n", this->_stringArray[i].c_str());
[7374]57      if (!nocaseCmp(this->_stringArray[i], completionBegin, inputLen))
58        completionList.push_back(this->_stringArray[i]);
[7412]59    }
[5184]60  }
61
[7407]62  CompletorPlugin* CompletorStringArray::clone() const
63  {
64    return new CompletorStringArray(this->_stringArray, this->_size);
65  }
[7387]66
67
68  CompletorList::CompletorList(const std::list<std::string>* list)
69  {
70    this->_list = list;
71  }
72
[7407]73  void CompletorList::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
[7387]74  {
75    unsigned int inputLen = completionBegin.size();
76    std::list<std::string>::const_iterator it;
77    for (it = this->_list->begin(); it != this->_list->end(); ++it)
78      if (!nocaseCmp((*it), completionBegin, inputLen))
79        completionList.push_back(*it);
80  }
81
[7407]82  CompletorPlugin* CompletorList::clone() const
83  {
84    return new CompletorList(this->_list);
85  }
[7387]86
87
[7377]88  CompletorFileSystem::CompletorFileSystem(const std::string& fileExtension,
[7423]89      const std::string& subDir)
90      : _fileExtension(fileExtension), _subDir(subDir)
[7377]91  {  }
92
[7387]93
[7407]94  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
[7377]95  {
[7661]96    Directory dir;
[7423]97
[7377]98    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
99    {
[7661]100      dir.setFileName(ResourceManager::getInstance()->getDataDir() + this->_subDir);
101      dir.open();
[7423]102      while(dir)
[7422]103      {
[7423]104        completionList.push_back(this->_subDir + "/" + dir.next());
[7422]105      }
[7423]106    }
107    else
108    {
[7424]109      bool grabbedDir = false;
[7423]110      std::string directoryName;
111      std::string::size_type pos = completionBegin.find_last_of("/");
112      if (pos != std::string::npos)
113        directoryName = completionBegin.substr(0, pos);
[7377]114
[7661]115      dir.setFileName(ResourceManager::getInstance()->getDataDir() + directoryName);
116      dir.open();
[7377]117
[7423]118      std::string fileName;
119      std::string currFile;
[7422]120      while(dir)
121      {
[7423]122        currFile = dir.next();
123        if (currFile[0] == '.')
124         continue;
125
126        if (directoryName.empty())
127          fileName = currFile;
128        else
129          fileName = directoryName + '/' + currFile;
130
131        if (!nocaseCmp(completionBegin, fileName, completionBegin.size())  &&
132             (this->_fileExtension.empty() || fileName.find(this->_fileExtension) != std::string::npos))
133        {
134          printf ("File %s\n", fileName.c_str());
135          completionList.push_back(fileName);
136          continue;
137        }
138        printf("%s\n", (ResourceManager::getInstance()->getDataDir() + fileName).c_str());
139        if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) &&
[7661]140             ResourceManager::isInDataDir(fileName))
[7423]141        {
142          printf("Dir %s\n", fileName.c_str());
[7424]143          grabbedDir = true;
[7423]144          completionList.push_back(fileName + "/");
145        }
[7422]146      }
[7424]147
148      if (completionList.size() == 1 && grabbedDir)
149      {
150        std::string dir = completionList[0];
151        completionList.clear();
152        this->addToCompleteList(completionList, dir);
153      }
[7377]154    }
155  }
[7423]156
[7407]157  CompletorPlugin* CompletorFileSystem::clone() const
158  {
[7423]159    return new CompletorFileSystem(this->_fileExtension, this->_subDir);
[7407]160  }
[7377]161
[7407]162
[7377]163}
164
Note: See TracBrowser for help on using the repository browser.