- Timestamp:
- Apr 28, 2006, 5:54:50 PM (19 years ago)
- Location:
- trunk/src/lib/shell
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/shell/shell_completion_plugin.cc
r7422 r7423 31 31 { 32 32 CompletorDefault::CompletorDefault(const MultiType* value) 33 :_value(value)33 :_value(value) 34 34 { } 35 35 … … 87 87 88 88 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) 92 91 { } 93 92 … … 95 94 void CompletorFileSystem::addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const 96 95 { 96 OS::Directory dir; 97 97 98 if (completionBegin.empty()) // if we do not yet have the beginning of the line, start with the chosen startDir. 98 99 { 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); 110 101 while(dir) 111 102 { 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 } 114 142 } 115 143 } 116 144 } 145 117 146 CompletorPlugin* CompletorFileSystem::clone() const 118 147 { 119 return new CompletorFileSystem(this->_fileExtension, this->_subDir , this->_startDir);148 return new CompletorFileSystem(this->_fileExtension, this->_subDir); 120 149 } 121 150 -
trunk/src/lib/shell/shell_completion_plugin.h
r7422 r7423 17 17 class CompletorPlugin 18 18 { 19 public:20 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const = 0;21 virtual ~CompletorPlugin() { };19 public: 20 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const = 0; 21 virtual ~CompletorPlugin() { }; 22 22 23 virtual CompletorPlugin* clone() const = 0;24 protected:25 CompletorPlugin() {};23 virtual CompletorPlugin* clone() const = 0; 24 protected: 25 CompletorPlugin() {}; 26 26 }; 27 27 28 28 class CompletorDefault : public CompletorPlugin 29 29 { 30 public:31 CompletorDefault(const MultiType* value);32 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;30 public: 31 CompletorDefault(const MultiType* value); 32 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; 33 33 34 virtual CompletorPlugin* clone() const;35 private:36 const MultiType* _value;34 virtual CompletorPlugin* clone() const; 35 private: 36 const MultiType* _value; 37 37 }; 38 38 … … 41 41 class CompletorStringArray : public CompletorPlugin 42 42 { 43 public:44 CompletorStringArray(const std::string* stringArray, unsigned int size)45 : _stringArray(stringArray), _size(size) {};46 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;43 public: 44 CompletorStringArray(const std::string* stringArray, unsigned int size) 45 : _stringArray(stringArray), _size(size) {}; 46 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; 47 47 48 virtual CompletorPlugin* clone() const;49 private:50 const std::string* _stringArray;51 unsigned int _size;48 virtual CompletorPlugin* clone() const; 49 private: 50 const std::string* _stringArray; 51 unsigned int _size; 52 52 }; 53 53 … … 55 55 class CompletorList : public CompletorPlugin 56 56 { 57 public:58 CompletorList(const std::list<std::string>* list);59 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const;60 virtual CompletorPlugin* clone() const;57 public: 58 CompletorList(const std::list<std::string>* list); 59 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; 60 virtual CompletorPlugin* clone() const; 61 61 62 private:63 const std::list<std::string>* _list;62 private: 63 const std::list<std::string>* _list; 64 64 }; 65 65 … … 69 69 class CompletorFileSystem : public CompletorPlugin 70 70 { 71 public: 72 // Where to search if the completionString is empty. 73 typedef enum 74 { 75 StartAtRoot, 76 StartAtHome, 77 StartAtDataDir, 78 } StartDirectory; 71 public: 72 CompletorFileSystem(const std::string& fileExtension = "", 73 const std::string& subDir = ""); 74 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; 75 virtual CompletorPlugin* clone() const; 79 76 80 CompletorFileSystem(const std::string& fileExtension = "", 81 const std::string& subDir = "", 82 StartDirectory startDir = StartAtDataDir); 83 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; 84 virtual CompletorPlugin* clone() const; 85 86 private: 87 std::string _fileExtension; 88 std::string _subDir; 89 StartDirectory _startDir; 77 private: 78 std::string _fileExtension; 79 std::string _subDir; 90 80 }; 91 81 … … 96 86 template<typename CLASS> class CompletorTList : public CompletorPlugin 97 87 { 98 public:99 CompletorTList(const std::list<CLASS*>& completionList);100 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin)101 {};102 virtual CompletorPlugin* clone() const;88 public: 89 CompletorTList(const std::list<CLASS*>& completionList); 90 virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) 91 {}; 92 virtual CompletorPlugin* clone() const; 103 93 }; 104 94
Note: See TracChangeset
for help on using the changeset viewer.