mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-22 03:46:50 +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
@ -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() {
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,10 @@ public:
|
||||
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();
|
||||
|
@ -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<DynamicFont> dynamic_font;
|
||||
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->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() {
|
||||
|
@ -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<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;
|
||||
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);
|
||||
|
||||
|
@ -79,7 +79,7 @@ public:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user