1 /**
2 Dialog for selecting files or directories in the filesystem.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.filedialog;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.confirmationdialog;
25 import godot.acceptdialog;
26 import godot.windowdialog;
27 import godot.inputevent;
28 import godot.lineedit;
29 import godot.vboxcontainer;
30 /**
31 Dialog for selecting files or directories in the filesystem.
32 
33 FileDialog is a preset dialog used to choose files and directories in the filesystem. It supports filter masks. The FileDialog automatically sets its window title according to the $(D mode). If you want to use a custom title, disable this by setting $(D modeOverridesTitle) to `false`.
34 */
35 @GodotBaseClass struct FileDialog
36 {
37 	package(godot) enum string _GODOT_internal_name = "FileDialog";
38 public:
39 @nogc nothrow:
40 	union { /** */ godot_object _godot_object; /** */ ConfirmationDialog _GODOT_base; }
41 	alias _GODOT_base this;
42 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
43 	package(godot) __gshared bool _classBindingInitialized = false;
44 	package(godot) static struct GDNativeClassBinding
45 	{
46 		__gshared:
47 		@GodotName("_action_pressed") GodotMethod!(void) _actionPressed;
48 		@GodotName("_cancel_pressed") GodotMethod!(void) _cancelPressed;
49 		@GodotName("_dir_entered") GodotMethod!(void, String) _dirEntered;
50 		@GodotName("_file_entered") GodotMethod!(void, String) _fileEntered;
51 		@GodotName("_filter_selected") GodotMethod!(void, long) _filterSelected;
52 		@GodotName("_go_up") GodotMethod!(void) _goUp;
53 		@GodotName("_make_dir") GodotMethod!(void) _makeDir;
54 		@GodotName("_make_dir_confirm") GodotMethod!(void) _makeDirConfirm;
55 		@GodotName("_save_confirm_pressed") GodotMethod!(void) _saveConfirmPressed;
56 		@GodotName("_select_drive") GodotMethod!(void, long) _selectDrive;
57 		@GodotName("_tree_item_activated") GodotMethod!(void) _treeItemActivated;
58 		@GodotName("_tree_multi_selected") GodotMethod!(void, GodotObject, long, bool) _treeMultiSelected;
59 		@GodotName("_tree_selected") GodotMethod!(void) _treeSelected;
60 		@GodotName("_unhandled_input") GodotMethod!(void, InputEvent) _unhandledInput;
61 		@GodotName("_update_dir") GodotMethod!(void) _updateDir;
62 		@GodotName("_update_file_list") GodotMethod!(void) _updateFileList;
63 		@GodotName("_update_file_name") GodotMethod!(void) _updateFileName;
64 		@GodotName("add_filter") GodotMethod!(void, String) addFilter;
65 		@GodotName("clear_filters") GodotMethod!(void) clearFilters;
66 		@GodotName("deselect_items") GodotMethod!(void) deselectItems;
67 		@GodotName("get_access") GodotMethod!(FileDialog.Access) getAccess;
68 		@GodotName("get_current_dir") GodotMethod!(String) getCurrentDir;
69 		@GodotName("get_current_file") GodotMethod!(String) getCurrentFile;
70 		@GodotName("get_current_path") GodotMethod!(String) getCurrentPath;
71 		@GodotName("get_filters") GodotMethod!(PoolStringArray) getFilters;
72 		@GodotName("get_line_edit") GodotMethod!(LineEdit) getLineEdit;
73 		@GodotName("get_mode") GodotMethod!(FileDialog.Mode) getMode;
74 		@GodotName("get_vbox") GodotMethod!(VBoxContainer) getVbox;
75 		@GodotName("invalidate") GodotMethod!(void) invalidate;
76 		@GodotName("is_mode_overriding_title") GodotMethod!(bool) isModeOverridingTitle;
77 		@GodotName("is_showing_hidden_files") GodotMethod!(bool) isShowingHiddenFiles;
78 		@GodotName("set_access") GodotMethod!(void, long) setAccess;
79 		@GodotName("set_current_dir") GodotMethod!(void, String) setCurrentDir;
80 		@GodotName("set_current_file") GodotMethod!(void, String) setCurrentFile;
81 		@GodotName("set_current_path") GodotMethod!(void, String) setCurrentPath;
82 		@GodotName("set_filters") GodotMethod!(void, PoolStringArray) setFilters;
83 		@GodotName("set_mode") GodotMethod!(void, long) setMode;
84 		@GodotName("set_mode_overrides_title") GodotMethod!(void, bool) setModeOverridesTitle;
85 		@GodotName("set_show_hidden_files") GodotMethod!(void, bool) setShowHiddenFiles;
86 	}
87 	/// 
88 	pragma(inline, true) bool opEquals(in FileDialog other) const
89 	{ return _godot_object.ptr is other._godot_object.ptr; }
90 	/// 
91 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
92 	{ _godot_object.ptr = n; return null; }
93 	/// 
94 	pragma(inline, true) bool opEquals(typeof(null) n) const
95 	{ return _godot_object.ptr is n; }
96 	/// 
97 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
98 	mixin baseCasts;
99 	/// Construct a new instance of FileDialog.
100 	/// Note: use `memnew!FileDialog` instead.
101 	static FileDialog _new()
102 	{
103 		static godot_class_constructor constructor;
104 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("FileDialog");
105 		if(constructor is null) return typeof(this).init;
106 		return cast(FileDialog)(constructor());
107 	}
108 	@disable new(size_t s);
109 	/// 
110 	enum Mode : int
111 	{
112 		/**
113 		The dialog allows selecting one, and only one file.
114 		*/
115 		modeOpenFile = 0,
116 		/**
117 		The dialog allows selecting multiple files.
118 		*/
119 		modeOpenFiles = 1,
120 		/**
121 		The dialog only allows selecting a directory, disallowing the selection of any file.
122 		*/
123 		modeOpenDir = 2,
124 		/**
125 		The dialog allows selecting one file or directory.
126 		*/
127 		modeOpenAny = 3,
128 		/**
129 		The dialog will warn when a file exists.
130 		*/
131 		modeSaveFile = 4,
132 	}
133 	/// 
134 	enum Access : int
135 	{
136 		/**
137 		The dialog only allows accessing files under the $(D Resource) path (`res://`).
138 		*/
139 		accessResources = 0,
140 		/**
141 		The dialog only allows accessing files under user data path (`user://`).
142 		*/
143 		accessUserdata = 1,
144 		/**
145 		The dialog allows accessing files on the whole file system.
146 		*/
147 		accessFilesystem = 2,
148 	}
149 	/// 
150 	enum Constants : int
151 	{
152 		modeOpenFile = 0,
153 		accessResources = 0,
154 		accessUserdata = 1,
155 		modeOpenFiles = 1,
156 		accessFilesystem = 2,
157 		modeOpenDir = 2,
158 		modeOpenAny = 3,
159 		modeSaveFile = 4,
160 	}
161 	/**
162 	
163 	*/
164 	void _actionPressed()
165 	{
166 		Array _GODOT_args = Array.make();
167 		String _GODOT_method_name = String("_action_pressed");
168 		this.callv(_GODOT_method_name, _GODOT_args);
169 	}
170 	/**
171 	
172 	*/
173 	void _cancelPressed()
174 	{
175 		Array _GODOT_args = Array.make();
176 		String _GODOT_method_name = String("_cancel_pressed");
177 		this.callv(_GODOT_method_name, _GODOT_args);
178 	}
179 	/**
180 	
181 	*/
182 	void _dirEntered(in String arg0)
183 	{
184 		Array _GODOT_args = Array.make();
185 		_GODOT_args.append(arg0);
186 		String _GODOT_method_name = String("_dir_entered");
187 		this.callv(_GODOT_method_name, _GODOT_args);
188 	}
189 	/**
190 	
191 	*/
192 	void _fileEntered(in String arg0)
193 	{
194 		Array _GODOT_args = Array.make();
195 		_GODOT_args.append(arg0);
196 		String _GODOT_method_name = String("_file_entered");
197 		this.callv(_GODOT_method_name, _GODOT_args);
198 	}
199 	/**
200 	
201 	*/
202 	void _filterSelected(in long arg0)
203 	{
204 		Array _GODOT_args = Array.make();
205 		_GODOT_args.append(arg0);
206 		String _GODOT_method_name = String("_filter_selected");
207 		this.callv(_GODOT_method_name, _GODOT_args);
208 	}
209 	/**
210 	
211 	*/
212 	void _goUp()
213 	{
214 		Array _GODOT_args = Array.make();
215 		String _GODOT_method_name = String("_go_up");
216 		this.callv(_GODOT_method_name, _GODOT_args);
217 	}
218 	/**
219 	
220 	*/
221 	void _makeDir()
222 	{
223 		Array _GODOT_args = Array.make();
224 		String _GODOT_method_name = String("_make_dir");
225 		this.callv(_GODOT_method_name, _GODOT_args);
226 	}
227 	/**
228 	
229 	*/
230 	void _makeDirConfirm()
231 	{
232 		Array _GODOT_args = Array.make();
233 		String _GODOT_method_name = String("_make_dir_confirm");
234 		this.callv(_GODOT_method_name, _GODOT_args);
235 	}
236 	/**
237 	
238 	*/
239 	void _saveConfirmPressed()
240 	{
241 		Array _GODOT_args = Array.make();
242 		String _GODOT_method_name = String("_save_confirm_pressed");
243 		this.callv(_GODOT_method_name, _GODOT_args);
244 	}
245 	/**
246 	
247 	*/
248 	void _selectDrive(in long arg0)
249 	{
250 		Array _GODOT_args = Array.make();
251 		_GODOT_args.append(arg0);
252 		String _GODOT_method_name = String("_select_drive");
253 		this.callv(_GODOT_method_name, _GODOT_args);
254 	}
255 	/**
256 	
257 	*/
258 	void _treeItemActivated()
259 	{
260 		Array _GODOT_args = Array.make();
261 		String _GODOT_method_name = String("_tree_item_activated");
262 		this.callv(_GODOT_method_name, _GODOT_args);
263 	}
264 	/**
265 	
266 	*/
267 	void _treeMultiSelected(GodotObject arg0, in long arg1, in bool arg2)
268 	{
269 		Array _GODOT_args = Array.make();
270 		_GODOT_args.append(arg0);
271 		_GODOT_args.append(arg1);
272 		_GODOT_args.append(arg2);
273 		String _GODOT_method_name = String("_tree_multi_selected");
274 		this.callv(_GODOT_method_name, _GODOT_args);
275 	}
276 	/**
277 	
278 	*/
279 	void _treeSelected()
280 	{
281 		Array _GODOT_args = Array.make();
282 		String _GODOT_method_name = String("_tree_selected");
283 		this.callv(_GODOT_method_name, _GODOT_args);
284 	}
285 	/**
286 	
287 	*/
288 	void _unhandledInput(InputEvent arg0)
289 	{
290 		Array _GODOT_args = Array.make();
291 		_GODOT_args.append(arg0);
292 		String _GODOT_method_name = String("_unhandled_input");
293 		this.callv(_GODOT_method_name, _GODOT_args);
294 	}
295 	/**
296 	
297 	*/
298 	void _updateDir()
299 	{
300 		Array _GODOT_args = Array.make();
301 		String _GODOT_method_name = String("_update_dir");
302 		this.callv(_GODOT_method_name, _GODOT_args);
303 	}
304 	/**
305 	
306 	*/
307 	void _updateFileList()
308 	{
309 		Array _GODOT_args = Array.make();
310 		String _GODOT_method_name = String("_update_file_list");
311 		this.callv(_GODOT_method_name, _GODOT_args);
312 	}
313 	/**
314 	
315 	*/
316 	void _updateFileName()
317 	{
318 		Array _GODOT_args = Array.make();
319 		String _GODOT_method_name = String("_update_file_name");
320 		this.callv(_GODOT_method_name, _GODOT_args);
321 	}
322 	/**
323 	Adds `filter` as a custom filter; `filter` should be of the form `"filename.extension ; Description"`. For example, `"*.png ; PNG Images"`.
324 	*/
325 	void addFilter(in String filter)
326 	{
327 		checkClassBinding!(typeof(this))();
328 		ptrcall!(void)(GDNativeClassBinding.addFilter, _godot_object, filter);
329 	}
330 	/**
331 	Clear all the added filters in the dialog.
332 	*/
333 	void clearFilters()
334 	{
335 		checkClassBinding!(typeof(this))();
336 		ptrcall!(void)(GDNativeClassBinding.clearFilters, _godot_object);
337 	}
338 	/**
339 	Clear currently selected items in the dialog.
340 	*/
341 	void deselectItems()
342 	{
343 		checkClassBinding!(typeof(this))();
344 		ptrcall!(void)(GDNativeClassBinding.deselectItems, _godot_object);
345 	}
346 	/**
347 	
348 	*/
349 	FileDialog.Access getAccess() const
350 	{
351 		checkClassBinding!(typeof(this))();
352 		return ptrcall!(FileDialog.Access)(GDNativeClassBinding.getAccess, _godot_object);
353 	}
354 	/**
355 	
356 	*/
357 	String getCurrentDir() const
358 	{
359 		checkClassBinding!(typeof(this))();
360 		return ptrcall!(String)(GDNativeClassBinding.getCurrentDir, _godot_object);
361 	}
362 	/**
363 	
364 	*/
365 	String getCurrentFile() const
366 	{
367 		checkClassBinding!(typeof(this))();
368 		return ptrcall!(String)(GDNativeClassBinding.getCurrentFile, _godot_object);
369 	}
370 	/**
371 	
372 	*/
373 	String getCurrentPath() const
374 	{
375 		checkClassBinding!(typeof(this))();
376 		return ptrcall!(String)(GDNativeClassBinding.getCurrentPath, _godot_object);
377 	}
378 	/**
379 	
380 	*/
381 	PoolStringArray getFilters() const
382 	{
383 		checkClassBinding!(typeof(this))();
384 		return ptrcall!(PoolStringArray)(GDNativeClassBinding.getFilters, _godot_object);
385 	}
386 	/**
387 	Returns the LineEdit for the selected file.
388 	*/
389 	LineEdit getLineEdit()
390 	{
391 		checkClassBinding!(typeof(this))();
392 		return ptrcall!(LineEdit)(GDNativeClassBinding.getLineEdit, _godot_object);
393 	}
394 	/**
395 	
396 	*/
397 	FileDialog.Mode getMode() const
398 	{
399 		checkClassBinding!(typeof(this))();
400 		return ptrcall!(FileDialog.Mode)(GDNativeClassBinding.getMode, _godot_object);
401 	}
402 	/**
403 	Returns the vertical box container of the dialog, custom controls can be added to it.
404 	*/
405 	VBoxContainer getVbox()
406 	{
407 		checkClassBinding!(typeof(this))();
408 		return ptrcall!(VBoxContainer)(GDNativeClassBinding.getVbox, _godot_object);
409 	}
410 	/**
411 	Invalidate and update the current dialog content list.
412 	*/
413 	void invalidate()
414 	{
415 		checkClassBinding!(typeof(this))();
416 		ptrcall!(void)(GDNativeClassBinding.invalidate, _godot_object);
417 	}
418 	/**
419 	
420 	*/
421 	bool isModeOverridingTitle() const
422 	{
423 		checkClassBinding!(typeof(this))();
424 		return ptrcall!(bool)(GDNativeClassBinding.isModeOverridingTitle, _godot_object);
425 	}
426 	/**
427 	
428 	*/
429 	bool isShowingHiddenFiles() const
430 	{
431 		checkClassBinding!(typeof(this))();
432 		return ptrcall!(bool)(GDNativeClassBinding.isShowingHiddenFiles, _godot_object);
433 	}
434 	/**
435 	
436 	*/
437 	void setAccess(in long access)
438 	{
439 		checkClassBinding!(typeof(this))();
440 		ptrcall!(void)(GDNativeClassBinding.setAccess, _godot_object, access);
441 	}
442 	/**
443 	
444 	*/
445 	void setCurrentDir(in String dir)
446 	{
447 		checkClassBinding!(typeof(this))();
448 		ptrcall!(void)(GDNativeClassBinding.setCurrentDir, _godot_object, dir);
449 	}
450 	/**
451 	
452 	*/
453 	void setCurrentFile(in String file)
454 	{
455 		checkClassBinding!(typeof(this))();
456 		ptrcall!(void)(GDNativeClassBinding.setCurrentFile, _godot_object, file);
457 	}
458 	/**
459 	
460 	*/
461 	void setCurrentPath(in String path)
462 	{
463 		checkClassBinding!(typeof(this))();
464 		ptrcall!(void)(GDNativeClassBinding.setCurrentPath, _godot_object, path);
465 	}
466 	/**
467 	
468 	*/
469 	void setFilters(in PoolStringArray filters)
470 	{
471 		checkClassBinding!(typeof(this))();
472 		ptrcall!(void)(GDNativeClassBinding.setFilters, _godot_object, filters);
473 	}
474 	/**
475 	
476 	*/
477 	void setMode(in long mode)
478 	{
479 		checkClassBinding!(typeof(this))();
480 		ptrcall!(void)(GDNativeClassBinding.setMode, _godot_object, mode);
481 	}
482 	/**
483 	
484 	*/
485 	void setModeOverridesTitle(in bool _override)
486 	{
487 		checkClassBinding!(typeof(this))();
488 		ptrcall!(void)(GDNativeClassBinding.setModeOverridesTitle, _godot_object, _override);
489 	}
490 	/**
491 	
492 	*/
493 	void setShowHiddenFiles(in bool show)
494 	{
495 		checkClassBinding!(typeof(this))();
496 		ptrcall!(void)(GDNativeClassBinding.setShowHiddenFiles, _godot_object, show);
497 	}
498 	/**
499 	The file system access scope. See enum `Access` constants.
500 	$(B Warning:) Currently, in sandboxed environments such as HTML5 builds or sandboxed macOS apps, FileDialog cannot access the host file system. See $(D url=https://github.com/godotengine/godot-proposals/issues/1123)godot-proposals#1123$(D /url).
501 	*/
502 	@property FileDialog.Access access()
503 	{
504 		return getAccess();
505 	}
506 	/// ditto
507 	@property void access(long v)
508 	{
509 		setAccess(v);
510 	}
511 	/**
512 	The current working directory of the file dialog.
513 	*/
514 	@property String currentDir()
515 	{
516 		return getCurrentDir();
517 	}
518 	/// ditto
519 	@property void currentDir(String v)
520 	{
521 		setCurrentDir(v);
522 	}
523 	/**
524 	The currently selected file of the file dialog.
525 	*/
526 	@property String currentFile()
527 	{
528 		return getCurrentFile();
529 	}
530 	/// ditto
531 	@property void currentFile(String v)
532 	{
533 		setCurrentFile(v);
534 	}
535 	/**
536 	The currently selected file path of the file dialog.
537 	*/
538 	@property String currentPath()
539 	{
540 		return getCurrentPath();
541 	}
542 	/// ditto
543 	@property void currentPath(String v)
544 	{
545 		setCurrentPath(v);
546 	}
547 	/**
548 	The available file type filters. For example, this shows only `.png` and `.gd` files: `set_filters(PoolStringArray($(D "*.png ; PNG Images","*.gd ; GDScript Files")))`.
549 	*/
550 	@property PoolStringArray filters()
551 	{
552 		return getFilters();
553 	}
554 	/// ditto
555 	@property void filters(PoolStringArray v)
556 	{
557 		setFilters(v);
558 	}
559 	/**
560 	The dialog's open or save mode, which affects the selection behavior. See enum `Mode` constants.
561 	*/
562 	@property FileDialog.Mode mode()
563 	{
564 		return getMode();
565 	}
566 	/// ditto
567 	@property void mode(long v)
568 	{
569 		setMode(v);
570 	}
571 	/**
572 	If `true`, changing the `Mode` property will set the window title accordingly (e.g. setting mode to $(D constant MODE_OPEN_FILE) will change the window title to "Open a File").
573 	*/
574 	@property bool modeOverridesTitle()
575 	{
576 		return isModeOverridingTitle();
577 	}
578 	/// ditto
579 	@property void modeOverridesTitle(bool v)
580 	{
581 		setModeOverridesTitle(v);
582 	}
583 	/**
584 	If `true`, the dialog will show hidden files.
585 	*/
586 	@property bool showHiddenFiles()
587 	{
588 		return isShowingHiddenFiles();
589 	}
590 	/// ditto
591 	@property void showHiddenFiles(bool v)
592 	{
593 		setShowHiddenFiles(v);
594 	}
595 }