CR feedback

This commit is contained in:
Thijs Wenker 2018-10-20 02:43:41 +02:00
parent e5ef589a3c
commit 4069ca2e0c
2 changed files with 19 additions and 19 deletions

View file

@ -231,8 +231,11 @@ function loaded() {
elRenameInput.select(); elRenameInput.select();
} }
entityListContextMenu.setCallback(function(optionName, selectedEntityID) { entityListContextMenu.setOnSelectedCallback(function(optionName, selectedEntityID) {
switch (optionName) { switch (optionName) {
case "Cut":
EventBridge.emitWebEvent(JSON.stringify({ type: 'cut' }));
break;
case "Copy": case "Copy":
EventBridge.emitWebEvent(JSON.stringify({ type: 'copy' })); EventBridge.emitWebEvent(JSON.stringify({ type: 'copy' }));
break; break;
@ -263,8 +266,6 @@ function loaded() {
focus: false, focus: false,
entityIds: selection, entityIds: selection,
})); }));
refreshFooter();
} }
let enabledContextMenuItems = []; let enabledContextMenuItems = [];
@ -765,7 +766,7 @@ function loaded() {
augmentSpinButtons(); augmentSpinButtons();
document.addEventListener("contextmenu", function (event) { document.addEventListener("contextmenu", function (event) {
entityListContextMenu.close.call(entityListContextMenu); entityListContextMenu.close();
// Disable default right-click context menu which is not visible in the HMD and makes it seem like the app has locked // Disable default right-click context menu which is not visible in the HMD and makes it seem like the app has locked
event.preventDefault(); event.preventDefault();
@ -773,6 +774,6 @@ function loaded() {
// close context menu when switching focus to another window // close context menu when switching focus to another window
$(window).blur(function() { $(window).blur(function() {
entityListContextMenu.close.call(entityListContextMenu); entityListContextMenu.close();
}); });
} }

View file

@ -18,7 +18,7 @@ const CONTEXT_MENU_CLASS = "context-menu";
*/ */
function EntityListContextMenu() { function EntityListContextMenu() {
this._elContextMenu = null; this._elContextMenu = null;
this._callback = null; this._onSelectedCallback = null;
this._listItems = []; this._listItems = [];
this._initialize(); this._initialize();
} }
@ -33,7 +33,7 @@ EntityListContextMenu.prototype = {
/** /**
* @private * @private
*/ */
_callback: null, _onSelectedCallback: null,
/** /**
* @private * @private
@ -82,20 +82,19 @@ EntityListContextMenu.prototype = {
}, },
/** /**
* Set the event callback * Set the callback for when a menu item is selected
* @param callback * @param onSelectedCallback
*/ */
setCallback: function(callback) { setOnSelectedCallback: function(onSelectedCallback) {
this._callback = callback; this._onSelectedCallback = onSelectedCallback;
}, },
/** /**
* Add a labeled item to the context menu * Add a labeled item to the context menu
* @param itemLabel * @param itemLabel
* @param isEnabled
* @private * @private
*/ */
_addListItem: function(itemLabel, isEnabled) { _addListItem: function(itemLabel) {
let elListItem = document.createElement("li"); let elListItem = document.createElement("li");
elListItem.innerText = itemLabel; elListItem.innerText = itemLabel;
@ -106,8 +105,8 @@ EntityListContextMenu.prototype = {
}; };
elListItem.addEventListener("click", function () { elListItem.addEventListener("click", function () {
if (listItem.enabled && this._callback) { if (listItem.enabled && this._onSelectedCallback) {
this._callback.call(this, itemLabel, this._selectedEntityID); this._onSelectedCallback.call(this, itemLabel, this._selectedEntityID);
} }
}.bind(this), false); }.bind(this), false);
@ -136,12 +135,12 @@ EntityListContextMenu.prototype = {
this._elContextMenu.setAttribute("class", CONTEXT_MENU_CLASS); this._elContextMenu.setAttribute("class", CONTEXT_MENU_CLASS);
document.body.appendChild(this._elContextMenu); document.body.appendChild(this._elContextMenu);
// TODO: enable Copy, Paste and Duplicate items once implemented this._addListItem("Cut");
this._addListItem("Copy", false); this._addListItem("Copy");
this._addListItem("Paste", false); this._addListItem("Paste");
this._addListSeparator(); this._addListSeparator();
this._addListItem("Rename"); this._addListItem("Rename");
this._addListItem("Duplicate", false); this._addListItem("Duplicate");
this._addListItem("Delete"); this._addListItem("Delete");
// Ignore clicks on context menu background or separator. // Ignore clicks on context menu background or separator.