Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ppspickups1/src/libraries/core/ArgumentCompletionFunctions.cc @ 6681

Last change on this file since 6681 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
Line 
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
29#include "ArgumentCompletionFunctions.h"
30
31#include <map>
32#include <boost/version.hpp>
33#include <boost/filesystem.hpp>
34
35#include "util/Convert.h"
36#include "util/StringUtils.h"
37#include "Identifier.h"
38#include "ConfigFileManager.h"
39#include "ConfigValueContainer.h"
40#include "TclThreadManager.h"
41
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
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                }
72#ifdef ORXONOX_PLATFORM_WINDOWS
73                else
74                {
75                    const std::string& dir = startdirectory.string();
76                    if (dir.size() > 0 && dir[dir.size() - 1] == ':')
77                        startdirectory = dir + '/';
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))
87                        dirlist.push_back(ArgumentCompletionListElement(file->string() + '/', getLowercase(file->string()) + '/', file->BOOST_LEAF_FUNCTION() + '/'));
88                    else
89                        filelist.push_back(ArgumentCompletionListElement(file->string(), getLowercase(file->string()), file->BOOST_LEAF_FUNCTION()));
90                    ++file;
91                }
92            }
93            catch (...) {}
94
95            filelist.insert(filelist.begin(), dirlist.begin(), dirlist.end());
96            return filelist;
97        }
98
99        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingssections)()
100        {
101            ArgumentCompletionList sectionList;
102
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)));
106
107            return sectionList;
108        }
109
110        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsentries)(const std::string& fragment, const std::string& section)
111        {
112            ArgumentCompletionList entryList;
113            SettingsConfigFile& settings = SettingsConfigFile::getInstance();
114            const std::string& sectionLC = getLowercase(section);
115
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));
119
120            return entryList;
121        }
122
123        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(settingsvalue)(const std::string& fragment, const std::string& entry, const std::string& section)
124        {
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)
132            {
133                if (it->second.first == entryLC)
134                {
135                    const std::string& valuestring = it->second.second->toString();
136                    oldValue.push_back(ArgumentCompletionListElement(valuestring, getLowercase(valuestring), "Old value: " + valuestring));
137                }
138            }
139
140            return oldValue;
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)
149                threads.push_back(ArgumentCompletionListElement(multi_cast<std::string>(*it)));
150
151            return threads;
152        }
153    }
154}
Note: See TracBrowser for help on using the repository browser.