actions: add action for environment update
This commit is contained in:
1
NEWS
1
NEWS
@@ -22,6 +22,7 @@ ncmpcpp-0.7 (????-??-??)
|
||||
* NCurses terminal sequence escaping is no longer used as it's not accurate enough.
|
||||
* Selecting items no longer depends on space mode and is bound by default to Insert key.
|
||||
* Support for Alt, Ctrl and Shift modifiers as well as Escape key was added.
|
||||
* Action that updates the environment can now be used in bindings configuration file.
|
||||
|
||||
ncmpcpp-0.6.4 (2015-05-02)
|
||||
|
||||
|
||||
@@ -114,6 +114,13 @@
|
||||
## could be used. Then ncmpcpp will not wait for confirmation
|
||||
## (enter) and will execute the command the moment it sees it.
|
||||
##
|
||||
## Note: while command chains are executed, internal environment
|
||||
## update (which includes current window refresh and mpd status
|
||||
## update) is not performed for performance reasons. However, it
|
||||
## may be desirable to do so in some situration. Therefore it's
|
||||
## possible to invoke by hand by performing 'update enviroment'
|
||||
## action.
|
||||
##
|
||||
## Note: There is a difference between:
|
||||
##
|
||||
## def_key "key"
|
||||
|
||||
@@ -301,6 +301,36 @@ BaseAction *get(const std::string &name)
|
||||
return result;
|
||||
}
|
||||
|
||||
UpdateEnvironment::UpdateEnvironment()
|
||||
: BaseAction(Type::UpdateEnvironment, "update_environment")
|
||||
, m_past(boost::posix_time::from_time_t(0))
|
||||
{ }
|
||||
|
||||
void UpdateEnvironment::run(bool update_timer, bool refresh_window)
|
||||
{
|
||||
using Global::Timer;
|
||||
|
||||
// update timer, status if necessary etc.
|
||||
Status::trace(update_timer, true);
|
||||
|
||||
// header stuff
|
||||
if ((myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
|
||||
&& (Timer - m_past > boost::posix_time::milliseconds(500))
|
||||
)
|
||||
{
|
||||
drawHeader();
|
||||
m_past = Timer;
|
||||
}
|
||||
|
||||
if (refresh_window)
|
||||
myScreen->refreshWindow();
|
||||
}
|
||||
|
||||
void UpdateEnvironment::run()
|
||||
{
|
||||
run(true, true);
|
||||
}
|
||||
|
||||
bool MouseEvent::canBeRun()
|
||||
{
|
||||
return Config.mouse_support;
|
||||
@@ -2427,6 +2457,7 @@ void populateActions()
|
||||
AvailableActions[static_cast<size_t>(a->type())] = a;
|
||||
};
|
||||
insert_action(new Actions::Dummy());
|
||||
insert_action(new Actions::UpdateEnvironment());
|
||||
insert_action(new Actions::MouseEvent());
|
||||
insert_action(new Actions::ScrollUp());
|
||||
insert_action(new Actions::ScrollDown());
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef NCMPCPP_ACTIONS_H
|
||||
#define NCMPCPP_ACTIONS_H
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -34,7 +35,7 @@ namespace Actions {
|
||||
enum class Type
|
||||
{
|
||||
MacroUtility = 0,
|
||||
Dummy, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
|
||||
Dummy, UpdateEnvironment, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
|
||||
ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd,
|
||||
ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn,
|
||||
NextColumn, MasterScreen, SlaveScreen, VolumeUp, VolumeDown, DeletePlaylistItems,
|
||||
@@ -122,6 +123,18 @@ private:
|
||||
virtual void run() OVERRIDE { }
|
||||
};
|
||||
|
||||
struct UpdateEnvironment: BaseAction
|
||||
{
|
||||
UpdateEnvironment();
|
||||
|
||||
void run(bool update_status, bool refresh_window);
|
||||
|
||||
private:
|
||||
boost::posix_time::ptime m_past;
|
||||
|
||||
virtual void run() OVERRIDE;
|
||||
};
|
||||
|
||||
struct MouseEvent: BaseAction
|
||||
{
|
||||
MouseEvent(): BaseAction(Type::MouseEvent, "mouse_event")
|
||||
@@ -134,9 +147,8 @@ private:
|
||||
virtual bool canBeRun() OVERRIDE;
|
||||
virtual void run() OVERRIDE;
|
||||
|
||||
private:
|
||||
MEVENT m_mouse_event;
|
||||
MEVENT m_old_mouse_event;
|
||||
MEVENT m_mouse_event;
|
||||
MEVENT m_old_mouse_event;
|
||||
};
|
||||
|
||||
struct ScrollUp: BaseAction
|
||||
|
||||
@@ -162,7 +162,9 @@ int main(int argc, char **argv)
|
||||
bool key_pressed = false;
|
||||
auto input = NC::Key::None;
|
||||
auto connect_attempt = boost::posix_time::from_time_t(0);
|
||||
auto past = boost::posix_time::from_time_t(0);
|
||||
auto update_environment = static_cast<Actions::UpdateEnvironment &>(
|
||||
Actions::get(Actions::Type::UpdateEnvironment)
|
||||
);
|
||||
|
||||
while (!Actions::ExitMainLoop)
|
||||
{
|
||||
@@ -190,29 +192,16 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
// update timer, status if necessary etc.
|
||||
Status::trace(!key_pressed, true);
|
||||
|
||||
if (run_resize_screen)
|
||||
{
|
||||
Actions::resizeScreen(true);
|
||||
run_resize_screen = false;
|
||||
}
|
||||
|
||||
// header stuff
|
||||
if ((myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
|
||||
&& (Timer - past > boost::posix_time::milliseconds(500))
|
||||
)
|
||||
{
|
||||
drawHeader();
|
||||
past = Timer;
|
||||
}
|
||||
update_environment.run(!key_pressed, key_pressed);
|
||||
|
||||
if (key_pressed)
|
||||
myScreen->refreshWindow();
|
||||
input = readKey(*wFooter);
|
||||
key_pressed = input != NC::Key::None;
|
||||
|
||||
if (!key_pressed)
|
||||
continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user