diff --git a/src/actions.cpp b/src/actions.cpp index 0166ba83..e70cf029 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -681,7 +681,7 @@ void JumpToParentDirectory::Run() { if (myBrowser->CurrentDir() != "/") { - myBrowser->main()->reset(); + myBrowser->main().reset(); myBrowser->enterPressed(); } } @@ -791,17 +791,17 @@ void Delete::Run() Statusbar::msg("Item(s) deleted"); } # ifndef WIN32 - else if (myScreen == myBrowser && !myBrowser->main()->empty()) + else if (myScreen == myBrowser && !myBrowser->main().empty()) { if (!myBrowser->isLocal() && !isMPDMusicDirSet()) return; std::string question; - if (myBrowser->main()->hasSelected()) + if (myBrowser->main().hasSelected()) question = "Delete selected items?"; 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; question = "Delete "; question += itemTypeToString(item.type); @@ -813,7 +813,7 @@ void Delete::Run() if (yes) { 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) { const MPD::Item &i = (*it)->value(); @@ -948,7 +948,7 @@ void SavePlaylist::Run() } if (!myBrowser->isLocal() && myBrowser->CurrentDir() == "/" - && !myBrowser->main()->empty()) + && !myBrowser->main().empty()) myBrowser->GetDirectory(myBrowser->CurrentDir()); } @@ -1135,7 +1135,7 @@ void ToggleDisplayMode::Run() { Config.columns_in_browser = !Config.columns_in_browser; 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) { @@ -1452,8 +1452,8 @@ bool EditDirectoryName::canBeRun() const { return isMPDMusicDirSet() && ((myScreen == myBrowser - && !myBrowser->main()->empty() - && myBrowser->main()->current().value().type == MPD::itDirectory) + && !myBrowser->main().empty() + && myBrowser->main().current().value().type == MPD::itDirectory) # ifdef HAVE_TAGLIB_H || (myScreen->activeWindow() == myTagEditor->Dirs && !myTagEditor->Dirs->empty() @@ -1468,7 +1468,7 @@ void EditDirectoryName::Run() if (myScreen == myBrowser) { - std::string old_dir = myBrowser->main()->current().value().name; + std::string old_dir = myBrowser->main().current().value().name; Statusbar::lock(); Statusbar::put() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd; std::string new_dir = wFooter->getString(old_dir); @@ -1532,8 +1532,8 @@ bool EditPlaylistName::canBeRun() const return (myScreen->activeWindow() == myPlaylistEditor->Playlists && !myPlaylistEditor->Playlists->empty()) || (myScreen == myBrowser - && !myBrowser->main()->empty() - && myBrowser->main()->current().value().type == MPD::itPlaylist); + && !myBrowser->main().empty() + && myBrowser->main().current().value().type == MPD::itPlaylist); } void EditPlaylistName::Run() @@ -1544,7 +1544,7 @@ void EditPlaylistName::Run() if (myScreen->activeWindow() == myPlaylistEditor->Playlists) old_name = myPlaylistEditor->Playlists->current().value(); else - old_name = myBrowser->main()->current().value().name; + old_name = myBrowser->main().current().value().name; Statusbar::lock(); Statusbar::put() << NC::fmtBold << "Playlist: " << NC::fmtBoldEnd; std::string new_name = wFooter->getString(old_name); @@ -1596,12 +1596,12 @@ void JumpToMediaLibrary::Run() bool JumpToPlaylistEditor::canBeRun() const { return myScreen == myBrowser - && myBrowser->main()->current().value().type == MPD::itPlaylist; + && myBrowser->main().current().value().type == MPD::itPlaylist; } void JumpToPlaylistEditor::Run() { - myPlaylistEditor->Locate(myBrowser->main()->current().value().name); + myPlaylistEditor->Locate(myBrowser->main().current().value().name); } void ToggleScreenLock::Run() @@ -2087,7 +2087,7 @@ void ToggleBrowserSortMode::Run() Statusbar::msg("Sort songs by: Name"); 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)); } diff --git a/src/browser.cpp b/src/browser.cpp index f4b372e3..9f7ab520 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -63,13 +63,13 @@ bool BrowserEntryMatcher(const Regex &rx, const MPD::Item &item, bool filter); Browser::Browser() : itsBrowseLocally(0), itsScrollBeginning(0), itsBrowsedDir("/") { - w = new NC::Menu(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->cyclicScrolling(Config.use_cyclic_scrolling); - w->centeredCursor(Config.centered_cursor); - w->setSelectedPrefix(Config.selected_item_prefix); - w->setSelectedSuffix(Config.selected_item_suffix); - w->setItemDisplayer(Display::Items); + w = NC::Menu(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.cyclicScrolling(Config.use_cyclic_scrolling); + w.centeredCursor(Config.centered_cursor); + w.setSelectedPrefix(Config.selected_item_prefix); + w.setSelectedSuffix(Config.selected_item_suffix); + w.setItemDisplayer(Display::Items); if (SupportedExtensions.empty()) Mpd.GetSupportedExtensions(SupportedExtensions); @@ -79,9 +79,9 @@ void Browser::resize() { size_t x_offset, width; getWindowResizeParams(x_offset, width); - w->resize(width, MainHeight); - w->moveTo(x_offset, MainStartY); - w->setTitle(Config.columns_in_browser && Config.titles_visibility ? Display::Columns(w->getWidth()) : ""); + w.resize(width, MainHeight); + w.moveTo(x_offset, MainStartY); + w.setTitle(Config.columns_in_browser && Config.titles_visibility ? Display::Columns(w.getWidth()) : ""); hasToBeResized = 0; } @@ -106,7 +106,7 @@ void Browser::switchTo() if (isLocal() && Config.browser_sort_mode == smMTime) // local browser doesn't support sorting by mtime Config.browser_sort_mode = smName; - if (w->empty()) + if (w.empty()) myBrowser->GetDirectory(itsBrowsedDir); else markSongsInPlaylist(getProxySongList()); @@ -126,10 +126,10 @@ std::wstring Browser::title() void Browser::enterPressed() { - if (w->empty()) + if (w.empty()) return; - const MPD::Item &item = w->current().value(); + const MPD::Item &item = w.current().value(); switch (item.type) { case itDirectory: @@ -159,19 +159,19 @@ void Browser::enterPressed() void Browser::spacePressed() { - if (w->empty()) + if (w.empty()) return; size_t i = itsBrowsedDir != "/" ? 1 : 0; - if (Config.space_selects && w->choice() >= i) + if (Config.space_selects && w.choice() >= i) { - i = w->choice(); - w->at(i).setSelected(!w->at(i).isSelected()); - w->scroll(NC::wDown); + i = w.choice(); + w.at(i).setSelected(!w.at(i).isSelected()); + w.scroll(NC::wDown); return; } - const MPD::Item &item = w->current().value(); + const MPD::Item &item = w.current().value(); if (isParentDirectory(item)) return; @@ -212,40 +212,40 @@ void Browser::spacePressed() break; } } - w->scroll(NC::wDown); + w.scroll(NC::wDown); } 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; if (me.bstate & (BUTTON1_PRESSED | BUTTON3_PRESSED)) { - w->Goto(me.y); - switch (w->current().value().type) + w.Goto(me.y); + switch (w.current().value().type) { case itDirectory: if (me.bstate & BUTTON1_PRESSED) { - GetDirectory(w->current().value().name); + GetDirectory(w.current().value().name); drawHeader(); } else { - size_t pos = w->choice(); + size_t pos = w.choice(); spacePressed(); - if (pos < w->size()-1) - w->scroll(NC::wUp); + if (pos < w.size()-1) + w.scroll(NC::wUp); } break; case itPlaylist: case itSong: if (me.bstate & BUTTON1_PRESSED) { - size_t pos = w->choice(); + size_t pos = w.choice(); spacePressed(); - if (pos < w->size()-1) - w->scroll(NC::wUp); + if (pos < w.size()-1) + w.scroll(NC::wUp); } else enterPressed(); @@ -265,15 +265,15 @@ bool Browser::allowsFiltering() std::string Browser::currentFilter() { - return RegexFilter::currentFilter(*w); + return RegexFilter::currentFilter(w); } void Browser::applyFilter(const std::string &filter) { - w->showAll(); + w.showAll(); auto fun = std::bind(BrowserEntryMatcher, _1, _2, true); auto rx = RegexFilter(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 rx = RegexFilter(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) { - w->nextFound(wrap); + w.nextFound(wrap); } void Browser::prevFound(bool wrap) { - w->prevFound(wrap); + w.prevFound(wrap); } /***********************************************************************/ std::shared_ptr Browser::getProxySongList() { - return mkProxySongList(*w, [](NC::Menu::Item &item) -> MPD::Song * { + return mkProxySongList(w, [](NC::Menu::Item &item) -> MPD::Song * { MPD::Song *ptr = 0; if (item.value().type == itSong) ptr = item.value().song.get(); @@ -319,7 +319,7 @@ bool Browser::allowsSelection() void Browser::reverseSelection() { - reverseSelectionHelper(w->begin()+(itsBrowsedDir == "/" ? 0 : 1), w->end()); + reverseSelectionHelper(w.begin()+(itsBrowsedDir == "/" ? 0 : 1), w.end()); } MPD::SongList Browser::getSelectedSongs() @@ -351,12 +351,12 @@ MPD::SongList Browser::getSelectedSongs() 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()) item_handler(it->value()); // if no item is selected, add current one - if (result.empty() && !w->empty()) - item_handler(w->current().value()); + if (result.empty() && !w.empty()) + item_handler(w.current().value()); return result; } @@ -372,11 +372,11 @@ void Browser::LocateSong(const MPD::Song &s) if (itsBrowsedDir != 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; } } @@ -391,17 +391,17 @@ void Browser::GetDirectory(std::string dir, std::string subdir) int highlightme = -1; itsScrollBeginning = 0; if (itsBrowsedDir != dir) - w->reset(); + w.reset(); itsBrowsedDir = dir; - w->clear(); + w.clear(); if (dir != "/") { MPD::Item parent; parent.name = ".."; parent.type = itDirectory; - w->addItem(parent); + w.addItem(parent); } MPD::ItemList list; @@ -423,14 +423,14 @@ void Browser::GetDirectory(std::string dir, std::string subdir) { case itPlaylist: { - w->addItem(*it); + w.addItem(*it); break; } case itDirectory: { if (it->name == subdir) - highlightme = w->size(); - w->addItem(*it); + highlightme = w.size(); + w.addItem(*it); break; } case itSong: @@ -444,13 +444,13 @@ void Browser::GetDirectory(std::string dir, std::string subdir) break; } } - w->addItem(*it, bold); + w.addItem(*it, bold); break; } } } if (highlightme >= 0) - w->highlight(highlightme); + w.highlight(highlightme); } #ifndef WIN32 @@ -563,7 +563,7 @@ void Browser::ChangeBrowseMode() itsBrowsedDir = itsBrowseLocally ? Config.GetHomeDirectory() : "/"; if (itsBrowseLocally && *itsBrowsedDir.rbegin() == '/') itsBrowsedDir.resize(itsBrowsedDir.length()-1); - w->reset(); + w.reset(); GetDirectory(itsBrowsedDir); drawHeader(); } diff --git a/src/browser.h b/src/browser.h index b3078f05..3623817b 100644 --- a/src/browser.h +++ b/src/browser.h @@ -25,7 +25,7 @@ #include "mpdpp.h" #include "screen.h" -struct Browser : public Screen *>, public Filterable, public HasSongs, public Searchable +struct Browser : public Screen>, public Filterable, public HasSongs, public Searchable { Browser(); diff --git a/src/status.cpp b/src/status.cpp index 91de9803..d24a57c2 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -191,7 +191,7 @@ void Status::Changes::database() if (isVisible(myBrowser)) myBrowser->GetDirectory(myBrowser->CurrentDir()); else - myBrowser->main()->clear(); + myBrowser->main().clear(); # ifdef HAVE_TAGLIB_H myTagEditor->Dirs->clear(); # endif // HAVE_TAGLIB_H