diff --git a/addons/zylann.translation_editor/tools/translation_editor.gd b/addons/zylann.translation_editor/tools/translation_editor.gd index 1e36c07..8519fa9 100644 --- a/addons/zylann.translation_editor/tools/translation_editor.gd +++ b/addons/zylann.translation_editor/tools/translation_editor.gd @@ -21,6 +21,8 @@ const FORMAT_GETTEXT = 1 onready var _file_menu = get_node("VBoxContainer/MenuBar/FileMenu") onready var _edit_menu = get_node("VBoxContainer/MenuBar/EditMenu") +onready var _search_edit = get_node("VBoxContainer/Main/LeftPane/Search/Search") +onready var _clear_search_button = get_node("VBoxContainer/Main/LeftPane/Search/ClearSearch") onready var _string_list = get_node("VBoxContainer/Main/LeftPane/StringList") onready var _translation_tab_container = \ get_node("VBoxContainer/Main/RightPane/VSplitContainer/TranslationTabContainer") @@ -249,7 +251,7 @@ func load_file(filepath): for language in _languages: _create_translation_edit(language) - + refresh_list() _modified_languages.clear() _update_status_label() @@ -369,12 +371,21 @@ func save_file(path, format): func refresh_list(): + var search_text = _search_edit.text.strip_edges() + + var sorted_strids = [] + if search_text == "": + sorted_strids = _data.keys() + else: + for strid in _data.keys(): + if strid.find(search_text) != -1: + sorted_strids.append(strid) + + sorted_strids.sort() + _string_list.clear() - var ordered_ids = _data.keys() - ordered_ids.sort() - for id in ordered_ids: - #var i = _string_list.get_item_count() - _string_list.add_item(id) + for strid in sorted_strids: + _string_list.add_item(strid) func _on_StringList_item_selected(index): @@ -518,3 +529,11 @@ func _on_ExtractorDialog_import_selected(results): if not _is_string_registered(text): add_new_string(text) + +func _on_Search_text_changed(search_text): + _clear_search_button.visible = (search_text != "") + refresh_list() + + +func _on_ClearSearch_pressed(): + _search_edit.text = "" diff --git a/addons/zylann.translation_editor/tools/translation_editor.tscn b/addons/zylann.translation_editor/tools/translation_editor.tscn index c77d2b4..fba3bce 100644 --- a/addons/zylann.translation_editor/tools/translation_editor.tscn +++ b/addons/zylann.translation_editor/tools/translation_editor.tscn @@ -203,7 +203,23 @@ size_flags_horizontal = 1 size_flags_vertical = 1 alignment = 0 -[node name="Search" type="LineEdit" parent="VBoxContainer/Main/LeftPane" index="0"] +[node name="Search" type="HBoxContainer" parent="VBoxContainer/Main/LeftPane" index="0"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_right = 273.0 +margin_bottom = 24.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 1 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 1 +alignment = 0 + +[node name="Search" type="LineEdit" parent="VBoxContainer/Main/LeftPane/Search" index="0"] anchor_left = 0.0 anchor_top = 0.0 @@ -216,7 +232,7 @@ rect_clip_content = false focus_mode = 2 mouse_filter = 0 mouse_default_cursor_shape = 1 -size_flags_horizontal = 1 +size_flags_horizontal = 3 size_flags_vertical = 1 focus_mode = 2 context_menu_enabled = true @@ -224,6 +240,32 @@ placeholder_alpha = 0.6 caret_blink = false caret_blink_speed = 0.65 caret_position = 0 +_sections_unfolded = [ "Size Flags" ] + +[node name="ClearSearch" type="Button" parent="VBoxContainer/Main/LeftPane/Search" index="1"] + +visible = false +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 254.0 +margin_right = 273.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 +text = "x" +flat = false +align = 1 [node name="StringList" type="ItemList" parent="VBoxContainer/Main/LeftPane" index="1"] @@ -499,6 +541,10 @@ max_lines_visible = -1 [connection signal="pressed" from="VBoxContainer/MenuBar/SaveButton" to="." method="_on_SaveButton_pressed"] +[connection signal="text_changed" from="VBoxContainer/Main/LeftPane/Search/Search" to="." method="_on_Search_text_changed"] + +[connection signal="pressed" from="VBoxContainer/Main/LeftPane/Search/ClearSearch" to="." method="_on_ClearSearch_pressed"] + [connection signal="item_selected" from="VBoxContainer/Main/LeftPane/StringList" to="." method="_on_StringList_item_selected"] [connection signal="pressed" from="VBoxContainer/Main/LeftPane/StringListActions/AddButton" to="." method="_on_AddButton_pressed"]