From 7bce71d2dbc9cdaabbc3283d3e10e1f72b63c67b Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Fri, 13 Jul 2012 18:12:59 +0200 Subject: [PATCH] Change the open file system with a simplest system --- Sources/libetk/etk/tool.cpp | 18 + Sources/libetk/etk/tool.h | 2 + Sources/libewol/ewol/widget/CheckBox.cpp | 1 + .../libewol/ewol/widget/ListFileSystem.cpp | 359 +++++++++++++ Sources/libewol/ewol/widget/ListFileSystem.h | 113 +++++ .../libewol/ewol/widgetMeta/FileChooser.cpp | 475 ++---------------- Sources/libewol/ewol/widgetMeta/FileChooser.h | 21 +- Sources/libewol/file.mk | 1 + 8 files changed, 555 insertions(+), 435 deletions(-) create mode 100644 Sources/libewol/ewol/widget/ListFileSystem.cpp create mode 100644 Sources/libewol/ewol/widget/ListFileSystem.h diff --git a/Sources/libetk/etk/tool.cpp b/Sources/libetk/etk/tool.cpp index 10a58607..1dc7fe47 100644 --- a/Sources/libetk/etk/tool.cpp +++ b/Sources/libetk/etk/tool.cpp @@ -38,3 +38,21 @@ int32_t etk::tool::irand(int32_t a, int32_t b) return (int32_t)(( rand()/(float)RAND_MAX ) * ((float)b-(float)a) + (float)a); } + +void etk::tool::SortList(etk::VectorType &m_listDirectory) +{ + etk::VectorType tmpList = m_listDirectory; + m_listDirectory.Clear(); + for(int32_t iii=0; iii *m_listDirectory[jjj]) { + findPos = jjj+1; + } + } + //EWOL_DEBUG("position="< +#include namespace etk { namespace tool { float frand(float a, float b); int32_t irand(int32_t a, int32_t b); + void SortList(etk::VectorType &m_listDirectory); }; }; diff --git a/Sources/libewol/ewol/widget/CheckBox.cpp b/Sources/libewol/ewol/widget/CheckBox.cpp index ec4340c9..8a1f2199 100644 --- a/Sources/libewol/ewol/widget/CheckBox.cpp +++ b/Sources/libewol/ewol/widget/CheckBox.cpp @@ -42,6 +42,7 @@ void ewol::CheckBox::Init(void) m_textColorBg = etk::color::color_White; m_value = false; SetCanHaveFocus(true); + SetMouseLimit(1); } ewol::CheckBox::CheckBox(void) diff --git a/Sources/libewol/ewol/widget/ListFileSystem.cpp b/Sources/libewol/ewol/widget/ListFileSystem.cpp new file mode 100644 index 00000000..8865e094 --- /dev/null +++ b/Sources/libewol/ewol/widget/ListFileSystem.cpp @@ -0,0 +1,359 @@ +/** + ******************************************************************************* + * @file ewol/widget/ListFile.cpp + * @brief ewol File lister widget system (Sources) + * @author Edouard DUPIN + * @date 12/07/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#include +#include + +extern "C" { + // file browsing ... + #include +} + +#undef __class__ +#define __class__ "ListFileSystem" + +extern const char * const ewolEventFSFileSelect = "ewol-event-file-system-file-select"; +extern const char * const ewolEventFSFileValidate = "ewol-event-file-system-file-validate"; +extern const char * const ewolEventFSFolderSelect = "ewol-event-file-system-folder-select"; +extern const char * const ewolEventFSFolderValidate = "ewol-event-file-system-folder-validate"; + +//!< EObject name : +extern const char * const TYPE_EOBJECT_WIDGET_FILE_LIST = "FileChooserFileList"; + + + +static void SortElementList(etk::VectorType &list) +{ + etk::VectorType tmpList = list; + list.Clear(); + for(int32_t iii=0; iiim_name > list[jjj]->m_name) { + findPos = jjj+1; + } + } + } + //EWOL_DEBUG("position="<d_type) { + if (ent->d_name != NULL) { + etk::UString tmpString(ent->d_name); + if( false==tmpString.StartWith(".") + || true ==m_showHidden) { + tmpEmement = new ewol::elementFS(tmpString, ewol::EFS_FILE); + if (NULL != tmpEmement) { + m_list.PushBack(tmpEmement); + } + tmpEmement = NULL; + } + } + } + if( true==m_showFolder + && DT_DIR==ent->d_type) { + if (ent->d_name != NULL) { + etk::UString tmpString(ent->d_name); + //EWOL_DEBUG(" find Folder : \"" << tmpString << "\"(" << tmpString.Size() << ") ?= \"" << ent->d_name << "\"(" << strlen(ent->d_name) ); + if (tmpString != "." && tmpString != "..") { + if( false==tmpString.StartWith(".") + || true ==m_showHidden) { + tmpEmement = new ewol::elementFS(tmpString, ewol::EFS_FOLDER); + if (NULL != tmpEmement) { + m_list.PushBack(tmpEmement); + } + tmpEmement = NULL; + } + } + } + } + } + closedir(dir); + } else { + EWOL_ERROR("could not open directory : \"" << m_folder << "\""); + } + + // reorder the files + SortElementList(m_list); + // request a redraw ... + MarkToReedraw(); +} + +void ewol::ListFileSystem::SetShowHiddenFiles(bool state) +{ + m_showHidden = state; + RegenerateView(); +} + +void ewol::ListFileSystem::SetShowTemporaryFiles(bool state) +{ + m_showTemporaryFile = state; + RegenerateView(); +} + +void ewol::ListFileSystem::SetShowFiles(bool state) +{ + m_showFile = state; + RegenerateView(); +} + +void ewol::ListFileSystem::SetShowFolder(bool state) +{ + m_showFolder = state; + RegenerateView(); +} + + +void ewol::ListFileSystem::SetFolder(etk::UString newFolder) +{ + m_folder = newFolder; + RegenerateView(); +} + + +etk::UString ewol::ListFileSystem::GetFolder(void) +{ + return m_folder; +} + + +etk::UString ewol::ListFileSystem::GetSelect(void) +{ + etk::UString tmpVal = ""; + if (m_selectedLine >= 0) { + if (m_list[m_selectedLine] != NULL) { + tmpVal = m_list[m_selectedLine]->m_name; + } + } + return tmpVal; +} + +// select the specific file +void ewol::ListFileSystem::SetSelect( etk::UString data) { + // remove selected line + m_selectedLine = -1; + // search the coresponding file : + for (int32_t iii=0; iiim_name == data) { + // we find the line : + m_selectedLine = iii; + break; + } + } + } + MarkToReedraw(); +} + +uint32_t ewol::ListFileSystem::GetNuberOfColomn(void) { + return 1; +}; +bool ewol::ListFileSystem::GetTitle(int32_t colomn, etk::UString &myTitle, color_ts &fg, color_ts &bg) { + myTitle = "title"; + return true; +}; +uint32_t ewol::ListFileSystem::GetNuberOfRaw(void) { + return m_list.Size(); +}; +bool ewol::ListFileSystem::GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, color_ts &fg, color_ts &bg) { + if (raw >= 0 && raw < m_list.Size() && NULL != m_list[raw]) { + myTextToWrite = m_list[raw]->m_name; + } else { + myTextToWrite = "ERROR"; + } + fg = etk::color::color_Black; + if (raw % 2) { + bg = 0xFFFFFF00; + } else { + bg = 0xBFBFBFFF; + } + if (m_selectedLine == raw) { + bg = 0x8F8FFFFF; + } + return true; +}; + +bool ewol::ListFileSystem::OnItemEvent(int32_t IdInput, ewol::eventInputType_te typeEvent, int32_t colomn, int32_t raw, float x, float y) { + if (typeEvent == ewol::EVENT_INPUT_TYPE_SINGLE) { + EWOL_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw ); + if (1 == IdInput) { + if (raw > m_list.Size() ) { + m_selectedLine = -1; + } else { + m_selectedLine = raw; + } + // need to regenerate the display of the list : + MarkToReedraw(); + if (m_selectedLine >=0 ) { + // generate event extern : + switch(m_list[m_selectedLine]->m_type) + { + case ewol::EFS_FILE : + GenerateEventId(ewolEventFSFileSelect, m_list[m_selectedLine]->m_name); + break; + case ewol::EFS_FOLDER : + GenerateEventId(ewolEventFSFolderSelect, m_list[m_selectedLine]->m_name); + break; + default: + EWOL_ERROR("Can not generate event on an unknow type"); + break; + } + } + return true; + } + } + if (typeEvent == ewol::EVENT_INPUT_TYPE_DOUBLE) { + EWOL_INFO("Event Double on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw ); + if (1 == IdInput) { + if (m_selectedLine >=0 ) { + switch(m_list[m_selectedLine]->m_type) + { + case ewol::EFS_FILE : + GenerateEventId(ewolEventFSFileValidate, m_list[m_selectedLine]->m_name); + break; + case ewol::EFS_FOLDER : + GenerateEventId(ewolEventFSFolderValidate, m_list[m_selectedLine]->m_name); + break; + default: + EWOL_ERROR("Can not generate event on an unknow type"); + break; + } + return true; + } + } + } + return false; +} + +/** + * @brief Check if the object has the specific type. + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type of the object we want to check + * @return true if the object is compatible, otherwise false + */ +bool ewol::ListFileSystem::CheckObjectType(const char * const objectType) +{ + if (NULL == objectType) { + EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_FILE_LIST << "\" != NULL(pointer) "); + return false; + } + if (objectType == TYPE_EOBJECT_WIDGET_FILE_LIST) { + return true; + } else { + if(true == ewol::List::CheckObjectType(objectType)) { + return true; + } + EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_FILE_LIST << "\" != \"" << objectType << "\""); + return false; + } +} + +/** + * @brief Get the current Object type of the EObject + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type description + * @return true if the object is compatible, otherwise false + */ +const char * const ewol::ListFileSystem::GetObjectType(void) +{ + return TYPE_EOBJECT_WIDGET_FILE_LIST; +} + diff --git a/Sources/libewol/ewol/widget/ListFileSystem.h b/Sources/libewol/ewol/widget/ListFileSystem.h new file mode 100644 index 00000000..033102d2 --- /dev/null +++ b/Sources/libewol/ewol/widget/ListFileSystem.h @@ -0,0 +1,113 @@ +/** + ******************************************************************************* + * @file ewol/widget/ListFile.h + * @brief ewol File lister widget system (header) + * @author Edouard DUPIN + * @date 12/07/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_LIST_FILE_H__ +#define __EWOL_LIST_FILE_H__ + +#include + +extern const char * const ewolEventFSFileSelect; +extern const char * const ewolEventFSFileValidate; +extern const char * const ewolEventFSFolderSelect; +extern const char * const ewolEventFSFolderValidate; + +//!< EObject name : +extern const char * const TYPE_EOBJECT_WIDGET_FILE_LIST; + +namespace ewol { + typedef enum { + EFS_FOLDER, + EFS_FILE, + EFS_LINK, + } elementFS_te; + + class elementFS + { + public : + etk::UString m_name; + elementFS_te m_type; + int32_t m_rights; + elementFS(etk::UString name, elementFS_te type) : + m_name(name), + m_type(type), + m_rights(0) + { }; + ~elementFS(void) {}; + }; + class ListFileSystem : public ewol::List + { + private: + etk::VectorType m_list; + etk::UString m_folder; + int32_t m_selectedLine; + bool m_showFile; + bool m_showTemporaryFile; + bool m_showFolder; + bool m_showHidden; + public: + ListFileSystem(void); + ~ListFileSystem(void); + // display API : + virtual color_ts GetBasicBG(void); + uint32_t GetNuberOfColomn(void); + bool GetTitle(int32_t colomn, etk::UString &myTitle, color_ts &fg, color_ts &bg); + uint32_t GetNuberOfRaw(void); + bool GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, color_ts &fg, color_ts &bg); + bool OnItemEvent(int32_t IdInput, ewol::eventInputType_te typeEvent, int32_t colomn, int32_t raw, float x, float y); + /** + * @brief Check if the object has the specific type. + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type of the object we want to check + * @return true if the object is compatible, otherwise false + */ + bool CheckObjectType(const char * const objectType); + + /** + * @brief Get the current Object type of the EObject + * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it + * @param[in] objectType type description + * @return true if the object is compatible, otherwise false + */ + const char * const GetObjectType(void); + public: + // extern API : + + void SetFolder(etk::UString newFolder); + etk::UString GetFolder(void); + // select the specific file + void SetSelect( etk::UString data); + etk::UString GetSelect(void); + // regenerate the view .... + void RegenerateView(void); + void SetShowFiles(bool state); + void SetShowFolder(bool state); + void SetShowHiddenFiles(bool state); + void SetShowTemporaryFiles(bool state); + }; +}; + +#define EWOL_CAST_WIDGET_FILE_LIST(curentPointer) EWOL_CAST(ewol::TYPE_EOBJECT_WIDGET_FILE_LIST,FileChooserFileList,curentPointer) + +#endif + diff --git a/Sources/libewol/ewol/widgetMeta/FileChooser.cpp b/Sources/libewol/ewol/widgetMeta/FileChooser.cpp index 696534a6..6a3e79fb 100644 --- a/Sources/libewol/ewol/widgetMeta/FileChooser.cpp +++ b/Sources/libewol/ewol/widgetMeta/FileChooser.cpp @@ -43,353 +43,6 @@ extern "C" { #include -void SortList(etk::VectorType &m_listDirectory) -{ - etk::VectorType tmpList = m_listDirectory; - m_listDirectory.Clear(); - for(int32_t iii=0; iii *m_listDirectory[jjj]) { - findPos = jjj+1; - } - } - //EWOL_DEBUG("position="< m_listDirectory; - int32_t m_selectedLine; - public: - FileChooserFolderList(void) - { - AddEventId(ewolEventFileChooserSelectFolder); - m_selectedLine = -1; - SetMouseLimit(2); - }; - ~FileChooserFolderList(void) - { - ClearElements(); - }; - - void AddElement(etk::UString element) - { - etk::UString* tmpEmement = new etk::UString(element); - m_listDirectory.PushBack(tmpEmement); - } - void EndGenerating(void) - { - SortList(m_listDirectory); - MarkToReedraw(); - } - - void ClearElements(void) { - for (int32_t iii=0; iii= 0) { - tmpVal = *(m_listDirectory[m_selectedLine]); - } - return tmpVal; - } - - - virtual color_ts GetBasicBG(void) { - color_ts bg(0x00000010); - return bg; - } - - uint32_t GetNuberOfColomn(void) { - return 1; - }; - bool GetTitle(int32_t colomn, etk::UString &myTitle, color_ts &fg, color_ts &bg) { - myTitle = "title"; - return true; - }; - uint32_t GetNuberOfRaw(void) { - return m_listDirectory.Size(); - }; - bool GetElement(int32_t colomn, int32_t raw, etk::UString &myTextToWrite, color_ts &fg, color_ts &bg) { - if (raw >= 0 && raw < m_listDirectory.Size()) { - myTextToWrite = *(m_listDirectory[raw]); - } else { - myTextToWrite = "ERROR"; - } - fg = etk::color::color_Black; - if (raw % 2) { - bg = 0xFFFFFF00; - } else { - bg = 0xBFBFBFFF; - } - if (m_selectedLine == raw) { - bg = 0x8F8FFFFF; - } - return true; - }; - - bool OnItemEvent(int32_t IdInput, ewol::eventInputType_te typeEvent, int32_t colomn, int32_t raw, float x, float y) { - if (typeEvent == ewol::EVENT_INPUT_TYPE_SINGLE) { - EWOL_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw ); - if (1 == IdInput) { - if (raw > m_listDirectory.Size() ) { - m_selectedLine = -1; - } else { - m_selectedLine = raw; - } - // need to regenerate the display of the list : - MarkToReedraw(); - return true; - } - } - if (typeEvent == ewol::EVENT_INPUT_TYPE_DOUBLE) { - EWOL_INFO("Event Double on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw ); - if (1 == IdInput) { - if (m_selectedLine >=0 ) { - // generate event extern : - GenerateEventId(ewolEventFileChooserSelectFolder); - return true; - } - } - } - return false; - } - - public: - /** - * @brief Check if the object has the specific type. - * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it - * @param[in] objectType type of the object we want to check - * @return true if the object is compatible, otherwise false - */ - bool CheckObjectType(const char * const objectType) - { - if (NULL == objectType) { - EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_FOLDER_LIST << "\" != NULL(pointer) "); - return false; - } - if (objectType == TYPE_EOBJECT_WIDGET_FOLDER_LIST) { - return true; - } else { - if(true == ewol::List::CheckObjectType(objectType)) { - return true; - } - EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_FOLDER_LIST << "\" != \"" << objectType << "\""); - return false; - } - } - - /** - * @brief Get the current Object type of the EObject - * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it - * @param[in] objectType type description - * @return true if the object is compatible, otherwise false - */ - const char * const GetObjectType(void) - { - return TYPE_EOBJECT_WIDGET_FOLDER_LIST; - } -}; -#define EWOL_CAST_WIDGET_FOLDER_LIST(curentPointer) EWOL_CAST(TYPE_EOBJECT_WIDGET_FOLDER_LIST,FileChooserFolderList,curentPointer) - -#undef __class__ -#define __class__ "FileChooser(FileList)" - -const char * const ewolEventFileChooserSelectFile = "ewol-event-file-chooser-Select-File"; -const char * const ewolEventFileChooserValidateFile = "ewol-event-file-chooser-Validate-File"; -//!< EObject name : -extern const char * const TYPE_EOBJECT_WIDGET_FILE_LIST = "FileChooserFileList"; - -class FileChooserFileList : public ewol::List -{ - private: - etk::VectorType m_listFile; - int32_t m_selectedLine; - public: - FileChooserFileList(void) - { - m_selectedLine = -1; - AddEventId(ewolEventFileChooserSelectFile); - AddEventId(ewolEventFileChooserValidateFile); - SetMouseLimit(2); - }; - ~FileChooserFileList(void) - { - ClearElements(); - }; - virtual color_ts GetBasicBG(void) { - color_ts bg(0x00000010); - return bg; - } - void AddElement(etk::UString element) - { - etk::UString* tmpEmement = new etk::UString(element); - m_listFile.PushBack(tmpEmement); - } - void EndGenerating(void) - { - SortList(m_listFile); - MarkToReedraw(); - } - void ClearElements(void) { - for (int32_t iii=0; iii= 0) { - tmpVal = *(m_listFile[m_selectedLine]); - } - return tmpVal; - } - // select the specific file - void SelectFile( etk::UString data) { - // remove selected line - m_selectedLine = -1; - // search the coresponding file : - for (int32_t iii=0; iii= 0 && raw < m_listFile.Size()) { - myTextToWrite = *(m_listFile[raw]); - } else { - myTextToWrite = "ERROR"; - } - fg = etk::color::color_Black; - if (raw % 2) { - bg = 0xFFFFFF00; - } else { - bg = 0xBFBFBFFF; - } - if (m_selectedLine == raw) { - bg = 0x8F8FFFFF; - } - return true; - }; - - bool OnItemEvent(int32_t IdInput, ewol::eventInputType_te typeEvent, int32_t colomn, int32_t raw, float x, float y) { - if (typeEvent == ewol::EVENT_INPUT_TYPE_SINGLE) { - EWOL_INFO("Event on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw ); - if (1 == IdInput) { - if (raw > m_listFile.Size() ) { - m_selectedLine = -1; - } else { - m_selectedLine = raw; - } - // need to regenerate the display of the list : - MarkToReedraw(); - if (m_selectedLine >=0 ) { - // generate event extern : - GenerateEventId(ewolEventFileChooserSelectFile); - return true; - } - return true; - } - } - if (typeEvent == ewol::EVENT_INPUT_TYPE_DOUBLE) { - EWOL_INFO("Event Double on List : IdInput=" << IdInput << " colomn=" << colomn << " raw=" << raw ); - if (1 == IdInput) { - if (m_selectedLine >=0 ) { - // generate event extern : - GenerateEventId(ewolEventFileChooserValidateFile); - return true; - } - } - } - return false; - return false; - } - - - public: - /** - * @brief Check if the object has the specific type. - * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it - * @param[in] objectType type of the object we want to check - * @return true if the object is compatible, otherwise false - */ - bool CheckObjectType(const char * const objectType) - { - if (NULL == objectType) { - EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_FILE_LIST << "\" != NULL(pointer) "); - return false; - } - if (objectType == TYPE_EOBJECT_WIDGET_FILE_LIST) { - return true; - } else { - if(true == ewol::List::CheckObjectType(objectType)) { - return true; - } - EWOL_ERROR("check error : \"" << TYPE_EOBJECT_WIDGET_FILE_LIST << "\" != \"" << objectType << "\""); - return false; - } - } - - /** - * @brief Get the current Object type of the EObject - * @note In Embended platforme, it is many time no -rtti flag, then it is not possible to use dynamic cast ==> this will replace it - * @param[in] objectType type description - * @return true if the object is compatible, otherwise false - */ - const char * const GetObjectType(void) - { - return TYPE_EOBJECT_WIDGET_FILE_LIST; - } -}; -#define EWOL_CAST_WIDGET_FILE_LIST(curentPointer) EWOL_CAST(TYPE_EOBJECT_WIDGET_FILE_LIST,FileChooserFileList,curentPointer) #undef __class__ @@ -403,6 +56,9 @@ extern const char * const ewolEventFileChooserEntryFolder = "ewol-event-fil extern const char * const ewolEventFileChooserEntryFolderEnter = "ewol-event-file-chooser-modify-entry-folder-enter"; extern const char * const ewolEventFileChooserEntryFile = "ewol-event-file-chooser-modify-entry-file"; extern const char * const ewolEventFileChooserEntryFileEnter = "ewol-event-file-chooser-modify-entry-file-enter"; +extern const char * const ewolEventFileChooserListFolder = "ewol-event-file-chooser-modify-list-folder"; +extern const char * const ewolEventFileChooserListFile = "ewol-event-file-chooser-modify-list-file"; +extern const char * const ewolEventFileChooserListFileValidate = "ewol-event-file-chooser-modify-list-file-validate"; extern const char * const ewolEventFileChooserHome = "ewol-event-file-chooser-home"; @@ -423,8 +79,6 @@ ewol::FileChooser::FileChooser(void) ewol::SizerVert * mySizerVert = NULL; ewol::SizerHori * mySizerHori = NULL; ewol::Spacer * mySpacer = NULL; - FileChooserFileList * myListFile = NULL; - FileChooserFolderList * myListFolder = NULL; //ewol::Label * myLabel = NULL; ewol::Image * myImage = NULL; #ifdef __PLATFORM__Android @@ -480,24 +134,28 @@ ewol::FileChooser::FileChooser(void) mySpacer = new ewol::Spacer(); mySpacer->SetSize(2); mySizerHori->SubWidgetAdd(mySpacer); - myListFolder = new FileChooserFolderList(); - m_widgetListFolder = myListFolder; - myListFolder->RegisterOnEvent(this, ewolEventFileChooserSelectFolder, ewolEventFileChooserSelectFolder); - myListFolder->SetExpendY(true); - myListFolder->SetFillY(true); - mySizerHori->SubWidgetAdd(myListFolder); + m_widgetListFolder = new ListFileSystem(); + m_widgetListFolder->SetShowFolder(true); + m_widgetListFolder->SetShowFiles(false); + m_widgetListFolder->SetShowHiddenFiles(false); + m_widgetListFolder->RegisterOnEvent(this, ewolEventFSFolderValidate, ewolEventFileChooserListFolder); + m_widgetListFolder->SetExpendY(true); + m_widgetListFolder->SetFillY(true); + mySizerHori->SubWidgetAdd(m_widgetListFolder); mySpacer = new ewol::Spacer(); mySpacer->SetSize(2); mySizerHori->SubWidgetAdd(mySpacer); - myListFile = new FileChooserFileList(); - m_widgetListFile = myListFile; - myListFile->RegisterOnEvent(this, ewolEventFileChooserSelectFile, ewolEventFileChooserSelectFile); - myListFile->RegisterOnEvent(this, ewolEventFileChooserValidateFile, ewolEventFileChooserValidateFile); - myListFile->SetExpendX(true); - myListFile->SetFillX(true); - myListFile->SetExpendY(true); - myListFile->SetFillY(true); - mySizerHori->SubWidgetAdd(myListFile); + m_widgetListFile = new ListFileSystem(); + m_widgetListFile->SetShowFolder(false); + m_widgetListFile->SetShowFiles(true); + m_widgetListFile->SetShowHiddenFiles(false); + m_widgetListFile->RegisterOnEvent(this, ewolEventFSFileSelect, ewolEventFileChooserListFile); + m_widgetListFile->RegisterOnEvent(this, ewolEventFSFileValidate, ewolEventFileChooserListFileValidate); + m_widgetListFile->SetExpendX(true); + m_widgetListFile->SetFillX(true); + m_widgetListFile->SetExpendY(true); + m_widgetListFile->SetFillY(true); + mySizerHori->SubWidgetAdd(m_widgetListFile); mySpacer = new ewol::Spacer(); mySpacer->SetSize(2); mySizerHori->SubWidgetAdd(mySpacer); @@ -627,23 +285,33 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha //==> change the file name m_file = data; // Update the selected file in the list : - FileChooserFileList * myListFile = EWOL_CAST_WIDGET_FILE_LIST(m_widgetListFile); - if (myListFile != NULL) { - myListFile->SelectFile(m_file); + if (m_widgetListFile != NULL) { + m_widgetListFile->SetSelect(m_file); } } else if (ewolEventFileChooserCancel == eventId) { //==> Auto remove ... GenerateEventId(eventId); MarkToRemove(); } else if (ewolEventFileChooserHidenFileChange == eventId) { - // regenerate the display ... - UpdateCurrentFolder(); - } else if (ewolEventFileChooserSelectFolder == eventId) { + if (data == "true") { + if (NULL!=m_widgetListFolder) { + m_widgetListFolder->SetShowHiddenFiles(true); + } + if (NULL!=m_widgetListFile) { + m_widgetListFile->SetShowHiddenFiles(true); + } + } else { + if (NULL!=m_widgetListFolder) { + m_widgetListFolder->SetShowHiddenFiles(false); + } + if (NULL!=m_widgetListFile) { + m_widgetListFile->SetShowHiddenFiles(false); + } + } + } else if (ewolEventFileChooserListFolder == eventId) { //==> this is an internal event ... - FileChooserFolderList * myListFolder = EWOL_CAST_WIDGET_FOLDER_LIST(m_widgetListFolder); - etk::UString tmpString = myListFolder->GetSelectedLine(); - EWOL_VERBOSE(" old PATH : \"" << m_folder << "\" + \"" << tmpString << "\""); - m_folder = m_folder + tmpString; + EWOL_VERBOSE(" old PATH : \"" << m_folder << "\" + \"" << data << "\""); + m_folder = m_folder + data; char buf[MAX_FILE_NAME]; memset(buf, 0, MAX_FILE_NAME); char * ok; @@ -661,15 +329,14 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha } SetFileName(""); UpdateCurrentFolder(); - } else if (ewolEventFileChooserSelectFile == eventId) { - FileChooserFileList * myListFile = EWOL_CAST_WIDGET_FILE_LIST(m_widgetListFile); - etk::UString file = myListFile->GetSelectedLine(); - SetFileName(file); + } else if (ewolEventFileChooserListFile == eventId) { + SetFileName(data); GenerateEventId(eventId); - } else if( eventId == ewolEventFileChooserValidateFile + } else if( eventId == ewolEventFileChooserListFileValidate || (eventId == ewolEventFileChooserValidate && m_file != "" ) || (eventId == ewolEventFileChooserEntryFileEnter && m_file != "" ) ) { // select the File ==> generate a validate + SetFileName(data); GenerateEventId(ewolEventFileChooserValidate); MarkToRemove(); } else if(ewolEventFileChooserHome == eventId) { @@ -699,57 +366,15 @@ void ewol::FileChooser::OnReceiveMessage(ewol::EObject * CallerObject, const cha void ewol::FileChooser::UpdateCurrentFolder(void) { - if (NULL == m_widgetListFile) { - return; + if (NULL != m_widgetListFile) { + m_widgetListFile->SetFolder(m_folder); } - if (NULL == m_widgetListFolder) { - return; + if (NULL != m_widgetListFolder) { + m_widgetListFolder->SetFolder(m_folder); } - FileChooserFileList * myListFile = EWOL_CAST_WIDGET_FILE_LIST(m_widgetListFile); - FileChooserFolderList * myListFolder = EWOL_CAST_WIDGET_FOLDER_LIST(m_widgetListFolder); - - myListFile->ClearElements(); - myListFolder->ClearElements(); - bool ShowHidenFile = true; - if (NULL != m_widgetCheckBox) { - ShowHidenFile = m_widgetCheckBox->GetValue(); - } else { - EWOL_ERROR("Can not get the hiden property of the file choozer..."); - } - if (NULL != m_widgetCurrentFolder) { m_widgetCurrentFolder->SetValue(m_folder); } - myListFolder->AddElement(etk::UString(".")); - if (m_folder != "/" ) { - myListFolder->AddElement(etk::UString("..")); - } - DIR *dir; - struct dirent *ent; - dir = opendir(m_folder.Utf8Data()); - if (dir != NULL) { - // for each element in the drectory... - while ((ent = readdir(dir)) != NULL) { - etk::UString tmpString(ent->d_name); - if (DT_REG == ent->d_type) { - if (false == tmpString.StartWith(".") || true==ShowHidenFile) { - myListFile->AddElement(tmpString); - } - } else if (DT_DIR == ent->d_type) { - //EWOL_DEBUG(" find Folder : \"" << tmpString << "\"(" << tmpString.Size() << ") ?= \"" << ent->d_name << "\"(" << strlen(ent->d_name) ); - if (tmpString != "." && tmpString != "..") { - if (false == tmpString.StartWith(".") || true==ShowHidenFile) { - myListFolder->AddElement(tmpString); - } - } - } - } - closedir(dir); - } else { - EWOL_ERROR("could not open directory : \"" << m_folder << "\""); - } - myListFile->EndGenerating(); - myListFolder->EndGenerating(); MarkToReedraw(); } diff --git a/Sources/libewol/ewol/widgetMeta/FileChooser.h b/Sources/libewol/ewol/widgetMeta/FileChooser.h index f11e67fe..97e5f7fc 100644 --- a/Sources/libewol/ewol/widgetMeta/FileChooser.h +++ b/Sources/libewol/ewol/widgetMeta/FileChooser.h @@ -32,6 +32,7 @@ #include #include #include +#include extern const char * const ewolEventFileChooserCancel; extern const char * const ewolEventFileChooserValidate; @@ -80,16 +81,16 @@ namespace ewol { etk::UString GetCompleateFileName(void); void UpdateCurrentFolder(void); private: - ewol::Label* m_widgetTitle; - ewol::Button* m_widgetValidate; - ewol::Button* m_widgetCancel; - ewol::Entry* m_widgetCurrentFolder; - ewol::Entry* m_widgetCurrentFileName; - ewol::Widget* m_widgetListFolder; - ewol::Widget* m_widgetListFile; - ewol::CheckBox* m_widgetCheckBox; - etk::UString m_folder; - etk::UString m_file; + ewol::Label* m_widgetTitle; + ewol::Button* m_widgetValidate; + ewol::Button* m_widgetCancel; + ewol::Entry* m_widgetCurrentFolder; + ewol::Entry* m_widgetCurrentFileName; + ewol::ListFileSystem* m_widgetListFolder; + ewol::ListFileSystem* m_widgetListFile; + ewol::CheckBox* m_widgetCheckBox; + etk::UString m_folder; + etk::UString m_file; }; extern const char * const TYPE_EOBJECT_WIDGET_FILE_CHOOSER; diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index cb911782..e551b8f3 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -39,6 +39,7 @@ FILE_LIST = ewol/ewol.cpp \ ewol/widget/Joystick.cpp \ ewol/widget/Label.cpp \ ewol/widget/List.cpp \ + ewol/widget/ListFileSystem.cpp \ ewol/widget/Layer.cpp \ ewol/widget/Menu.cpp \ ewol/widget/PopUp.cpp \