summaryrefslogtreecommitdiff
path: root/editor/import_dock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import_dock.cpp')
-rw-r--r--editor/import_dock.cpp73
1 files changed, 56 insertions, 17 deletions
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp
index 648e60a554..3507eaff94 100644
--- a/editor/import_dock.cpp
+++ b/editor/import_dock.cpp
@@ -42,6 +42,7 @@ public:
Vector<String> paths;
Set<StringName> checked;
bool checking;
+ String base_options_path;
bool _set(const StringName &p_name, const Variant &p_value) {
if (values.has(p_name)) {
@@ -66,7 +67,7 @@ public:
}
void _get_property_list(List<PropertyInfo> *p_list) const {
for (const PropertyInfo &E : properties) {
- if (!importer->get_option_visibility(E.name, values)) {
+ if (!importer->get_option_visibility(base_options_path, E.name, values)) {
continue;
}
PropertyInfo pi = E;
@@ -104,8 +105,9 @@ void ImportDock::set_edit_path(const String &p_path) {
params->paths.clear();
params->paths.push_back(p_path);
+ params->base_options_path = p_path;
- _update_options(config);
+ _update_options(p_path, config);
List<Ref<ResourceImporter>> importers;
ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers);
@@ -127,31 +129,37 @@ void ImportDock::set_edit_path(const String &p_path) {
}
}
- import_as->add_separator();
- import_as->add_item(TTR("Keep File (No Import)"));
- import_as->set_item_metadata(import_as->get_item_count() - 1, "keep");
- if (importer_name == "keep") {
- import_as->select(import_as->get_item_count() - 1);
- }
+ _add_keep_import_option(importer_name);
import->set_disabled(false);
+ _set_dirty(false);
import_as->set_disabled(false);
preset->set_disabled(false);
imported->set_text(p_path.get_file());
}
-void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
+void ImportDock::_add_keep_import_option(const String &p_importer_name) {
+ import_as->add_separator();
+ import_as->add_item(TTR("Keep File (No Import)"));
+ import_as->set_item_metadata(import_as->get_item_count() - 1, "keep");
+ if (p_importer_name == "keep") {
+ import_as->select(import_as->get_item_count() - 1);
+ }
+}
+
+void ImportDock::_update_options(const String &p_path, const Ref<ConfigFile> &p_config) {
List<ResourceImporter::ImportOption> options;
if (params->importer.is_valid()) {
- params->importer->get_import_options(&options);
+ params->importer->get_import_options(p_path, &options);
}
params->properties.clear();
params->values.clear();
params->checking = params->paths.size() > 1;
params->checked.clear();
+ params->base_options_path = p_path;
for (const ResourceImporter::ImportOption &E : options) {
params->properties.push_back(E.option);
@@ -179,10 +187,12 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
// Use the value that is repeated the most.
Map<String, Dictionary> value_frequency;
+ Set<String> extensions;
for (int i = 0; i < p_paths.size(); i++) {
Ref<ConfigFile> config;
config.instantiate();
+ extensions.insert(p_paths[i].get_extension());
Error err = config->load(p_paths[i] + ".import");
ERR_CONTINUE(err != OK);
@@ -218,13 +228,18 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
ERR_FAIL_COND(params->importer.is_null());
+ String base_path;
+ if (extensions.size() == 1 && p_paths.size() > 0) {
+ base_path = p_paths[0];
+ }
List<ResourceImporter::ImportOption> options;
- params->importer->get_import_options(&options);
+ params->importer->get_import_options(base_path, &options);
params->properties.clear();
params->values.clear();
params->checking = true;
params->checked.clear();
+ params->base_options_path = base_path;
for (const ResourceImporter::ImportOption &E : options) {
params->properties.push_back(E.option);
@@ -270,10 +285,13 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
}
}
+ _add_keep_import_option(params->importer->get_importer_name());
+
_update_preset_menu();
params->paths = p_paths;
import->set_disabled(false);
+ _set_dirty(false);
import_as->set_disabled(false);
preset->set_disabled(false);
@@ -319,22 +337,22 @@ void ImportDock::_importer_selected(int i_idx) {
String name = import_as->get_selected_metadata();
if (name == "keep") {
params->importer.unref();
- _update_options(Ref<ConfigFile>());
+ _update_options(params->base_options_path, Ref<ConfigFile>());
} else {
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(name);
ERR_FAIL_COND(importer.is_null());
params->importer = importer;
-
Ref<ConfigFile> config;
if (params->paths.size()) {
+ String path = params->paths[0];
config.instantiate();
- Error err = config->load(params->paths[0] + ".import");
+ Error err = config->load(path + ".import");
if (err != OK) {
config.unref();
}
}
- _update_options(config);
+ _update_options(params->base_options_path, config);
}
}
@@ -379,7 +397,7 @@ void ImportDock::_preset_selected(int p_idx) {
default: {
List<ResourceImporter::ImportOption> options;
- params->importer->get_import_options(&options, p_idx);
+ params->importer->get_import_options(params->base_options_path, &options, p_idx);
if (params->checking) {
params->checked.clear();
@@ -507,7 +525,7 @@ void ImportDock::_reimport() {
Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(importer_name);
ERR_CONTINUE(!importer.is_valid());
String group_file_property = importer->get_option_group_file();
- if (group_file_property != String()) {
+ if (!group_file_property.is_empty()) {
//can import from a group (as in, atlas)
ERR_CONTINUE(!params->values.has(group_file_property));
String group_file = params->values[group_file_property];
@@ -527,6 +545,8 @@ void ImportDock::_reimport() {
EditorFileSystem::get_singleton()->reimport_files(params->paths);
EditorFileSystem::get_singleton()->emit_signal(SNAME("filesystem_changed")); //it changed, so force emitting the signal
+
+ _set_dirty(false);
}
void ImportDock::_notification(int p_what) {
@@ -542,6 +562,24 @@ void ImportDock::_notification(int p_what) {
}
}
+void ImportDock::_property_edited(const StringName &p_prop) {
+ _set_dirty(true);
+}
+
+void ImportDock::_set_dirty(bool p_dirty) {
+ if (p_dirty) {
+ // Add a dirty marker to notify the user that they should reimport the selected resource to see changes.
+ import->set_text(TTR("Reimport") + " (*)");
+ import->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor")));
+ import->set_tooltip(TTR("You have pending changes that haven't been applied yet. Click Reimport to apply changes made to the import options.\nSelecting another resource in the FileSystem dock without clicking Reimport first will discard changes made in the Import dock."));
+ } else {
+ // Remove the dirty marker on the Reimport button.
+ import->set_text(TTR("Reimport"));
+ import->remove_theme_color_override("font_color");
+ import->set_tooltip("");
+ }
+}
+
void ImportDock::_property_toggled(const StringName &p_prop, bool p_checked) {
if (p_checked) {
params->checked.insert(p_prop);
@@ -582,6 +620,7 @@ ImportDock::ImportDock() {
import_opts = memnew(EditorInspector);
add_child(import_opts);
import_opts->set_v_size_flags(SIZE_EXPAND_FILL);
+ import_opts->connect("property_edited", callable_mp(this, &ImportDock::_property_edited));
import_opts->connect("property_toggled", callable_mp(this, &ImportDock::_property_toggled));
hb = memnew(HBoxContainer);