actions: require action to be non-null if we query by action type

master
Andrzej Rybczak 13 years ago
parent fb9df0caee
commit 7167d036d0
  1. 15
      src/actions.cpp
  2. 8
      src/actions.h
  3. 1
      src/bindings.cpp
  4. 2
      src/bindings.h
  5. 3
      src/help.cpp

@ -282,11 +282,14 @@ bool isMPDMusicDirSet()
return true; return true;
} }
BaseAction *get(Actions::Type at) BaseAction &get(Actions::Type at)
{ {
if (AvailableActions.empty()) if (AvailableActions.empty())
populateActions(); populateActions();
return AvailableActions[at]; BaseAction *action = AvailableActions[at];
// action should be always present if action type in queried
assert(action != nullptr);
return *action;
} }
BaseAction *get(const std::string &name) BaseAction *get(const std::string &name)
@ -348,9 +351,9 @@ void MouseEvent::run()
) // volume ) // volume
{ {
if (m_mouse_event.bstate & BUTTON2_PRESSED) if (m_mouse_event.bstate & BUTTON2_PRESSED)
get(Type::VolumeDown)->execute(); get(Type::VolumeDown).execute();
else else
get(Type::VolumeUp)->execute(); get(Type::VolumeUp).execute();
} }
else if (m_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED)) else if (m_mouse_event.bstate & (BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON4_PRESSED))
myScreen->mouseButtonPressed(m_mouse_event); myScreen->mouseButtonPressed(m_mouse_event);
@ -2573,8 +2576,8 @@ void seek()
int old_timeout = wFooter->getTimeout(); int old_timeout = wFooter->getTimeout();
wFooter->setTimeout(500); wFooter->setTimeout(500);
auto seekForward = Actions::get(Actions::Type::SeekForward); auto seekForward = &Actions::get(Actions::Type::SeekForward);
auto seekBackward = Actions::get(Actions::Type::SeekBackward); auto seekBackward = &Actions::get(Actions::Type::SeekBackward);
SeekingInProgress = true; SeekingInProgress = true;
while (true) while (true)

@ -50,7 +50,7 @@ enum class Type
NextFoundItem, PreviousFoundItem, ToggleFindMode, ToggleReplayGainMode, NextFoundItem, PreviousFoundItem, ToggleFindMode, ToggleReplayGainMode,
ToggleSpaceMode, ToggleAddMode, ToggleMouse, ToggleBitrateVisibility, ToggleSpaceMode, ToggleAddMode, ToggleMouse, ToggleBitrateVisibility,
AddRandomItems, ToggleBrowserSortMode, ToggleLibraryTagType, AddRandomItems, ToggleBrowserSortMode, ToggleLibraryTagType,
ToggleMediaLibrarySortMode, RefetchLyrics, RefetchArtistInfo, ToggleMediaLibrarySortMode, RefetchLyrics,
SetSelectedItemsPriority, FilterPlaylistOnPriorities, ShowSongInfo, SetSelectedItemsPriority, FilterPlaylistOnPriorities, ShowSongInfo,
ShowArtistInfo, ShowLyrics, Quit, NextScreen, PreviousScreen, ShowHelp, ShowArtistInfo, ShowLyrics, Quit, NextScreen, PreviousScreen, ShowHelp,
ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine, ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine,
@ -68,9 +68,6 @@ void setWindowsDimensions();
bool askYesNoQuestion(const std::string &question, void (*callback)()); bool askYesNoQuestion(const std::string &question, void (*callback)());
bool isMPDMusicDirSet(); bool isMPDMusicDirSet();
struct BaseAction *get(Type at);
struct BaseAction *get(const std::string &name);
extern bool OriginalStatusbarVisibility; extern bool OriginalStatusbarVisibility;
extern bool ExitMainLoop; extern bool ExitMainLoop;
@ -105,6 +102,9 @@ private:
const char *m_name; const char *m_name;
}; };
BaseAction &get(Type at);
BaseAction *get(const std::string &name);
struct Dummy : public BaseAction struct Dummy : public BaseAction
{ {
Dummy() : BaseAction(Type::Dummy, "dummy") { } Dummy() : BaseAction(Type::Dummy, "dummy") { }

@ -582,7 +582,6 @@ void BindingsConfiguration::generateDefaults()
bind(k, Actions::Type::ToggleBrowserSortMode); bind(k, Actions::Type::ToggleBrowserSortMode);
bind(k, Actions::Type::ToggleLibraryTagType); bind(k, Actions::Type::ToggleLibraryTagType);
bind(k, Actions::Type::RefetchLyrics); bind(k, Actions::Type::RefetchLyrics);
bind(k, Actions::Type::RefetchArtistInfo);
bind(k, Actions::Type::AddRandomItems); bind(k, Actions::Type::AddRandomItems);
} }
if (notBound(k = stringToKey("ctrl_p"))) if (notBound(k = stringToKey("ctrl_p")))

@ -74,7 +74,7 @@ struct Binding
{ {
typedef std::vector<Actions::BaseAction *> ActionChain; typedef std::vector<Actions::BaseAction *> ActionChain;
Binding(Actions::Type at) : m_is_single(true), m_action(Actions::get(at)) { } Binding(Actions::Type at) : m_is_single(true), m_action(&Actions::get(at)) { }
Binding(const ActionChain &actions) { Binding(const ActionChain &actions) {
assert(actions.size() > 0); assert(actions.size() > 0);
if (actions.size() == 1) { if (actions.size() == 1) {

@ -348,9 +348,6 @@ void Help::GetKeybindings()
KeyDesc(Actions::Type::EditLyrics, "Open lyrics in external editor"); KeyDesc(Actions::Type::EditLyrics, "Open lyrics in external editor");
KeyDesc(Actions::Type::RefetchLyrics, "Refetch lyrics"); KeyDesc(Actions::Type::RefetchLyrics, "Refetch lyrics");
KeysSection("Artist info");
KeyDesc(Actions::Type::RefetchArtistInfo, "Refetch artist info");
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
KeysSection("Tiny tag editor"); KeysSection("Tiny tag editor");
KeyDesc(Actions::Type::PressEnter, "Edit tag"); KeyDesc(Actions::Type::PressEnter, "Edit tag");

Loading…
Cancel
Save