File: editor_file_dialog.h

package info (click to toggle)
godot 3.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 104,964 kB
  • sloc: ansic: 732,795; cpp: 601,776; xml: 56,216; asm: 17,127; lisp: 12,017; python: 9,048; java: 8,253; cs: 5,803; sh: 557; perl: 275; makefile: 98; objc: 17
file content (271 lines) | stat: -rw-r--r-- 7,868 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*************************************************************************/
/*  editor_file_dialog.h                                                 */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                      https://godotengine.org                          */
/*************************************************************************/
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.                 */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)    */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/

#ifndef EDITORFILEDIALOG_H
#define EDITORFILEDIALOG_H

#include "os/dir_access.h"
#include "scene/gui/box_container.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/item_list.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/option_button.h"
#include "scene/gui/separator.h"
#include "scene/gui/split_container.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tool_button.h"

class DependencyRemoveDialog;

/**
	@author Juan Linietsky <reduzio@gmail.com>
*/
class EditorFileDialog : public ConfirmationDialog {

	GDCLASS(EditorFileDialog, ConfirmationDialog);

public:
	enum DisplayMode {
		DISPLAY_THUMBNAILS,
		DISPLAY_LIST
	};

	enum Access {
		ACCESS_RESOURCES,
		ACCESS_USERDATA,
		ACCESS_FILESYSTEM
	};

	enum Mode {
		MODE_OPEN_FILE,
		MODE_OPEN_FILES,
		MODE_OPEN_DIR,
		MODE_OPEN_ANY,
		MODE_SAVE_FILE
	};

	typedef Ref<Texture> (*GetIconFunc)(const String &);
	typedef void (*RegisterFunc)(EditorFileDialog *);

	static GetIconFunc get_icon_func;
	static GetIconFunc get_large_icon_func;
	static RegisterFunc register_func;
	static RegisterFunc unregister_func;

private:
	enum ItemMenu {
		ITEM_MENU_COPY_PATH,
		ITEM_MENU_DELETE,
		ITEM_MENU_REFRESH,
		ITEM_MENU_NEW_FOLDER,
		ITEM_MENU_SHOW_IN_EXPLORER
	};

	ConfirmationDialog *makedialog;
	LineEdit *makedirname;

	Button *makedir;
	Access access;
	//Button *action;
	VBoxContainer *vbox;
	Mode mode;
	bool can_create_dir;
	LineEdit *dir;

	ToolButton *dir_prev;
	ToolButton *dir_next;
	ToolButton *dir_up;

	OptionButton *drives;
	ItemList *item_list;
	PopupMenu *item_menu;
	TextureRect *preview;
	VBoxContainer *preview_vb;
	HSplitContainer *list_hb;
	LineEdit *file;
	AcceptDialog *mkdirerr;
	AcceptDialog *exterr;
	OptionButton *filter;
	DirAccess *dir_access;
	ConfirmationDialog *confirm_save;
	DependencyRemoveDialog *remove_dialog;
	ToolButton *mode_thumbnails;
	ToolButton *mode_list;

	ToolButton *refresh;
	ToolButton *favorite;

	ToolButton *fav_up;
	ToolButton *fav_down;
	ToolButton *fav_rm;

	ItemList *favorites;
	ItemList *recent;

	Vector<String> local_history;
	int local_history_pos;
	void _push_history();

	Vector<String> filters;

	bool preview_waiting;
	int preview_wheel_index;
	float preview_wheel_timeout;
	static bool default_show_hidden_files;
	static DisplayMode default_display_mode;
	bool show_hidden_files;
	DisplayMode display_mode;

	bool disable_overwrite_warning;
	bool invalidated;

	void update_dir();
	void update_file_list();
	void update_filters();

	void _update_favorites();
	void _favorite_toggled(bool p_toggle);
	void _favorite_selected(int p_idx);
	void _favorite_move_up();
	void _favorite_move_down();

	void _recent_selected(int p_idx);

	void _item_selected(int p_item);
	void _multi_selected(int p_item, bool p_selected);
	void _items_clear_selection();
	void _item_dc_selected(int p_item);

	void _item_list_item_rmb_selected(int p_item, const Vector2 &p_pos);
	void _item_list_rmb_clicked(const Vector2 &p_pos);
	void _item_menu_id_pressed(int p_option);

	void _select_drive(int p_idx);
	void _dir_entered(String p_dir);
	void _file_entered(const String &p_file);
	void _action_pressed();
	void _save_confirm_pressed();
	void _cancel_pressed();
	void _filter_selected(int);
	void _make_dir();
	void _make_dir_confirm();

	void _delete_items();

	void _update_drives();

	void _go_up();
	void _go_back();
	void _go_forward();

	virtual void _post_popup();

	void _save_to_recent();
	//callback function is callback(String p_path,Ref<Texture> preview,Variant udata) preview null if could not load

	void _thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
	void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
	void _request_single_thumbnail(const String &p_path);

	void _unhandled_input(const Ref<InputEvent> &p_event);

	bool _is_open_should_be_disabled();

protected:
	void _notification(int p_what);
	static void _bind_methods();
	//bind helpers
public:
	void clear_filters();
	void add_filter(const String &p_filter);

	void set_enable_multiple_selection(bool p_enable);
	Vector<String> get_selected_files() const;

	String get_current_dir() const;
	String get_current_file() const;
	String get_current_path() const;
	void set_current_dir(const String &p_dir);
	void set_current_file(const String &p_file);
	void set_current_path(const String &p_path);

	void set_display_mode(DisplayMode p_mode);
	DisplayMode get_display_mode() const;

	void set_mode(Mode p_mode);
	Mode get_mode() const;

	VBoxContainer *get_vbox();
	LineEdit *get_line_edit() { return file; }

	void set_access(Access p_access);
	Access get_access() const;

	void set_show_hidden_files(bool p_show);
	bool is_showing_hidden_files() const;

	static void set_default_show_hidden_files(bool p_show);
	static void set_default_display_mode(DisplayMode p_mode);

	void invalidate();

	void set_disable_overwrite_warning(bool p_disable);
	bool is_overwrite_warning_disabled() const;

	EditorFileDialog();
	~EditorFileDialog();
};

class EditorLineEditFileChooser : public HBoxContainer {

	GDCLASS(EditorLineEditFileChooser, HBoxContainer);
	Button *button;
	LineEdit *line_edit;
	EditorFileDialog *dialog;

	void _chosen(const String &p_text);
	void _browse();

protected:
	static void _bind_methods();

public:
	Button *get_button() { return button; }
	LineEdit *get_line_edit() { return line_edit; }
	EditorFileDialog *get_file_dialog() { return dialog; }

	EditorLineEditFileChooser();
};

VARIANT_ENUM_CAST(EditorFileDialog::Mode);
VARIANT_ENUM_CAST(EditorFileDialog::Access);
VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);

#endif // EDITORFILEDIALOG_H