Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Native File Dialog] Add support for using native dialogs in the editor. #89735

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions doc/classes/EditorFileDialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
For example, a [param filter] of [code]"*.tscn, *.scn"[/code] and a [param description] of [code]"Scenes"[/code] results in filter text "Scenes (*.tscn, *.scn)".
</description>
</method>
<method name="add_option">
<return type="void" />
<param index="0" name="name" type="String" />
<param index="1" name="values" type="PackedStringArray" />
<param index="2" name="default_value_index" type="int" />
<description>
Adds an additional [OptionButton] to the file dialog. If [param values] is empty, a [CheckBox] is added instead.
[param default_value_index] should be an index of the value in the [param values]. If [param values] is empty it should be either [code]1[/code] (checked), or [code]0[/code] (unchecked).
</description>
</method>
<method name="add_side_menu">
<return type="void" />
<param index="0" name="menu" type="Control" />
Expand All @@ -40,6 +50,33 @@
[b]Warning:[/b] This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their [member CanvasItem.visible] property.
</description>
</method>
<method name="get_option_default" qualifiers="const">
<return type="int" />
<param index="0" name="option" type="int" />
<description>
Returns the default value index of the [OptionButton] or [CheckBox] with index [param option].
</description>
</method>
<method name="get_option_name" qualifiers="const">
<return type="String" />
<param index="0" name="option" type="int" />
<description>
Returns the name of the [OptionButton] or [CheckBox] with index [param option].
</description>
</method>
<method name="get_option_values" qualifiers="const">
<return type="PackedStringArray" />
<param index="0" name="option" type="int" />
<description>
Returns an array of values of the [OptionButton] with index [param option].
</description>
</method>
<method name="get_selected_options" qualifiers="const">
<return type="Dictionary" />
<description>
Returns a [Dictionary] with the selected values of the additional [OptionButton]s and/or [CheckBox]es. [Dictionary] keys are names and values are selected value indices.
</description>
</method>
<method name="get_vbox">
<return type="VBoxContainer" />
<description>
Expand All @@ -53,6 +90,30 @@
Notify the [EditorFileDialog] that its view of the data is no longer accurate. Updates the view contents on next view update.
</description>
</method>
<method name="set_option_default">
<return type="void" />
<param index="0" name="option" type="int" />
<param index="1" name="default_value_index" type="int" />
<description>
Sets the default value index of the [OptionButton] or [CheckBox] with index [param option].
</description>
</method>
<method name="set_option_name">
<return type="void" />
<param index="0" name="option" type="int" />
<param index="1" name="name" type="String" />
<description>
Sets the name of the [OptionButton] or [CheckBox] with index [param option].
</description>
</method>
<method name="set_option_values">
<return type="void" />
<param index="0" name="option" type="int" />
<param index="1" name="values" type="PackedStringArray" />
<description>
Sets the option values of the [OptionButton] with index [param option].
</description>
</method>
</methods>
<members>
<member name="access" type="int" setter="set_access" getter="get_access" enum="EditorFileDialog.Access" default="0">
Expand Down Expand Up @@ -80,6 +141,9 @@
<member name="filters" type="PackedStringArray" setter="set_filters" getter="get_filters" default="PackedStringArray()">
The available file type filters. For example, this shows only [code].png[/code] and [code].gd[/code] files: [code]set_filters(PackedStringArray(["*.png ; PNG Images","*.gd ; GDScript Files"]))[/code]. Multiple file types can also be specified in a single filter. [code]"*.png, *.jpg, *.jpeg ; Supported Images"[/code] will show both PNG and JPEG files when selected.
</member>
<member name="option_count" type="int" setter="set_option_count" getter="get_option_count" default="0">
The number of additional [OptionButton]s and [CheckBox]es in the dialog.
</member>
<member name="show_hidden_files" type="bool" setter="set_show_hidden_files" getter="is_showing_hidden_files" default="false">
If [code]true[/code], hidden files and directories will be visible in the [EditorFileDialog]. This property is synchronized with [member EditorSettings.filesystem/file_dialog/show_hidden_files].
</member>
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/EditorSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@
If [code]true[/code], editor main menu is using embedded [MenuBar] instead of system global menu.
Specific to the macOS platform.
</member>
<member name="interface/editor/use_native_file_dialogs" type="bool" setter="" getter="">
If [code]true[/code], editor UI uses OS native file/directory selection dialogs.
</member>
<member name="interface/editor/vsync_mode" type="int" setter="" getter="">
Sets the V-Sync mode for the editor. Does not affect the project when run from the editor (this is controlled by [member ProjectSettings.display/window/vsync/vsync_mode]).
Depending on the platform and used renderer, the engine will fall back to [b]Enabled[/b] if the desired mode is not supported.
Expand Down
5 changes: 3 additions & 2 deletions doc/classes/FileDialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
<return type="void" />
<param index="0" name="name" type="String" />
<param index="1" name="values" type="PackedStringArray" />
<param index="2" name="index" type="int" />
<param index="2" name="default_value_index" type="int" />
<description>
Adds an additional [OptionButton] to the file dialog. If [param values] is empty, a [CheckBox] is added instead.
[param default_value_index] should be an index of the value in the [param values]. If [param values] is empty it should be either [code]1[/code] (checked), or [code]0[/code] (unchecked).
</description>
</method>
<method name="clear_filters">
Expand Down Expand Up @@ -90,7 +91,7 @@
<method name="set_option_default">
<return type="void" />
<param index="0" name="option" type="int" />
<param index="1" name="index" type="int" />
<param index="1" name="default_value_index" type="int" />
<description>
Sets the default value index of the [OptionButton] or [CheckBox] with index [param option].
</description>
Expand Down
21 changes: 7 additions & 14 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2066,8 +2066,9 @@ void EditorNode::_dialog_action(String p_file) {
} break;

