Fix plugin initialization when active on Godot startup and added open tool button

This commit is contained in:
Marc Gilleron 2018-11-14 23:25:09 +00:00
parent 77c5db71c6
commit 7489df3553
2 changed files with 47 additions and 8 deletions

View File

@ -63,6 +63,13 @@ func _ready():
if _base_control != null:
dialogs_parent = _base_control
# In the editor the parent is still busy setting up children...
call_deferred("_setup_dialogs", dialogs_parent)
_update_status_label()
func _setup_dialogs(dialogs_parent):
_open_dialog = FileDialog.new()
_open_dialog.window_title = "Open translations"
_open_dialog.add_filter("*.csv ; CSV files")
@ -98,8 +105,6 @@ func _ready():
_remove_language_confirmation_dialog.connect("confirmed", self, "_on_RemoveLanguageConfirmationDialog_confirmed")
dialogs_parent.add_child(_remove_language_confirmation_dialog)
_update_status_label()
func configure_for_godot_integration(base_control):
# You have to call this before adding to the tree
@ -113,7 +118,7 @@ func configure_for_godot_integration(base_control):
func _on_FileMenu_id_pressed(id):
match id:
MENU_FILE_OPEN:
_open_dialog.popup_centered_ratio()
_open()
MENU_FILE_SAVE:
_save()
@ -150,6 +155,10 @@ func _on_SaveFolderDialog_dir_selected(filepath):
save_file(filepath, FORMAT_GETTEXT)
func _on_OpenButton_pressed():
_open()
func _on_SaveButton_pressed():
_save()
@ -158,6 +167,10 @@ func _on_LanguageSelectionDialog_language_selected(language):
_add_language(language)
func _open():
_open_dialog.popup_centered_ratio()
func _save():
if _current_path == null:
# Have to default to CSV for now...
@ -432,4 +445,3 @@ func _remove_language(language):
func _on_RemoveLanguageConfirmationDialog_confirmed():
var language = get_current_language()
_remove_language(language)

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://addons/zylann.translation_editor/tools/translation_editor.gd" type="Script" id=1]
[ext_resource path="res://addons/zylann.translation_editor/tools/icons/icon_save.svg" type="Texture" id=2]
[ext_resource path="res://addons/zylann.translation_editor/tools/icons/icon_load.svg" type="Texture" id=2]
[ext_resource path="res://addons/zylann.translation_editor/tools/icons/icon_save.svg" type="Texture" id=3]
[node name="TranslationEditor" type="Panel"]
[node name="TranslationEditor" type="Panel" index="0"]
anchor_left = 0.0
anchor_top = 0.0
@ -118,7 +119,7 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
[node name="SaveButton" type="ToolButton" parent="VBoxContainer/MenuBar" index="3"]
[node name="OpenButton" type="ToolButton" parent="VBoxContainer/MenuBar" index="3"]
anchor_left = 0.0
anchor_top = 0.0
@ -142,6 +143,30 @@ icon = ExtResource( 2 )
flat = true
align = 1
[node name="SaveButton" type="ToolButton" parent="VBoxContainer/MenuBar" index="4"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 119.0
margin_right = 147.0
margin_bottom = 24.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
focus_mode = 2
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
toggle_mode = false
enabled_focus_mode = 2
shortcut = null
group = null
icon = ExtResource( 3 )
flat = true
align = 1
[node name="Main" type="HSplitContainer" parent="VBoxContainer" index="1"]
anchor_left = 0.0
@ -470,6 +495,8 @@ percent_visible = 1.0
lines_skipped = 0
max_lines_visible = -1
[connection signal="pressed" from="VBoxContainer/MenuBar/OpenButton" to="." method="_on_OpenButton_pressed"]
[connection signal="pressed" from="VBoxContainer/MenuBar/SaveButton" to="." method="_on_SaveButton_pressed"]
[connection signal="item_selected" from="VBoxContainer/Main/LeftPane/StringList" to="." method="_on_StringList_item_selected"]