Skip to content

Commit

Permalink
Prevent Theme resource from emitting changes during bulk operations
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSizov committed May 31, 2021
1 parent afe1d16 commit 9cd96eb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 69 deletions.
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

0 comments on commit 9cd96eb

Please sign in to comment.