mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-14 01:33:03 +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.
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import _ from 'lodash';
|
|
import { t } from '../util/locale';
|
|
import { actionDisconnect } from '../actions/index';
|
|
import { behaviorOperation } from '../behavior/index';
|
|
|
|
|
|
export function operationDisconnect(selectedIDs, context) {
|
|
var vertices = _.filter(selectedIDs, function(entityId) {
|
|
return context.geometry(entityId) === 'vertex';
|
|
});
|
|
|
|
var entityId = vertices[0],
|
|
action = actionDisconnect(entityId);
|
|
|
|
if (selectedIDs.length > 1) {
|
|
action.limitWays(_.without(selectedIDs, entityId));
|
|
}
|
|
|
|
|
|
var operation = function() {
|
|
context.perform(action, operation.annotation());
|
|
};
|
|
|
|
|
|
operation.available = function() {
|
|
return vertices.length === 1;
|
|
};
|
|
|
|
|
|
operation.disabled = function() {
|
|
var reason;
|
|
if (_.some(selectedIDs, context.hasHiddenConnections)) {
|
|
reason = 'connected_to_hidden';
|
|
}
|
|
return action.disabled(context.graph()) || reason;
|
|
};
|
|
|
|
|
|
operation.tooltip = function() {
|
|
var disable = operation.disabled();
|
|
return disable ?
|
|
t('operations.disconnect.' + disable) :
|
|
t('operations.disconnect.description');
|
|
};
|
|
|
|
|
|
operation.annotation = function() {
|
|
return t('operations.disconnect.annotation');
|
|
};
|
|
|
|
|
|
operation.id = 'disconnect';
|
|
operation.keys = [t('operations.disconnect.key')];
|
|
operation.title = t('operations.disconnect.title');
|
|
operation.behavior = behaviorOperation(context).which(operation);
|
|
|
|
return operation;
|
|
}
|