[DEV] rework ListFileSystem widget

This commit is contained in:
Edouard DUPIN 2014-01-04 17:20:46 +01:00
parent ab979adf2a
commit 0f6ed06350
7 changed files with 371 additions and 403 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit 45602989a0b3861ee7e36c80e1820c5557689734
Subproject commit b5883ad93675e97ba1ec9dee0bbc3026984b8d22

2
external/exml vendored

@ -1 +1 @@
Subproject commit a420811f5928bf2a972aace1df8898079dc43abf
Subproject commit 4b66ba43741c05d9ec8c2e644f90fd07fb9c9474

View File

@ -15,32 +15,57 @@
#undef __class__
#define __class__ "ListFileSystem"
static ewol::Widget* Create(void) {
return new ewol::widget::ListFileSystem();
}
void ewol::widget::ListFileSystem::init(ewol::widget::Manager& _widgetManager) {
_widgetManager.addWidgetCreator(__class__,&Create);
}
const char * const ewol::widget::ListFileSystem::eventFileSelect = "file-select";
const char * const ewol::widget::ListFileSystem::eventFileValidate = "file-validate";
const char * const ewol::widget::ListFileSystem::eventFolderSelect = "folder-select";
const char * const ewol::widget::ListFileSystem::eventFolderValidate = "folder-validate";
const char* const ewol::widget::ListFileSystem::configShowHidden = "show-hidden";
const char* const ewol::widget::ListFileSystem::configShowFile = "show-file";
const char* const ewol::widget::ListFileSystem::configShowFolder = "show-folder";
const char* const ewol::widget::ListFileSystem::configShowTemporary = "show-temporary";
const char* const ewol::widget::ListFileSystem::configPath = "path";
const char* const ewol::widget::ListFileSystem::configSelect = "select";
ewol::widget::ListFileSystem::ListFileSystem(void) {
ewol::widget::ListFileSystem::ListFileSystem(void) :
m_selectedLine(-1),
m_folder ("/"),
m_showFile(true),
m_showFolder(true),
m_showHidden(true),
m_showTemporaryFile(true) {
addObjectType("ewol::widget::ListFileSystem");
m_selectedLine = -1;
m_showFile = true;
m_showTemporaryFile = true;
m_showHidden = true;
m_showFolder = true;
#if defined(__TARGET_OS__Windows)
m_folder = "c:/";
#else
m_folder = "/";
#endif
addEventId(eventFileSelect);
addEventId(eventFileValidate);
addEventId(eventFolderSelect);
addEventId(eventFolderValidate);
registerConfig(configShowHidden, "bool", NULL, "Show the hidden element (file, folder, ...)");
registerConfig(configShowFile, "bool", NULL, "display files");
registerConfig(configShowFolder, "bool", NULL, "display folders");
registerConfig(configShowTemporary, "bool", NULL, "display temporary files");
registerConfig(configPath, "string", NULL, "Path to display");
registerConfig(configSelect, "string", NULL, "selection af a specific file");
setMouseLimit(1);
};
ewol::widget::ListFileSystem::~ListFileSystem(void) {
clearList();
};
void ewol::widget::ListFileSystem::clearList(void) {
for (size_t iii=0; iii<m_list.size(); iii++) {
if (NULL != m_list[iii]) {
delete(m_list[iii]);
@ -55,14 +80,7 @@ etk::Color<> ewol::widget::ListFileSystem::getBasicBG(void) {
void ewol::widget::ListFileSystem::regenerateView(void) {
// clean the list of files :
for (size_t iii=0; iii<m_list.size(); iii++) {
if (NULL != m_list[iii]) {
delete(m_list[iii]);
m_list[iii] = NULL;
}
}
clearList();
m_selectedLine = -1;
m_list.clear();
m_originScrooled.setValue(0,0);
@ -73,36 +91,7 @@ void ewol::widget::ListFileSystem::regenerateView(void) {
markToRedraw();
}
void ewol::widget::ListFileSystem::setShowHiddenFiles(bool _state) {
m_showHidden = _state;
regenerateView();
}
void ewol::widget::ListFileSystem::setShowTemporaryFiles(bool _state) {
m_showTemporaryFile = _state;
regenerateView();
}
void ewol::widget::ListFileSystem::setShowFiles(bool _state) {
m_showFile = _state;
regenerateView();
}
void ewol::widget::ListFileSystem::setShowFolder(bool _state) {
m_showFolder = _state;
regenerateView();
}
void ewol::widget::ListFileSystem::setFolder(std::string _newFolder) {
m_folder = _newFolder;
regenerateView();
}
std::string ewol::widget::ListFileSystem::getFolder(void) {
return m_folder;
}
std::string ewol::widget::ListFileSystem::getSelect(void) {
std::string ewol::widget::ListFileSystem::getSelect(void) const {
std::string tmpVal = "";
if (m_selectedLine >= 0) {
if (m_list[m_selectedLine] != NULL) {
@ -113,7 +102,7 @@ std::string ewol::widget::ListFileSystem::getSelect(void) {
}
// select the specific file
void ewol::widget::ListFileSystem::setSelect( std::string _data) {
void ewol::widget::ListFileSystem::setSelect(const std::string& _data) {
// remove selected line
m_selectedLine = -1;
// search the coresponding file :
@ -258,3 +247,67 @@ bool ewol::widget::ListFileSystem::onItemEvent(int32_t _IdInput,
return false;
}
bool ewol::widget::ListFileSystem::onSetConfig(const ewol::object::Config& _conf) {
if (true == ewol::widget::List::onSetConfig(_conf)) {
return true;
}
if (_conf.getConfig() == configShowHidden) {
setShowHidden(std::stob(_conf.getData()));
return true;
}
if (_conf.getConfig() == configShowFile) {
setShowFiles(std::stob(_conf.getData()));
return true;
}
if (_conf.getConfig() == configShowFolder) {
setShowFolder(std::stob(_conf.getData()));
return true;
}
if (_conf.getConfig() == configShowTemporary) {
setShowTemporaryFiles(std::stob(_conf.getData()));
return true;
}
if (_conf.getConfig() == configPath) {
setFolder(_conf.getData());
return true;
}
if (_conf.getConfig() == configSelect) {
setSelect(_conf.getData());
return true;
}
return false;
}
bool ewol::widget::ListFileSystem::onGetConfig(const char* _config, std::string& _result) const {
if (true == ewol::widget::List::onGetConfig(_config, _result)) {
return true;
}
if (_config == configShowHidden) {
_result = std::to_string(getShowHidden());
return true;
}
if (_config == configShowFile) {
_result = std::to_string(getShowFiles());
return true;
}
if (_config == configShowFolder) {
_result = std::to_string(getShowFolder());
return true;
}
if (_config == configShowTemporary) {
_result = std::to_string(getShowTemporaryFiles());
return true;
}
if (_config == configPath) {
_result = getFolder();
return true;
}
if (_config == configSelect) {
_result = getSelect();
return true;
}
return false;
}

View File

@ -12,50 +12,154 @@
#include <ewol/widget/List.h>
#include <etk/os/FSNode.h>
namespace ewol {
namespace widget {
/**
* @ingroup ewolWidgetGroup
* @brief Generic display folder class. This widget display the content of a single folder :
*/
class ListFileSystem : public ewol::widget::List {
public:
//! @not-in-doc
static void init(ewol::widget::Manager& _widgetManager);
// Event list of properties
static const char * const eventFileSelect;
static const char * const eventFileValidate;
static const char * const eventFileSelect; //!< @event "file-select" Generated when a file is selected.
static const char * const eventFileValidate; //!< @event "file-validate" Generate when the user validate (return) or double click on the element
static const char * const eventFolderSelect;
static const char * const eventFolderValidate;
private:
std::vector<etk::FSNode *> m_list;
std::string m_folder;
int32_t m_selectedLine;
bool m_showFile;
bool m_showTemporaryFile;
bool m_showFolder;
bool m_showHidden;
// Config list of properties
static const char* const configShowHidden; //!< @config "show-hidden"
static const char* const configShowFile;
static const char* const configShowFolder;
static const char* const configShowTemporary;
static const char* const configPath;
static const char* const configSelect;
// TODO : Add a standalone configuration ..
public:
ListFileSystem(void);
~ListFileSystem(void);
// Derived function
protected : // Derived function from the List...
virtual etk::Color<> getBasicBG(void);
uint32_t getNuberOfColomn(void);
bool getTitle(int32_t _colomn, std::string& _myTitle, etk::Color<>& _fg, etk::Color<>& _bg);
uint32_t getNuberOfRaw(void);
bool getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg);
bool onItemEvent(int32_t _IdInput, enum ewol::key::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y);
virtual uint32_t getNuberOfColomn(void);
virtual bool getTitle(int32_t _colomn, std::string& _myTitle, etk::Color<>& _fg, etk::Color<>& _bg);
virtual uint32_t getNuberOfRaw(void);
virtual bool getElement(int32_t _colomn, int32_t _raw, std::string& _myTextToWrite, etk::Color<>& _fg, etk::Color<>& _bg);
virtual bool onItemEvent(int32_t _IdInput, enum ewol::key::status _typeEvent, int32_t _colomn, int32_t _raw, float _x, float _y);
protected:
std::vector<etk::FSNode *> m_list; //!< List of all element in the path. (they are filtered)
/**
* @brief Clean the list of element.
*/
void clearList(void);
/**
* @brief Regenerate the content of the view. this is actually not automation on the system update.
*/
virtual void regenerateView(void);
protected:
int32_t m_selectedLine; //!< Current Line ID that is selected
public:
// extern API :
void setFolder(std::string _newFolder);
std::string getFolder(void);
// select the specific file
void setSelect(std::string _data);
std::string getSelect(void);
// regenerate the view ....
void regenerateView(void);
void setShowFiles(bool _state);
void setShowFolder(bool _state);
void setShowHiddenFiles(bool _state);
void setShowTemporaryFiles(bool _state);
/**
* @brief Select a specific file in the path
* @param[in] _data File to selested.
*/
virtual void setSelect(const std::string& _data);
/**
* @brief Get the current selected file/folder/... in the list
* @return the String of the element selected.
*/
std::string getSelect(void) const ;
protected:
std::string m_folder; //!< Current folder that display point on.
public:
/**
* @brief Set a folder to display (might be a valid folder !!!)
* @param[in] _newFolder Path on the folder to display content.
*/
void setFolder(const std::string& _newFolder) {
m_folder = _newFolder;
regenerateView();
};
/**
* @brief Get the element current displaying folder path.
* @return Path on the folder.
*/
const std::string& getFolder(void) const {
return m_folder;
};
protected:
bool m_showFile; //!< Show files elements
public:
/**
* @brief Set the status of the displaying files or Not.
* @param[in] _state New state to apply on display the 'file'.
*/
void setShowFiles(bool _state) {
m_showFile = _state;
regenerateView();
};
/**
* @brief Get the status of the displaying files or Not.
* @return The status on displaying the 'file'.
*/
bool getShowFiles(void) const {
return m_showFile;
};
protected:
bool m_showFolder; //!< Display the folders elements
public:
/**
* @brief Set the status of the displaying fodlers or Not.
* @param[in] _state New state to apply on display the 'folder'.
*/
void setShowFolder(bool _state) {
m_showFolder = _state;
regenerateView();
};
/**
* @brief Get the status of the displaying fodlers or Not.
* @return The status on displaying the 'folder'.
*/
bool getShowFolder(void) const {
return m_showFile;
};
protected:
bool m_showHidden; //!< Display hidden elements
public:
/**
* @brief Set the status of the displaying hidden files or folder or Not.
* @param[in] _state New state to apply on display the hidden element.
*/
void setShowHidden(bool _state) {
m_showHidden = _state;
regenerateView();
};
/**
* @brief Get the status of the displaying hidden files or folder or Not.
* @return The status on displaying the hidden element.
*/
bool getShowHidden(void) const {
return m_showFile;
};
protected:
bool m_showTemporaryFile; //!< show the temporary files elements (XXX~, XXX.bck, XXX.pyc ...)
public:
/**
* @brief Set the status of the displaying temporary file (xxx~, xxx.bck, xxx.pyc) or Not.
* @param[in] _state New state to apply on display temporary files.
*/
void setShowTemporaryFiles(bool _state) {
m_showTemporaryFile = _state;
regenerateView();
};
/**
* @brief Get the status of the displaying temporary file (xxx~, xxx.bck, xxx.pyc) or Not.
* @return The status on displaying temporary files.
*/
bool getShowTemporaryFiles(void) const {
return m_showFile;
};
public: // glocal derived functions
virtual bool onSetConfig(const ewol::object::Config& _conf);
virtual bool onGetConfig(const char* _config, std::string& _result) const;
};
};
};

View File

@ -25,6 +25,7 @@
#include <ewol/widget/Scroll.h>
#include <ewol/widget/PopUp.h>
#include <ewol/widget/WSlider.h>
#include <ewol/widget/ListFileSystem.h>
#include <vector>
#undef __class__
@ -58,6 +59,7 @@ ewol::widget::Manager::Manager(void) :
ewol::widget::ContextMenu::init(*this);
ewol::widget::PopUp::init(*this);
ewol::widget::WSlider::init(*this);
ewol::widget::ListFileSystem::init(*this);
}
ewol::widget::Manager::~Manager(void) {

View File

@ -49,21 +49,13 @@ ewol::widget::FileChooser::FileChooser(void) {
addEventId(eventCancel);
addEventId(eventValidate);
m_widgetTitle = NULL;
m_widgetValidate = NULL;
m_widgetCancel = NULL;
m_widgetCurrentFolder = NULL;
m_widgetCurrentFileName = NULL;
m_widgetListFolder = NULL;
m_widgetListFile = NULL;
m_widgetCheckBox = NULL;
ewol::widget::Sizer * mySizerVert = NULL;
ewol::widget::Sizer * mySizerHori = NULL;
ewol::widget::Spacer * mySpacer = NULL;
//ewol::widget::Label * myLabel = NULL;
ewol::widget::Image * myImage = NULL;
m_folder = etk::getUserHomeFolder();
/*
#if defined(__TARGET_OS__Android)
setMinSize(ewol::Dimension(vec2(90,90),ewol::Dimension::Pourcent));;
#elif defined(__TARGET_OS__Windows)
@ -71,222 +63,70 @@ ewol::widget::FileChooser::FileChooser(void) {
#else
setMinSize(ewol::Dimension(vec2(80,80),ewol::Dimension::Pourcent));;
#endif
m_file = "";
/*
SubWidgetSet(new ewol::widget::Composer(widget::Composer::String,
"<composer>\n"
" <sizer mode=\"vert\" lock=\"true\">\n"
" <sizer mode=\"hori\">\n"
" <checkbox name=\"EWOL:file-shooser:show-hiden-file\"/>\n"
" <label>Show hiden files</label>\n"
" <spacer expand=\"true,false\"/>\n"
" <button name=\"EWOL:file-shooser:button-validate\">\n"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:Load.svg\" fill=\"true\" size=\"70,70mm\"/>\n"
" <label>Validate</label>\n"
" </sizer>\n"
" </button>\n"
" <button name=\"EWOL:file-shooser:button-cancel\">\n"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:Remove.svg\" fill=\"true\" size=\"70,70mm\"/>\n"
" <label>Cancel</label>\n"
" </sizer>\n"
" </button>\n"
" </sizer>\n"
" <sizer mode=\"hori\">\n"
" <spacer min-size=\"2,2mm\"/>\n"
" <ListFileSystem name=\"EWOL:file-shooser:list-folder\" min-size=\"20,0%\" expand=\"false,true\"/>\n"
" <spacer min-size=\"2,2mm\"/>\n"
" <ListFileSystem name=\"EWOL:file-shooser:list-files\" expand=\"true,true\"/>\n"
" <spacer min-size=\"2,2mm\"/>\n"
" </sizer>\n"
" <sizer mode=\"hori\">\n"
" \n"
" </sizer>\n"
" </sizer>\n"
"</composer\n"));
*/
mySizerVert = new ewol::widget::Sizer(ewol::widget::Sizer::modeVert);
if (NULL == mySizerVert) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->lockExpand(bvec2(true,true));
mySizerVert->setExpand(bvec2(true,true));
// set it in the pop-up-system :
setSubWidget(mySizerVert);
mySizerHori = new ewol::widget::Sizer(ewol::widget::Sizer::modeHori);
if (NULL == mySizerHori) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->subWidgetAdd(mySizerHori);
m_widgetCheckBox = new ewol::widget::CheckBox("Show hiden files");
if (NULL == m_widgetCheckBox) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetCheckBox->registerOnEvent(this, "clicked", ewolEventFileChooserHidenFileChange);
m_widgetCheckBox->setValue(false);
mySizerHori->subWidgetAdd(m_widgetCheckBox);
}
mySpacer = new ewol::widget::Spacer();
if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySpacer->setExpand(bvec2(true,false));
mySizerHori->subWidgetAdd(mySpacer);
}
m_widgetValidate = new ewol::widget::Button();
if (NULL == m_widgetValidate) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetValidate->setSubWidget(
new ewol::widget::Composer(widget::Composer::String,
"<composer>\n"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:Load.svg\" expand=\"true\" size=\"8,8mm\"/>\n"
" <label>Validate</label>\n"
" </sizer>\n"
"</composer>\n"));
m_widgetValidate->registerOnEvent(this, "pressed", eventValidate);
mySizerHori->subWidgetAdd(m_widgetValidate);
}
m_widgetCancel = new ewol::widget::Button();
if (NULL == m_widgetCancel) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetCancel->setSubWidget(
new ewol::widget::Composer(widget::Composer::String,
"<composer>\n"
" <sizer mode=\"hori\">\n"
" <image src=\"THEME:GUI:Remove.svg\" expand=\"true\" size=\"8,8mm\"/>\n"
" <label>Cancel</label>\n"
" </sizer>\n"
"</composer>\n"));
m_widgetCancel->registerOnEvent(this, "pressed", eventCancel);
mySizerHori->subWidgetAdd(m_widgetCancel);
}
}
mySizerHori = new ewol::widget::Sizer(widget::Sizer::modeHori);
if (NULL == mySizerHori) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->subWidgetAdd(mySizerHori);
mySpacer = new ewol::widget::Spacer();
if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySpacer->setMinSize(vec2(2,2));
mySizerHori->subWidgetAdd(mySpacer);
}
m_widgetListFolder = new ewol::widget::ListFileSystem();
if (NULL == m_widgetListFolder) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetListFolder->setShowFolder(true);
m_widgetListFolder->setShowFiles(false);
m_widgetListFolder->setShowHiddenFiles(false);
m_widgetListFolder->registerOnEvent(this, "folder-validate", ewolEventFileChooserListFolder);
m_widgetListFolder->setExpand(bvec2(false,true));
m_widgetListFolder->setFill(bvec2(false,true));
mySizerHori->subWidgetAdd(m_widgetListFolder);
}
mySpacer = new ewol::widget::Spacer();
if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySpacer->setMinSize(vec2(2,2));
mySizerHori->subWidgetAdd(mySpacer);
}
m_widgetListFile = new ewol::widget::ListFileSystem();
if (NULL == m_widgetListFile) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetListFile->setShowFolder(false);
m_widgetListFile->setShowFiles(true);
m_widgetListFile->setShowHiddenFiles(false);
m_widgetListFile->registerOnEvent(this, "file-select", ewolEventFileChooserListFile);
m_widgetListFile->registerOnEvent(this, "file-validate", ewolEventFileChooserListFileValidate);
m_widgetListFile->setExpand(bvec2(true,true));
m_widgetListFile->setFill(bvec2(true,true));
mySizerHori->subWidgetAdd(m_widgetListFile);
}
mySpacer = new ewol::widget::Spacer();
if (NULL == mySpacer) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySpacer->setMinSize(vec2(2,2));
mySizerHori->subWidgetAdd(mySpacer);
}
}
mySizerHori = new ewol::widget::Sizer(widget::Sizer::modeHori);
if (NULL == mySizerHori) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->subWidgetAdd(mySizerHori);
myImage = new ewol::widget::Image("THEME:GUI:File.svg", ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter));
if (NULL == myImage) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
//myImage->setImageSize(ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter));
myImage->setExpand(bvec2(false,false));
mySizerHori->subWidgetAdd(myImage);
}
m_widgetCurrentFileName = new ewol::widget::Entry(m_file);
if (NULL == m_widgetCurrentFileName) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetCurrentFileName->registerOnEvent(this, "modify", ewolEventFileChooserEntryFile);
m_widgetCurrentFileName->registerOnEvent(this, "enter", ewolEventFileChooserEntryFileEnter);
m_widgetCurrentFileName->setExpand(bvec2(true,false));
m_widgetCurrentFileName->setFill(bvec2(true,false));
//m_widgetCurrentFileName->setWidth(200);
mySizerHori->subWidgetAdd(m_widgetCurrentFileName);
}
}
mySizerHori = new ewol::widget::Sizer(widget::Sizer::modeHori);
if (NULL == mySizerHori) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->subWidgetAdd(mySizerHori);
myImage = new ewol::widget::Image("THEME:GUI:Folder.svg", ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter));
if (NULL == myImage) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
//myImage->setImageSize(ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter));
myImage->setExpand(bvec2(false,false));
mySizerHori->subWidgetAdd(myImage);
}
m_widgetCurrentFolder = new ewol::widget::Entry(m_folder);
if (NULL == m_widgetCurrentFolder) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
m_widgetCurrentFolder->registerOnEvent(this, "modify", ewolEventFileChooserEntryFolder);
m_widgetCurrentFolder->registerOnEvent(this, "enter", ewolEventFileChooserEntryFolderEnter);
m_widgetCurrentFolder->setExpand(bvec2(true,false));
m_widgetCurrentFolder->setFill(bvec2(true,false));
//m_widgetCurrentFolder->setWidth(200);
mySizerHori->subWidgetAdd(m_widgetCurrentFolder);
}
myImage = new ewol::widget::Image("THEME:GUI:Home.svg", ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter));
if (NULL == myImage) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
//myImage->setImageSize(ewol::Dimension(vec2(8,8),ewol::Dimension::Millimeter));
myImage->registerOnEvent(this, "pressed", ewolEventFileChooserHome);
myImage->setExpand(bvec2(false,false));
mySizerHori->subWidgetAdd(myImage);
}
}
m_widgetTitle = new ewol::widget::Label("File chooser ...");
if (NULL == m_widgetTitle) {
EWOL_ERROR("Can not allocate widget == > display might be in error");
} else {
mySizerVert->subWidgetAdd(m_widgetTitle);
}
}
m_file = "";
std::string myDescription = std::string("")
+ "<popup >\n"
+ " <sizer mode='vert' lock='true' fill='true' expand='true'>\n"
+ " <sizer mode='hori'>\n"
+ " <checkbox name='[" + std::to_string(getId()) + "]file-shooser:show-hiden-file'/>\n"
+ " <label>Show hiden files</label>\n"
+ " <spacer expand='true,false'/>\n"
+ " <button name='[" + std::to_string(getId()) + "]file-shooser:button-validate'>\n"
+ " <sizer mode='hori'>\n"
+ " <image src='THEME:GUI:Load.svg' fill='true' size='7,7mm'/>\n"
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:validate-label'>Validate</label>\n"
+ " </sizer>\n"
+ " </button>\n"
+ " <button name='[" + std::to_string(getId()) + "]file-shooser:button-cancel'>\n"
+ " <sizer mode='hori'>\n"
+ " <image src='THEME:GUI:Remove.svg' fill='true' size='7,7mm'/>\n"
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:cancel-label'>Cancel</label>\n"
+ " </sizer>\n"
+ " </button>\n"
+ " </sizer>\n"
+ " <sizer mode='hori'>\n"
+ " <spacer min-size='2,2mm'/>\n"
+ " <ListFileSystem name='[" + std::to_string(getId()) + "]file-shooser:list-folder'\n"
+ " min-size='20,0%'\n"
+ " expand='false,true'\n"
+ " show-hidden='false'\n"
+ " show-file='false'\n"
+ " show-folder='true'\n"
+ " show-temporary='false'/>\n"
+ " <spacer min-size='2,2mm'/>\n"
+ " <ListFileSystem name='[" + std::to_string(getId()) + "]file-shooser:list-files'\n"
+ " expand='true,true'\n"
+ " show-hidden='false'\n"
+ " show-file='true'\n"
+ " show-folder='false'\n"
+ " show-temporary='false'/>\n"
+ " <spacer min-size='2,2mm'/>\n"
+ " </sizer>\n"
+ " <sizer mode='hori'>\n"
+ " <image name='[" + std::to_string(getId()) + "]file-shooser:img-file' src='THEME:GUI:File.svg' expand='false' size='8,8mm'/>\n"
+ " <entry name='[" + std::to_string(getId()) + "]file-shooser:entry-file' expand='true,false' fill='true,false'/>\n"
+ " </sizer>\n"
+ " <sizer mode='hori'>\n"
+ " <image name='[" + std::to_string(getId()) + "]file-shooser:img-folder' src='THEME:GUI:Folder.svg' expand='false' size='8,8mm'/>\n"
+ " <entry name='[" + std::to_string(getId()) + "]file-shooser:entry-folder' expand='true,false' fill='true,false'/>\n"
+ " <image name='[" + std::to_string(getId()) + "]file-shooser:img-home' src='THEME:GUI:Home.svg' expand='false' size='8,8mm'/>\n"
+ " </sizer>\n"
+ " <label name='[" + std::to_string(getId()) + "]file-shooser:title-label'>File chooser ...</label>\n"
+ " </sizer>\n"
+ "</popup>";
loadFromString(myDescription);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:show-hiden-file", "clicked", ewolEventFileChooserHidenFileChange);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:button-validate", "pressed", eventValidate);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:button-cancel", "pressed", eventCancel);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:list-folder", "folder-validate", ewolEventFileChooserListFolder);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:list-files", "file-select", ewolEventFileChooserListFile);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:list-files", "file-validate", ewolEventFileChooserListFileValidate);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:entry-file", "modify", ewolEventFileChooserEntryFile);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:entry-file", "enter", ewolEventFileChooserEntryFileEnter);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:entry-folder", "modify", ewolEventFileChooserEntryFolder);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:entry-folder", "enter", ewolEventFileChooserEntryFolderEnter);
registerOnEventNameWidget("[" + std::to_string(getId()) + "]file-shooser:img-home", "pressed", ewolEventFileChooserHome);
// set the default Folder properties:
updateCurrentFolder();
}
@ -297,30 +137,15 @@ ewol::widget::FileChooser::~FileChooser(void) {
}
void ewol::widget::FileChooser::setTitle(const std::string& _label) {
if (NULL == m_widgetTitle) {
return;
}
m_widgetTitle->setLabel(_label);
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:title-label", "value", _label);
}
void ewol::widget::FileChooser::setValidateLabel(const std::string& _label) {
if (NULL == m_widgetValidate) {
return;
}
// TODO : set if back :
/*
m_widgetValidate->setLabel(label);
*/
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:validate-label", "value", _label);
}
void ewol::widget::FileChooser::setCancelLabel(const std::string& _label) {
if (NULL == m_widgetCancel) {
return;
}
// TODO : set if back :
/*
m_widgetCancel->setLabel(label);
*/
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:cancel-label", "value", _label);
}
void ewol::widget::FileChooser::setFolder(const std::string& _folder) {
@ -330,10 +155,7 @@ void ewol::widget::FileChooser::setFolder(const std::string& _folder) {
void ewol::widget::FileChooser::setFileName(const std::string& _filename) {
m_file = _filename;
if (NULL == m_widgetCurrentFileName) {
return;
}
m_widgetCurrentFileName->setValue(_filename);
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:entry-file", "value", _filename);
}
void ewol::widget::FileChooser::onReceiveMessage(const ewol::object::Message& _msg) {
@ -344,29 +166,19 @@ void ewol::widget::FileChooser::onReceiveMessage(const ewol::object::Message& _m
} else if (ewolEventFileChooserEntryFile == _msg.getMessage()) {
// == > change the file name
m_file = _msg.getData();
// update the selected file in the list :
if (m_widgetListFile != NULL) {
m_widgetListFile->setSelect(m_file);
}
// update the selected file in the list :
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-files", "select", m_file);
} else if (eventCancel == _msg.getMessage()) {
// == > Auto remove ...
generateEventId(_msg.getMessage());
autoDestroy();
} else if (ewolEventFileChooserHidenFileChange == _msg.getMessage()) {
if (_msg.getData() == "true") {
if (NULL!=m_widgetListFolder) {
m_widgetListFolder->setShowHiddenFiles(true);
}
if (NULL!=m_widgetListFile) {
m_widgetListFile->setShowHiddenFiles(true);
}
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-folder", "show-hidden", "true");
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-files", "show-hidden", "true");
} else {
if (NULL!=m_widgetListFolder) {
m_widgetListFolder->setShowHiddenFiles(false);
}
if (NULL!=m_widgetListFile) {
m_widgetListFile->setShowHiddenFiles(false);
}
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-folder", "show-hidden", "false");
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-files", "show-hidden", "false");
}
} else if (ewolEventFileChooserListFolder == _msg.getMessage()) {
// == > this is an internal event ...
@ -411,15 +223,9 @@ void ewol::widget::FileChooser::updateCurrentFolder(void) {
m_folder += "/";
}
}
if (NULL != m_widgetListFile) {
m_widgetListFile->setFolder(m_folder);
}
if (NULL != m_widgetListFolder) {
m_widgetListFolder->setFolder(m_folder);
}
if (NULL != m_widgetCurrentFolder) {
m_widgetCurrentFolder->setValue(m_folder);
}
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-files", "path", m_folder);
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:list-folder", "path", m_folder);
setConfigNamed("[" + std::to_string(getId()) + "]file-shooser:entry-folder", "value", m_folder);
markToRedraw();
}
@ -429,39 +235,3 @@ std::string ewol::widget::FileChooser::getCompleateFileName(void) {
tmpString += m_file;
return tmpString;
}
/**
* @brief Inform object that an other object is removed ...
* @param[in] removeObject Pointer on the EObject remeved == > the user must remove all reference on this EObject
* @note : Sub classes must call this class
*/
void ewol::widget::FileChooser::onObjectRemove(ewol::Object * removeObject) {
// First step call parrent :
ewol::widget::PopUp::onObjectRemove(removeObject);
// second step find if in all the elements ...
if(removeObject == m_widgetTitle) {
m_widgetTitle = NULL;
}
if(removeObject == m_widgetValidate) {
m_widgetValidate = NULL;
}
if(removeObject == m_widgetCancel) {
m_widgetCancel = NULL;
}
if(removeObject == m_widgetCurrentFolder) {
m_widgetCurrentFolder = NULL;
}
if(removeObject == m_widgetCurrentFileName) {
m_widgetCurrentFileName = NULL;
}
if(removeObject == m_widgetListFolder) {
m_widgetListFolder = NULL;
}
if(removeObject == m_widgetListFile) {
m_widgetListFile = NULL;
}
if(removeObject == m_widgetCheckBox) {
m_widgetCheckBox = NULL;
}
}

View File

@ -11,19 +11,67 @@
#include <etk/types.h>
#include <ewol/debug.h>
#include <ewol/widget/PopUp.h>
#include <ewol/widget/Button.h>
#include <ewol/widget/Entry.h>
#include <ewol/widget/Label.h>
#include <ewol/widget/CheckBox.h>
#include <ewol/widget/ListFileSystem.h>
#include <ewol/widget/Composer.h>
namespace ewol {
namespace widget {
/**
* @ingroup ewolWidgetGroup
* @brief File Chooser is a simple selector of file for opening, saving, and what you want ...
*
* As all other pop-up methode ( wost case we can have) the creating is simple , but event back is not all the time simple:
*
* Fist global static declaration and inclusion:
* [code style=c++]
* #include <ewol/widget/meta/FileChooser.h>
* static const char* const g_eventOpenFile = "appl-local-event-open-file";
* static const char* const g_eventClosePopUp = "appl-local-event-close-pop-up";
* [/code]
*
* The first step is to create the file chooser pop-up :
* [code style=c++]
* ewol::widget::FileChooser* tmpWidget = new ewol::widget::FileChooser();
* if (tmpWidget == NULL) {
* APPL_ERROR("Can not open File chooser !!! ");
* return -1;
* }
* // register on the Validate event:
* tmpWidget->registerOnEvent(this, "validate", g_eventOpenFile);
* // no need of this event watching ...
* tmpWidget->registerOnEvent(this, "cancel", g_eventClosePopUp);
* // set the title:
* tmpWidget->setTitle("Open files ...");
* // Set the validate Label:
* tmpWidget->setValidateLabel("Open");
* // simply set a folder (by default this is the home folder)
* //tmpWidget->setFolder("/home/me");
* // add the widget as windows pop-up ...
* ewol::widget::Widows* tmpWindows = getWindows();
* if (tmpWindows == NULL) {
* APPL_ERROR("Can not get the current windows !!! ");
* return -1;
* }
* tmpWindows->popUpWidgetPush(tmpWidget);
* [/code]
*
* Now we just need to wait the the open event message.
*
* [code style=c++]
* void ********::onReceiveMessage(const ewol::object::Message& _msg) {
* APPL_DEBUG("Receive Message: " << _msg );
* if (_msg.getMessage() == g_eventOpenFile) {
* APPL_INFO("Request open file : '" << _msg.getData() << "'");
* return;
* }
* if (_msg.getMessage() == g_eventClosePopUp) {
* APPL_INFO("The File chooser has been closed");
* // generaly nothing to do ...
* return;
* }
* }
* [/code]
* This is the best example of a Meta-widget.
*/
class FileChooser : public ewol::widget::PopUp {
class FileChooser : public ewol::widget::Composer {
public:
// Event list of properties
static const char* const eventCancel;
@ -33,14 +81,6 @@ namespace ewol {
FileChooser(void);
virtual ~FileChooser(void);
private:
ewol::widget::Label* m_widgetTitle;
ewol::widget::Button* m_widgetValidate;
ewol::widget::Button* m_widgetCancel;
ewol::widget::Entry* m_widgetCurrentFolder;
ewol::widget::Entry* m_widgetCurrentFileName;
ewol::widget::ListFileSystem* m_widgetListFolder;
ewol::widget::ListFileSystem* m_widgetListFile;
ewol::widget::CheckBox* m_widgetCheckBox;
std::string m_folder;
std::string m_file;
public:
@ -53,7 +93,6 @@ namespace ewol {
void updateCurrentFolder(void);
public: // Derived function
virtual void onReceiveMessage(const ewol::object::Message& _msg);
virtual void onObjectRemove(ewol::Object* _removeObject);
};
};
};