actions: add action for environment update

This commit is contained in:
Andrzej Rybczak
2015-05-17 13:41:30 +02:00
parent c53e98e2a5
commit 4446242bbc
5 changed files with 71 additions and 31 deletions

1
NEWS
View File

@@ -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)

View File

@@ -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"

View File

@@ -190,7 +190,7 @@ void resizeScreen(bool reload_main_window)
using Global::MainHeight;
using Global::wHeader;
using Global::wFooter;
// update internal screen dimensions
if (reload_main_window)
{
@@ -198,29 +198,29 @@ void resizeScreen(bool reload_main_window)
endwin();
refresh();
}
MainHeight = LINES-(Config.design == Design::Alternative ? 7 : 4);
validateScreenSize();
if (!Config.header_visibility)
MainHeight += 2;
if (!Config.statusbar_visibility)
++MainHeight;
setResizeFlags();
applyToVisibleWindows(&BaseScreen::resize);
if (Config.header_visibility || Config.design == Design::Alternative)
wHeader->resize(COLS, HeaderHeight);
FooterStartY = LINES-(Config.statusbar_visibility ? 2 : 1);
wFooter->moveTo(0, FooterStartY);
wFooter->resize(COLS, Config.statusbar_visibility ? 2 : 1);
applyToVisibleWindows(&BaseScreen::refresh);
Status::Changes::elapsedTime(false);
Status::Changes::playerState();
// Note: routines for drawing separator if alternative user
@@ -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());

View File

@@ -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

View File

@@ -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)
{
@@ -189,30 +191,17 @@ int main(int argc, char **argv)
Status::handleClientError(e);
}
}
// 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;
}
if (key_pressed)
myScreen->refreshWindow();
update_environment.run(!key_pressed, key_pressed);
input = readKey(*wFooter);
key_pressed = input != NC::Key::None;
if (!key_pressed)
continue;