mirror of
https://github.com/Relintai/godot_translation_editor.git
synced 2025-02-06 06:15:54 +01:00
Deduplicate string results in extractor, put their location in collapsed items
This commit is contained in:
parent
a96703cc83
commit
ab8e09b75a
@ -2,6 +2,7 @@
|
||||
const STATE_SEARCHING = 0
|
||||
const STATE_READING_TEXT = 1
|
||||
|
||||
# results: { string => { fpath => line number } }
|
||||
signal finished(results)
|
||||
signal progress_reported(ratio)
|
||||
|
||||
@ -181,9 +182,9 @@ static func find_unescaped_quote(s, from):
|
||||
|
||||
|
||||
func _add_string(file, line_number, text):
|
||||
if not _strings.has(file):
|
||||
_strings[file] = {}
|
||||
_strings[file][text] = line_number
|
||||
if not _strings.has(text):
|
||||
_strings[text] = {}
|
||||
_strings[text][file] = line_number
|
||||
|
||||
|
||||
static func _walk(folder_path, file_action, filter):
|
||||
|
@ -14,6 +14,7 @@ onready var _extract_button = get_node("VBoxContainer/Buttons/ExtractButton")
|
||||
onready var _import_button = get_node("VBoxContainer/Buttons/ImportButton")
|
||||
|
||||
var _extractor = null
|
||||
# { string => { fpath => line number } }
|
||||
var _results = {}
|
||||
var _registered_string_filter = null
|
||||
|
||||
@ -94,38 +95,27 @@ func _on_Extractor_finished(results):
|
||||
# TODO We might actually want to not filter, in order to update location comments
|
||||
# Filter results
|
||||
if _registered_string_filter != null:
|
||||
|
||||
var fpaths = results.keys()
|
||||
for fpath in fpaths:
|
||||
var strings_dict = results[fpath]
|
||||
|
||||
var strings = strings_dict.keys()
|
||||
for text in strings:
|
||||
if _registered_string_filter.call_func(text):
|
||||
strings_dict.erase(text)
|
||||
registered_set[text] = true
|
||||
|
||||
if len(strings_dict) == 0:
|
||||
results.erase(fpath)
|
||||
var texts = results.keys()
|
||||
for text in texts:
|
||||
if _registered_string_filter.call_func(text):
|
||||
results.erase(text)
|
||||
registered_set[text] = true
|
||||
|
||||
# Root
|
||||
_results_list.create_item()
|
||||
|
||||
for fpath in results:
|
||||
#print(fpath)
|
||||
var strings = results[fpath]
|
||||
for text in results:
|
||||
var item = _results_list.create_item()
|
||||
item.set_text(0, text)
|
||||
item.collapsed = true
|
||||
new_set[text] = true
|
||||
|
||||
for text in strings:
|
||||
var line_number = strings[text]
|
||||
#print(" ", line_number, ": `", text, "`")
|
||||
var files = results[text]
|
||||
for file in files:
|
||||
var line_number = files[file]
|
||||
|
||||
var item = _results_list.create_item()
|
||||
item.set_text(0, text)
|
||||
item.set_text(1, str(fpath, ": ", line_number))
|
||||
#item.set_tooltip(
|
||||
item.set_metadata(1, fpath)
|
||||
|
||||
new_set[text] = true
|
||||
var file_item = _results_list.create_item(item)
|
||||
file_item.set_text(0, str(file, ": ", line_number))
|
||||
|
||||
_results = results
|
||||
_extractor = null
|
||||
|
@ -248,7 +248,7 @@ mouse_filter = 0
|
||||
mouse_default_cursor_shape = 0
|
||||
size_flags_horizontal = 1
|
||||
size_flags_vertical = 3
|
||||
columns = 2
|
||||
columns = 1
|
||||
allow_reselect = false
|
||||
allow_rmb_select = false
|
||||
hide_folding = false
|
||||
|
@ -521,13 +521,9 @@ func _is_string_registered(text):
|
||||
|
||||
|
||||
func _on_ExtractorDialog_import_selected(results):
|
||||
for fpath in results:
|
||||
var strings = results[fpath]
|
||||
for text in strings:
|
||||
# Checking because there might be duplicates,
|
||||
# strings can be found in multiple places
|
||||
if not _is_string_registered(text):
|
||||
add_new_string(text)
|
||||
for text in results:
|
||||
if not _is_string_registered(text):
|
||||
add_new_string(text)
|
||||
|
||||
|
||||
func _on_Search_text_changed(search_text):
|
||||
|
Loading…
Reference in New Issue
Block a user