From d611ee9834561622faeeddb604062d92b30a4512 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 6 Mar 2013 14:45:31 +0100 Subject: Remove debug info. Add setPath method. --- plugingui/filebrowser.cc | 27 ++++++++++++++++++++++----- plugingui/filebrowser.h | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 6582202..127c7f2 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -56,13 +56,19 @@ void changeDir(void *ptr) char filename[1024]; char *c = getcwd(filename, sizeof(filename)); (void)c; - strcat(filename, "/"); - strcat(filename, value.c_str()); + if(value != "") { +#ifdef WIN32 + strcat(filename, "\\"); +#else + strcat(filename, "/"); +#endif + strcat(filename, value.c_str()); + } struct stat st; if(stat(filename, &st) == 0) { if((st.st_mode & S_IFDIR) != 0) { - //printf("'%s' is present and is a directory\n", filename); + // printf("'%s' is present and is a directory\n", filename); } if((st.st_mode & S_IFREG) != 0) { //printf("'%s' is present and is a file\n", filename); @@ -78,8 +84,12 @@ void changeDir(void *ptr) int i = chdir(value.c_str()); (void)i; DIR *dir = opendir("."); + if(!dir) { + lb->addItem("[ Could not open dir ]", ""); + return; + } - struct dirent *entry; + struct dirent *entry; while((entry = readdir(dir)) != NULL) { lb->addItem(entry->d_name, entry->d_name); } @@ -97,8 +107,8 @@ GUI::FileBrowser::FileBrowser(GUI::Widget *parent) #define btn_h 12 listbox = new GUI::ListBox(this); - listbox->registerDblClickHandler(changeDir, prv); prv->listbox = listbox; + listbox->registerDblClickHandler(changeDir, prv); btn = new GUI::Button(this); btn->setText("Select"); @@ -115,6 +125,13 @@ GUI::FileBrowser::~FileBrowser() delete prv; } +void GUI::FileBrowser::setPath(std::string path) +{ + int i = chdir(path.c_str()); + (void)i; + changeDir(prv); +} + void GUI::FileBrowser::resize(size_t w, size_t h) { GUI::Widget::resize(w,h); diff --git a/plugingui/filebrowser.h b/plugingui/filebrowser.h index bdfe98f..e745e7e 100644 --- a/plugingui/filebrowser.h +++ b/plugingui/filebrowser.h @@ -41,6 +41,8 @@ public: FileBrowser(Widget *parent); ~FileBrowser(); + void setPath(std::string path); + bool isFocusable() { return true; } void registerFileSelectHandler(void (*handler)(void *, std::string), -- cgit v1.2.3