Skip to content

Commit 7e9e3b7

Browse files
committed
Fix some Text Editor theme issues and clean up
1 parent c6d130a commit 7e9e3b7

File tree

8 files changed

+354
-431
lines changed

8 files changed

+354
-431
lines changed

doc/classes/EditorSettings.xml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,27 @@
14991499
The script editor's comment color.
15001500
[b]Note:[/b] In GDScript, unlike Python, multiline strings are not considered to be comments, and will use the string highlighting color instead.
15011501
</member>
1502+
<member name="text_editor/theme/highlighting/comment_markers/critical_color" type="Color" setter="" getter="">
1503+
The script editor's critical comment marker text color. These markers are determined by [member text_editor/theme/highlighting/comment_markers/critical_list].
1504+
</member>
1505+
<member name="text_editor/theme/highlighting/comment_markers/critical_list" type="String" setter="" getter="">
1506+
A comma-separated list of case-sensitive words to highlight in comments. The text will be highlighted in the script editor with the [member text_editor/theme/highlighting/comment_markers/critical_color] color. These must not include spaces or symbols or they will not be highlighted.
1507+
[b]Note:[/b] This is only implemented in the GDScript syntax highlighter.
1508+
</member>
1509+
<member name="text_editor/theme/highlighting/comment_markers/notice_color" type="Color" setter="" getter="">
1510+
The script editor's notice comment marker text color. These markers are determined by [member text_editor/theme/highlighting/comment_markers/notice_list].
1511+
</member>
1512+
<member name="text_editor/theme/highlighting/comment_markers/notice_list" type="String" setter="" getter="">
1513+
A comma-separated list of case-sensitive words to highlight in comments. The text will be highlighted in the script editor with the [member text_editor/theme/highlighting/comment_markers/notice_color] color. These must not include spaces or symbols or they will not be highlighted.
1514+
[b]Note:[/b] This is only implemented in the GDScript syntax highlighter.
1515+
</member>
1516+
<member name="text_editor/theme/highlighting/comment_markers/warning_color" type="Color" setter="" getter="">
1517+
The script editor's warning comment marker text color. These markers are determined by [member text_editor/theme/highlighting/comment_markers/warning_list].
1518+
</member>
1519+
<member name="text_editor/theme/highlighting/comment_markers/warning_list" type="String" setter="" getter="">
1520+
A comma-separated list of case-sensitive words to highlight in comments. The text will be highlighted in the script editor with the [member text_editor/theme/highlighting/comment_markers/warning_color] color. These must not include spaces or symbols or they will not be highlighted.
1521+
[b]Note:[/b] This is only implemented in the GDScript syntax highlighter.
1522+
</member>
15021523
<member name="text_editor/theme/highlighting/completion_background_color" type="Color" setter="" getter="">
15031524
The script editor's autocompletion box background color.
15041525
</member>
@@ -1537,7 +1558,25 @@
15371558
</member>
15381559
<member name="text_editor/theme/highlighting/function_color" type="Color" setter="" getter="">
15391560
The script editor's function call color.
1540-
[b]Note:[/b] When using the GDScript syntax highlighter, this is replaced by the function definition color configured in the syntax theme for function definitions (e.g. [code]func _ready():[/code]).
1561+
[b]Note:[/b] When using the GDScript syntax highlighter, this is only used when calling some functions since function definitions and global functions have their own colors [member text_editor/theme/highlighting/gdscript/function_definition_color] and [member text_editor/theme/highlighting/gdscript/global_function_color].
1562+
</member>
1563+
<member name="text_editor/theme/highlighting/gdscript/annotation_color" type="Color" setter="" getter="">
1564+
The GDScript syntax highlighter text color for annotations (e.g. [code]@export[/code]).
1565+
</member>
1566+
<member name="text_editor/theme/highlighting/gdscript/function_definition_color" type="Color" setter="" getter="">
1567+
The GDScript syntax highlighter text color for function definitions (e.g. the [code]_ready[/code] in [code]func _ready():[/code]).
1568+
</member>
1569+
<member name="text_editor/theme/highlighting/gdscript/global_function_color" type="Color" setter="" getter="">
1570+
The GDScript syntax highlighter text color for global functions, such as the ones in [@GlobalScope] (e.g. [code]preload()[/code]).
1571+
</member>
1572+
<member name="text_editor/theme/highlighting/gdscript/node_path_color" type="Color" setter="" getter="">
1573+
The GDScript syntax highlighter text color for [NodePath] literals (e.g. [code]^"position:x"[/code]).
1574+
</member>
1575+
<member name="text_editor/theme/highlighting/gdscript/node_reference_color" type="Color" setter="" getter="">
1576+
The GDScript syntax highlighter text color for node reference literals (e.g. [code]$"Sprite"[/code] and [code]%"Sprite"[/code]]).
1577+
</member>
1578+
<member name="text_editor/theme/highlighting/gdscript/string_name_color" type="Color" setter="" getter="">
1579+
The GDScript syntax highlighter text color for [StringName] literals (e.g. [code]&gt;"example"[/code]).
15411580
</member>
15421581
<member name="text_editor/theme/highlighting/keyword_color" type="Color" setter="" getter="">
15431582
The script editor's non-control flow keyword color (used for keywords like [code]var[/code], [code]func[/code], [code]extends[/code], ...).

