mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-25 17:37:49 +02:00
Move the edit menu logic to uiInit
Make context the first argument of operation objects Add Paste operation to edit menu when opening the context menu on a blank area of the map (close #2508)
This commit is contained in:
@@ -8,6 +8,7 @@ import { behaviorSelect } from '../behavior/select';
|
||||
import { modeDragNode } from './drag_node';
|
||||
import { modeDragNote } from './drag_note';
|
||||
|
||||
import { operationPaste } from '../operations/paste';
|
||||
|
||||
export function modeBrowse(context) {
|
||||
var mode = {
|
||||
@@ -60,5 +61,10 @@ export function modeBrowse(context) {
|
||||
};
|
||||
|
||||
|
||||
mode.operations = function() {
|
||||
return [operationPaste(context)];
|
||||
};
|
||||
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ export function modeMove(context, entityIDs, baseGraph) {
|
||||
var keybinding = utilKeybinding('move');
|
||||
var behaviors = [
|
||||
behaviorEdit(context),
|
||||
operationCircularize(entityIDs, context).behavior,
|
||||
operationDelete(entityIDs, context).behavior,
|
||||
operationOrthogonalize(entityIDs, context).behavior,
|
||||
operationReflectLong(entityIDs, context).behavior,
|
||||
operationReflectShort(entityIDs, context).behavior,
|
||||
operationRotate(entityIDs, context).behavior
|
||||
operationCircularize(context, entityIDs).behavior,
|
||||
operationDelete(context, entityIDs).behavior,
|
||||
operationOrthogonalize(context, entityIDs).behavior,
|
||||
operationReflectLong(context, entityIDs).behavior,
|
||||
operationReflectShort(context, entityIDs).behavior,
|
||||
operationRotate(context, entityIDs).behavior
|
||||
];
|
||||
var annotation = entityIDs.length === 1 ?
|
||||
t('operations.move.annotation.' + context.graph().geometry(entityIDs[0])) :
|
||||
|
||||
@@ -34,12 +34,12 @@ export function modeRotate(context, entityIDs) {
|
||||
var keybinding = utilKeybinding('rotate');
|
||||
var behaviors = [
|
||||
behaviorEdit(context),
|
||||
operationCircularize(entityIDs, context).behavior,
|
||||
operationDelete(entityIDs, context).behavior,
|
||||
operationMove(entityIDs, context).behavior,
|
||||
operationOrthogonalize(entityIDs, context).behavior,
|
||||
operationReflectLong(entityIDs, context).behavior,
|
||||
operationReflectShort(entityIDs, context).behavior
|
||||
operationCircularize(context, entityIDs).behavior,
|
||||
operationDelete(context, entityIDs).behavior,
|
||||
operationMove(context, entityIDs).behavior,
|
||||
operationOrthogonalize(context, entityIDs).behavior,
|
||||
operationReflectLong(context, entityIDs).behavior,
|
||||
operationReflectShort(context, entityIDs).behavior
|
||||
];
|
||||
var annotation = entityIDs.length === 1 ?
|
||||
t('operations.rotate.annotation.' + context.graph().geometry(entityIDs[0])) :
|
||||
|
||||
+11
-60
@@ -17,7 +17,6 @@ import { modeDragNode } from './drag_node';
|
||||
import { modeDragNote } from './drag_note';
|
||||
import { osmNode, osmWay } from '../osm';
|
||||
import * as Operations from '../operations/index';
|
||||
import { uiEditMenu } from '../ui/edit_menu';
|
||||
import { uiCmd } from '../ui/cmd';
|
||||
import {
|
||||
utilArrayIntersection, utilDeepMemberSelector, utilEntityOrDeepMemberSelector,
|
||||
@@ -46,7 +45,6 @@ export function modeSelect(context, selectedIDs) {
|
||||
modeDragNote(context).behavior
|
||||
];
|
||||
var inspector; // unused?
|
||||
var _editMenu; // uiEditMenu
|
||||
var _newFeature = false;
|
||||
var _follow = false;
|
||||
|
||||
@@ -141,44 +139,6 @@ export function modeSelect(context, selectedIDs) {
|
||||
}
|
||||
|
||||
|
||||
function closeMenu() {
|
||||
// remove any existing menu no matter how it was added
|
||||
context.map().supersurface
|
||||
.select('.edit-menu').remove();
|
||||
}
|
||||
|
||||
mode.showMenu = function(anchorPoint, triggerType) {
|
||||
|
||||
// remove any displayed menu
|
||||
closeMenu();
|
||||
|
||||
// disable menu if in wide selection, for example
|
||||
if (!context.map().editableDataEnabled()) return;
|
||||
|
||||
// don't show the menu for relations alone
|
||||
if (selectedIDs.every(function(id) {
|
||||
return context.graph().geometry(id) === 'relation';
|
||||
})) return;
|
||||
|
||||
var surfaceNode = context.surface().node();
|
||||
if (surfaceNode.focus) { // FF doesn't support it
|
||||
// focus the surface or else clicking off the menu may not trigger modeBrowse
|
||||
surfaceNode.focus();
|
||||
}
|
||||
|
||||
// don't load the menu until it's needed
|
||||
if (!_editMenu) _editMenu = uiEditMenu(context);
|
||||
|
||||
_editMenu
|
||||
.anchorLoc(anchorPoint)
|
||||
.triggerType(triggerType)
|
||||
.operations(operations);
|
||||
|
||||
// render the menu
|
||||
context.map().supersurface.call(_editMenu);
|
||||
};
|
||||
|
||||
|
||||
mode.selectedIDs = function() {
|
||||
return selectedIDs;
|
||||
};
|
||||
@@ -189,12 +149,6 @@ export function modeSelect(context, selectedIDs) {
|
||||
};
|
||||
|
||||
|
||||
mode.reselect = function() {
|
||||
if (!checkSelectedIDs()) return;
|
||||
return mode;
|
||||
};
|
||||
|
||||
|
||||
mode.newFeature = function(val) {
|
||||
if (!arguments.length) return _newFeature;
|
||||
_newFeature = val;
|
||||
@@ -219,12 +173,12 @@ export function modeSelect(context, selectedIDs) {
|
||||
});
|
||||
|
||||
operations = Object.values(Operations)
|
||||
.map(function(o) { return o(selectedIDs, context); })
|
||||
.map(function(o) { return o(context, selectedIDs); })
|
||||
.filter(function(o) { return o.available() && o.id !== 'delete' && o.id !== 'downgrade'; });
|
||||
|
||||
var downgradeOperation = Operations.operationDowngrade(selectedIDs, context);
|
||||
var downgradeOperation = Operations.operationDowngrade(context, selectedIDs);
|
||||
// don't allow delete if downgrade is available
|
||||
var lastOperation = !context.inIntro() && downgradeOperation.available() ? downgradeOperation : Operations.operationDelete(selectedIDs, context);
|
||||
var lastOperation = !context.inIntro() && downgradeOperation.available() ? downgradeOperation : Operations.operationDelete(context, selectedIDs);
|
||||
|
||||
operations.push(lastOperation);
|
||||
|
||||
@@ -235,9 +189,13 @@ export function modeSelect(context, selectedIDs) {
|
||||
});
|
||||
|
||||
// remove any displayed menu
|
||||
closeMenu();
|
||||
context.ui().closeEditMenu();
|
||||
}
|
||||
|
||||
mode.operations = function() {
|
||||
return operations;
|
||||
};
|
||||
|
||||
|
||||
mode.enter = function() {
|
||||
if (!checkSelectedIDs()) return;
|
||||
@@ -269,11 +227,10 @@ export function modeSelect(context, selectedIDs) {
|
||||
// reselect after change in case relation members were removed or added
|
||||
selectElements();
|
||||
})
|
||||
.on('undone.select', update)
|
||||
.on('redone.select', update);
|
||||
.on('undone.select', checkSelectedIDs)
|
||||
.on('redone.select', checkSelectedIDs);
|
||||
|
||||
context.map()
|
||||
.on('move.select', closeMenu)
|
||||
.on('drawn.select', selectElements)
|
||||
.on('crossEditableZoom.select', function() {
|
||||
selectElements();
|
||||
@@ -301,12 +258,6 @@ export function modeSelect(context, selectedIDs) {
|
||||
}
|
||||
|
||||
|
||||
function update() {
|
||||
closeMenu();
|
||||
checkSelectedIDs();
|
||||
}
|
||||
|
||||
|
||||
function didDoubleUp(loc) {
|
||||
if (!context.map().withinEditableZoom()) return;
|
||||
|
||||
@@ -500,7 +451,7 @@ export function modeSelect(context, selectedIDs) {
|
||||
d3_select(document)
|
||||
.call(keybinding.unbind);
|
||||
|
||||
closeMenu();
|
||||
context.ui().closeEditMenu();
|
||||
|
||||
context.history()
|
||||
.on('change.select', null)
|
||||
|
||||
Reference in New Issue
Block a user