2010-02-04 13:33:47 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
|
|
|
* massimiliano.torromeo@gmail.com *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#include "menusettingfile.h"
|
|
|
|
#include "filedialog.h"
|
|
|
|
#include "utilities.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace fastdelegate;
|
|
|
|
|
2010-05-02 15:29:09 +03:00
|
|
|
MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter)
|
2010-05-03 23:21:36 +03:00
|
|
|
: MenuSetting(gmenu2x,name,description)
|
|
|
|
{
|
|
|
|
IconButton *btn;
|
|
|
|
|
2010-02-04 13:33:47 +02:00
|
|
|
this->filter = filter;
|
|
|
|
_value = value;
|
|
|
|
originalValue = *value;
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]);
|
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingFile::clear));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
btn = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Select a file"]);
|
|
|
|
btn->setAction(MakeDelegate(this, &MenuSettingFile::select));
|
|
|
|
buttonBox.add(btn);
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingFile::draw(int y)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
MenuSetting::draw(y);
|
|
|
|
gmenu2x->s->write( gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingFile::manageInput()
|
|
|
|
{
|
|
|
|
if (gmenu2x->input[ACTION_X])
|
|
|
|
setValue("");
|
|
|
|
if (gmenu2x->input[ACTION_B])
|
|
|
|
select();
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingFile::clear()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
setValue("");
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingFile::select()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
FileDialog fd(gmenu2x, description, filter, value());
|
2010-05-03 23:21:36 +03:00
|
|
|
if (fd.exec())
|
|
|
|
setValue(fd.getPath()+"/"+fd.getFile());
|
2010-02-04 13:33:47 +02:00
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
void MenuSettingFile::setValue(const string &value)
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
*_value = value;
|
|
|
|
}
|
|
|
|
|
2010-05-03 23:21:36 +03:00
|
|
|
const string &MenuSettingFile::value()
|
|
|
|
{
|
2010-02-04 13:33:47 +02:00
|
|
|
return *_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MenuSettingFile::adjustInput() {}
|
|
|
|
|
|
|
|
bool MenuSettingFile::edited() {
|
|
|
|
return originalValue != value();
|
|
|
|
}
|