Update list of wide characters
[centerim5.git] / cppconsui / KeyConfig.h
blob34c69e382a367159dcff0c50bcefdf09c3f66dbc
1 // Copyright (C) 2009-2015 Petr Pavlu <setup@dagobah.cz>
2 //
3 // This file is part of CenterIM.
4 //
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
18 /// @file
19 /// KeyConfig singleton class.
20 ///
21 /// @ingroup cppconsui
23 #ifndef KEYCONFIG_H
24 #define KEYCONFIG_H
26 #include "CppConsUI.h"
27 #include "Keys.h"
29 #include <map>
30 #include <string>
31 #include <termkey.h>
33 namespace CppConsUI {
35 /// This singleton class is used to keep the key definitions. It holds the
36 /// context, action, description, the default and the configured key values.
37 ///
38 /// The use case for a class X derived from @ref InputProcessor class is the
39 /// following:
40 /// \code
41 /// class X : public Y {
42 /// private:
43 /// void declareBindables();
44 /// };
45 ///
46 /// void X::declareBindable()
47 /// {
48 /// // Register a bindable.
49 /// declareBindable("context", "action", sigc::mem_fun(this, X::onActionDo));
50 ///
51 /// // Register a bindable conditionally.
52 /// if (some condition)
53 /// declareBindable("context", "action2", sigc::mem_fun(this,
54 /// X::onAction2Do));
55 /// }
56 /// \endcode
57 class KeyConfig {
58 public:
59 /// Maps keys to actions for one context, {key: action}.
60 typedef std::map<TermKeyKey, std::string, Keys::TermKeyCmp> KeyBindContext;
62 /// Maps context to key binds in that context, {context: KeyContext}.
63 typedef std::map<std::string, KeyBindContext> KeyBinds;
65 /// Binds a key to an action (in a given context).
66 bool bindKey(const char *context, const char *action, const char *key);
68 /// Returns all key binds.
69 const KeyBinds *getKeyBinds() const { return &binds_; }
71 /// Returns all key binds for a given context.
72 const KeyBindContext *getKeyBinds(const char *context) const;
74 /// Returns a key bind for a given context and action. Note that this method
75 /// returns a pointer to a static buffer.
76 const char *getKeyBind(const char *context, const char *action) const;
78 /// Converts a TermKeyKey to its string representation.
79 char *termKeyToString(const TermKeyKey &key) const;
81 /// Parses a string into a TermKeyKey.
82 bool stringToTermKey(const char *key, TermKeyKey *termkey) const;
84 /// Removes all key binds.
85 void clear();
87 /// Loads default key configuration.
88 void loadDefaultKeyConfig();
90 private:
91 /// Current key binds.
92 KeyBinds binds_;
94 KeyConfig() {}
95 ~KeyConfig() {}
96 CONSUI_DISABLE_COPY(KeyConfig);
98 friend void initializeConsUI(AppInterface &interface);
99 friend void finalizeConsUI();
102 } // namespace CppConsUI
104 #endif // KEYCONFIG_H
106 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: