From c9dffaa9ddd2ee3f4e3787f82d792ea0e4c3d3be Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Thu, 10 Nov 2016 22:11:25 -0800 Subject: [PATCH] make actions contextual --- web/app/3d/menu/menu-config.js | 5 +++++ web/app/3d/menu/menu.js | 10 +++++----- web/app/3d/ui/input-manager.js | 29 ++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/web/app/3d/menu/menu-config.js b/web/app/3d/menu/menu-config.js index b3161498..892d5cb2 100644 --- a/web/app/3d/menu/menu-config.js +++ b/web/app/3d/menu/menu-config.js @@ -33,3 +33,8 @@ export const main = { 'EditFace', '-', 'DeselectAll', 'RefreshSketches' ] }; +export const SolidContext = { + label: 'solid-context', + info: 'solid context actions', + actions: ['LookAtSolid'] +}; diff --git a/web/app/3d/menu/menu.js b/web/app/3d/menu/menu.js index 9223994c..5a7e14a0 100644 --- a/web/app/3d/menu/menu.js +++ b/web/app/3d/menu/menu.js @@ -56,10 +56,10 @@ Menu.prototype.show = function(app, event) { this.node.removeClass('menu-flat-bottom'); this.node.show(); //node should be visible to get right dimensions const r = Math.round; - let source = EventData.get(event, 'menu-button'); - if (source != undefined) { - var off = source.offset(); - var orientation = source.data('menuOrientation'); + let button = EventData.get(event, 'initiator'); + if (button != undefined) { + var off = button.offset(); + var orientation = button.data('menuOrientation'); if (orientation == 'up') { this.node.addClass('menu-flat-bottom'); this.node.offset({ @@ -70,7 +70,7 @@ Menu.prototype.show = function(app, event) { this.node.addClass('menu-flat-top'); this.node.offset({ left: r(off.left), - top: r(off.top + source.outerHeight()) + top: r(off.top + button.outerHeight()) }); } else { } diff --git a/web/app/3d/ui/input-manager.js b/web/app/3d/ui/input-manager.js index 6173d10e..f7ff7a8e 100644 --- a/web/app/3d/ui/input-manager.js +++ b/web/app/3d/ui/input-manager.js @@ -7,6 +7,7 @@ import {LoadTemplate, DefaultMouseEvent, EventData, fit} from './utils' export function InputManager(app) { this.app = app; this.openMenus = []; + this.menuContext = null; this.keymap = keymap; this.mouseInfo = new DefaultMouseEvent(); this.requestedActionInfo = null; @@ -19,7 +20,8 @@ export function InputManager(app) { .on('mouseenter', '.action-item', (e) => this.showActionInfo($(e.currentTarget))) .on('mouseleave', '.action-item', (e) => this.hideActionInfo()) .on('mousemove', (e) => this.mouseInfo = e) - .on('click', '.action-item', (e) => this.handleActionClick(e)); + .on('click', '.action-item', (e) => this.handleActionClick(e)) + .on('contextmenu', '.action-item', (e) => {return this.handleRightClick(e)}); }); } @@ -40,14 +42,28 @@ InputManager.prototype.clear = function(e) { if (e != undefined && $(e.target).closest('.menu-item').length != 0) { return; } + this.clearMenus(); + this.requestedActionInfo = null; + this.messageSink.hide(); +}; + +InputManager.prototype.clearMenus = function() { + this.menuContext = null; if (this.openMenus.length != 0) { for (let openMenu of this.openMenus) { openMenu.node.hide(); } this.openMenus = []; } - this.requestedActionInfo = null; - this.messageSink.hide(); +}; + +InputManager.prototype.handleRightClick = function(e) { + if ($(event.currentTarget).hasClass('.right-click-action')) { + e.preventDefault(); + this.handleActionClick(e); + return false; + } + return true; }; InputManager.prototype.handleActionClick = function(event) { @@ -55,14 +71,17 @@ InputManager.prototype.handleActionClick = function(event) { var action = target.data('action'); if (action != undefined) { this.clear(); - EventData.set(event, 'menu-button', target); + EventData.set(event, 'initiator', this.menuContext ? this.menuContext : target); this.app.actionManager.run(action, event); } }; -InputManager.prototype.registerOpenMenu = function(menu) { +InputManager.prototype.registerOpenMenu = function(menu, button) { fit(menu.node, $('body')); this.openMenus.push(menu); + if (this.menuContext == null) { + this.menuContext = button; + } }; InputManager.prototype.hideActionInfo = function() {