summaryrefslogtreecommitdiff
path: root/editor/editor_settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_settings.cpp')
-rw-r--r--editor/editor_settings.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 740e73e18c..1820804cfe 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -1409,7 +1409,7 @@ Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
// 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);
+ const OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
if (builtin_default) {
sc.instantiate();
sc->set_event(builtin_default.get().front()->get());
@@ -1444,6 +1444,23 @@ Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path) {
return sc;
}
+void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode) {
+ Ref<Shortcut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
+ ERR_FAIL_COND_MSG(!sc.is_valid(), "Used ED_SHORTCUT_OVERRIDE with invalid shortcut: " + p_path + ".");
+
+ // Only add the override if the OS supports the provided feature.
+ if (OS::get_singleton()->has_feature(p_feature)) {
+ Ref<InputEventKey> ie;
+ if (p_keycode) {
+ ie = InputEventKey::create_reference(p_keycode);
+ }
+
+ // Directly override the existing shortcut.
+ sc->set_event(ie);
+ sc->set_meta("original", ie);
+ }
+}
+
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode) {
#ifdef OSX_ENABLED
// Use Cmd+Backspace as a general replacement for Delete shortcuts on macOS
@@ -1454,14 +1471,7 @@ Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keyc
Ref<InputEventKey> ie;
if (p_keycode) {
- ie.instantiate();
-
- ie->set_unicode(p_keycode & KEY_CODE_MASK);
- ie->set_keycode(p_keycode & KEY_CODE_MASK);
- ie->set_shift_pressed(bool(p_keycode & KEY_MASK_SHIFT));
- ie->set_alt_pressed(bool(p_keycode & KEY_MASK_ALT));
- ie->set_ctrl_pressed(bool(p_keycode & KEY_MASK_CTRL));
- ie->set_meta_pressed(bool(p_keycode & KEY_MASK_META));
+ ie = InputEventKey::create_reference(p_keycode);
}
if (!EditorSettings::get_singleton()) {
@@ -1502,15 +1512,23 @@ void EditorSettings::set_builtin_action_override(const String &p_name, const Arr
// 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);
+ OrderedHashMap<String, List<Ref<InputEvent>>>::ConstElement builtin_default = InputMap::get_singleton()->get_builtins_with_feature_overrides_applied().find(p_name);
if (builtin_default) {
List<Ref<InputEvent>> builtin_events = builtin_default.get();
- if (p_events.size() == builtin_events.size()) {
+ // In the editor we only care about key events.
+ List<Ref<InputEventKey>> builtin_key_events;
+ for (Ref<InputEventKey> iek : builtin_events) {
+ if (iek.is_valid()) {
+ builtin_key_events.push_back(iek);
+ }
+ }
+
+ if (p_events.size() == builtin_key_events.size()) {
int event_idx = 0;
// Check equality of each event.
- for (const Ref<InputEvent> &E : builtin_events) {
+ for (const Ref<InputEventKey> &E : builtin_key_events) {
if (!E->is_match(p_events[event_idx])) {
same_as_builtin = false;
break;