Moved GotoLineDialog to it's own file.

This commit is contained in:
Relintai 2023-02-18 13:59:28 +01:00
parent 1296786c9d
commit 1b0c1c14f0
8 changed files with 146 additions and 61 deletions

View File

@ -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 ****/

View File

@ -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)

View File

@ -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"));

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -73,6 +73,7 @@
#include "connection_info_dialog.h"
#include "script_editor.h"
#include "goto_line_dialog.h"
Vector<String> ScriptTextEditor::get_functions() {
String errortxt;

View File

@ -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;