Rewrite search behaviour (fixes #8)

This commit is contained in:
don-tnowe 2022-10-02 22:26:07 +03:00
parent fdcd89ef8a
commit 29359a1596
3 changed files with 21 additions and 24 deletions

View File

@ -73,7 +73,7 @@ func _on_filesystem_changed():
var path = editor_interface.get_resource_filesystem().get_filesystem_path(current_path)
if !path: return
if path.get_file_count() != rows.size():
display_folder(current_path, sorting_by, sorting_reverse, true)
refresh()
else:
for k in remembered_paths:
@ -81,7 +81,7 @@ func _on_filesystem_changed():
var res = remembered_paths[k]
remembered_paths.erase(k)
remembered_paths[res.resource_path] = res
display_folder(current_path, sorting_by, sorting_reverse, true)
refresh()
break
@ -90,7 +90,10 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
$"HeaderContentSplit/MarginContainer/FooterContentSplit/Panel/Label".visible = false
if !folderpath.ends_with("/"):
folderpath += "/"
if search_cond == null:
_on_SearchCond_text_entered("true")
_load_resources_from_folder(folderpath, sort_by, sort_reverse)
if columns.size() == 0: return
@ -100,7 +103,6 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
or current_path != folderpath
or columns.size() != get_node(path_columns).get_child_count()
)
_apply_search_cond()
current_path = folderpath
_update_hidden_columns()
_update_column_sizes()
@ -110,6 +112,10 @@ func display_folder(folderpath : String, sort_by : String = "", sort_reverse : b
display_folder(folderpath, sort_by, sort_reverse, force_rebuild)
func refresh():
display_folder(current_path, sorting_by, sorting_reverse, true)
func _load_resources_from_folder(folderpath : String, sort_by : String, sort_reverse : bool):
var dir := Directory.new()
dir.open(folderpath)
@ -153,11 +159,14 @@ func _load_resources_from_folder(folderpath : String, sort_by : String, sort_rev
func _insert_row_sorted(res : Resource, rows : Array, sort_by : String, sort_reverse : bool):
if !search_cond.can_show(res, rows.size()):
return
for i in rows.size():
if sort_reverse == _compare_values(res.get(sort_by), rows[i].get(sort_by)):
rows.insert(i, res)
return
rows.append(res)
@ -222,7 +231,7 @@ func _update_column_sizes():
if table_root.get_child_count() < column_headers.size(): return
if column_headers.size() != columns.size():
display_folder(current_path, sorting_by, sorting_reverse, true)
refresh()
return
var clip_text : bool = ProjectSettings.get_setting(SettingsGrid.SETTING_PREFIX + "clip_headers")
@ -276,18 +285,6 @@ func _update_row(row_index : int, color_rows : bool = true):
column_editors[i].set_color(current_node, next_color)
func _apply_search_cond():
if search_cond == null:
_on_SearchCond_text_entered("true")
var table_elements = get_node(path_table_root).get_children()
for i in rows.size():
var row_visible = search_cond.can_show(rows[i], i)
for j in columns.size():
table_elements[i * columns.size() + j].visible = row_visible
func _update_hidden_columns():
if !hidden_columns.has(current_path):
hidden_columns[current_path] = {}
@ -357,7 +354,7 @@ func _on_Path_text_entered(new_text : String = ""):
display_folder(new_text, "", false, true)
else:
display_folder(current_path, sorting_by, sorting_reverse, true)
refresh()
func _on_RecentPaths_item_selected(index : int):
@ -747,7 +744,7 @@ func _on_SearchCond_text_entered(new_text : String):
var new_script_instance = new_script.new()
search_cond = new_script_instance
_apply_search_cond()
refresh()
func _on_ProcessExpr_text_entered(new_text : String):

View File

@ -392,13 +392,12 @@ margin_bottom = 21.0
rect_min_size = Vector2( 18, 18 )
hint_tooltip = "Enter an expression. The table only show rows where the expression returns `true`.
You can use `res.<property_name>` to get a property, and `index` to get row number. Hit ENTER to run the search.
You can use `res.<property_name>` to get a property. Hit ENTER to run the search.
Try out these:
- (res.number_property > 0 and res.number_property < 100)
- (res.text_property != \"\")
- (\"a\" in res.text_property)
- (index < 5)"
- (\"a\" in res.text_property)"
mouse_filter = 0
mouse_default_cursor_shape = 16
text = "(?)"
@ -450,6 +449,7 @@ margin_left = 600.0
margin_right = 1018.0
margin_bottom = 24.0
size_flags_horizontal = 3
text = "value"
[node name="Control" type="Control" parent="."]
margin_left = 3.0

View File

@ -5,5 +5,5 @@ description="Edit Many Resources from one Folder as a table.
Heavily inspired by Multi-Cursor-Editing in text editors, so after selecting multiple cells (in the same column!) using Ctrl+Click or Shift+Click, most Basic-to-Intermediate movements should be available."
author="Don Tnowe"
version="1.5.1"
version="1.5.2"
script="plugin.gd"