mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-12-27 07:03:19 +02:00
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().
This commit is contained in:
parent
1dec6f6f11
commit
0b785770dc
@ -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();
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ public:
|
||||
DirDialog(
|
||||
GMenu2X *gmenu2x, Touchscreen &ts,
|
||||
const std::string &text, const std::string &dir = "");
|
||||
~DirDialog();
|
||||
};
|
||||
|
||||
#endif // DIRDIALOG_H
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
};
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user