Expose annotations for each operation

This commit is contained in:
Bryan Housel
2017-02-15 22:01:30 -05:00
parent 33227c2b53
commit 028ef3de3f
13 changed files with 46 additions and 36 deletions
+7 -3
View File
@@ -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);
}
+2 -1
View File
@@ -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;
+1
View File
@@ -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;
+6 -9
View File
@@ -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;
+2 -1
View File
@@ -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;
+3 -3
View File
@@ -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;
+3
View File
@@ -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;
+2 -1
View File
@@ -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;
+2 -1
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, 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;
+2 -1
View File
@@ -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;
+3
View File
@@ -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;
+11 -15
View File
@@ -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;
+2 -1
View File
@@ -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;
}