diff --git a/addons/block_code/block_code_plugin.gd b/addons/block_code/block_code_plugin.gd index 0067b7f2..9ced14ee 100644 --- a/addons/block_code/block_code_plugin.gd +++ b/addons/block_code/block_code_plugin.gd @@ -61,9 +61,7 @@ func _enter_tree(): func script_window_requested(script: String): var script_window = ScriptWindow.instantiate() script_window.script_content = script - - EditorInterface.get_base_control().add_child(script_window) - + EditorInterface.popup_dialog(script_window) await script_window.close_requested script_window.queue_free() diff --git a/addons/block_code/ui/script_window/script_window.gd b/addons/block_code/ui/script_window/script_window.gd index 77b09dd8..6926e111 100644 --- a/addons/block_code/ui/script_window/script_window.gd +++ b/addons/block_code/ui/script_window/script_window.gd @@ -3,11 +3,31 @@ extends Window var script_content: String = "" -@onready var script_label: TextEdit = $Margin/VBox/ColorRect/Scroll/Margin/Code +@onready var script_label: CodeEdit = %Code + + +## Attempts to match the syntax highlighting for some open script in the +## editor, which is more likely to be appropriate for the editor theme +## than our hardcoded default +func _apply_editor_syntax_highlighter(): + var script_editor: ScriptEditor = EditorInterface.get_script_editor() + for x in script_editor.get_open_script_editors(): + var control: Control = x.get_base_editor() + if control is TextEdit: + script_label.syntax_highlighter = control.syntax_highlighter + break + + +## Undoes the effect of the CodeEdit being read-only +func _remove_font_color_alpha_clamp(): + var font_readonly_color = script_label.get_theme_color("font_readonly_color") + font_readonly_color.a = 1 + script_label.add_theme_color_override("font_readonly_color", font_readonly_color) func _ready(): - popup_centered() + _apply_editor_syntax_highlighter() + _remove_font_color_alpha_clamp() script_label.text = script_content.replace("\t", " ") diff --git a/addons/block_code/ui/script_window/script_window.tscn b/addons/block_code/ui/script_window/script_window.tscn index b275d5cb..0a72b48d 100644 --- a/addons/block_code/ui/script_window/script_window.tscn +++ b/addons/block_code/ui/script_window/script_window.tscn @@ -4,6 +4,7 @@ [sub_resource type="SystemFont" id="SystemFont_r6ct2"] font_names = PackedStringArray("DejaVu Sans Mono") +subpixel_positioning = 0 [sub_resource type="CodeHighlighter" id="CodeHighlighter_yvmnf"] number_color = Color(0.498039, 0.760784, 0.686275, 1) @@ -35,50 +36,40 @@ size = Vector2i(750, 750) transient = true script = ExtResource("1_jja22") -[node name="Margin" type="MarginContainer" parent="."] +[node name="PanelContainer" type="PanelContainer" parent="."] anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme_override_constants/margin_left = 25 -theme_override_constants/margin_top = 25 -theme_override_constants/margin_right = 25 -theme_override_constants/margin_bottom = 25 -[node name="VBox" type="VBoxContainer" parent="Margin"] +[node name="Panel" type="Panel" parent="PanelContainer"] layout_mode = 2 -[node name="CopyCode" type="Button" parent="Margin/VBox"] +[node name="VBox" type="VBoxContainer" parent="PanelContainer"] layout_mode = 2 -text = "Copy" -[node name="ColorRect" type="ColorRect" parent="Margin/VBox"] +[node name="Code" type="CodeEdit" parent="PanelContainer/VBox"] +unique_name_in_owner = true layout_mode = 2 -size_flags_horizontal = 3 size_flags_vertical = 3 -color = Color(0.172833, 0.172833, 0.172833, 1) +theme_override_fonts/font = SubResource("SystemFont_r6ct2") +editable = false +syntax_highlighter = SubResource("CodeHighlighter_yvmnf") -[node name="Scroll" type="ScrollContainer" parent="Margin/VBox/ColorRect"] +[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBox"] layout_mode = 2 -offset_top = -27.0 -offset_right = 700.0 -offset_bottom = 673.0 -[node name="Margin" type="MarginContainer" parent="Margin/VBox/ColorRect/Scroll"] +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBox/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 -size_flags_vertical = 3 -theme_override_constants/margin_left = 35 -theme_override_constants/margin_top = 55 -theme_override_constants/margin_right = 35 -theme_override_constants/margin_bottom = 35 +theme_override_constants/margin_left = 3 +theme_override_constants/margin_right = 3 +theme_override_constants/margin_bottom = 3 -[node name="Code" type="TextEdit" parent="Margin/VBox/ColorRect/Scroll/Margin"] +[node name="CopyCode" type="Button" parent="PanelContainer/VBox/HBoxContainer/MarginContainer"] layout_mode = 2 -theme_override_colors/background_color = Color(0.144063, 0.144063, 0.144062, 1) -theme_override_fonts/font = SubResource("SystemFont_r6ct2") -editable = false -syntax_highlighter = SubResource("CodeHighlighter_yvmnf") +size_flags_horizontal = 4 +text = "Copy" -[connection signal="pressed" from="Margin/VBox/CopyCode" to="." method="_on_copy_code_pressed"] +[connection signal="pressed" from="PanelContainer/VBox/HBoxContainer/MarginContainer/CopyCode" to="." method="_on_copy_code_pressed"]