Skip to content

Commit

Permalink
Implement editor indent settings per project (type and size)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinn committed Oct 16, 2024
1 parent af77100 commit 8b4a039
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "code_editor.h"

#include "core/config/project_settings.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/string/string_builder.h"
Expand Down Expand Up @@ -1599,6 +1600,9 @@ void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) {

void CodeTextEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &CodeTextEditor::update_editor_settings));
} break;
case NOTIFICATION_THEME_CHANGED: {
if (toggle_scripts_button->is_visible()) {
update_toggle_scripts_button();
Expand Down Expand Up @@ -1748,6 +1752,12 @@ float CodeTextEditor::get_zoom_factor() {
}

void CodeTextEditor::_bind_methods() {
EditorSettings *ed = EditorSettings::get_singleton();
int default_indent_type = ed->get("editor/text_editor/behavior/indent/type");
int default_indent_size = ed->get("text_editor/behavior/indent/size");
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/text_editor/behavior/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"), default_indent_type);
GLOBAL_DEF(PropertyInfo(Variant::INT, "editor/text_editor/behavior/indent/size", PROPERTY_HINT_RANGE, "1,64,1"), default_indent_size);

ADD_SIGNAL(MethodInfo("validate_script"));
ADD_SIGNAL(MethodInfo("load_theme_settings"));
ADD_SIGNAL(MethodInfo("show_errors_panel"));
Expand Down
6 changes: 4 additions & 2 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,10 @@ Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_re
}

Variant _EDITOR_GET(const String &p_setting) {
ERR_FAIL_COND_V(!EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
return EditorSettings::get_singleton()->get(p_setting);
String project_override_setting = String("editor/" + p_setting);
ERR_FAIL_COND_V(!ProjectSettings::get_singleton() || !EditorSettings::get_singleton() || !EditorSettings::get_singleton()->has_setting(p_setting), Variant());
Variant def_val = EditorSettings::get_singleton()->get(p_setting);
return ProjectSettings::get_singleton()->get_setting(project_override_setting, def_val);
}

bool EditorSettings::_property_can_revert(const StringName &p_name) const {
Expand Down

0 comments on commit 8b4a039

Please sign in to comment.