1 // Copyright (C) 2009-2015 Petr Pavlu <setup@dagobah.cz>
3 // This file is part of CenterIM.
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.
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/>.
19 /// KeyConfig singleton class.
21 /// @ingroup cppconsui
26 #include "CppConsUI.h"
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.
38 /// The use case for a class X derived from @ref InputProcessor class is the
41 /// class X : public Y {
43 /// void declareBindables();
46 /// void X::declareBindable()
48 /// // Register a bindable.
49 /// declareBindable("context", "action", sigc::mem_fun(this, X::onActionDo));
51 /// // Register a bindable conditionally.
52 /// if (some condition)
53 /// declareBindable("context", "action2", sigc::mem_fun(this,
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.
87 /// Loads default key configuration.
88 void loadDefaultKeyConfig();
91 /// Current key binds.
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: