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.
This commit is contained in:
Bryan Housel
2017-02-15 23:02:13 -05:00
parent b7a81c6bec
commit 2ce78d6c43
13 changed files with 79 additions and 31 deletions

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

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