Skip to content

Commit 2012381

Browse files
committed
Some QOL and cleanup to EditorHelp's FindBar
1 parent 32eafc1 commit 2012381

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

editor/code_editor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ FindReplaceBar::FindReplaceBar() {
797797

798798
find_prev = memnew(Button);
799799
find_prev->set_flat(true);
800+
find_prev->set_disabled(results_count < 1);
800801
find_prev->set_tooltip_text(TTR("Previous Match"));
801802
find_prev->set_accessibility_name(TTRC("Previous Match"));
802803
hbc_button_search->add_child(find_prev);
@@ -805,6 +806,7 @@ FindReplaceBar::FindReplaceBar() {
805806

806807
find_next = memnew(Button);
807808
find_next->set_flat(true);
809+
find_next->set_disabled(results_count < 1);
808810
find_next->set_tooltip_text(TTR("Next Match"));
809811
find_next->set_accessibility_name(TTRC("Next Match"));
810812
hbc_button_search->add_child(find_next);

editor/editor_help.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4758,44 +4758,47 @@ EditorHelpHighlighter::~EditorHelpHighlighter() {
47584758

47594759
FindBar::FindBar() {
47604760
search_text = memnew(LineEdit);
4761-
search_text->set_accessibility_name(TTRC("Search help"));
4762-
add_child(search_text);
47634761
search_text->set_keep_editing_on_text_submit(true);
4762+
add_child(search_text);
4763+
search_text->set_placeholder(TTR("Search"));
4764+
search_text->set_tooltip_text(TTR("Search"));
4765+
search_text->set_accessibility_name(TTRC("Search Documentation"));
47644766
search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
47654767
search_text->set_h_size_flags(SIZE_EXPAND_FILL);
47664768
search_text->connect(SceneStringName(text_changed), callable_mp(this, &FindBar::_search_text_changed));
47674769
search_text->connect(SceneStringName(text_submitted), callable_mp(this, &FindBar::_search_text_submitted));
47684770

47694771
matches_label = memnew(Label);
4770-
matches_label->set_focus_mode(FOCUS_ACCESSIBILITY);
47714772
add_child(matches_label);
4773+
matches_label->set_focus_mode(FOCUS_ACCESSIBILITY);
47724774
matches_label->hide();
47734775

47744776
find_prev = memnew(Button);
4775-
find_prev->set_accessibility_name(TTRC("Find Previous"));
47764777
find_prev->set_flat(true);
4778+
find_prev->set_disabled(results_count < 1);
4779+
find_prev->set_tooltip_text(TTR("Previous Match"));
4780+
find_prev->set_accessibility_name(TTRC("Previous Match"));
47774781
add_child(find_prev);
47784782
find_prev->set_focus_mode(FOCUS_NONE);
47794783
find_prev->connect(SceneStringName(pressed), callable_mp(this, &FindBar::search_prev));
47804784

47814785
find_next = memnew(Button);
4782-
find_next->set_accessibility_name(TTRC("Find Next"));
47834786
find_next->set_flat(true);
4787+
find_next->set_disabled(results_count < 1);
4788+
find_next->set_tooltip_text(TTR("Next Match"));
4789+
find_next->set_accessibility_name(TTRC("Next Match"));
47844790
add_child(find_next);
47854791
find_next->set_focus_mode(FOCUS_NONE);
47864792
find_next->connect(SceneStringName(pressed), callable_mp(this, &FindBar::search_next));
47874793

4788-
Control *space = memnew(Control);
4789-
add_child(space);
4790-
space->set_custom_minimum_size(Size2(4, 0) * EDSCALE);
4791-
4792-
hide_button = memnew(TextureButton);
4793-
add_child(hide_button);
4794+
hide_button = memnew(Button);
4795+
hide_button->set_flat(true);
4796+
hide_button->set_tooltip_text(TTR("Hide"));
47944797
hide_button->set_accessibility_name(TTRC("Hide"));
47954798
hide_button->set_focus_mode(FOCUS_NONE);
4796-
hide_button->set_ignore_texture_size(true);
4797-
hide_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED);
47984799
hide_button->connect(SceneStringName(pressed), callable_mp(this, &FindBar::_hide_bar));
4800+
hide_button->set_v_size_flags(SIZE_SHRINK_CENTER);
4801+
add_child(hide_button);
47994802
}
48004803

48014804
void FindBar::popup_search() {
@@ -4820,10 +4823,7 @@ void FindBar::_notification(int p_what) {
48204823
case NOTIFICATION_THEME_CHANGED: {
48214824
find_prev->set_button_icon(get_editor_theme_icon(SNAME("MoveUp")));
48224825
find_next->set_button_icon(get_editor_theme_icon(SNAME("MoveDown")));
4823-
hide_button->set_texture_normal(get_editor_theme_icon(SNAME("Close")));
4824-
hide_button->set_texture_hover(get_editor_theme_icon(SNAME("Close")));
4825-
hide_button->set_texture_pressed(get_editor_theme_icon(SNAME("Close")));
4826-
hide_button->set_custom_minimum_size(hide_button->get_texture_normal()->get_size());
4826+
hide_button->set_button_icon(get_editor_theme_icon(SNAME("Close")));
48274827
matches_label->add_theme_color_override(SceneStringName(font_color), results_count > 0 ? get_theme_color(SceneStringName(font_color), SNAME("Label")) : get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
48284828
} break;
48294829

@@ -4848,22 +4848,25 @@ bool FindBar::search_prev() {
48484848
bool FindBar::_search(bool p_search_previous) {
48494849
String stext = search_text->get_text();
48504850
bool keep = prev_search == stext;
4851-
48524851
bool ret = rich_text_label->search(stext, keep, p_search_previous);
48534852

48544853
prev_search = stext;
4854+
if (!keep) {
4855+
results_count_to_current = 0;
4856+
}
48554857

48564858
if (ret) {
4857-
_update_results_count();
4859+
_update_results_count(p_search_previous);
48584860
} else {
48594861
results_count = 0;
4862+
results_count_to_current = 0;
48604863
}
48614864
_update_matches_label();
48624865

48634866
return ret;
48644867
}
48654868

4866-
void FindBar::_update_results_count() {
4869+
void FindBar::_update_results_count(bool p_search_previous) {
48674870
results_count = 0;
48684871

48694872
String searched = search_text->get_text();
@@ -4884,6 +4887,13 @@ void FindBar::_update_results_count() {
48844887
results_count++;
48854888
from_pos = pos + searched.length();
48864889
}
4890+
4891+
results_count_to_current += (p_search_previous) ? -1 : 1;
4892+
if (results_count_to_current > results_count) {
4893+
results_count_to_current = results_count_to_current - results_count;
4894+
} else if (results_count_to_current <= 0) {
4895+
results_count_to_current = results_count;
4896+
}
48874897
}
48884898

48894899
void FindBar::_update_matches_label() {
@@ -4893,8 +4903,16 @@ void FindBar::_update_matches_label() {
48934903
matches_label->show();
48944904

48954905
matches_label->add_theme_color_override(SceneStringName(font_color), results_count > 0 ? get_theme_color(SceneStringName(font_color), SNAME("Label")) : get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
4896-
matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count));
4906+
if (results_count == 0) {
4907+
matches_label->set_text(TTR("No match"));
4908+
} else if (results_count_to_current == 0) {
4909+
matches_label->set_text(vformat(TTRN("%d match", "%d matches", results_count), results_count));
4910+
} else {
4911+
matches_label->set_text(vformat(TTRN("%d of %d match", "%d of %d matches", results_count), results_count_to_current, results_count));
4912+
}
48974913
}
4914+
find_prev->set_disabled(results_count < 1);
4915+
find_next->set_disabled(results_count < 1);
48984916
}
48994917

49004918
void FindBar::_hide_bar() {

editor/editor_help.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ class FindBar : public HBoxContainer {
4747
Button *find_prev = nullptr;
4848
Button *find_next = nullptr;
4949
Label *matches_label = nullptr;
50-
TextureButton *hide_button = nullptr;
51-
String prev_search;
50+
Button *hide_button = nullptr;
5251

5352
RichTextLabel *rich_text_label = nullptr;
5453

54+
String prev_search;
5555
int results_count = 0;
56+
int results_count_to_current = 0;
5657

5758
virtual void input(const Ref<InputEvent> &p_event) override;
5859

@@ -61,7 +62,7 @@ class FindBar : public HBoxContainer {
6162
void _search_text_changed(const String &p_text);
6263
void _search_text_submitted(const String &p_text);
6364

64-
void _update_results_count();
65+
void _update_results_count(bool p_search_previous);
6566
void _update_matches_label();
6667

6768
protected:

0 commit comments

Comments
 (0)