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.cpp165
1 files changed, 71 insertions, 94 deletions
diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp
index 20d47e8250..8ab2e0aef1 100644
--- a/editor/import_dock.cpp
+++ b/editor/import_dock.cpp
@@ -44,12 +44,11 @@ public:
bool checking;
bool _set(const StringName &p_name, const Variant &p_value) {
-
if (values.has(p_name)) {
values[p_name] = p_value;
if (checking) {
checked.insert(p_name);
- _change_notify(String(p_name).utf8().get_data());
+ _change_notify();
}
return true;
}
@@ -58,7 +57,6 @@ public:
}
bool _get(const StringName &p_name, Variant &r_ret) const {
-
if (values.has(p_name)) {
r_ret = values[p_name];
return true;
@@ -67,10 +65,10 @@ public:
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
-
for (const List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
- if (!importer->get_option_visibility(E->get().name, values))
+ if (!importer->get_option_visibility(E->get().name, values)) {
continue;
+ }
PropertyInfo pi = E->get();
if (checking) {
pi.usage |= PROPERTY_USAGE_CHECKABLE;
@@ -92,7 +90,6 @@ public:
};
void ImportDock::set_edit_path(const String &p_path) {
-
Ref<ConfigFile> config;
config.instance();
Error err = config->load(p_path + ".import");
@@ -107,21 +104,24 @@ void ImportDock::set_edit_path(const String &p_path) {
return;
}
+ params->paths.clear();
+ params->paths.push_back(p_path);
+
_update_options(config);
- List<Ref<ResourceImporter> > importers;
+ List<Ref<ResourceImporter>> importers;
ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers);
- List<Pair<String, String> > importer_names;
+ List<Pair<String, String>> importer_names;
- for (List<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
+ for (List<Ref<ResourceImporter>>::Element *E = importers.front(); E; E = E->next()) {
importer_names.push_back(Pair<String, String>(E->get()->get_visible_name(), E->get()->get_importer_name()));
}
- importer_names.sort_custom<PairSort<String, String> >();
+ importer_names.sort_custom<PairSort<String, String>>();
import_as->clear();
- for (List<Pair<String, String> >::Element *E = importer_names.front(); E; E = E->next()) {
+ for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) {
import_as->add_item(E->get().first);
import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second);
if (E->get().second == params->importer->get_importer_name()) {
@@ -129,8 +129,6 @@ void ImportDock::set_edit_path(const String &p_path) {
}
}
- params->paths.clear();
- params->paths.push_back(p_path);
import->set_disabled(false);
import_as->set_disabled(false);
preset->set_disabled(false);
@@ -139,17 +137,15 @@ void ImportDock::set_edit_path(const String &p_path) {
}
void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
-
List<ResourceImporter::ImportOption> options;
params->importer->get_import_options(&options);
params->properties.clear();
params->values.clear();
- params->checking = false;
+ params->checking = params->paths.size() > 1;
params->checked.clear();
for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
-
params->properties.push_back(E->get().option);
if (p_config.is_valid() && p_config->has_section_key("params", E->get().option.name)) {
params->values[E->get().option.name] = p_config->get_value("params", E->get().option.name);
@@ -159,35 +155,16 @@ void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
}
params->update();
-
- preset->get_popup()->clear();
-
- if (params->importer->get_preset_count() == 0) {
- preset->get_popup()->add_item(TTR("Default"));
- } else {
- for (int i = 0; i < params->importer->get_preset_count(); i++) {
- preset->get_popup()->add_item(params->importer->get_preset_name(i));
- }
- }
-
- preset->get_popup()->add_separator();
- preset->get_popup()->add_item(vformat(TTR("Set as Default for '%s'"), params->importer->get_visible_name()), ITEM_SET_AS_DEFAULT);
- if (ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name())) {
- preset->get_popup()->add_item(TTR("Load Default"), ITEM_LOAD_DEFAULT);
- preset->get_popup()->add_separator();
- preset->get_popup()->add_item(vformat(TTR("Clear Default for '%s'"), params->importer->get_visible_name()), ITEM_CLEAR_DEFAULT);
- }
+ _update_preset_menu();
}
void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
-
clear();
// Use the value that is repeated the most.
Map<String, Dictionary> value_frequency;
for (int i = 0; i < p_paths.size(); i++) {
-
Ref<ConfigFile> config;
config.instance();
Error err = config->load(p_paths[i] + ".import");
@@ -205,7 +182,6 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
config->get_section_keys("params", &keys);
for (List<String>::Element *E = keys.front(); E; E = E->next()) {
-
if (!value_frequency.has(E->get())) {
value_frequency[E->get()] = Dictionary();
}
@@ -231,11 +207,9 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
params->checked.clear();
for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
-
params->properties.push_back(E->get().option);
if (value_frequency.has(E->get().option.name)) {
-
Dictionary d = value_frequency[E->get().option.name];
int freq = 0;
List<Variant> v;
@@ -256,19 +230,19 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
params->update();
- List<Ref<ResourceImporter> > importers;
+ List<Ref<ResourceImporter>> importers;
ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_paths[0].get_extension(), &importers);
- List<Pair<String, String> > importer_names;
+ List<Pair<String, String>> importer_names;
- for (List<Ref<ResourceImporter> >::Element *E = importers.front(); E; E = E->next()) {
+ for (List<Ref<ResourceImporter>>::Element *E = importers.front(); E; E = E->next()) {
importer_names.push_back(Pair<String, String>(E->get()->get_visible_name(), E->get()->get_importer_name()));
}
- importer_names.sort_custom<PairSort<String, String> >();
+ importer_names.sort_custom<PairSort<String, String>>();
import_as->clear();
- for (List<Pair<String, String> >::Element *E = importer_names.front(); E; E = E->next()) {
+ for (List<Pair<String, String>>::Element *E = importer_names.front(); E; E = E->next()) {
import_as->add_item(E->get().first);
import_as->set_item_metadata(import_as->get_item_count() - 1, E->get().second);
if (E->get().second == params->importer->get_importer_name()) {
@@ -276,6 +250,17 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
}
}
+ _update_preset_menu();
+
+ params->paths = p_paths;
+ import->set_disabled(false);
+ import_as->set_disabled(false);
+ preset->set_disabled(false);
+
+ imported->set_text(vformat(TTR("%d Files"), p_paths.size()));
+}
+
+void ImportDock::_update_preset_menu() {
preset->get_popup()->clear();
if (params->importer->get_preset_count() == 0) {
@@ -286,12 +271,13 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
}
}
- params->paths = p_paths;
- import->set_disabled(false);
- import_as->set_disabled(false);
- preset->set_disabled(false);
-
- imported->set_text(itos(p_paths.size()) + TTR(" Files"));
+ preset->get_popup()->add_separator();
+ preset->get_popup()->add_item(vformat(TTR("Set as Default for '%s'"), params->importer->get_visible_name()), ITEM_SET_AS_DEFAULT);
+ if (ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name())) {
+ preset->get_popup()->add_item(TTR("Load Default"), ITEM_LOAD_DEFAULT);
+ preset->get_popup()->add_separator();
+ preset->get_popup()->add_item(vformat(TTR("Clear Default for '%s'"), params->importer->get_visible_name()), ITEM_CLEAR_DEFAULT);
+ }
}
void ImportDock::_importer_selected(int i_idx) {
@@ -313,7 +299,6 @@ void ImportDock::_importer_selected(int i_idx) {
}
void ImportDock::_preset_selected(int p_idx) {
-
int item_id = preset->get_popup()->get_item_id(p_idx);
switch (item_id) {
@@ -326,46 +311,51 @@ void ImportDock::_preset_selected(int p_idx) {
ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), d);
ProjectSettings::get_singleton()->save();
-
+ _update_preset_menu();
} break;
case ITEM_LOAD_DEFAULT: {
-
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name()));
Dictionary d = ProjectSettings::get_singleton()->get("importer_defaults/" + params->importer->get_importer_name());
List<Variant> v;
d.get_key_list(&v);
+ if (params->checking) {
+ params->checked.clear();
+ }
for (List<Variant>::Element *E = v.front(); E; E = E->next()) {
params->values[E->get()] = d[E->get()];
+ if (params->checking) {
+ params->checked.insert(E->get());
+ }
}
params->update();
-
} break;
case ITEM_CLEAR_DEFAULT: {
-
ProjectSettings::get_singleton()->set("importer_defaults/" + params->importer->get_importer_name(), Variant());
ProjectSettings::get_singleton()->save();
-
+ _update_preset_menu();
} break;
default: {
-
List<ResourceImporter::ImportOption> options;
params->importer->get_import_options(&options, p_idx);
+ if (params->checking) {
+ params->checked.clear();
+ }
for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
-
params->values[E->get().option.name] = E->get().default_value;
+ if (params->checking) {
+ params->checked.insert(E->get().option.name);
+ }
}
-
params->update();
} break;
}
}
void ImportDock::clear() {
-
imported->set_text("");
import->set_disabled(true);
import_as->clear();
@@ -378,28 +368,27 @@ void ImportDock::clear() {
}
static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path) {
-
- if (!efsd)
+ if (!efsd) {
return false;
+ }
for (int i = 0; i < efsd->get_subdir_count(); i++) {
-
if (_find_owners(efsd->get_subdir(i), p_path)) {
return true;
}
}
for (int i = 0; i < efsd->get_file_count(); i++) {
-
Vector<String> deps = efsd->get_file_deps(i);
- if (deps.find(p_path) != -1)
+ if (deps.find(p_path) != -1) {
return true;
+ }
}
return false;
}
-void ImportDock::_reimport_attempt() {
+void ImportDock::_reimport_attempt() {
bool need_restart = false;
bool used_in_resources = false;
for (int i = 0; i < params->paths.size(); i++) {
@@ -419,7 +408,7 @@ void ImportDock::_reimport_attempt() {
if (need_restart) {
label_warning->set_visible(used_in_resources);
- reimport_confirm->popup_centered_minsize();
+ reimport_confirm->popup_centered();
return;
}
@@ -427,7 +416,6 @@ void ImportDock::_reimport_attempt() {
}
void ImportDock::_reimport_and_restart() {
-
EditorNode::get_singleton()->save_all_scenes();
EditorResourcePreview::get_singleton()->stop(); //don't try to re-create previews after import
_reimport();
@@ -435,9 +423,7 @@ void ImportDock::_reimport_and_restart() {
}
void ImportDock::_reimport() {
-
for (int i = 0; i < params->paths.size(); i++) {
-
Ref<ConfigFile> config;
config.instance();
Error err = config->load(params->paths[i] + ".import");
@@ -445,8 +431,8 @@ void ImportDock::_reimport() {
String importer_name = params->importer->get_importer_name();
- if (params->checking) {
- //update only what edited (checkboxes)
+ if (params->checking && config->get_value("remap", "importer") == params->importer->get_importer_name()) {
+ //update only what is edited (checkboxes) if the importer is the same
for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) {
if (params->checked.has(E->get().name)) {
config->set_value("params", E->get().name, params->values[E->get().name]);
@@ -455,7 +441,9 @@ void ImportDock::_reimport() {
} else {
//override entirely
config->set_value("remap", "importer", importer_name);
- config->erase_section("params");
+ if (config->has_section("params")) {
+ config->erase_section("params");
+ }
for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) {
config->set_value("params", E->get().name, params->values[E->get().name]);
@@ -484,16 +472,13 @@ void ImportDock::_reimport() {
void ImportDock::_notification(int p_what) {
switch (p_what) {
-
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
-
- imported->add_style_override("normal", get_stylebox("normal", "LineEdit"));
+ imported->add_theme_style_override("normal", get_theme_stylebox("normal", "LineEdit"));
} break;
case NOTIFICATION_ENTER_TREE: {
-
import_opts->edit(params);
- label_warning->add_color_override("font_color", get_color("warning_color", "Editor"));
+ label_warning->add_theme_color_override("font_color", get_theme_color("warning_color", "Editor"));
} break;
}
}
@@ -505,62 +490,55 @@ void ImportDock::_property_toggled(const StringName &p_prop, bool p_checked) {
params->checked.erase(p_prop);
}
}
-void ImportDock::_bind_methods() {
+void ImportDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_reimport"), &ImportDock::_reimport);
- ClassDB::bind_method(D_METHOD("_preset_selected"), &ImportDock::_preset_selected);
- ClassDB::bind_method(D_METHOD("_importer_selected"), &ImportDock::_importer_selected);
- ClassDB::bind_method(D_METHOD("_property_toggled"), &ImportDock::_property_toggled);
- ClassDB::bind_method(D_METHOD("_reimport_and_restart"), &ImportDock::_reimport_and_restart);
- ClassDB::bind_method(D_METHOD("_reimport_attempt"), &ImportDock::_reimport_attempt);
}
void ImportDock::initialize_import_options() const {
-
ERR_FAIL_COND(!import_opts || !params);
import_opts->edit(params);
}
ImportDock::ImportDock() {
-
set_name("Import");
imported = memnew(Label);
- imported->add_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal", "LineEdit"));
+ imported->add_theme_style_override("normal", EditorNode::get_singleton()->get_gui_base()->get_theme_stylebox("normal", "LineEdit"));
imported->set_clip_text(true);
add_child(imported);
HBoxContainer *hb = memnew(HBoxContainer);
add_margin_child(TTR("Import As:"), hb);
import_as = memnew(OptionButton);
import_as->set_disabled(true);
- import_as->connect("item_selected", this, "_importer_selected");
+ import_as->connect("item_selected", callable_mp(this, &ImportDock::_importer_selected));
hb->add_child(import_as);
import_as->set_h_size_flags(SIZE_EXPAND_FILL);
preset = memnew(MenuButton);
preset->set_text(TTR("Preset"));
preset->set_disabled(true);
- preset->get_popup()->connect("index_pressed", this, "_preset_selected");
+ preset->get_popup()->connect("index_pressed", callable_mp(this, &ImportDock::_preset_selected));
hb->add_child(preset);
import_opts = memnew(EditorInspector);
add_child(import_opts);
import_opts->set_v_size_flags(SIZE_EXPAND_FILL);
- import_opts->connect("property_toggled", this, "_property_toggled");
+ import_opts->connect("property_toggled", callable_mp(this, &ImportDock::_property_toggled));
hb = memnew(HBoxContainer);
add_child(hb);
import = memnew(Button);
import->set_text(TTR("Reimport"));
import->set_disabled(true);
- import->connect("pressed", this, "_reimport_attempt");
+ import->connect("pressed", callable_mp(this, &ImportDock::_reimport_attempt));
hb->add_spacer();
hb->add_child(import);
hb->add_spacer();
reimport_confirm = memnew(ConfirmationDialog);
- reimport_confirm->get_ok()->set_text(TTR("Save scenes, re-import and restart"));
+ reimport_confirm->get_ok()->set_text(TTR("Save Scenes, Re-Import, and Restart"));
add_child(reimport_confirm);
- reimport_confirm->connect("confirmed", this, "_reimport_and_restart");
+ reimport_confirm->connect("confirmed", callable_mp(this, &ImportDock::_reimport_and_restart));
VBoxContainer *vbc_confirm = memnew(VBoxContainer());
vbc_confirm->add_child(memnew(Label(TTR("Changing the type of an imported file requires editor restart."))));
@@ -572,6 +550,5 @@ ImportDock::ImportDock() {
}
ImportDock::~ImportDock() {
-
memdelete(params);
}