mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 17:52:55 +00:00
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.
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
import _ from 'lodash';
|
|
import { t } from '../util/locale';
|
|
import { actionStraighten } from '../actions/index';
|
|
import { behaviorOperation } from '../behavior/index';
|
|
|
|
|
|
export function operationStraighten(selectedIDs, context) {
|
|
var entityId = selectedIDs[0],
|
|
action = actionStraighten(entityId, context.projection);
|
|
|
|
|
|
function operation() {
|
|
context.perform(action, operation.annotation());
|
|
}
|
|
|
|
|
|
operation.available = function() {
|
|
var entity = context.entity(entityId);
|
|
return selectedIDs.length === 1 &&
|
|
entity.type === 'way' &&
|
|
!entity.isClosed() &&
|
|
_.uniq(entity.nodes).length > 2;
|
|
};
|
|
|
|
|
|
operation.disabled = function() {
|
|
var reason;
|
|
if (context.hasHiddenConnections(entityId)) {
|
|
reason = 'connected_to_hidden';
|
|
}
|
|
return action.disabled(context.graph()) || reason;
|
|
};
|
|
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.straighten.' + disable) :
|
|
t('operations.straighten.description');
|
|
};
|
|
|
|
|
|
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);
|
|
|
|
return operation;
|
|
}
|