diff --git a/editor_modules/text_editor/text_editor_settings.cpp b/editor_modules/text_editor/text_editor_settings.cpp index cec99204db..0727eb21f6 100644 --- a/editor_modules/text_editor/text_editor_settings.cpp +++ b/editor_modules/text_editor/text_editor_settings.cpp @@ -88,7 +88,7 @@ void TextEditorSettings::remove_opened_file(const int index, ItemList *fileconta EditorSettings::get_singleton()->set_project_metadata("file_editor", "files", arr); Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary()); - + if (fonts_dict.has(f)) { fonts_dict.erase(f); EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict); @@ -115,22 +115,23 @@ Array TextEditorSettings::load_opened_files() { if (fonts_dict.has(a[1])) { k.push_back(fonts_dict[a[1]]); } else { - k.push_back("null"); + k.push_back(""); } keys.append(k); } - ERR_PRINT(Variant(keys)); - return keys; } void TextEditorSettings::store_editor_fonts(const String &file_path, const String &font_path) { Dictionary fonts_dict = EditorSettings::get_singleton()->get_project_metadata("file_editor", "file_fonts", Dictionary()); - fonts_dict[file_path] = font_path; - ERR_PRINT(Variant(fonts_dict)); + if (!font_path.empty()) { + fonts_dict[file_path] = font_path; + } else { + fonts_dict.erase(file_path); + } EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", fonts_dict); } @@ -139,6 +140,10 @@ String TextEditorSettings::get_editor_font() { return EditorSettings::get_singleton()->get_setting("interface/editor/code_font"); } +void TextEditorSettings::clear_editor_fonts() { + EditorSettings::get_singleton()->set_project_metadata("file_editor", "file_fonts", Dictionary()); +} + TextEditorSettings::TextEditorSettings() { } diff --git a/editor_modules/text_editor/text_editor_settings.h b/editor_modules/text_editor/text_editor_settings.h index 7c36d7ea33..a73639a4da 100644 --- a/editor_modules/text_editor/text_editor_settings.h +++ b/editor_modules/text_editor/text_editor_settings.h @@ -43,8 +43,10 @@ class TextEditorSettings : public Reference { void store_opened_files(ItemList *filecontainer); void remove_opened_file(const int index, ItemList *filecontainer); Array load_opened_files(); + void store_editor_fonts(const String &file_name, const String &font_path); String get_editor_font(); + void clear_editor_fonts(); TextEditorSettings(); ~TextEditorSettings(); diff --git a/editor_modules/text_editor/text_editor_vanilla_editor.cpp b/editor_modules/text_editor/text_editor_vanilla_editor.cpp index 6c1c705ea2..67bdcb3d43 100644 --- a/editor_modules/text_editor/text_editor_vanilla_editor.cpp +++ b/editor_modules/text_editor/text_editor_vanilla_editor.cpp @@ -75,6 +75,11 @@ void TextEditorVanillaEditor::set_search_flag(const int val) { } void TextEditorVanillaEditor::set_font(const String &font_path) { + if (font_path.empty()) { + text_editor->remove_theme_font_override("font"); + return; + } + Ref dynamic_font; Ref dynamic_font_data; @@ -83,7 +88,7 @@ void TextEditorVanillaEditor::set_font(const String &font_path) { dynamic_font_data->set_font_path(font_path); dynamic_font->set_font_data(dynamic_font_data); - text_editor->set("custom_fonts/font", dynamic_font); + text_editor->add_theme_font_override("font", dynamic_font); } void TextEditorVanillaEditor::load_default_font() { diff --git a/editor_modules/text_editor/text_file_editor.cpp b/editor_modules/text_editor/text_file_editor.cpp index a839b68d39..80b19f336a 100644 --- a/editor_modules/text_editor/text_file_editor.cpp +++ b/editor_modules/text_editor/text_file_editor.cpp @@ -178,6 +178,27 @@ void TextFileEditor::_on_preview_btn_pressed(const int id) { void TextFileEditor::_on_settings_btn_pressed(const int index) { if (index == 0) { select_font_dialog->popup(); + } else if (index == 1) { + if (!current_file_path.empty()) { + _text_editor_settings->store_editor_fonts(current_file_path, ""); + } + + if (current_editor) { + current_editor->set_font(""); + } + } else if (index == 2) { + _text_editor_settings->clear_editor_fonts(); + + for (int i = 0; i < _open_file_list->get_item_count(); ++i) { + Array selected_item_metadata = _open_file_list->get_item_metadata(i); + + ObjectID editor = selected_item_metadata[0]; + TextEditorVanillaEditor *e = Object::cast_to(ObjectDB::get_instance(editor)); + + if (e) { + e->set_font(""); + } + } } } @@ -250,7 +271,7 @@ void TextFileEditor::open_file(const String &path, const String &font) { current_file_path = path; TextEditorVanillaEditor *vanilla_editor = open_in_vanillaeditor(path); - if (font != "null") { + if (!font.empty()) { vanilla_editor->set_font(font); } @@ -651,6 +672,8 @@ TextFileEditor::TextFileEditor() { settings_btn_popup = settings_btn->get_popup(); settings_btn_popup->add_item("Change Font"); + settings_btn_popup->add_item("Clear Font"); + settings_btn_popup->add_item("Clear All Fonts"); //SplitContainer; editor_container = memnew(HSplitContainer); @@ -801,7 +824,7 @@ void TextFileEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_on_font_selected", "font_path"), &TextFileEditor::_on_font_selected); ClassDB::bind_method(D_METHOD("_on_fileitem_pressed", "index"), &TextFileEditor::_on_fileitem_pressed); - ClassDB::bind_method(D_METHOD("open_file", "path", "font"), &TextFileEditor::open_file, "null"); + ClassDB::bind_method(D_METHOD("open_file", "path", "font"), &TextFileEditor::open_file, ""); //ClassDB::bind_method(D_METHOD("generate_file_item", "path", "veditor"), &TextFileEditor::generate_file_item); //ClassDB::bind_method(D_METHOD("open_in_vanillaeditor", "path"), &TextFileEditor::open_in_vanillaeditor); diff --git a/editor_modules/text_editor/text_file_editor.h b/editor_modules/text_editor/text_file_editor.h index 34c588358c..cbd1d63a4d 100644 --- a/editor_modules/text_editor/text_file_editor.h +++ b/editor_modules/text_editor/text_file_editor.h @@ -79,7 +79,7 @@ class TextFileEditor : public Control { void _on_font_selected(const String &font_path); void _on_fileitem_pressed(const int index); - void open_file(const String &path, const String &font = "null"); + void open_file(const String &path, const String &font = ""); void generate_file_item(const String &path, Control *veditor); TextEditorVanillaEditor *open_in_vanillaeditor(const String &path); void close_file(const int index);