diff --git a/modules/behavior/operation.js b/modules/behavior/operation.js index 57c0e8d46..804a5b7d9 100644 --- a/modules/behavior/operation.js +++ b/modules/behavior/operation.js @@ -9,14 +9,18 @@ export function behaviorOperation(context) { var behavior = function () { - if (which) { + if (which && which.available() && !context.inIntro()) { keybinding = d3keybinding('behavior.key.' + which.id); keybinding.on(which.keys, function() { d3.event.preventDefault(); - if (which.available() && !which.disabled() && !context.inIntro()) { + var disabled = which.disabled(); + if (disabled) { + uiFlash().text(which.tooltip); + } else { + var annotation = which.annotation || which.title; + uiFlash().text(annotation); which(); } - uiFlash().text('you did ' + which.title); }); d3.select(document).call(keybinding); } diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index 8aebef11e..895d33aef 100644 --- a/modules/operations/circularize.js +++ b/modules/operations/circularize.js @@ -13,7 +13,7 @@ export function operationCircularize(selectedIDs, context) { var operation = function() { - context.perform(action, t('operations.circularize.annotation.' + geometry)); + context.perform(action, operation.annotation); }; @@ -46,6 +46,7 @@ export function operationCircularize(selectedIDs, context) { operation.id = 'circularize'; operation.keys = [t('operations.circularize.key')]; operation.title = t('operations.circularize.title'); + operation.annotation = t('operations.circularize.annotation.' + geometry); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/continue.js b/modules/operations/continue.js index 5d24f463a..2393ada58 100644 --- a/modules/operations/continue.js +++ b/modules/operations/continue.js @@ -56,6 +56,7 @@ export function operationContinue(selectedIDs, context) { operation.id = 'continue'; operation.keys = [t('operations.continue.key')]; operation.title = t('operations.continue.title'); + operation.annotation = t('operations.continue.annotation.line'); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/delete.js b/modules/operations/delete.js index ead998bb2..b7d330482 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -13,21 +13,15 @@ export function operationDelete(selectedIDs, context) { var operation = function() { - var annotation, - nextSelectedID; + var nextSelectedID; - if (selectedIDs.length > 1) { - annotation = t('operations.delete.annotation.multiple', { n: selectedIDs.length }); - - } else { + if (selectedIDs.length === 1) { var id = selectedIDs[0], entity = context.entity(id), geometry = context.geometry(id), parents = context.graph().parentWays(entity), parent = parents[0]; - annotation = t('operations.delete.annotation.' + geometry); - // Select the next closest node in the way. if (geometry === 'vertex' && parent.nodes.length > 2) { var nodes = parent.nodes, @@ -47,7 +41,7 @@ export function operationDelete(selectedIDs, context) { } } - context.perform(action, annotation); + context.perform(action, operation.annotation); if (nextSelectedID && context.hasEntity(nextSelectedID)) { context.enter( @@ -111,6 +105,9 @@ export function operationDelete(selectedIDs, context) { operation.id = 'delete'; operation.keys = [uiCmd('⌘⌫'), uiCmd('⌘⌦'), uiCmd('⌦')]; operation.title = t('operations.delete.title'); + operation.annotation = selectedIDs.length === 1 ? + t('operations.delete.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.delete.annotation.multiple', { n: selectedIDs.length }); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index 420162ecd..815fe8c94 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -18,7 +18,7 @@ export function operationDisconnect(selectedIDs, context) { var operation = function() { - context.perform(action, t('operations.disconnect.annotation')); + context.perform(action, operation.annotation); }; @@ -47,6 +47,7 @@ export function operationDisconnect(selectedIDs, context) { operation.id = 'disconnect'; operation.keys = [t('operations.disconnect.key')]; operation.title = t('operations.disconnect.title'); + operation.annotation = t('operations.disconnect.annotation'); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/merge.js b/modules/operations/merge.js index c55e3c350..e986b4688 100644 --- a/modules/operations/merge.js +++ b/modules/operations/merge.js @@ -15,8 +15,7 @@ export function operationMerge(selectedIDs, context) { mergePolygon = actionMergePolygon(selectedIDs); var operation = function() { - var annotation = t('operations.merge.annotation', {n: selectedIDs.length}), - action; + var action; if (!join.disabled(context.graph())) { action = join; @@ -26,7 +25,7 @@ export function operationMerge(selectedIDs, context) { action = mergePolygon; } - context.perform(action, annotation); + context.perform(action, operation.annotation); var ids = selectedIDs.filter(function(id) { var entity = context.hasEntity(id); return entity && entity.type !== 'node'; @@ -72,6 +71,7 @@ export function operationMerge(selectedIDs, context) { operation.id = 'merge'; operation.keys = [t('operations.merge.key')]; operation.title = t('operations.merge.title'); + operation.annotation = t('operations.merge.annotation', { n: selectedIDs.length }); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/move.js b/modules/operations/move.js index 7c9a9277a..07af2d7cf 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -52,6 +52,9 @@ export function operationMove(selectedIDs, context) { operation.id = 'move'; operation.keys = [t('operations.move.key')]; operation.title = t('operations.move.title'); + operation.annotation = selectedIDs.length === 1 ? + t('operations.move.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.move.annotation.multiple'); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/orthogonalize.js b/modules/operations/orthogonalize.js index 8275e4f7a..f34f2facd 100644 --- a/modules/operations/orthogonalize.js +++ b/modules/operations/orthogonalize.js @@ -13,7 +13,7 @@ export function operationOrthogonalize(selectedIDs, context) { var operation = function() { - context.perform(action, t('operations.orthogonalize.annotation.' + geometry)); + context.perform(action, operation.annotation); }; @@ -47,6 +47,7 @@ export function operationOrthogonalize(selectedIDs, context) { operation.id = 'orthogonalize'; operation.keys = [t('operations.orthogonalize.key')]; operation.title = t('operations.orthogonalize.title'); + operation.annotation = t('operations.orthogonalize.annotation.' + geometry); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index ce224d9d2..85fdcfdb9 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -26,7 +26,7 @@ export function operationReflect(selectedIDs, context, axis) { var operation = function() { var action = actionReflect(selectedIDs, context.projection) .useLongAxis(Boolean(axis === 'long')); - context.perform(action, t('operations.reflect.annotation.' + axis + '.' + multi)); + context.perform(action, operation.annotation); }; @@ -70,6 +70,7 @@ export function operationReflect(selectedIDs, context, axis) { operation.id = 'reflect-' + axis; operation.keys = [t('operations.reflect.key.' + axis)]; operation.title = t('operations.reflect.title.' + axis); + operation.annotation = t('operations.reflect.annotation.' + axis + '.' + multi); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/reverse.js b/modules/operations/reverse.js index 2e0d39b40..a16904d3d 100644 --- a/modules/operations/reverse.js +++ b/modules/operations/reverse.js @@ -7,7 +7,7 @@ export function operationReverse(selectedIDs, context) { var entityId = selectedIDs[0]; var operation = function() { - context.perform(actionReverse(entityId), t('operations.reverse.annotation')); + context.perform(actionReverse(entityId), operation.annotation); }; @@ -29,6 +29,7 @@ export function operationReverse(selectedIDs, context) { operation.id = 'reverse'; operation.keys = [t('operations.reverse.key')]; operation.title = t('operations.reverse.title'); + operation.annotation = t('operations.reverse.annotation'); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index aa7359f09..9e702acc3 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -57,6 +57,9 @@ export function operationRotate(selectedIDs, context) { operation.id = 'rotate'; operation.keys = [t('operations.rotate.key')]; operation.title = t('operations.rotate.title'); + operation.annotation = selectedIDs.length === 1 ? + t('operations.rotate.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.rotate.annotation.multiple'); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/split.js b/modules/operations/split.js index cc81c90a3..229e83458 100644 --- a/modules/operations/split.js +++ b/modules/operations/split.js @@ -11,24 +11,19 @@ export function operationSplit(selectedIDs, context) { }); var entityId = vertices[0], - action = actionSplit(entityId); + action = actionSplit(entityId), + ways = []; - if (selectedIDs.length > 1) { - action.limitWays(_.without(selectedIDs, entityId)); + if (vertices.length === 1) { + if (selectedIDs.length > 1) { + action.limitWays(_.without(selectedIDs, entityId)); + } + ways = action.ways(context.graph()); } var operation = function() { - var annotation; - - var ways = action.ways(context.graph()); - if (ways.length === 1) { - annotation = t('operations.split.annotation.' + context.geometry(ways[0].id)); - } else { - annotation = t('operations.split.annotation.multiple', {n: ways.length}); - } - - var difference = context.perform(action, annotation); + var difference = context.perform(action, operation.annotation); context.enter(modeSelect(context, difference.extantIDs())); }; @@ -52,8 +47,6 @@ export function operationSplit(selectedIDs, context) { if (disable) { return t('operations.split.' + disable); } - - var ways = action.ways(context.graph()); if (ways.length === 1) { return t('operations.split.description.' + context.geometry(ways[0].id)); } else { @@ -65,6 +58,9 @@ export function operationSplit(selectedIDs, context) { operation.id = 'split'; operation.keys = [t('operations.split.key')]; operation.title = t('operations.split.title'); + operation.annotation = ways.length === 1 ? + t('operations.split.annotation.' + context.geometry(ways[0].id)) : + t('operations.split.annotation.multiple', { n: ways.length }); operation.behavior = behaviorOperation(context).which(operation); return operation; diff --git a/modules/operations/straighten.js b/modules/operations/straighten.js index 8a029caa0..afe87e4c8 100644 --- a/modules/operations/straighten.js +++ b/modules/operations/straighten.js @@ -10,7 +10,7 @@ export function operationStraighten(selectedIDs, context) { function operation() { - context.perform(action, t('operations.straighten.annotation')); + context.perform(action, operation.annotation); } @@ -44,6 +44,7 @@ export function operationStraighten(selectedIDs, context) { operation.keys = [t('operations.straighten.key')]; operation.title = t('operations.straighten.title'); operation.behavior = behaviorOperation(context).which(operation); + operation.annotation = t('operations.straighten.annotation'); return operation; }