Skip to content

Commit a6bfd14

Browse files
authored
Merge pull request #674 from Shallowmallow/FolderDialog
FolderDialog
2 parents 07fc7aa + 5dea98f commit a6bfd14

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package haxe.ui.backend;
2+
3+
import haxe.ui.containers.dialogs.Dialog.DialogButton;
4+
import haxe.ui.containers.dialogs.Dialog.DialogEvent;
5+
import haxe.ui.containers.dialogs.Dialogs;
6+
import haxe.ui.containers.dialogs.MessageBox.MessageBoxType;
7+
8+
typedef OpenFolderDialogOptions = {
9+
@:optional var defaultPath:String;
10+
@:optional var title:String;
11+
@:optional var multiple:Null<Bool>;
12+
@:optional var hiddenFolders:Null<Bool>;
13+
@:optional var canCreateFolder:Null<Bool>;
14+
}
15+
16+
class OpenFolderDialogBase {
17+
public var selectedFolders:Array<String> = null;
18+
public var callback:DialogButton->Array<String>->Void = null;
19+
public var onDialogClosed:DialogEvent->Void = null;
20+
21+
public function new(options:OpenFolderDialogOptions = null, callback:DialogButton->Array<String>->Void = null) {
22+
this.options = options;
23+
this.callback = callback;
24+
}
25+
26+
private var _options:OpenFolderDialogOptions = null;
27+
public var options(get, set):OpenFolderDialogOptions;
28+
private function get_options():OpenFolderDialogOptions {
29+
return _options;
30+
}
31+
private function set_options(value:OpenFolderDialogOptions):OpenFolderDialogOptions {
32+
_options = value;
33+
validateOptions();
34+
return value;
35+
}
36+
37+
private function validateOptions() {
38+
if (_options == null) {
39+
options = { };
40+
}
41+
42+
if (_options.multiple == null) {
43+
_options.multiple = false;
44+
}
45+
46+
if (_options.canCreateFolder == null) {
47+
_options.canCreateFolder = false;
48+
}
49+
50+
if (_options.hiddenFolders == null) {
51+
_options.hiddenFolders = false;
52+
}
53+
}
54+
55+
public function show() {
56+
Dialogs.messageBox("OpenFolderDialog has no implementation on this backend", "Open Folder", MessageBoxType.TYPE_ERROR);
57+
}
58+
59+
private function dialogConfirmed(folders:Array<String>) {
60+
selectedFolders = folders;
61+
if (callback != null) {
62+
callback(DialogButton.OK, selectedFolders);
63+
}
64+
if (onDialogClosed != null) {
65+
var event = new DialogEvent(DialogEvent.DIALOG_CLOSED, false, selectedFolders);
66+
event.button = DialogButton.OK;
67+
onDialogClosed(event);
68+
}
69+
}
70+
71+
private function dialogCancelled() {
72+
selectedFolders = null;
73+
if (callback != null) {
74+
callback(DialogButton.CANCEL, selectedFolders);
75+
}
76+
if (onDialogClosed != null) {
77+
var event = new DialogEvent(DialogEvent.DIALOG_CLOSED, false, selectedFolders);
78+
event.button = DialogButton.CANCEL;
79+
onDialogClosed(event);
80+
}
81+
}
82+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package haxe.ui.backend;
2+
3+
class OpenFolderDialogImpl extends OpenFolderDialogBase {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package haxe.ui.containers.dialogs;
2+
3+
import haxe.ui.backend.OpenFolderDialogImpl;
4+
5+
#if haxeui_expose_all
6+
@:expose
7+
#end
8+
class OpenFolderDialog extends OpenFolderDialogImpl {
9+
}

0 commit comments

Comments
 (0)