browser: make main type non-pointer

This commit is contained in:
Andrzej Rybczak
2012-09-14 16:20:54 +02:00
parent 9c29082afe
commit d05707ad82
4 changed files with 71 additions and 71 deletions

View File

@@ -681,7 +681,7 @@ void JumpToParentDirectory::Run()
{ {
if (myBrowser->CurrentDir() != "/") if (myBrowser->CurrentDir() != "/")
{ {
myBrowser->main()->reset(); myBrowser->main().reset();
myBrowser->enterPressed(); myBrowser->enterPressed();
} }
} }
@@ -791,17 +791,17 @@ void Delete::Run()
Statusbar::msg("Item(s) deleted"); Statusbar::msg("Item(s) deleted");
} }
# ifndef WIN32 # ifndef WIN32
else if (myScreen == myBrowser && !myBrowser->main()->empty()) else if (myScreen == myBrowser && !myBrowser->main().empty())
{ {
if (!myBrowser->isLocal() && !isMPDMusicDirSet()) if (!myBrowser->isLocal() && !isMPDMusicDirSet())
return; return;
std::string question; std::string question;
if (myBrowser->main()->hasSelected()) if (myBrowser->main().hasSelected())
question = "Delete selected items?"; question = "Delete selected items?";
else else
{ {
MPD::Item &item = myBrowser->main()->current().value(); MPD::Item &item = myBrowser->main().current().value();
std::string name = item.type == MPD::itSong ? item.song->getName() : item.name; std::string name = item.type == MPD::itSong ? item.song->getName() : item.name;
question = "Delete "; question = "Delete ";
question += itemTypeToString(item.type); question += itemTypeToString(item.type);
@@ -813,7 +813,7 @@ void Delete::Run()
if (yes) if (yes)
{ {
bool success = true; bool success = true;
auto list = getSelectedOrCurrent(myBrowser->main()->begin(), myBrowser->main()->end(), myBrowser->main()->currentI()); auto list = getSelectedOrCurrent(myBrowser->main().begin(), myBrowser->main().end(), myBrowser->main().currentI());
for (auto it = list.begin(); it != list.end(); ++it) for (auto it = list.begin(); it != list.end(); ++it)
{ {
const MPD::Item &i = (*it)->value(); const MPD::Item &i = (*it)->value();
@@ -948,7 +948,7 @@ void SavePlaylist::Run()
} }
if (!myBrowser->isLocal() if (!myBrowser->isLocal()
&& myBrowser->CurrentDir() == "/" && myBrowser->CurrentDir() == "/"
&& !myBrowser->main()->empty()) && !myBrowser->main().empty())
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
@@ -1135,7 +1135,7 @@ void ToggleDisplayMode::Run()
{ {
Config.columns_in_browser = !Config.columns_in_browser; Config.columns_in_browser = !Config.columns_in_browser;
Statusbar::msg("Browser display mode: %s", Config.columns_in_browser ? "Columns" : "Classic"); Statusbar::msg("Browser display mode: %s", Config.columns_in_browser ? "Columns" : "Classic");
myBrowser->main()->setTitle(Config.columns_in_browser && Config.titles_visibility ? Display::Columns(myBrowser->main()->getWidth()) : ""); myBrowser->main().setTitle(Config.columns_in_browser && Config.titles_visibility ? Display::Columns(myBrowser->main().getWidth()) : "");
} }
else if (myScreen == mySearcher) else if (myScreen == mySearcher)
{ {
@@ -1452,8 +1452,8 @@ bool EditDirectoryName::canBeRun() const
{ {
return isMPDMusicDirSet() return isMPDMusicDirSet()
&& ((myScreen == myBrowser && ((myScreen == myBrowser
&& !myBrowser->main()->empty() && !myBrowser->main().empty()
&& myBrowser->main()->current().value().type == MPD::itDirectory) && myBrowser->main().current().value().type == MPD::itDirectory)
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
|| (myScreen->activeWindow() == myTagEditor->Dirs || (myScreen->activeWindow() == myTagEditor->Dirs
&& !myTagEditor->Dirs->empty() && !myTagEditor->Dirs->empty()
@@ -1468,7 +1468,7 @@ void EditDirectoryName::Run()
if (myScreen == myBrowser) if (myScreen == myBrowser)
{ {
std::string old_dir = myBrowser->main()->current().value().name; std::string old_dir = myBrowser->main().current().value().name;
Statusbar::lock(); Statusbar::lock();
Statusbar::put() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd; Statusbar::put() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd;
std::string new_dir = wFooter->getString(old_dir); std::string new_dir = wFooter->getString(old_dir);
@@ -1532,8 +1532,8 @@ bool EditPlaylistName::canBeRun() const
return (myScreen->activeWindow() == myPlaylistEditor->Playlists return (myScreen->activeWindow() == myPlaylistEditor->Playlists
&& !myPlaylistEditor->Playlists->empty()) && !myPlaylistEditor->Playlists->empty())
|| (myScreen == myBrowser || (myScreen == myBrowser
&& !myBrowser->main()->empty() && !myBrowser->main().empty()
&& myBrowser->main()->current().value().type == MPD::itPlaylist); && myBrowser->main().current().value().type == MPD::itPlaylist);
} }
void EditPlaylistName::Run() void EditPlaylistName::Run()
@@ -1544,7 +1544,7 @@ void EditPlaylistName::Run()
if (myScreen->activeWindow() == myPlaylistEditor->Playlists) if (myScreen->activeWindow() == myPlaylistEditor->Playlists)
old_name = myPlaylistEditor->Playlists->current().value(); old_name = myPlaylistEditor->Playlists->current().value();
else else
old_name = myBrowser->main()->current().value().name; old_name = myBrowser->main().current().value().name;
Statusbar::lock(); Statusbar::lock();
Statusbar::put() << NC::fmtBold << "Playlist: " << NC::fmtBoldEnd; Statusbar::put() << NC::fmtBold << "Playlist: " << NC::fmtBoldEnd;
std::string new_name = wFooter->getString(old_name); std::string new_name = wFooter->getString(old_name);
@@ -1596,12 +1596,12 @@ void JumpToMediaLibrary::Run()
bool JumpToPlaylistEditor::canBeRun() const bool JumpToPlaylistEditor::canBeRun() const
{ {
return myScreen == myBrowser return myScreen == myBrowser
&& myBrowser->main()->current().value().type == MPD::itPlaylist; && myBrowser->main().current().value().type == MPD::itPlaylist;
} }
void JumpToPlaylistEditor::Run() void JumpToPlaylistEditor::Run()
{ {
myPlaylistEditor->Locate(myBrowser->main()->current().value().name); myPlaylistEditor->Locate(myBrowser->main().current().value().name);
} }
void ToggleScreenLock::Run() void ToggleScreenLock::Run()
@@ -2087,7 +2087,7 @@ void ToggleBrowserSortMode::Run()
Statusbar::msg("Sort songs by: Name"); Statusbar::msg("Sort songs by: Name");
break; break;
} }
std::sort(myBrowser->main()->begin()+(myBrowser->CurrentDir() != "/"), myBrowser->main()->end(), std::sort(myBrowser->main().begin()+(myBrowser->CurrentDir() != "/"), myBrowser->main().end(),
LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode)); LocaleBasedItemSorting(std::locale(), Config.ignore_leading_the, Config.browser_sort_mode));
} }

View File

@@ -63,13 +63,13 @@ bool BrowserEntryMatcher(const Regex &rx, const MPD::Item &item, bool filter);
Browser::Browser() : itsBrowseLocally(0), itsScrollBeginning(0), itsBrowsedDir("/") Browser::Browser() : itsBrowseLocally(0), itsScrollBeginning(0), itsBrowsedDir("/")
{ {
w = new NC::Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.columns_in_browser && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::brNone); w = NC::Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.columns_in_browser && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::brNone);
w->setHighlightColor(Config.main_highlight_color); w.setHighlightColor(Config.main_highlight_color);
w->cyclicScrolling(Config.use_cyclic_scrolling); w.cyclicScrolling(Config.use_cyclic_scrolling);
w->centeredCursor(Config.centered_cursor); w.centeredCursor(Config.centered_cursor);
w->setSelectedPrefix(Config.selected_item_prefix); w.setSelectedPrefix(Config.selected_item_prefix);
w->setSelectedSuffix(Config.selected_item_suffix); w.setSelectedSuffix(Config.selected_item_suffix);
w->setItemDisplayer(Display::Items); w.setItemDisplayer(Display::Items);
if (SupportedExtensions.empty()) if (SupportedExtensions.empty())
Mpd.GetSupportedExtensions(SupportedExtensions); Mpd.GetSupportedExtensions(SupportedExtensions);
@@ -79,9 +79,9 @@ void Browser::resize()
{ {
size_t x_offset, width; size_t x_offset, width;
getWindowResizeParams(x_offset, width); getWindowResizeParams(x_offset, width);
w->resize(width, MainHeight); w.resize(width, MainHeight);
w->moveTo(x_offset, MainStartY); w.moveTo(x_offset, MainStartY);
w->setTitle(Config.columns_in_browser && Config.titles_visibility ? Display::Columns(w->getWidth()) : ""); w.setTitle(Config.columns_in_browser && Config.titles_visibility ? Display::Columns(w.getWidth()) : "");
hasToBeResized = 0; hasToBeResized = 0;
} }
@@ -106,7 +106,7 @@ void Browser::switchTo()
if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime
Config.browser_sort_mode = smName; Config.browser_sort_mode = smName;
if (w->empty()) if (w.empty())
myBrowser->GetDirectory(itsBrowsedDir); myBrowser->GetDirectory(itsBrowsedDir);
else else
markSongsInPlaylist(getProxySongList()); markSongsInPlaylist(getProxySongList());
@@ -126,10 +126,10 @@ std::wstring Browser::title()
void Browser::enterPressed() void Browser::enterPressed()
{ {
if (w->empty()) if (w.empty())
return; return;
const MPD::Item &item = w->current().value(); const MPD::Item &item = w.current().value();
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
@@ -159,19 +159,19 @@ void Browser::enterPressed()
void Browser::spacePressed() void Browser::spacePressed()
{ {
if (w->empty()) if (w.empty())
return; return;
size_t i = itsBrowsedDir != "/" ? 1 : 0; size_t i = itsBrowsedDir != "/" ? 1 : 0;
if (Config.space_selects && w->choice() >= i) if (Config.space_selects && w.choice() >= i)
{ {
i = w->choice(); i = w.choice();
w->at(i).setSelected(!w->at(i).isSelected()); w.at(i).setSelected(!w.at(i).isSelected());
w->scroll(NC::wDown); w.scroll(NC::wDown);
return; return;
} }
const MPD::Item &item = w->current().value(); const MPD::Item &item = w.current().value();
if (isParentDirectory(item)) if (isParentDirectory(item))
return; return;
@@ -212,40 +212,40 @@ void Browser::spacePressed()
break; break;
} }
} }
w->scroll(NC::wDown); w.scroll(NC::wDown);
} }
void Browser::mouseButtonPressed(MEVENT me) void Browser::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())
return; return;
if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)) if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED))
{ {
w->Goto(me.y); w.Goto(me.y);
switch (w->current().value().type) switch (w.current().value().type)
{ {
case itDirectory: case itDirectory:
if (me.bstate & BUTTON1_PRESSED) if (me.bstate & BUTTON1_PRESSED)
{ {
GetDirectory(w->current().value().name); GetDirectory(w.current().value().name);
drawHeader(); drawHeader();
} }
else else
{ {
size_t pos = w->choice(); size_t pos = w.choice();
spacePressed(); spacePressed();
if (pos < w->size()-1) if (pos < w.size()-1)
w->scroll(NC::wUp); w.scroll(NC::wUp);
} }
break; break;
case itPlaylist: case itPlaylist:
case itSong: case itSong:
if (me.bstate & BUTTON1_PRESSED) if (me.bstate & BUTTON1_PRESSED)
{ {
size_t pos = w->choice(); size_t pos = w.choice();
spacePressed(); spacePressed();
if (pos < w->size()-1) if (pos < w.size()-1)
w->scroll(NC::wUp); w.scroll(NC::wUp);
} }
else else
enterPressed(); enterPressed();
@@ -265,15 +265,15 @@ bool Browser::allowsFiltering()
std::string Browser::currentFilter() std::string Browser::currentFilter()
{ {
return RegexFilter<MPD::Item>::currentFilter(*w); return RegexFilter<MPD::Item>::currentFilter(w);
} }
void Browser::applyFilter(const std::string &filter) void Browser::applyFilter(const std::string &filter)
{ {
w->showAll(); w.showAll();
auto fun = std::bind(BrowserEntryMatcher, _1, _2, true); auto fun = std::bind(BrowserEntryMatcher, _1, _2, true);
auto rx = RegexFilter<MPD::Item>(filter, Config.regex_type, fun); auto rx = RegexFilter<MPD::Item>(filter, Config.regex_type, fun);
w->filter(w->begin(), w->end(), rx); w.filter(w.begin(), w.end(), rx);
} }
/***********************************************************************/ /***********************************************************************/
@@ -287,24 +287,24 @@ bool Browser::search(const std::string &constraint)
{ {
auto fun = std::bind(BrowserEntryMatcher, _1, _2, false); auto fun = std::bind(BrowserEntryMatcher, _1, _2, false);
auto rx = RegexFilter<MPD::Item>(constraint, Config.regex_type, fun); auto rx = RegexFilter<MPD::Item>(constraint, Config.regex_type, fun);
return w->search(w->begin(), w->end(), rx); return w.search(w.begin(), w.end(), rx);
} }
void Browser::nextFound(bool wrap) void Browser::nextFound(bool wrap)
{ {
w->nextFound(wrap); w.nextFound(wrap);
} }
void Browser::prevFound(bool wrap) void Browser::prevFound(bool wrap)
{ {
w->prevFound(wrap); w.prevFound(wrap);
} }
/***********************************************************************/ /***********************************************************************/
std::shared_ptr<ProxySongList> Browser::getProxySongList() std::shared_ptr<ProxySongList> Browser::getProxySongList()
{ {
return mkProxySongList(*w, [](NC::Menu<MPD::Item>::Item &item) -> MPD::Song * { return mkProxySongList(w, [](NC::Menu<MPD::Item>::Item &item) -> MPD::Song * {
MPD::Song *ptr = 0; MPD::Song *ptr = 0;
if (item.value().type == itSong) if (item.value().type == itSong)
ptr = item.value().song.get(); ptr = item.value().song.get();
@@ -319,7 +319,7 @@ bool Browser::allowsSelection()
void Browser::reverseSelection() void Browser::reverseSelection()
{ {
reverseSelectionHelper(w->begin()+(itsBrowsedDir == "/" ? 0 : 1), w->end()); reverseSelectionHelper(w.begin()+(itsBrowsedDir == "/" ? 0 : 1), w.end());
} }
MPD::SongList Browser::getSelectedSongs() MPD::SongList Browser::getSelectedSongs()
@@ -351,12 +351,12 @@ MPD::SongList Browser::getSelectedSongs()
result.insert(result.end(), list.begin(), list.end()); result.insert(result.end(), list.begin(), list.end());
} }
}; };
for (auto it = w->begin(); it != w->end(); ++it) for (auto it = w.begin(); it != w.end(); ++it)
if (it->isSelected()) if (it->isSelected())
item_handler(it->value()); item_handler(it->value());
// if no item is selected, add current one // if no item is selected, add current one
if (result.empty() && !w->empty()) if (result.empty() && !w.empty())
item_handler(w->current().value()); item_handler(w.current().value());
return result; return result;
} }
@@ -372,11 +372,11 @@ void Browser::LocateSong(const MPD::Song &s)
if (itsBrowsedDir != s.getDirectory()) if (itsBrowsedDir != s.getDirectory())
GetDirectory(s.getDirectory()); GetDirectory(s.getDirectory());
for (size_t i = 0; i < w->size(); ++i) for (size_t i = 0; i < w.size(); ++i)
{ {
if ((*w)[i].value().type == itSong && s.getHash() == (*w)[i].value().song->getHash()) if (w[i].value().type == itSong && s.getHash() == w[i].value().song->getHash())
{ {
w->highlight(i); w.highlight(i);
break; break;
} }
} }
@@ -391,17 +391,17 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
int highlightme = -1; int highlightme = -1;
itsScrollBeginning = 0; itsScrollBeginning = 0;
if (itsBrowsedDir != dir) if (itsBrowsedDir != dir)
w->reset(); w.reset();
itsBrowsedDir = dir; itsBrowsedDir = dir;
w->clear(); w.clear();
if (dir != "/") if (dir != "/")
{ {
MPD::Item parent; MPD::Item parent;
parent.name = ".."; parent.name = "..";
parent.type = itDirectory; parent.type = itDirectory;
w->addItem(parent); w.addItem(parent);
} }
MPD::ItemList list; MPD::ItemList list;
@@ -423,14 +423,14 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
{ {
case itPlaylist: case itPlaylist:
{ {
w->addItem(*it); w.addItem(*it);
break; break;
} }
case itDirectory: case itDirectory:
{ {
if (it->name == subdir) if (it->name == subdir)
highlightme = w->size(); highlightme = w.size();
w->addItem(*it); w.addItem(*it);
break; break;
} }
case itSong: case itSong:
@@ -444,13 +444,13 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
break; break;
} }
} }
w->addItem(*it, bold); w.addItem(*it, bold);
break; break;
} }
} }
} }
if (highlightme >= 0) if (highlightme >= 0)
w->highlight(highlightme); w.highlight(highlightme);
} }
#ifndef WIN32 #ifndef WIN32
@@ -563,7 +563,7 @@ void Browser::ChangeBrowseMode()
itsBrowsedDir = itsBrowseLocally ? Config.GetHomeDirectory() : "/"; itsBrowsedDir = itsBrowseLocally ? Config.GetHomeDirectory() : "/";
if (itsBrowseLocally && *itsBrowsedDir.rbegin() == '/') if (itsBrowseLocally && *itsBrowsedDir.rbegin() == '/')
itsBrowsedDir.resize(itsBrowsedDir.length()-1); itsBrowsedDir.resize(itsBrowsedDir.length()-1);
w->reset(); w.reset();
GetDirectory(itsBrowsedDir); GetDirectory(itsBrowsedDir);
drawHeader(); drawHeader();
} }

View File

@@ -25,7 +25,7 @@
#include "mpdpp.h" #include "mpdpp.h"
#include "screen.h" #include "screen.h"
struct Browser : public Screen<NC::Menu<MPD::Item> *>, public Filterable, public HasSongs, public Searchable struct Browser : public Screen<NC::Menu<MPD::Item>>, public Filterable, public HasSongs, public Searchable
{ {
Browser(); Browser();

View File

@@ -191,7 +191,7 @@ void Status::Changes::database()
if (isVisible(myBrowser)) if (isVisible(myBrowser))
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
else else
myBrowser->main()->clear(); myBrowser->main().clear();
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
myTagEditor->Dirs->clear(); myTagEditor->Dirs->clear();
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H