summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-03-06 14:45:31 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-03-06 14:45:31 +0100
commitd611ee9834561622faeeddb604062d92b30a4512 (patch)
treee2f474edfc29af0915c9800bf19d3c6eb2bc7fde /plugingui
parent79071c752b907858c4ca7c0bd8b54cb17860254f (diff)
Remove debug info. Add setPath method.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/filebrowser.cc27
-rw-r--r--plugingui/filebrowser.h2
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),