clean NCurse::List class a bit and remove a few redundant functions
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
23
src/menu.cpp
23
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))
|
||||
|
||||
111
src/menu.h
111
src/menu.h
@@ -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,31 +265,31 @@ namespace NCurses
|
||||
///
|
||||
void BoldOption(int pos, bool state);
|
||||
|
||||
/// Makes given position static/active.
|
||||
/// Static positions cannot be highlighted.
|
||||
/// @param pos position in list
|
||||
/// @param state state of activity
|
||||
///
|
||||
void Static(int pos, bool state);
|
||||
|
||||
/// Checks whether given position is static or active
|
||||
/// @param pos position to be checked, -1 checks currently highlighted position
|
||||
/// @return true if position is static, false otherwise
|
||||
///
|
||||
bool isStatic(int pos = -1) const;
|
||||
|
||||
/// 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);
|
||||
|
||||
/// Checks if given position is selected
|
||||
/// @param pos position to be checked, -1 checks currently highlighted position
|
||||
/// @return true if position is selected, false otherwise
|
||||
///
|
||||
virtual bool isSelected(int pos = -1) const;
|
||||
|
||||
/// Checks whether given position is static or active
|
||||
/// @param pos position to be checked, -1 checks currently highlighted position
|
||||
/// @return true if position is static, false otherwise
|
||||
///
|
||||
virtual bool isStatic(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;
|
||||
|
||||
/// Reverses selection of all items in list
|
||||
/// @param beginning beginning of range that has to be reversed
|
||||
///
|
||||
void ReverseSelection(size_t beginning = 0);
|
||||
|
||||
/// Highlights given position
|
||||
/// @param pos position to be highlighted
|
||||
///
|
||||
virtual void Highlight(size_t pos);
|
||||
|
||||
/// @return size of the list
|
||||
///
|
||||
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();
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -220,7 +220,7 @@ void Playlist::SpacePressed()
|
||||
{
|
||||
if (w == Items)
|
||||
{
|
||||
Items->SelectCurrent();
|
||||
Items->Select(Items->Choice(), !Items->isSelected());
|
||||
Items->Scroll(wDown);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -251,7 +251,7 @@ void SearchEngine::SpacePressed()
|
||||
|
||||
if (Config.space_selects)
|
||||
{
|
||||
w->SelectCurrent();
|
||||
w->Select(w->Choice(), !w->isSelected());
|
||||
w->Scroll(wDown);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ void TagEditor::SpacePressed()
|
||||
{
|
||||
if (w == Tags)
|
||||
{
|
||||
Tags->SelectCurrent();
|
||||
Tags->Select(Tags->Choice(), !Tags->isSelected());
|
||||
w->Scroll(wDown);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user