Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/debugger/editor_expression_evaluator.cpp
9898 views
1
/**************************************************************************/
2
/* editor_expression_evaluator.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "editor_expression_evaluator.h"
32
33
#include "editor/debugger/editor_debugger_inspector.h"
34
#include "editor/debugger/script_editor_debugger.h"
35
#include "scene/gui/button.h"
36
#include "scene/gui/check_box.h"
37
#include "scene/gui/line_edit.h"
38
39
void EditorExpressionEvaluator::on_start() {
40
expression_input->set_editable(false);
41
evaluate_btn->set_disabled(true);
42
43
if (clear_on_run_checkbox->is_pressed()) {
44
inspector->clear_stack_variables();
45
}
46
}
47
48
void EditorExpressionEvaluator::set_editor_debugger(ScriptEditorDebugger *p_editor_debugger) {
49
editor_debugger = p_editor_debugger;
50
}
51
52
void EditorExpressionEvaluator::add_value(const Array &p_array) {
53
inspector->add_stack_variable(p_array, 0);
54
inspector->set_v_scroll(0);
55
inspector->set_h_scroll(0);
56
}
57
58
void EditorExpressionEvaluator::_evaluate() {
59
const String &expression = expression_input->get_text();
60
if (expression.is_empty()) {
61
return;
62
}
63
64
if (!editor_debugger->is_session_active()) {
65
return;
66
}
67
68
editor_debugger->request_remote_evaluate(expression, editor_debugger->get_stack_script_frame());
69
70
expression_input->clear();
71
}
72
73
void EditorExpressionEvaluator::_clear() {
74
inspector->clear_stack_variables();
75
}
76
77
void EditorExpressionEvaluator::_remote_object_selected(ObjectID p_id) {
78
Array arr = { p_id };
79
editor_debugger->emit_signal(SNAME("remote_objects_requested"), arr);
80
}
81
82
void EditorExpressionEvaluator::_on_expression_input_changed(const String &p_expression) {
83
evaluate_btn->set_disabled(p_expression.is_empty());
84
}
85
86
void EditorExpressionEvaluator::_on_debugger_breaked(bool p_breaked, bool p_can_debug) {
87
expression_input->set_editable(p_breaked);
88
evaluate_btn->set_disabled(!p_breaked);
89
}
90
91
void EditorExpressionEvaluator::_on_debugger_clear_execution(Ref<Script> p_stack_script) {
92
expression_input->set_editable(false);
93
evaluate_btn->set_disabled(true);
94
}
95
96
void EditorExpressionEvaluator::_notification(int p_what) {
97
switch (p_what) {
98
case NOTIFICATION_READY: {
99
EditorDebuggerNode::get_singleton()->connect("breaked", callable_mp(this, &EditorExpressionEvaluator::_on_debugger_breaked));
100
EditorDebuggerNode::get_singleton()->connect("clear_execution", callable_mp(this, &EditorExpressionEvaluator::_on_debugger_clear_execution));
101
} break;
102
}
103
}
104
105
EditorExpressionEvaluator::EditorExpressionEvaluator() {
106
set_h_size_flags(SIZE_EXPAND_FILL);
107
108
HBoxContainer *hb = memnew(HBoxContainer);
109
add_child(hb);
110
111
expression_input = memnew(LineEdit);
112
expression_input->set_h_size_flags(Control::SIZE_EXPAND_FILL);
113
expression_input->set_placeholder(TTR("Expression to evaluate"));
114
expression_input->set_accessibility_name(TTRC("Expression to evaluate"));
115
expression_input->set_clear_button_enabled(true);
116
expression_input->connect(SceneStringName(text_submitted), callable_mp(this, &EditorExpressionEvaluator::_evaluate).unbind(1));
117
expression_input->connect(SceneStringName(text_changed), callable_mp(this, &EditorExpressionEvaluator::_on_expression_input_changed));
118
hb->add_child(expression_input);
119
120
clear_on_run_checkbox = memnew(CheckBox);
121
clear_on_run_checkbox->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
122
clear_on_run_checkbox->set_text(TTR("Clear on Run"));
123
clear_on_run_checkbox->set_pressed(true);
124
hb->add_child(clear_on_run_checkbox);
125
126
evaluate_btn = memnew(Button);
127
evaluate_btn->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
128
evaluate_btn->set_text(TTR("Evaluate"));
129
evaluate_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorExpressionEvaluator::_evaluate));
130
hb->add_child(evaluate_btn);
131
132
clear_btn = memnew(Button);
133
clear_btn->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
134
clear_btn->set_text(TTR("Clear"));
135
clear_btn->connect(SceneStringName(pressed), callable_mp(this, &EditorExpressionEvaluator::_clear));
136
hb->add_child(clear_btn);
137
138
inspector = memnew(EditorDebuggerInspector);
139
inspector->set_v_size_flags(SIZE_EXPAND_FILL);
140
inspector->set_property_name_style(EditorPropertyNameProcessor::STYLE_RAW);
141
inspector->set_read_only(true);
142
inspector->connect("object_selected", callable_mp(this, &EditorExpressionEvaluator::_remote_object_selected));
143
inspector->set_use_filter(true);
144
add_child(inspector);
145
146
expression_input->set_editable(false);
147
evaluate_btn->set_disabled(true);
148
}
149
150