diff --git a/scripts/system/libraries/entityList.js b/scripts/system/libraries/entityList.js index 1dca853668..fa09f27965 100644 --- a/scripts/system/libraries/entityList.js +++ b/scripts/system/libraries/entityList.js @@ -3,6 +3,7 @@ var ENTITY_LIST_HTML_URL = Script.resolvePath('../html/entityList.html'); EntityListTool = function(opts) { var that = {}; + var url = ENTITY_LIST_HTML_URL; var webView = new OverlayWebWindow({ title: 'Entity List', source: url, toolWindow: true @@ -98,7 +99,6 @@ EntityListTool = function(opts) { webView.emitScriptEvent(JSON.stringify(data)); } - webView.webEventReceived.connect(function(data) { data = JSON.parse(data); if (data.type == "selectionUpdate") { @@ -121,9 +121,19 @@ EntityListTool = function(opts) { MyAvatar.position = selectionManager.worldPosition; } } else if (data.type == "pal") { - print("fixme got pal"); - if (selectionManager.hasSelection()) { - print('fixme selection', JSON.stringify(selectionManager.selections)); + var sessionIds = {}; // Collect the sessionsIds of all selected entitities, w/o duplicates. + selectionManager.selections.forEach(function (id) { + var lastEditedBy = Entities.getEntityProperties(id, 'lastEditedBy').lastEditedBy; + if (lastEditedBy) { + sessionIds[lastEditedBy] = true; + } + }); + var dedupped = Object.keys(sessionIds); + if (!dedupped.length) { + Window.alert('There were no recent users of the ' + selectionManager.selections.length + ' selected objects.'); + } else { + // No need to subscribe if we're just sending. + Messages.sendMessage('com.highfidelity.pal', JSON.stringify({method: 'select', params: dedupped}), 'local'); } } else if (data.type == "delete") { deleteSelectedEntities(); diff --git a/scripts/system/pal.js b/scripts/system/pal.js index e727f9a1e3..4c4a9c0eaf 100644 --- a/scripts/system/pal.js +++ b/scripts/system/pal.js @@ -256,6 +256,27 @@ function removeOverlays() { ExtendedOverlay.some(function (overlay) { overlay.deleteOverlay(); }); } +// +// Message from other scripts, such as edit.js +// +var CHANNEL = 'com.highfidelity.pal'; +function receiveMessage(channel, messageString, senderID) { + if ((channel !== CHANNEL) || + (senderID !== MyAvatar.sessionUUID)) { + return; + } + var message = JSON.parse(messageString); + switch (message.method) { + case 'select': + print('fixme processing', message.params); + break; + default: + print('Unrecognized PAL message', messageString); + } +} +Messages.subscribe(CHANNEL); +Messages.messageReceived.connect(receiveMessage); + // // Clicks. // @@ -412,6 +433,8 @@ Script.scriptEnding.connect(function () { Users.usernameFromIDReply.disconnect(usernameFromIDReply); Window.domainChanged.disconnect(clearIgnoredInQMLAndClosePAL); Window.domainConnectionRefused.disconnect(clearIgnoredInQMLAndClosePAL); + Messages.unsubscribe(CHANNEL); + Messages.messageReceived.disconnect(receiveMessage); off(); });