Implemented search

This commit is contained in:
Marc Gilleron 2018-11-21 00:20:11 +00:00
parent 9ae7c13d7d
commit d9f6602a34
2 changed files with 73 additions and 8 deletions

View File

@ -21,6 +21,8 @@ const FORMAT_GETTEXT = 1
onready var _file_menu = get_node("VBoxContainer/MenuBar/FileMenu") onready var _file_menu = get_node("VBoxContainer/MenuBar/FileMenu")
onready var _edit_menu = get_node("VBoxContainer/MenuBar/EditMenu") 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 _string_list = get_node("VBoxContainer/Main/LeftPane/StringList")
onready var _translation_tab_container = \ onready var _translation_tab_container = \
get_node("VBoxContainer/Main/RightPane/VSplitContainer/TranslationTabContainer") get_node("VBoxContainer/Main/RightPane/VSplitContainer/TranslationTabContainer")
@ -249,7 +251,7 @@ func load_file(filepath):
for language in _languages: for language in _languages:
_create_translation_edit(language) _create_translation_edit(language)
refresh_list() refresh_list()
_modified_languages.clear() _modified_languages.clear()
_update_status_label() _update_status_label()
@ -369,12 +371,21 @@ func save_file(path, format):
func refresh_list(): 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() _string_list.clear()
var ordered_ids = _data.keys() for strid in sorted_strids:
ordered_ids.sort() _string_list.add_item(strid)
for id in ordered_ids:
#var i = _string_list.get_item_count()
_string_list.add_item(id)
func _on_StringList_item_selected(index): func _on_StringList_item_selected(index):
@ -518,3 +529,11 @@ func _on_ExtractorDialog_import_selected(results):
if not _is_string_registered(text): if not _is_string_registered(text):
add_new_string(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 = ""

View File

@ -203,7 +203,23 @@ size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
alignment = 0 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_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -216,7 +232,7 @@ rect_clip_content = false
focus_mode = 2 focus_mode = 2
mouse_filter = 0 mouse_filter = 0
mouse_default_cursor_shape = 1 mouse_default_cursor_shape = 1
size_flags_horizontal = 1 size_flags_horizontal = 3
size_flags_vertical = 1 size_flags_vertical = 1
focus_mode = 2 focus_mode = 2
context_menu_enabled = true context_menu_enabled = true
@ -224,6 +240,32 @@ placeholder_alpha = 0.6
caret_blink = false caret_blink = false
caret_blink_speed = 0.65 caret_blink_speed = 0.65
caret_position = 0 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"] [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="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="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"] [connection signal="pressed" from="VBoxContainer/Main/LeftPane/StringListActions/AddButton" to="." method="_on_AddButton_pressed"]