Skip to content

Commit

Permalink
Avoid moving an action above any builtin action
Browse files Browse the repository at this point in the history
  • Loading branch information
garychia committed Nov 14, 2023
1 parent fee6df7 commit 52c7f4d
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions editor/project_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,27 +446,49 @@ void ProjectSettingsEditor::_action_reordered(const String &p_action_name, const
HashMap<String, Variant> action_values;
ProjectSettings::get_singleton()->get_property_list(&props);

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Update Input Action Order"));
bool target_builtin = false;

for (const PropertyInfo &prop : props) {
// Skip builtins and non-inputs
// Order matters here, checking for "input/" filters out properties that aren't settings and produce errors in is_builtin_setting().
if (!prop.name.begins_with("input/") || ProjectSettings::get_singleton()->is_builtin_setting(prop.name)) {
if (!prop.name.begins_with("input/")) {
continue;
} else if (ProjectSettings::get_singleton()->is_builtin_setting(prop.name)) {
// No action is allowed to be inserted between builtins.
if (target_builtin) {
return;
} else if (prop.name == target_name) {
target_builtin = true;
}
continue;
}

action_values.insert(prop.name, ps->get(prop.name));
}

// No action is allowed to be placed before any builtin.
if (target_builtin && p_before) {
return;
}

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Update Input Action Order"));

for (const KeyValue<String, Variant> &E : action_values) {
undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", E.key);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", E.key);
}

undo_redo->add_do_method(ProjectSettings::get_singleton(), "clear", prop.name);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "clear", prop.name);
if (target_builtin) {
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
}

for (const KeyValue<String, Variant> &E : action_values) {
String name = E.key;
const Variant &value = E.value;

if (name == target_name) {
if (!target_builtin && name == target_name) {
if (p_before) {
// Insert before target
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", action_name, action_value);
Expand Down

0 comments on commit 52c7f4d

Please sign in to comment.