From 2ce78d6c4399b954ee9dbfd058b3eeafac5bfab6 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Wed, 15 Feb 2017 23:02:13 -0500 Subject: [PATCH] Call annotation as a function instead of a property This is because, like tooltip(), it doesn't always make sense to call it, and it should never get called if the operation is not available. --- modules/behavior/operation.js | 4 ++-- modules/operations/circularize.js | 8 ++++++-- modules/operations/continue.js | 6 +++++- modules/operations/delete.js | 12 ++++++++---- modules/operations/disconnect.js | 8 ++++++-- modules/operations/merge.js | 8 ++++++-- modules/operations/move.js | 10 +++++++--- modules/operations/orthogonalize.js | 8 ++++++-- modules/operations/reflect.js | 8 ++++++-- modules/operations/reverse.js | 8 ++++++-- modules/operations/rotate.js | 10 +++++++--- modules/operations/split.js | 12 ++++++++---- modules/operations/straighten.js | 8 ++++++-- 13 files changed, 79 insertions(+), 31 deletions(-) diff --git a/modules/behavior/operation.js b/modules/behavior/operation.js index f397460d3..997c42487 100644 --- a/modules/behavior/operation.js +++ b/modules/behavior/operation.js @@ -15,9 +15,9 @@ export function behaviorOperation(context) { d3.event.preventDefault(); var disabled = which.disabled(); if (disabled) { - uiFlash(2000, 500).text(which.tooltip); + uiFlash(2500, 500).text(which.tooltip); } else { - var annotation = which.annotation || which.title; + var annotation = which.annotation() || which.title; uiFlash(1500, 250).text(annotation); which(); } diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index 895d33aef..a7b713bb0 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, operation.annotation); + context.perform(action, operation.annotation()); }; @@ -43,10 +43,14 @@ export function operationCircularize(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.circularize.annotation.' + geometry); + }; + + 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 2393ada58..77e45905c 100644 --- a/modules/operations/continue.js +++ b/modules/operations/continue.js @@ -53,10 +53,14 @@ export function operationContinue(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.continue.annotation.line'); + }; + + 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 b7d330482..ae8b28c29 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -41,7 +41,7 @@ export function operationDelete(selectedIDs, context) { } } - context.perform(action, operation.annotation); + context.perform(action, operation.annotation()); if (nextSelectedID && context.hasEntity(nextSelectedID)) { context.enter( @@ -102,12 +102,16 @@ export function operationDelete(selectedIDs, context) { }; + operation.annotation = function() { + return selectedIDs.length === 1 ? + t('operations.delete.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.delete.annotation.multiple', { n: selectedIDs.length }); + }; + + 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 815fe8c94..2649f0e6f 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, operation.annotation); + context.perform(action, operation.annotation()); }; @@ -44,10 +44,14 @@ export function operationDisconnect(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.disconnect.annotation'); + }; + + 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 e986b4688..b35d21973 100644 --- a/modules/operations/merge.js +++ b/modules/operations/merge.js @@ -25,7 +25,7 @@ export function operationMerge(selectedIDs, context) { action = mergePolygon; } - context.perform(action, operation.annotation); + context.perform(action, operation.annotation()); var ids = selectedIDs.filter(function(id) { var entity = context.hasEntity(id); return entity && entity.type !== 'node'; @@ -68,10 +68,14 @@ export function operationMerge(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.merge.annotation', { n: selectedIDs.length }); + }; + + 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 07af2d7cf..1205562a0 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -49,12 +49,16 @@ export function operationMove(selectedIDs, context) { }; + operation.annotation = function() { + return selectedIDs.length === 1 ? + t('operations.move.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.move.annotation.multiple'); + }; + + 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 f34f2facd..50f1f685e 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, operation.annotation); + context.perform(action, operation.annotation()); }; @@ -44,10 +44,14 @@ export function operationOrthogonalize(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.orthogonalize.annotation.' + geometry); + }; + + 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 85fdcfdb9..2457e20b3 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, operation.annotation); + context.perform(action, operation.annotation()); }; @@ -67,10 +67,14 @@ export function operationReflect(selectedIDs, context, axis) { }; + operation.annotation = function() { + return t('operations.reflect.annotation.' + axis + '.' + multi); + }; + + 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 a16904d3d..3320c6902 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), operation.annotation); + context.perform(actionReverse(entityId), operation.annotation()); }; @@ -26,10 +26,14 @@ export function operationReverse(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.reverse.annotation'); + }; + + 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 9e702acc3..b0fe066f4 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -54,12 +54,16 @@ export function operationRotate(selectedIDs, context) { }; + operation.annotation = function() { + return selectedIDs.length === 1 ? + t('operations.rotate.annotation.' + context.geometry(selectedIDs[0])) : + t('operations.rotate.annotation.multiple'); + }; + + 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 229e83458..0823d4879 100644 --- a/modules/operations/split.js +++ b/modules/operations/split.js @@ -23,7 +23,7 @@ export function operationSplit(selectedIDs, context) { var operation = function() { - var difference = context.perform(action, operation.annotation); + var difference = context.perform(action, operation.annotation()); context.enter(modeSelect(context, difference.extantIDs())); }; @@ -55,12 +55,16 @@ export function operationSplit(selectedIDs, context) { }; + operation.annotation = function() { + return ways.length === 1 ? + t('operations.split.annotation.' + context.geometry(ways[0].id)) : + t('operations.split.annotation.multiple', { n: ways.length }); + }; + + 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 afe87e4c8..5d4f8a835 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, operation.annotation); + context.perform(action, operation.annotation()); } @@ -40,11 +40,15 @@ export function operationStraighten(selectedIDs, context) { }; + operation.annotation = function() { + return t('operations.straighten.annotation'); + }; + + operation.id = 'straighten'; 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; }