case FILE_EXPORT_MESH_LIBRARY: {
bool merge_with_existing_library = file_export_lib_merge->is_pressed();
bool apply_mesh_instance_transforms = file_export_lib_apply_xforms->is_pressed();
const Dictionary &fd_options = file_export_lib->get_selected_options();
bool merge_with_existing_library = fd_options.get(TTR("Merge With Existing"), true);
bool apply_mesh_instance_transforms = fd_options.get(TTR("Apply MeshInstance Transforms"), false);

Ref<MeshLibrary> ml;
if (merge_with_existing_library && FileAccess::exists(p_file)) {
Expand Down Expand Up @@ -2723,8 +2724,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
root_name = EditorNode::adjust_scene_name_casing(root_name);
file->set_current_path(root_name + "." + extensions.front()->get().to_lower());
}
file->popup_file_dialog();
file->set_title(TTR("Save Scene As..."));
file->popup_file_dialog();

} break;

Expand Down Expand Up @@ -3238,8 +3239,8 @@ void EditorNode::_export_as_menu_option(int p_idx) {
file_export_lib->add_filter("*." + E);
}

file_export_lib->popup_file_dialog();
file_export_lib->set_title(TTR("Export Mesh Library"));
file_export_lib->popup_file_dialog();
} else { // Custom menu options added by plugins
if (export_as_menu->get_item_submenu(p_idx).is_empty()) { // If not a submenu
Callable callback = export_as_menu->get_item_metadata(p_idx);
Expand Down Expand Up @@ -7128,16 +7129,8 @@ EditorNode::EditorNode() {
file_export_lib->set_title(TTR("Export Library"));
file_export_lib->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
file_export_lib->connect("file_selected", callable_mp(this, &EditorNode::_dialog_action));
file_export_lib_merge = memnew(CheckBox);
file_export_lib_merge->set_text(TTR("Merge With Existing"));
file_export_lib_merge->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
file_export_lib_merge->set_pressed(true);
file_export_lib->get_vbox()->add_child(file_export_lib_merge);
file_export_lib_apply_xforms = memnew(CheckBox);
file_export_lib_apply_xforms->set_text(TTR("Apply MeshInstance Transforms"));
file_export_lib_apply_xforms->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
file_export_lib_apply_xforms->set_pressed(false);
file_export_lib->get_vbox()->add_child(file_export_lib_apply_xforms);
file_export_lib->add_option(TTR("Merge With Existing"), Vector<String>(), true);
file_export_lib->add_option(TTR("Apply MeshInstance Transforms"), Vector<String>(), false);
gui_base->add_child(file_export_lib);

file_script = memnew(EditorFileDialog);
Expand Down
2 changes: 0 additions & 2 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ class EditorNode : public Node {
EditorFileDialog *file_export_lib = nullptr;
EditorFileDialog *file_script = nullptr;
EditorFileDialog *file_android_build_source = nullptr;
CheckBox *file_export_lib_merge = nullptr;
CheckBox *file_export_lib_apply_xforms = nullptr;
String current_path;
MenuButton *update_spinner = nullptr;

Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
set_restart_if_changed("interface/editor/debug/enable_pseudolocalization", true);
// Use pseudolocalization in editor.
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_embedded_menu", false, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/use_native_file_dialogs", false, "", PROPERTY_USAGE_DEFAULT)
EDITOR_SETTING_USAGE(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/expand_to_title", true, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)

EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "interface/editor/main_font_size", 14, "8,48,1")
Expand Down
25 changes: 11 additions & 14 deletions editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,13 @@ void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {
Ref<EditorExportPlatform> platform = current->get_platform();
ERR_FAIL_COND(platform.is_null());

const Dictionary &fd_option = export_pck_zip->get_selected_options();
bool export_debug = fd_option.get(TTR("Export With Debug"), true);

if (p_path.ends_with(".zip")) {
platform->export_zip(current, export_pck_zip_debug->is_pressed(), p_path);
platform->export_zip(current, export_debug, p_path);
} else if (p_path.ends_with(".pck")) {
platform->export_pack(current, export_pck_zip_debug->is_pressed(), p_path);
platform->export_pack(current, export_debug, p_path);
} else {
ERR_FAIL_MSG("Path must end with .pck or .zip");
}
Expand Down Expand Up @@ -1123,7 +1126,10 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) {

platform->clear_messages();
current->update_value_overrides();
Error err = platform->export_project(current, export_debug->is_pressed(), current->get_export_path(), 0);
Dictionary fd_option = export_project->get_selected_options();
bool export_debug = fd_option.get(TTR("Export With Debug"), true);

Error err = platform->export_project(current, export_debug, current->get_export_path(), 0);
result_dialog_log->clear();
if (err != ERR_SKIP) {
if (platform->fill_log_messages(result_dialog_log, err)) {
Expand Down Expand Up @@ -1552,17 +1558,8 @@ ProjectExportDialog::ProjectExportDialog() {
export_project->connect("file_selected", callable_mp(this, &ProjectExportDialog::_export_project_to_path));
export_project->get_line_edit()->connect("text_changed", callable_mp(this, &ProjectExportDialog::_validate_export_path));

export_debug = memnew(CheckBox);
export_debug->set_text(TTR("Export With Debug"));
export_debug->set_pressed(true);
export_debug->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
export_project->get_vbox()->add_child(export_debug);

export_pck_zip_debug = memnew(CheckBox);
export_pck_zip_debug->set_text(TTR("Export With Debug"));
export_pck_zip_debug->set_pressed(true);
export_pck_zip_debug->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
export_pck_zip->get_vbox()->add_child(export_pck_zip_debug);
export_project->add_option(TTR("Export With Debug"), Vector<String>(), true);
export_pck_zip->add_option(TTR("Export With Debug"), Vector<String>(), true);

set_hide_on_ok(false);

Expand Down
2 changes: 0 additions & 2 deletions editor/export/project_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class ProjectExportDialog : public ConfirmationDialog {

EditorFileDialog *export_pck_zip = nullptr;
EditorFileDialog *export_project = nullptr;
CheckBox *export_debug = nullptr;
CheckBox *export_pck_zip_debug = nullptr;

CheckButton *enc_pck = nullptr;
CheckButton *enc_directory = nullptr;
Expand Down
Loading
Loading