rename keys.{cpp,h} to bindings.{cpp,h}
This commit is contained in:
@@ -5,6 +5,7 @@ ncmpcpp_SOURCES = \
|
||||
utility/string.cpp \
|
||||
utility/type_conversions.cpp \
|
||||
actions.cpp \
|
||||
bindings.cpp \
|
||||
browser.cpp \
|
||||
charset.cpp \
|
||||
clock.cpp \
|
||||
@@ -14,7 +15,6 @@ ncmpcpp_SOURCES = \
|
||||
global.cpp \
|
||||
help.cpp \
|
||||
helpers.cpp \
|
||||
keys.cpp \
|
||||
lastfm.cpp \
|
||||
lastfm_service.cpp \
|
||||
lyrics.cpp \
|
||||
@@ -52,6 +52,7 @@ noinst_HEADERS = \
|
||||
utility/string.h \
|
||||
utility/numeric_conversions.h \
|
||||
utility/type_conversions.h \
|
||||
bindings.h \
|
||||
browser.h \
|
||||
charset.h \
|
||||
clock.h \
|
||||
@@ -62,7 +63,6 @@ noinst_HEADERS = \
|
||||
help.h \
|
||||
helpers.h \
|
||||
interfaces.h \
|
||||
keys.h \
|
||||
lastfm.h \
|
||||
lastfm_service.h \
|
||||
lyrics.h \
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
#include "helpers.h"
|
||||
#include "utility/comparators.h"
|
||||
|
||||
#include "bindings.h"
|
||||
#include "browser.h"
|
||||
#include "clock.h"
|
||||
#include "help.h"
|
||||
#include "keys.h"
|
||||
#include "media_library.h"
|
||||
#include "lastfm.h"
|
||||
#include "lyrics.h"
|
||||
@@ -249,7 +249,7 @@ void Action::Seek()
|
||||
int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time;
|
||||
|
||||
Key input = Key::read(*wFooter);
|
||||
auto k = Keys.Bindings.equal_range(input);
|
||||
auto k = Bindings.get(input);
|
||||
if (k.first == k.second || !k.first->second.isSingle()) // no single action?
|
||||
break;
|
||||
Action *a = k.first->second.action();
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "global.h"
|
||||
#include "keys.h"
|
||||
#include "bindings.h"
|
||||
#include "utility/string.h"
|
||||
|
||||
KeyConfiguration Keys;
|
||||
BindingsConfiguration Bindings;
|
||||
|
||||
Key Key::noOp = Key(ERR, NCurses);
|
||||
|
||||
@@ -174,7 +174,7 @@ Key Key::read(NC::Window &w)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KeyConfiguration::read(const std::string &file)
|
||||
bool BindingsConfiguration::read(const std::string &file)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
@@ -250,7 +250,7 @@ bool KeyConfiguration::read(const std::string &file)
|
||||
return result;
|
||||
}
|
||||
|
||||
void KeyConfiguration::generateBindings()
|
||||
void BindingsConfiguration::generateDefault()
|
||||
{
|
||||
Key k = Key::noOp;
|
||||
if (notBound(k = stringToKey("mouse")))
|
||||
@@ -18,8 +18,8 @@
|
||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _KEYS_H
|
||||
#define _KEYS_H
|
||||
#ifndef _BINDINGS_H
|
||||
#define _BINDINGS_H
|
||||
|
||||
#include <cassert>
|
||||
#include "actions.h"
|
||||
@@ -105,24 +105,35 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
/// Key configuration
|
||||
struct KeyConfiguration
|
||||
/// Keybindings configuration
|
||||
struct BindingsConfiguration
|
||||
{
|
||||
bool read(const std::string &file);
|
||||
void generateBindings();
|
||||
typedef std::multimap<Key, Binding> BindingsMap;
|
||||
typedef BindingsMap::iterator BindingIterator;
|
||||
typedef BindingsMap::const_iterator ConstBindingIterator;
|
||||
|
||||
std::multimap<Key, Binding> Bindings;
|
||||
bool read(const std::string &file);
|
||||
void generateDefault();
|
||||
|
||||
std::pair<BindingIterator, BindingIterator> get(const Key &k) {
|
||||
return m_bindings.equal_range(k);
|
||||
}
|
||||
|
||||
ConstBindingIterator begin() const { return m_bindings.begin(); }
|
||||
ConstBindingIterator end() const { return m_bindings.end(); }
|
||||
|
||||
private:
|
||||
bool notBound(const Key &k) const {
|
||||
return k != Key::noOp && Bindings.find(k) == Bindings.end();
|
||||
return k != Key::noOp && m_bindings.find(k) == m_bindings.end();
|
||||
}
|
||||
|
||||
template <typename T> void bind(Key k, T t) {
|
||||
Bindings.insert(std::make_pair(k, Binding(t)));
|
||||
m_bindings.insert(std::make_pair(k, Binding(t)));
|
||||
}
|
||||
|
||||
BindingsMap m_bindings;
|
||||
};
|
||||
|
||||
extern KeyConfiguration Keys;
|
||||
extern BindingsConfiguration Bindings;
|
||||
|
||||
#endif // _KEYS_H
|
||||
#endif // _BINDINGS_H
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
#include "mpdpp.h"
|
||||
|
||||
#include "bindings.h"
|
||||
#include "global.h"
|
||||
#include "help.h"
|
||||
#include "keys.h"
|
||||
#include "settings.h"
|
||||
|
||||
using Global::MainHeight;
|
||||
@@ -142,7 +142,7 @@ std::string Help::DisplayKeys(const ActionType at)
|
||||
{
|
||||
bool print_backspace = true;
|
||||
std::string result;
|
||||
for (auto it = Keys.Bindings.begin(); it != Keys.Bindings.end(); ++it)
|
||||
for (auto it = Bindings.begin(); it != Bindings.end(); ++it)
|
||||
{
|
||||
if (it->second.isSingle() && it->second.action()->Type() == at)
|
||||
{
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
#include "mpdpp.h"
|
||||
|
||||
#include "actions.h"
|
||||
#include "bindings.h"
|
||||
#include "browser.h"
|
||||
#include "global.h"
|
||||
#include "helpers.h"
|
||||
#include "keys.h"
|
||||
#include "lyrics.h"
|
||||
#include "playlist.h"
|
||||
#include "settings.h"
|
||||
@@ -98,10 +98,10 @@ int main(int argc, char **argv)
|
||||
Config.Read();
|
||||
Config.GenerateColumns();
|
||||
|
||||
if (!Keys.read(Config.ncmpcpp_directory + "keys"))
|
||||
if (!Bindings.read(Config.ncmpcpp_directory + "keys"))
|
||||
return 1;
|
||||
|
||||
Keys.generateBindings();
|
||||
Bindings.generateDefault();
|
||||
|
||||
if (getenv("MPD_HOST"))
|
||||
Mpd.SetHostname(getenv("MPD_HOST"));
|
||||
@@ -273,7 +273,7 @@ int main(int argc, char **argv)
|
||||
if (input == Key::noOp)
|
||||
continue;
|
||||
|
||||
auto k = Keys.Bindings.equal_range(input);
|
||||
auto k = Bindings.get(input);
|
||||
for (; k.first != k.second; ++k.first)
|
||||
{
|
||||
Binding &b = k.first->second;
|
||||
|
||||
Reference in New Issue
Block a user