|
|
|
@ -39,96 +39,6 @@
|
|
|
|
|
|
|
|
|
|
#define UPPER_BOUND (1 << 15) // for substring search.
|
|
|
|
|
|
|
|
|
|
/* ------- TreeSearchPanel ------- */
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_initialize_controls() {
|
|
|
|
|
line_edit_search = memnew(LineEdit);
|
|
|
|
|
check_button_filter_highlight = memnew(CheckBox);
|
|
|
|
|
close_button = memnew(Button);
|
|
|
|
|
label_filter = memnew(Label);
|
|
|
|
|
|
|
|
|
|
line_edit_search->set_placeholder(TTR("Search tree"));
|
|
|
|
|
|
|
|
|
|
label_filter->set_text(TTR("Filter"));
|
|
|
|
|
|
|
|
|
|
close_button->set_theme_type_variation("FlatButton");
|
|
|
|
|
|
|
|
|
|
// positioning and sizing
|
|
|
|
|
set_anchors_and_offsets_preset(LayoutPreset::PRESET_BOTTOM_WIDE);
|
|
|
|
|
set_v_size_flags(SIZE_SHRINK_CENTER); // Do not expand vertically
|
|
|
|
|
|
|
|
|
|
line_edit_search->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
|
|
|
|
|
_add_spacer(0.25); // otherwise the lineedits expand margin touches the left border.
|
|
|
|
|
add_child(line_edit_search);
|
|
|
|
|
_add_spacer(0.25);
|
|
|
|
|
|
|
|
|
|
add_child(check_button_filter_highlight);
|
|
|
|
|
add_child(label_filter);
|
|
|
|
|
|
|
|
|
|
_add_spacer(0.25);
|
|
|
|
|
add_child(close_button);
|
|
|
|
|
_add_spacer(0.25);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_add_spacer(float p_width_multiplier) {
|
|
|
|
|
Control *spacer = memnew(Control);
|
|
|
|
|
spacer->set_custom_minimum_size(Vector2(8.0 * EDSCALE * p_width_multiplier, 0.0));
|
|
|
|
|
add_child(spacer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_notification(int p_what) {
|
|
|
|
|
switch (p_what) {
|
|
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
|
BUTTON_SET_ICON(close_button, get_theme_icon(LW_NAME(Close), LW_NAME(EditorIcons)));
|
|
|
|
|
|
|
|
|
|
// close callbacks
|
|
|
|
|
close_button->connect("pressed", Callable(this, "set_visible").bind(false));
|
|
|
|
|
close_button->set_shortcut(LW_GET_SHORTCUT("limbo_ai/hide_tree_search"));
|
|
|
|
|
|
|
|
|
|
// search callbacks
|
|
|
|
|
Callable c_update_requested = Callable(this, "emit_signal").bind("update_requested");
|
|
|
|
|
Callable c_text_submitted = Callable((Object *)this, "emit_signal").bind("text_submitted");
|
|
|
|
|
|
|
|
|
|
line_edit_search->connect("text_changed", c_update_requested.unbind(1));
|
|
|
|
|
check_button_filter_highlight->connect("pressed", c_update_requested);
|
|
|
|
|
line_edit_search->connect("text_submitted", c_text_submitted.unbind(1));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_bind_methods() {
|
|
|
|
|
ADD_SIGNAL(MethodInfo("update_requested"));
|
|
|
|
|
ADD_SIGNAL(MethodInfo("text_submitted"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeSearchPanel::TreeSearchPanel() {
|
|
|
|
|
_initialize_controls();
|
|
|
|
|
set_visible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeSearch::TreeSearchMode TreeSearchPanel::get_search_mode() {
|
|
|
|
|
if (!check_button_filter_highlight || !check_button_filter_highlight->is_pressed()) {
|
|
|
|
|
return TreeSearch::TreeSearchMode::HIGHLIGHT;
|
|
|
|
|
}
|
|
|
|
|
return TreeSearch::TreeSearchMode::FILTER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String TreeSearchPanel::get_text() {
|
|
|
|
|
if (!line_edit_search) {
|
|
|
|
|
return String();
|
|
|
|
|
}
|
|
|
|
|
return line_edit_search->get_text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::show_and_focus() {
|
|
|
|
|
set_visible(true);
|
|
|
|
|
line_edit_search->grab_focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* !TreeSearchPanel */
|
|
|
|
|
|
|
|
|
|
/* ------- TreeSearch ------- */
|
|
|
|
|
|
|
|
|
|
void TreeSearch::_filter_tree(const String &p_search_mask) {
|
|
|
|
@ -221,11 +131,11 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Calla
|
|
|
|
|
Vector2 substring_before_size = font->get_string_size(substring_before, HORIZONTAL_ALIGNMENT_LEFT, -1.f, font_size);
|
|
|
|
|
|
|
|
|
|
// stylebox
|
|
|
|
|
Ref<StyleBox> stylebox = p_tree_item->get_tree()->get_theme_stylebox("Focus");
|
|
|
|
|
Ref<StyleBox> stylebox = p_tree_item->get_tree()->get_theme_stylebox(LW_NAME(Focus));
|
|
|
|
|
ERR_FAIL_NULL(stylebox);
|
|
|
|
|
|
|
|
|
|
// extract separation
|
|
|
|
|
float h_sep = p_tree_item->get_tree()->get_theme_constant("h_separation");
|
|
|
|
|
float h_sep = p_tree_item->get_tree()->get_theme_constant(LW_NAME(h_separation));
|
|
|
|
|
|
|
|
|
|
// compose draw rect
|
|
|
|
|
const Vector2 PADDING = Vector2(4., 2.);
|
|
|
|
@ -246,9 +156,9 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Calla
|
|
|
|
|
// second part: draw number
|
|
|
|
|
int num_mat = number_matches.has(p_tree_item) ? number_matches.get(p_tree_item) : 0;
|
|
|
|
|
if (num_mat > 0) {
|
|
|
|
|
float h_sep = p_tree_item->get_tree()->get_theme_constant("h_separation");
|
|
|
|
|
Ref<Font> font = tree_reference->get_theme_font("font");
|
|
|
|
|
float font_size = tree_reference->get_theme_font_size("font") * 0.75;
|
|
|
|
|
float h_sep = p_tree_item->get_tree()->get_theme_constant(LW_NAME(h_separation));
|
|
|
|
|
Ref<Font> font = tree_reference->get_theme_font(LW_NAME(font));
|
|
|
|
|
float font_size = tree_reference->get_theme_font_size(LW_NAME(font)) * 0.75;
|
|
|
|
|
|
|
|
|
|
String num_string = String::num_int64(num_mat);
|
|
|
|
|
Vector2 string_size = font->get_string_size(num_string, HORIZONTAL_ALIGNMENT_CENTER, -1, font_size);
|
|
|
|
@ -263,7 +173,8 @@ void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Calla
|
|
|
|
|
|
|
|
|
|
void TreeSearch::_update_matching_entries(const String &p_search_mask) {
|
|
|
|
|
Vector<TreeItem *> accum;
|
|
|
|
|
matching_entries = _find_matching_entries(tree_reference->get_root(), p_search_mask, accum);
|
|
|
|
|
_find_matching_entries(tree_reference->get_root(), p_search_mask, accum);
|
|
|
|
|
matching_entries = accum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this linearizes the tree into [ordered_tree_items] like so:
|
|
|
|
@ -294,8 +205,8 @@ void TreeSearch::_update_number_matches() {
|
|
|
|
|
for (int i = 0; i < matching_entries.size(); i++) {
|
|
|
|
|
TreeItem *item = matching_entries[i];
|
|
|
|
|
while (item) {
|
|
|
|
|
int old_num_value = number_matches.has(item) ? number_matches.get(item) : 0;
|
|
|
|
|
number_matches[item] = old_num_value + 1;
|
|
|
|
|
int previous_match_cnt = number_matches.has(item) ? number_matches.get(item) : 0;
|
|
|
|
|
number_matches[item] = previous_match_cnt + 1;
|
|
|
|
|
item = item->get_parent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -306,13 +217,14 @@ String TreeSearch::_get_search_mask() {
|
|
|
|
|
return search_panel->get_text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector<TreeItem *> TreeSearch::_find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum) {
|
|
|
|
|
if (!p_tree_item)
|
|
|
|
|
return p_accum;
|
|
|
|
|
void TreeSearch::_find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum) {
|
|
|
|
|
if (!p_tree_item) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
StringSearchIndices item_search_indices = _substring_bounds(p_tree_item->get_text(0), p_search_mask);
|
|
|
|
|
if (item_search_indices.hit())
|
|
|
|
|
if (item_search_indices.hit()) {
|
|
|
|
|
p_accum.push_back(p_tree_item);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < p_tree_item->get_child_count(); i++) {
|
|
|
|
|
TreeItem *child = p_tree_item->get_child(i);
|
|
|
|
|
_find_matching_entries(child, p_search_mask, p_accum);
|
|
|
|
@ -323,7 +235,7 @@ Vector<TreeItem *> TreeSearch::_find_matching_entries(TreeItem *p_tree_item, con
|
|
|
|
|
p_accum.sort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p_accum;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the lower and upper bounds of a substring. Does fuzzy search: Simply looks if words exist in right ordering.
|
|
|
|
@ -341,8 +253,10 @@ TreeSearch::StringSearchIndices TreeSearch::_substring_bounds(const String &p_se
|
|
|
|
|
// Determine if the search should be case-insensitive.
|
|
|
|
|
bool is_case_insensitive = (p_search_mask == p_search_mask.to_lower());
|
|
|
|
|
String searchable_processed = is_case_insensitive ? p_searchable.to_lower() : p_searchable;
|
|
|
|
|
|
|
|
|
|
PackedStringArray words = p_search_mask.split(" ");
|
|
|
|
|
int word_position = 0;
|
|
|
|
|
|
|
|
|
|
for (const String &word : words) {
|
|
|
|
|
if (word.is_empty()) {
|
|
|
|
|
continue; // Skip empty words.
|
|
|
|
@ -394,7 +308,6 @@ void TreeSearch::_select_first_match() {
|
|
|
|
|
if (!_vector_has_bsearch(matching_entries, item)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String debug_string = "[";
|
|
|
|
|
_select_item(item);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -419,14 +332,12 @@ void TreeSearch::_select_next_match() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// find the best fitting entry.
|
|
|
|
|
for (int i = 0; i < ordered_tree_items.size(); i++) {
|
|
|
|
|
for (int i = MAX(0, selected_idx) + 1; i < ordered_tree_items.size(); i++) {
|
|
|
|
|
TreeItem *item = ordered_tree_items[i];
|
|
|
|
|
if (!_vector_has_bsearch(matching_entries, item) || selected_idx >= i) {
|
|
|
|
|
continue;
|
|
|
|
|
if (_vector_has_bsearch(matching_entries, item)) {
|
|
|
|
|
_select_item(item);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_select_item(item);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_select_first_match(); // wrap around.
|
|
|
|
|
}
|
|
|
|
@ -470,9 +381,6 @@ void TreeSearch::update_search(Tree *p_tree) {
|
|
|
|
|
_update_number_matches();
|
|
|
|
|
|
|
|
|
|
_highlight_tree(search_mask);
|
|
|
|
|
if (!search_panel->is_connected("text_submitted", callable_mp(this, &TreeSearch::_select_next_match))) {
|
|
|
|
|
search_panel->connect("text_submitted", callable_mp(this, &TreeSearch::_select_next_match));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (search_mode == TreeSearchMode::FILTER) {
|
|
|
|
|
_filter_tree(search_mask);
|
|
|
|
@ -481,8 +389,100 @@ void TreeSearch::update_search(Tree *p_tree) {
|
|
|
|
|
|
|
|
|
|
TreeSearch::TreeSearch(TreeSearchPanel *p_search_panel) {
|
|
|
|
|
search_panel = p_search_panel;
|
|
|
|
|
search_panel->connect("text_submitted", callable_mp(this, &TreeSearch::_select_next_match));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* !TreeSearch */
|
|
|
|
|
|
|
|
|
|
/* ------- TreeSearchPanel ------- */
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_initialize_controls() {
|
|
|
|
|
line_edit_search = memnew(LineEdit);
|
|
|
|
|
check_button_filter_highlight = memnew(CheckBox);
|
|
|
|
|
close_button = memnew(Button);
|
|
|
|
|
label_filter = memnew(Label);
|
|
|
|
|
|
|
|
|
|
line_edit_search->set_placeholder(TTR("Search tree"));
|
|
|
|
|
|
|
|
|
|
close_button->set_theme_type_variation(LW_NAME(FlatButton));
|
|
|
|
|
|
|
|
|
|
// positioning and sizing
|
|
|
|
|
set_anchors_and_offsets_preset(LayoutPreset::PRESET_BOTTOM_WIDE);
|
|
|
|
|
set_v_size_flags(SIZE_SHRINK_CENTER); // Do not expand vertically
|
|
|
|
|
|
|
|
|
|
line_edit_search->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
|
|
|
|
|
_add_spacer(0.25); // otherwise the lineedits expand margin touches the left border.
|
|
|
|
|
add_child(line_edit_search);
|
|
|
|
|
_add_spacer(0.25);
|
|
|
|
|
|
|
|
|
|
add_child(check_button_filter_highlight);
|
|
|
|
|
add_child(label_filter);
|
|
|
|
|
|
|
|
|
|
_add_spacer(0.25);
|
|
|
|
|
add_child(close_button);
|
|
|
|
|
_add_spacer(0.25);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_add_spacer(float p_width_multiplier) {
|
|
|
|
|
Control *spacer = memnew(Control);
|
|
|
|
|
spacer->set_custom_minimum_size(Vector2(8.0 * EDSCALE * p_width_multiplier, 0.0));
|
|
|
|
|
add_child(spacer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_notification(int p_what) {
|
|
|
|
|
switch (p_what) {
|
|
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
|
// close callbacks
|
|
|
|
|
close_button->connect("pressed", Callable(this, "set_visible").bind(false));
|
|
|
|
|
close_button->set_shortcut(LW_GET_SHORTCUT("limbo_ai/hide_tree_search"));
|
|
|
|
|
|
|
|
|
|
// search callbacks
|
|
|
|
|
Callable c_update_requested = Callable(this, "emit_signal").bind("update_requested");
|
|
|
|
|
Callable c_text_submitted = Callable((Object *)this, "emit_signal").bind("text_submitted");
|
|
|
|
|
|
|
|
|
|
line_edit_search->connect("text_changed", c_update_requested.unbind(1));
|
|
|
|
|
check_button_filter_highlight->connect("pressed", c_update_requested);
|
|
|
|
|
line_edit_search->connect("text_submitted", c_text_submitted.unbind(1));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
|
|
|
|
BUTTON_SET_ICON(close_button, get_theme_icon(LW_NAME(Close), LW_NAME(EditorIcons)));
|
|
|
|
|
label_filter->set_text(TTR("Filter"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::_bind_methods() {
|
|
|
|
|
ADD_SIGNAL(MethodInfo("update_requested"));
|
|
|
|
|
ADD_SIGNAL(MethodInfo("text_submitted"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeSearchPanel::TreeSearchPanel() {
|
|
|
|
|
_initialize_controls();
|
|
|
|
|
set_visible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeSearch::TreeSearchMode TreeSearchPanel::get_search_mode() {
|
|
|
|
|
if (!check_button_filter_highlight || !check_button_filter_highlight->is_pressed()) {
|
|
|
|
|
return TreeSearch::TreeSearchMode::HIGHLIGHT;
|
|
|
|
|
}
|
|
|
|
|
return TreeSearch::TreeSearchMode::FILTER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String TreeSearchPanel::get_text() {
|
|
|
|
|
if (!line_edit_search) {
|
|
|
|
|
return String();
|
|
|
|
|
}
|
|
|
|
|
return line_edit_search->get_text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TreeSearchPanel::show_and_focus() {
|
|
|
|
|
set_visible(true);
|
|
|
|
|
line_edit_search->grab_focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* !TreeSearchPanel */
|
|
|
|
|
|
|
|
|
|
#endif // TOOLS_ENABLED
|