Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1436


Ignore:
Timestamp:
May 27, 2008, 3:01:49 AM (16 years ago)
Author:
landauf
Message:

cool stuff: autocompletion works with filesystem (has to be tested on other systems)

Location:
code/branches/console/src/core
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/ArgumentCompleter.h

    r1430 r1436  
    6464                        return (*this->function_5_)(param1, param2, param3, param4, param5);
    6565                    default:
    66                         return (*this->function_0_)();
     66                        return std::list<std::pair<std::string, std::string> >();
    6767                }
    6868            }
  • code/branches/console/src/core/ArgumentCompletionFunctions.cc

    r1434 r1436  
    3030#include <map>
    3131
     32//#include <stdio.h>
     33//#include <stdlib.h>
     34//#include <errno.h>
     35//#include <sys/types.h>
     36//#include <sys/stat.h>
     37#include <dirent.h>
     38
    3239#include "ArgumentCompletionFunctions.h"
    3340#include "CoreIncludes.h"
     
    3643#include "TclThreadManager.h"
    3744#include "util/String.h"
     45#include "util/SubString.h"
    3846
    3947namespace orxonox
     
    4452        {
    4553            return std::list<std::pair<std::string, std::string> >();
     54        }
     55
     56        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment)
     57        {
     58            std::list<std::pair<std::string, std::string> > dirlist;
     59            std::list<std::pair<std::string, std::string> > filelist;
     60
     61            SubString tokens(fragment, "/", "", false, '\0', false, '\0', false, '\0', '\0', false, '\0');
     62
     63            std::string startdirectory = ".";
     64            if (fragment.size() > 0 && fragment[fragment.size() - 1] == '/' && tokens.size() > 0)
     65                startdirectory = tokens.subSet(0, tokens.size()).join("/");
     66            else if (tokens.size() > 1)
     67                startdirectory = tokens.subSet(0, tokens.size() - 1).join("/");
     68
     69std::cout << "startdir: " << startdirectory << std::endl;
     70
     71            struct stat fileInfo;
     72            struct dirent *currentFile;
     73            DIR *handler = 0;
     74
     75            handler = opendir(startdirectory.c_str());
     76            if (handler)
     77            {
     78                while ((currentFile = readdir(handler)) != 0)
     79                {
     80                    if (strcmp(currentFile->d_name, ".") && strcmp(currentFile->d_name, ".."))
     81                    {
     82                        std::string path = startdirectory + "/" + currentFile->d_name;
     83                        if (stat(path.c_str(), &fileInfo) == -1)
     84                        {
     85                            closedir(handler);
     86                            break;
     87                        }
     88
     89                        if (S_ISREG(fileInfo.st_mode)) // normal file
     90                            filelist.push_back(std::pair<std::string, std::string>(getLowercase(path), path));
     91                        else if (S_ISDIR(fileInfo.st_mode)) // directory
     92                            dirlist.push_back(std::pair<std::string, std::string>(getLowercase(path) + "/", path + "/"));
     93                        else // special file
     94                            filelist.push_back(std::pair<std::string, std::string>(getLowercase(path), path));
     95                    }
     96                }
     97
     98                closedir(handler);
     99            }
     100
     101            filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end());
     102            return filelist;
    46103        }
    47104
     
    57114        }
    58115
    59         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& classname)
     116        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalues)(const std::string& fragment, const std::string& classname)
    60117        {
    61118            std::list<std::pair<std::string, std::string> > configvalues;
     
    71128        }
    72129
    73         ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& varname, const std::string& classname)
     130        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname)
    74131        {
    75132            std::list<std::pair<std::string, std::string> > oldvalue;
  • code/branches/console/src/core/ArgumentCompletionFunctions.h

    r1434 r1436  
    5656    {
    5757        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
     58        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(files)(const std::string& fragment);
    5859        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalueclasses)();
    59         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalues)(const std::string& classname);
    60         ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalue)(const std::string& varname, const std::string& classname);
     60        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalues)(const std::string& fragment, const std::string& classname);
     61        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(configvalue)(const std::string& fragment, const std::string& varname, const std::string& classname);
    6162        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(tclthreads)();
    6263    }
  • code/branches/console/src/core/CommandExecutor.cc

    r1435 r1436  
    557557        unsigned int lowestIndex = 1 + (CommandExecutor::getEvaluation().functionclass_ != 0);
    558558
    559         for (unsigned int i = CommandExecutor::argumentsGiven() - 2; i >= lowestIndex; --i)
     559        for (unsigned int i = CommandExecutor::argumentsGiven() - 1; i >= lowestIndex; --i)
    560560        {
    561561            params[index] = CommandExecutor::getArgument(i);
  • code/branches/console/src/core/ConfigFileManager.cc

    r1435 r1436  
    4242    SetConsoleCommandShortcutExtern(reloadConfig);
    4343    SetConsoleCommandShortcutExtern(cleanConfig);
    44     SetConsoleCommandShortcutExtern(loadSettings);
    45     SetConsoleCommandShortcutExtern(loadKeybindings);
     44    SetConsoleCommandShortcutExtern(loadSettings).setArgumentCompleter(0, autocompletion::files());
     45    SetConsoleCommandShortcutExtern(loadKeybindings).setArgumentCompleter(0, autocompletion::files());
    4646
    4747    bool config(const std::string& classname, const std::string& varname, const std::string& value)
  • code/branches/console/src/core/ConsoleCommandCompilation.cc

    r1341 r1436  
    3434namespace orxonox
    3535{
    36     SetConsoleCommandShortcutExtern(source);
     36    SetConsoleCommandShortcutExtern(source).setArgumentCompleter(0, autocompletion::files());
    3737    SetConsoleCommandShortcutExtern(echo);
    3838    SetConsoleCommandShortcutExtern(puts);
    3939
    40     SetConsoleCommandShortcutExtern(read);
    41     SetConsoleCommandShortcutExtern(append);
    42     SetConsoleCommandShortcutExtern(write);
     40    SetConsoleCommandShortcutExtern(read).setArgumentCompleter(0, autocompletion::files());
     41    SetConsoleCommandShortcutExtern(append).setArgumentCompleter(0, autocompletion::files());
     42    SetConsoleCommandShortcutExtern(write).setArgumentCompleter(0, autocompletion::files());
    4343
    4444    SetConsoleCommandShortcutExtern(calculate);
Note: See TracChangeset for help on using the changeset viewer.