Skip to content

Commit

Permalink
Merge pull request #88465 from AeioMuch/search_results_button
Browse files Browse the repository at this point in the history
[Editor] Hide Search Results by default and show it on first search.
  • Loading branch information
akien-mga committed Mar 25, 2024
2 parents 0e36df6 + 5cf6f3c commit c4aa107
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
12 changes: 12 additions & 0 deletions editor/find_in_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ void FindInFilesDialog::_bind_methods() {
//-----------------------------------------------------------------------------
const char *FindInFilesPanel::SIGNAL_RESULT_SELECTED = "result_selected";
const char *FindInFilesPanel::SIGNAL_FILES_MODIFIED = "files_modified";
const char *FindInFilesPanel::SIGNAL_CLOSE_BUTTON_CLICKED = "close_button_clicked";

FindInFilesPanel::FindInFilesPanel() {
_finder = memnew(FindInFiles);
Expand Down Expand Up @@ -611,6 +612,11 @@ FindInFilesPanel::FindInFilesPanel() {
_cancel_button->hide();
hbc->add_child(_cancel_button);

_close_button = memnew(Button);
_close_button->set_text(TTR("Close"));
_close_button->connect("pressed", callable_mp(this, &FindInFilesPanel::_on_close_button_clicked));
hbc->add_child(_close_button);

vbc->add_child(hbc);
}

Expand Down Expand Up @@ -843,6 +849,10 @@ void FindInFilesPanel::_on_cancel_button_clicked() {
stop_search();
}

void FindInFilesPanel::_on_close_button_clicked() {
emit_signal(SNAME(SIGNAL_CLOSE_BUTTON_CLICKED));
}

void FindInFilesPanel::_on_result_selected() {
TreeItem *item = _results_display->get_selected();
HashMap<TreeItem *, Result>::Iterator E = _result_items.find(item);
Expand Down Expand Up @@ -1010,4 +1020,6 @@ void FindInFilesPanel::_bind_methods() {
PropertyInfo(Variant::INT, "end")));

ADD_SIGNAL(MethodInfo(SIGNAL_FILES_MODIFIED, PropertyInfo(Variant::STRING, "paths")));

ADD_SIGNAL(MethodInfo(SIGNAL_CLOSE_BUTTON_CLICKED));
}
3 changes: 3 additions & 0 deletions editor/find_in_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class FindInFilesPanel : public Control {
public:
static const char *SIGNAL_RESULT_SELECTED;
static const char *SIGNAL_FILES_MODIFIED;
static const char *SIGNAL_CLOSE_BUTTON_CLICKED;

FindInFilesPanel();

Expand All @@ -180,6 +181,7 @@ class FindInFilesPanel : public Control {
void _on_finished();
void _on_refresh_button_clicked();
void _on_cancel_button_clicked();
void _on_close_button_clicked();
void _on_result_selected();
void _on_item_edited();
void _on_replace_text_changed(const String &text);
Expand Down Expand Up @@ -207,6 +209,7 @@ class FindInFilesPanel : public Control {
Label *_status_label = nullptr;
Button *_refresh_button = nullptr;
Button *_cancel_button = nullptr;
Button *_close_button = nullptr;
ProgressBar *_progress_bar = nullptr;
HashMap<String, TreeItem *> _file_items;
HashMap<TreeItem *, Result> _result_items;
Expand Down
27 changes: 15 additions & 12 deletions editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,18 +1716,6 @@ void ScriptEditor::_notification(int p_what) {
_test_script_times_on_disk();
_update_modified_scripts_for_external_editor();
} break;

case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
find_in_files_button->show();
} else {
if (find_in_files->is_visible_in_tree()) {
EditorNode::get_bottom_panel()->hide_bottom_panel();
}
find_in_files_button->hide();
}

} break;
}
}

Expand Down Expand Up @@ -3776,6 +3764,7 @@ void ScriptEditor::_on_find_in_files_result_selected(const String &fpath, int li
ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor());

if (ste) {
EditorInterface::get_singleton()->set_main_screen_editor("Script");
ste->goto_line_selection(line_number, begin, end);
}
}
Expand All @@ -3790,6 +3779,7 @@ void ScriptEditor::_on_find_in_files_result_selected(const String &fpath, int li

ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor());
if (ste) {
EditorInterface::get_singleton()->set_main_screen_editor("Script");
ste->goto_line_selection(line_number - 1, begin, end);
}
return;
Expand Down Expand Up @@ -3823,6 +3813,13 @@ void ScriptEditor::_start_find_in_files(bool with_replace) {
find_in_files->set_replace_text(find_in_files_dialog->get_replace_text());
find_in_files->start_search();

if (find_in_files_button->get_index() != find_in_files_button->get_parent()->get_child_count()) {
find_in_files_button->get_parent()->move_child(find_in_files_button, -1);
}
if (!find_in_files_button->is_visible()) {
find_in_files_button->show();
}

EditorNode::get_bottom_panel()->make_item_visible(find_in_files);
}

Expand All @@ -3849,6 +3846,11 @@ void ScriptEditor::_set_zoom_factor(float p_zoom_factor) {
}
}

void ScriptEditor::_on_find_in_files_close_button_clicked() {
EditorNode::get_bottom_panel()->hide_bottom_panel();
find_in_files_button->hide();
}

void ScriptEditor::_window_changed(bool p_visible) {
make_floating->set_visible(!p_visible);
is_floating = p_visible;
Expand Down Expand Up @@ -4203,6 +4205,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
find_in_files->set_custom_minimum_size(Size2(0, 200) * EDSCALE);
find_in_files->connect(FindInFilesPanel::SIGNAL_RESULT_SELECTED, callable_mp(this, &ScriptEditor::_on_find_in_files_result_selected));
find_in_files->connect(FindInFilesPanel::SIGNAL_FILES_MODIFIED, callable_mp(this, &ScriptEditor::_on_find_in_files_modified_files));
find_in_files->connect(FindInFilesPanel::SIGNAL_CLOSE_BUTTON_CLICKED, callable_mp(this, &ScriptEditor::_on_find_in_files_close_button_clicked));
find_in_files->hide();
find_in_files_button->hide();

Expand Down
1 change: 1 addition & 0 deletions editor/plugins/script_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class ScriptEditor : public PanelContainer {
void _on_find_in_files_result_selected(const String &fpath, int line_number, int begin, int end);
void _start_find_in_files(bool with_replace);
void _on_find_in_files_modified_files(const PackedStringArray &paths);
void _on_find_in_files_close_button_clicked();

void _set_zoom_factor(float p_zoom_factor);

Expand Down

0 comments on commit c4aa107

Please sign in to comment.