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

Unify usage of undo_redo in editor #65062

Merged
merged 1 commit into from
Nov 2, 2022
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
10 changes: 5 additions & 5 deletions editor/editor_autoload_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void EditorAutoloadSettings::_autoload_edited() {
TreeItem *ti = tree->get_edited();
int column = tree->get_edited_column();

Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_undo_redo();
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

if (column == 0) {
String name = ti->get_text(0);
Expand Down Expand Up @@ -289,7 +289,7 @@ void EditorAutoloadSettings::_autoload_button_pressed(Object *p_item, int p_colu

String name = "autoload/" + ti->get_text(0);

Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_undo_redo();
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

switch (p_button) {
case BUTTON_OPEN: {
Expand Down Expand Up @@ -714,7 +714,7 @@ void EditorAutoloadSettings::drop_data_fw(const Point2 &p_point, const Variant &

orders.sort();

Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_undo_redo();
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

undo_redo->create_action(TTR("Rearrange Autoloads"));

Expand Down Expand Up @@ -757,7 +757,7 @@ bool EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_

name = "autoload/" + name;

Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_undo_redo();
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

undo_redo->create_action(TTR("Add Autoload"));
// Singleton autoloads are represented with a leading "*" in their path.
Expand All @@ -783,7 +783,7 @@ bool EditorAutoloadSettings::autoload_add(const String &p_name, const String &p_
void EditorAutoloadSettings::autoload_remove(const String &p_name) {
String name = "autoload/" + p_name;

Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_undo_redo();
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

int order = ProjectSettings::get_singleton()->get_order(name);

Expand Down
2 changes: 0 additions & 2 deletions editor/editor_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,10 @@ Callable EditorData::get_move_array_element_function(const StringName &p_class)
}

void EditorData::remove_editor_plugin(EditorPlugin *p_plugin) {
p_plugin->undo_redo = Ref<EditorUndoRedoManager>();
editor_plugins.erase(p_plugin);
}

void EditorData::add_editor_plugin(EditorPlugin *p_plugin) {
p_plugin->undo_redo = undo_redo_manager;
editor_plugins.push_back(p_plugin);
}

Expand Down
20 changes: 9 additions & 11 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "editor/editor_property_name_processor.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/editor_undo_redo_manager.h"
#include "editor/plugins/script_editor_plugin.h"
#include "multi_node_edit.h"
#include "scene/gui/center_container.h"
Expand Down Expand Up @@ -1698,6 +1699,7 @@ void EditorInspectorArray::_move_element(int p_element_index, int p_to_pos) {
} else {
action_name = vformat("Move element %d to position %d in property array with prefix %s.", p_element_index, p_to_pos, array_element_prefix);
}
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(action_name);
if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {
// Call the function.
Expand Down Expand Up @@ -1841,6 +1843,7 @@ void EditorInspectorArray::_move_element(int p_element_index, int p_to_pos) {
}

void EditorInspectorArray::_clear_array() {
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(vformat("Clear property array with prefix %s.", array_element_prefix));
if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {
for (int i = count - 1; i >= 0; i--) {
Expand Down Expand Up @@ -1893,6 +1896,7 @@ void EditorInspectorArray::_resize_array(int p_size) {
return;
}

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(vformat("Resize property array with prefix %s.", array_element_prefix));
if (p_size > count) {
if (mode == MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION) {
Expand Down Expand Up @@ -2242,10 +2246,6 @@ void EditorInspectorArray::_bind_methods() {
ADD_SIGNAL(MethodInfo("page_change_request"));
}

void EditorInspectorArray::set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo) {
undo_redo = p_undo_redo;
}

void EditorInspectorArray::setup_with_move_element_function(Object *p_object, String p_label, const StringName &p_array_element_prefix, int p_page, const Color &p_bg_color, bool p_foldable, bool p_movable, bool p_numbered, int p_page_length, const String &p_add_item_text) {
count_property = "";
mode = MODE_USE_MOVE_ARRAY_ELEMENT_FUNCTION;
Expand Down Expand Up @@ -2508,10 +2508,6 @@ Button *EditorInspector::create_inspector_action_button(const String &p_text) {
return button;
}

void EditorInspector::set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo) {
undo_redo = p_undo_redo;
}

String EditorInspector::get_selected_path() const {
return property_selected;
}
Expand Down Expand Up @@ -3077,7 +3073,6 @@ void EditorInspector::update_tree() {
int page = per_array_page.has(array_element_prefix) ? per_array_page[array_element_prefix] : 0;
editor_inspector_array->setup_with_move_element_function(object, array_label, array_element_prefix, page, c, use_folding);
editor_inspector_array->connect("page_change_request", callable_mp(this, &EditorInspector::_page_change_request).bind(array_element_prefix));
editor_inspector_array->set_undo_redo(undo_redo);
} else if (p.type == Variant::INT) {
// Setup the array to use the count property and built-in functions to create/move/delete elements.
if (class_name_components.size() >= 2) {
Expand All @@ -3087,8 +3082,6 @@ void EditorInspector::update_tree() {

editor_inspector_array->setup_with_count_property(object, class_name_components[0], p.name, array_element_prefix, page, c, foldable, movable, numbered, page_size, add_button_text, swap_method);
editor_inspector_array->connect("page_change_request", callable_mp(this, &EditorInspector::_page_change_request).bind(array_element_prefix));

editor_inspector_array->set_undo_redo(undo_redo);
}
}

Expand Down Expand Up @@ -3565,6 +3558,7 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
}
}

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
if (!undo_redo.is_valid() || bool(object->call("_dont_undo_redo"))) {
object->set(p_name, p_value);
if (p_refresh_all) {
Expand Down Expand Up @@ -3685,6 +3679,7 @@ void EditorInspector::_multiple_properties_changed(Vector<String> p_paths, Array
}
names += p_paths[i];
}
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Set Multiple:") + " " + names, UndoRedo::MERGE_ENDS);
for (int i = 0; i < p_paths.size(); i++) {
_edit_set(p_paths[i], p_values[i], false, "");
Expand Down Expand Up @@ -3719,6 +3714,7 @@ void EditorInspector::_property_deleted(const String &p_path) {

if (p_path.begins_with("metadata/")) {
String name = p_path.replace_first("metadata/", "");
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(vformat(TTR("Remove metadata %s"), name));
undo_redo->add_do_method(object, "remove_meta", name);
undo_redo->add_undo_method(object, "set_meta", name, object->get_meta(name));
Expand Down Expand Up @@ -3784,6 +3780,7 @@ void EditorInspector::_property_pinned(const String &p_path, bool p_pinned) {
Node *node = Object::cast_to<Node>(object);
ERR_FAIL_COND(!node);

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
if (undo_redo.is_valid()) {
undo_redo->create_action(vformat(p_pinned ? TTR("Pinned %s") : TTR("Unpinned %s"), p_path));
undo_redo->add_do_method(node, "_set_property_pinned", p_path, p_pinned);
Expand Down Expand Up @@ -3981,6 +3978,7 @@ void EditorInspector::_add_meta_confirm() {
Variant defval;
Callable::CallError ce;
Variant::construct(Variant::Type(add_meta_type->get_selected_id()), defval, nullptr, 0, ce);
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(vformat(TTR("Add metadata %s"), name));
undo_redo->add_do_method(object, "set_meta", name, defval);
undo_redo->add_undo_method(object, "remove_meta", name);
Expand Down
8 changes: 0 additions & 8 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#ifndef EDITOR_INSPECTOR_H
#define EDITOR_INSPECTOR_H

#include "editor/editor_undo_redo_manager.h"
#include "editor_property_name_processor.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
Expand Down Expand Up @@ -305,8 +304,6 @@ class EditorInspectorSection : public Container {
class EditorInspectorArray : public EditorInspectorSection {
GDCLASS(EditorInspectorArray, EditorInspectorSection);

Ref<EditorUndoRedoManager> undo_redo;

enum Mode {
MODE_NONE,
MODE_USE_COUNT_PROPERTY,
Expand Down Expand Up @@ -401,8 +398,6 @@ class EditorInspectorArray : public EditorInspectorSection {
static void _bind_methods();

public:
void set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo);

void setup_with_move_element_function(Object *p_object, String p_label, const StringName &p_array_element_prefix, int p_page, const Color &p_bg_color, bool p_foldable, bool p_movable = true, bool p_numbered = false, int p_page_length = 5, const String &p_add_item_text = "");
void setup_with_count_property(Object *p_object, String p_label, const StringName &p_count_property, const StringName &p_array_element_prefix, int p_page, const Color &p_bg_color, bool p_foldable, bool p_movable = true, bool p_numbered = false, int p_page_length = 5, const String &p_add_item_text = "", const String &p_swap_method = "");
VBoxContainer *get_vbox(int p_index);
Expand Down Expand Up @@ -441,7 +436,6 @@ class EditorPaginator : public HBoxContainer {
class EditorInspector : public ScrollContainer {
GDCLASS(EditorInspector, ScrollContainer);

Ref<EditorUndoRedoManager> undo_redo;
enum {
MAX_PLUGINS = 1024
};
Expand Down Expand Up @@ -555,8 +549,6 @@ class EditorInspector : public ScrollContainer {

static EditorProperty *instantiate_property_editor(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide = false);

void set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo);

String get_selected_path() const;

void update_tree();
Expand Down
6 changes: 4 additions & 2 deletions editor/editor_locale_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ void EditorLocaleDialog::_filter_lang_option_changed() {

f_lang_all.sort();

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Changed Locale Language Filter"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/language_filter", f_lang_all);
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/language_filter", prev);
Expand Down Expand Up @@ -174,6 +175,7 @@ void EditorLocaleDialog::_filter_script_option_changed() {

f_script_all.sort();

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Changed Locale Script Filter"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/script_filter", f_script_all);
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/script_filter", prev);
Expand Down Expand Up @@ -207,6 +209,7 @@ void EditorLocaleDialog::_filter_cnt_option_changed() {

f_cnt_all.sort();

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Changed Locale Country Filter"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/country_filter", f_cnt_all);
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/country_filter", prev);
Expand All @@ -221,6 +224,7 @@ void EditorLocaleDialog::_filter_mode_changed(int p_mode) {
prev = GLOBAL_GET("internationalization/locale/locale_filter_mode");
}

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Changed Locale Filter Mode"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), "internationalization/locale/locale_filter_mode", f_mode);
undo_redo->add_undo_property(ProjectSettings::get_singleton(), "internationalization/locale/locale_filter_mode", prev);
Expand Down Expand Up @@ -385,8 +389,6 @@ void EditorLocaleDialog::popup_locale_dialog() {
}

EditorLocaleDialog::EditorLocaleDialog() {
undo_redo = EditorNode::get_undo_redo();

set_title(TTR("Select a Locale"));

VBoxContainer *vb = memnew(VBoxContainer);
Expand Down
3 changes: 0 additions & 3 deletions editor/editor_locale_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class VBoxContainer;
class LineEdit;
class Tree;
class OptionButton;
class EditorUndoRedoManager;

class EditorLocaleDialog : public ConfirmationDialog {
GDCLASS(EditorLocaleDialog, ConfirmationDialog);
Expand All @@ -63,8 +62,6 @@ class EditorLocaleDialog : public ConfirmationDialog {
Tree *script_list = nullptr;
Tree *cnt_list = nullptr;

Ref<EditorUndoRedoManager> undo_redo;

bool locale_set = false;
bool updating_lists = false;

Expand Down
1 change: 1 addition & 0 deletions editor/editor_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "editor_log.h"

#include "core/object/undo_redo.h"
#include "core/os/keyboard.h"
#include "core/version.h"
#include "editor/editor_node.h"
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ void EditorPlugin::_bind_methods() {
}

Ref<EditorUndoRedoManager> EditorPlugin::get_undo_redo() {
return undo_redo;
return EditorNode::get_undo_redo();
}

EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS];
Expand Down
2 changes: 0 additions & 2 deletions editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#define EDITOR_PLUGIN_H

#include "core/io/config_file.h"
#include "core/object/undo_redo.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/editor_inspector.h"
#include "editor/editor_translation_parser.h"
Expand Down Expand Up @@ -134,7 +133,6 @@ class EditorInterface : public Node {
class EditorPlugin : public Node {
GDCLASS(EditorPlugin, Node);
friend class EditorData;
Ref<EditorUndoRedoManager> undo_redo;

bool input_event_forwarding_always_enabled = false;
bool force_draw_over_forwarding_enabled = false;
Expand Down
1 change: 0 additions & 1 deletion editor/editor_plugin_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#ifndef EDITOR_PLUGIN_SETTINGS_H
#define EDITOR_PLUGIN_SETTINGS_H

#include "core/object/undo_redo.h"
#include "editor/editor_data.h"
#include "editor/plugin_config_dialog.h"

Expand Down
1 change: 0 additions & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4097,7 +4097,6 @@ void EditorPropertyResource::update_property() {
sub_inspector->set_keying(is_keying());
sub_inspector->set_read_only(is_read_only());
sub_inspector->set_use_folding(is_using_folding());
sub_inspector->set_undo_redo(EditorNode::get_undo_redo());

sub_inspector_vbox = memnew(VBoxContainer);
add_child(sub_inspector_vbox);
Expand Down
8 changes: 4 additions & 4 deletions editor/editor_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void EditorSettingsDialog::_notification(int p_what) {
} break;

case NOTIFICATION_READY: {
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_method_notify_callback(EditorDebuggerNode::_method_changeds, nullptr);
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_property_notify_callback(EditorDebuggerNode::_property_changeds, nullptr);
undo_redo->get_or_create_history(EditorUndoRedoManager::GLOBAL_HISTORY).undo_redo->set_commit_notify_callback(_undo_redo_callback, this);
Expand All @@ -158,9 +159,9 @@ void EditorSettingsDialog::_notification(int p_what) {

void EditorSettingsDialog::shortcut_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();

const Ref<InputEventKey> k = p_event;

if (k.is_valid() && k->is_pressed()) {
bool handled = false;

Expand Down Expand Up @@ -229,6 +230,7 @@ void EditorSettingsDialog::_event_config_confirmed() {
void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Array &p_events) {
Array old_input_array = EditorSettings::get_singleton()->get_builtin_action_overrides(p_name);

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Edit Built-in Action") + " '" + p_name + "'");
undo_redo->add_do_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
undo_redo->add_undo_method(EditorSettings::get_singleton(), "mark_setting_changed", "builtin_action_overrides");
Expand All @@ -244,6 +246,7 @@ void EditorSettingsDialog::_update_builtin_action(const String &p_name, const Ar
void EditorSettingsDialog::_update_shortcut_events(const String &p_path, const Array &p_events) {
Ref<Shortcut> current_sc = EditorSettings::get_singleton()->get_shortcut(p_path);

Ref<EditorUndoRedoManager> &undo_redo = EditorNode::get_undo_redo();
undo_redo->create_action(TTR("Edit Shortcut") + " '" + p_path + "'");
undo_redo->add_do_method(current_sc.ptr(), "set_events", p_events);
undo_redo->add_undo_method(current_sc.ptr(), "set_events", current_sc->get_events());
Expand Down Expand Up @@ -697,8 +700,6 @@ void EditorSettingsDialog::_bind_methods() {
EditorSettingsDialog::EditorSettingsDialog() {
set_title(TTR("Editor Settings"));

undo_redo = EditorNode::get_undo_redo();

tabs = memnew(TabContainer);
tabs->set_theme_type_variation("TabContainerOdd");
tabs->connect("tab_changed", callable_mp(this, &EditorSettingsDialog::_tabs_tab_changed));
Expand All @@ -723,7 +724,6 @@ EditorSettingsDialog::EditorSettingsDialog() {
inspector->get_inspector()->set_use_filter(true);
inspector->register_search_box(search_box);
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
inspector->get_inspector()->set_undo_redo(undo_redo);
tab_general->add_child(inspector);
inspector->get_inspector()->connect("property_edited", callable_mp(this, &EditorSettingsDialog::_settings_property_edited));
inspector->get_inspector()->connect("restart_requested", callable_mp(this, &EditorSettingsDialog::_editor_restart_request));
Expand Down
4 changes: 0 additions & 4 deletions editor/editor_settings_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
#include "scene/gui/tab_container.h"
#include "scene/gui/texture_rect.h"

class EditorUndoRedoManager;

class EditorSettingsDialog : public AcceptDialog {
GDCLASS(EditorSettingsDialog, AcceptDialog);

Expand Down Expand Up @@ -75,8 +73,6 @@ class EditorSettingsDialog : public AcceptDialog {

Timer *timer = nullptr;

Ref<EditorUndoRedoManager> undo_redo;

virtual void cancel_pressed() override;
virtual void ok_pressed() override;

Expand Down
Loading