make actions contextual

This commit is contained in:
Val Erastov 2016-11-10 22:11:25 -08:00
parent d0d41d45fd
commit c9dffaa9dd
3 changed files with 34 additions and 10 deletions

View file

@ -33,3 +33,8 @@ export const main = {
'EditFace', '-', 'DeselectAll', 'RefreshSketches' ]
};
export const SolidContext = {
label: 'solid-context',
info: 'solid context actions',
actions: ['LookAtSolid']
};

View file

@ -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 {
}

View file

@ -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() {