Merge pull request #14337 from thoys/feat/create/forwardWindowShortcuts

[CreateApp] make shortcuts work from windows
This commit is contained in:
Brad Hefta-Gaub 2018-11-14 12:56:27 -08:00 committed by GitHub
commit 6ffee02b4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 237 additions and 89 deletions

View file

@ -26,6 +26,8 @@ Item {
property bool interactive: false
property bool blurOnCtrlShift: true
StylesUIt.HifiConstants {
id: hifi
}
@ -180,8 +182,8 @@ Item {
}
Keys.onPressed: {
if ((event.modifiers & Qt.ShiftModifier) && (event.modifiers & Qt.ControlModifier)) {
webViewCore.focus = false;
if (blurOnCtrlShift && (event.modifiers & Qt.ShiftModifier) && (event.modifiers & Qt.ControlModifier)) {
webViewCore.focus = false;
}
}
}

View file

@ -22,6 +22,7 @@ Item {
property bool punctuationMode: false
property bool passwordField: false
property alias flickable: webroot.interactive
property alias blurOnCtrlShift: webroot.blurOnCtrlShift
function stop() {
webroot.stop();

View file

@ -12,4 +12,5 @@ WebView {
id: entityListToolWebView
url: Paths.defaultScripts + "/system/html/entityList.html"
enabled: true
blurOnCtrlShift: false
}

View file

@ -245,6 +245,7 @@ TabBar {
id: entityListToolWebView
url: Paths.defaultScripts + "/system/html/entityList.html"
enabled: true
blurOnCtrlShift: false
}
}
}
@ -260,6 +261,7 @@ TabBar {
id: entityPropertiesWebView
url: Paths.defaultScripts + "/system/html/entityProperties.html"
enabled: true
blurOnCtrlShift: false
}
}
}
@ -275,6 +277,7 @@ TabBar {
id: gridControlsWebView
url: Paths.defaultScripts + "/system/html/gridControls.html"
enabled: true
blurOnCtrlShift: false
}
}
}

View file

@ -251,6 +251,7 @@ TabBar {
id: entityPropertiesWebView
url: Paths.defaultScripts + "/system/html/entityProperties.html"
enabled: true
blurOnCtrlShift: false
}
}
}
@ -266,6 +267,7 @@ TabBar {
id: gridControlsWebView
url: Paths.defaultScripts + "/system/html/gridControls.html"
enabled: true
blurOnCtrlShift: false
}
}
}

View file

@ -2,4 +2,5 @@ WebView {
id: entityListToolWebView
url: Paths.defaultScripts + "/system/html/entityList.html"
enabled: true
blurOnCtrlShift: false
}

View file

