mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-03 09:29:38 +01:00
Implemented clearing custom fonts in the editor's text editor module. Also small improvements.
This commit is contained in:
parent
2a0b2b696a
commit
441c52afd3
@ -115,22 +115,23 @@ Array TextEditorSettings::load_opened_files() {
|
|||||||
if (fonts_dict.has(a[1])) {
|
if (fonts_dict.has(a[1])) {
|
||||||
k.push_back(fonts_dict[a[1]]);
|
k.push_back(fonts_dict[a[1]]);
|
||||||
} else {
|
} else {
|
||||||
k.push_back("null");
|
k.push_back("");
|
||||||
}
|
}
|
||||||
|
|
||||||
keys.append(k);
|
keys.append(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_PRINT(Variant(keys));
|
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorSettings::store_editor_fonts(const String &file_path, const String &font_path) {
|
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());
|
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);
|
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");
|
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() {
|
TextEditorSettings::TextEditorSettings() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,10 @@ public:
|
|||||||
void store_opened_files(ItemList *filecontainer);
|
void store_opened_files(ItemList *filecontainer);
|
||||||
void remove_opened_file(const int index, ItemList *filecontainer);
|
void remove_opened_file(const int index, ItemList *filecontainer);
|
||||||
Array load_opened_files();
|
Array load_opened_files();
|
||||||
|
|
||||||
void store_editor_fonts(const String &file_name, const String &font_path);
|
void store_editor_fonts(const String &file_name, const String &font_path);
|
||||||
String get_editor_font();
|
String get_editor_font();
|
||||||
|
void clear_editor_fonts();
|
||||||
|
|
||||||
TextEditorSettings();
|
TextEditorSettings();
|
||||||
~TextEditorSettings();
|
~TextEditorSettings();
|
||||||
|
@ -75,6 +75,11 @@ void TextEditorVanillaEditor::set_search_flag(const int val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorVanillaEditor::set_font(const String &font_path) {
|
void TextEditorVanillaEditor::set_font(const String &font_path) {
|
||||||
|
if (font_path.empty()) {
|
||||||
|
text_editor->remove_theme_font_override("font");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Ref<DynamicFont> dynamic_font;
|
Ref<DynamicFont> dynamic_font;
|
||||||
Ref<DynamicFontData> dynamic_font_data;
|
Ref<DynamicFontData> 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_data->set_font_path(font_path);
|
||||||
dynamic_font->set_font_data(dynamic_font_data);
|
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() {
|
void TextEditorVanillaEditor::load_default_font() {
|
||||||
|
@ -178,6 +178,27 @@ void TextFileEditor::_on_preview_btn_pressed(const int id) {
|
|||||||
void TextFileEditor::_on_settings_btn_pressed(const int index) {
|
void TextFileEditor::_on_settings_btn_pressed(const int index) {
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
select_font_dialog->popup();
|
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<TextEditorVanillaEditor>(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;
|
current_file_path = path;
|
||||||
TextEditorVanillaEditor *vanilla_editor = open_in_vanillaeditor(path);
|
TextEditorVanillaEditor *vanilla_editor = open_in_vanillaeditor(path);
|
||||||
|
|
||||||
if (font != "null") {
|
if (!font.empty()) {
|
||||||
vanilla_editor->set_font(font);
|
vanilla_editor->set_font(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,6 +672,8 @@ TextFileEditor::TextFileEditor() {
|
|||||||
|
|
||||||
settings_btn_popup = settings_btn->get_popup();
|
settings_btn_popup = settings_btn->get_popup();
|
||||||
settings_btn_popup->add_item("Change Font");
|
settings_btn_popup->add_item("Change Font");
|
||||||
|
settings_btn_popup->add_item("Clear Font");
|
||||||
|
settings_btn_popup->add_item("Clear All Fonts");
|
||||||
|
|
||||||
//SplitContainer;
|
//SplitContainer;
|
||||||
editor_container = memnew(HSplitContainer);
|
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_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("_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("generate_file_item", "path", "veditor"), &TextFileEditor::generate_file_item);
|
||||||
//ClassDB::bind_method(D_METHOD("open_in_vanillaeditor", "path"), &TextFileEditor::open_in_vanillaeditor);
|
//ClassDB::bind_method(D_METHOD("open_in_vanillaeditor", "path"), &TextFileEditor::open_in_vanillaeditor);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ public:
|
|||||||
void _on_font_selected(const String &font_path);
|
void _on_font_selected(const String &font_path);
|
||||||
void _on_fileitem_pressed(const int index);
|
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);
|
void generate_file_item(const String &path, Control *veditor);
|
||||||
TextEditorVanillaEditor *open_in_vanillaeditor(const String &path);
|
TextEditorVanillaEditor *open_in_vanillaeditor(const String &path);
|
||||||
void close_file(const int index);
|
void close_file(const int index);
|
||||||
|
Loading…
Reference in New Issue
Block a user