Merge pull request #31254 from YeldhamDev/text_editor_find_files

Add "Find in Files..." to the text editor
This commit is contained in:
Rémi Verschelde 2019-08-13 08:09:37 +02:00 committed by GitHub
commit 1ccc2af226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

View File

@ -1072,6 +1072,7 @@ void ScriptEditor::_menu_option(int p_option) {
save_all_scripts(); save_all_scripts();
} break; } break;
case SEARCH_IN_FILES: { case SEARCH_IN_FILES: {
_on_find_in_files_requested(""); _on_find_in_files_requested("");
} break; } break;
case SEARCH_HELP: { case SEARCH_HELP: {

View File

@ -1197,7 +1197,6 @@ void ScriptTextEditor::_edit_option(int p_op) {
// Yep, because it doesn't make sense to instance this dialog for every single script open... // Yep, because it doesn't make sense to instance this dialog for every single script open...
// So this will be delegated to the ScriptEditor. // So this will be delegated to the ScriptEditor.
emit_signal("search_in_files_requested", selected_text); emit_signal("search_in_files_requested", selected_text);
} break; } break;
case SEARCH_LOCATE_FUNCTION: { case SEARCH_LOCATE_FUNCTION: {

View File

@ -482,6 +482,14 @@ void TextEditor::_edit_option(int p_op) {
code_editor->get_find_replace_bar()->popup_replace(); code_editor->get_find_replace_bar()->popup_replace();
} break; } break;
case SEARCH_IN_FILES: {
String selected_text = code_editor->get_text_edit()->get_selection_text();
// Yep, because it doesn't make sense to instance this dialog for every single script open...
// So this will be delegated to the ScriptEditor.
emit_signal("search_in_files_requested", selected_text);
} break;
case SEARCH_GOTO_LINE: { case SEARCH_GOTO_LINE: {
goto_line_dialog->popup_find_line(tx); goto_line_dialog->popup_find_line(tx);
@ -558,7 +566,7 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
int to_column = tx->get_selection_to_column(); int to_column = tx->get_selection_to_column();
if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) {
// Right click is outside the selected text // Right click is outside the selected text.
tx->deselect(); tx->deselect();
} }
} }
@ -636,13 +644,15 @@ TextEditor::TextEditor() {
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT);
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV);
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE);
search_menu->get_popup()->add_separator();
search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES);
edit_menu = memnew(MenuButton); edit_menu = memnew(MenuButton);
edit_hb->add_child(edit_menu);
edit_menu->set_text(TTR("Edit")); edit_menu->set_text(TTR("Edit"));
edit_menu->set_switch_on_hover(true); edit_menu->set_switch_on_hover(true);
edit_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_menu->get_popup()->connect("id_pressed", this, "_edit_option");
edit_hb->add_child(edit_menu);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_separator();

View File

@ -87,6 +87,7 @@ private:
SEARCH_FIND_NEXT, SEARCH_FIND_NEXT,
SEARCH_FIND_PREV, SEARCH_FIND_PREV,
SEARCH_REPLACE, SEARCH_REPLACE,
SEARCH_IN_FILES,
SEARCH_GOTO_LINE, SEARCH_GOTO_LINE,
BOOKMARK_TOGGLE, BOOKMARK_TOGGLE,
BOOKMARK_GOTO_NEXT, BOOKMARK_GOTO_NEXT,