Merge pull request #49265 from KoBeWi/keepfreplace_2_keepers_of_replace
Move FindReplaceBar out of CodeTextEditor
This commit is contained in:
commit
58c1235111
10 changed files with 74 additions and 15 deletions
|
@ -583,15 +583,29 @@ void FindReplaceBar::set_error(const String &p_label) {
|
|||
emit_signal("error", p_label);
|
||||
}
|
||||
|
||||
void FindReplaceBar::set_text_edit(CodeEdit *p_text_edit) {
|
||||
void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) {
|
||||
if (p_text_editor == base_text_editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (base_text_editor) {
|
||||
base_text_editor->remove_find_replace_bar();
|
||||
base_text_editor = nullptr;
|
||||
text_editor->disconnect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
|
||||
text_editor = nullptr;
|
||||
}
|
||||
|
||||
results_count = -1;
|
||||
text_editor = p_text_edit;
|
||||
base_text_editor = p_text_editor;
|
||||
text_editor = base_text_editor->get_text_editor();
|
||||
text_editor->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed));
|
||||
|
||||
_update_results_count();
|
||||
_update_matches_label();
|
||||
}
|
||||
|
||||
void FindReplaceBar::_bind_methods() {
|
||||
ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input);
|
||||
|
||||
ClassDB::bind_method("_search_current", &FindReplaceBar::search_current);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("search"));
|
||||
|
@ -939,6 +953,25 @@ void CodeTextEditor::update_editor_settings() {
|
|||
text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
|
||||
}
|
||||
|
||||
void CodeTextEditor::set_find_replace_bar(FindReplaceBar *p_bar) {
|
||||
if (find_replace_bar) {
|
||||
return;
|
||||
}
|
||||
|
||||
find_replace_bar = p_bar;
|
||||
find_replace_bar->set_text_edit(this);
|
||||
find_replace_bar->connect("error", callable_mp(error, &Label::set_text));
|
||||
}
|
||||
|
||||
void CodeTextEditor::remove_find_replace_bar() {
|
||||
if (!find_replace_bar) {
|
||||
return;
|
||||
}
|
||||
|
||||
find_replace_bar->disconnect("error", callable_mp(error, &Label::set_text));
|
||||
find_replace_bar = nullptr;
|
||||
}
|
||||
|
||||
void CodeTextEditor::trim_trailing_whitespace() {
|
||||
bool trimed_whitespace = false;
|
||||
for (int i = 0; i < text_editor->get_line_count(); i++) {
|
||||
|
@ -1760,14 +1793,6 @@ CodeTextEditor::CodeTextEditor() {
|
|||
} break;
|
||||
}
|
||||
|
||||
// Added second so it opens at the bottom, so it won't shift the entire text editor when opening.
|
||||
find_replace_bar = memnew(FindReplaceBar);
|
||||
add_child(find_replace_bar);
|
||||
find_replace_bar->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
find_replace_bar->hide();
|
||||
|
||||
find_replace_bar->set_text_edit(text_editor);
|
||||
|
||||
text_editor->set_draw_line_numbers(true);
|
||||
text_editor->set_brace_matching(true);
|
||||
text_editor->set_auto_indent(true);
|
||||
|
@ -1808,7 +1833,6 @@ CodeTextEditor::CodeTextEditor() {
|
|||
error->set_v_size_flags(SIZE_EXPAND | SIZE_SHRINK_CENTER);
|
||||
error->set_mouse_filter(MOUSE_FILTER_STOP);
|
||||
error->connect("gui_input", callable_mp(this, &CodeTextEditor::_error_pressed));
|
||||
find_replace_bar->connect("error", callable_mp(error, &Label::set_text));
|
||||
|
||||
// Warnings
|
||||
warning_button = memnew(Button);
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
GotoLineDialog();
|
||||
};
|
||||
|
||||
class CodeTextEditor;
|
||||
|
||||
class FindReplaceBar : public HBoxContainer {
|
||||
GDCLASS(FindReplaceBar, HBoxContainer);
|
||||
|
||||
|
@ -77,6 +79,7 @@ class FindReplaceBar : public HBoxContainer {
|
|||
HBoxContainer *hbc_button_replace;
|
||||
HBoxContainer *hbc_option_replace;
|
||||
|
||||
CodeTextEditor *base_text_editor = nullptr;
|
||||
CodeEdit *text_editor;
|
||||
|
||||
int result_line;
|
||||
|
@ -120,7 +123,7 @@ public:
|
|||
bool is_selection_only() const;
|
||||
void set_error(const String &p_label);
|
||||
|
||||
void set_text_edit(CodeEdit *p_text_edit);
|
||||
void set_text_edit(CodeTextEditor *p_text_editor);
|
||||
|
||||
void popup_search(bool p_show_only = false);
|
||||
void popup_replace();
|
||||
|
@ -138,7 +141,7 @@ class CodeTextEditor : public VBoxContainer {
|
|||
GDCLASS(CodeTextEditor, VBoxContainer);
|
||||
|
||||
CodeEdit *text_editor;
|
||||
FindReplaceBar *find_replace_bar;
|
||||
FindReplaceBar *find_replace_bar = nullptr;
|
||||
HBoxContainer *status_bar;
|
||||
|
||||
Button *toggle_scripts_button;
|
||||
|
@ -243,6 +246,8 @@ public:
|
|||
void update_line_and_column() { _line_col_changed(); }
|
||||
CodeEdit *get_text_editor() { return text_editor; }
|
||||
FindReplaceBar *get_find_replace_bar() { return find_replace_bar; }
|
||||
void set_find_replace_bar(FindReplaceBar *p_bar);
|
||||
void remove_find_replace_bar();
|
||||
virtual void apply_code() {}
|
||||
void goto_error();
|
||||
|
||||
|
|
|
@ -1640,10 +1640,13 @@ void ScriptEditor::ensure_select_current() {
|
|||
ScriptEditorBase *se = _get_current_editor();
|
||||
if (se) {
|
||||
se->enable_editor();
|
||||
se->set_find_replace_bar(find_replace_bar);
|
||||
|
||||
if (!grab_focus_block && is_visible_in_tree()) {
|
||||
se->ensure_focus();
|
||||
}
|
||||
} else {
|
||||
find_replace_bar->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3379,11 +3382,19 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
|
|||
help_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing
|
||||
help_overview->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
VBoxContainer *code_editor_container = memnew(VBoxContainer);
|
||||
script_split->add_child(code_editor_container);
|
||||
|
||||
tab_container = memnew(TabContainer);
|
||||
tab_container->set_tabs_visible(false);
|
||||
tab_container->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
|
||||
script_split->add_child(tab_container);
|
||||
code_editor_container->add_child(tab_container);
|
||||
tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
tab_container->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
find_replace_bar = memnew(FindReplaceBar);
|
||||
code_editor_container->add_child(find_replace_bar);
|
||||
find_replace_bar->hide();
|
||||
|
||||
ED_SHORTCUT("script_editor/window_sort", TTR("Sort"));
|
||||
ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP);
|
||||
|
|
|
@ -162,6 +162,7 @@ public:
|
|||
virtual void set_tooltip_request_func(String p_method, Object *p_obj) = 0;
|
||||
virtual Control *get_edit_menu() = 0;
|
||||
virtual void clear_edit_menu() = 0;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) = 0;
|
||||
|
||||
virtual Control *get_base_editor() const = 0;
|
||||
|
||||
|
@ -270,6 +271,7 @@ class ScriptEditor : public PanelContainer {
|
|||
ConfirmationDialog *erase_tab_confirm;
|
||||
ScriptCreateDialog *script_create_dialog;
|
||||
Button *scripts_visible;
|
||||
FindReplaceBar *find_replace_bar;
|
||||
|
||||
String current_theme;
|
||||
|
||||
|
|
|
@ -1358,6 +1358,10 @@ void ScriptTextEditor::clear_edit_menu() {
|
|||
memdelete(edit_hb);
|
||||
}
|
||||
|
||||
void ScriptTextEditor::set_find_replace_bar(FindReplaceBar *p_bar) {
|
||||
code_editor->set_find_replace_bar(p_bar);
|
||||
}
|
||||
|
||||
void ScriptTextEditor::reload(bool p_soft) {
|
||||
CodeEdit *te = code_editor->get_text_editor();
|
||||
Ref<Script> scr = script;
|
||||
|
|
|
@ -233,6 +233,8 @@ public:
|
|||
|
||||
Control *get_edit_menu() override;
|
||||
virtual void clear_edit_menu() override;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
|
||||
|
||||
static void register_editor();
|
||||
|
||||
virtual Control *get_base_editor() const override;
|
||||
|
|
|
@ -751,6 +751,11 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) {
|
|||
editor_box->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
editor_box->add_child(shader_editor);
|
||||
|
||||
FindReplaceBar *bar = memnew(FindReplaceBar);
|
||||
main_container->add_child(bar);
|
||||
bar->hide();
|
||||
shader_editor->set_find_replace_bar(bar);
|
||||
|
||||
warnings_panel = memnew(RichTextLabel);
|
||||
warnings_panel->set_custom_minimum_size(Size2(0, 100 * EDSCALE));
|
||||
warnings_panel->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
|
|
|
@ -281,6 +281,10 @@ void TextEditor::clear_edit_menu() {
|
|||
memdelete(edit_hb);
|
||||
}
|
||||
|
||||
void TextEditor::set_find_replace_bar(FindReplaceBar *p_bar) {
|
||||
code_editor->set_find_replace_bar(p_bar);
|
||||
}
|
||||
|
||||
void TextEditor::_edit_option(int p_op) {
|
||||
CodeEdit *tx = code_editor->get_text_editor();
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ public:
|
|||
|
||||
virtual Control *get_edit_menu() override;
|
||||
virtual void clear_edit_menu() override;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override;
|
||||
|
||||
virtual void validate() override;
|
||||
|
||||
|
|
|
@ -317,6 +317,7 @@ public:
|
|||
virtual void set_tooltip_request_func(String p_method, Object *p_obj) override;
|
||||
virtual Control *get_edit_menu() override;
|
||||
virtual void clear_edit_menu() override;
|
||||
virtual void set_find_replace_bar(FindReplaceBar *p_bar) override { p_bar->hide(); }; // Not needed here.
|
||||
virtual bool can_lose_focus_on_node_selection() override { return false; }
|
||||
virtual void validate() override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue