| 68 | } |
| 69 | |
| 70 | char* FileDialog(const char* path, int flags){ |
| 71 | dflags = flags; |
| 72 | |
| 73 | if(!path){ |
| 74 | path = "."; // Current Directory |
| 75 | } |
| 76 | |
| 77 | selectedPth = nullptr; |
| 78 | dialogFileView = nullptr; |
| 79 | dialogFileBox = nullptr; |
| 80 | |
| 81 | Window* win = new Window("Open...", {480, 300}, WINDOW_FLAGS_RESIZABLE, WindowType::GUI); |
| 82 | |
| 83 | FileView* fv = new FileView({0, 0, 0, 63}, path, FileDialogOnFileOpened); |
| 84 | win->AddWidget(fv); |
| 85 | fv->SetLayout(LayoutSize::Stretch, LayoutSize::Stretch, WAlignLeft); |
| 86 | fv->OnFileSelected = FileDialogOnFileSelected; |
| 87 | |
| 88 | dialogFileView = fv; |
| 89 | |
| 90 | Button* okBtn = new Button("OK", {5, 34, 100, 24}); |
| 91 | win->AddWidget(okBtn); |
| 92 | okBtn->SetLayout(LayoutSize::Fixed, LayoutSize::Fixed, WAlignRight, WAlignBottom); |
| 93 | okBtn->OnPress = FileDialogOnOKPress; |
| 94 | |
| 95 | Button* cancelBtn = new Button("Cancel", {5, 5, 100, 24}); |
| 96 | win->AddWidget(cancelBtn); |
| 97 | cancelBtn->SetLayout(LayoutSize::Fixed, LayoutSize::Fixed, WAlignRight, WAlignBottom); |
| 98 | cancelBtn->OnPress = FileDialogOnCancelPress; |
| 99 | |
| 100 | TextBox* fileBox = new TextBox({125, 36, 110, 20}, false); |
| 101 | win->AddWidget(fileBox); |
| 102 | fileBox->SetLayout(LayoutSize::Stretch, LayoutSize::Fixed, WAlignLeft, WAlignBottom); |
| 103 | fileBox->OnSubmit = FileDialogOnFileBoxSubmit; |
| 104 | dialogFileBox = fileBox; |
| 105 | |
| 106 | while(!win->closed && !selectedPth){ |
| 107 | LemonEvent ev; |
| 108 | while(win->PollEvent(ev)){ |
| 109 | win->GUIHandleEvent(ev); |
| 110 | } |
| 111 | |
| 112 | win->Paint(); |
| 113 | win->WaitEvent(); |
| 114 | } |
| 115 | |
| 116 | delete win; |
| 117 | |
| 118 | return selectedPth; |
| 119 | } |
| 120 | } |
no test coverage detected