| 31 | } |
| 32 | |
| 33 | void FileDialogOnFileBoxSubmit(Lemon::GUI::TextBox* box){ |
| 34 | if(box->contents.front().find('/') != std::string::npos && box->contents.size() > NAME_MAX){ |
| 35 | DisplayMessageBox("Open...", "Filename is invalid!", MsgButtonsOK); |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | std::string path = dialogFileView->currentPath; |
| 40 | path += box->contents.front(); |
| 41 | |
| 42 | struct stat sResult; |
| 43 | int e = stat(path.c_str(), &sResult); |
| 44 | if(e && dflags & FILE_DIALOG_CREATE && errno == ENOENT){ |
| 45 | FileDialogOnFileOpened(path.c_str(), dialogFileView); |
| 46 | return; |
| 47 | } else if(e && errno == ENOENT) { |
| 48 | char buf[512]; |
| 49 | sprintf(buf, "File %s not found!", path.c_str()); |
| 50 | DisplayMessageBox("Open...", buf, MsgButtonsOK); |
| 51 | return; |
| 52 | } else if(e){ |
| 53 | perror("GUI: FileDialog: "); |
| 54 | char buf[512]; |
| 55 | sprintf(buf, "Error opening file %s (Error code: %d)", path.c_str(), errno); |
| 56 | DisplayMessageBox("Open...", buf, MsgButtonsOK); |
| 57 | return; |
| 58 | } else if((sResult.st_mode & S_IFMT) == S_IFDIR && !(dflags & FILE_DIALOG_DIRECTORIES)) { |
| 59 | dialogFileView->OnSubmit(path); |
| 60 | return; |
| 61 | } else { |
| 62 | FileDialogOnFileOpened(path.c_str(), dialogFileView); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void FileDialogOnOKPress(__attribute__((unused)) Lemon::GUI::Button* btn){ |
| 67 | FileDialogOnFileBoxSubmit(dialogFileBox); |
no test coverage detected