godot/editor/editor_file_dialog.h

261 lines
8.2 KiB
C++
Raw Normal View History

2015-05-31 04:59:42 +00:00
/*************************************************************************/
/* editor_file_dialog.h */
2015-05-31 04:59:42 +00:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
2015-05-31 04:59:42 +00:00
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
2015-05-31 04:59:42 +00:00
/* */
/* 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 EDITOR_FILE_DIALOG_H
#define EDITOR_FILE_DIALOG_H
2015-05-31 04:59:42 +00:00
#include "core/io/dir_access.h"
#include "editor/plugins/editor_preview_plugins.h"
#include "scene/gui/box_container.h"
2015-05-31 04:59:42 +00:00
#include "scene/gui/dialogs.h"
#include "scene/gui/item_list.h"
2015-05-31 04:59:42 +00:00
#include "scene/gui/line_edit.h"
#include "scene/gui/option_button.h"
2017-12-25 04:29:00 +00:00
#include "scene/gui/separator.h"
#include "scene/gui/split_container.h"
#include "scene/gui/texture_rect.h"
class DependencyRemoveDialog;
2015-05-31 04:59:42 +00:00
class EditorFileDialog : public ConfirmationDialog {
GDCLASS(EditorFileDialog, ConfirmationDialog);
2015-05-31 04:59:42 +00:00
public:
enum DisplayMode {
DISPLAY_THUMBNAILS,
DISPLAY_LIST
};
2015-05-31 04:59:42 +00:00
enum Access {
ACCESS_RESOURCES,
ACCESS_USERDATA,
ACCESS_FILESYSTEM
};
enum FileMode {
FILE_MODE_OPEN_FILE,
FILE_MODE_OPEN_FILES,
FILE_MODE_OPEN_DIR,
FILE_MODE_OPEN_ANY,
FILE_MODE_SAVE_FILE
2015-05-31 04:59:42 +00:00
};
typedef Ref<Texture2D> (*GetIconFunc)(const String &);
typedef void (*RegisterFunc)(EditorFileDialog *);
2015-05-31 04:59:42 +00:00
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 = nullptr;
LineEdit *makedirname = nullptr;
2015-05-31 04:59:42 +00:00
Button *makedir = nullptr;
Access access = ACCESS_RESOURCES;
VBoxContainer *vbox = nullptr;
FileMode mode = FILE_MODE_SAVE_FILE;
bool can_create_dir = false;
LineEdit *dir = nullptr;
Button *dir_prev = nullptr;
Button *dir_next = nullptr;
Button *dir_up = nullptr;
HBoxContainer *drives_container = nullptr;
HBoxContainer *shortcuts_container = nullptr;
OptionButton *drives = nullptr;
ItemList *item_list = nullptr;
PopupMenu *item_menu = nullptr;
TextureRect *preview = nullptr;
VBoxContainer *preview_vb = nullptr;
HSplitContainer *list_hb = nullptr;
HBoxContainer *file_box = nullptr;
LineEdit *file = nullptr;
OptionButton *filter = nullptr;
AcceptDialog *error_dialog = nullptr;
Ref<DirAccess> dir_access;
ConfirmationDialog *confirm_save = nullptr;
DependencyRemoveDialog *dep_remove_dialog = nullptr;
ConfirmationDialog *global_remove_dialog = nullptr;
Button *mode_thumbnails = nullptr;
Button *mode_list = nullptr;
Button *refresh = nullptr;
Button *favorite = nullptr;
Button *show_hidden = nullptr;
Button *fav_up = nullptr;
Button *fav_down = nullptr;
ItemList *favorites = nullptr;
ItemList *recent = nullptr;
Vector<String> local_history;
int local_history_pos = 0;
void _push_history();
2015-05-31 04:59:42 +00:00
Vector<String> filters;
bool previews_enabled = true;
bool preview_waiting = false;
int preview_wheel_index = 0;
float preview_wheel_timeout = 0.0f;
2015-05-31 04:59:42 +00:00
static bool default_show_hidden_files;
static DisplayMode default_display_mode;
2015-05-31 04:59:42 +00:00
bool show_hidden_files;
DisplayMode display_mode;
2015-05-31 04:59:42 +00:00
bool disable_overwrite_warning = false;
bool invalidated = true;
2015-05-31 04:59:42 +00:00
void update_dir();
void update_file_name();
2015-05-31 04:59:42 +00:00
void update_file_list();
void update_filters();
void _focus_file_text();
void _update_favorites();
void _favorite_pressed();
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(const Vector2 &p_pos, MouseButton p_mouse_button_index);
void _item_dc_selected(int p_item);
2015-05-31 04:59:42 +00:00
2021-11-25 23:53:27 +00:00
void _item_list_item_rmb_clicked(int p_item, const Vector2 &p_pos, MouseButton p_mouse_button_index);
void _item_list_empty_clicked(const Vector2 &p_pos, MouseButton p_mouse_button_index);
void _item_menu_id_pressed(int p_option);
2015-05-31 04:59:42 +00:00
void _select_drive(int p_idx);
void _dir_submitted(String p_dir);
void _file_submitted(const String &p_file);
2015-05-31 04:59:42 +00:00
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 _delete_files_global();
void _update_drives(bool p_select = true);
void _update_icons();
2015-05-31 04:59:42 +00:00
void _go_up();
void _go_back();
void _go_forward();
2015-05-31 04:59:42 +00:00
2020-07-10 10:34:39 +00:00
virtual void _post_popup() override;
2015-05-31 04:59:42 +00:00
void _save_to_recent();
// Callback function is callback(String p_path,Ref<Texture2D> preview,Variant udata) preview null if could not load.
2015-05-31 04:59:42 +00:00
void _thumbnail_result(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
void _request_single_thumbnail(const String &p_path);
2015-05-31 04:59:42 +00:00
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
bool _is_open_should_be_disabled();
2015-05-31 04:59:42 +00:00
protected:
void _notification(int p_what);
static void _bind_methods();
2015-05-31 04:59:42 +00:00
public:
void popup_file_dialog();
2015-05-31 04:59:42 +00:00
void clear_filters();
void add_filter(const String &p_filter, const String &p_description = "");
2015-05-31 04:59:42 +00:00
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);
2015-05-31 04:59:42 +00:00
void set_display_mode(DisplayMode p_mode);
DisplayMode get_display_mode() const;
void set_file_mode(FileMode p_mode);
FileMode get_file_mode() const;
2015-05-31 04:59:42 +00:00
VBoxContainer *get_vbox();
LineEdit *get_line_edit() { return file; }
void set_access(Access p_access);
Access get_access() const;
static void set_default_show_hidden_files(bool p_show);
static void set_default_display_mode(DisplayMode p_mode);
void set_show_hidden_files(bool p_show);
bool is_showing_hidden_files() const;
2015-05-31 04:59:42 +00:00
void invalidate();
void set_disable_overwrite_warning(bool p_disable);
bool is_overwrite_warning_disabled() const;
void set_previews_enabled(bool p_enabled);
bool are_previews_enabled();
2015-05-31 04:59:42 +00:00
EditorFileDialog();
~EditorFileDialog();
};
VARIANT_ENUM_CAST(EditorFileDialog::FileMode);
VARIANT_ENUM_CAST(EditorFileDialog::Access);
VARIANT_ENUM_CAST(EditorFileDialog::DisplayMode);
2015-05-31 04:59:42 +00:00
#endif // EDITOR_FILE_DIALOG_H