Skip to content

Commit

Permalink
[Native File Dialog] Add support for adding custom options to the dia…
Browse files Browse the repository at this point in the history
…logs.

Add support for adding custom options (checkboxes and optionboxes) to the dialogs (both native and built-in).
Add support for using native dialogs in the editor.
  • Loading branch information
bruvzg committed Jan 25, 2024
1 parent 5034478 commit b1e0170
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 71 deletions.
63 changes: 63 additions & 0 deletions doc/classes/EditorFileDialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
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="index" type="int" />
<description>
Adds an additional [OptionButton] to the file dialog. If [param values] is empty, a [CheckBox] is added instead.
</description>
</method>
<method name="add_side_menu">
<return type="void" />
<param index="0" name="menu" type="Control" />
Expand All @@ -40,6 +49,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 +89,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="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 +140,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 @@ -627,6 +627,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/inspector/float_drag_speed" type="float" setter="" getter="">
Base speed for increasing/decreasing float values by dragging them in the inspector.
</member>
Expand Down
24 changes: 10 additions & 14 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,9 @@ void EditorNode::_dialog_action(String p_file) {

case FILE_EXPORT_MESH_LIBRARY: {
Ref<MeshLibrary> ml;
if (file_export_lib_merge->is_pressed() && FileAccess::exists(p_file)) {
const Dictionary &fd_options = file_export_lib->get_selected_options();
bool file_export_lib_merge = (bool)fd_options.get(TTR("Merge With Existing"), true);
if (file_export_lib_merge && FileAccess::exists(p_file)) {
ml = ResourceLoader::load(p_file, "MeshLibrary");

if (ml.is_null()) {
Expand All @@ -2038,7 +2040,8 @@ void EditorNode::_dialog_action(String p_file) {
ml = Ref<MeshLibrary>(memnew(MeshLibrary));
}

MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true, file_export_lib_apply_xforms->is_pressed());
bool file_export_lib_apply_xforms = (bool)fd_options.get(TTR("Apply MeshInstance Transforms"), false);
MeshLibraryEditor::update_library_file(editor_data.get_edited_scene_root(), ml, true, file_export_lib_apply_xforms);

Error err = ResourceSaver::save(ml, p_file);
if (err) {
Expand Down Expand Up @@ -2660,8 +2663,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 @@ -3092,8 +3095,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 @@ -7188,16 +7191,9 @@ 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 @@ -392,8 +392,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 @@ -413,6 +413,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_USAGE(Variant::FLOAT, PROPERTY_HINT_RANGE, "interface/editor/custom_display_scale", 1.0, "0.5,3,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)
Expand Down
26 changes: 12 additions & 14 deletions editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,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 = (bool)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);
}
}

Expand Down Expand Up @@ -1084,7 +1087,11 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) {
exporting = true;

platform->clear_messages();
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 = (bool)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 @@ -1485,17 +1492,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 @@ -152,8 +152,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

0 comments on commit b1e0170

Please sign in to comment.