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
+ }
0 commit comments