MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / FileDialog

Function FileDialog

LibLemon/src/gui/filedialog.cpp:70–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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}

Callers 6

OnOpenFunction · 0.85
OnSaveFunction · 0.85
OnWindowCmdFunction · 0.85
mainFunction · 0.85
OpenFileFunction · 0.85
SaveFileAsFunction · 0.85

Calls 6

SetLayoutMethod · 0.80
PollEventMethod · 0.80
GUIHandleEventMethod · 0.80
WaitEventMethod · 0.80
AddWidgetMethod · 0.45
PaintMethod · 0.45

Tested by

no test coverage detected