Implement undo/redo for adding and deleting global properties

This commit is contained in:
Franklin Sobrinho 2016-07-07 10:10:12 -03:00
parent 1b9433594e
commit 9be07081de
2 changed files with 33 additions and 5 deletions

View File

@ -616,10 +616,26 @@ void ProjectSettings::_item_add() {
String name = catname!="" ? catname+"/"+propname : propname;
Globals::get_singleton()->set(name,value);
undo_redo->create_action("Add Global Property");
undo_redo->add_do_property(Globals::get_singleton(), name, value);
undo_redo->add_do_method(Globals::get_singleton(), "set_persisting", name, true);
if (Globals::get_singleton()->has(name)) {
undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name));
} else {
undo_redo->add_undo_property(Globals::get_singleton(), name, Variant());
}
undo_redo->add_do_method(globals_editor, "update_category_list");
undo_redo->add_undo_method(globals_editor, "update_category_list");
undo_redo->add_do_method(this, "_settings_changed");
undo_redo->add_undo_method(this, "_settings_changed");
undo_redo->commit_action();
globals_editor->set_current_section(catname);
globals_editor->update_category_list();
_settings_changed();
}
@ -633,10 +649,20 @@ void ProjectSettings::_item_del() {
String name = catname!="" ? catname+"/"+propname : propname;
Globals::get_singleton()->set(name,Variant());
undo_redo->create_action("Delete Global Property");
globals_editor->set_current_section(catname);
globals_editor->update_category_list();
undo_redo->add_do_property(Globals::get_singleton(), name, Variant());
undo_redo->add_undo_property(Globals::get_singleton(), name, Globals::get_singleton()->get(name));
undo_redo->add_undo_method(Globals::get_singleton(), "set_persisting", name, Globals::get_singleton()->is_persisting(name));
undo_redo->add_do_method(globals_editor, "update_category_list");
undo_redo->add_undo_method(globals_editor, "update_category_list");
undo_redo->add_do_method(this, "_settings_changed");
undo_redo->add_undo_method(this, "_settings_changed");
undo_redo->commit_action();
_settings_changed();
}

View File

@ -4191,6 +4191,8 @@ public:
void SectionedPropertyEditor::_bind_methods() {
ObjectTypeDB::bind_method("_section_selected",&SectionedPropertyEditor::_section_selected);
ObjectTypeDB::bind_method("update_category_list", &SectionedPropertyEditor::update_category_list);
}
void SectionedPropertyEditor::_section_selected(int p_which) {