bindings: add support for action "require_screen"
This commit is contained in:
@@ -88,6 +88,13 @@
|
|||||||
## before we stuff characters into input queue, so if condition
|
## before we stuff characters into input queue, so if condition
|
||||||
## is not met, whole chain is aborted and we're fine.
|
## is not met, whole chain is aborted and we're fine.
|
||||||
##
|
##
|
||||||
|
## - require_screen "screen" - checks whether given screen is
|
||||||
|
## currently active. accepted values: browser, clock, help,
|
||||||
|
## media_library, outputs, playlist, playlist_editor,
|
||||||
|
## search_engine, tag_editor, visualizer, last_fm, lyrics,
|
||||||
|
## selected_items_adder, server_info, song_info,
|
||||||
|
## sort_playlist_dialog, tiny_tag_editor.
|
||||||
|
##
|
||||||
## Note: Both 'backspace' and 'backspace_2' are used because some
|
## Note: Both 'backspace' and 'backspace_2' are used because some
|
||||||
## terminals interpret backspace using keycode of 'backspace'
|
## terminals interpret backspace using keycode of 'backspace'
|
||||||
## and some the one of 'backspace_2'. You can get away with
|
## and some the one of 'backspace_2'. You can get away with
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ ncmpcpp_SOURCES = \
|
|||||||
lastfm_service.cpp \
|
lastfm_service.cpp \
|
||||||
lyrics.cpp \
|
lyrics.cpp \
|
||||||
lyrics_fetcher.cpp \
|
lyrics_fetcher.cpp \
|
||||||
|
macro_utilities.cpp \
|
||||||
media_library.cpp \
|
media_library.cpp \
|
||||||
mpdpp.cpp \
|
mpdpp.cpp \
|
||||||
mutable_song.cpp \
|
mutable_song.cpp \
|
||||||
|
|||||||
@@ -127,6 +127,16 @@ Action *parseActionLine(const std::string &line, F error)
|
|||||||
else
|
else
|
||||||
error() << "empty argument passed to push_characters\n";
|
error() << "empty argument passed to push_characters\n";
|
||||||
}
|
}
|
||||||
|
else if (action_name == "require_screen")
|
||||||
|
{
|
||||||
|
// require screen of given type
|
||||||
|
std::string arg = getEnclosedString(line, '"', '"', 0);
|
||||||
|
ScreenType screen_type = stringToScreenType(arg);
|
||||||
|
if (screen_type != ScreenType::Unknown)
|
||||||
|
result = new RequireScreen(screen_type);
|
||||||
|
else
|
||||||
|
error() << "unknown screen passed to require_screen: '" << arg << "'\n";
|
||||||
|
}
|
||||||
else if (action_name == "require_runnable")
|
else if (action_name == "require_runnable")
|
||||||
{
|
{
|
||||||
// require that given action is runnable
|
// require that given action is runnable
|
||||||
|
|||||||
38
src/macro_utilities.cpp
Normal file
38
src/macro_utilities.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2008-2012 by Andrzej Rybczak *
|
||||||
|
* electricityispower@gmail.com *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the *
|
||||||
|
* Free Software Foundation, Inc., *
|
||||||
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
#include "macro_utilities.h"
|
||||||
|
|
||||||
|
void PushCharacters::Run()
|
||||||
|
{
|
||||||
|
for (auto it = m_queue.begin(); it != m_queue.end(); ++it)
|
||||||
|
(*m_window)->pushChar(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RequireRunnable::canBeRun() const
|
||||||
|
{
|
||||||
|
return m_action->canBeRun();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RequireScreen::canBeRun() const
|
||||||
|
{
|
||||||
|
return Global::myScreen->type() == m_screen_type;
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
|
#include "screen_type.h"
|
||||||
|
|
||||||
struct PushCharacters : public Action
|
struct PushCharacters : public Action
|
||||||
{
|
{
|
||||||
@@ -30,10 +31,7 @@ struct PushCharacters : public Action
|
|||||||
: Action(aMacroUtility, ""), m_window(w), m_queue(queue) { }
|
: Action(aMacroUtility, ""), m_window(w), m_queue(queue) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Run() {
|
virtual void Run();
|
||||||
for (auto it = m_queue.begin(); it != m_queue.end(); ++it)
|
|
||||||
(*m_window)->pushChar(*it);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NC::Window **m_window;
|
NC::Window **m_window;
|
||||||
@@ -46,11 +44,24 @@ struct RequireRunnable : public Action
|
|||||||
: Action(aMacroUtility, ""), m_action(action) { assert(action); }
|
: Action(aMacroUtility, ""), m_action(action) { assert(action); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool canBeRun() const { return m_action->canBeRun(); }
|
virtual bool canBeRun() const;
|
||||||
virtual void Run() { }
|
virtual void Run() { }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Action *m_action;
|
Action *m_action;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct RequireScreen : public Action
|
||||||
|
{
|
||||||
|
RequireScreen(ScreenType screen_type)
|
||||||
|
: Action(aMacroUtility, ""), m_screen_type(screen_type) { }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool canBeRun() const;
|
||||||
|
virtual void Run() { }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScreenType m_screen_type;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // _MACRO_UTILITIES
|
#endif // _MACRO_UTILITIES
|
||||||
|
|||||||
Reference in New Issue
Block a user