diff options
-rw-r--r-- | src/browser.cpp | 7 | ||||
-rw-r--r-- | src/media_library.cpp | 6 | ||||
-rw-r--r-- | src/menu.cpp | 23 | ||||
-rw-r--r-- | src/menu.h | 111 | ||||
-rw-r--r-- | src/ncmpcpp.cpp | 10 | ||||
-rw-r--r-- | src/playlist.cpp | 2 | ||||
-rw-r--r-- | src/playlist_editor.cpp | 6 | ||||
-rw-r--r-- | src/search_engine.cpp | 2 | ||||
-rw-r--r-- | src/tag_editor.cpp | 2 |
9 files changed, 62 insertions, 107 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index c39a91c8..f8fb432c 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -125,14 +125,17 @@ void Browser::EnterPressed() void Browser::SpacePressed() { + if (w->Empty()) + return; + if (Config.space_selects && w->Choice() >= (itsBrowsedDir != "/" ? 1 : 0)) { - w->SelectCurrent(); + w->Select(w->Choice(), !w->isSelected()); w->Scroll(wDown); return; } - if (w->Empty() || (itsBrowsedDir != "/" && w->Choice() == 0 /* parent dir */)) + if (itsBrowsedDir != "/" && w->Choice() == 0 /* parent dir */) return; const Item &item = w->Current(); diff --git a/src/media_library.cpp b/src/media_library.cpp index f9fed51a..771a9e95 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -324,11 +324,11 @@ void MediaLibrary::SpacePressed() { if (Config.space_selects && w == Songs) { - Songs->SelectCurrent(); + Songs->Select(Songs->Choice(), !Songs->isSelected()); w->Scroll(wDown); - return; } - AddToPlaylist(0); + else + AddToPlaylist(0); } void MediaLibrary::MouseButtonPressed(MEVENT me) diff --git a/src/menu.cpp b/src/menu.cpp index 7b8095f5..9c4dc1eb 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -22,29 +22,6 @@ using namespace NCurses; -void List::SelectCurrent() -{ - if (Empty()) - return; - size_t i = Choice(); - Select(i, !isSelected(i)); -} - -void List::ReverseSelection(size_t beginning) -{ - for (size_t i = beginning; i < Size(); ++i) - Select(i, !isSelected(i) && !isStatic(i)); -} - -bool List::Deselect() -{ - if (!hasSelected()) - return false; - for (size_t i = 0; i < Size(); ++i) - Select(i, 0); - return true; -} - template <> std::string Menu<std::string>::GetOption(size_t pos) { if (itsOptionsPtr->at(pos)) @@ -34,7 +34,6 @@ namespace NCurses class List { public: - /// Exception class, thrown by various functions /// that return references to items on the list /// if requested item is separator @@ -49,22 +48,10 @@ namespace NCurses /// virtual void Select(int pos, bool state) = 0; - /// @see Menu::Static() - /// - virtual void Static(int pos, bool state) = 0; - - /// @see Menu::Empty() - /// - virtual bool Empty() const = 0; - /// @see Menu::isSelected() /// virtual bool isSelected(int pos = -1) const = 0; - /// @see Menu::isStatic() - /// - virtual bool isStatic(int pos = -1) const = 0; - /// @see Menu::hasSelected() /// virtual bool hasSelected() const = 0; @@ -73,36 +60,14 @@ namespace NCurses /// virtual void GetSelected(std::vector<size_t> &v) const = 0; - /// @see Menu::Highlight() + /// @see Menu::Empty() /// - virtual void Highlight(size_t pos) = 0; + virtual bool Empty() const = 0; /// @see Menu::Size() /// virtual size_t Size() const = 0; - /// @see Menu::Choice() - /// - virtual size_t Choice() const = 0; - - /// @see Menu::RealChoice() - /// - virtual size_t RealChoice() const = 0; - - /// Selects current position - /// - void SelectCurrent(); - - /// Reverses selection of all items in list - /// @param beginning beginning of range that has to be reversed - /// - void ReverseSelection(size_t beginning = 0); - - /// Deselects all items in list - /// @return true if there was at least one selected items, false otherwise - /// - bool Deselect(); - /// @see Menu::Search() /// virtual bool Search(const std::string &constraint, size_t beginning = 0, int flags = 0) = 0; @@ -127,10 +92,6 @@ namespace NCurses /// virtual const std::string &GetFilter() = 0; - /// @see Menu::GetOption() - /// - virtual std::string GetOption(size_t pos) = 0; - /// @see Menu::isFiltered() /// virtual bool isFiltered() = 0; @@ -304,30 +265,30 @@ namespace NCurses /// void BoldOption(int pos, bool state); - /// Selects/deselects given position - /// @param pos position in list - /// @param state state of selection - /// - virtual void Select(int pos, bool state); - /// Makes given position static/active. /// Static positions cannot be highlighted. /// @param pos position in list /// @param state state of activity /// - virtual void Static(int pos, bool state); + void Static(int pos, bool state); - /// Checks if given position is selected + /// Checks whether given position is static or active /// @param pos position to be checked, -1 checks currently highlighted position - /// @return true if position is selected, false otherwise + /// @return true if position is static, false otherwise /// - virtual bool isSelected(int pos = -1) const; + bool isStatic(int pos = -1) const; - /// Checks whether given position is static or active + /// Selects/deselects given position + /// @param pos position in list + /// @param state state of selection + /// + virtual void Select(int pos, bool state); + + /// Checks if given position is selected /// @param pos position to be checked, -1 checks currently highlighted position - /// @return true if position is static, false otherwise + /// @return true if position is selected, false otherwise /// - virtual bool isStatic(int pos = -1) const; + virtual bool isSelected(int pos = -1) const; /// Checks whether list contains selected positions /// @return true if it contains them, false otherwise @@ -339,23 +300,24 @@ namespace NCurses /// virtual void GetSelected(std::vector<size_t> &v) const; - /// Highlights given position - /// @param pos position to be highlighted + /// Reverses selection of all items in list + /// @param beginning beginning of range that has to be reversed /// - virtual void Highlight(size_t pos); + void ReverseSelection(size_t beginning = 0); - /// @return size of the list + /// Highlights given position + /// @param pos position to be highlighted /// - virtual size_t Size() const; + void Highlight(size_t pos); /// @return currently highlighted position /// - virtual size_t Choice() const; + size_t Choice() const; /// @return real current positions, i.e it doesn't /// count positions that are static or separators /// - virtual size_t RealChoice() const; + size_t RealChoice() const; /// Searches the list for a given contraint. It uses GetStringFunction to convert stored items /// into strings and then performs pattern matching. Note that this supports regular expressions. @@ -395,14 +357,6 @@ namespace NCurses /// virtual const std::string &GetFilter(); - /// Converts given position in list to string using GetStringFunction - /// if specified and an empty string otherwise - /// @param pos position to be converted - /// @return item converted to string - /// @see SetItemDisplayer() - /// - virtual std::string GetOption(size_t pos); - /// @return true if list is currently filtered, false otherwise /// virtual bool isFiltered() { return itsOptionsPtr == &itsFilteredOptions; } @@ -415,6 +369,14 @@ namespace NCurses /// void ShowFiltered() { itsOptionsPtr = &itsFilteredOptions; } + /// Converts given position in list to string using GetStringFunction + /// if specified and an empty string otherwise + /// @param pos position to be converted + /// @return item converted to string + /// @see SetItemDisplayer() + /// + std::string GetOption(size_t pos); + /// Refreshes the menu window /// @see Window::Refresh() /// @@ -485,6 +447,10 @@ namespace NCurses /// virtual bool Empty() const { return itsOptionsPtr->empty(); } + /// @return size of the list + /// + virtual size_t Size() const; + /// @return reference to last item on the list /// @throw List::InvalidItem if requested item is separator /// @@ -1004,6 +970,13 @@ template <typename T> size_t NCurses::Menu<T>::RealChoice() const return result; } +template <typename T> void NCurses::Menu<T>::ReverseSelection(size_t beginning) +{ + option_iterator it = itsOptionsPtr->begin()+beginning; + for (size_t i = beginning; i < Size(); ++i, ++it) + (*it)->isSelected = !(*it)->isSelected && !(*it)->isStatic; +} + template <typename T> bool NCurses::Menu<T>::Search(const std::string &constraint, size_t beginning, int flags) { itsFound.clear(); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 179ff432..eef8296d 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1549,10 +1549,12 @@ int main(int argc, char *argv[]) { if (myScreen->allowsSelection()) { - if (myScreen->GetList()->Deselect()) - { - ShowMessage("Items deselected!"); - } + List *mList = myScreen->GetList(); + if (!mList->hasSelected()) + continue; + for (size_t i = 0; i < mList->Size(); ++i) + mList->Select(i, 0); + ShowMessage("Items deselected!"); } } else if (Keypressed(input, Key.AddSelected)) diff --git a/src/playlist.cpp b/src/playlist.cpp index 860518fb..e2b27620 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -220,7 +220,7 @@ void Playlist::SpacePressed() { if (w == Items) { - Items->SelectCurrent(); + Items->Select(Items->Choice(), !Items->isSelected()); Items->Scroll(wDown); } } diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index f67f47f0..cd15b29e 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -213,11 +213,11 @@ void PlaylistEditor::SpacePressed() { if (Config.space_selects && w == Content) { - Content->SelectCurrent(); + Content->Select(Content->Choice(), !Content->isSelected()); w->Scroll(wDown); - return; } - AddToPlaylist(0); + else + AddToPlaylist(0); } void PlaylistEditor::MouseButtonPressed(MEVENT me) diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 1c37529e..d88aa673 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -251,7 +251,7 @@ void SearchEngine::SpacePressed() if (Config.space_selects) { - w->SelectCurrent(); + w->Select(w->Choice(), !w->isSelected()); w->Scroll(wDown); return; } diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 8ac2dd2a..63efc88b 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -682,7 +682,7 @@ void TagEditor::SpacePressed() { if (w == Tags) { - Tags->SelectCurrent(); + Tags->Select(Tags->Choice(), !Tags->isSelected()); w->Scroll(wDown); return; } |