virtualx-engine/scene/gui/file_dialog.h

264 lines
8.1 KiB
C++
Raw Normal View History

/**************************************************************************/
/* file_dialog.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* 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. */
/**************************************************************************/
2014-02-10 02:10:30 +01:00
#ifndef FILE_DIALOG_H
#define FILE_DIALOG_H
#include "box_container.h"
#include "core/io/dir_access.h"
#include "scene/gui/dialogs.h"
2014-02-10 02:10:30 +01:00
#include "scene/gui/line_edit.h"
#include "scene/gui/option_button.h"
#include "scene/gui/tree.h"
2019-08-10 14:28:17 +02:00
class GridContainer;
2014-02-10 02:10:30 +01:00
class FileDialog : public ConfirmationDialog {
GDCLASS(FileDialog, ConfirmationDialog);
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
public:
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
2014-02-10 02:10:30 +01:00
};
typedef Ref<Texture2D> (*GetIconFunc)(const String &);
typedef void (*RegisterFunc)(FileDialog *);
2014-02-10 02:10:30 +01:00
static GetIconFunc get_icon_func;
static RegisterFunc register_func;
static RegisterFunc unregister_func;
private:
ConfirmationDialog *makedialog = nullptr;
LineEdit *makedirname = nullptr;
2014-02-10 02:10:30 +01:00
Button *makedir = nullptr;
Access access = ACCESS_RESOURCES;
VBoxContainer *vbox = nullptr;
GridContainer *grid_options = nullptr;
FileMode mode;
LineEdit *dir = nullptr;
HBoxContainer *drives_container = nullptr;
HBoxContainer *shortcuts_container = nullptr;
OptionButton *drives = nullptr;
Tree *tree = nullptr;
HBoxContainer *file_box = nullptr;
LineEdit *file = nullptr;
OptionButton *filter = nullptr;
AcceptDialog *mkdirerr = nullptr;
AcceptDialog *exterr = nullptr;
Ref<DirAccess> dir_access;
ConfirmationDialog *confirm_save = nullptr;
Label *message = nullptr;
Button *dir_prev = nullptr;
Button *dir_next = nullptr;
Button *dir_up = nullptr;
Button *refresh = nullptr;
Button *show_hidden = nullptr;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
Vector<String> filters;
Vector<String> local_history;
int local_history_pos = 0;
void _push_history();
bool mode_overrides_title = true;
2022-03-13 01:35:20 +01:00
String root_subfolder;
String root_prefix;
static bool default_show_hidden_files;
bool show_hidden_files = false;
bool use_native_dialog = false;
2023-01-22 18:26:32 +01:00
bool is_invalidating = false;
2016-03-09 00:00:52 +01:00
struct ThemeCache {
Ref<Texture2D> parent_folder;
Ref<Texture2D> forward_folder;
Ref<Texture2D> back_folder;
Ref<Texture2D> reload;
Ref<Texture2D> toggle_hidden;
Ref<Texture2D> folder;
Ref<Texture2D> file;
2024-02-25 17:51:50 +01:00
Ref<Texture2D> create_folder;
Color folder_icon_color;
Color file_icon_color;
Color file_disabled_color;
Color icon_normal_color;
Color icon_hover_color;
Color icon_focus_color;
Color icon_pressed_color;
} theme_cache;
struct Option {
String name;
Vector<String> values;
int default_idx = 0;
};
Vector<Option> options;
Dictionary selected_options;
bool options_dirty = false;
2014-02-10 02:10:30 +01:00
void update_dir();
void update_file_name();
2014-02-10 02:10:30 +01:00
void update_file_list();
void update_filters();
2016-03-09 00:00:52 +01:00
void _focus_file_text();
void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected);
2014-02-10 02:10:30 +01:00
void _tree_selected();
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
void _select_drive(int p_idx);
void _tree_item_activated();
void _dir_submitted(String p_dir);
void _file_submitted(const String &p_file);
2014-02-10 02:10:30 +01:00
void _action_pressed();
void _save_confirm_pressed();
void _cancel_pressed();
void _filter_selected(int);
void _make_dir();
void _make_dir_confirm();
void _go_up();
void _go_back();
void _go_forward();
2014-02-10 02:10:30 +01:00
2022-03-13 01:35:20 +01:00
void _change_dir(const String &p_new_dir);
void _update_drives(bool p_select = true);
2014-02-10 02:10:30 +01:00
2023-01-22 18:26:32 +01:00
void _invalidate();
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
void _native_popup();
void _native_dialog_cb(bool p_ok, const Vector<String> &p_files, int p_filter, const Dictionary &p_selected_options);
bool _is_open_should_be_disabled();
TypedArray<Dictionary> _get_options() const;
void _update_option_controls();
void _option_changed_checkbox_toggled(bool p_pressed, const String &p_name);
void _option_changed_item_selected(int p_idx, const String &p_name);
2020-07-10 12:34:39 +02:00
virtual void _post_popup() override;
2014-02-10 02:10:30 +01:00
protected:
void _validate_property(PropertyInfo &p_property) const;
2014-02-10 02:10:30 +01:00
void _notification(int p_what);
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
2014-02-10 02:10:30 +01:00
static void _bind_methods();
2023-09-08 21:00:10 +02:00
2014-02-10 02:10:30 +01:00
public:
virtual void set_visible(bool p_visible) override;
virtual void popup(const Rect2i &p_rect = Rect2i()) override;
void popup_file_dialog();
2014-02-10 02:10:30 +01:00
void clear_filters();
void add_filter(const String &p_filter, const String &p_description = "");
void set_filters(const Vector<String> &p_filters);
Vector<String> get_filters() const;
2014-02-10 02:10:30 +01:00
void set_enable_multiple_selection(bool p_enable);
Vector<String> get_selected_files() const;
2016-03-09 00:00:52 +01:00
2014-02-10 02:10:30 +01:00
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);
2014-02-10 02:10:30 +01:00
String get_option_name(int p_option) const;
Vector<String> get_option_values(int p_option) const;
int get_option_default(int p_option) const;
void set_option_name(int p_option, const String &p_name);
void set_option_values(int p_option, const Vector<String> &p_values);
void set_option_default(int p_option, int p_index);
void add_option(const String &p_name, const Vector<String> &p_values, int p_index);
void set_option_count(int p_count);
int get_option_count() const;
Dictionary get_selected_options() const;
2022-03-13 01:35:20 +01:00
void set_root_subfolder(const String &p_root);
String get_root_subfolder() const;
void set_mode_overrides_title(bool p_override);
bool is_mode_overriding_title() const;
void set_use_native_dialog(bool p_native);
bool get_use_native_dialog() const;
void set_file_mode(FileMode p_mode);
FileMode get_file_mode() const;
2014-02-10 02:10:30 +01:00
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);
2014-02-10 02:10:30 +01:00
void invalidate();
2016-03-09 00:00:52 +01:00
2020-12-21 11:26:41 +01:00
void deselect_all();
2016-03-09 00:00:52 +01:00
FileDialog();
2014-02-10 02:10:30 +01:00
~FileDialog();
};
VARIANT_ENUM_CAST(FileDialog::FileMode);
VARIANT_ENUM_CAST(FileDialog::Access);
2014-02-10 02:10:30 +01:00
#endif // FILE_DIALOG_H