summaryrefslogtreecommitdiff
path: root/src/actions.cpp
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2016-06-10 15:00:32 +0200
committerAndrzej Rybczak <electricityispower@gmail.com>2016-06-10 15:00:32 +0200
commita0b662886555be36037222e541e84c2dc5787658 (patch)
treeb4cb387812e1391317a018cc8ad53fa75ca7fe65 /src/actions.cpp
parent82ea8bf8088e5fa48a9563da2e925a2d6991e57e (diff)
actions: allow action chains to be used for seeking
Diffstat (limited to 'src/actions.cpp')
-rw-r--r--src/actions.cpp39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/actions.cpp b/src/actions.cpp
index d63215c2..e14cbcad 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -2830,9 +2830,34 @@ void seek()
int old_timeout = wFooter->getTimeout();
wFooter->setTimeout(BaseScreen::defaultWindowTimeout);
- auto seekForward = &Actions::get(Actions::Type::SeekForward);
- auto seekBackward = &Actions::get(Actions::Type::SeekBackward);
-
+ // Accept single action of a given type or action chain for which all actions
+ // can be run and one of them is of the given type. This will still not work
+ // in some contrived cases, but allows for more flexibility than accepting
+ // single actions only.
+ auto hasRunnableAction = [](BindingsConfiguration::BindingIteratorPair &bindings, Actions::Type type) {
+ bool success = false;
+ for (auto binding = bindings.first; binding != bindings.second; ++binding)
+ {
+ auto &actions = binding->actions();
+ for (const auto &action : actions)
+ {
+ if (action->canBeRun())
+ {
+ if (action->type() == type)
+ success = true;
+ }
+ else
+ {
+ success = false;
+ break;
+ }
+ }
+ if (success)
+ break;
+ }
+ return success;
+ };
+
SeekingInProgress = true;
while (true)
{
@@ -2843,16 +2868,14 @@ void seek()
: Config.seek_time;
NC::Key::Type input = readKey(*wFooter);
+
auto k = Bindings.get(input);
- if (k.first == k.second || !k.first->isSingle()) // no single action?
- break;
- auto a = k.first->action();
- if (a == seekForward)
+ if (hasRunnableAction(k, Actions::Type::SeekForward))
{
if (songpos < Status::State::totalTime())
songpos = std::min(songpos + howmuch, Status::State::totalTime());
}
- else if (a == seekBackward)
+ else if (hasRunnableAction(k, Actions::Type::SeekBackward))
{
if (songpos > 0)
{