void FileDialog::init(){ //Directories ListBox* dir = new ListBox(); dir->setPosition(Vector2D(50, 100)); dir->setSpan(Vector2D(400, 600)); dir->addEntries(Filesystem::getDirectories(cwd_+SEPARATOR+path_)); dir->setCbFunc(&changeDir); addElement(dir); //Files ListBox* file = new ListBox(); file->setPosition(Vector2D(564, 100)); file->setSpan(Vector2D(400, 600)); file->addEntries(Filesystem::getFiles(cwd_+SEPARATOR+path_)); file->setCbFunc(&writeFilename); addElement(file); //Input field InputField* inp = new InputField(); inp->setOpacity(0.8f); inp->setPosition(Vector2D(50, 50)); inp->setSpan(Vector2D(300,18)); addUnscaledElement(inp); //OK button PDButton* ok = new PDButton(); ok->setPosition(Vector2D(575, 50)); ok->setSpan(Vector2D(75,18)); ok->setText(" OK"); addUnscaledElement(ok); //Abort button PDButton* abort = new PDButton(); abort->setPosition(Vector2D(700, 50)); abort->setSpan(Vector2D(75,18)); abort->setText(" Abort"); addUnscaledElement(abort); }
//! The change directory callback void FileDialog::changeDir(GuiElement* elem){ Dialog* dia = dynamic_cast<Dialog*>(elem->getParent()); ListBox* dirs = dynamic_cast<ListBox*>(dia->getElement(0)); string dir = dirs->selectedItem(); //collapse path when .. is chosen and the situation is appropriate if (dir == ".." && path_.length() > 1 && path_[path_.length()-1] != '.'){ size_t n = path_.find_last_of(SEPARATOR); if (n != path_.npos) path_.erase(n); else path_ += "."; } else path_ += SEPARATOR+dir; dirs->clear(); dirs->addEntries(Filesystem::getDirectories(cwd_+SEPARATOR+path_)); //update file list ListBox* files = dynamic_cast<ListBox*>(dia->getElement(1)); files->clear(); files->addEntries(Filesystem::getFiles(cwd_+SEPARATOR+path_)); }