@ -4039,21 +4039,23 @@ void Application::keyPressEvent(QKeyEvent* event) {
break;
case Qt::Key_P: {
AudioInjectorOptions options;
options.localOnly = true;
options.stereo = true;
Setting::Handle<bool> notificationSounds{ MenuOption::NotificationSounds, true};
Setting::Handle<bool> notificationSoundSnapshot{ MenuOption::NotificationSoundsSnapshot, true};
if (notificationSounds.get() && notificationSoundSnapshot.get()) {
if (_snapshotSoundInjector) {
_snapshotSoundInjector->setOptions(options);
_snapshotSoundInjector->restart();
} else {
QByteArray samples = _snapshotSound->getByteArray();
_snapshotSoundInjector = AudioInjector::playSound(samples, options);
if (!isShifted && !isMeta && !isOption && !event->isAutoRepeat()) {
AudioInjectorOptions options;
options.localOnly = true;
options.stereo = true;
Setting::Handle<bool> notificationSounds{ MenuOption::NotificationSounds, true };
Setting::Handle<bool> notificationSoundSnapshot{ MenuOption::NotificationSoundsSnapshot, true };
if (notificationSounds.get() && notificationSoundSnapshot.get()) {
if (_snapshotSoundInjector) {
_snapshotSoundInjector->setOptions(options);
_snapshotSoundInjector->restart();
} else {
QByteArray samples = _snapshotSound->getByteArray();
_snapshotSoundInjector = AudioInjector::playSound(samples, options);
}
}
takeSnapshot(true);
}
takeSnapshot(true);
break;
}

View file

@ -12,7 +12,8 @@
/* global Script, SelectionDisplay, LightOverlayManager, CameraManager, Grid, GridTool, EntityListTool, Vec3, SelectionManager,
Overlays, OverlayWebWindow, UserActivityLogger, Settings, Entities, Tablet, Toolbars, Messages, Menu, Camera,
progressDialog, tooltip, MyAvatar, Quat, Controller, Clipboard, HMD, UndoStack, OverlaySystemWindow */
progressDialog, tooltip, MyAvatar, Quat, Controller, Clipboard, HMD, UndoStack, OverlaySystemWindow,
keyUpEventFromUIWindow:true */
(function() { // BEGIN LOCAL_SCOPE
@ -113,7 +114,6 @@ selectionManager.addEventListener(function () {
entityIconOverlayManager.updatePositions();
});
var KEY_P = 80; //Key code for letter p used for Parenting hotkey.
var DEGREES_TO_RADIANS = Math.PI / 180.0;
var RADIANS_TO_DEGREES = 180.0 / Math.PI;
@ -1964,14 +1964,6 @@ var keyReleaseEvent = function (event) {
if (isActive) {
cameraManager.keyReleaseEvent(event);
}
// since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items
if (event.key === KEY_P && event.isControl && !event.isAutoRepeat) {
if (event.isShifted) {
unparentSelectedEntities();
} else {
parentSelectedEntities();
}
}
};
Controller.keyReleaseEvent.connect(keyReleaseEvent);
Controller.keyPressEvent.connect(keyPressEvent);
@ -2365,10 +2357,6 @@ var PropertiesTool = function (opts) {
}
pushCommandForSelections();
selectionManager._update(false, this);
} else if (data.type === 'parent') {
parentSelectedEntities();
} else if (data.type === 'unparent') {
unparentSelectedEntities();
} else if (data.type === 'saveUserData' || data.type === 'saveMaterialData') {
//the event bridge and json parsing handle our avatar id string differently.
var actualID = data.id.split('"')[1];
@ -2681,9 +2669,14 @@ function whenReleased(fn) {
};
}
var isOnMacPlatform = Controller.getValue(Controller.Hardware.Application.PlatformMac);
var mapping = Controller.newMapping(CONTROLLER_MAPPING_NAME);
mapping.from([Controller.Hardware.Keyboard.Delete]).when([!Controller.Hardware.Application.PlatformMac]).to(deleteKey);
mapping.from([Controller.Hardware.Keyboard.Backspace]).when([Controller.Hardware.Application.PlatformMac]).to(deleteKey);
if (isOnMacPlatform) {
mapping.from([Controller.Hardware.Keyboard.Backspace]).to(deleteKey);
} else {
mapping.from([Controller.Hardware.Keyboard.Delete]).to(deleteKey);
}
mapping.from([Controller.Hardware.Keyboard.T]).to(toggleKey);
mapping.from([Controller.Hardware.Keyboard.F]).to(focusKey);
mapping.from([Controller.Hardware.Keyboard.G]).to(gridKey);
@ -2706,6 +2699,53 @@ mapping.from([Controller.Hardware.Keyboard.Z])
.to(whenPressed(function() { undoHistory.redo() }));
mapping.from([Controller.Hardware.Keyboard.P])
.when([Controller.Hardware.Keyboard.Control, Controller.Hardware.Keyboard.Shift])
.to(whenReleased(function() { unparentSelectedEntities(); }));
mapping.from([Controller.Hardware.Keyboard.P])
.when([Controller.Hardware.Keyboard.Control, !Controller.Hardware.Keyboard.Shift])
.to(whenReleased(function() { parentSelectedEntities(); }));
keyUpEventFromUIWindow = function(keyUpEvent) {
var WANT_DEBUG_MISSING_SHORTCUTS = false;
var pressedValue = 0.0;
if ((!isOnMacPlatform && keyUpEvent.keyCodeString === "Delete")
|| (isOnMacPlatform && keyUpEvent.keyCodeString === "Backspace")) {
deleteKey(pressedValue);
} else if (keyUpEvent.keyCodeString === "T") {
toggleKey(pressedValue);
} else if (keyUpEvent.keyCodeString === "F") {
focusKey(pressedValue);
} else if (keyUpEvent.keyCodeString === "G") {
gridKey(pressedValue);
} else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "X") {
selectionManager.cutSelectedEntities();
} else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "C") {
selectionManager.copySelectedEntities();
} else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "V") {
selectionManager.pasteEntities();
} else if (keyUpEvent.controlKey && keyUpEvent.keyCodeString === "D") {
selectionManager.duplicateSelection();
} else if (keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") {
undoHistory.undo();
} else if (keyUpEvent.controlKey && !keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "P") {
parentSelectedEntities();
} else if (keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "P") {
unparentSelectedEntities();
} else if (
(keyUpEvent.controlKey && keyUpEvent.shiftKey && keyUpEvent.keyCodeString === "Z") ||
(keyUpEvent.controlKey && keyUpEvent.keyCodeString === "Y")) {
undoHistory.redo();
} else if (WANT_DEBUG_MISSING_SHORTCUTS) {
console.warn("unhandled key event: " + JSON.stringify(keyUpEvent))
}
};
var propertyMenu = new PopupMenu();
propertyMenu.onSelectMenuItem = function (name) {
@ -2719,22 +2759,6 @@ var showMenuItem = propertyMenu.addMenuItem("Show in Marketplace");
var propertiesTool = new PropertiesTool();
entityListTool.webView.webEventReceived.connect(function(data) {
try {
data = JSON.parse(data);
} catch(e) {
print("edit.js: Error parsing JSON");
return;
}
if (data.type === 'parent') {
parentSelectedEntities();
} else if (data.type === 'unparent') {
unparentSelectedEntities();
}
});
selectionDisplay.onSpaceModeChange = function(spaceMode) {
entityListTool.setSpaceMode(spaceMode);
propertiesTool.setSpaceMode(spaceMode);

View file

@ -21,8 +21,6 @@ const MAX_LENGTH_RADIUS = 9;
const MINIMUM_COLUMN_WIDTH = 24;
const SCROLLBAR_WIDTH = 20;
const RESIZER_WIDTH = 10;
const DELETE = 46; // Key code for the delete key.
const KEY_P = 80; // Key code for letter p used for Parenting hotkey.
const COLUMNS = {
type: {
@ -1114,22 +1112,70 @@ function loaded() {
elToggleSpaceMode.innerText = "World";
}
}
const KEY_CODES = {
BACKSPACE: 8,
DELETE: 46
};
document.addEventListener("keydown", function (keyDownEvent) {
if (keyDownEvent.target.nodeName === "INPUT") {
document.addEventListener("keyup", function (keyUpEvent) {
if (keyUpEvent.target.nodeName === "INPUT") {
return;
}
let keyCode = keyDownEvent.keyCode;
if (keyCode === DELETE) {
EventBridge.emitWebEvent(JSON.stringify({ type: 'delete' }));
let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent;
let controlKey = window.navigator.platform.startsWith("Mac") ? metaKey : ctrlKey;
let keyCodeString;
switch (keyCode) {
case KEY_CODES.DELETE:
keyCodeString = "Delete";
break;
case KEY_CODES.BACKSPACE:
keyCodeString = "Backspace";
break;
default:
keyCodeString = String.fromCharCode(keyUpEvent.keyCode);
break;
}
if (keyDownEvent.keyCode === KEY_P && keyDownEvent.ctrlKey) {
if (keyDownEvent.shiftKey) {
EventBridge.emitWebEvent(JSON.stringify({ type: 'unparent' }));
} else {
EventBridge.emitWebEvent(JSON.stringify({ type: 'parent' }));
if (controlKey && keyCodeString === "A") {
let visibleEntityIDs = visibleEntities.map(visibleEntity => visibleEntity.id);
let selectionIncludesAllVisibleEntityIDs = visibleEntityIDs.every(visibleEntityID => {
return selectedEntities.includes(visibleEntityID);
});
let selection = [];
if (!selectionIncludesAllVisibleEntityIDs) {
selection = visibleEntityIDs;
}
updateSelectedEntities(selection);
EventBridge.emitWebEvent(JSON.stringify({
type: "selectionUpdate",
focus: false,
entityIds: selection,
}));
return;
}
EventBridge.emitWebEvent(JSON.stringify({
type: 'keyUpEvent',
keyUpEvent: {
code,
key,
keyCode,
keyCodeString,
altKey,
controlKey,
shiftKey,
}
}));
}, false);
if (window.EventBridge !== undefined) {

View file

@ -1352,8 +1352,6 @@ const COLOR_MIN = 0;
const COLOR_MAX = 255;
const COLOR_STEP = 1;
const KEY_P = 80; // Key code for letter p used for Parenting hotkey.
const MATERIAL_PREFIX_STRING = "mat::";
const PENDING_SCRIPT_STATUS = "[ Fetching status ]";
@ -3494,16 +3492,46 @@ function loaded() {
el.parentNode.removeChild(el);
elDropdowns = document.getElementsByTagName("select");
}
document.addEventListener("keydown", function (keyDown) {
if (keyDown.keyCode === KEY_P && keyDown.ctrlKey) {
if (keyDown.shiftKey) {
EventBridge.emitWebEvent(JSON.stringify({ type: 'unparent' }));
} else {
EventBridge.emitWebEvent(JSON.stringify({ type: 'parent' }));
}
const KEY_CODES = {
BACKSPACE: 8,
DELETE: 46
};
document.addEventListener("keyup", function (keyUpEvent) {
if (keyUpEvent.target.nodeName === "INPUT") {
return;
}
});
let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent;
let controlKey = window.navigator.platform.startsWith("Mac") ? metaKey : ctrlKey;
let keyCodeString;
switch (keyCode) {
case KEY_CODES.DELETE:
keyCodeString = "Delete";
break;
case KEY_CODES.BACKSPACE:
keyCodeString = "Backspace";
break;
default:
keyCodeString = String.fromCharCode(keyUpEvent.keyCode);
break;
}
EventBridge.emitWebEvent(JSON.stringify({
type: 'keyUpEvent',
keyUpEvent: {
code,
key,
keyCode,
keyCodeString,
altKey,
controlKey,
shiftKey,
}
}));
}, false);
window.onblur = function() {
// Fake a change event

View file

@ -6,8 +6,6 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
const KEY_P = 80; //Key code for letter p used for Parenting hotkey.
function loaded() {
openEventBridge(function() {
elPosY = document.getElementById("horiz-y");
@ -105,7 +103,7 @@ function loaded() {
elColorBlue.value = blue;
gridColor = { red: red, green: green, blue: blue };
emitUpdate();
}
};
elColorRed.addEventListener('change', colorChangeFunction);
elColorGreen.addEventListener('change', colorChangeFunction);
@ -131,15 +129,47 @@ function loaded() {
EventBridge.emitWebEvent(JSON.stringify({ type: 'init' }));
});
document.addEventListener("keydown", function (keyDown) {
if (keyDown.keyCode === KEY_P && keyDown.ctrlKey) {
if (keyDown.shiftKey) {
EventBridge.emitWebEvent(JSON.stringify({ type: 'unparent' }));
} else {
EventBridge.emitWebEvent(JSON.stringify({ type: 'parent' }));
}
}
})
const KEY_CODES = {
BACKSPACE: 8,
DELETE: 46
};
document.addEventListener("keyup", function (keyUpEvent) {
if (keyUpEvent.target.nodeName === "INPUT") {
return;
}
let {code, key, keyCode, altKey, ctrlKey, metaKey, shiftKey} = keyUpEvent;
let controlKey = window.navigator.platform.startsWith("Mac") ? metaKey : ctrlKey;
let keyCodeString;
switch (keyCode) {
case KEY_CODES.DELETE:
keyCodeString = "Delete";
break;
case KEY_CODES.BACKSPACE:
keyCodeString = "Backspace";
break;
default:
keyCodeString = String.fromCharCode(keyUpEvent.keyCode);
break;
}
EventBridge.emitWebEvent(JSON.stringify({
type: 'keyUpEvent',
keyUpEvent: {
code,
key,
keyCode,
keyCodeString,
altKey,
controlKey,
shiftKey,
}
}));
}, false);
// Disable right-click context menu which is not visible in the HMD and makes it seem like the app has locked
document.addEventListener("contextmenu", function (event) {
event.preventDefault();

View file

@ -8,4 +8,5 @@ HifiControls.WebView {
id: entityListToolWebView
url: Qt.resolvedUrl("../html/entityList.html")
enabled: true
blurOnCtrlShift: false
}

View file

@ -9,7 +9,8 @@
//
/* global EntityListTool, Tablet, selectionManager, Entities, Camera, MyAvatar, Vec3, Menu, Messages,
cameraManager, MENU_EASE_ON_FOCUS, deleteSelectedEntities, toggleSelectedEntitiesLocked, toggleSelectedEntitiesVisible */
cameraManager, MENU_EASE_ON_FOCUS, deleteSelectedEntities, toggleSelectedEntitiesLocked, toggleSelectedEntitiesVisible,
keyUpEventFromUIWindow */
var PROFILING_ENABLED = false;
var profileIndent = '';
@ -298,6 +299,8 @@ EntityListTool = function(shouldUseEditTabletApp) {
SelectionManager._update();
} else if (data.type === "toggleSpaceMode") {
SelectionDisplay.toggleSpaceMode();
} else if (data.type === 'keyUpEvent') {
keyUpEventFromUIWindow(data.keyUpEvent);
}
};

View file

@ -1,3 +1,5 @@
/* global keyUpEventFromUIWindow */
var GRID_CONTROLS_HTML_URL = Script.resolvePath('../html/gridControls.html');
Grid = function() {
@ -270,24 +272,26 @@ GridTool = function(opts) {
return;
}
if (data.type == "init") {
if (data.type === "init") {
horizontalGrid.emitUpdate();
} else if (data.type == "update") {
} else if (data.type === "update") {
horizontalGrid.update(data);
for (var i = 0; i < listeners.length; i++) {
listeners[i] && listeners[i](data);
}
} else if (data.type == "action") {
} else if (data.type === "action") {
var action = data.action;
if (action == "moveToAvatar") {
if (action === "moveToAvatar") {
var position = MyAvatar.getJointPosition("LeftFoot");
if (position.x == 0 && position.y == 0 && position.z == 0) {
if (position.x === 0 && position.y === 0 && position.z === 0) {
position = MyAvatar.position;
}
horizontalGrid.setPosition(position);
} else if (action == "moveToSelection") {
} else if (action === "moveToSelection") {
horizontalGrid.moveToSelection();
}
} else if (data.type === 'keyUpEvent') {
keyUpEventFromUIWindow(data.keyUpEvent);
}
};