From 0b785770dc449b2c94e9910075dfb622520dce3a Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Wed, 13 Aug 2014 04:14:19 +0000 Subject: [PATCH] Use a plain FileLister instead of a pointer in BrowseDialog Configuration of the FileLister is now left to the subclasses of BrowseDialog, as the construction of a FileLister and its configuration (to show or hide directories and files) have been separated. This allows deleting the destructors of BrowseDialog's subclasses, which existed solely to delete a FileLister object constructed by each subclass. The allocation of a BrowseDialog now also implies allocating enough space for its FileLister, so remove the check for fl being nullptr in BrowseDialog::exec(). --- src/browsedialog.cpp | 29 +++++++++++++---------------- src/browsedialog.h | 6 +++--- src/dirdialog.cpp | 8 +------- src/dirdialog.h | 1 - src/filedialog.cpp | 10 ++-------- src/filedialog.h | 1 - src/imagedialog.cpp | 4 ++-- 7 files changed, 21 insertions(+), 38 deletions(-) diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index 174517b..5d9793d 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -48,9 +48,6 @@ BrowseDialog::~BrowseDialog() bool BrowseDialog::exec() { - if (!fl) - return false; - string path = getPath(); if (path.empty() || !fileExists(path) || path.compare(0, strlen(CARD_ROOT), CARD_ROOT) != 0) @@ -127,7 +124,7 @@ void BrowseDialog::handleInput() ts_pressed = false; } - if (action == BrowseDialog::ACT_SELECT && (*fl)[selected] == "..") { + if (action == BrowseDialog::ACT_SELECT && fl[selected] == "..") { action = BrowseDialog::ACT_GOUP; } switch (action) { @@ -136,7 +133,7 @@ void BrowseDialog::handleInput() break; case BrowseDialog::ACT_UP: if (selected == 0) - selected = fl->size() - 1; + selected = fl.size() - 1; else selected -= 1; break; @@ -147,14 +144,14 @@ void BrowseDialog::handleInput() selected -= numRows - 2; break; case BrowseDialog::ACT_DOWN: - if (fl->size() - 1 <= selected) + if (fl.size() - 1 <= selected) selected = 0; else selected += 1; break; case BrowseDialog::ACT_SCROLLDOWN: - if (selected+(numRows-2)>=fl->size()) - selected = fl->size()-1; + if (selected+(numRows-2)>=fl.size()) + selected = fl.size()-1; else selected += numRows-2; break; @@ -162,7 +159,7 @@ void BrowseDialog::handleInput() directoryUp(); break; case BrowseDialog::ACT_SELECT: - if (fl->isDirectory(selected)) { + if (fl.isDirectory(selected)) { directoryEnter(); break; } @@ -203,7 +200,7 @@ void BrowseDialog::directoryEnter() path += "/"; } - setPath(path + fl->at(selected)); + setPath(path + fl.at(selected)); selected = 0; } @@ -253,8 +250,8 @@ void BrowseDialog::paint() gmenu2x->skinConfColors[COLOR_SELECTION_BG]); lastElement = firstElement + numRows; - if (lastElement > fl->size()) - lastElement = fl->size(); + if (lastElement > fl.size()) + lastElement = fl.size(); offsetY = topBarHeight + 1; @@ -262,8 +259,8 @@ void BrowseDialog::paint() s.setClipRect(clipRect); for (i = firstElement; i < lastElement; i++) { Surface *icon; - if (fl->isDirectory(i)) { - if ((*fl)[i] == "..") { + if (fl.isDirectory(i)) { + if (fl[i] == "..") { icon = iconGoUp; } else { icon = iconFolder; @@ -272,7 +269,7 @@ void BrowseDialog::paint() icon = iconFile; } icon->blit(s, 5, offsetY); - gmenu2x->font->write(s, (*fl)[i], 24, offsetY + rowHeight / 2, + gmenu2x->font->write(s, fl[i], 24, offsetY + rowHeight / 2, Font::HAlignLeft, Font::VAlignMiddle); if (ts.available() && ts.pressed() @@ -285,6 +282,6 @@ void BrowseDialog::paint() } s.clearClipRect(); - gmenu2x->drawScrollBar(numRows,fl->size(), firstElement); + gmenu2x->drawScrollBar(numRows,fl.size(), firstElement); s.flip(); } diff --git a/src/browsedialog.h b/src/browsedialog.h index 56d04d3..ae2d3b8 100644 --- a/src/browsedialog.h +++ b/src/browsedialog.h @@ -41,10 +41,10 @@ protected: void setPath(const std::string &path) { this->path = path; - fl->browse(path); + fl.browse(path); } - FileLister *fl; + FileLister fl; unsigned int selected; private: @@ -98,7 +98,7 @@ public: return path; } std::string getFile() { - return (*fl)[selected]; + return fl[selected]; } }; diff --git a/src/dirdialog.cpp b/src/dirdialog.cpp index bababb3..1248280 100644 --- a/src/dirdialog.cpp +++ b/src/dirdialog.cpp @@ -29,12 +29,6 @@ DirDialog::DirDialog( const string &text, const string &dir) : BrowseDialog(gmenu2x, ts, "Directory Browser", text) { - fl = new FileLister(); - fl->setShowFiles(false); + fl.setShowFiles(false); setPath(dir); } - -DirDialog::~DirDialog() -{ - delete fl; -} diff --git a/src/dirdialog.h b/src/dirdialog.h index e7a2907..b956fcc 100644 --- a/src/dirdialog.h +++ b/src/dirdialog.h @@ -28,7 +28,6 @@ public: DirDialog( GMenu2X *gmenu2x, Touchscreen &ts, const std::string &text, const std::string &dir = ""); - ~DirDialog(); }; #endif // DIRDIALOG_H diff --git a/src/filedialog.cpp b/src/filedialog.cpp index 23e2f77..fafe6f4 100644 --- a/src/filedialog.cpp +++ b/src/filedialog.cpp @@ -37,19 +37,13 @@ FileDialog::FileDialog( path = file.substr(0, pos); } - fl = new FileLister(); - fl->setFilter(filter); + fl.setFilter(filter); setPath(path); } -FileDialog::~FileDialog() -{ - delete fl; -} - bool FileDialog::exec() { bool ret = BrowseDialog::exec(); - if (ret && fl->isDirectory(selected)) { + if (ret && fl.isDirectory(selected)) { // FileDialog must only pick regular files. ret = false; } diff --git a/src/filedialog.h b/src/filedialog.h index 51ae092..6383ee7 100644 --- a/src/filedialog.h +++ b/src/filedialog.h @@ -29,7 +29,6 @@ public: GMenu2X *gmenu2x, Touchscreen &ts, const std::string &text, const std::string &filter="*", const std::string &file="", const std::string &title = "File Dialog"); - virtual ~FileDialog(); bool exec(); }; diff --git a/src/imagedialog.cpp b/src/imagedialog.cpp index dbb6767..add6f06 100644 --- a/src/imagedialog.cpp +++ b/src/imagedialog.cpp @@ -54,8 +54,8 @@ ImageDialog::~ImageDialog() { } void ImageDialog::beforeFileList() { - if (fl->isFile(selected) && fileExists(getPath()+"/"+(*fl)[selected])) - previews[getPath()+"/"+(*fl)[selected]]->blitRight(*gmenu2x->s, 310, 43); + if (fl.isFile(selected) && fileExists(getPath()+"/"+fl[selected])) + previews[getPath()+"/"+fl[selected]]->blitRight(*gmenu2x->s, 310, 43); } void ImageDialog::onChangeDir() {