Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc @ 6950

Last change on this file since 6950 was 6536, checked in by rgrieder, 15 years ago

Merged revisions 6430-6440 from the gamestate branch to the trunk.
This adds keybindings merging functionality.

(from log of r6437)
When running development builds, the keybinder will merge the local file and the one from the data folder.
Catch: if you want to remove a binding, you'll have to write "NoBinding" (not case sensitive) to override the default command

The keybind command already does that for you though.

  • Property svn:eol-style set to native
File size: 5.8 KB
RevLine 
[1505]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
[2710]29#include "ArgumentCompletionFunctions.h"
30
[1505]31#include <map>
[2728]32#include <boost/version.hpp>
[2087]33#include <boost/filesystem.hpp>
[1505]34
[3196]35#include "util/Convert.h"
[3280]36#include "util/StringUtils.h"
[1505]37#include "Identifier.h"
[6536]38#include "ConfigFileManager.h"
[1505]39#include "ConfigValueContainer.h"
40#include "TclThreadManager.h"
41
[2728]42// Boost 1.36 has some issues with deprecated functions that have been omitted
43#if (BOOST_VERSION == 103600)
44#  define BOOST_LEAF_FUNCTION filename
45#else
46#  define BOOST_LEAF_FUNCTION leaf
47#endif
48
[1505]49namespace orxonox
50{
51    namespace autocompletion
52    {
53        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)()
54        {
55            return ArgumentCompletionList();
56        }
57
58        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(files)(const std::string& fragment)
59        {
60            ArgumentCompletionList dirlist;
61            ArgumentCompletionList filelist;
62
63            try
64            {
65                boost::filesystem::path input(fragment);
66                boost::filesystem::path startdirectory(input.branch_path());
67
68                if (!boost::filesystem::exists(startdirectory))
69                {
70                    startdirectory = ".";
71                }
[2710]72#ifdef ORXONOX_PLATFORM_WINDOWS
[1505]73                else
74                {
[6417]75                    const std::string& dir = startdirectory.string();
[1505]76                    if (dir.size() > 0 && dir[dir.size() - 1] == ':')
[2759]77                        startdirectory = dir + '/';
[1505]78                }
79#endif
80
81                boost::filesystem::directory_iterator file(startdirectory);
82                boost::filesystem::directory_iterator end;
83
84                while (file != end)
85                {
86                    if (boost::filesystem::is_directory(*file))
[6417]87                        dirlist.push_back(ArgumentCompletionListElement(file->string() + '/', getLowercase(file->string()) + '/', file->BOOST_LEAF_FUNCTION() + '/'));
[1505]88                    else
[6417]89                        filelist.push_back(ArgumentCompletionListElement(file->string(), getLowercase(file->string()), file->BOOST_LEAF_FUNCTION()));
[1505]90                    ++file;
91                }
92            }
93            catch (...) {}
94
95            filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end());
96            return filelist;
97        }
98
[6536]99        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)()
[1505]100        {
[6536]101            ArgumentCompletionList sectionList;
[1505]102
[6536]103            const std::set<std::string>& names = SettingsConfigFile::getInstance().getSectionNames();
104            for (std::set<std::string>::const_iterator it = names.begin(); it != names.end(); ++it)
105                sectionList.push_back(ArgumentCompletionListElement(*it, getLowercase(*it)));
[1505]106
[6536]107            return sectionList;
[1505]108        }
109
[6536]110        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section)
[1505]111        {
[6536]112            ArgumentCompletionList entryList;
113            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
114            const std::string& sectionLC = getLowercase(section);
[1505]115
[6536]116            SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
117            for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
118                entryList.push_back(ArgumentCompletionListElement(it->second.second->getName(), it->second.first));
[1505]119
[6536]120            return entryList;
[1505]121        }
122
[6536]123        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section)
[1505]124        {
[6536]125            ArgumentCompletionList oldValue;
126            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
127            const std::string& sectionLC = getLowercase(section);
128            const std::string& entryLC = getLowercase(entry);
129
130            SettingsConfigFile::ContainerMap::const_iterator upper = settings.getContainerUpperBound(sectionLC);
131            for (SettingsConfigFile::ContainerMap::const_iterator it = settings.getContainerLowerBound(sectionLC); it != upper; ++it)
[1505]132            {
[6536]133                if (it->second.first == entryLC)
[1505]134                {
[6536]135                    const std::string& valuestring = it->second.second->toString();
136                    oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
[1505]137                }
138            }
[6536]139
140            return oldValue;
[1505]141        }
142
143        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(tclthreads)()
144        {
145            std::list<unsigned int> threadnumbers = TclThreadManager::getInstance().getThreadList();
146            ArgumentCompletionList threads;
147
148            for (std::list<unsigned int>::const_iterator it = threadnumbers.begin(); it != threadnumbers.end(); ++it)
[3280]149                threads.push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it)));
[1505]150
151            return threads;
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.