diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2015-09-27 03:31:02 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2015-09-27 03:55:12 +0200 |
commit | 6ad3de7366f3854442cce108c964f93c01011531 (patch) | |
tree | c8bbf20771fcf071efaa50d2cb843ecb93205605 /src | |
parent | 43a6b81820d669b02fcc09e488199a685440d8c5 (diff) |
help: show defined action chains
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.h | 10 | ||||
-rw-r--r-- | src/bindings.h | 8 | ||||
-rw-r--r-- | src/help.cpp | 50 | ||||
-rw-r--r-- | src/macro_utilities.cpp | 47 | ||||
-rw-r--r-- | src/macro_utilities.h | 14 | ||||
-rw-r--r-- | src/screen_type.cpp | 53 | ||||
-rw-r--r-- | src/screen_type.h | 2 |
7 files changed, 156 insertions, 28 deletions
diff --git a/src/actions.h b/src/actions.h index 581e8feb..544115d1 100644 --- a/src/actions.h +++ b/src/actions.h @@ -88,9 +88,9 @@ extern size_t FooterStartY; struct BaseAction { - BaseAction(Type type_, const char *name_): m_type(type_), m_name(name_) { } + BaseAction(Type type_, const char *name_): m_name(name_), m_type(type_) { } - const char *name() const { return m_name; } + const std::string &name() const { return m_name; } Type type() const { return m_type; } virtual bool canBeRun() { return true; } @@ -104,12 +104,14 @@ struct BaseAction } return false; } - + +protected: + std::string m_name; + private: virtual void run() = 0; Type m_type; - const char *m_name; }; BaseAction &get(Type at); diff --git a/src/bindings.h b/src/bindings.h index 35d3e3dd..f14763b9 100644 --- a/src/bindings.h +++ b/src/bindings.h @@ -36,8 +36,8 @@ struct Binding typedef std::vector<Actions::BaseAction *> ActionChain; template <typename ArgT> - Binding(ArgT &&actions) - : m_actions(std::forward<ArgT>(actions)) { + Binding(ArgT &&actions_) + : m_actions(std::forward<ArgT>(actions_)) { assert(!m_actions.empty()); } Binding(Actions::Type at) @@ -58,6 +58,10 @@ struct Binding return m_actions[0]; } + const ActionChain &actions() const { + return m_actions; + } + private: ActionChain m_actions; }; diff --git a/src/help.cpp b/src/help.cpp index 807fc580..9a017c0c 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -25,6 +25,7 @@ #include "help.h" #include "settings.h" #include "status.h" +#include "utility/string.h" #include "utility/wide_string.h" #include "title.h" #include "screen_switcher.h" @@ -36,6 +37,22 @@ Help *myHelp; namespace { +std::string align_key_rep(std::wstring keys) +{ + size_t i = 0, len = 0; + const size_t max_len = 20; + for (; i < keys.size(); ++i) + { + int width = std::max(1, wcwidth(keys[i])); + if (len+width > max_len) + break; + else + len += width; + } + keys.resize(i + max_len - len, ' '); + return ToString(keys); +} + std::string display_keys(const Actions::Type at) { std::wstring result, skey; @@ -54,18 +71,7 @@ std::string display_keys(const Actions::Type at) } } } - size_t i = 0, len = 0; - const size_t max_len = 20; - for (; i < result.size(); ++i) - { - int width = std::max(1, wcwidth(result[i])); - if (len+width > max_len) - break; - else - len += width; - } - result.resize(i + max_len - len, ' '); - return ToString(result); + return align_key_rep(std::move(result)); } void section(NC::Scrollpad &w, const char *type_, const char *title_) @@ -93,6 +99,11 @@ void key(NC::Scrollpad &w, const Actions::Type at, const boost::format &desc) w << " " << display_keys(at) << " : " << desc.str() << '\n'; } +void key(NC::Scrollpad &w, NC::Key::Type k, const std::string &desc) +{ + w << " " << align_key_rep(keyToWString(k)) << " : " << desc << '\n'; +} + /**********************************************************************/ void mouse_section(NC::Scrollpad &w, const char *title_) @@ -393,6 +404,21 @@ void write_bindings(NC::Scrollpad &w) mouse(w, "Right click", "Toggle output"); # endif // ENABLE_OUTPUTS + section(w, "", "Action chains"); + for (const auto &k : Bindings) + { + for (const auto &binding : k.second) + { + if (!binding.isSingle()) + { + std::vector<std::string> commands; + for (const auto &action : binding.actions()) + commands.push_back(action->name()); + key(w, k.first, join<std::string>(commands, ", ")); + } + } + } + section(w, "", "List of available colors"); for (int i = 0; i < COLORS; ++i) w << NC::Color(i, NC::Color::transparent) << i+1 << NC::Color::End << " "; diff --git a/src/macro_utilities.cpp b/src/macro_utilities.cpp index 093d8c8e..c7e95716 100644 --- a/src/macro_utilities.cpp +++ b/src/macro_utilities.cpp @@ -18,31 +18,76 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ +#include "bindings.h" #include "global.h" #include "macro_utilities.h" +#include "utility/string.h" +#include "utility/wide_string.h" namespace Actions { +PushCharacters::PushCharacters(NC::Window **w, std::vector<NC::Key::Type> &&queue) + : BaseAction(Type::MacroUtility, "push_characters") + , m_window(w) + , m_queue(queue) +{ + assert(w != nullptr); + std::vector<std::string> keys; + for (const auto &key : queue) + keys.push_back(ToString(keyToWString(key))); + m_name += " \""; + m_name += join<std::string>(keys, ", "); + m_name += "\""; +} + void PushCharacters::run() { for (auto it = m_queue.begin(); it != m_queue.end(); ++it) (*m_window)->pushChar(*it); } +RequireRunnable::RequireRunnable(BaseAction *action) + : BaseAction(Type::MacroUtility, "require_runnable") + , m_action(action) +{ + assert(m_action != nullptr); + m_name += " \""; + m_name += m_action->name(); + m_name += "\""; +} + bool RequireRunnable::canBeRun() { return m_action->canBeRun(); } +RequireScreen::RequireScreen(ScreenType screen_type) + : BaseAction(Type::MacroUtility, "require_screen") + , m_screen_type(screen_type) +{ + m_name += " \""; + m_name += screenTypeToString(m_screen_type); + m_name += "\""; +} + bool RequireScreen::canBeRun() { return Global::myScreen->type() == m_screen_type; } +RunExternalCommand::RunExternalCommand(std::string command) + : BaseAction(Type::MacroUtility, "run_external_command") + , m_command(std::move(command)) +{ + m_name += " \""; + m_name += m_command; + m_name += "\""; +} + void RunExternalCommand::run() { GNUC_UNUSED int res; res = std::system(m_command.c_str()); } -}
\ No newline at end of file +} diff --git a/src/macro_utilities.h b/src/macro_utilities.h index 2f75b00c..dd864691 100644 --- a/src/macro_utilities.h +++ b/src/macro_utilities.h @@ -29,9 +29,8 @@ namespace Actions { struct PushCharacters: BaseAction { - PushCharacters(NC::Window **w, std::vector<NC::Key::Type> &&queue) - : BaseAction(Type::MacroUtility, ""), m_window(w), m_queue(queue) { } - + PushCharacters(NC::Window **w, std::vector<NC::Key::Type> &&queue); + private: virtual void run() OVERRIDE; @@ -41,8 +40,7 @@ private: struct RequireRunnable: BaseAction { - RequireRunnable(BaseAction *action) - : BaseAction(Type::MacroUtility, ""), m_action(action) { assert(action); } + RequireRunnable(BaseAction *action); private: virtual bool canBeRun() OVERRIDE; @@ -53,8 +51,7 @@ private: struct RequireScreen: BaseAction { - RequireScreen(ScreenType screen_type) - : BaseAction(Type::MacroUtility, ""), m_screen_type(screen_type) { } + RequireScreen(ScreenType screen_type); private: virtual bool canBeRun() OVERRIDE; @@ -65,8 +62,7 @@ private: struct RunExternalCommand: BaseAction { - RunExternalCommand(std::string command) - : BaseAction(Type::MacroUtility, ""), m_command(command) { } + RunExternalCommand(std::string command); private: virtual void run() OVERRIDE; diff --git a/src/screen_type.cpp b/src/screen_type.cpp index 20f3c4f2..3f9c4f59 100644 --- a/src/screen_type.cpp +++ b/src/screen_type.cpp @@ -39,6 +39,59 @@ #include "tiny_tag_editor.h" #include "visualizer.h" +std::string screenTypeToString(ScreenType st) +{ + switch (st) + { + case ScreenType::Browser: + return "browser"; +#ifdef ENABLE_CLOCK + case ScreenType::Clock: + return "clock"; +#endif // ENABLE_CLOCK + case ScreenType::Help: + return "help"; +#ifdef HAVE_CURL_CURL_H + case ScreenType::Lastfm: + return "last_fm"; +#endif // HAVE_CURL_CURL_H + case ScreenType::Lyrics: + return "lyrics"; + case ScreenType::MediaLibrary: + return "media_library"; +#ifdef ENABLE_OUTPUTS + case ScreenType::Outputs: + return "outputs"; +#endif // ENABLE_OUTPUTS + case ScreenType::Playlist: + return "playlist"; + case ScreenType::PlaylistEditor: + return "playlist_editor"; + case ScreenType::SearchEngine: + return "search_engine"; + case ScreenType::SelectedItemsAdder: + return "selected_items_adder"; + case ScreenType::ServerInfo: + return "server_info"; + case ScreenType::SongInfo: + return "song_info"; + case ScreenType::SortPlaylistDialog: + return "sort_playlist_dialog"; +#ifdef HAVE_TAGLIB_H + case ScreenType::TagEditor: + return "tag_editor"; + case ScreenType::TinyTagEditor: + return "tiny_tag_editor"; +#endif // HAVE_TAGLIB_H + case ScreenType::Unknown: + return "unknown"; +#ifdef ENABLE_VISUALIZER + case ScreenType::Visualizer: + return "visualizer"; +#endif // ENABLE_VISUALIZER + } +} + ScreenType stringtoStartupScreenType(const std::string &s) { ScreenType result = ScreenType::Unknown; diff --git a/src/screen_type.h b/src/screen_type.h index a1568120..f6f87faf 100644 --- a/src/screen_type.h +++ b/src/screen_type.h @@ -58,6 +58,8 @@ enum class ScreenType { # endif // ENABLE_VISUALIZER }; +std::string screenTypeToString(ScreenType st); + ScreenType stringtoStartupScreenType(const std::string &s); ScreenType stringToScreenType(const std::string &s); |