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

Prevent Theme resource from emitting changes during bulk operations #49227

Merged
merged 1 commit into from
Jun 13, 2021
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
34 changes: 33 additions & 1 deletion editor/plugins/theme_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ void ThemeItemImportTree::_import_selected() {
return;
}

ProgressDialog::get_singleton()->add_task("import_theme_items", TTR("Importing Theme Items"), selected_items.size());
// Prevent changes from immediatelly being reported while the operation is still ongoing.
edited_theme->_freeze_change_propagation();
ProgressDialog::get_singleton()->add_task("import_theme_items", TTR("Importing Theme Items"), selected_items.size() + 2);

int idx = 0;
for (Map<ThemeItem, ItemCheckedState>::Element *E = selected_items.front(); E; E = E->next()) {
Expand Down Expand Up @@ -814,6 +816,12 @@ void ThemeItemImportTree::_import_selected() {
idx++;
}

// Allow changes to be reported now that the operation is finished.
ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Updating the editor"), idx++);
edited_theme->_unfreeze_and_propagate_changes();
// Make sure the task is not ended before the editor freezes to update the Inspector.
ProgressDialog::get_singleton()->task_step("import_theme_items", TTR("Finalizing"), idx++);

ProgressDialog::get_singleton()->end_task("import_theme_items");
emit_signal("items_imported");
}
Expand Down Expand Up @@ -1488,15 +1496,24 @@ void ThemeItemEditorDialog::_add_theme_item(Theme::DataType p_data_type, String
void ThemeItemEditorDialog::_remove_data_type_items(Theme::DataType p_data_type, String p_item_type) {
List<StringName> names;

// Prevent changes from immediatelly being reported while the operation is still ongoing.
edited_theme->_freeze_change_propagation();

edited_theme->get_theme_item_list(p_data_type, p_item_type, &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
edited_theme->clear_theme_item(p_data_type, E->get(), p_item_type);
}

// Allow changes to be reported now that the operation is finished.
edited_theme->_unfreeze_and_propagate_changes();
}

void ThemeItemEditorDialog::_remove_class_items() {
List<StringName> names;

// Prevent changes from immediatelly being reported while the operation is still ongoing.
edited_theme->_freeze_change_propagation();

for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) {
Theme::DataType data_type = (Theme::DataType)dt;

Expand All @@ -1509,12 +1526,18 @@ void ThemeItemEditorDialog::_remove_class_items() {
}
}

// Allow changes to be reported now that the operation is finished.
edited_theme->_unfreeze_and_propagate_changes();

_update_edit_item_tree(edited_item_type);
}

void ThemeItemEditorDialog::_remove_custom_items() {
List<StringName> names;

// Prevent changes from immediatelly being reported while the operation is still ongoing.
edited_theme->_freeze_change_propagation();

for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) {
Theme::DataType data_type = (Theme::DataType)dt;

Expand All @@ -1527,12 +1550,18 @@ void ThemeItemEditorDialog::_remove_custom_items() {
}
}

// Allow changes to be reported now that the operation is finished.
edited_theme->_unfreeze_and_propagate_changes();

_update_edit_item_tree(edited_item_type);
}

void ThemeItemEditorDialog::_remove_all_items() {
List<StringName> names;

// Prevent changes from immediatelly being reported while the operation is still ongoing.
edited_theme->_freeze_change_propagation();

for (int dt = 0; dt < Theme::DATA_TYPE_MAX; dt++) {
Theme::DataType data_type = (Theme::DataType)dt;

Expand All @@ -1543,6 +1572,9 @@ void ThemeItemEditorDialog::_remove_all_items() {
}
}

// Allow changes to be reported now that the operation is finished.
edited_theme->_unfreeze_and_propagate_changes();

_update_edit_item_tree(edited_item_type);
}

Expand Down
Loading