From 0823d783745994b9a03d21762a9d532a55d00b86 Mon Sep 17 00:00:00 2001 From: Kis Levente Lorand Date: Thu, 23 May 2019 18:18:24 +0300 Subject: [PATCH] Created a fallback from the "Save Theme" button to "Save Theme As" when a default theme is in use. --- editor/editor_settings.cpp | 23 +++++++++++++++++------ editor/editor_settings.h | 2 ++ editor/plugins/script_editor_plugin.cpp | 24 +++++++++++++++--------- editor/plugins/script_editor_plugin.h | 1 + 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index cb40926ce3a..d3f201fdd63 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -679,6 +679,10 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { return false; } +bool EditorSettings::_is_default_text_editor_theme(String p_theme_name) { + return p_theme_name == "default" || p_theme_name == "adaptive" || p_theme_name == "custom"; +} + static Dictionary _get_builtin_script_templates() { Dictionary templates; @@ -1271,7 +1275,7 @@ void EditorSettings::list_text_editor_themes() { d->list_dir_begin(); String file = d->get_next(); while (file != String()) { - if (file.get_extension() == "tet" && file.get_basename().to_lower() != "default" && file.get_basename().to_lower() != "adaptive" && file.get_basename().to_lower() != "custom") { + if (file.get_extension() == "tet" && !_is_default_text_editor_theme(file.get_basename().to_lower())) { custom_themes.push_back(file.get_basename()); } file = d->get_next(); @@ -1288,14 +1292,16 @@ void EditorSettings::list_text_editor_themes() { } void EditorSettings::load_text_editor_theme() { - if (get("text_editor/theme/color_theme") == "Default" || get("text_editor/theme/color_theme") == "Adaptive" || get("text_editor/theme/color_theme") == "Custom") { - if (get("text_editor/theme/color_theme") == "Default") { + String p_file = get("text_editor/theme/color_theme"); + + if (_is_default_text_editor_theme(p_file.get_file().to_lower())) { + if (p_file == "Default") { _load_default_text_editor_theme(); } return; // sorry for "Settings changed" console spam } - String theme_path = get_text_editor_themes_dir().plus_file((String)get("text_editor/theme/color_theme") + ".tet"); + String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet"); Ref cf = memnew(ConfigFile); Error err = cf->load(theme_path); @@ -1347,7 +1353,7 @@ bool EditorSettings::save_text_editor_theme() { String p_file = get("text_editor/theme/color_theme"); - if (p_file.get_file().to_lower() == "default" || p_file.get_file().to_lower() == "adaptive" || p_file.get_file().to_lower() == "custom") { + if (_is_default_text_editor_theme(p_file.get_file().to_lower())) { return false; } String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet"); @@ -1359,7 +1365,7 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) { p_file += ".tet"; } - if (p_file.get_file().to_lower() == "default.tet" || p_file.get_file().to_lower() == "adaptive.tet" || p_file.get_file().to_lower() == "custom.tet") { + if (_is_default_text_editor_theme(p_file.get_file().to_lower().trim_suffix(".tet"))) { return false; } if (_save_text_editor_theme(p_file)) { @@ -1377,6 +1383,11 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) { return false; } +bool EditorSettings::is_default_text_editor_theme() { + String p_file = get("text_editor/theme/color_theme"); + return _is_default_text_editor_theme(p_file.get_file().to_lower()); +} + Vector EditorSettings::get_script_templates(const String &p_extension) { Vector templates; diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 43a8cbf7392..2ee8dd805b4 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -123,6 +123,7 @@ private: void _load_defaults(Ref p_extra_config = NULL); void _load_default_text_editor_theme(); bool _save_text_editor_theme(String p_file); + bool _is_default_text_editor_theme(String p_file); protected: static void _bind_methods(); @@ -187,6 +188,7 @@ public: bool import_text_editor_theme(String p_file); bool save_text_editor_theme(); bool save_text_editor_theme_as(String p_file); + bool is_default_text_editor_theme(); Vector get_script_templates(const String &p_extension); String get_editor_layouts_config() const; diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 828abef9a92..1432221915a 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1296,23 +1296,29 @@ void ScriptEditor::_theme_option(int p_option) { EditorSettings::get_singleton()->load_text_editor_theme(); } break; case THEME_SAVE: { - if (!EditorSettings::get_singleton()->save_text_editor_theme()) { + if (EditorSettings::get_singleton()->is_default_text_editor_theme()) { + ScriptEditor::_show_save_theme_as_dialog(); + } else if (!EditorSettings::get_singleton()->save_text_editor_theme()) { editor->show_warning(TTR("Error while saving theme"), TTR("Error saving")); } } break; case THEME_SAVE_AS: { - file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); - file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - file_dialog_option = THEME_SAVE_AS; - file_dialog->clear_filters(); - file_dialog->add_filter("*.tet"); - file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme"))); - file_dialog->popup_centered_ratio(); - file_dialog->set_title(TTR("Save Theme As...")); + ScriptEditor::_show_save_theme_as_dialog(); } break; } } +void ScriptEditor::_show_save_theme_as_dialog() { + file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); + file_dialog_option = THEME_SAVE_AS; + file_dialog->clear_filters(); + file_dialog->add_filter("*.tet"); + file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme"))); + file_dialog->popup_centered_ratio(); + file_dialog->set_title(TTR("Save Theme As...")); +} + void ScriptEditor::_tab_changed(int p_which) { ensure_select_current(); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 683fa881f86..d47a5af5ecd 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -263,6 +263,7 @@ class ScriptEditor : public PanelContainer { void _tab_changed(int p_which); void _menu_option(int p_option); void _theme_option(int p_option); + void _show_save_theme_as_dialog(); Tree *disk_changed_list; ConfirmationDialog *disk_changed;