From 1b0c1c14f0f527184eab16b5063a59af2a58e247 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 18 Feb 2023 13:59:28 +0100 Subject: [PATCH] Moved GotoLineDialog to it's own file. --- .../shader_editor/shader_editor_plugin.cpp | 2 + modules/code_editor/SCsub | 1 + modules/code_editor/code_editor.cpp | 45 +--------- modules/code_editor/code_editor.h | 18 +--- modules/code_editor/goto_line_dialog.cpp | 82 +++++++++++++++++++ modules/code_editor/goto_line_dialog.h | 57 +++++++++++++ modules/code_editor/script_text_editor.cpp | 1 + modules/code_editor/text_editor.cpp | 1 + 8 files changed, 146 insertions(+), 61 deletions(-) create mode 100644 modules/code_editor/goto_line_dialog.cpp create mode 100644 modules/code_editor/goto_line_dialog.h diff --git a/editor_modules/shader_editor/shader_editor_plugin.cpp b/editor_modules/shader_editor/shader_editor_plugin.cpp index 049201aaa..c02a46a8d 100644 --- a/editor_modules/shader_editor/shader_editor_plugin.cpp +++ b/editor_modules/shader_editor/shader_editor_plugin.cpp @@ -65,6 +65,8 @@ #include "servers/rendering/shader_types.h" #include "servers/rendering_server.h" +#include "modules/code_editor/goto_line_dialog.h" + struct ScriptCodeCompletionOption; /*** SHADER SCRIPT EDITOR ****/ diff --git a/modules/code_editor/SCsub b/modules/code_editor/SCsub index be27388f6..de2d1be0d 100644 --- a/modules/code_editor/SCsub +++ b/modules/code_editor/SCsub @@ -14,6 +14,7 @@ sources = [ "script_editor_base.cpp", "script_editor.cpp", "connection_info_dialog.cpp", + "goto_line_dialog.cpp", ] env_mlp.add_source_files(env.modules_sources, sources) diff --git a/modules/code_editor/code_editor.cpp b/modules/code_editor/code_editor.cpp index 1a32b2de3..c7c5b7d2f 100644 --- a/modules/code_editor/code_editor.cpp +++ b/modules/code_editor/code_editor.cpp @@ -65,52 +65,9 @@ #include "scene/resources/font.h" #include "scene/resources/texture.h" +#include "goto_line_dialog.h" #include "script_editor.h" -void GotoLineDialog::popup_find_line(TextEdit *p_edit) { - text_editor = p_edit; - - line->set_text(itos(text_editor->cursor_get_line())); - line->select_all(); - popup_centered(Size2(180, 80) * EDSCALE); - line->grab_focus(); -} - -int GotoLineDialog::get_line() const { - return line->get_text().to_int(); -} - -void GotoLineDialog::ok_pressed() { - if (get_line() < 1 || get_line() > text_editor->get_line_count()) { - return; - } - text_editor->unfold_line(get_line() - 1); - text_editor->cursor_set_line(get_line() - 1); - hide(); -} - -GotoLineDialog::GotoLineDialog() { - set_title(TTR("Go to Line")); - - VBoxContainer *vbc = memnew(VBoxContainer); - vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE); - vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE); - add_child(vbc); - - Label *l = memnew(Label); - l->set_text(TTR("Line Number:")); - vbc->add_child(l); - - line = memnew(LineEdit); - vbc->add_child(line); - register_text_enter(line); - text_editor = nullptr; - - set_hide_on_ok(false); -} - void FindReplaceBar::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { find_prev->set_icon(get_theme_icon("MoveUp", "EditorIcons")); diff --git a/modules/code_editor/code_editor.h b/modules/code_editor/code_editor.h index b2b6f1365..0d1ad97ce 100644 --- a/modules/code_editor/code_editor.h +++ b/modules/code_editor/code_editor.h @@ -51,23 +51,7 @@ class TextureButton; class Timer; class ToolButton; struct ScriptCodeCompletionOption; - -class GotoLineDialog : public ConfirmationDialog { - GDCLASS(GotoLineDialog, ConfirmationDialog); - - Label *line_label; - LineEdit *line; - - TextEdit *text_editor; - - virtual void ok_pressed(); - -public: - void popup_find_line(TextEdit *p_edit); - int get_line() const; - - GotoLineDialog(); -}; +class GotoLineDialog; class FindReplaceBar : public HBoxContainer { GDCLASS(FindReplaceBar, HBoxContainer); diff --git a/modules/code_editor/goto_line_dialog.cpp b/modules/code_editor/goto_line_dialog.cpp new file mode 100644 index 000000000..978ccdfe9 --- /dev/null +++ b/modules/code_editor/goto_line_dialog.cpp @@ -0,0 +1,82 @@ +/*************************************************************************/ +/* code_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "goto_line_dialog.h" + +#include "scene/gui/line_edit.h" +#include "scene/gui/text_edit.h" +#include "scene/gui/box_container.h" +#include "scene/gui/label.h" + +#include "editor/editor_scale.h" + +void GotoLineDialog::popup_find_line(TextEdit *p_edit) { + text_editor = p_edit; + + line->set_text(itos(text_editor->cursor_get_line())); + line->select_all(); + popup_centered(Size2(180, 80) * EDSCALE); + line->grab_focus(); +} + +int GotoLineDialog::get_line() const { + return line->get_text().to_int(); +} + +void GotoLineDialog::ok_pressed() { + if (get_line() < 1 || get_line() > text_editor->get_line_count()) { + return; + } + text_editor->unfold_line(get_line() - 1); + text_editor->cursor_set_line(get_line() - 1); + hide(); +} + +GotoLineDialog::GotoLineDialog() { + set_title(TTR("Go to Line")); + + VBoxContainer *vbc = memnew(VBoxContainer); + vbc->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_BEGIN, 8 * EDSCALE); + vbc->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 8 * EDSCALE); + vbc->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, -8 * EDSCALE); + vbc->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, -8 * EDSCALE); + add_child(vbc); + + Label *l = memnew(Label); + l->set_text(TTR("Line Number:")); + vbc->add_child(l); + + line = memnew(LineEdit); + vbc->add_child(line); + register_text_enter(line); + text_editor = nullptr; + + set_hide_on_ok(false); +} diff --git a/modules/code_editor/goto_line_dialog.h b/modules/code_editor/goto_line_dialog.h new file mode 100644 index 000000000..97ef72b1d --- /dev/null +++ b/modules/code_editor/goto_line_dialog.h @@ -0,0 +1,57 @@ +#ifndef GOTO_LINE_DIALOH_H +#define GOTO_LINE_DIALOH_H + +/*************************************************************************/ +/* code_editor.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "scene/gui/dialogs.h" + +class Label; +class LineEdit; +class TextEdit; + +class GotoLineDialog : public ConfirmationDialog { + GDCLASS(GotoLineDialog, ConfirmationDialog); + + Label *line_label; + LineEdit *line; + + TextEdit *text_editor; + + virtual void ok_pressed(); + +public: + void popup_find_line(TextEdit *p_edit); + int get_line() const; + + GotoLineDialog(); +}; + +#endif // CODE_EDITOR_H diff --git a/modules/code_editor/script_text_editor.cpp b/modules/code_editor/script_text_editor.cpp index 6ee74d0ec..d8fb6fb76 100644 --- a/modules/code_editor/script_text_editor.cpp +++ b/modules/code_editor/script_text_editor.cpp @@ -73,6 +73,7 @@ #include "connection_info_dialog.h" #include "script_editor.h" +#include "goto_line_dialog.h" Vector ScriptTextEditor::get_functions() { String errortxt; diff --git a/modules/code_editor/text_editor.cpp b/modules/code_editor/text_editor.cpp index 5bca17068..6a115bf0f 100644 --- a/modules/code_editor/text_editor.cpp +++ b/modules/code_editor/text_editor.cpp @@ -51,6 +51,7 @@ #include "scene/resources/texture.h" #include "script_editor.h" +#include "goto_line_dialog.h" void TextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) { highlighters[p_highlighter->get_name()] = p_highlighter;