editor/script/script_editor_plugin.cpp

Lines changed: 72 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,73 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Resource> p_for_script) {
12221222
return need_reload;
12231223
}
12241224

1225+
void _import_text_editor_theme(const String &p_file) {
1226+
if (p_file.get_extension() != "tet") {
1227+
EditorToaster::get_singleton()->popup_str(TTR("Importing theme failed. File is not a text editor theme file (.tet)."), EditorToaster::SEVERITY_ERROR);
1228+
return;
1229+
}
1230+
const String theme_name = p_file.get_file().get_basename();
1231+
if (EditorSettings::is_default_text_editor_theme(theme_name.to_lower())) {
1232+
EditorToaster::get_singleton()->popup_str(TTR("Importing theme failed. File name cannot be 'Default', 'Custom', or 'Godot 2'."), EditorToaster::SEVERITY_ERROR);
1233+
return;
1234+
}
1235+
1236+
const String theme_dir = EditorPaths::get_singleton()->get_text_editor_themes_dir();
1237+
Ref<DirAccess> d = DirAccess::open(theme_dir);
1238+
Error err = FAILED;
1239+
if (d.is_valid()) {
1240+
err = d->copy(p_file, theme_dir.path_join(p_file.get_file()));
1241+
}
1242+
1243+
if (err != OK) {
1244+
EditorToaster::get_singleton()->popup_str(TTR("Importing theme failed. Failed to copy theme file."), EditorToaster::SEVERITY_ERROR);
1245+
return;
1246+
}
1247+
1248+
// Reload themes and switch to new theme.
1249+
EditorSettings::get_singleton()->update_text_editor_themes_list();
1250+
EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", theme_name, true);
1251+
EditorSettings::get_singleton()->notify_changes();
1252+
}
1253+
1254+
void _save_text_editor_theme_as(const String &p_file) {
1255+
String file = p_file;
1256+
if (p_file.get_extension() != "tet") {
1257+
file += ".tet";
1258+
}
1259+
1260+
const String theme_name = file.get_file().get_basename();
1261+
if (EditorSettings::is_default_text_editor_theme(theme_name.to_lower())) {
1262+
EditorToaster::get_singleton()->popup_str(TTR("Saving theme failed. File name cannot be 'Default', 'Custom', or 'Godot 2'."), EditorToaster::SEVERITY_ERROR);
1263+
return;
1264+
}
1265+
1266+
const String theme_section = "color_theme";
1267+
const Ref<ConfigFile> cf = memnew(ConfigFile);
1268+
1269+
// Use the keys from the Godot 2 theme to know which settings to save.
1270+
HashMap<StringName, Color> text_colors = EditorSettings::get_godot2_text_editor_theme();
1271+
text_colors.sort();
1272+
for (const KeyValue<StringName, Color> &text_color : text_colors) {
1273+
const Color val = EditorSettings::get_singleton()->get_setting(text_color.key);
1274+
const String &key = text_color.key.operator String().replace("text_editor/theme/highlighting/", "");
1275+
cf->set_value(theme_section, key, val.to_html());
1276+
}
1277+
1278+
const Error err = cf->save(file);
1279+
if (err != OK) {
1280+
EditorToaster::get_singleton()->popup_str(TTR("Saving theme failed."), EditorToaster::SEVERITY_ERROR);
1281+
return;
1282+
}
1283+
1284+
// Reload themes and switch to saved theme.
1285+
EditorSettings::get_singleton()->update_text_editor_themes_list();
1286+
if (p_file.get_base_dir() == EditorPaths::get_singleton()->get_text_editor_themes_dir()) {
1287+
// Don't need to emit signal or notify changes as the colors are already set.
1288+
EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", theme_name, false);
1289+
}
1290+
}
1291+
12251292
void ScriptEditor::_file_dialog_action(const String &p_file) {
12261293
switch (file_dialog_option) {
12271294
case FILE_MENU_NEW_TEXTFILE: {
@@ -1266,14 +1333,10 @@ void ScriptEditor::_file_dialog_action(const String &p_file) {
12661333
}
12671334
} break;
12681335
case THEME_SAVE_AS: {
1269-
if (!EditorSettings::get_singleton()->save_text_editor_theme_as(p_file)) {
1270-
EditorNode::get_singleton()->show_warning(TTR("Error while saving theme."), TTR("Error Saving"));
1271-
}
1336+
_save_text_editor_theme_as(p_file);
12721337
} break;
12731338
case THEME_IMPORT: {
1274-
if (!EditorSettings::get_singleton()->import_text_editor_theme(p_file)) {
1275-
EditorNode::get_singleton()->show_warning(TTR("Error importing theme."), TTR("Error Importing"));
1276-
}
1339+
_import_text_editor_theme(p_file);
12771340
} break;
12781341
}
12791342
file_dialog_option = -1;
@@ -1642,14 +1705,8 @@ void ScriptEditor::_theme_option(int p_option) {
16421705
file_dialog->popup_file_dialog();
16431706
} break;
16441707
case THEME_RELOAD: {
1645-
EditorSettings::get_singleton()->load_text_editor_theme();
1646-
} break;
1647-
case THEME_SAVE: {
1648-
if (EditorSettings::get_singleton()->is_default_text_editor_theme()) {
1649-
ScriptEditor::_show_save_theme_as_dialog();
1650-
} else if (!EditorSettings::get_singleton()->save_text_editor_theme()) {
1651-
EditorNode::get_singleton()->show_warning(TTR("Error while saving theme"), TTR("Error saving"));
1652-
}
1708+
EditorSettings::get_singleton()->mark_setting_changed("text_editor/theme/color_theme");
1709+
EditorSettings::get_singleton()->notify_changes();
16531710
} break;
16541711
case THEME_SAVE_AS: {
16551712
ScriptEditor::_show_save_theme_as_dialog();
@@ -1663,7 +1720,7 @@ void ScriptEditor::_show_save_theme_as_dialog() {
16631720
file_dialog_option = THEME_SAVE_AS;
16641721
file_dialog->clear_filters();
16651722
file_dialog->add_filter("*.tet");
1666-
file_dialog->set_current_path(EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(EDITOR_GET("text_editor/theme/color_theme")));
1723+
file_dialog->set_current_path(EditorPaths::get_singleton()->get_text_editor_themes_dir().path_join(EDITOR_GET("text_editor/theme/color_theme")) + " New");
16671724
file_dialog->set_title(TTRC("Save Theme As..."));
16681725
file_dialog->popup_file_dialog();
16691726
}
@@ -3033,13 +3090,6 @@ void ScriptEditor::_apply_editor_settings() {
30333090

30343091
_update_autosave_timer();
30353092

3036-
if (current_theme.is_empty()) {
3037-
current_theme = EDITOR_GET("text_editor/theme/color_theme");
3038-
} else if (current_theme != String(EDITOR_GET("text_editor/theme/color_theme"))) {
3039-
current_theme = EDITOR_GET("text_editor/theme/color_theme");
3040-
EditorSettings::get_singleton()->load_text_editor_theme();
3041-
}
3042-
30433093
_update_script_names();
30443094

30453095
ScriptServer::set_reload_scripts_on_save(EDITOR_GET("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save"));
@@ -4161,7 +4211,6 @@ void ScriptEditor::_bind_methods() {
41614211

41624212
ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
41634213
window_wrapper = p_wrapper;
4164-
current_theme = "";
41654214

41664215
script_editor_cache.instantiate();
41674216
script_editor_cache->load(EditorPaths::get_singleton()->get_project_settings_dir().path_join("script_editor_cache.cfg"));
@@ -4340,7 +4389,6 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
43404389
theme_submenu->connect(SceneStringName(id_pressed), callable_mp(this, &ScriptEditor::_theme_option));
43414390

43424391
theme_submenu->add_separator();
4343-
theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTRC("Save Theme")), THEME_SAVE);
43444392
theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTRC("Save Theme As...")), THEME_SAVE_AS);
43454393

43464394
file_menu->get_popup()->add_separator();

editor/script/script_editor_plugin.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,10 @@ class ScriptEditor : public PanelContainer {
301301

302302
SEARCH_HELP,
303303
SEARCH_WEBSITE,
304-
};
305304

306-
enum ThemeMenu {
305+
// Theme.
307306
THEME_IMPORT,
308307
THEME_RELOAD,
309-
THEME_SAVE,
310308
THEME_SAVE_AS,
311309
};
312310

@@ -362,8 +360,6 @@ class ScriptEditor : public PanelContainer {
362360
Button *scripts_visible = nullptr;
363361
FindReplaceBar *find_replace_bar = nullptr;
364362

365-
String current_theme;
366-
367363
float zoom_factor = 1.0f;
368364

369365
TextureRect *script_icon = nullptr;

0 commit comments

Comments
 (0)