Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/docks/inspector_dock.cpp
9903 views
1
/**************************************************************************/
2
/* inspector_dock.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 "inspector_dock.h"
32
33
#include "editor/debugger/editor_debugger_inspector.h"
34
#include "editor/debugger/editor_debugger_node.h"
35
#include "editor/docks/filesystem_dock.h"
36
#include "editor/editor_main_screen.h"
37
#include "editor/editor_node.h"
38
#include "editor/editor_string_names.h"
39
#include "editor/editor_undo_redo_manager.h"
40
#include "editor/gui/editor_file_dialog.h"
41
#include "editor/gui/editor_object_selector.h"
42
#include "editor/script/script_editor_plugin.h"
43
#include "editor/settings/editor_settings.h"
44
#include "editor/themes/editor_scale.h"
45
46
InspectorDock *InspectorDock::singleton = nullptr;
47
48
void InspectorDock::_prepare_menu() {
49
PopupMenu *menu = object_menu->get_popup();
50
for (int i = EditorPropertyNameProcessor::STYLE_RAW; i <= EditorPropertyNameProcessor::STYLE_LOCALIZED; i++) {
51
menu->set_item_checked(menu->get_item_index(PROPERTY_NAME_STYLE_RAW + i), i == property_name_style);
52
}
53
}
54
55
void InspectorDock::_menu_option(int p_option) {
56
_menu_option_confirm(p_option, false);
57
}
58
59
void InspectorDock::_menu_confirm_current() {
60
_menu_option_confirm(current_option, true);
61
}
62
63
void InspectorDock::_menu_option_confirm(int p_option, bool p_confirmed) {
64
if (!p_confirmed) {
65
current_option = p_option;
66
}
67
68
switch (p_option) {
69
case EXPAND_ALL: {
70
_menu_expandall();
71
} break;
72
case COLLAPSE_ALL: {
73
_menu_collapseall();
74
} break;
75
case EXPAND_REVERTABLE: {
76
_menu_expand_revertable();
77
} break;
78
79
case RESOURCE_SAVE: {
80
_save_resource(false);
81
} break;
82
case RESOURCE_SAVE_AS: {
83
_save_resource(true);
84
} break;
85
86
case RESOURCE_MAKE_BUILT_IN: {
87
_unref_resource();
88
} break;
89
case RESOURCE_COPY: {
90
_copy_resource();
91
} break;
92
case RESOURCE_EDIT_CLIPBOARD: {
93
_paste_resource();
94
} break;
95
case RESOURCE_SHOW_IN_FILESYSTEM: {
96
Ref<Resource> current_res = _get_current_resource();
97
ERR_FAIL_COND(current_res.is_null());
98
FileSystemDock::get_singleton()->navigate_to_path(current_res->get_path());
99
} break;
100
101
case OBJECT_REQUEST_HELP: {
102
if (current) {
103
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
104
emit_signal(SNAME("request_help"), current->get_class());
105
}
106
} break;
107
108
case OBJECT_COPY_PARAMS: {
109
editor_data->apply_changes_in_editors();
110
if (current) {
111
editor_data->copy_object_params(current);
112
}
113
} break;
114
115
case OBJECT_PASTE_PARAMS: {
116
editor_data->apply_changes_in_editors();
117
if (current) {
118
editor_data->paste_object_params(current);
119
}
120
} break;
121
122
case OBJECT_UNIQUE_RESOURCES: {
123
if (!p_confirmed) {
124
Vector<String> resource_propnames;
125
126
if (current) {
127
List<PropertyInfo> props;
128
current->get_property_list(&props);
129
130
for (const PropertyInfo &property : props) {
131
if (!(property.usage & PROPERTY_USAGE_STORAGE)) {
132
continue;
133
}
134
if (property.usage & PROPERTY_USAGE_NEVER_DUPLICATE) {
135
continue;
136
}
137
138
Variant v = current->get(property.name);
139
Ref<RefCounted> ref = v;
140
Ref<Resource> res = ref;
141
if (v.is_ref_counted() && ref.is_valid() && res.is_valid()) {
142
// Valid resource which would be duplicated if action is confirmed.
143
resource_propnames.append(property.name);
144
}
145
}
146
}
147
148
unique_resources_list_tree->clear();
149
if (resource_propnames.size()) {
150
const EditorPropertyNameProcessor::Style name_style = inspector->get_property_name_style();
151
152
TreeItem *root = unique_resources_list_tree->create_item();
153
for (const String &E : resource_propnames) {
154
const String propname = EditorPropertyNameProcessor::get_singleton()->process_name(E, name_style);
155
156
TreeItem *ti = unique_resources_list_tree->create_item(root);
157
ti->set_text(0, propname);
158
}
159
160
unique_resources_label->set_text(TTRC("The following resources will be duplicated and embedded within this resource/object."));
161
unique_resources_confirmation->popup_centered();
162
} else {
163
current_option = -1;
164
unique_resources_label->set_text(TTRC("This object has no resources."));
165
unique_resources_confirmation->popup_centered();
166
}
167
} else {
168
editor_data->apply_changes_in_editors();
169
170
if (current) {
171
List<PropertyInfo> props;
172
current->get_property_list(&props);
173
HashMap<Ref<Resource>, Ref<Resource>> duplicates;
174
for (const PropertyInfo &prop_info : props) {
175
if (!(prop_info.usage & PROPERTY_USAGE_STORAGE)) {
176
continue;
177
}
178
179
Variant v = current->get(prop_info.name);
180
if (v.is_ref_counted()) {
181
Ref<RefCounted> ref = v;
182
if (ref.is_valid()) {
183
Ref<Resource> res = ref;
184
if (res.is_valid()) {
185
if (!duplicates.has(res)) {
186
duplicates[res] = res->duplicate();
187
}
188
res = duplicates[res];
189
190
current->set(prop_info.name, res);
191
get_inspector_singleton()->update_property(prop_info.name);
192
}
193
}
194
}
195
}
196
}
197
198
int history_id = EditorUndoRedoManager::get_singleton()->get_history_id_for_object(current);
199
EditorUndoRedoManager::get_singleton()->clear_history(history_id);
200
201
EditorNode::get_singleton()->edit_item(current, inspector);
202
}
203
204
} break;
205
206
case PROPERTY_NAME_STYLE_RAW:
207
case PROPERTY_NAME_STYLE_CAPITALIZED:
208
case PROPERTY_NAME_STYLE_LOCALIZED: {
209
property_name_style = (EditorPropertyNameProcessor::Style)(p_option - PROPERTY_NAME_STYLE_RAW);
210
inspector->set_property_name_style(property_name_style);
211
} break;
212
213
default: {
214
if (p_option >= OBJECT_METHOD_BASE) {
215
ERR_FAIL_NULL(current);
216
217
int idx = p_option - OBJECT_METHOD_BASE;
218
219
List<MethodInfo> methods;
220
current->get_method_list(&methods);
221
222
ERR_FAIL_INDEX(idx, methods.size());
223
String name = methods.get(idx).name;
224
225
current->call(name);
226
}
227
}
228
}
229
}
230
231
void InspectorDock::_new_resource() {
232
new_resource_dialog->popup_create(true);
233
}
234
235
void InspectorDock::_load_resource(const String &p_type) {
236
load_resource_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
237
238
List<String> extensions;
239
ResourceLoader::get_recognized_extensions_for_type(p_type, &extensions);
240
241
load_resource_dialog->clear_filters();
242
for (const String &extension : extensions) {
243
load_resource_dialog->add_filter("*." + extension, extension.to_upper());
244
}
245
246
const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions"))).split(",", false);
247
for (int i = 0; i < textfile_ext.size(); i++) {
248
load_resource_dialog->add_filter("*." + textfile_ext[i], textfile_ext[i].to_upper());
249
}
250
251
load_resource_dialog->popup_file_dialog();
252
}
253
254
void InspectorDock::_resource_file_selected(const String &p_file) {
255
Ref<Resource> res;
256
if (ResourceLoader::exists(p_file, "")) {
257
res = ResourceLoader::load(p_file);
258
} else {
259
const Vector<String> textfile_ext = ((String)(EDITOR_GET("docks/filesystem/textfile_extensions"))).split(",", false);
260
if (textfile_ext.has(p_file.get_extension())) {
261
res = ScriptEditor::get_singleton()->open_file(p_file);
262
}
263
}
264
265
if (res.is_null()) {
266
info_dialog->set_text(TTRC("Failed to load resource."));
267
return;
268
};
269
270
EditorNode::get_singleton()->push_item(res.operator->());
271
}
272
273
void InspectorDock::_save_resource(bool save_as) {
274
Ref<Resource> current_res = _get_current_resource();
275
ERR_FAIL_COND(current_res.is_null());
276
277
if (save_as) {
278
EditorNode::get_singleton()->save_resource_as(current_res);
279
} else {
280
EditorNode::get_singleton()->save_resource(current_res);
281
}
282
}
283
284
void InspectorDock::_unref_resource() {
285
Ref<Resource> current_res = _get_current_resource();
286
ERR_FAIL_COND(current_res.is_null());
287
current_res->set_path("");
288
EditorNode::get_singleton()->edit_current();
289
}
290
291
void InspectorDock::_copy_resource() {
292
Ref<Resource> current_res = _get_current_resource();
293
ERR_FAIL_COND(current_res.is_null());
294
EditorSettings::get_singleton()->set_resource_clipboard(current_res);
295
}
296
297
void InspectorDock::_paste_resource() {
298
Ref<Resource> r = EditorSettings::get_singleton()->get_resource_clipboard();
299
if (r.is_valid()) {
300
EditorNode::get_singleton()->push_item(EditorSettings::get_singleton()->get_resource_clipboard().ptr(), String());
301
}
302
}
303
304
void InspectorDock::_prepare_resource_extra_popup() {
305
Ref<Resource> r = EditorSettings::get_singleton()->get_resource_clipboard();
306
PopupMenu *popup = resource_extra_button->get_popup();
307
popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null());
308
309
Ref<Resource> current_res = _get_current_resource();
310
popup->set_item_disabled(popup->get_item_index(RESOURCE_SHOW_IN_FILESYSTEM), current_res.is_null() || current_res->is_built_in());
311
}
312
313
Ref<Resource> InspectorDock::_get_current_resource() const {
314
ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current();
315
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;
316
return Ref<Resource>(Object::cast_to<Resource>(current_obj));
317
}
318
319
void InspectorDock::_prepare_history() {
320
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
321
editor_history->cleanup_history();
322
323
int history_to = MAX(0, editor_history->get_history_len() - 25);
324
325
history_menu->get_popup()->clear();
326
327
HashSet<ObjectID> already;
328
for (int i = editor_history->get_history_len() - 1; i >= history_to; i--) {
329
ObjectID id = editor_history->get_history_obj(i);
330
Object *obj = ObjectDB::get_instance(id);
331
if (!obj || already.has(id)) {
332
if (history_to > 0) {
333
history_to--;
334
}
335
continue;
336
}
337
338
already.insert(id);
339
340
Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(obj, "Object");
341
342
String text;
343
if (obj->has_method("_get_editor_name")) {
344
text = obj->call("_get_editor_name");
345
} else if (Object::cast_to<Resource>(obj)) {
346
Resource *r = Object::cast_to<Resource>(obj);
347
if (r->get_path().is_resource_file()) {
348
text = r->get_path().get_file();
349
} else if (!r->get_name().is_empty()) {
350
text = r->get_name();
351
} else {
352
text = r->get_class();
353
}
354
} else if (Object::cast_to<Node>(obj)) {
355
text = Object::cast_to<Node>(obj)->get_name();
356
} else if (obj->is_class("EditorDebuggerRemoteObjects")) {
357
text = obj->call("get_title");
358
} else {
359
text = obj->get_class();
360
}
361
362
if (i == editor_history->get_history_pos() && current) {
363
text += " " + TTR("(Current)");
364
}
365
history_menu->get_popup()->add_icon_item(icon, text, i);
366
}
367
}
368
369
void InspectorDock::_select_history(int p_idx) {
370
// Push it to the top, it is not correct, but it's more useful.
371
ObjectID id = EditorNode::get_singleton()->get_editor_selection_history()->get_history_obj(p_idx);
372
Object *obj = ObjectDB::get_instance(id);
373
if (!obj) {
374
return;
375
}
376
EditorNode::get_singleton()->push_item(obj);
377
378
if (const EditorDebuggerRemoteObjects *robjs = Object::cast_to<EditorDebuggerRemoteObjects>(obj)) {
379
EditorDebuggerNode::get_singleton()->set_remote_selection(robjs->remote_object_ids.duplicate());
380
}
381
}
382
383
void InspectorDock::_resource_created() {
384
Variant c = new_resource_dialog->instantiate_selected();
385
386
ERR_FAIL_COND(!c);
387
Resource *r = Object::cast_to<Resource>(c);
388
ERR_FAIL_NULL(r);
389
390
EditorNode::get_singleton()->push_item(r);
391
}
392
393
void InspectorDock::_resource_selected(const Ref<Resource> &p_res, const String &p_property) {
394
if (p_res.is_null()) {
395
return;
396
}
397
398
Ref<Resource> r = p_res;
399
EditorNode::get_singleton()->push_item(r.operator->(), p_property);
400
}
401
402
void InspectorDock::_files_moved(const String &p_old_file, const String &p_new_file) {
403
// Because only the file name is shown, we care about changes on the file name.
404
if (p_old_file.get_file() == p_new_file.get_file()) {
405
return;
406
}
407
408
ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current();
409
Ref<Resource> res(current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr);
410
// We only care about updating the path if the current object is the one being renamed.
411
if (res.is_valid() && p_old_file == res->get_path()) {
412
res->set_path(p_new_file);
413
object_selector->update_path();
414
}
415
}
416
417
void InspectorDock::_edit_forward() {
418
if (EditorNode::get_singleton()->get_editor_selection_history()->next()) {
419
EditorNode::get_singleton()->edit_current();
420
421
if (const EditorDebuggerRemoteObjects *robjs = Object::cast_to<EditorDebuggerRemoteObjects>(current)) {
422
EditorDebuggerNode::get_singleton()->set_remote_selection(robjs->remote_object_ids.duplicate());
423
}
424
}
425
}
426
427
void InspectorDock::_edit_back() {
428
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
429
if ((current && editor_history->previous()) || editor_history->get_path_size() == 1) {
430
EditorNode::get_singleton()->edit_current();
431
432
if (const EditorDebuggerRemoteObjects *robjs = Object::cast_to<EditorDebuggerRemoteObjects>(current)) {
433
EditorDebuggerNode::get_singleton()->set_remote_selection(robjs->remote_object_ids.duplicate());
434
}
435
}
436
}
437
438
void InspectorDock::_menu_collapseall() {
439
inspector->collapse_all_folding();
440
}
441
442
void InspectorDock::_menu_expandall() {
443
inspector->expand_all_folding();
444
}
445
446
void InspectorDock::_menu_expand_revertable() {
447
inspector->expand_revertable();
448
}
449
450
void InspectorDock::_info_pressed() {
451
info_dialog->popup_centered();
452
}
453
454
Container *InspectorDock::get_addon_area() {
455
return this;
456
}
457
458
void InspectorDock::_notification(int p_what) {
459
switch (p_what) {
460
case NOTIFICATION_TRANSLATION_CHANGED: {
461
update(current);
462
[[fallthrough]];
463
}
464
case NOTIFICATION_THEME_CHANGED:
465
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
466
resource_new_button->set_button_icon(get_editor_theme_icon(SNAME("New")));
467
resource_load_button->set_button_icon(get_editor_theme_icon(SNAME("Load")));
468
resource_save_button->set_button_icon(get_editor_theme_icon(SNAME("Save")));
469
resource_extra_button->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
470
open_docs_button->set_button_icon(get_editor_theme_icon(SNAME("HelpSearch")));
471
472
PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
473
resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), get_editor_theme_icon(SNAME("ActionPaste")));
474
resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_COPY), get_editor_theme_icon(SNAME("ActionCopy")));
475
resource_extra_popup->set_item_icon(resource_extra_popup->get_item_index(RESOURCE_SHOW_IN_FILESYSTEM), get_editor_theme_icon(SNAME("ShowInFileSystem")));
476
477
if (is_layout_rtl()) {
478
backward_button->set_button_icon(get_editor_theme_icon(SNAME("Forward")));
479
forward_button->set_button_icon(get_editor_theme_icon(SNAME("Back")));
480
} else {
481
backward_button->set_button_icon(get_editor_theme_icon(SNAME("Back")));
482
forward_button->set_button_icon(get_editor_theme_icon(SNAME("Forward")));
483
}
484
485
const int icon_width = get_theme_constant(SNAME("class_icon_size"), EditorStringName(Editor));
486
history_menu->get_popup()->add_theme_constant_override("icon_max_width", icon_width);
487
488
history_menu->set_button_icon(get_editor_theme_icon(SNAME("History")));
489
object_menu->set_button_icon(get_editor_theme_icon(SNAME("Tools")));
490
search->set_right_icon(get_editor_theme_icon(SNAME("Search")));
491
if (info_is_warning) {
492
info->set_button_icon(get_editor_theme_icon(SNAME("NodeWarning")));
493
info->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
494
} else {
495
info->set_button_icon(get_editor_theme_icon(SNAME("NodeInfo")));
496
info->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), EditorStringName(Editor)));
497
}
498
} break;
499
}
500
}
501
502
void InspectorDock::_bind_methods() {
503
ClassDB::bind_method("store_script_properties", &InspectorDock::store_script_properties);
504
ClassDB::bind_method("apply_script_properties", &InspectorDock::apply_script_properties);
505
506
ADD_SIGNAL(MethodInfo("request_help"));
507
}
508
509
void InspectorDock::edit_resource(const Ref<Resource> &p_resource) {
510
_resource_selected(p_resource, "");
511
}
512
513
void InspectorDock::open_resource(const String &p_type) {
514
_load_resource(p_type);
515
}
516
517
void InspectorDock::set_info(const String &p_button_text, const String &p_message, bool p_is_warning) {
518
info->hide();
519
info_is_warning = p_is_warning;
520
521
if (info_is_warning) {
522
info->set_button_icon(get_editor_theme_icon(SNAME("NodeWarning")));
523
info->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
524
} else {
525
info->set_button_icon(get_editor_theme_icon(SNAME("NodeInfo")));
526
info->add_theme_color_override(SceneStringName(font_color), get_theme_color(SceneStringName(font_color), EditorStringName(Editor)));
527
}
528
529
if (!p_button_text.is_empty() && !p_message.is_empty()) {
530
info->show();
531
info->set_text(p_button_text);
532
info_dialog->set_text(p_message);
533
}
534
}
535
536
void InspectorDock::clear() {
537
}
538
539
void InspectorDock::update(Object *p_object) {
540
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
541
542
backward_button->set_disabled(editor_history->is_at_beginning());
543
forward_button->set_disabled(editor_history->is_at_end());
544
545
history_menu->set_disabled(true);
546
if (editor_history->get_history_len() > 0) {
547
history_menu->set_disabled(false);
548
}
549
object_selector->update_path();
550
551
current = p_object;
552
553
const bool is_object = p_object != nullptr;
554
const bool is_resource = is_object && p_object->is_class("Resource");
555
const bool is_text_file = is_object && p_object->is_class("TextFile");
556
const bool is_node = is_object && p_object->is_class("Node");
557
558
object_menu->set_disabled(!is_object || is_text_file);
559
search->set_editable(is_object && !is_text_file);
560
resource_save_button->set_disabled(!is_resource || is_text_file);
561
open_docs_button->set_disabled(is_text_file || (!is_resource && !is_node));
562
563
PopupMenu *resource_extra_popup = resource_extra_button->get_popup();
564
resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_COPY), !is_resource || is_text_file);
565
resource_extra_popup->set_item_disabled(resource_extra_popup->get_item_index(RESOURCE_MAKE_BUILT_IN), !is_resource || is_text_file);
566
567
if (!is_object || is_text_file) {
568
info->hide();
569
object_selector->clear_path();
570
return;
571
}
572
573
object_selector->enable_path();
574
575
PopupMenu *p = object_menu->get_popup();
576
577
p->clear();
578
p->add_icon_shortcut(get_editor_theme_icon(SNAME("GuiTreeArrowDown")), ED_SHORTCUT("property_editor/expand_all", TTRC("Expand All")), EXPAND_ALL);
579
p->add_icon_shortcut(get_editor_theme_icon(SNAME("GuiTreeArrowRight")), ED_SHORTCUT("property_editor/collapse_all", TTRC("Collapse All")), COLLAPSE_ALL);
580
// Calling it 'revertable' internally, because that's what the implementation is based on, but labeling it as 'non-default' because that's more user friendly, even if not 100% accurate.
581
p->add_shortcut(ED_SHORTCUT("property_editor/expand_revertable", TTRC("Expand Non-Default")), EXPAND_REVERTABLE);
582
583
p->add_separator(TTRC("Property Name Style"));
584
p->add_radio_check_item(vformat(TTR("Raw (e.g. \"%s\")"), "z_index"), PROPERTY_NAME_STYLE_RAW);
585
p->add_radio_check_item(vformat(TTR("Capitalized (e.g. \"%s\")"), "Z Index"), PROPERTY_NAME_STYLE_CAPITALIZED);
586
// TRANSLATORS: "Z Index" should match the existing translated CanvasItem property name in the current language you're working on.
587
p->add_radio_check_item(TTR("Localized (e.g. \"Z Index\")"), PROPERTY_NAME_STYLE_LOCALIZED);
588
589
if (!EditorPropertyNameProcessor::is_localization_available()) {
590
const int index = p->get_item_index(PROPERTY_NAME_STYLE_LOCALIZED);
591
p->set_item_disabled(index, true);
592
p->set_item_tooltip(index, TTRC("Localization not available for current language."));
593
}
594
595
p->add_separator();
596
p->add_shortcut(ED_SHORTCUT("property_editor/copy_params", TTRC("Copy Properties")), OBJECT_COPY_PARAMS);
597
p->add_shortcut(ED_SHORTCUT("property_editor/paste_params", TTRC("Paste Properties")), OBJECT_PASTE_PARAMS);
598
599
if (is_resource || is_node) {
600
p->add_separator();
601
p->add_shortcut(ED_SHORTCUT("property_editor/make_subresources_unique", TTRC("Make Sub-Resources Unique")), OBJECT_UNIQUE_RESOURCES);
602
}
603
604
List<MethodInfo> methods;
605
p_object->get_method_list(&methods);
606
607
if (!methods.is_empty()) {
608
bool found = false;
609
List<MethodInfo>::Element *I = methods.front();
610
int i = 0;
611
while (I) {
612
if (I->get().flags & METHOD_FLAG_EDITOR) {
613
if (!found) {
614
p->add_separator();
615
found = true;
616
}
617
p->add_item(I->get().name.capitalize(), OBJECT_METHOD_BASE + i);
618
}
619
i++;
620
I = I->next();
621
}
622
}
623
}
624
625
void InspectorDock::go_back() {
626
_edit_back();
627
}
628
629
EditorPropertyNameProcessor::Style InspectorDock::get_property_name_style() const {
630
return property_name_style;
631
}
632
633
void InspectorDock::store_script_properties(Object *p_object) {
634
ERR_FAIL_NULL(p_object);
635
ScriptInstance *si = p_object->get_script_instance();
636
if (!si) {
637
return;
638
}
639
si->get_property_state(stored_properties);
640
}
641
642
void InspectorDock::apply_script_properties(Object *p_object) {
643
ERR_FAIL_NULL(p_object);
644
ScriptInstance *si = p_object->get_script_instance();
645
if (!si) {
646
return;
647
}
648
649
List<PropertyInfo> properties;
650
si->get_property_list(&properties);
651
652
for (const Pair<StringName, Variant> &E : stored_properties) {
653
Variant current_prop;
654
if (si->get(E.first, current_prop) && current_prop.get_type() == E.second.get_type()) {
655
si->set(E.first, E.second);
656
} else if (E.second.get_type() == Variant::OBJECT) {
657
for (const PropertyInfo &pi : properties) {
658
if (E.first != pi.name) {
659
continue;
660
}
661
662
if (pi.type != Variant::OBJECT) {
663
break;
664
}
665
666
Object *p_property_object = E.second;
667
668
if (p_property_object->is_class(pi.hint_string)) {
669
si->set(E.first, E.second);
670
break;
671
}
672
673
Ref<Script> base_script = p_property_object->get_script();
674
while (base_script.is_valid()) {
675
if (base_script->get_global_name() == pi.hint_string) {
676
si->set(E.first, E.second);
677
break;
678
}
679
base_script = base_script->get_base_script();
680
}
681
break;
682
}
683
}
684
}
685
stored_properties.clear();
686
}
687
688
void InspectorDock::shortcut_input(const Ref<InputEvent> &p_event) {
689
ERR_FAIL_COND(p_event.is_null());
690
691
Ref<InputEventKey> key = p_event;
692
693
if (key.is_null() || !key->is_pressed() || key->is_echo()) {
694
return;
695
}
696
697
if (!is_visible() || !inspector->get_rect().has_point(inspector->get_local_mouse_position())) {
698
return;
699
}
700
701
if (ED_IS_SHORTCUT("editor/open_search", p_event)) {
702
search->grab_focus();
703
search->select_all();
704
accept_event();
705
}
706
}
707
708
InspectorDock::InspectorDock(EditorData &p_editor_data) {
709
singleton = this;
710
set_name("Inspector");
711
712
editor_data = &p_editor_data;
713
714
property_name_style = EditorPropertyNameProcessor::get_default_inspector_style();
715
716
HBoxContainer *general_options_hb = memnew(HBoxContainer);
717
add_child(general_options_hb);
718
719
resource_new_button = memnew(Button);
720
resource_new_button->set_theme_type_variation("FlatMenuButton");
721
resource_new_button->set_tooltip_text(TTRC("Create a new resource in memory and edit it."));
722
general_options_hb->add_child(resource_new_button);
723
resource_new_button->connect(SceneStringName(pressed), callable_mp(this, &InspectorDock::_new_resource));
724
resource_new_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
725
726
resource_load_button = memnew(Button);
727
resource_load_button->set_theme_type_variation("FlatMenuButton");
728
resource_load_button->set_tooltip_text(TTRC("Load an existing resource from disk and edit it."));
729
general_options_hb->add_child(resource_load_button);
730
resource_load_button->connect(SceneStringName(pressed), callable_mp(this, &InspectorDock::_open_resource_selector));
731
resource_load_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
732
733
resource_save_button = memnew(MenuButton);
734
resource_save_button->set_flat(false);
735
resource_save_button->set_theme_type_variation("FlatMenuButton");
736
resource_save_button->set_tooltip_text(TTRC("Save the currently edited resource."));
737
general_options_hb->add_child(resource_save_button);
738
resource_save_button->get_popup()->add_item(TTRC("Save"), RESOURCE_SAVE);
739
resource_save_button->get_popup()->add_item(TTRC("Save As..."), RESOURCE_SAVE_AS);
740
resource_save_button->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &InspectorDock::_menu_option));
741
resource_save_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
742
resource_save_button->set_disabled(true);
743
744
resource_extra_button = memnew(MenuButton);
745
resource_extra_button->set_flat(false);
746
resource_extra_button->set_theme_type_variation("FlatMenuButton");
747
resource_extra_button->set_tooltip_text(TTRC("Extra resource options."));
748
general_options_hb->add_child(resource_extra_button);
749
resource_extra_button->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_resource_extra_popup));
750
resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/paste_resource", TTRC("Edit Resource from Clipboard")), RESOURCE_EDIT_CLIPBOARD);
751
resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/copy_resource", TTRC("Copy Resource")), RESOURCE_COPY);
752
resource_extra_button->get_popup()->set_item_disabled(1, true);
753
resource_extra_button->get_popup()->add_separator();
754
resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/show_in_filesystem", TTRC("Show in FileSystem")), RESOURCE_SHOW_IN_FILESYSTEM);
755
resource_extra_button->get_popup()->add_shortcut(ED_SHORTCUT("property_editor/unref_resource", TTRC("Make Resource Built-In")), RESOURCE_MAKE_BUILT_IN);
756
resource_extra_button->get_popup()->set_item_disabled(3, true);
757
resource_extra_button->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &InspectorDock::_menu_option));
758
759
general_options_hb->add_spacer();
760
761
backward_button = memnew(Button);
762
backward_button->set_flat(true);
763
general_options_hb->add_child(backward_button);
764
backward_button->set_tooltip_text(TTRC("Go to previous edited object in history."));
765
backward_button->set_disabled(true);
766
backward_button->connect(SceneStringName(pressed), callable_mp(this, &InspectorDock::_edit_back));
767
768
forward_button = memnew(Button);
769
forward_button->set_flat(true);
770
general_options_hb->add_child(forward_button);
771
forward_button->set_tooltip_text(TTRC("Go to next edited object in history."));
772
forward_button->set_disabled(true);
773
forward_button->connect(SceneStringName(pressed), callable_mp(this, &InspectorDock::_edit_forward));
774
775
history_menu = memnew(MenuButton);
776
history_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
777
history_menu->set_flat(false);
778
history_menu->set_theme_type_variation("FlatMenuButton");
779
history_menu->set_tooltip_text(TTRC("History of recently edited objects."));
780
general_options_hb->add_child(history_menu);
781
history_menu->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_history));
782
history_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &InspectorDock::_select_history));
783
784
HBoxContainer *subresource_hb = memnew(HBoxContainer);
785
add_child(subresource_hb);
786
object_selector = memnew(EditorObjectSelector(EditorNode::get_singleton()->get_editor_selection_history()));
787
object_selector->set_h_size_flags(Control::SIZE_EXPAND_FILL);
788
subresource_hb->add_child(object_selector);
789
790
open_docs_button = memnew(Button);
791
open_docs_button->set_theme_type_variation("FlatMenuButton");
792
open_docs_button->set_disabled(true);
793
open_docs_button->set_tooltip_text(TTRC("Open documentation for this object."));
794
open_docs_button->set_shortcut(ED_SHORTCUT("property_editor/open_help", TTRC("Open Documentation")));
795
subresource_hb->add_child(open_docs_button);
796
open_docs_button->connect(SceneStringName(pressed), callable_mp(this, &InspectorDock::_menu_option).bind(OBJECT_REQUEST_HELP));
797
798
new_resource_dialog = memnew(CreateDialog);
799
EditorNode::get_singleton()->get_gui_base()->add_child(new_resource_dialog);
800
new_resource_dialog->set_base_type("Resource");
801
new_resource_dialog->connect("create", callable_mp(this, &InspectorDock::_resource_created));
802
803
HBoxContainer *property_tools_hb = memnew(HBoxContainer);
804
add_child(property_tools_hb);
805
806
search = memnew(LineEdit);
807
search->set_h_size_flags(Control::SIZE_EXPAND_FILL);
808
search->set_placeholder(TTRC("Filter Properties"));
809
search->set_clear_button_enabled(true);
810
property_tools_hb->add_child(search);
811
812
object_menu = memnew(MenuButton);
813
object_menu->set_flat(false);
814
object_menu->set_theme_type_variation("FlatMenuButton");
815
property_tools_hb->add_child(object_menu);
816
object_menu->set_tooltip_text(TTRC("Manage object properties."));
817
object_menu->get_popup()->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_menu));
818
object_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &InspectorDock::_menu_option));
819
820
info = memnew(Button);
821
add_child(info);
822
info->set_clip_text(true);
823
info->set_accessibility_name(TTRC("Information"));
824
info->hide();
825
info->connect(SceneStringName(pressed), callable_mp(this, &InspectorDock::_info_pressed));
826
827
unique_resources_confirmation = memnew(ConfirmationDialog);
828
add_child(unique_resources_confirmation);
829
830
VBoxContainer *container = memnew(VBoxContainer);
831
unique_resources_confirmation->add_child(container);
832
833
unique_resources_label = memnew(Label);
834
unique_resources_label->set_focus_mode(FOCUS_ACCESSIBILITY);
835
container->add_child(unique_resources_label);
836
837
unique_resources_list_tree = memnew(Tree);
838
unique_resources_list_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
839
unique_resources_list_tree->set_hide_root(true);
840
unique_resources_list_tree->set_columns(1);
841
unique_resources_list_tree->set_custom_minimum_size(Size2(0, 200 * EDSCALE));
842
container->add_child(unique_resources_list_tree);
843
844
Label *bottom_label = memnew(Label);
845
bottom_label->set_focus_mode(FOCUS_ACCESSIBILITY);
846
bottom_label->set_text(TTRC("This cannot be undone. Are you sure?"));
847
container->add_child(bottom_label);
848
849
unique_resources_confirmation->connect(SceneStringName(confirmed), callable_mp(this, &InspectorDock::_menu_confirm_current));
850
851
info_dialog = memnew(AcceptDialog);
852
EditorNode::get_singleton()->get_gui_base()->add_child(info_dialog);
853
854
load_resource_dialog = memnew(EditorFileDialog);
855
add_child(load_resource_dialog);
856
load_resource_dialog->set_current_dir("res://");
857
load_resource_dialog->connect("file_selected", callable_mp(this, &InspectorDock::_resource_file_selected));
858
859
inspector = memnew(EditorInspector);
860
add_child(inspector);
861
inspector->set_autoclear(true);
862
inspector->set_show_categories(true, true);
863
inspector->set_v_size_flags(Control::SIZE_EXPAND_FILL);
864
inspector->set_use_doc_hints(true);
865
inspector->set_hide_script(false);
866
inspector->set_hide_metadata(false);
867
inspector->set_use_settings_name_style(false);
868
inspector->set_property_name_style(property_name_style);
869
inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
870
inspector->register_text_enter(search);
871
872
inspector->set_use_filter(true);
873
874
inspector->connect("resource_selected", callable_mp(this, &InspectorDock::_resource_selected));
875
876
FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &InspectorDock::_files_moved));
877
878
set_process_shortcut_input(true);
879
}
880
881
InspectorDock::~InspectorDock() {
882
singleton = nullptr;
883
}
884
885