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