Merge pull request #43663 from EricEzaM/PR/INP4-dehardcode_scene_shortcuts
Remove hardcoded shortcuts from /scene and instead use the input action system to allow them to be customised.
This commit is contained in:
commit
7eb4e6415d
@ -32,6 +32,7 @@
|
||||
|
||||
#include "core/core_bind.h"
|
||||
#include "core/core_string_names.h"
|
||||
#include "core/input/input_map.h"
|
||||
#include "core/io/file_access_network.h"
|
||||
#include "core/io/file_access_pack.h"
|
||||
#include "core/io/marshalls.h"
|
||||
@ -1057,17 +1058,35 @@ void ProjectSettings::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("save_custom", "file"), &ProjectSettings::_save_custom_bnd);
|
||||
}
|
||||
|
||||
void ProjectSettings::_add_builtin_input_map() {
|
||||
if (InputMap::get_singleton()) {
|
||||
OrderedHashMap<String, List<Ref<InputEvent>>> builtins = InputMap::get_singleton()->get_builtins();
|
||||
|
||||
for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
|
||||
Array events;
|
||||
|
||||
// Convert list of input events into array
|
||||
for (List<Ref<InputEvent>>::Element *I = E.get().front(); I; I = I->next()) {
|
||||
events.push_back(I->get());
|
||||
}
|
||||
|
||||
Dictionary action;
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
action["events"] = events;
|
||||
|
||||
String action_name = "input/" + E.key();
|
||||
GLOBAL_DEF(action_name, action);
|
||||
input_presets.push_back(action_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ProjectSettings::ProjectSettings() {
|
||||
// Initialization of engine variables should be done in the setup() method,
|
||||
// so that the values can be overridden from project.godot or project.binary.
|
||||
|
||||
singleton = this;
|
||||
|
||||
Array events;
|
||||
Dictionary action;
|
||||
Ref<InputEventKey> key;
|
||||
Ref<InputEventJoypadButton> joyb;
|
||||
|
||||
GLOBAL_DEF_BASIC("application/config/name", "");
|
||||
GLOBAL_DEF_BASIC("application/config/description", "");
|
||||
custom_prop_info["application/config/description"] = PropertyInfo(Variant::STRING, "application/config/description", PROPERTY_HINT_MULTILINE_TEXT);
|
||||
@ -1094,163 +1113,7 @@ ProjectSettings::ProjectSettings() {
|
||||
GLOBAL_DEF("editor/script/templates_search_path", "res://script_templates");
|
||||
custom_prop_info["editor/script/templates_search_path"] = PropertyInfo(Variant::STRING, "editor/script/templates_search_path", PROPERTY_HINT_DIR);
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_ENTER);
|
||||
events.push_back(key);
|
||||
key.instance();
|
||||
key->set_keycode(KEY_KP_ENTER);
|
||||
events.push_back(key);
|
||||
key.instance();
|
||||
key->set_keycode(KEY_SPACE);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_A);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_accept", action);
|
||||
input_presets.push_back("input/ui_accept");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_SPACE);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_Y);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_select", action);
|
||||
input_presets.push_back("input/ui_select");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_ESCAPE);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_B);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_cancel", action);
|
||||
input_presets.push_back("input/ui_cancel");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_TAB);
|
||||
events.push_back(key);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_focus_next", action);
|
||||
input_presets.push_back("input/ui_focus_next");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_TAB);
|
||||
key->set_shift(true);
|
||||
events.push_back(key);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_focus_prev", action);
|
||||
input_presets.push_back("input/ui_focus_prev");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_LEFT);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_DPAD_LEFT);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_left", action);
|
||||
input_presets.push_back("input/ui_left");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_RIGHT);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_DPAD_RIGHT);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_right", action);
|
||||
input_presets.push_back("input/ui_right");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_UP);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_DPAD_UP);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_up", action);
|
||||
input_presets.push_back("input/ui_up");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_DOWN);
|
||||
events.push_back(key);
|
||||
joyb.instance();
|
||||
joyb->set_button_index(JOY_BUTTON_DPAD_DOWN);
|
||||
events.push_back(joyb);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_down", action);
|
||||
input_presets.push_back("input/ui_down");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_PAGEUP);
|
||||
events.push_back(key);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_page_up", action);
|
||||
input_presets.push_back("input/ui_page_up");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_PAGEDOWN);
|
||||
events.push_back(key);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_page_down", action);
|
||||
input_presets.push_back("input/ui_page_down");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_HOME);
|
||||
events.push_back(key);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_home", action);
|
||||
input_presets.push_back("input/ui_home");
|
||||
|
||||
action = Dictionary();
|
||||
action["deadzone"] = Variant(0.5f);
|
||||
events = Array();
|
||||
key.instance();
|
||||
key->set_keycode(KEY_END);
|
||||
events.push_back(key);
|
||||
action["events"] = events;
|
||||
GLOBAL_DEF("input/ui_end", action);
|
||||
input_presets.push_back("input/ui_end");
|
||||
_add_builtin_input_map();
|
||||
|
||||
custom_prop_info["display/window/handheld/orientation"] = PropertyInfo(Variant::STRING, "display/window/handheld/orientation", PROPERTY_HINT_ENUM, "landscape,portrait,reverse_landscape,reverse_portrait,sensor_landscape,sensor_portrait,sensor");
|
||||
custom_prop_info["rendering/driver/threads/thread_model"] = PropertyInfo(Variant::INT, "rendering/driver/threads/thread_model", PROPERTY_HINT_ENUM, "Single-Unsafe,Single-Safe,Multi-Threaded");
|
||||
|
@ -116,6 +116,9 @@ protected:
|
||||
|
||||
Error _setup(const String &p_path, const String &p_main_pack, bool p_upwards = false);
|
||||
|
||||
void _add_builtin_input_map();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
|
@ -604,21 +604,21 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
|
||||
}
|
||||
}
|
||||
|
||||
for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) {
|
||||
if (InputMap::get_singleton()->event_is_action(p_event, E->key())) {
|
||||
for (OrderedHashMap<StringName, InputMap::Action>::ConstElement E = InputMap::get_singleton()->get_action_map().front(); E; E = E.next()) {
|
||||
if (InputMap::get_singleton()->event_is_action(p_event, E.key())) {
|
||||
// If not echo and action pressed state has changed
|
||||
if (!p_event->is_echo() && is_action_pressed(E->key(), false) != p_event->is_action_pressed(E->key())) {
|
||||
if (!p_event->is_echo() && is_action_pressed(E.key(), false) != p_event->is_action_pressed(E.key())) {
|
||||
Action action;
|
||||
action.physics_frame = Engine::get_singleton()->get_physics_frames();
|
||||
action.process_frame = Engine::get_singleton()->get_process_frames();
|
||||
action.pressed = p_event->is_action_pressed(E->key());
|
||||
action.pressed = p_event->is_action_pressed(E.key());
|
||||
action.strength = 0.0f;
|
||||
action.raw_strength = 0.0f;
|
||||
action.exact = InputMap::get_singleton()->event_is_action(p_event, E->key(), true);
|
||||
action_state[E->key()] = action;
|
||||
action.exact = InputMap::get_singleton()->event_is_action(p_event, E.key(), true);
|
||||
action_state[E.key()] = action;
|
||||
}
|
||||
action_state[E->key()].strength = p_event->get_action_strength(E->key());
|
||||
action_state[E->key()].raw_strength = p_event->get_action_raw_strength(E->key());
|
||||
action_state[E.key()].strength = p_event->get_action_strength(E.key());
|
||||
action_state[E.key()].raw_strength = p_event->get_action_raw_strength(E.key());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -384,6 +384,31 @@ String InputEventKey::to_string() {
|
||||
return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", kc, mods, physical, p, e);
|
||||
}
|
||||
|
||||
Ref<InputEventKey> InputEventKey::create_reference(uint32_t p_keycode) {
|
||||
Ref<InputEventKey> ie;
|
||||
ie.instance();
|
||||
ie->set_keycode(p_keycode & KEY_CODE_MASK);
|
||||
ie->set_unicode(p_keycode & KEY_CODE_MASK);
|
||||
|
||||
if (p_keycode & KEY_MASK_SHIFT) {
|
||||
ie->set_shift(true);
|
||||
}
|
||||
if (p_keycode & KEY_MASK_ALT) {
|
||||
ie->set_alt(true);
|
||||
}
|
||||
if (p_keycode & KEY_MASK_CTRL) {
|
||||
ie->set_control(true);
|
||||
}
|
||||
if (p_keycode & KEY_MASK_CMD) {
|
||||
ie->set_command(true);
|
||||
}
|
||||
if (p_keycode & KEY_MASK_META) {
|
||||
ie->set_metakey(true);
|
||||
}
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
|
||||
Ref<InputEventKey> key = p_event;
|
||||
if (key.is_null()) {
|
||||
@ -1011,6 +1036,14 @@ String InputEventJoypadButton::to_string() {
|
||||
return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
|
||||
}
|
||||
|
||||
Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) {
|
||||
Ref<InputEventJoypadButton> ie;
|
||||
ie.instance();
|
||||
ie->set_button_index(p_btn_index);
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
void InputEventJoypadButton::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
|
||||
ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
|
||||
|
@ -260,6 +260,8 @@ public:
|
||||
virtual String as_text() const override;
|
||||
virtual String to_string() override;
|
||||
|
||||
static Ref<InputEventKey> create_reference(uint32_t p_keycode_with_modifier_masks);
|
||||
|
||||
InputEventKey() {}
|
||||
};
|
||||
|
||||
@ -406,6 +408,8 @@ public:
|
||||
virtual String as_text() const override;
|
||||
virtual String to_string() override;
|
||||
|
||||
static Ref<InputEventJoypadButton> create_reference(int p_btn_index);
|
||||
|
||||
InputEventJoypadButton() {}
|
||||
};
|
||||
|
||||
|
@ -88,8 +88,8 @@ List<StringName> InputMap::get_actions() const {
|
||||
return actions;
|
||||
}
|
||||
|
||||
for (Map<StringName, Action>::Element *E = input_map.front(); E; E = E->next()) {
|
||||
actions.push_back(E->key());
|
||||
for (OrderedHashMap<StringName, Action>::Element E = input_map.front(); E; E = E.next()) {
|
||||
actions.push_back(E.key());
|
||||
}
|
||||
|
||||
return actions;
|
||||
@ -179,12 +179,12 @@ Array InputMap::_action_get_events(const StringName &p_action) {
|
||||
}
|
||||
|
||||
const List<Ref<InputEvent>> *InputMap::action_get_events(const StringName &p_action) {
|
||||
const Map<StringName, Action>::Element *E = input_map.find(p_action);
|
||||
const OrderedHashMap<StringName, Action>::Element E = input_map.find(p_action);
|
||||
if (!E) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &E->get().inputs;
|
||||
return &E.get().inputs;
|
||||
}
|
||||
|
||||
bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
|
||||
@ -192,7 +192,7 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName
|
||||
}
|
||||
|
||||
bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
|
||||
Map<StringName, Action>::Element *E = input_map.find(p_action);
|
||||
OrderedHashMap<StringName, Action>::Element E = input_map.find(p_action);
|
||||
ERR_FAIL_COND_V_MSG(!E, false, "Request for nonexistent InputMap action '" + String(p_action) + "'.");
|
||||
|
||||
Ref<InputEventAction> input_event_action = p_event;
|
||||
@ -209,7 +209,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
|
||||
bool pressed;
|
||||
float strength;
|
||||
float raw_strength;
|
||||
List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, p_exact_match, &pressed, &strength, &raw_strength);
|
||||
List<Ref<InputEvent>>::Element *event = _find_event(E.get(), p_event, p_exact_match, &pressed, &strength, &raw_strength);
|
||||
if (event != nullptr) {
|
||||
if (p_pressed != nullptr) {
|
||||
*p_pressed = pressed;
|
||||
@ -226,7 +226,7 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
|
||||
}
|
||||
}
|
||||
|
||||
const Map<StringName, InputMap::Action> &InputMap::get_action_map() const {
|
||||
const OrderedHashMap<StringName, InputMap::Action> &InputMap::get_action_map() const {
|
||||
return input_map;
|
||||
}
|
||||
|
||||
@ -260,84 +260,444 @@ void InputMap::load_from_project_settings() {
|
||||
}
|
||||
}
|
||||
|
||||
struct _BuiltinActionDisplayName {
|
||||
const char *name;
|
||||
const char *display_name;
|
||||
};
|
||||
|
||||
static const _BuiltinActionDisplayName _builtin_action_display_names[] = {
|
||||
/* clang-format off */
|
||||
{ "ui_accept", TTRC("Accept") },
|
||||
{ "ui_select", TTRC("Select") },
|
||||
{ "ui_cancel", TTRC("Cancel") },
|
||||
{ "ui_focus_next", TTRC("Focus Next") },
|
||||
{ "ui_focus_prev", TTRC("Focus Prev") },
|
||||
{ "ui_left", TTRC("Left") },
|
||||
{ "ui_right", TTRC("Right") },
|
||||
{ "ui_up", TTRC("Up") },
|
||||
{ "ui_down", TTRC("Down") },
|
||||
{ "ui_page_up", TTRC("Page Up") },
|
||||
{ "ui_page_down", TTRC("Page Down") },
|
||||
{ "ui_home", TTRC("Home") },
|
||||
{ "ui_end", TTRC("End") },
|
||||
{ "ui_cut", TTRC("Cut") },
|
||||
{ "ui_copy", TTRC("Copy") },
|
||||
{ "ui_paste", TTRC("Paste") },
|
||||
{ "ui_undo", TTRC("Undo") },
|
||||
{ "ui_redo", TTRC("Redo") },
|
||||
{ "ui_text_completion_query", TTRC("Completion Query") },
|
||||
{ "ui_text_newline", TTRC("New Line") },
|
||||
{ "ui_text_newline_blank", TTRC("New Blank Line") },
|
||||
{ "ui_text_newline_above", TTRC("New Line Above") },
|
||||
{ "ui_text_indent", TTRC("Indent") },
|
||||
{ "ui_text_dedent", TTRC("Dedent") },
|
||||
{ "ui_text_backspace", TTRC("Backspace") },
|
||||
{ "ui_text_backspace_word", TTRC("Backspace Word") },
|
||||
{ "ui_text_backspace_word.OSX", TTRC("Backspace Word") },
|
||||
{ "ui_text_backspace_all_to_left", TTRC("Backspace all to Left") },
|
||||
{ "ui_text_backspace_all_to_left.OSX", TTRC("Backspace all to Left") },
|
||||
{ "ui_text_delete", TTRC("Delete") },
|
||||
{ "ui_text_delete_word", TTRC("Delete Word") },
|
||||
{ "ui_text_delete_word.OSX", TTRC("Delete Word") },
|
||||
{ "ui_text_delete_all_to_right", TTRC("Delete all to Right") },
|
||||
{ "ui_text_delete_all_to_right.OSX", TTRC("Delete all to Right") },
|
||||
{ "ui_text_caret_left", TTRC("Caret Left") },
|
||||
{ "ui_text_caret_word_left", TTRC("Caret Word Left") },
|
||||
{ "ui_text_caret_word_left.OSX", TTRC("Caret Word Left") },
|
||||
{ "ui_text_caret_right", TTRC("Caret Right") },
|
||||
{ "ui_text_caret_word_right", TTRC("Caret Word Right") },
|
||||
{ "ui_text_caret_word_right.OSX", TTRC("Caret Word Right") },
|
||||
{ "ui_text_caret_up", TTRC("Caret Up") },
|
||||
{ "ui_text_caret_down", TTRC("Caret Down") },
|
||||
{ "ui_text_caret_line_start", TTRC("Caret Line Start") },
|
||||
{ "ui_text_caret_line_start.OSX", TTRC("Caret Line Start") },
|
||||
{ "ui_text_caret_line_end", TTRC("Caret Line End") },
|
||||
{ "ui_text_caret_line_end.OSX", TTRC("Caret Line End") },
|
||||
{ "ui_text_caret_page_up", TTRC("Caret Page Up") },
|
||||
{ "ui_text_caret_page_down", TTRC("Caret Page Down") },
|
||||
{ "ui_text_caret_document_start", TTRC("Caret Document Start") },
|
||||
{ "ui_text_caret_document_start.OSX", TTRC("Caret Document Start") },
|
||||
{ "ui_text_caret_document_end", TTRC("Caret Document End") },
|
||||
{ "ui_text_caret_document_end.OSX", TTRC("Caret Document End") },
|
||||
{ "ui_text_scroll_up", TTRC("Scroll Up") },
|
||||
{ "ui_text_scroll_up.OSX", TTRC("Scroll Up") },
|
||||
{ "ui_text_scroll_down", TTRC("Scroll Down") },
|
||||
{ "ui_text_scroll_down.OSX", TTRC("Scroll Down") },
|
||||
{ "ui_text_select_all", TTRC("Select All") },
|
||||
{ "ui_text_toggle_insert_mode", TTRC("Toggle Insert Mode") },
|
||||
{ "ui_graph_duplicate", TTRC("Duplicate Nodes") },
|
||||
{ "ui_graph_delete", TTRC("Delete Nodes") },
|
||||
{ "ui_filedialog_up_one_level", TTRC("Go Up One Level") },
|
||||
{ "ui_filedialog_refresh", TTRC("Refresh") },
|
||||
{ "ui_filedialog_show_hidden", TTRC("Show Hidden") },
|
||||
{ "ui_swap_input_direction ", TTRC("Swap Input Direction") },
|
||||
{ "", TTRC("")}
|
||||
/* clang-format on */
|
||||
};
|
||||
|
||||
String InputMap::get_builtin_display_name(const String &p_name) const {
|
||||
int len = sizeof(_builtin_action_display_names) / sizeof(_BuiltinActionDisplayName);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (_builtin_action_display_names[i].name == p_name) {
|
||||
return RTR(_builtin_action_display_names[i].display_name);
|
||||
}
|
||||
}
|
||||
|
||||
return p_name;
|
||||
}
|
||||
|
||||
const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() {
|
||||
// Return cache if it has already been built.
|
||||
if (default_builtin_cache.size()) {
|
||||
return default_builtin_cache;
|
||||
}
|
||||
|
||||
List<Ref<InputEvent>> inputs;
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_ENTER));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_SPACE));
|
||||
default_builtin_cache.insert("ui_accept", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_Y));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_SPACE));
|
||||
default_builtin_cache.insert("ui_select", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_ESCAPE));
|
||||
default_builtin_cache.insert("ui_cancel", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_TAB));
|
||||
default_builtin_cache.insert("ui_focus_next", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_TAB | KEY_MASK_SHIFT));
|
||||
default_builtin_cache.insert("ui_focus_prev", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_LEFT));
|
||||
inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_LEFT));
|
||||
default_builtin_cache.insert("ui_left", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_RIGHT));
|
||||
inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_RIGHT));
|
||||
default_builtin_cache.insert("ui_right", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_UP));
|
||||
inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_UP));
|
||||
default_builtin_cache.insert("ui_up", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DOWN));
|
||||
inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_DOWN));
|
||||
default_builtin_cache.insert("ui_down", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_PAGEUP));
|
||||
default_builtin_cache.insert("ui_page_up", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_PAGEDOWN));
|
||||
default_builtin_cache.insert("ui_page_down", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_HOME));
|
||||
default_builtin_cache.insert("ui_home", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_END));
|
||||
default_builtin_cache.insert("ui_end", inputs);
|
||||
|
||||
// ///// UI basic Shortcuts /////
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_X | KEY_MASK_CMD));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_SHIFT));
|
||||
default_builtin_cache.insert("ui_cut", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_C | KEY_MASK_CMD));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_INSERT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_copy", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_V | KEY_MASK_CMD));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_INSERT | KEY_MASK_SHIFT));
|
||||
default_builtin_cache.insert("ui_paste", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_Z | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_undo", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_Y | KEY_MASK_CMD));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_Z | KEY_MASK_CMD | KEY_MASK_SHIFT));
|
||||
default_builtin_cache.insert("ui_redo", inputs);
|
||||
|
||||
// ///// UI Text Input Shortcuts /////
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_SPACE | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_completion_query", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_TAB));
|
||||
default_builtin_cache.insert("ui_text_completion_accept", inputs);
|
||||
|
||||
// Newlines
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_ENTER));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER));
|
||||
default_builtin_cache.insert("ui_text_newline", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_ENTER | KEY_MASK_CMD));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_newline_blank", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_ENTER | KEY_MASK_SHIFT | KEY_MASK_CMD));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER | KEY_MASK_SHIFT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_newline_above", inputs);
|
||||
|
||||
// Indentation
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_TAB));
|
||||
default_builtin_cache.insert("ui_text_indent", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_TAB | KEY_MASK_SHIFT));
|
||||
default_builtin_cache.insert("ui_text_dedent", inputs);
|
||||
|
||||
// Text Backspace and Delete
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE));
|
||||
default_builtin_cache.insert("ui_text_backspace", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_backspace_word", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_ALT));
|
||||
default_builtin_cache.insert("ui_text_backspace_word.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
default_builtin_cache.insert("ui_text_backspace_all_to_left", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_backspace_all_to_left.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DELETE));
|
||||
default_builtin_cache.insert("ui_text_delete", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_delete_word", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_ALT));
|
||||
default_builtin_cache.insert("ui_text_delete_word.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
default_builtin_cache.insert("ui_text_delete_all_to_right", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_delete_all_to_right.OSX", inputs);
|
||||
|
||||
// Text Caret Movement Left/Right
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_LEFT));
|
||||
default_builtin_cache.insert("ui_text_caret_left", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_LEFT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_word_left", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_LEFT | KEY_MASK_ALT));
|
||||
default_builtin_cache.insert("ui_text_caret_word_left.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_RIGHT));
|
||||
default_builtin_cache.insert("ui_text_caret_right", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_word_right", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_ALT));
|
||||
default_builtin_cache.insert("ui_text_caret_word_right.OSX", inputs);
|
||||
|
||||
// Text Caret Movement Up/Down
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_UP));
|
||||
default_builtin_cache.insert("ui_text_caret_up", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DOWN));
|
||||
default_builtin_cache.insert("ui_text_caret_down", inputs);
|
||||
|
||||
// Text Caret Movement Line Start/End
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_HOME));
|
||||
default_builtin_cache.insert("ui_text_caret_line_start", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_A | KEY_MASK_CTRL));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_LEFT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_line_start.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_END));
|
||||
default_builtin_cache.insert("ui_text_caret_line_end", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_E | KEY_MASK_CTRL));
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_line_end.OSX", inputs);
|
||||
// Text Caret Movement Page Up/Down
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_PAGEUP));
|
||||
default_builtin_cache.insert("ui_text_caret_page_up", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_PAGEDOWN));
|
||||
default_builtin_cache.insert("ui_text_caret_page_down", inputs);
|
||||
|
||||
// Text Caret Movement Document Start/End
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_HOME | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_document_start", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_UP | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_document_start.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_END | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_document_end", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DOWN | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_caret_document_end.OSX", inputs);
|
||||
|
||||
// Text Scrolling
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_UP | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_scroll_up", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_UP | KEY_MASK_CMD | KEY_MASK_ALT));
|
||||
default_builtin_cache.insert("ui_text_scroll_up.OSX", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DOWN | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_scroll_down", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DOWN | KEY_MASK_CMD | KEY_MASK_ALT));
|
||||
default_builtin_cache.insert("ui_text_scroll_down.OSX", inputs);
|
||||
|
||||
// Text Misc
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_A | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_text_select_all", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_INSERT));
|
||||
default_builtin_cache.insert("ui_text_toggle_insert_mode", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_MENU));
|
||||
default_builtin_cache.insert("ui_menu", inputs);
|
||||
|
||||
// ///// UI Graph Shortcuts /////
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_D | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_graph_duplicate", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_DELETE));
|
||||
default_builtin_cache.insert("ui_graph_delete", inputs);
|
||||
|
||||
// ///// UI File Dialog Shortcuts /////
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE));
|
||||
default_builtin_cache.insert("ui_filedialog_up_one_level", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_F5));
|
||||
default_builtin_cache.insert("ui_filedialog_refresh", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_H));
|
||||
default_builtin_cache.insert("ui_filedialog_show_hidden", inputs);
|
||||
|
||||
inputs = List<Ref<InputEvent>>();
|
||||
inputs.push_back(InputEventKey::create_reference(KEY_QUOTELEFT | KEY_MASK_CMD));
|
||||
default_builtin_cache.insert("ui_swap_input_direction", inputs);
|
||||
|
||||
return default_builtin_cache;
|
||||
}
|
||||
|
||||
void InputMap::load_default() {
|
||||
Ref<InputEventKey> key;
|
||||
OrderedHashMap<String, List<Ref<InputEvent>>> builtins = get_builtins();
|
||||
|
||||
add_action("ui_accept");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_ENTER);
|
||||
action_add_event("ui_accept", key);
|
||||
// List of Builtins which have an override for OSX.
|
||||
Vector<String> osx_builtins;
|
||||
for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
|
||||
if (String(E.key()).ends_with(".OSX")) {
|
||||
// Strip .OSX from name: some_input_name.OSX -> some_input_name
|
||||
osx_builtins.push_back(String(E.key()).split(".")[0]);
|
||||
}
|
||||
}
|
||||
|
||||
key.instance();
|
||||
key->set_keycode(KEY_KP_ENTER);
|
||||
action_add_event("ui_accept", key);
|
||||
for (OrderedHashMap<String, List<Ref<InputEvent>>>::Element E = builtins.front(); E; E = E.next()) {
|
||||
String fullname = E.key();
|
||||
String name = fullname.split(".")[0];
|
||||
String override_for = fullname.split(".").size() > 1 ? fullname.split(".")[1] : "";
|
||||
|
||||
key.instance();
|
||||
key->set_keycode(KEY_SPACE);
|
||||
action_add_event("ui_accept", key);
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (osx_builtins.has(name) && override_for != "OSX") {
|
||||
// Name has osx builtin but this particular one is for non-osx systems - so skip.
|
||||
continue;
|
||||
}
|
||||
#else
|
||||
if (override_for == "OSX") {
|
||||
// Override for OSX - not needed on non-osx platforms.
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
add_action("ui_select");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_SPACE);
|
||||
action_add_event("ui_select", key);
|
||||
add_action(name);
|
||||
|
||||
add_action("ui_cancel");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_ESCAPE);
|
||||
action_add_event("ui_cancel", key);
|
||||
List<Ref<InputEvent>> inputs = E.get();
|
||||
for (List<Ref<InputEvent>>::Element *I = inputs.front(); I; I = I->next()) {
|
||||
Ref<InputEventKey> iek = I->get();
|
||||
|
||||
add_action("ui_focus_next");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_TAB);
|
||||
action_add_event("ui_focus_next", key);
|
||||
|
||||
add_action("ui_focus_prev");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_TAB);
|
||||
key->set_shift(true);
|
||||
action_add_event("ui_focus_prev", key);
|
||||
|
||||
add_action("ui_left");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_LEFT);
|
||||
action_add_event("ui_left", key);
|
||||
|
||||
add_action("ui_right");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_RIGHT);
|
||||
action_add_event("ui_right", key);
|
||||
|
||||
add_action("ui_up");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_UP);
|
||||
action_add_event("ui_up", key);
|
||||
|
||||
add_action("ui_down");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_DOWN);
|
||||
action_add_event("ui_down", key);
|
||||
|
||||
add_action("ui_page_up");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_PAGEUP);
|
||||
action_add_event("ui_page_up", key);
|
||||
|
||||
add_action("ui_page_down");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_PAGEDOWN);
|
||||
action_add_event("ui_page_down", key);
|
||||
|
||||
add_action("ui_home");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_HOME);
|
||||
action_add_event("ui_home", key);
|
||||
|
||||
add_action("ui_end");
|
||||
key.instance();
|
||||
key->set_keycode(KEY_END);
|
||||
action_add_event("ui_end", key);
|
||||
|
||||
//set("display/window/handheld/orientation", "landscape");
|
||||
// For the editor, only add keyboard actions.
|
||||
if (iek.is_valid()) {
|
||||
action_add_event(fullname, I->get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputMap::InputMap() {
|
||||
|
@ -33,6 +33,8 @@
|
||||
|
||||
#include "core/input/input_event.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "core/object/object.h"
|
||||
#include "core/templates/ordered_hash_map.h"
|
||||
|
||||
class InputMap : public Object {
|
||||
GDCLASS(InputMap, Object);
|
||||
@ -52,7 +54,8 @@ public:
|
||||
private:
|
||||
static InputMap *singleton;
|
||||
|
||||
mutable Map<StringName, Action> input_map;
|
||||
mutable OrderedHashMap<StringName, Action> input_map;
|
||||
OrderedHashMap<String, List<Ref<InputEvent>>> default_builtin_cache;
|
||||
|
||||
List<Ref<InputEvent>>::Element *_find_event(Action &p_action, const Ref<InputEvent> &p_event, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
|
||||
|
||||
@ -81,10 +84,14 @@ public:
|
||||
bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false) const;
|
||||
bool event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match = false, bool *p_pressed = nullptr, float *p_strength = nullptr, float *p_raw_strength = nullptr) const;
|
||||
|
||||
const Map<StringName, Action> &get_action_map() const;
|
||||
const OrderedHashMap<StringName, Action> &get_action_map() const;
|
||||
void load_from_project_settings();
|
||||
void load_default();
|
||||
|
||||
String get_builtin_display_name(const String &p_name) const;
|
||||
// Use an Ordered Map so insertion order is preserved. We want the elements to be 'grouped' somewhat.
|
||||
const OrderedHashMap<String, List<Ref<InputEvent>>> &get_builtins();
|
||||
|
||||
InputMap();
|
||||
};
|
||||
|
||||
|
@ -6215,8 +6215,8 @@ EditorNode::EditorNode() {
|
||||
pm_export->connect("id_pressed", callable_mp(this, &EditorNode::_menu_option));
|
||||
|
||||
p->add_separator();
|
||||
p->add_shortcut(ED_SHORTCUT("editor/undo", TTR("Undo"), KEY_MASK_CMD + KEY_Z), EDIT_UNDO, true);
|
||||
p->add_shortcut(ED_SHORTCUT("editor/redo", TTR("Redo"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_Z), EDIT_REDO, true);
|
||||
p->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO, true);
|
||||
p->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO, true);
|
||||
|
||||
p->add_separator();
|
||||
p->add_shortcut(ED_SHORTCUT("editor/reload_saved_scene", TTR("Reload Saved Scene")), EDIT_RELOAD_SAVED_SCENE);
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "editor_settings.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/input/input_map.h"
|
||||
#include "core/io/certs_compressed.gen.h"
|
||||
#include "core/io/compression.h"
|
||||
#include "core/io/config_file.h"
|
||||
@ -70,7 +71,7 @@ bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
|
||||
bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value) {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
if (p_name.operator String() == "shortcuts") {
|
||||
if (p_name == "shortcuts") {
|
||||
Array arr = p_value;
|
||||
ERR_FAIL_COND_V(arr.size() && arr.size() & 1, true);
|
||||
for (int i = 0; i < arr.size(); i += 2) {
|
||||
@ -83,6 +84,24 @@ bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value)
|
||||
add_shortcut(name, sc);
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (p_name == "builtin_action_overrides") {
|
||||
Array actions_arr = p_value;
|
||||
for (int i = 0; i < actions_arr.size(); i++) {
|
||||
Dictionary action_dict = actions_arr[i];
|
||||
|
||||
String name = action_dict["name"];
|
||||
Array events = action_dict["events"];
|
||||
|
||||
InputMap *im = InputMap::get_singleton();
|
||||
im->action_erase_events(name);
|
||||
|
||||
builtin_action_overrides[name].clear();
|
||||
for (int ev_idx = 0; ev_idx < events.size(); ev_idx++) {
|
||||
im->action_add_event(name, events[ev_idx]);
|
||||
builtin_action_overrides[name].push_back(events[ev_idx]);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -118,11 +137,16 @@ bool EditorSettings::_set_only(const StringName &p_name, const Variant &p_value)
|
||||
bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
if (p_name.operator String() == "shortcuts") {
|
||||
if (p_name == "shortcuts") {
|
||||
Array arr;
|
||||
for (const Map<String, Ref<Shortcut>>::Element *E = shortcuts.front(); E; E = E->next()) {
|
||||
Ref<Shortcut> sc = E->get();
|
||||
|
||||
if (builtin_action_overrides.has(E->key())) {
|
||||
// This shortcut was auto-generated from built in actions: don't save.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (optimize_save) {
|
||||
if (!sc->has_meta("original")) {
|
||||
continue; //this came from settings but is not any longer used
|
||||
@ -139,6 +163,27 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
}
|
||||
r_ret = arr;
|
||||
return true;
|
||||
} else if (p_name == "builtin_action_overrides") {
|
||||
Array actions_arr;
|
||||
for (Map<String, List<Ref<InputEvent>>>::Element *E = builtin_action_overrides.front(); E; E = E->next()) {
|
||||
List<Ref<InputEvent>> events = E->get();
|
||||
|
||||
// TODO: skip actions which are the same as the builtin.
|
||||
Dictionary action_dict;
|
||||
action_dict["name"] = E->key();
|
||||
|
||||
Array events_arr;
|
||||
for (List<Ref<InputEvent>>::Element *I = events.front(); I; I = I->next()) {
|
||||
events_arr.push_back(I->get());
|
||||
}
|
||||
|
||||
action_dict["events"] = events_arr;
|
||||
|
||||
actions_arr.push_back(action_dict);
|
||||
}
|
||||
|
||||
r_ret = actions_arr;
|
||||
return true;
|
||||
}
|
||||
|
||||
const VariantContainer *v = props.getptr(p_name);
|
||||
@ -220,6 +265,7 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
}
|
||||
|
||||
p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); //do not edit
|
||||
p_list->push_back(PropertyInfo(Variant::ARRAY, "builtin_action_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
|
||||
}
|
||||
|
||||
void EditorSettings::_add_property_info_bind(const Dictionary &p_info) {
|
||||
@ -1539,12 +1585,39 @@ bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_
|
||||
}
|
||||
|
||||
Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
|
||||
const Map<String, Ref<Shortcut>>::Element *E = shortcuts.find(p_name);
|
||||
if (!E) {
|
||||
return Ref<Shortcut>();
|
||||
const Map<String, Ref<Shortcut>>::Element *SC = shortcuts.find(p_name);
|
||||
if (SC) {
|
||||
return SC->get();
|
||||
}
|
||||
|
||||
return E->get();
|
||||
// If no shortcut with the provided name is found in the list, check the built-in shortcuts.
|
||||
// Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.
|
||||
|
||||
Ref<Shortcut> sc;
|
||||
const Map<String, List<Ref<InputEvent>>>::Element *builtin_override = builtin_action_overrides.find(p_name);
|
||||
if (builtin_override) {
|
||||
sc.instance();
|
||||
sc->set_shortcut(builtin_override->get().front()->get());
|
||||
sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
|
||||
}
|
||||
|
||||
// If there was no override, check the default builtins to see if it has an InputEvent for the provided name.
|
||||
if (sc.is_null()) {
|
||||
const OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins().find(p_name);
|
||||
if (builtin_default) {
|
||||
sc.instance();
|
||||
sc->set_shortcut(builtin_default.get().front()->get());
|
||||
sc->set_name(InputMap::get_singleton()->get_builtin_display_name(p_name));
|
||||
}
|
||||
}
|
||||
|
||||
if (sc.is_valid()) {
|
||||
// Add the shortcut to the list.
|
||||
shortcuts[p_name] = sc;
|
||||
return sc;
|
||||
}
|
||||
|
||||
return Ref<Shortcut>();
|
||||
}
|
||||
|
||||
void EditorSettings::get_shortcut_list(List<String> *r_shortcuts) {
|
||||
@ -1610,6 +1683,66 @@ Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p
|
||||
return sc;
|
||||
}
|
||||
|
||||
void EditorSettings::set_builtin_action_override(const String &p_name, const Array &p_events) {
|
||||
List<Ref<InputEvent>> event_list;
|
||||
|
||||
// Override the whole list, since events may have their order changed or be added, removed or edited.
|
||||
InputMap::get_singleton()->action_erase_events(p_name);
|
||||
for (int i = 0; i < p_events.size(); i++) {
|
||||
event_list.push_back(p_events[i]);
|
||||
InputMap::get_singleton()->action_add_event(p_name, p_events[i]);
|
||||
}
|
||||
|
||||
// Check if the provided event array is same as built-in. If it is, it does not need to be added to the overrides.
|
||||
// Note that event order must also be the same.
|
||||
bool same_as_builtin = true;
|
||||
OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins().find(p_name);
|
||||
if (builtin_default) {
|
||||
List<Ref<InputEvent>> builtin_events = builtin_default.get();
|
||||
|
||||
if (p_events.size() == builtin_events.size()) {
|
||||
int event_idx = 0;
|
||||
|
||||
// Check equality of each event.
|
||||
for (List<Ref<InputEvent>>::Element *E = builtin_events.front(); E; E = E->next()) {
|
||||
if (!E->get()->shortcut_match(p_events[event_idx])) {
|
||||
same_as_builtin = false;
|
||||
break;
|
||||
}
|
||||
event_idx++;
|
||||
}
|
||||
} else {
|
||||
same_as_builtin = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (same_as_builtin && builtin_action_overrides.has(p_name)) {
|
||||
builtin_action_overrides.erase(p_name);
|
||||
} else {
|
||||
builtin_action_overrides[p_name] = event_list;
|
||||
}
|
||||
|
||||
// Update the shortcut (if it is used somewhere in the editor) to be the first event of the new list.
|
||||
if (shortcuts.has(p_name)) {
|
||||
shortcuts[p_name]->set_shortcut(event_list.front()->get());
|
||||
}
|
||||
}
|
||||
|
||||
const Array EditorSettings::get_builtin_action_overrides(const String &p_name) const {
|
||||
const Map<String, List<Ref<InputEvent>>>::Element *AO = builtin_action_overrides.find(p_name);
|
||||
if (AO) {
|
||||
Array event_array;
|
||||
|
||||
List<Ref<InputEvent>> events_list = AO->get();
|
||||
for (List<Ref<InputEvent>>::Element *E = events_list.front(); E; E = E->next()) {
|
||||
event_array.push_back(E->get());
|
||||
}
|
||||
return event_array;
|
||||
}
|
||||
|
||||
return Array();
|
||||
}
|
||||
|
||||
void EditorSettings::notify_changes() {
|
||||
_THREAD_SAFE_METHOD_
|
||||
|
||||
@ -1648,6 +1781,8 @@ void EditorSettings::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_recent_dirs", "dirs"), &EditorSettings::set_recent_dirs);
|
||||
ClassDB::bind_method(D_METHOD("get_recent_dirs"), &EditorSettings::get_recent_dirs);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_builtin_action_override", "name", "actions_list"), &EditorSettings::set_builtin_action_override);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("settings_changed"));
|
||||
|
||||
BIND_CONSTANT(NOTIFICATION_EDITOR_SETTINGS_CHANGED);
|
||||
|
@ -84,7 +84,8 @@ private:
|
||||
int last_order;
|
||||
|
||||
Ref<Resource> clipboard;
|
||||
Map<String, Ref<Shortcut>> shortcuts;
|
||||
mutable Map<String, Ref<Shortcut>> shortcuts;
|
||||
Map<String, List<Ref<InputEvent>>> builtin_action_overrides;
|
||||
|
||||
String resource_path;
|
||||
String settings_dir;
|
||||
@ -186,6 +187,9 @@ public:
|
||||
Ref<Shortcut> get_shortcut(const String &p_name) const;
|
||||
void get_shortcut_list(List<String> *r_shortcuts);
|
||||
|
||||
void set_builtin_action_override(const String &p_name, const Array &p_events);
|
||||
const Array get_builtin_action_overrides(const String &p_name) const;
|
||||
|
||||
void notify_changes();
|
||||
|
||||
EditorSettings();
|
||||
|
@ -1066,7 +1066,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
||||
return;
|
||||
}
|
||||
|
||||
tx->indent_left();
|
||||
tx->indent_selected_lines_left();
|
||||
} break;
|
||||
case EDIT_INDENT_RIGHT: {
|
||||
Ref<Script> scr = script;
|
||||
@ -1074,7 +1074,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
||||
return;
|
||||
}
|
||||
|
||||
tx->indent_right();
|
||||
tx->indent_selected_lines_right();
|
||||
} break;
|
||||
case EDIT_DELETE_LINE: {
|
||||
code_editor->delete_lines();
|
||||
@ -1632,16 +1632,16 @@ void ScriptTextEditor::_color_changed(const Color &p_color) {
|
||||
|
||||
void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos) {
|
||||
context_menu->clear();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
||||
@ -1743,14 +1743,14 @@ void ScriptTextEditor::_enable_code_editor() {
|
||||
search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option));
|
||||
|
||||
edit_hb->add_child(edit_menu);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
||||
@ -1763,7 +1763,7 @@ void ScriptTextEditor::_enable_code_editor() {
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES);
|
||||
@ -1915,12 +1915,6 @@ static ScriptEditorBase *create_editor(const RES &p_resource) {
|
||||
}
|
||||
|
||||
void ScriptTextEditor::register_editor() {
|
||||
ED_SHORTCUT("script_text_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z);
|
||||
ED_SHORTCUT("script_text_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y);
|
||||
ED_SHORTCUT("script_text_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X);
|
||||
ED_SHORTCUT("script_text_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C);
|
||||
ED_SHORTCUT("script_text_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V);
|
||||
ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A);
|
||||
ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT | KEY_UP);
|
||||
ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN);
|
||||
ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K);
|
||||
@ -1936,10 +1930,8 @@ void ScriptTextEditor::register_editor() {
|
||||
ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0);
|
||||
#ifdef OSX_ENABLED
|
||||
ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_C);
|
||||
ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE);
|
||||
#else
|
||||
ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_D);
|
||||
ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE);
|
||||
#endif
|
||||
ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E);
|
||||
ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T);
|
||||
|
@ -282,7 +282,7 @@ void ShaderEditor::_menu_option(int p_option) {
|
||||
}
|
||||
|
||||
CodeEdit *tx = shader_editor->get_text_editor();
|
||||
tx->indent_left();
|
||||
tx->indent_selected_lines_left();
|
||||
|
||||
} break;
|
||||
case EDIT_INDENT_RIGHT: {
|
||||
@ -291,7 +291,7 @@ void ShaderEditor::_menu_option(int p_option) {
|
||||
}
|
||||
|
||||
CodeEdit *tx = shader_editor->get_text_editor();
|
||||
tx->indent_right();
|
||||
tx->indent_selected_lines_right();
|
||||
|
||||
} break;
|
||||
case EDIT_DELETE_LINE: {
|
||||
@ -533,15 +533,15 @@ void ShaderEditor::_bookmark_item_pressed(int p_idx) {
|
||||
void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) {
|
||||
context_menu->clear();
|
||||
if (p_selection) {
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
}
|
||||
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
||||
@ -585,14 +585,14 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) {
|
||||
edit_menu->set_text(TTR("Edit"));
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
||||
@ -602,7 +602,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) {
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_completion_query"), EDIT_COMPLETE);
|
||||
edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &ShaderEditor::_menu_option));
|
||||
|
||||
search_menu = memnew(MenuButton);
|
||||
|
@ -363,10 +363,10 @@ void TextEditor::_edit_option(int p_op) {
|
||||
code_editor->move_lines_down();
|
||||
} break;
|
||||
case EDIT_INDENT_LEFT: {
|
||||
tx->indent_left();
|
||||
tx->indent_selected_lines_left();
|
||||
} break;
|
||||
case EDIT_INDENT_RIGHT: {
|
||||
tx->indent_right();
|
||||
tx->indent_selected_lines_right();
|
||||
} break;
|
||||
case EDIT_DELETE_LINE: {
|
||||
code_editor->delete_lines();
|
||||
@ -514,15 +514,15 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
||||
void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) {
|
||||
context_menu->clear();
|
||||
if (p_selection) {
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
}
|
||||
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO);
|
||||
context_menu->add_separator();
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
|
||||
context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
|
||||
@ -584,14 +584,14 @@ TextEditor::TextEditor() {
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &TextEditor::_edit_option));
|
||||
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("un_redo"), EDIT_REDO);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_text_select_all"), EDIT_SELECT_ALL);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
|
||||
|
@ -143,7 +143,7 @@ void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
|
||||
if (k.is_valid() && k->is_pressed()) {
|
||||
bool handled = false;
|
||||
|
||||
if (ED_IS_SHORTCUT("editor/undo", p_event)) {
|
||||
if (ED_IS_SHORTCUT("ui_undo", p_event)) {
|
||||
String action = undo_redo->get_current_action_name();
|
||||
if (action != "") {
|
||||
EditorNode::get_log()->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR);
|
||||
@ -152,7 +152,7 @@ void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (ED_IS_SHORTCUT("editor/redo", p_event)) {
|
||||
if (ED_IS_SHORTCUT("ui_redo", p_event)) {
|
||||
undo_redo->redo();
|
||||
String action = undo_redo->get_current_action_name();
|
||||
if (action != "") {
|
||||
|
@ -515,8 +515,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
|
||||
|
||||
MAIN_PRINT("Main: Initialize Globals");
|
||||
|
||||
globals = memnew(ProjectSettings);
|
||||
input_map = memnew(InputMap);
|
||||
globals = memnew(ProjectSettings);
|
||||
|
||||
register_core_settings(); //here globals is present
|
||||
|
||||
|
@ -4274,13 +4274,13 @@ VisualScriptEditor::VisualScriptEditor() {
|
||||
edit_menu->set_shortcut_context(this);
|
||||
edit_menu->set_text(TTR("Edit"));
|
||||
edit_menu->set_switch_on_hover(true);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/delete_selected"), EDIT_DELETE_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_graph_delete"), EDIT_DELETE_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/toggle_breakpoint"), EDIT_TOGGLE_BREAKPOINT);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/find_node_type"), EDIT_FIND_NODE_TYPE);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/copy_nodes"), EDIT_COPY_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/cut_nodes"), EDIT_CUT_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/paste_nodes"), EDIT_PASTE_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_copy"), EDIT_COPY_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_cut"), EDIT_CUT_NODES);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_paste"), EDIT_PASTE_NODES);
|
||||
edit_menu->get_popup()->add_separator();
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/create_function"), EDIT_CREATE_FUNCTION);
|
||||
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("visual_script_editor/refresh_nodes"), REFRESH_GRAPH);
|
||||
@ -4520,12 +4520,8 @@ void VisualScriptEditor::free_clipboard() {
|
||||
static void register_editor_callback() {
|
||||
ScriptEditor::register_create_script_editor_function(create_editor);
|
||||
|
||||
ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected"), KEY_DELETE);
|
||||
ED_SHORTCUT("visual_script_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9);
|
||||
ED_SHORTCUT("visual_script_editor/find_node_type", TTR("Find Node Type"), KEY_MASK_CMD + KEY_F);
|
||||
ED_SHORTCUT("visual_script_editor/copy_nodes", TTR("Copy Nodes"), KEY_MASK_CMD + KEY_C);
|
||||
ED_SHORTCUT("visual_script_editor/cut_nodes", TTR("Cut Nodes"), KEY_MASK_CMD + KEY_X);
|
||||
ED_SHORTCUT("visual_script_editor/paste_nodes", TTR("Paste Nodes"), KEY_MASK_CMD + KEY_V);
|
||||
ED_SHORTCUT("visual_script_editor/create_function", TTR("Make Function"), KEY_MASK_CMD + KEY_G);
|
||||
ED_SHORTCUT("visual_script_editor/refresh_nodes", TTR("Refresh Graph"), KEY_MASK_CMD + KEY_R);
|
||||
ED_SHORTCUT("visual_script_editor/edit_member", TTR("Edit Member"), KEY_MASK_CMD + KEY_E);
|
||||
|
@ -1330,25 +1330,17 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventKey> k = p_ev;
|
||||
|
||||
if (k.is_valid()) {
|
||||
if (k->get_keycode() == KEY_D && k->is_pressed() && k->get_command()) {
|
||||
if (p_ev->is_pressed()) {
|
||||
if (p_ev->is_action("ui_graph_duplicate")) {
|
||||
emit_signal("duplicate_nodes_request");
|
||||
accept_event();
|
||||
}
|
||||
|
||||
if (k->get_keycode() == KEY_C && k->is_pressed() && k->get_command()) {
|
||||
} else if (p_ev->is_action("ui_copy")) {
|
||||
emit_signal("copy_nodes_request");
|
||||
accept_event();
|
||||
}
|
||||
|
||||
if (k->get_keycode() == KEY_V && k->is_pressed() && k->get_command()) {
|
||||
} else if (p_ev->is_action("ui_paste")) {
|
||||
emit_signal("paste_nodes_request");
|
||||
accept_event();
|
||||
}
|
||||
|
||||
if (k->get_keycode() == KEY_DELETE && k->is_pressed()) {
|
||||
} else if (p_ev->is_action("ui_graph_delete")) {
|
||||
emit_signal("delete_nodes_request");
|
||||
accept_event();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "line_edit.h"
|
||||
|
||||
#include "core/input/input_map.h"
|
||||
#include "core/object/message_queue.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "core/os/os.h"
|
||||
@ -44,6 +45,175 @@
|
||||
#endif
|
||||
#include "scene/main/window.h"
|
||||
|
||||
void LineEdit::_swap_current_input_direction() {
|
||||
if (input_direction == TEXT_DIRECTION_LTR) {
|
||||
input_direction = TEXT_DIRECTION_RTL;
|
||||
} else {
|
||||
input_direction = TEXT_DIRECTION_LTR;
|
||||
}
|
||||
set_cursor_position(get_cursor_position());
|
||||
update();
|
||||
}
|
||||
|
||||
void LineEdit::_move_cursor_left(bool p_select, bool p_move_by_word) {
|
||||
if (selection.enabled && !p_select) {
|
||||
set_cursor_position(selection.begin);
|
||||
deselect();
|
||||
return;
|
||||
}
|
||||
|
||||
shift_selection_check_pre(p_select);
|
||||
|
||||
if (p_move_by_word) {
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = words.size() - 1; i >= 0; i--) {
|
||||
if (words[i].x < cc) {
|
||||
cc = words[i].x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_cursor_position(cc);
|
||||
} else {
|
||||
if (mid_grapheme_caret_enabled) {
|
||||
set_cursor_position(get_cursor_position() - 1);
|
||||
} else {
|
||||
set_cursor_position(TS->shaped_text_prev_grapheme_pos(text_rid, get_cursor_position()));
|
||||
}
|
||||
}
|
||||
|
||||
shift_selection_check_post(p_select);
|
||||
}
|
||||
|
||||
void LineEdit::_move_cursor_right(bool p_select, bool p_move_by_word) {
|
||||
if (selection.enabled && !p_select) {
|
||||
set_cursor_position(selection.end);
|
||||
deselect();
|
||||
return;
|
||||
}
|
||||
|
||||
shift_selection_check_pre(p_select);
|
||||
|
||||
if (p_move_by_word) {
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = 0; i < words.size(); i++) {
|
||||
if (words[i].y > cc) {
|
||||
cc = words[i].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_cursor_position(cc);
|
||||
} else {
|
||||
if (mid_grapheme_caret_enabled) {
|
||||
set_cursor_position(get_cursor_position() + 1);
|
||||
} else {
|
||||
set_cursor_position(TS->shaped_text_next_grapheme_pos(text_rid, get_cursor_position()));
|
||||
}
|
||||
}
|
||||
|
||||
shift_selection_check_post(p_select);
|
||||
}
|
||||
|
||||
void LineEdit::_move_cursor_start(bool p_select) {
|
||||
shift_selection_check_pre(p_select);
|
||||
set_cursor_position(0);
|
||||
shift_selection_check_post(p_select);
|
||||
}
|
||||
|
||||
void LineEdit::_move_cursor_end(bool p_select) {
|
||||
shift_selection_check_pre(p_select);
|
||||
set_cursor_position(text.length());
|
||||
shift_selection_check_post(p_select);
|
||||
}
|
||||
|
||||
void LineEdit::_backspace(bool p_word, bool p_all_to_left) {
|
||||
if (!editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_all_to_left) {
|
||||
deselect();
|
||||
text = text.substr(0, cursor_pos);
|
||||
_text_changed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selection.enabled) {
|
||||
selection_delete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_word) {
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = words.size() - 1; i >= 0; i--) {
|
||||
if (words[i].x < cc) {
|
||||
cc = words[i].x;
|
||||
}
|
||||
}
|
||||
|
||||
delete_text(cc, cursor_pos);
|
||||
|
||||
set_cursor_position(cc);
|
||||
} else {
|
||||
delete_char();
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::_delete(bool p_word, bool p_all_to_right) {
|
||||
if (!editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_all_to_right) {
|
||||
deselect();
|
||||
text = text.substr(cursor_pos, text.length() - cursor_pos);
|
||||
_shape();
|
||||
set_cursor_position(0);
|
||||
_text_changed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selection.enabled) {
|
||||
selection_delete();
|
||||
return;
|
||||
}
|
||||
|
||||
int text_len = text.length();
|
||||
|
||||
if (cursor_pos == text_len) {
|
||||
return; // Nothing to do.
|
||||
}
|
||||
|
||||
if (p_word) {
|
||||
int cc = cursor_pos;
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = 0; i < words.size(); i++) {
|
||||
if (words[i].y > cc) {
|
||||
cc = words[i].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete_text(cursor_pos, cc);
|
||||
} else {
|
||||
if (mid_grapheme_caret_enabled) {
|
||||
set_cursor_position(cursor_pos + 1);
|
||||
delete_char();
|
||||
} else {
|
||||
int cc = cursor_pos;
|
||||
set_cursor_position(TS->shaped_text_next_grapheme_pos(text_rid, cursor_pos));
|
||||
delete_text(cc, cursor_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::_gui_input(Ref<InputEvent> p_event) {
|
||||
Ref<InputEventMouseButton> b = p_event;
|
||||
|
||||
@ -55,7 +225,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
|
||||
if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
|
||||
menu->set_position(get_screen_transform().xform(get_local_mouse_position()));
|
||||
menu->set_size(Vector2(1, 1));
|
||||
//menu->set_scale(get_global_transform().get_scale());
|
||||
_generate_context_menu();
|
||||
menu->popup();
|
||||
grab_focus();
|
||||
accept_event();
|
||||
@ -153,453 +323,163 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_control() && !k->get_shift() && !k->get_alt() && !k->get_command()) {
|
||||
uint32_t remap_key = KEY_UNKNOWN;
|
||||
switch (k->get_keycode()) {
|
||||
case KEY_F: {
|
||||
remap_key = KEY_RIGHT;
|
||||
} break;
|
||||
case KEY_B: {
|
||||
remap_key = KEY_LEFT;
|
||||
} break;
|
||||
case KEY_P: {
|
||||
remap_key = KEY_UP;
|
||||
} break;
|
||||
case KEY_N: {
|
||||
remap_key = KEY_DOWN;
|
||||
} break;
|
||||
case KEY_D: {
|
||||
remap_key = KEY_DELETE;
|
||||
} break;
|
||||
case KEY_H: {
|
||||
remap_key = KEY_BACKSPACE;
|
||||
} break;
|
||||
case KEY_A: {
|
||||
remap_key = KEY_HOME;
|
||||
} break;
|
||||
case KEY_E: {
|
||||
remap_key = KEY_END;
|
||||
} break;
|
||||
}
|
||||
|
||||
if (remap_key != KEY_UNKNOWN) {
|
||||
k->set_keycode(remap_key);
|
||||
k->set_control(false);
|
||||
if (context_menu_enabled) {
|
||||
if (k->is_action("ui_menu", true)) {
|
||||
Point2 pos = Point2(get_cursor_pixel_pos().x, (get_size().y + get_theme_font("font")->get_height(get_theme_font_size("font_size"))) / 2);
|
||||
menu->set_position(get_global_transform().xform(pos));
|
||||
menu->set_size(Vector2(1, 1));
|
||||
_generate_context_menu();
|
||||
menu->popup();
|
||||
menu->grab_focus();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int code = k->get_keycode();
|
||||
// Default is ENTER, KP_ENTER. Cannot use ui_accept as default includes SPACE
|
||||
if (k->is_action("ui_text_newline", true)) {
|
||||
emit_signal("text_entered", text);
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
|
||||
DisplayServer::get_singleton()->virtual_keyboard_hide();
|
||||
}
|
||||
}
|
||||
|
||||
if (k->get_command() && is_shortcut_keys_enabled()) {
|
||||
bool handled = true;
|
||||
|
||||
switch (code) {
|
||||
case (KEY_QUOTELEFT): { // Swap current input direction (primary cursor)
|
||||
|
||||
if (input_direction == TEXT_DIRECTION_LTR) {
|
||||
input_direction = TEXT_DIRECTION_RTL;
|
||||
} else {
|
||||
input_direction = TEXT_DIRECTION_LTR;
|
||||
}
|
||||
set_cursor_position(get_cursor_position());
|
||||
update();
|
||||
|
||||
} break;
|
||||
|
||||
case (KEY_X): { // CUT.
|
||||
|
||||
if (editable) {
|
||||
cut_text();
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case (KEY_C): { // COPY.
|
||||
|
||||
copy_text();
|
||||
|
||||
} break;
|
||||
|
||||
case (KEY_Y): // PASTE (Yank for unix users).
|
||||
case (KEY_V): { // PASTE.
|
||||
|
||||
if (editable) {
|
||||
paste_text();
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case (KEY_Z): { // Undo/redo.
|
||||
if (editable) {
|
||||
if (k->get_shift()) {
|
||||
redo();
|
||||
} else {
|
||||
undo();
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case (KEY_U): { // Delete from start to cursor.
|
||||
|
||||
if (editable) {
|
||||
deselect();
|
||||
text = text.substr(cursor_pos, text.length() - cursor_pos);
|
||||
_shape();
|
||||
set_cursor_position(0);
|
||||
_text_changed();
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case (KEY_K): { // Delete from cursor_pos to end.
|
||||
|
||||
if (editable) {
|
||||
deselect();
|
||||
text = text.substr(0, cursor_pos);
|
||||
_text_changed();
|
||||
}
|
||||
|
||||
} break;
|
||||
case (KEY_A): { // Select all.
|
||||
select();
|
||||
|
||||
} break;
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
case (KEY_LEFT): { // Go to start of text - like HOME key.
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
set_cursor_position(0);
|
||||
shift_selection_check_post(k->get_shift());
|
||||
} break;
|
||||
case (KEY_RIGHT): { // Go to end of text - like END key.
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
set_cursor_position(text.length());
|
||||
shift_selection_check_post(k->get_shift());
|
||||
} break;
|
||||
case (KEY_BACKSPACE): {
|
||||
if (!editable)
|
||||
break;
|
||||
|
||||
// If selected, delete the selection
|
||||
if (selection.enabled) {
|
||||
selection_delete();
|
||||
break;
|
||||
}
|
||||
|
||||
// Otherwise delete from cursor to beginning of text edit
|
||||
int current_pos = get_cursor_position();
|
||||
if (current_pos != 0) {
|
||||
delete_text(0, current_pos);
|
||||
}
|
||||
} break;
|
||||
#endif
|
||||
default: {
|
||||
handled = false;
|
||||
}
|
||||
if (is_shortcut_keys_enabled()) {
|
||||
if (k->is_action("ui_copy", true)) {
|
||||
copy_text();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
if (k->is_action("ui_text_select_all", true)) {
|
||||
select();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// Cut / Paste
|
||||
if (k->is_action("ui_cut", true)) {
|
||||
cut_text();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
if (k->is_action("ui_paste", true)) {
|
||||
paste_text();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// Undo / Redo
|
||||
if (k->is_action("ui_undo", true)) {
|
||||
undo();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
if (k->is_action("ui_redo", true)) {
|
||||
redo();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_reset_caret_blink_timer();
|
||||
if (!k->get_metakey()) {
|
||||
bool handled = true;
|
||||
switch (code) {
|
||||
case KEY_KP_ENTER:
|
||||
case KEY_ENTER: {
|
||||
emit_signal("text_entered", text);
|
||||
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
|
||||
DisplayServer::get_singleton()->virtual_keyboard_hide();
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case KEY_BACKSPACE: {
|
||||
if (!editable) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (selection.enabled) {
|
||||
selection_delete();
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_alt()) {
|
||||
#else
|
||||
if (k->get_alt()) {
|
||||
handled = false;
|
||||
break;
|
||||
} else if (k->get_command()) {
|
||||
#endif
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = words.size() - 1; i >= 0; i--) {
|
||||
if (words[i].x < cc) {
|
||||
cc = words[i].x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete_text(cc, cursor_pos);
|
||||
|
||||
set_cursor_position(cc);
|
||||
|
||||
} else {
|
||||
delete_char();
|
||||
}
|
||||
|
||||
} break;
|
||||
case KEY_KP_4: {
|
||||
if (k->get_unicode() != 0) {
|
||||
handled = false;
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case KEY_LEFT: {
|
||||
#ifndef APPLE_STYLE_KEYS
|
||||
if (!k->get_alt()) {
|
||||
#endif
|
||||
if (selection.enabled && !k->get_shift()) {
|
||||
set_cursor_position(selection.begin);
|
||||
deselect();
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
#ifndef APPLE_STYLE_KEYS
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_command()) {
|
||||
set_cursor_position(0);
|
||||
} else if (k->get_alt()) {
|
||||
#else
|
||||
if (k->get_alt()) {
|
||||
handled = false;
|
||||
break;
|
||||
} else if (k->get_command()) {
|
||||
#endif
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = words.size() - 1; i >= 0; i--) {
|
||||
if (words[i].x < cc) {
|
||||
cc = words[i].x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_cursor_position(cc);
|
||||
|
||||
} else {
|
||||
if (mid_grapheme_caret_enabled) {
|
||||
set_cursor_position(get_cursor_position() - 1);
|
||||
} else {
|
||||
set_cursor_position(TS->shaped_text_prev_grapheme_pos(text_rid, get_cursor_position()));
|
||||
}
|
||||
}
|
||||
|
||||
shift_selection_check_post(k->get_shift());
|
||||
|
||||
} break;
|
||||
case KEY_KP_6: {
|
||||
if (k->get_unicode() != 0) {
|
||||
handled = false;
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case KEY_RIGHT: {
|
||||
#ifndef APPLE_STYLE_KEYS
|
||||
if (!k->get_alt()) {
|
||||
#endif
|
||||
if (selection.enabled && !k->get_shift()) {
|
||||
set_cursor_position(selection.end);
|
||||
deselect();
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
#ifndef APPLE_STYLE_KEYS
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_command()) {
|
||||
set_cursor_position(text.length());
|
||||
} else if (k->get_alt()) {
|
||||
#else
|
||||
if (k->get_alt()) {
|
||||
handled = false;
|
||||
break;
|
||||
} else if (k->get_command()) {
|
||||
#endif
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = 0; i < words.size(); i++) {
|
||||
if (words[i].y > cc) {
|
||||
cc = words[i].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
set_cursor_position(cc);
|
||||
|
||||
} else {
|
||||
if (mid_grapheme_caret_enabled) {
|
||||
set_cursor_position(get_cursor_position() + 1);
|
||||
} else {
|
||||
set_cursor_position(TS->shaped_text_next_grapheme_pos(text_rid, get_cursor_position()));
|
||||
}
|
||||
}
|
||||
|
||||
shift_selection_check_post(k->get_shift());
|
||||
|
||||
} break;
|
||||
case KEY_UP: {
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
if (get_cursor_position() == 0) {
|
||||
handled = false;
|
||||
}
|
||||
set_cursor_position(0);
|
||||
shift_selection_check_post(k->get_shift());
|
||||
} break;
|
||||
case KEY_DOWN: {
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
if (get_cursor_position() == text.length()) {
|
||||
handled = false;
|
||||
}
|
||||
set_cursor_position(text.length());
|
||||
shift_selection_check_post(k->get_shift());
|
||||
} break;
|
||||
case KEY_DELETE: {
|
||||
if (!editable) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (k->get_shift() && !k->get_command() && !k->get_alt()) {
|
||||
cut_text();
|
||||
break;
|
||||
}
|
||||
|
||||
if (selection.enabled) {
|
||||
selection_delete();
|
||||
break;
|
||||
}
|
||||
|
||||
int text_len = text.length();
|
||||
|
||||
if (cursor_pos == text_len) {
|
||||
break; // Nothing to do.
|
||||
}
|
||||
|
||||
#ifdef APPLE_STYLE_KEYS
|
||||
if (k->get_alt()) {
|
||||
#else
|
||||
if (k->get_alt()) {
|
||||
handled = false;
|
||||
break;
|
||||
} else if (k->get_command()) {
|
||||
#endif
|
||||
int cc = cursor_pos;
|
||||
|
||||
Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text_rid);
|
||||
for (int i = 0; i < words.size(); i++) {
|
||||
if (words[i].y > cc) {
|
||||
cc = words[i].y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete_text(cursor_pos, cc);
|
||||
|
||||
} else {
|
||||
if (mid_grapheme_caret_enabled) {
|
||||
set_cursor_position(cursor_pos + 1);
|
||||
delete_char();
|
||||
} else {
|
||||
int cc = cursor_pos;
|
||||
set_cursor_position(TS->shaped_text_next_grapheme_pos(text_rid, cursor_pos));
|
||||
delete_text(cc, cursor_pos);
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
case KEY_KP_7: {
|
||||
if (k->get_unicode() != 0) {
|
||||
handled = false;
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case KEY_HOME: {
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
set_cursor_position(0);
|
||||
shift_selection_check_post(k->get_shift());
|
||||
} break;
|
||||
case KEY_KP_1: {
|
||||
if (k->get_unicode() != 0) {
|
||||
handled = false;
|
||||
break;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case KEY_END: {
|
||||
shift_selection_check_pre(k->get_shift());
|
||||
set_cursor_position(text.length());
|
||||
shift_selection_check_post(k->get_shift());
|
||||
} break;
|
||||
case KEY_MENU: {
|
||||
if (context_menu_enabled) {
|
||||
Point2 pos = Point2(get_cursor_pixel_pos().x, (get_size().y + get_theme_font("font")->get_height(get_theme_font_size("font_size"))) / 2);
|
||||
menu->set_position(get_global_transform().xform(pos));
|
||||
menu->set_size(Vector2(1, 1));
|
||||
//menu->set_scale(get_global_transform().get_scale());
|
||||
menu->popup();
|
||||
menu->grab_focus();
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
handled = false;
|
||||
} break;
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
accept_event();
|
||||
} else if (!k->get_command()) {
|
||||
if (k->get_unicode() >= 32 && k->get_keycode() != KEY_DELETE) {
|
||||
if (editable) {
|
||||
selection_delete();
|
||||
char32_t ucodestr[2] = { (char32_t)k->get_unicode(), 0 };
|
||||
int prev_len = text.length();
|
||||
append_at_cursor(ucodestr);
|
||||
if (text.length() != prev_len) {
|
||||
_text_changed();
|
||||
}
|
||||
accept_event();
|
||||
}
|
||||
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
// BACKSPACE
|
||||
if (k->is_action("ui_text_backspace_all_to_left", true)) {
|
||||
_backspace(false, true);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_backspace_word", true)) {
|
||||
_backspace(true);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_backspace", true)) {
|
||||
_backspace();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
// DELETE
|
||||
if (k->is_action("ui_text_delete_all_to_right", true)) {
|
||||
_delete(false, true);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_delete_word", true)) {
|
||||
_delete(true);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_delete", true)) {
|
||||
_delete();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// Cursor Movement
|
||||
|
||||
k = k->duplicate();
|
||||
bool shift_pressed = k->get_shift();
|
||||
// Remove shift or else actions will not match. Use above variable for selection.
|
||||
k->set_shift(false);
|
||||
|
||||
if (k->is_action("ui_text_caret_word_left", true)) {
|
||||
_move_cursor_left(shift_pressed, true);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_caret_left", true)) {
|
||||
_move_cursor_left(shift_pressed);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_caret_word_right", true)) {
|
||||
_move_cursor_right(shift_pressed, true);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_caret_right", true)) {
|
||||
_move_cursor_right(shift_pressed, false);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// Up = Home, Down = End
|
||||
if (k->is_action("ui_text_caret_up", true) || k->is_action("ui_text_caret_line_start", true) || k->is_action("ui_text_caret_page_up", true)) {
|
||||
_move_cursor_start(shift_pressed);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
if (k->is_action("ui_text_caret_down", true) || k->is_action("ui_text_caret_line_end", true) || k->is_action("ui_text_caret_page_down", true)) {
|
||||
_move_cursor_end(shift_pressed);
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// Misc
|
||||
if (k->is_action("ui_swap_input_direction", true)) {
|
||||
_swap_current_input_direction();
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
_reset_caret_blink_timer();
|
||||
|
||||
// Allow unicode handling if:
|
||||
// * No Modifiers are pressed (except shift)
|
||||
bool allow_unicode_handling = !(k->get_command() || k->get_control() || k->get_alt() || k->get_metakey());
|
||||
|
||||
if (allow_unicode_handling && editable && k->get_unicode() >= 32) {
|
||||
// Handle Unicode (if no modifiers active)
|
||||
selection_delete();
|
||||
char32_t ucodestr[2] = { (char32_t)k->get_unicode(), 0 };
|
||||
int prev_len = text.length();
|
||||
append_at_cursor(ucodestr);
|
||||
if (text.length() != prev_len) {
|
||||
_text_changed();
|
||||
}
|
||||
accept_event();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1013,13 +893,17 @@ void LineEdit::copy_text() {
|
||||
}
|
||||
|
||||
void LineEdit::cut_text() {
|
||||
if (selection.enabled && !pass) {
|
||||
if (editable && selection.enabled && !pass) {
|
||||
DisplayServer::get_singleton()->clipboard_set(text.substr(selection.begin, selection.end - selection.begin));
|
||||
selection_delete();
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::paste_text() {
|
||||
if (!editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Strip escape characters like \n and \t as they can't be displayed on LineEdit.
|
||||
String paste_buffer = DisplayServer::get_singleton()->clipboard_get().strip_escapes();
|
||||
|
||||
@ -1040,6 +924,10 @@ void LineEdit::paste_text() {
|
||||
}
|
||||
|
||||
void LineEdit::undo() {
|
||||
if (!editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (undo_stack_pos == nullptr) {
|
||||
if (undo_stack.size() <= 1) {
|
||||
return;
|
||||
@ -1059,6 +947,10 @@ void LineEdit::undo() {
|
||||
}
|
||||
|
||||
void LineEdit::redo() {
|
||||
if (!editable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (undo_stack_pos == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -2060,25 +1952,50 @@ void LineEdit::_create_undo_state() {
|
||||
undo_stack.push_back(op);
|
||||
}
|
||||
|
||||
int LineEdit::_get_menu_action_accelerator(const String &p_action) {
|
||||
const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(p_action);
|
||||
if (!events) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use first event in the list for the accelerator.
|
||||
const List<Ref<InputEvent>>::Element *first_event = events->front();
|
||||
if (!first_event) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Ref<InputEventKey> event = first_event->get();
|
||||
if (event.is_null()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use physical keycode if non-zero
|
||||
if (event->get_physical_keycode() != 0) {
|
||||
return event->get_physical_keycode_with_modifiers();
|
||||
} else {
|
||||
return event->get_keycode_with_modifiers();
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::_generate_context_menu() {
|
||||
// Reorganize context menu.
|
||||
menu->clear();
|
||||
if (editable) {
|
||||
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_X : 0);
|
||||
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
|
||||
}
|
||||
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_C : 0);
|
||||
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
|
||||
if (editable) {
|
||||
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_V : 0);
|
||||
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
|
||||
}
|
||||
menu->add_separator();
|
||||
if (is_selecting_enabled()) {
|
||||
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_A : 0);
|
||||
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
|
||||
}
|
||||
if (editable) {
|
||||
menu->add_item(RTR("Clear"), MENU_CLEAR);
|
||||
menu->add_separator();
|
||||
menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_Z : 0);
|
||||
menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Z : 0);
|
||||
menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
|
||||
menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0);
|
||||
}
|
||||
menu->add_separator();
|
||||
menu->add_submenu_item(RTR("Text writing direction"), "DirMenu");
|
||||
|
@ -163,6 +163,7 @@ private:
|
||||
void _clear_redo();
|
||||
void _create_undo_state();
|
||||
|
||||
int _get_menu_action_accelerator(const String &p_action);
|
||||
void _generate_context_menu();
|
||||
|
||||
void _shape();
|
||||
@ -188,6 +189,14 @@ private:
|
||||
|
||||
void _editor_settings_changed();
|
||||
|
||||
void _swap_current_input_direction();
|
||||
void _move_cursor_left(bool p_select, bool p_move_by_word = false);
|
||||
void _move_cursor_right(bool p_select, bool p_move_by_word = false);
|
||||
void _move_cursor_start(bool p_select);
|
||||
void _move_cursor_end(bool p_select);
|
||||
void _backspace(bool p_word = false, bool p_all_to_left = false);
|
||||
void _delete(bool p_word = false, bool p_all_to_right = false);
|
||||
|
||||
void _gui_input(Ref<InputEvent> p_event);
|
||||
void _notification(int p_what);
|
||||
|
||||
|
@ -1575,53 +1575,36 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
|
||||
Ref<InputEventKey> k = p_event;
|
||||
|
||||
if (k.is_valid()) {
|
||||
if (k->is_pressed() && !k->get_alt() && !k->get_shift()) {
|
||||
if (k->is_pressed()) {
|
||||
bool handled = false;
|
||||
switch (k->get_keycode()) {
|
||||
case KEY_PAGEUP: {
|
||||
if (vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() - vscroll->get_page());
|
||||
handled = true;
|
||||
}
|
||||
} break;
|
||||
case KEY_PAGEDOWN: {
|
||||
if (vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() + vscroll->get_page());
|
||||
handled = true;
|
||||
}
|
||||
} break;
|
||||
case KEY_UP: {
|
||||
if (vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
|
||||
handled = true;
|
||||
}
|
||||
} break;
|
||||
case KEY_DOWN: {
|
||||
if (vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
|
||||
handled = true;
|
||||
}
|
||||
} break;
|
||||
case KEY_HOME: {
|
||||
if (vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(0);
|
||||
handled = true;
|
||||
}
|
||||
} break;
|
||||
case KEY_END: {
|
||||
if (vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_max());
|
||||
handled = true;
|
||||
}
|
||||
} break;
|
||||
case KEY_INSERT:
|
||||
case KEY_C: {
|
||||
if (k->get_command()) {
|
||||
selection_copy();
|
||||
handled = true;
|
||||
}
|
||||
|
||||
} break;
|
||||
if (k->is_action("ui_pageup") && vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() - vscroll->get_page());
|
||||
handled = true;
|
||||
}
|
||||
if (k->is_action("ui_pagedown") && vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() + vscroll->get_page());
|
||||
handled = true;
|
||||
}
|
||||
if (k->is_action("ui_up") && vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
|
||||
handled = true;
|
||||
}
|
||||
if (k->is_action("ui_down") && vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
|
||||
handled = true;
|
||||
}
|
||||
if (k->is_action("ui_home") && vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(0);
|
||||
handled = true;
|
||||
}
|
||||
if (k->is_action("ui_end") && vscroll->is_visible_in_tree()) {
|
||||
vscroll->set_value(vscroll->get_max());
|
||||
handled = true;
|
||||
}
|
||||
if (k->is_action("ui_copy")) {
|
||||
selection_copy();
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -408,6 +408,7 @@ private:
|
||||
int _get_control_height() const;
|
||||
|
||||
Point2 _get_local_mouse_pos() const;
|
||||
int _get_menu_action_accelerator(const String &p_action);
|
||||
|
||||
void _reset_caret_blink_timer();
|
||||
void _toggle_draw_caret();
|
||||
@ -441,6 +442,26 @@ private:
|
||||
int _calculate_spaces_till_next_left_indent(int column);
|
||||
int _calculate_spaces_till_next_right_indent(int column);
|
||||
|
||||
// Methods used in shortcuts
|
||||
void _swap_current_input_direction();
|
||||
void _new_line(bool p_split_current = true, bool p_above = false);
|
||||
void _indent_right();
|
||||
void _indent_left();
|
||||
void _move_cursor_left(bool p_select, bool p_move_by_word = false);
|
||||
void _move_cursor_right(bool p_select, bool p_move_by_word = false);
|
||||
void _move_cursor_up(bool p_select);
|
||||
void _move_cursor_down(bool p_select);
|
||||
void _move_cursor_to_line_start(bool p_select);
|
||||
void _move_cursor_to_line_end(bool p_select);
|
||||
void _move_cursor_page_up(bool p_select);
|
||||
void _move_cursor_page_down(bool p_select);
|
||||
void _backspace(bool p_word = false, bool p_all_to_left = false);
|
||||
void _delete(bool p_word = false, bool p_all_to_right = false);
|
||||
void _delete_selection();
|
||||
void _move_cursor_document_start(bool p_select);
|
||||
void _move_cursor_document_end(bool p_select);
|
||||
void _handle_unicode_character(uint32_t unicode, bool p_had_selection, bool p_update_auto_complete);
|
||||
|
||||
protected:
|
||||
struct Cache {
|
||||
Ref<Texture2D> tab_icon;
|
||||
@ -639,8 +660,8 @@ public:
|
||||
int get_row_height() const;
|
||||
void backspace_at_cursor();
|
||||
|
||||
void indent_left();
|
||||
void indent_right();
|
||||
void indent_selected_lines_left();
|
||||
void indent_selected_lines_right();
|
||||
int get_indent_level(int p_line) const;
|
||||
bool is_line_comment(int p_line) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user