Skip to content

Commit add1611

Browse files
authored
Merge pull request #286 from endlessm/fix-script-popup
Fix script popup
2 parents 94a4d60 + 778c8d7 commit add1611

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

addons/block_code/block_code_plugin.gd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ func _enter_tree():
6161
func script_window_requested(script: String):
6262
var script_window = ScriptWindow.instantiate()
6363
script_window.script_content = script
64-
65-
EditorInterface.get_base_control().add_child(script_window)
66-
64+
EditorInterface.popup_dialog(script_window)
6765
await script_window.close_requested
6866

6967
script_window.queue_free()

addons/block_code/ui/script_window/script_window.gd

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,31 @@ extends Window
33

44
var script_content: String = ""
55

6-
@onready var script_label: TextEdit = $Margin/VBox/ColorRect/Scroll/Margin/Code
6+
@onready var script_label: CodeEdit = %Code
7+
8+
9+
## Attempts to match the syntax highlighting for some open script in the
10+
## editor, which is more likely to be appropriate for the editor theme
11+
## than our hardcoded default
12+
func _apply_editor_syntax_highlighter():
13+
var script_editor: ScriptEditor = EditorInterface.get_script_editor()
14+
for x in script_editor.get_open_script_editors():
15+
var control: Control = x.get_base_editor()
16+
if control is TextEdit:
17+
script_label.syntax_highlighter = control.syntax_highlighter
18+
break
19+
20+
21+
## Undoes the effect of the CodeEdit being read-only
22+
func _remove_font_color_alpha_clamp():
23+
var font_readonly_color = script_label.get_theme_color("font_readonly_color")
24+
font_readonly_color.a = 1
25+
script_label.add_theme_color_override("font_readonly_color", font_readonly_color)
726

827

928
func _ready():
10-
popup_centered()
29+
_apply_editor_syntax_highlighter()
30+
_remove_font_color_alpha_clamp()
1131
script_label.text = script_content.replace("\t", " ")
1232

1333

addons/block_code/ui/script_window/script_window.tscn

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[sub_resource type="SystemFont" id="SystemFont_r6ct2"]
66
font_names = PackedStringArray("DejaVu Sans Mono")
7+
subpixel_positioning = 0
78

89
[sub_resource type="CodeHighlighter" id="CodeHighlighter_yvmnf"]
910
number_color = Color(0.498039, 0.760784, 0.686275, 1)
@@ -35,50 +36,40 @@ size = Vector2i(750, 750)
3536
transient = true
3637
script = ExtResource("1_jja22")
3738

38-
[node name="Margin" type="MarginContainer" parent="."]
39+
[node name="PanelContainer" type="PanelContainer" parent="."]
3940
anchors_preset = 15
4041
anchor_right = 1.0
4142
anchor_bottom = 1.0
4243
grow_horizontal = 2
4344
grow_vertical = 2
44-
theme_override_constants/margin_left = 25
45-
theme_override_constants/margin_top = 25
46-
theme_override_constants/margin_right = 25
47-
theme_override_constants/margin_bottom = 25
4845

49-
[node name="VBox" type="VBoxContainer" parent="Margin"]
46+
[node name="Panel" type="Panel" parent="PanelContainer"]
5047
layout_mode = 2
5148

52-
[node name="CopyCode" type="Button" parent="Margin/VBox"]
49+
[node name="VBox" type="VBoxContainer" parent="PanelContainer"]
5350
layout_mode = 2
54-
text = "Copy"
5551

56-
[node name="ColorRect" type="ColorRect" parent="Margin/VBox"]
52+
[node name="Code" type="CodeEdit" parent="PanelContainer/VBox"]
53+
unique_name_in_owner = true
5754
layout_mode = 2
58-
size_flags_horizontal = 3
5955
size_flags_vertical = 3
60-
color = Color(0.172833, 0.172833, 0.172833, 1)
56+
theme_override_fonts/font = SubResource("SystemFont_r6ct2")
57+
editable = false
58+
syntax_highlighter = SubResource("CodeHighlighter_yvmnf")
6159

62-
[node name="Scroll" type="ScrollContainer" parent="Margin/VBox/ColorRect"]
60+
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBox"]
6361
layout_mode = 2
64-
offset_top = -27.0
65-
offset_right = 700.0
66-
offset_bottom = 673.0
6762

68-
[node name="Margin" type="MarginContainer" parent="Margin/VBox/ColorRect/Scroll"]
63+
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer/VBox/HBoxContainer"]
6964
layout_mode = 2
7065
size_flags_horizontal = 3
71-
size_flags_vertical = 3
72-
theme_override_constants/margin_left = 35
73-
theme_override_constants/margin_top = 55
74-
theme_override_constants/margin_right = 35
75-
theme_override_constants/margin_bottom = 35
66+
theme_override_constants/margin_left = 3
67+
theme_override_constants/margin_right = 3
68+
theme_override_constants/margin_bottom = 3
7669

77-
[node name="Code" type="TextEdit" parent="Margin/VBox/ColorRect/Scroll/Margin"]
70+
[node name="CopyCode" type="Button" parent="PanelContainer/VBox/HBoxContainer/MarginContainer"]
7871
layout_mode = 2
79-
theme_override_colors/background_color = Color(0.144063, 0.144063, 0.144062, 1)
80-
theme_override_fonts/font = SubResource("SystemFont_r6ct2")
81-
editable = false
82-
syntax_highlighter = SubResource("CodeHighlighter_yvmnf")
72+
size_flags_horizontal = 4
73+
text = "Copy"
8374

84-
[connection signal="pressed" from="Margin/VBox/CopyCode" to="." method="_on_copy_code_pressed"]
75+
[connection signal="pressed" from="PanelContainer/VBox/HBoxContainer/MarginContainer/CopyCode" to="." method="_on_copy_code_pressed"]

0 commit comments

Comments
 (0)