handle esc/enter for wizards

This commit is contained in:
Val Erastov 2016-10-17 19:53:25 -07:00
parent 7b1a31deec
commit fd92fe5f1e
8 changed files with 24 additions and 13 deletions

View file

@ -184,6 +184,7 @@ UI.prototype.registerWizard = function(wizard, overridingHistory) {
wizard.apply = function() { wizard.apply = function() {
craft.modify(wizard.createRequest(), overridingHistory); craft.modify(wizard.createRequest(), overridingHistory);
}; };
wizard.focus();
return wizard; return wizard;
}; };

View file

@ -1,12 +1,11 @@
import {AXIS, IDENTITY_BASIS} from '../../math/l3space' import {AXIS, IDENTITY_BASIS} from '../../math/l3space'
import * as tk from '../../ui/toolkit.js' import * as tk from '../../ui/toolkit.js'
import {FACE_COLOR} from '../cad-utils' import {FACE_COLOR} from '../cad-utils'
import {addOkCancelLogic} from './wizard-commons' import {addBehavior} from './wizard-commons'
export function BoxWizard(viewer, initParams) { export function BoxWizard(viewer, initParams) {
this.previewGroup = new THREE.Object3D(); this.previewGroup = new THREE.Object3D();
this.viewer = viewer; this.viewer = viewer;
addOkCancelLogic(this);
viewer.scene.add(this.previewGroup); viewer.scene.add(this.previewGroup);
this.previewGroup.add(this.box = this.createBox()); this.previewGroup.add(this.box = this.createBox());
if (!initParams) { if (!initParams) {
@ -14,6 +13,7 @@ export function BoxWizard(viewer, initParams) {
} }
this.ui = {}; this.ui = {};
this.createUI.apply(this, initParams); this.createUI.apply(this, initParams);
addBehavior(this);
this.synch(); this.synch();
} }

View file

@ -3,18 +3,18 @@ import * as workbench from '../workbench'
import * as cad_utils from '../cad-utils' import * as cad_utils from '../cad-utils'
import Vector from '../../math/vector' import Vector from '../../math/vector'
import {Matrix3, ORIGIN} from '../../math/l3space' import {Matrix3, ORIGIN} from '../../math/l3space'
import {OpWizard, IMAGINE_MATERIAL, BASE_MATERIAL, addOkCancelLogic} from './wizard-commons' import {OpWizard, IMAGINE_MATERIAL, BASE_MATERIAL, addBehavior} from './wizard-commons'
export function ExtrudeWizard(app, face, invert, initParams) { export function ExtrudeWizard(app, face, invert, initParams) {
OpWizard.call(this, app.viewer); OpWizard.call(this, app.viewer);
this.app = app; this.app = app;
this.face = face; this.face = face;
this.invert = invert; this.invert = invert;
addOkCancelLogic(this);
this.updatePolygons(); this.updatePolygons();
this.ui = {}; this.ui = {};
if (!initParams) initParams = ExtrudeWizard.DEFAULT_PARAMS; if (!initParams) initParams = ExtrudeWizard.DEFAULT_PARAMS;
this.createUI.apply(this, initParams); this.createUI.apply(this, initParams);
addBehavior(this);
this.synch(); this.synch();
} }

View file

@ -1,12 +1,11 @@
import {AXIS, IDENTITY_BASIS} from '../../math/l3space' import {AXIS, IDENTITY_BASIS} from '../../math/l3space'
import * as tk from '../../ui/toolkit.js' import * as tk from '../../ui/toolkit.js'
import {FACE_COLOR} from '../cad-utils' import {FACE_COLOR} from '../cad-utils'
import {addOkCancelLogic} from './wizard-commons' import {addBehavior} from './wizard-commons'
export function PlaneWizard(viewer, initParams) { export function PlaneWizard(viewer, initParams) {
this.previewGroup = new THREE.Object3D(); this.previewGroup = new THREE.Object3D();
this.viewer = viewer; this.viewer = viewer;
addOkCancelLogic(this);
viewer.scene.add(this.previewGroup); viewer.scene.add(this.previewGroup);
this.previewGroup.add(this.plane = this.createPlane()); this.previewGroup.add(this.plane = this.createPlane());
this.operationParams = { this.operationParams = {
@ -18,6 +17,8 @@ export function PlaneWizard(viewer, initParams) {
} }
this.ui = {}; this.ui = {};
this.createUI.apply(this, initParams); this.createUI.apply(this, initParams);
addBehavior(this);
this.focus = () => this.ui.depth.input.focus();
this.synch(); this.synch();
} }

View file

@ -16,7 +16,7 @@ ShellWizard.prototype.update = function(d) {
}; };
ExtrudeWizard.prototype.updatePolygons = function() { ExtrudeWizard.prototype.updatePolygons = function() {
this.polygons = workbench.reconstructOutline(this.face.solid.csg, this.face); this.polygons = [];//workbench.reconstructOutline(this.face.solid.csg, this.face);
}; };
ShellWizard.prototype.createUI = function(d) { ShellWizard.prototype.createUI = function(d) {

View file

@ -1,12 +1,11 @@
import {AXIS, IDENTITY_BASIS} from '../../math/l3space' import {AXIS, IDENTITY_BASIS} from '../../math/l3space'
import * as tk from '../../ui/toolkit.js' import * as tk from '../../ui/toolkit.js'
import {FACE_COLOR} from '../cad-utils' import {FACE_COLOR} from '../cad-utils'
import {addOkCancelLogic} from './wizard-commons' import {addBehavior} from './wizard-commons'
export function SphereWizard(viewer, initParams) { export function SphereWizard(viewer, initParams) {
this.previewGroup = new THREE.Object3D(); this.previewGroup = new THREE.Object3D();
this.viewer = viewer; this.viewer = viewer;
addOkCancelLogic(this);
viewer.scene.add(this.previewGroup); viewer.scene.add(this.previewGroup);
this.previewGroup.add(this.sphere = this.createSphere()); this.previewGroup.add(this.sphere = this.createSphere());
if (!initParams) { if (!initParams) {
@ -14,6 +13,7 @@ export function SphereWizard(viewer, initParams) {
} }
this.ui = {}; this.ui = {};
this.createUI.apply(this, initParams); this.createUI.apply(this, initParams);
addBehavior(this);
this.synch(); this.synch();
} }

View file

@ -1,13 +1,12 @@
import {AXIS, IDENTITY_BASIS} from '../../math/l3space' import {AXIS, IDENTITY_BASIS} from '../../math/l3space'
import * as tk from '../../ui/toolkit.js' import * as tk from '../../ui/toolkit.js'
import {FACE_COLOR} from '../cad-utils' import {FACE_COLOR} from '../cad-utils'
import {addOkCancelLogic} from './wizard-commons' import {addBehavior} from './wizard-commons'
export function TransformWizard(viewer, solid, initParams) { export function TransformWizard(viewer, solid, initParams) {
this.previewGroup = new THREE.Object3D(); this.previewGroup = new THREE.Object3D();
this.viewer = viewer; this.viewer = viewer;
this.solid = solid; this.solid = solid;
addOkCancelLogic(this);
if (!initParams) { if (!initParams) {
initParams = TransformWizard.DEFAULT_PARAMS; initParams = TransformWizard.DEFAULT_PARAMS;
} }
@ -22,6 +21,7 @@ export function TransformWizard(viewer, solid, initParams) {
this.transfomControlListener = tk.methodRef(this, "synchToUI"); this.transfomControlListener = tk.methodRef(this, "synchToUI");
this.viewer.transformControls.addEventListener( 'objectChange', this.transfomControlListener ); this.viewer.transformControls.addEventListener( 'objectChange', this.transfomControlListener );
this.createUI.apply(this, initParams); this.createUI.apply(this, initParams);
addBehavior(this);
this.synch(); this.synch();
} }

View file

@ -14,7 +14,7 @@ const BASE_MATERIAL = new THREE.LineBasicMaterial({
depthTest: false depthTest: false
}); });
function addOkCancelLogic(wizard) { function addBehavior(wizard) {
wizard.apply = function() {}; wizard.apply = function() {};
wizard.onCancel = function() {}; wizard.onCancel = function() {};
wizard.okClick = function() { wizard.okClick = function() {
@ -25,6 +25,15 @@ function addOkCancelLogic(wizard) {
this.onCancel(); this.onCancel();
this.dispose(); this.dispose();
}; };
wizard.ui.box.root.keydown((e) => {
switch (e.keyCode) {
case 27 : wizard.cancelClick(); break;
case 13 : wizard.okClick(); break;
}
});
wizard.focus = () => {
wizard.ui.box.root.find('input, select').first().focus()
};
} }
function OpWizard(viewer) { function OpWizard(viewer) {
@ -56,4 +65,4 @@ OpWizard.prototype.dispose = function() {
this.viewer.render(); this.viewer.render();
}; };
export {OpWizard, IMAGINE_MATERIAL, BASE_MATERIAL, addOkCancelLogic} export {OpWizard, IMAGINE_MATERIAL, BASE_MATERIAL, addBehavior}