Behaviors for all Operations

This commit is contained in:
Bryan Housel
2016-12-20 00:28:24 -05:00
parent 068a40e6cc
commit 087a8c62d1
14 changed files with 47 additions and 44 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ export function behaviorOperation(context) {
keybinding = d3keybinding('behavior.key.' + which.id);
keybinding.on(which.keys, function() {
d3.event.preventDefault();
if (!(context.inIntro() || which.disabled())) {
if (which.available() && !which.disabled() && !context.inIntro()) {
which();
}
});
+10 -15
View File
@@ -392,16 +392,22 @@ export function modeSelect(context, selectedIDs) {
if (!checkSelectedIDs()) return;
behaviors.forEach(function(behavior) {
context.install(behavior);
});
var operations = _.without(d3.values(Operations), Operations.operationDelete)
.map(function(o) { return o(selectedIDs, context); })
.filter(function(o) { return o.available(); });
operations.unshift(Operations.operationDelete(selectedIDs, context));
operations.forEach(function(operation) {
if (operation.behavior) {
behaviors.push(operation.behavior);
}
});
behaviors.forEach(function(behavior) {
context.install(behavior);
});
keybinding
.on(['[','pgup'], previousVertex)
.on([']', 'pgdown'], nextVertex)
@@ -411,17 +417,6 @@ export function modeSelect(context, selectedIDs) {
.on('⎋', esc, true)
.on('space', toggleMenu);
operations.forEach(function(operation) {
operation.keys.forEach(function(key) {
keybinding.on(key, function() {
d3.event.preventDefault();
if (!(context.inIntro() || operation.disabled())) {
operation();
}
});
});
});
d3.select(document)
.call(keybinding);
+4 -3
View File
@@ -1,6 +1,7 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { actionCircularize } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
export function operationCircularize(selectedIDs, context) {
@@ -10,9 +11,9 @@ export function operationCircularize(selectedIDs, context) {
geometry = context.geometry(entityId),
action = actionCircularize(entityId, context.projection);
var operation = function() {
var annotation = t('operations.circularize.annotation.' + geometry);
context.perform(action, annotation);
context.perform(action, t('operations.circularize.annotation.' + geometry));
};
@@ -45,7 +46,7 @@ export function operationCircularize(selectedIDs, context) {
operation.id = 'circularize';
operation.keys = [t('operations.circularize.key')];
operation.title = t('operations.circularize.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+2 -1
View File
@@ -1,6 +1,7 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { modeDrawLine } from '../modes/index';
import { behaviorOperation } from '../behavior/index';
export function operationContinue(selectedIDs, context) {
@@ -54,7 +55,7 @@ export function operationContinue(selectedIDs, context) {
operation.id = 'continue';
operation.keys = [t('operations.continue.key')];
operation.title = t('operations.continue.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+4 -3
View File
@@ -1,9 +1,10 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { modeBrowse, modeSelect } from '../modes/index';
import { actionDeleteMultiple } from '../actions/index';
import { uiCmd } from '../ui/index';
import { behaviorOperation } from '../behavior/index';
import { geoSphericalDistance } from '../geo/index';
import { modeBrowse, modeSelect } from '../modes/index';
import { uiCmd } from '../ui/index';
export function operationDelete(selectedIDs, context) {
@@ -82,7 +83,7 @@ export function operationDelete(selectedIDs, context) {
operation.id = 'delete';
operation.keys = [uiCmd('⌘⌫'), uiCmd('⌘⌦'), uiCmd('⌦')];
operation.title = t('operations.delete.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+3 -1
View File
@@ -1,6 +1,7 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { actionDisconnect } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
export function operationDisconnect(selectedIDs, context) {
@@ -15,6 +16,7 @@ export function operationDisconnect(selectedIDs, context) {
action.limitWays(_.without(selectedIDs, entityId));
}
var operation = function() {
context.perform(action, t('operations.disconnect.annotation'));
};
@@ -45,7 +47,7 @@ export function operationDisconnect(selectedIDs, context) {
operation.id = 'disconnect';
operation.keys = [t('operations.disconnect.key')];
operation.title = t('operations.disconnect.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+2 -1
View File
@@ -5,6 +5,7 @@ import {
actionMergePolygon
} from '../actions/index';
import { behaviorOperation } from '../behavior/index';
import { modeSelect } from '../modes/index';
@@ -68,7 +69,7 @@ export function operationMerge(selectedIDs, context) {
operation.id = 'merge';
operation.keys = [t('operations.merge.key')];
operation.title = t('operations.merge.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+4 -2
View File
@@ -1,7 +1,8 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { geoExtent } from '../geo/index';
import { actionMove } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
import { geoExtent } from '../geo/index';
import { modeMove } from '../modes/index';
@@ -10,6 +11,7 @@ export function operationMove(selectedIDs, context) {
return extent.extend(context.entity(id).extent(context.graph()));
}, geoExtent());
var operation = function() {
context.enter(modeMove(context, selectedIDs));
};
@@ -44,7 +46,7 @@ export function operationMove(selectedIDs, context) {
operation.id = 'move';
operation.keys = [t('operations.move.key')];
operation.title = t('operations.move.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+4 -3
View File
@@ -1,6 +1,7 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { actionOrthogonalize } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
export function operationOrthogonalize(selectedIDs, context) {
@@ -10,9 +11,9 @@ export function operationOrthogonalize(selectedIDs, context) {
geometry = context.geometry(entityId),
action = actionOrthogonalize(entityId, context.projection);
var operation = function() {
var annotation = t('operations.orthogonalize.annotation.' + geometry);
context.perform(action, annotation);
context.perform(action, t('operations.orthogonalize.annotation.' + geometry));
};
@@ -46,7 +47,7 @@ export function operationOrthogonalize(selectedIDs, context) {
operation.id = 'orthogonalize';
operation.keys = [t('operations.orthogonalize.key')];
operation.title = t('operations.orthogonalize.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
-1
View File
@@ -56,6 +56,5 @@ export function operationReflect(selectedIDs, context, axis) {
operation.title = t('operations.reflect.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+4 -7
View File
@@ -1,21 +1,18 @@
import { t } from '../util/locale';
import { actionReverse } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
export function operationReverse(selectedIDs, context) {
var entityId = selectedIDs[0];
var operation = function() {
context.perform(
actionReverse(entityId),
t('operations.reverse.annotation')
);
context.perform(actionReverse(entityId), t('operations.reverse.annotation'));
};
operation.available = function() {
return selectedIDs.length === 1 &&
context.geometry(entityId) === 'line';
return selectedIDs.length === 1 && context.geometry(entityId) === 'line';
};
@@ -32,7 +29,7 @@ export function operationReverse(selectedIDs, context) {
operation.id = 'reverse';
operation.keys = [t('operations.reverse.key')];
operation.title = t('operations.reverse.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+3 -1
View File
@@ -1,5 +1,6 @@
import { t } from '../util/locale';
import { modeRotateWay } from '../modes/index';
import { behaviorOperation } from '../behavior/index';
export function operationRotate(selectedIDs, context) {
@@ -8,6 +9,7 @@ export function operationRotate(selectedIDs, context) {
extent = entity.extent(context.graph()),
geometry = context.geometry(entityId);
var operation = function() {
context.enter(modeRotateWay(context, entityId));
};
@@ -47,7 +49,7 @@ export function operationRotate(selectedIDs, context) {
operation.id = 'rotate';
operation.keys = [t('operations.rotate.key')];
operation.title = t('operations.rotate.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+3 -2
View File
@@ -1,7 +1,8 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { modeSelect } from '../modes/index';
import { actionSplit } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
import { modeSelect } from '../modes/index';
export function operationSplit(selectedIDs, context) {
@@ -64,7 +65,7 @@ export function operationSplit(selectedIDs, context) {
operation.id = 'split';
operation.keys = [t('operations.split.key')];
operation.title = t('operations.split.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}
+3 -3
View File
@@ -1,6 +1,7 @@
import _ from 'lodash';
import { t } from '../util/locale';
import { actionStraighten } from '../actions/index';
import { behaviorOperation } from '../behavior/index';
export function operationStraighten(selectedIDs, context) {
@@ -9,8 +10,7 @@ export function operationStraighten(selectedIDs, context) {
function operation() {
var annotation = t('operations.straighten.annotation');
context.perform(action, annotation);
context.perform(action, t('operations.straighten.annotation'));
}
@@ -43,7 +43,7 @@ export function operationStraighten(selectedIDs, context) {
operation.id = 'straighten';
operation.keys = [t('operations.straighten.key')];
operation.title = t('operations.straighten.title');
operation.behavior = behaviorOperation(context).which(operation);
return operation;
}