Add drag and drop info label
This commit is contained in:
parent
92a90a8e6f
commit
2d03275c88
4 changed files with 81 additions and 0 deletions
|
|
@ -1366,6 +1366,9 @@
|
|||
<member name="text_editor/appearance/caret/type" type="int" setter="" getter="">
|
||||
The shape of the caret to use in the script editor. [b]Line[/b] displays a vertical line to the left of the current character, whereas [b]Block[/b] displays an outline over the current character.
|
||||
</member>
|
||||
<member name="text_editor/appearance/drag_and_drop_info/show_drag_and_drop_info" type="bool" setter="" getter="">
|
||||
If [code]true[/code], shows an info label listing available drop options when dragging an object into the script text editor.
|
||||
</member>
|
||||
<member name="text_editor/appearance/enable_inline_color_picker" type="bool" setter="" getter="">
|
||||
If [code]true[/code], displays a colored button before any [Color] constructor in the script editor. Clicking on them allows the color to be modified through a color picker.
|
||||
</member>
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include "scene/gui/menu_button.h"
|
||||
#include "scene/gui/rich_text_label.h"
|
||||
#include "scene/gui/split_container.h"
|
||||
#include "scene/resources/style_box_flat.h"
|
||||
|
||||
void ConnectionInfoDialog::ok_pressed() {
|
||||
}
|
||||
|
|
@ -296,6 +297,14 @@ void ScriptTextEditor::_load_theme_settings() {
|
|||
folded_code_region_color = updated_folded_code_region_color;
|
||||
}
|
||||
|
||||
Ref<StyleBoxFlat> drag_info_sb = drag_info_label->get_theme_stylebox(CoreStringName(normal));
|
||||
drag_info_sb->set_bg_color(EDITOR_GET("text_editor/theme/highlighting/completion_background_color"));
|
||||
Color info_color = EDITOR_GET("text_editor/theme/highlighting/text_color");
|
||||
info_color.a = 0.5f;
|
||||
drag_info_sb->set_border_color(info_color);
|
||||
info_color.a = 0.7f;
|
||||
drag_info_label->add_theme_color_override(SceneStringName(font_color), info_color);
|
||||
|
||||
theme_loaded = true;
|
||||
Ref<Script> script = edited_res;
|
||||
if (script.is_valid()) {
|
||||
|
|
@ -419,6 +428,10 @@ void ScriptTextEditor::_error_clicked(const Variant &p_line) {
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_on_mouse_exited() {
|
||||
drag_info_label->hide();
|
||||
}
|
||||
|
||||
void ScriptTextEditor::add_callback(const String &p_function, const PackedStringArray &p_args) {
|
||||
Ref<Script> script = edited_res;
|
||||
ScriptLanguage *language = script->get_language();
|
||||
|
|
@ -1870,6 +1883,9 @@ void ScriptTextEditor::_notification(int p_what) {
|
|||
inline_color_options->add_theme_font_override("font", code_font);
|
||||
inline_color_options->get_popup()->add_theme_font_override("font", code_font);
|
||||
} break;
|
||||
case NOTIFICATION_DRAG_END: {
|
||||
drag_info_label->hide();
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1904,12 +1920,48 @@ bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_
|
|||
String(d["type"]) == "nodes" ||
|
||||
String(d["type"]) == "obj_property" ||
|
||||
String(d["type"]) == "files_and_dirs")) {
|
||||
_set_drop_info_text(d);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptTextEditor::_set_drop_info_text(const Dictionary &p_info) const {
|
||||
if (drag_info_label->is_visible() || !EDITOR_GET("text_editor/appearance/drag_and_drop_info/show_drag_and_drop_info")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text;
|
||||
String c = keycode_get_string((Key)KeyModifierMask::CMD_OR_CTRL);
|
||||
bool drop_as_uid = bool(EDITOR_GET("text_editor/behavior/files/drop_preload_resources_as_uid"));
|
||||
String default_drop_option = drop_as_uid ? TTR("UID path") : TTR("file path");
|
||||
String alternate_drop_option = drop_as_uid ? TTR("file path") : TTR("UID path");
|
||||
|
||||
const String type = p_info.get("type", "");
|
||||
|
||||
if (type == "files" || type == "files_and_dirs" || type == "resource") {
|
||||
Array files = p_info.get("files", Array());
|
||||
text = TTRN("Drop file path.", "Drop file paths.", files.size()) +
|
||||
"\n" + vformat(TTRN("Hold %s: Add const preload by %s.", "Hold %s: Add const preloads by %s.", files.size()), c, default_drop_option) +
|
||||
"\n" + vformat(TTRN("Hold %s+Shift: Add const preload by %s.", "Hold %s+Shift: Add const preloads by %s.", files.size()), c, alternate_drop_option) +
|
||||
"\n" + TTRN("Hold Alt: Add @export var pointing to the resource.", "Hold Alt: Add @export vars pointing to the resources.", files.size());
|
||||
} else if (type == "nodes") {
|
||||
Array nodes = p_info["nodes"];
|
||||
text = TTRN("Drop node path.", "Drop node paths.", nodes.size()) +
|
||||
"\n" + vformat(TTRN("Hold %s: Add @onready var pointing to the node path.", "Hold %s: Add @onready vars pointing to the node paths.", nodes.size()), c) +
|
||||
"\n" + TTRN("Hold Alt: Add @export var pointing to the node.", "Hold Alt: Add @export vars pointing to the nodes.", nodes.size());
|
||||
} else if (type == "obj_property") {
|
||||
text = TTR("Drop property path.");
|
||||
}
|
||||
|
||||
if (!text.is_empty()) {
|
||||
drag_info_label->show();
|
||||
drag_info_label->set_text(text);
|
||||
drag_info_label->set_anchors_and_offsets_preset(Control::PRESET_BOTTOM_RIGHT, Control::PRESET_MODE_MINSIZE, 20 * EDSCALE);
|
||||
}
|
||||
}
|
||||
|
||||
static Node *_find_script_node(Node *p_current_node, const Ref<Script> &script) {
|
||||
if (p_current_node->get_script() == script) {
|
||||
return p_current_node;
|
||||
|
|
@ -2240,6 +2292,8 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
|
|||
te->insert_text_at_caret(text_to_drop);
|
||||
te->end_complex_operation();
|
||||
te->grab_focus();
|
||||
|
||||
drag_info_label->hide();
|
||||
}
|
||||
|
||||
Vector<ObjectID> ScriptTextEditor::_get_objects_for_export_assignment() const {
|
||||
|
|
@ -2655,6 +2709,23 @@ ScriptTextEditor::ScriptTextEditor() {
|
|||
errors_panel->set_focus_mode(FOCUS_CLICK);
|
||||
errors_panel->hide();
|
||||
|
||||
drag_info_label = memnew(Label);
|
||||
drag_info_label->set_anchors_preset(Control::PRESET_BOTTOM_RIGHT);
|
||||
drag_info_label->set_focus_mode(FOCUS_ACCESSIBILITY);
|
||||
drag_info_label->add_theme_constant_override("line_spacing", 0);
|
||||
|
||||
Ref<StyleBoxFlat> drag_info_sb;
|
||||
drag_info_sb.instantiate();
|
||||
drag_info_sb->set_border_width_all(2 * EDSCALE);
|
||||
drag_info_sb->set_corner_radius_all(5 * EDSCALE);
|
||||
drag_info_sb->set_corner_detail(5);
|
||||
drag_info_sb->set_expand_margin_all(5);
|
||||
drag_info_label->add_theme_style_override(CoreStringName(normal), drag_info_sb);
|
||||
|
||||
code_editor->get_text_editor()->connect(SceneStringName(mouse_exited), callable_mp(this, &ScriptTextEditor::_on_mouse_exited));
|
||||
code_editor->get_text_editor()->add_child(drag_info_label);
|
||||
drag_info_label->hide();
|
||||
|
||||
code_editor->get_text_editor()->set_symbol_lookup_on_click_enabled(true);
|
||||
code_editor->get_text_editor()->set_symbol_tooltip_on_hover_enabled(true);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class ScriptTextEditor : public CodeEditorBase {
|
|||
bool script_is_valid = false;
|
||||
|
||||
RichTextLabel *errors_panel = nullptr;
|
||||
Label *drag_info_label = nullptr;
|
||||
|
||||
Vector<String> functions;
|
||||
List<ScriptLanguage::Warning> warnings;
|
||||
|
|
@ -173,6 +174,7 @@ protected:
|
|||
void _show_warnings_panel(bool p_show);
|
||||
void _error_clicked(const Variant &p_line);
|
||||
virtual bool _warning_clicked(const Variant &p_line) override;
|
||||
void _on_mouse_exited();
|
||||
|
||||
bool _is_valid_color_info(const Dictionary &p_info);
|
||||
Array _inline_object_parse(const String &p_text);
|
||||
|
|
@ -198,6 +200,8 @@ protected:
|
|||
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
|
||||
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
|
||||
|
||||
void _set_drop_info_text(const Dictionary &p_info) const;
|
||||
|
||||
String _get_absolute_path(const String &rel_path);
|
||||
|
||||
void _goto_line(int p_line) { goto_line(p_line); }
|
||||
|
|
|
|||
|
|
@ -776,6 +776,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
|
|||
_initial_set("text_editor/appearance/minimap/show_minimap", true, true);
|
||||
EDITOR_SETTING(Variant::INT, PROPERTY_HINT_RANGE, "text_editor/appearance/minimap/minimap_width", 80, "50,250,1")
|
||||
|
||||
// Appearance: Drag Info Label
|
||||
_initial_set("text_editor/appearance/drag_and_drop_info/show_drag_and_drop_info", true, true);
|
||||
|
||||
// Appearance: Lines
|
||||
_initial_set("text_editor/appearance/lines/code_folding", true, true);
|
||||
EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "text_editor/appearance/lines/word_wrap", 0, "None,Boundary")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue