diff --git a/modules/behavior/operation.js b/modules/behavior/operation.js index fa57ddc41..0e2741dd8 100644 --- a/modules/behavior/operation.js +++ b/modules/behavior/operation.js @@ -12,7 +12,7 @@ export function behaviorOperation(context) { keybinding = d3keybinding('behavior.key.' + which.id); keybinding.on(which.keys, function() { d3.event.preventDefault(); - if (!(context.inIntro() || which.disabled())) { + if (which.available() && !which.disabled() && !context.inIntro()) { which(); } }); diff --git a/modules/modes/select.js b/modules/modes/select.js index 077fc670c..a4d2dc7a6 100644 --- a/modules/modes/select.js +++ b/modules/modes/select.js @@ -392,16 +392,22 @@ export function modeSelect(context, selectedIDs) { if (!checkSelectedIDs()) return; - behaviors.forEach(function(behavior) { - context.install(behavior); - }); - var operations = _.without(d3.values(Operations), Operations.operationDelete) .map(function(o) { return o(selectedIDs, context); }) .filter(function(o) { return o.available(); }); operations.unshift(Operations.operationDelete(selectedIDs, context)); + operations.forEach(function(operation) { + if (operation.behavior) { + behaviors.push(operation.behavior); + } + }); + + behaviors.forEach(function(behavior) { + context.install(behavior); + }); + keybinding .on(['[','pgup'], previousVertex) .on([']', 'pgdown'], nextVertex) @@ -411,17 +417,6 @@ export function modeSelect(context, selectedIDs) { .on('⎋', esc, true) .on('space', toggleMenu); - operations.forEach(function(operation) { - operation.keys.forEach(function(key) { - keybinding.on(key, function() { - d3.event.preventDefault(); - if (!(context.inIntro() || operation.disabled())) { - operation(); - } - }); - }); - }); - d3.select(document) .call(keybinding); diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index 475523ecb..8aebef11e 100644 --- a/modules/operations/circularize.js +++ b/modules/operations/circularize.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import { t } from '../util/locale'; import { actionCircularize } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; export function operationCircularize(selectedIDs, context) { @@ -10,9 +11,9 @@ export function operationCircularize(selectedIDs, context) { geometry = context.geometry(entityId), action = actionCircularize(entityId, context.projection); + var operation = function() { - var annotation = t('operations.circularize.annotation.' + geometry); - context.perform(action, annotation); + context.perform(action, t('operations.circularize.annotation.' + geometry)); }; @@ -45,7 +46,7 @@ export function operationCircularize(selectedIDs, context) { operation.id = 'circularize'; operation.keys = [t('operations.circularize.key')]; operation.title = t('operations.circularize.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/continue.js b/modules/operations/continue.js index e0b286d83..4feaab5ef 100644 --- a/modules/operations/continue.js +++ b/modules/operations/continue.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import { t } from '../util/locale'; import { modeDrawLine } from '../modes/index'; +import { behaviorOperation } from '../behavior/index'; export function operationContinue(selectedIDs, context) { @@ -54,7 +55,7 @@ export function operationContinue(selectedIDs, context) { operation.id = 'continue'; operation.keys = [t('operations.continue.key')]; operation.title = t('operations.continue.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/delete.js b/modules/operations/delete.js index af046916f..ffdcb5a27 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -1,9 +1,10 @@ import _ from 'lodash'; import { t } from '../util/locale'; -import { modeBrowse, modeSelect } from '../modes/index'; import { actionDeleteMultiple } from '../actions/index'; -import { uiCmd } from '../ui/index'; +import { behaviorOperation } from '../behavior/index'; import { geoSphericalDistance } from '../geo/index'; +import { modeBrowse, modeSelect } from '../modes/index'; +import { uiCmd } from '../ui/index'; export function operationDelete(selectedIDs, context) { @@ -82,7 +83,7 @@ export function operationDelete(selectedIDs, context) { operation.id = 'delete'; operation.keys = [uiCmd('⌘⌫'), uiCmd('⌘⌦'), uiCmd('⌦')]; operation.title = t('operations.delete.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index 842aa4afa..420162ecd 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import { t } from '../util/locale'; import { actionDisconnect } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; export function operationDisconnect(selectedIDs, context) { @@ -15,6 +16,7 @@ export function operationDisconnect(selectedIDs, context) { action.limitWays(_.without(selectedIDs, entityId)); } + var operation = function() { context.perform(action, t('operations.disconnect.annotation')); }; @@ -45,7 +47,7 @@ export function operationDisconnect(selectedIDs, context) { operation.id = 'disconnect'; operation.keys = [t('operations.disconnect.key')]; operation.title = t('operations.disconnect.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/merge.js b/modules/operations/merge.js index 345440cce..d58a9a8bf 100644 --- a/modules/operations/merge.js +++ b/modules/operations/merge.js @@ -5,6 +5,7 @@ import { actionMergePolygon } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; import { modeSelect } from '../modes/index'; @@ -68,7 +69,7 @@ export function operationMerge(selectedIDs, context) { operation.id = 'merge'; operation.keys = [t('operations.merge.key')]; operation.title = t('operations.merge.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/move.js b/modules/operations/move.js index 69a2f2a4b..2c8fb58d0 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -1,7 +1,8 @@ import _ from 'lodash'; import { t } from '../util/locale'; -import { geoExtent } from '../geo/index'; import { actionMove } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; +import { geoExtent } from '../geo/index'; import { modeMove } from '../modes/index'; @@ -10,6 +11,7 @@ export function operationMove(selectedIDs, context) { return extent.extend(context.entity(id).extent(context.graph())); }, geoExtent()); + var operation = function() { context.enter(modeMove(context, selectedIDs)); }; @@ -44,7 +46,7 @@ export function operationMove(selectedIDs, context) { operation.id = 'move'; operation.keys = [t('operations.move.key')]; operation.title = t('operations.move.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/orthogonalize.js b/modules/operations/orthogonalize.js index b8143edce..8275e4f7a 100644 --- a/modules/operations/orthogonalize.js +++ b/modules/operations/orthogonalize.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import { t } from '../util/locale'; import { actionOrthogonalize } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; export function operationOrthogonalize(selectedIDs, context) { @@ -10,9 +11,9 @@ export function operationOrthogonalize(selectedIDs, context) { geometry = context.geometry(entityId), action = actionOrthogonalize(entityId, context.projection); + var operation = function() { - var annotation = t('operations.orthogonalize.annotation.' + geometry); - context.perform(action, annotation); + context.perform(action, t('operations.orthogonalize.annotation.' + geometry)); }; @@ -46,7 +47,7 @@ export function operationOrthogonalize(selectedIDs, context) { operation.id = 'orthogonalize'; operation.keys = [t('operations.orthogonalize.key')]; operation.title = t('operations.orthogonalize.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index b7e5e1808..7656e6495 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -56,6 +56,5 @@ export function operationReflect(selectedIDs, context, axis) { operation.title = t('operations.reflect.title'); operation.behavior = behaviorOperation(context).which(operation); - return operation; } diff --git a/modules/operations/reverse.js b/modules/operations/reverse.js index 6c75df732..2e0d39b40 100644 --- a/modules/operations/reverse.js +++ b/modules/operations/reverse.js @@ -1,21 +1,18 @@ import { t } from '../util/locale'; import { actionReverse } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; export function operationReverse(selectedIDs, context) { var entityId = selectedIDs[0]; var operation = function() { - context.perform( - actionReverse(entityId), - t('operations.reverse.annotation') - ); + context.perform(actionReverse(entityId), t('operations.reverse.annotation')); }; operation.available = function() { - return selectedIDs.length === 1 && - context.geometry(entityId) === 'line'; + return selectedIDs.length === 1 && context.geometry(entityId) === 'line'; }; @@ -32,7 +29,7 @@ export function operationReverse(selectedIDs, context) { operation.id = 'reverse'; operation.keys = [t('operations.reverse.key')]; operation.title = t('operations.reverse.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index 42cadfd1c..431e56df9 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -1,5 +1,6 @@ import { t } from '../util/locale'; import { modeRotateWay } from '../modes/index'; +import { behaviorOperation } from '../behavior/index'; export function operationRotate(selectedIDs, context) { @@ -8,6 +9,7 @@ export function operationRotate(selectedIDs, context) { extent = entity.extent(context.graph()), geometry = context.geometry(entityId); + var operation = function() { context.enter(modeRotateWay(context, entityId)); }; @@ -47,7 +49,7 @@ export function operationRotate(selectedIDs, context) { operation.id = 'rotate'; operation.keys = [t('operations.rotate.key')]; operation.title = t('operations.rotate.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/split.js b/modules/operations/split.js index 0f6aba352..cc81c90a3 100644 --- a/modules/operations/split.js +++ b/modules/operations/split.js @@ -1,7 +1,8 @@ import _ from 'lodash'; import { t } from '../util/locale'; -import { modeSelect } from '../modes/index'; import { actionSplit } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; +import { modeSelect } from '../modes/index'; export function operationSplit(selectedIDs, context) { @@ -64,7 +65,7 @@ export function operationSplit(selectedIDs, context) { operation.id = 'split'; operation.keys = [t('operations.split.key')]; operation.title = t('operations.split.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; } diff --git a/modules/operations/straighten.js b/modules/operations/straighten.js index e0d42cb8d..8a029caa0 100644 --- a/modules/operations/straighten.js +++ b/modules/operations/straighten.js @@ -1,6 +1,7 @@ import _ from 'lodash'; import { t } from '../util/locale'; import { actionStraighten } from '../actions/index'; +import { behaviorOperation } from '../behavior/index'; export function operationStraighten(selectedIDs, context) { @@ -9,8 +10,7 @@ export function operationStraighten(selectedIDs, context) { function operation() { - var annotation = t('operations.straighten.annotation'); - context.perform(action, annotation); + context.perform(action, t('operations.straighten.annotation')); } @@ -43,7 +43,7 @@ export function operationStraighten(selectedIDs, context) { operation.id = 'straighten'; operation.keys = [t('operations.straighten.key')]; operation.title = t('operations.straighten.title'); - + operation.behavior = behaviorOperation(context).which(operation); return operation; }