Repository: godotengine/godot
File: editor/settings/editor_settings_dialog.cpp (C++)

Code before:
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/check_button.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"

void EditorSettingsDialog::ok_pressed() {
	if (!EditorSettings::get_singleton()) {
		return;
	}
	_settings_save();
}

void EditorSettingsDialog::_settings_changed() {
	timer->start();
}

void EditorSettingsDialog::_settings_property_edited() {
	Vector<String> changed = EditorSettings::get_singleton()->get_changed_settings();
	if (changed.is_empty()) {
		return;
	}

	String full_name = changed.get(changed.size() - 1);

	// Set theme presets to Custom when controlled settings change.

	if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders" || full_name == "interface/theme/icon_saturation" || full_name == "interface/theme/draw_relationship_lines" || full_name == "interface/theme/corner_radius") {
		EditorSettings::get_singleton()->set_manually("interface/theme/color_preset", "Custom");
	} else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
		EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
	} else if (full_name.begins_with("text_editor/theme/highlighting")) {
		EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
	} else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
		EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
	} else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button" || full_name == "editors/3d/navigation/emulate_3_button_mouse") {
		EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
	} else if (full_name == "editors/3d/navigation/navigation_scheme") {
		update_navigation_preset();
	}
}

void EditorSettingsDialog::update_navigation_preset() {
	Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
	Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
	Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
	Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
	bool set_3_button_mouse = false;
	Ref<InputEventKey> orbit_mod_key_1;

Review comment (performance):
```suggestion
	String full_name = changed[changed.size() - 1];
```
Although it would be more efficient to add some `get_last_changed_setting()` method, because the `changed` Vector is converted from HashSet.

Code after:
#include "editor/themes/editor_scale.h"
#include "editor/themes/editor_theme_manager.h"
#include "scene/gui/check_button.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/tab_container.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"

void EditorSettingsDialog::ok_pressed() {
	if (!EditorSettings::get_singleton()) {
		return;
	}
	_settings_save();
}

void EditorSettingsDialog::_settings_changed() {
	timer->start();
}

void EditorSettingsDialog::_settings_property_edited() {
	Vector<String> changed = EditorSettings::get_singleton()->get_changed_settings();
	if (changed.is_empty()) {
		return;
	}

	const String full_name = changed[changed.size() - 1];

	// Set theme presets to Custom when controlled settings change.

	if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast" || full_name == "interface/theme/draw_extra_borders" || full_name == "interface/theme/icon_saturation" || full_name == "interface/theme/draw_relationship_lines" || full_name == "interface/theme/corner_radius") {
		EditorSettings::get_singleton()->set_manually("interface/theme/color_preset", "Custom");
	} else if (full_name == "interface/theme/base_spacing" || full_name == "interface/theme/additional_spacing") {
		EditorSettings::get_singleton()->set_manually("interface/theme/spacing_preset", "Custom");
	} else if (full_name.begins_with("text_editor/theme/highlighting")) {
		EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom");
	} else if (full_name.begins_with("editors/visual_editors/connection_colors") || full_name.begins_with("editors/visual_editors/category_colors")) {
		EditorSettings::get_singleton()->set_manually("editors/visual_editors/color_theme", "Custom");
	} else if (full_name == "editors/3d/navigation/orbit_mouse_button" || full_name == "editors/3d/navigation/pan_mouse_button" || full_name == "editors/3d/navigation/zoom_mouse_button" || full_name == "editors/3d/navigation/emulate_3_button_mouse") {
		EditorSettings::get_singleton()->set_manually("editors/3d/navigation/navigation_scheme", (int)Node3DEditorViewport::NAVIGATION_CUSTOM);
	} else if (full_name == "editors/3d/navigation/navigation_scheme") {
		update_navigation_preset();
	}
}

void EditorSettingsDialog::update_navigation_preset() {
	Node3DEditorViewport::NavigationScheme nav_scheme = (Node3DEditorViewport::NavigationScheme)EDITOR_GET("editors/3d/navigation/navigation_scheme").operator int();
	Node3DEditorViewport::ViewportNavMouseButton set_orbit_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
	Node3DEditorViewport::ViewportNavMouseButton set_pan_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
	Node3DEditorViewport::ViewportNavMouseButton set_zoom_mouse_button = Node3DEditorViewport::NAVIGATION_LEFT_MOUSE;
	bool set_3_button_mouse = false;
	Ref<InputEventKey> orbit_mod_key_1;