outputs: replace enterPressed with toggleOutput

This commit is contained in:
Andrzej Rybczak
2015-09-27 14:24:30 +02:00
parent c6506d77fd
commit 0ee09fb109
8 changed files with 48 additions and 22 deletions

View File

@@ -193,6 +193,9 @@
# select_item # select_item
# #
#def_key "enter" #def_key "enter"
# toggle_output
#
#def_key "enter"
# press_enter # press_enter
# #
#def_key "space" #def_key "space"

View File

@@ -2216,6 +2216,16 @@ void SetSelectedItemsPriority::run()
myPlaylist->SetSelectedItemsPriority(prio); myPlaylist->SetSelectedItemsPriority(prio);
} }
bool ToggleOutput::canBeRun()
{
return myScreen == myOutputs;
}
void ToggleOutput::run()
{
myOutputs->toggleOutput();
}
bool ToggleVisualizationType::canBeRun() bool ToggleVisualizationType::canBeRun()
{ {
# ifdef ENABLE_VISUALIZER # ifdef ENABLE_VISUALIZER
@@ -2667,6 +2677,7 @@ void populateActions()
insert_action(new Actions::ToggleMediaLibrarySortMode()); insert_action(new Actions::ToggleMediaLibrarySortMode());
insert_action(new Actions::RefetchLyrics()); insert_action(new Actions::RefetchLyrics());
insert_action(new Actions::SetSelectedItemsPriority()); insert_action(new Actions::SetSelectedItemsPriority());
insert_action(new Actions::ToggleOutput());
insert_action(new Actions::ToggleVisualizationType()); insert_action(new Actions::ToggleVisualizationType());
insert_action(new Actions::SetVisualizerSampleMultiplier()); insert_action(new Actions::SetVisualizerSampleMultiplier());
insert_action(new Actions::ShowSongInfo()); insert_action(new Actions::ShowSongInfo());

View File

@@ -56,7 +56,7 @@ enum class Type
ToggleAddMode, ToggleMouse, ToggleBitrateVisibility, ToggleAddMode, ToggleMouse, ToggleBitrateVisibility,
AddRandomItems, ToggleBrowserSortMode, ToggleLibraryTagType, AddRandomItems, ToggleBrowserSortMode, ToggleLibraryTagType,
ToggleMediaLibrarySortMode, RefetchLyrics, ToggleMediaLibrarySortMode, RefetchLyrics,
SetSelectedItemsPriority, ToggleVisualizationType, SetVisualizerSampleMultiplier, SetSelectedItemsPriority, ToggleOutput, ToggleVisualizationType, SetVisualizerSampleMultiplier,
ShowSongInfo, ShowArtistInfo, ShowLyrics, Quit, NextScreen, PreviousScreen, ShowSongInfo, ShowArtistInfo, ShowLyrics, Quit, NextScreen, PreviousScreen,
ShowHelp, ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine, ShowHelp, ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine,
ResetSearchEngine, ShowMediaLibrary, ToggleMediaLibraryColumnsMode, ResetSearchEngine, ShowMediaLibrary, ToggleMediaLibraryColumnsMode,
@@ -1045,6 +1045,15 @@ private:
virtual void run() OVERRIDE; virtual void run() OVERRIDE;
}; };
struct ToggleOutput: BaseAction
{
ToggleOutput(): BaseAction(Type::ToggleOutput, "toggle_output") { }
private:
virtual bool canBeRun() OVERRIDE;
virtual void run() OVERRIDE;
};
struct ToggleVisualizationType: BaseAction struct ToggleVisualizationType: BaseAction
{ {
ToggleVisualizationType() ToggleVisualizationType()

View File

@@ -496,7 +496,10 @@ void BindingsConfiguration::generateDefaults()
if (notBound(k = stringToKey("insert"))) if (notBound(k = stringToKey("insert")))
bind(k, Actions::Type::SelectItem); bind(k, Actions::Type::SelectItem);
if (notBound(k = stringToKey("enter"))) if (notBound(k = stringToKey("enter")))
{
bind(k, Actions::Type::ToggleOutput);
bind(k, Actions::Type::PressEnter); bind(k, Actions::Type::PressEnter);
}
if (notBound(k = stringToKey("space"))) if (notBound(k = stringToKey("space")))
{ {
bind(k, Actions::Type::AddItemToPlaylist); bind(k, Actions::Type::AddItemToPlaylist);

View File

@@ -330,7 +330,7 @@ void write_bindings(NC::Scrollpad &w)
# ifdef ENABLE_OUTPUTS # ifdef ENABLE_OUTPUTS
key_section(w, "Outputs"); key_section(w, "Outputs");
key(w, Type::PressEnter, "Toggle output"); key(w, Type::ToggleOutput, "Toggle output");
# endif // ENABLE_OUTPUTS # endif // ENABLE_OUTPUTS
# if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H) # if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H)

View File

@@ -69,20 +69,6 @@ std::wstring Outputs::title()
return L"Outputs"; return L"Outputs";
} }
void Outputs::enterPressed()
{
if (w.current()->value().enabled())
{
Mpd.DisableOutput(w.choice());
Statusbar::printf("Output \"%s\" disabled", w.current()->value().name());
}
else
{
Mpd.EnableOutput(w.choice());
Statusbar::printf("Output \"%s\" enabled", w.current()->value().name());
}
}
void Outputs::mouseButtonPressed(MEVENT me) void Outputs::mouseButtonPressed(MEVENT me)
{ {
if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size()) if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
@@ -97,7 +83,7 @@ void Outputs::mouseButtonPressed(MEVENT me)
Screen<WindowType>::mouseButtonPressed(me); Screen<WindowType>::mouseButtonPressed(me);
} }
void Outputs::FetchList() void Outputs::fetchList()
{ {
w.clear(); w.clear();
for (MPD::OutputIterator out = Mpd.GetOutputs(), end; out != end; ++out) for (MPD::OutputIterator out = Mpd.GetOutputs(), end; out != end; ++out)
@@ -111,5 +97,18 @@ void Outputs::FetchList()
w.refresh(); w.refresh();
} }
#endif // ENABLE_OUTPUTS void Outputs::toggleOutput()
{
if (w.current()->value().enabled())
{
Mpd.DisableOutput(w.choice());
Statusbar::printf("Output \"%s\" disabled", w.current()->value().name());
}
else
{
Mpd.EnableOutput(w.choice());
Statusbar::printf("Output \"%s\" enabled", w.current()->value().name());
}
}
#endif // ENABLE_OUTPUTS

View File

@@ -43,14 +43,15 @@ struct Outputs: Screen<NC::Menu<MPD::Output>>, Tabbable
virtual void update() OVERRIDE { } virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE; virtual void enterPressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE; virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; } virtual bool isLockable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; } virtual bool isMergable() OVERRIDE { return true; }
// private members // private members
void FetchList(); void fetchList();
void toggleOutput();
}; };
extern Outputs *myOutputs; extern Outputs *myOutputs;

View File

@@ -159,7 +159,7 @@ void initialize_status()
myBrowser->fetchSupportedExtensions(); myBrowser->fetchSupportedExtensions();
# ifdef ENABLE_OUTPUTS # ifdef ENABLE_OUTPUTS
myOutputs->FetchList(); myOutputs->fetchList();
# endif // ENABLE_OUTPUTS # endif // ENABLE_OUTPUTS
# ifdef ENABLE_VISUALIZER # ifdef ENABLE_VISUALIZER
myVisualizer->ResetFD(); myVisualizer->ResetFD();
@@ -760,6 +760,6 @@ void Status::Changes::mixer()
void Status::Changes::outputs() void Status::Changes::outputs()
{ {
# ifdef ENABLE_OUTPUTS # ifdef ENABLE_OUTPUTS
myOutputs->FetchList(); myOutputs->fetchList();
# endif // ENABLE_OUTPUTS # endif // ENABLE_OUTPUTS
} }