浏览代码

Merge pull request #241 from Unity-Technologies/fix_shortcuts

fix shortcuts for ide
/main
GitHub 3 年前
当前提交
81f7ced6
共有 6 个文件被更改,包括 149 次插入52 次删除
  1. 3
      com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
  2. 67
      com.unity.uiwidgets/Runtime/services/keyboard_key.cs
  3. 2
      com.unity.uiwidgets/Runtime/widgets/actions.cs
  4. 31
      com.unity.uiwidgets/Runtime/widgets/shortcuts.cs
  5. 95
      com.unity.uiwidgets/Runtime/widgets/raw_keyoard_listener.cs
  6. 3
      com.unity.uiwidgets/Runtime/widgets/raw_keyoard_listener.cs.meta

3
com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs


var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnMouseScroll(delta: delta, pos: pos);
}
else if (evt.isKey) {
_wrapper.OnKeyDown(e: evt);
}
}
protected virtual void main() {

67
com.unity.uiwidgets/Runtime/services/keyboard_key.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using UnityEngine;
namespace Unity.UIWidgets.services {
public abstract class KeyboardKey : Diagnosticable {

public override int GetHashCode() {
unchecked {
int hashCode = (int) keyId;
hashCode = (hashCode * 397) ^ (debugName != null ? debugName.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (keyLabel != null ? keyLabel.GetHashCode() : 0);
protected LogicalKeyboardKey(long keyId, string debugName = null, string keyLabel = null) : base() {
public LogicalKeyboardKey(long keyId, string debugName = null, string keyLabel = null) : base() {
D.assert(keyId != null);
this.keyId = keyId;
this.debugName = debugName;

debugName: foundation_.kReleaseMode ? null : "Usb Error Undefined");
public static readonly LogicalKeyboardKey keyA = new LogicalKeyboardKey(0x00000000061, keyLabel: "a",
public static readonly LogicalKeyboardKey keyA = new LogicalKeyboardKey((long)KeyCode.A, keyLabel: "a",
public static readonly LogicalKeyboardKey keyB = new LogicalKeyboardKey(0x00000000062, keyLabel: "b",
public static readonly LogicalKeyboardKey keyB = new LogicalKeyboardKey((long)KeyCode.B, keyLabel: "b",
public static readonly LogicalKeyboardKey keyC = new LogicalKeyboardKey(0x00000000063, keyLabel: "c",
public static readonly LogicalKeyboardKey keyC = new LogicalKeyboardKey((long)KeyCode.C, keyLabel: "c",
public static readonly LogicalKeyboardKey keyD = new LogicalKeyboardKey(0x00000000064, keyLabel: "d",
public static readonly LogicalKeyboardKey keyD = new LogicalKeyboardKey((long)KeyCode.D, keyLabel: "d",
public static readonly LogicalKeyboardKey keyE = new LogicalKeyboardKey(0x00000000065, keyLabel: "e",
public static readonly LogicalKeyboardKey keyE = new LogicalKeyboardKey((long)KeyCode.E, keyLabel: "e",
public static readonly LogicalKeyboardKey keyF = new LogicalKeyboardKey(0x00000000066, keyLabel: "f",
public static readonly LogicalKeyboardKey keyF = new LogicalKeyboardKey((long)KeyCode.F, keyLabel: "f",
public static readonly LogicalKeyboardKey keyG = new LogicalKeyboardKey(0x00000000067, keyLabel: "g",
public static readonly LogicalKeyboardKey keyG = new LogicalKeyboardKey((long)KeyCode.G, keyLabel: "g",
public static readonly LogicalKeyboardKey keyH = new LogicalKeyboardKey(0x00000000068, keyLabel: "h",
public static readonly LogicalKeyboardKey keyH = new LogicalKeyboardKey((long)KeyCode.H, keyLabel: "h",
public static readonly LogicalKeyboardKey keyI = new LogicalKeyboardKey(0x00000000069, keyLabel: "i",
public static readonly LogicalKeyboardKey keyI = new LogicalKeyboardKey((long)KeyCode.I, keyLabel: "i",
public static readonly LogicalKeyboardKey keyJ = new LogicalKeyboardKey(0x0000000006a, keyLabel: "j",
public static readonly LogicalKeyboardKey keyJ = new LogicalKeyboardKey((long)KeyCode.J, keyLabel: "j",
public static readonly LogicalKeyboardKey keyK = new LogicalKeyboardKey(0x0000000006b, keyLabel: "k",
public static readonly LogicalKeyboardKey keyK = new LogicalKeyboardKey((long)KeyCode.K, keyLabel: "k",
public static readonly LogicalKeyboardKey keyL = new LogicalKeyboardKey(0x0000000006c, keyLabel: "l",
public static readonly LogicalKeyboardKey keyL = new LogicalKeyboardKey((long)KeyCode.L, keyLabel: "l",
public static readonly LogicalKeyboardKey keyM = new LogicalKeyboardKey(0x0000000006d, keyLabel: "m",
public static readonly LogicalKeyboardKey keyM = new LogicalKeyboardKey((long)KeyCode.M, keyLabel: "m",
public static readonly LogicalKeyboardKey keyN = new LogicalKeyboardKey(0x0000000006e, keyLabel: "n",
public static readonly LogicalKeyboardKey keyN = new LogicalKeyboardKey((long)KeyCode.N, keyLabel: "n",
public static readonly LogicalKeyboardKey keyO = new LogicalKeyboardKey(0x0000000006f, keyLabel: "o",
public static readonly LogicalKeyboardKey keyO = new LogicalKeyboardKey((long)KeyCode.O, keyLabel: "o",
public static readonly LogicalKeyboardKey keyP = new LogicalKeyboardKey(0x00000000070, keyLabel: "p",
public static readonly LogicalKeyboardKey keyP = new LogicalKeyboardKey((long)KeyCode.P, keyLabel: "p",
public static readonly LogicalKeyboardKey keyQ = new LogicalKeyboardKey(0x00000000071, keyLabel: "q",
public static readonly LogicalKeyboardKey keyQ = new LogicalKeyboardKey((long)KeyCode.Q, keyLabel: "q",
public static readonly LogicalKeyboardKey keyR = new LogicalKeyboardKey(0x00000000072, keyLabel: "",
public static readonly LogicalKeyboardKey keyR = new LogicalKeyboardKey((long)KeyCode.R, keyLabel: "",
public static readonly LogicalKeyboardKey keyS = new LogicalKeyboardKey(0x00000000073, keyLabel: "s",
public static readonly LogicalKeyboardKey keyS = new LogicalKeyboardKey((long)KeyCode.S, keyLabel: "s",
public static readonly LogicalKeyboardKey keyT = new LogicalKeyboardKey(0x00000000074, keyLabel: "t",
public static readonly LogicalKeyboardKey keyT = new LogicalKeyboardKey((long)KeyCode.T, keyLabel: "t",
public static readonly LogicalKeyboardKey keyU = new LogicalKeyboardKey(0x00000000075, keyLabel: "u",
public static readonly LogicalKeyboardKey keyU = new LogicalKeyboardKey((long)KeyCode.U, keyLabel: "u",
public static readonly LogicalKeyboardKey keyV = new LogicalKeyboardKey(0x00000000076, keyLabel: "v",
public static readonly LogicalKeyboardKey keyV = new LogicalKeyboardKey((long)KeyCode.V, keyLabel: "v",
public static readonly LogicalKeyboardKey keyW = new LogicalKeyboardKey(0x00000000077, keyLabel: "w",
public static readonly LogicalKeyboardKey keyW = new LogicalKeyboardKey((long)KeyCode.W, keyLabel: "w",
public static readonly LogicalKeyboardKey keyX = new LogicalKeyboardKey(0x00000000078, keyLabel: "x",
public static readonly LogicalKeyboardKey keyX = new LogicalKeyboardKey((long)KeyCode.X, keyLabel: "x",
public static readonly LogicalKeyboardKey keyY = new LogicalKeyboardKey(0x00000000079, keyLabel: "y",
public static readonly LogicalKeyboardKey keyY = new LogicalKeyboardKey((long)KeyCode.Y, keyLabel: "y",
public static readonly LogicalKeyboardKey keyZ = new LogicalKeyboardKey(0x0000000007a, keyLabel: "z",
public static readonly LogicalKeyboardKey keyZ = new LogicalKeyboardKey((long)KeyCode.Z, keyLabel: "z",
debugName: foundation_.kReleaseMode ? null : "Key Z");

public static readonly LogicalKeyboardKey enter =
new LogicalKeyboardKey(0x00100070028, debugName: foundation_.kReleaseMode ? null : "Ente");
new LogicalKeyboardKey((long)KeyCode.Return, debugName: foundation_.kReleaseMode ? null : "Ente");
new LogicalKeyboardKey(0x00100070029, debugName: foundation_.kReleaseMode ? null : "Escape");
new LogicalKeyboardKey((long)KeyCode.Escape, debugName: foundation_.kReleaseMode ? null : "Escape");
new LogicalKeyboardKey(0x0010007002a, debugName: foundation_.kReleaseMode ? null : "Backspace");
new LogicalKeyboardKey((long)KeyCode.Backspace, debugName: foundation_.kReleaseMode ? null : "Backspace");
new LogicalKeyboardKey(0x0010007002b, debugName: foundation_.kReleaseMode ? null : "Tab");
new LogicalKeyboardKey((long)KeyCode.Tab, debugName: foundation_.kReleaseMode ? null : "Tab");
public static readonly LogicalKeyboardKey space = new LogicalKeyboardKey(0x00000000020, keyLabel: " ",
public static readonly LogicalKeyboardKey space = new LogicalKeyboardKey((long)KeyCode.Space, keyLabel: " ",
debugName: foundation_.kReleaseMode ? null : "Space");

2
com.unity.uiwidgets/Runtime/widgets/actions.cs


}
actionsElement = element;
Actions actions = element.widget as Actions;
action = actions.actions[intent.key]?.Invoke();
action = actions.actions.getOrDefault(intent.key)?.Invoke();
return action == null;
}

31
com.unity.uiwidgets/Runtime/widgets/shortcuts.cs


public static readonly List<int> _tempHashStore4 = new List<int> {0, 0, 0, 0}; // used to sort exactly 4 keys
public readonly HashSet<T> _keys;
public int _hashCode;
public KeySet(
T key1,
T key2 = default,

return true;
}
return Equals(objA: _keys, objB: other._keys) && _hashCode == other._hashCode;
return _keys.SetEquals(other._keys);
}
public override bool Equals(object obj) {

public override int GetHashCode() {
unchecked {
if (_hashCode != 0) {
return _hashCode;
}
var h1 = iterator.GetHashCode();
var h1 = iterator.Current.GetHashCode();
return _hashCode = h1;
return h1;
var h2 = iterator.GetHashCode();
var h2 = iterator.Current.GetHashCode();
return _hashCode = h1 < h2
return h1 < h2
? ((h1 != null ? h1.GetHashCode() : 0) * 397) ^ h2.GetHashCode()
: ((h2 != null ? h2.GetHashCode() : 0) * 397) ^ h1.GetHashCode();
}

sortedHashes[0] = h1;
sortedHashes[1] = h2;
iterator.MoveNext();
sortedHashes[2] = iterator.GetHashCode();
sortedHashes[2] = iterator.Current.GetHashCode();
sortedHashes[3] = iterator.GetHashCode();
sortedHashes[3] = iterator.Current.GetHashCode();
return _hashCode = (_hashCode * 397) ^ (sortedHashes != null ? sortedHashes.GetHashCode() : 0);
var _hashCode = sortedHashes[0].GetHashCode();
for (var i = 1; i < sortedHashes.Count; i++) {
_hashCode = (_hashCode * 397) ^ (sortedHashes[i].GetHashCode());
}
return _hashCode;
}
}

notifyListeners();
}
}
public bool handleKeypress(
public virtual bool handleKeypress(
BuildContext context,
RawKeyEvent rawKeyEvent,
LogicalKeySet keysPressed = null

95
com.unity.uiwidgets/Runtime/widgets/raw_keyoard_listener.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
namespace Unity.UIWidgets.widgets {
public class RawKeyboardListener : StatefulWidget {
public RawKeyboardListener(
Key key = null,
FocusNode focusNode = null,
bool autofocus = false,
ValueChanged<RawKeyEvent> onKey = null,
Widget child = null
) : base(key: key) {
D.assert(focusNode != null);
D.assert(child != null);
this.focusNode = focusNode;
this.autofocus = autofocus;
this.onKey = onKey;
this.child = child;
}
public readonly FocusNode focusNode;
public readonly bool autofocus;
public readonly ValueChanged<RawKeyEvent> onKey;
public readonly Widget child;
public override State createState() => new _RawKeyboardListenerState();
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<FocusNode>("focusNode", focusNode));
}
}
public class _RawKeyboardListenerState : State<RawKeyboardListener> {
public override void initState() {
base.initState();
widget.focusNode.addListener(_handleFocusChanged);
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
var _oldWidgt = oldWidget as RawKeyboardListener;
base.didUpdateWidget(oldWidget);
if (widget.focusNode != _oldWidgt.focusNode) {
_oldWidgt.focusNode.removeListener(_handleFocusChanged);
widget.focusNode.addListener(_handleFocusChanged);
}
}
public override void dispose() {
widget.focusNode.removeListener(_handleFocusChanged);
_detachKeyboardIfAttached();
base.dispose();
}
void _handleFocusChanged() {
if (widget.focusNode.hasFocus)
_attachKeyboardIfDetached();
else
_detachKeyboardIfAttached();
}
bool _listening = false;
void _attachKeyboardIfDetached() {
if (_listening)
return;
RawKeyboard.instance.addListener(_handleRawKeyEvent);
_listening = true;
}
void _detachKeyboardIfAttached() {
if (!_listening)
return;
RawKeyboard.instance.removeListener(_handleRawKeyEvent);
_listening = false;
}
void _handleRawKeyEvent(RawKeyEvent evt) {
if (widget.onKey != null)
widget.onKey(evt);
}
public override Widget build(BuildContext context) {
return new Focus(
focusNode: widget.focusNode,
autofocus: widget.autofocus,
child: widget.child
);
}
}
}

3
com.unity.uiwidgets/Runtime/widgets/raw_keyoard_listener.cs.meta


fileFormatVersion: 2
guid: ceed7889e4244dc09b9b2d9cb5151900
timeCreated: 1629712713
正在加载...
取消
保存