Permalink
Browse files

Tooltips for disabled operations (fixes #573)

  • Loading branch information...
jfirebaugh committed Mar 29, 2013
1 parent 52dd7bf commit b1daf85cfde0156b7ced0d6055a92b37340ee64c
View
@@ -39,18 +39,22 @@ en:
annotation: Changed tags.
circularize:
title: Circularize
- description: Make this round.
+ description:
+ line: Make this line circular.
+ area: Make this area circular.
key: O
annotation:
line: Made a line circular.
area: Made an area circular.
+ not_closed: This can't be made circular because it's not a loop.
orthogonalize:
title: Orthogonalize
description: Square these corners.
key: Q
annotation:
line: Squared the corners of a line.
area: Squared the corners of an area.
+ not_closed: This can't be made square because it's not a loop.
delete:
title: Delete
description: Remove this from the map.
@@ -69,14 +73,17 @@ en:
area: Connected a way to an area.
disconnect:
title: Disconnect
- description: Disconnect these ways from each other.
+ description: Disconnect these lines/areas from each other.
key: D
- annotation: Disconnected ways.
+ annotation: Disconnected lines/areas.
+ not_connected: There aren't enough lines/areas here to disconnect.
merge:
title: Merge
description: Merge these lines.
key: C
annotation: "Merged {n} lines."
+ not_eligible: These features can't be merged.
+ not_adjacent: These lines can't be merged because they aren't connected.
move:
title: Move
description: Move this to a different location.
@@ -87,6 +94,7 @@ en:
line: Moved a line.
area: Moved an area.
multiple: Moved multiple objects.
+ incomplete_relation: This feature can't be moved because it hasn't been fully downloaded.
rotate:
title: Rotate
description: Rotate this object around its centre point.
@@ -104,6 +112,8 @@ en:
description: Split this into two ways at this point.
key: X
annotation: Split a way.
+ not_eligible: Lines can't be split at their beginning or end.
+ multiple_ways: There are too many lines here to split.
nothing_to_undo: Nothing to undo.
nothing_to_redo: Nothing to redo.
just_edited: "You just edited OpenStreetMap!"
View
@@ -53,12 +53,16 @@ locale.en = {
},
"circularize": {
"title": "Circularize",
- "description": "Make this round.",
+ "description": {
+ "line": "Make this line circular.",
+ "area": "Make this area circular."
+ },
"key": "O",
"annotation": {
"line": "Made a line circular.",
"area": "Made an area circular."
- }
+ },
+ "not_closed": "This can't be made circular because it's not a loop."
},
"orthogonalize": {
"title": "Orthogonalize",
@@ -67,7 +71,8 @@ locale.en = {
"annotation": {
"line": "Squared the corners of a line.",
"area": "Squared the corners of an area."
- }
+ },
+ "not_closed": "This can't be made square because it's not a loop."
},
"delete": {
"title": "Delete",
@@ -91,15 +96,18 @@ locale.en = {
},
"disconnect": {
"title": "Disconnect",
- "description": "Disconnect these ways from each other.",
+ "description": "Disconnect these lines/areas from each other.",
"key": "D",
- "annotation": "Disconnected ways."
+ "annotation": "Disconnected lines/areas.",
+ "not_connected": "There aren't enough lines/areas here to disconnect."
},
"merge": {
"title": "Merge",
"description": "Merge these lines.",
"key": "C",
- "annotation": "Merged {n} lines."
+ "annotation": "Merged {n} lines.",
+ "not_eligible": "These features can't be merged.",
+ "not_adjacent": "These lines can't be merged because they aren't connected."
},
"move": {
"title": "Move",
@@ -111,7 +119,8 @@ locale.en = {
"line": "Moved a line.",
"area": "Moved an area.",
"multiple": "Moved multiple objects."
- }
+ },
+ "incomplete_relation": "This feature can't be moved because it hasn't been fully downloaded."
},
"rotate": {
"title": "Rotate",
@@ -132,7 +141,9 @@ locale.en = {
"title": "Split",
"description": "Split this into two ways at this point.",
"key": "X",
- "annotation": "Split a way."
+ "annotation": "Split a way.",
+ "not_eligible": "Lines can't be split at their beginning or end.",
+ "multiple_ways": "There are too many lines here to split."
}
},
"nothing_to_undo": "Nothing to undo.",
@@ -58,8 +58,9 @@ iD.actions.Circularize = function(wayId, projection, count) {
return graph;
};
- action.enabled = function(graph) {
- return graph.entity(wayId).isClosed();
+ action.disabled = function(graph) {
+ if (!graph.entity(wayId).isClosed())
+ return 'not_closed';
};
return action;
View
@@ -13,7 +13,7 @@
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/actions/MergeNodesAction.java
//
iD.actions.Connect = function(nodeIds) {
- var action = function(graph) {
+ return function(graph) {
var survivor = graph.entity(_.last(nodeIds));
for (var i = 0; i < nodeIds.length - 1; i++) {
@@ -37,10 +37,4 @@ iD.actions.Connect = function(nodeIds) {
return graph;
};
-
- action.enabled = function() {
- return nodeIds.length > 1;
- };
-
- return action;
};
@@ -12,9 +12,6 @@
//
iD.actions.Disconnect = function(nodeId, newNodeId) {
var action = function(graph) {
- if (!action.enabled(graph))
- return graph;
-
var node = graph.entity(nodeId);
graph.parentWays(node).forEach(function(parent, i) {
@@ -40,12 +37,14 @@ iD.actions.Disconnect = function(nodeId, newNodeId) {
return graph;
};
- action.enabled = function(graph) {
+ action.disabled = function(graph) {
var parentWays = graph.parentWays(graph.entity(nodeId));
- return parentWays.length >= 2 ||
- (parentWays.length == 1 && parentWays[0].nodes.filter(function(d) {
- return d === nodeId;
- }).length >= 2);
+ if (parentWays.length >= 2)
+ return;
+ if (parentWays.length === 0)
+ return 'not_connected';
+ if (parentWays[0].nodes.filter(function(d) { return d === nodeId; }).length < 2)
+ return 'not_connected';
};
return action;
View
@@ -57,19 +57,20 @@ iD.actions.Join = function(ids) {
return graph;
};
- action.enabled = function(graph) {
+ action.disabled = function(graph) {
var geometries = groupEntitiesByGeometry(graph);
if (ids.length !== 2 || ids.length !== geometries.line.length)
- return false;
+ return 'not_eligible';
var a = graph.entity(idA),
b = graph.entity(idB);
- return a.first() === b.first() ||
- a.first() === b.last() ||
- a.last() === b.first() ||
- a.last() === b.last();
+ if (a.first() !== b.first() &&
+ a.first() !== b.last() &&
+ a.last() !== b.first() &&
+ a.last() !== b.last())
+ return 'not_adjacent';
};
return action;
View
@@ -25,11 +25,12 @@ iD.actions.Merge = function(ids) {
return graph;
};
- action.enabled = function(graph) {
+ action.disabled = function(graph) {
var geometries = groupEntitiesByGeometry(graph);
- return geometries.point.length > 0 &&
- (geometries.area.length + geometries.line.length) === 1 &&
- geometries.relation.length === 0;
+ if (geometries.point.length === 0 ||
+ (geometries.area.length + geometries.line.length) !== 1 ||
+ geometries.relation.length !== 0)
+ return 'not_eligible';
};
return action;
View
@@ -29,11 +29,14 @@ iD.actions.Move = function(ids, delta, projection) {
return graph;
};
- action.enabled = function(graph) {
- return _.every(ids, function(id) {
+ action.disabled = function(graph) {
+ function incompleteRelation(id) {
var entity = graph.entity(id);
- return entity.type !== 'relation' || entity.isComplete(graph);
- });
+ return entity.type === 'relation' && !entity.isComplete(graph);
+ }
+
+ if (_.any(ids, incompleteRelation))
+ return 'incomplete_relation';
};
return action;
@@ -127,8 +127,9 @@ iD.actions.Orthogonalize = function(wayId, projection) {
}
};
- action.enabled = function(graph) {
- return graph.entity(wayId).isClosed();
+ action.disabled = function(graph) {
+ if (!graph.entity(wayId).isClosed())
+ return 'not_closed';
};
return action;
View
@@ -94,8 +94,12 @@ iD.actions.Split = function(nodeId, newWayId) {
return graph;
};
- action.enabled = function(graph) {
- return candidateWays(graph).length === 1;
+ action.disabled = function(graph) {
+ var candidates = candidateWays(graph);
+ if (candidates.length === 0)
+ return 'not_eligible';
+ if (candidates.length > 1)
+ return 'multiple_ways';
};
return action;
View
@@ -65,7 +65,7 @@ iD.modes.Select = function(context, selection, initial) {
operations.forEach(function(operation) {
operation.keys.forEach(function(key) {
keybinding.on(key, function() {
- if (operation.enabled()) {
+ if (!operation.disabled()) {
operation();
}
});
@@ -1,9 +1,10 @@
iD.operations.Circularize = function(selection, context) {
var entityId = selection[0],
+ geometry = context.geometry(entityId),
action = iD.actions.Circularize(entityId, context.projection);
var operation = function() {
- var annotation = t('operations.circularize.annotation.' + context.geometry(entityId));
+ var annotation = t('operations.circularize.annotation.' + geometry);
context.perform(action, annotation);
};
@@ -12,14 +13,20 @@ iD.operations.Circularize = function(selection, context) {
context.entity(entityId).type === 'way';
};
- operation.enabled = function() {
- return action.enabled(context.graph());
+ operation.disabled = function() {
+ return action.disabled(context.graph());
+ };
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ return disable ?
+ t('operations.circularize.' + disable) :
+ t('operations.circularize.description.' + geometry);
};
operation.id = "circularize";
operation.keys = [t('operations.circularize.key')];
operation.title = t('operations.circularize.title');
- operation.description = t('operations.circularize.description');
return operation;
};
@@ -19,14 +19,17 @@ iD.operations.Delete = function(selection, context) {
return true;
};
- operation.enabled = function() {
- return true;
+ operation.disabled = function() {
+ return false;
+ };
+
+ operation.tooltip = function() {
+ return t('operations.delete.description');
};
operation.id = "delete";
operation.keys = [iD.ui.cmd(''), iD.ui.cmd('')];
operation.title = t('operations.delete.title');
- operation.description = t('operations.delete.description');
return operation;
};
@@ -11,14 +11,20 @@ iD.operations.Disconnect = function(selection, context) {
context.geometry(entityId) === 'vertex';
};
- operation.enabled = function() {
- return action.enabled(context.graph());
+ operation.disabled = function() {
+ return action.disabled(context.graph());
+ };
+
+ operation.tooltip = function() {
+ var disable = operation.disabled();
+ return disable ?
+ t('operations.disconnect.' + disable) :
+ t('operations.disconnect.description');
};
operation.id = "disconnect";
operation.keys = [t('operations.disconnect.key')];
operation.title = t('operations.disconnect.title');
- operation.description = t('operations.disconnect.description');
return operation;
};
Oops, something went wrong.

0 comments on commit b1daf85

Please sign in to comment.