Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/scriptchanges.new/src/lib/shell/shell_completion_plugin.cc @ 10514

Last change on this file since 10514 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
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 "helper_functions.h"
24#include "loading/resource_manager.h"
25
26#include "filesys/directory.h"
27#include "debug.h"
28
29namespace OrxShell
30{
31  CompletorDefault::CompletorDefault(const MultiType* value)
32      :_value(value)
33  { }
34
35  void CompletorDefault::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
36  {
37    PRINT(0)("Requires '%s'\n", MultiType::MultiTypeToString(this->_value->getType()).c_str());
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  {
51    printf("TEST\n");
52    unsigned int inputLen = completionBegin.size();
53    for (unsigned int i = 0; i < this->_size; ++i)
54    {
55      printf("%s\n", this->_stringArray[i].c_str());
56      if (!nocaseCmp(this->_stringArray[i], completionBegin, inputLen))
57        completionList.push_back(this->_stringArray[i]);
58    }
59  }
60
61  CompletorPlugin* CompletorStringArray::clone() const
62  {
63    return new CompletorStringArray(this->_stringArray, this->_size);
64  }
65
66
67  CompletorList::CompletorList(const std::list<std::string>* list)
68  {
69    this->_list = list;
70  }
71
72  void CompletorList::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
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
81  CompletorPlugin* CompletorList::clone() const
82  {
83    return new CompletorList(this->_list);
84  }
85
86
87  CompletorFileSystem::CompletorFileSystem(const std::string& fileExtension,
88      const std::string& subDir)
89      : _fileExtension(fileExtension), _subDir(subDir)
90  {  }
91
92
93  void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const
94  {
95    Directory dir;
96
97    if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir.
98    {
99      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + this->_subDir);
100      dir.open();
101      for(unsigned int i = 0; i < dir.fileCount(); i++ )
102      {
103        completionList.push_back(this->_subDir + "/" + dir[i]);
104      }
105    }
106    else
107    {
108      bool grabbedDir = false;
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);
113
114      dir.setFileName(Resources::ResourceManager::getInstance()->mainGlobalPath().name() + directoryName);
115      dir.open();
116
117      std::string fileName;
118      std::string currFile;
119      for(unsigned int i = 0; i < dir.fileCount(); i++)
120      {
121        currFile = dir[i];
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        }
137        printf("%s\n", (Resources::ResourceManager::getInstance()->mainGlobalPath().name() + fileName).c_str());
138        if (!nocaseCmp(completionBegin, fileName, completionBegin.size()) &&
139             Resources::ResourceManager::getInstance()->checkFileInMainPath(fileName))
140        {
141          printf("Dir %s\n", fileName.c_str());
142          grabbedDir = true;
143          completionList.push_back(fileName + "/");
144        }
145      }
146
147      if (completionList.size() == 1 && grabbedDir)
148      {
149        std::string dir = completionList[0];
150        completionList.clear();
151        this->addToCompleteList(completionList, dir);
152      }
153    }
154  }
155
156  CompletorPlugin* CompletorFileSystem::clone() const
157  {
158    return new CompletorFileSystem(this->_fileExtension, this->_subDir);
159  }
160
161
162}
163
Note: See TracBrowser for help on using the repository browser.