Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Completing works

File size: 4.3 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL
17
18#include "shell_completion_plugin.h"
19#include "shell_command_class.h"
20
21#include "shell_command.h"
22
23#include "substring.h"
24#include "class_list.h"
25#include "loading/resource_manager.h"
26
27#include "osdir.h"
28#include "debug.h"
29
30namespace OrxShell
31{
32  CompletorDefault::CompletorDefault(const MultiType* value)
33      :_value(value)
34  { }
35
36  void CompletorDefault::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
37  {
38    PRINT(0)("Requires '%s'\n", MultiType::MultiTypeToString(this->_value->getType()).c_str());
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  {
52    printf("TEST\n");
53    unsigned int inputLen = completionBegin.size();
54    for (unsigned int i = 0; i < this->_size; ++i)
55    {
56      printf("%s\n", this->_stringArray[i].c_str());
57      if (!nocaseCmp(this->_stringArray[i], completionBegin, inputLen))
58        completionList.push_back(this->_stringArray[i]);
59    }
60  }
61
62  CompletorPlugin* CompletorStringArray::clone() const
63  {
64    return new CompletorStringArray(this->_stringArray, this->_size);
65  }
66
67
68  CompletorList::CompletorList(const std::list<std::string>* list)
69  {
70    this->_list = list;
71  }
72
73  void CompletorList::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
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
82  CompletorPlugin* CompletorList::clone() const
83  {
84    return new CompletorList(this->_list);
85  }
86
87
88  CompletorFileSystem::CompletorFileSystem(const std::string& fileExtension,
89      const std::string& subDir)
90      : _fileExtension(fileExtension), _subDir(subDir)
91  {  }
92
93
94  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
95  {
96    OS::Directory dir;
97
98    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
99    {
100      dir.open(ResourceManager::getInstance()->getDataDir() + this->_subDir);
101      while(dir)
102      {
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        }
142      }
143    }
144  }
145
146  CompletorPlugin* CompletorFileSystem::clone() const
147  {
148    return new CompletorFileSystem(this->_fileExtension, this->_subDir);
149  }
150
151
152}
153
Note: See TracBrowser for help on using the repository browser.