From ad327befc74a18790fa79c84758d7f4f3d4df952 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 25 Mar 2020 13:59:09 -0700 Subject: [PATCH] Move keybindings from map panes to uiInit --- modules/ui/init.js | 40 +++++++++++++++++++++++++++++++++- modules/ui/panes/background.js | 19 ---------------- modules/ui/panes/map_data.js | 32 --------------------------- 3 files changed, 39 insertions(+), 52 deletions(-) diff --git a/modules/ui/init.js b/modules/ui/init.js index 23697ba98..9279aa551 100644 --- a/modules/ui/init.js +++ b/modules/ui/init.js @@ -311,7 +311,45 @@ export function uiInit(context) { .on(['⇧←', uiCmd('⌘←')], pan([map.dimensions()[0], 0])) .on(['⇧↑', uiCmd('⌘↑')], pan([0, map.dimensions()[1]])) .on(['⇧→', uiCmd('⌘→')], pan([-map.dimensions()[0], 0])) - .on(['⇧↓', uiCmd('⌘↓')], pan([0, -map.dimensions()[1]])); + .on(['⇧↓', uiCmd('⌘↓')], pan([0, -map.dimensions()[1]])) + .on(uiCmd('⌘' + t('background.key')), function quickSwitch() { + if (d3_event) { + d3_event.stopImmediatePropagation(); + d3_event.preventDefault(); + } + var previousBackground = context.background().findSource(context.storage('background-last-used-toggle')); + if (previousBackground) { + var currentBackground = context.background().baseLayerSource(); + context.storage('background-last-used-toggle', currentBackground.id); + context.storage('background-last-used', previousBackground.id); + context.background().baseLayerSource(previousBackground); + } + }) + .on(t('area_fill.wireframe.key'), function toggleWireframe() { + d3_event.preventDefault(); + d3_event.stopPropagation(); + context.map().toggleWireframe(); + }) + .on(uiCmd('⌥' + t('area_fill.wireframe.key')), function toggleOsmData() { + d3_event.preventDefault(); + d3_event.stopPropagation(); + + // Don't allow layer changes while drawing - #6584 + var mode = context.mode(); + if (mode && /^draw/.test(mode.id)) return; + + var layer = context.layers().layer('osm'); + if (layer) { + layer.enabled(!layer.enabled()); + if (!layer.enabled()) { + context.enter(modeBrowse(context)); + } + } + }) + .on(t('map_data.highlight_edits.key'), function toggleHighlightEdited() { + d3_event.preventDefault(); + context.map().toggleHighlightEdited(); + }); context.enter(modeBrowse(context)); diff --git a/modules/ui/panes/background.js b/modules/ui/panes/background.js index 5a96dfd4c..74c9e9fb2 100644 --- a/modules/ui/panes/background.js +++ b/modules/ui/panes/background.js @@ -1,7 +1,5 @@ -import { event as d3_event } from 'd3-selection'; import { t } from '../../util/locale'; -import { uiCmd } from '../cmd'; import { uiPane } from '../pane'; import { uiSectionBackgroundDisplayOptions } from '../sections/background_display_options'; @@ -11,23 +9,6 @@ import { uiSectionOverlayList } from '../sections/overlay_list'; export function uiPaneBackground(context) { - context.keybinding() - .on(uiCmd('⌘' + t('background.key')), quickSwitch); - - function quickSwitch() { - if (d3_event) { - d3_event.stopImmediatePropagation(); - d3_event.preventDefault(); - } - var previousBackground = context.background().findSource(context.storage('background-last-used-toggle')); - if (previousBackground) { - var currentBackground = context.background().baseLayerSource(); - context.storage('background-last-used-toggle', currentBackground.id); - context.storage('background-last-used', previousBackground.id); - context.background().baseLayerSource(previousBackground); - } - } - var backgroundPane = uiPane('background', context) .key(t('background.key')) .title(t('background.title')) diff --git a/modules/ui/panes/map_data.js b/modules/ui/panes/map_data.js index 11d2d7051..8446756b2 100644 --- a/modules/ui/panes/map_data.js +++ b/modules/ui/panes/map_data.js @@ -1,10 +1,5 @@ -import { - event as d3_event -} from 'd3-selection'; import { t } from '../../util/locale'; -import { modeBrowse } from '../../modes/browse'; -import { uiCmd } from '../cmd'; import { uiPane } from '../pane'; import { uiSectionDataLayers } from '../sections/data_layers'; @@ -14,33 +9,6 @@ import { uiSectionPhotoOverlays } from '../sections/photo_overlays'; export function uiPaneMapData(context) { - context.keybinding() - .on(t('area_fill.wireframe.key'), function toggleWireframe() { - d3_event.preventDefault(); - d3_event.stopPropagation(); - context.map().toggleWireframe(); - }) - .on(uiCmd('⌥' + t('area_fill.wireframe.key')), function toggleOsmData() { - d3_event.preventDefault(); - d3_event.stopPropagation(); - - // Don't allow layer changes while drawing - #6584 - var mode = context.mode(); - if (mode && /^draw/.test(mode.id)) return; - - var layer = context.layers().layer('osm'); - if (layer) { - layer.enabled(!layer.enabled()); - if (!layer.enabled()) { - context.enter(modeBrowse(context)); - } - } - }) - .on(t('map_data.highlight_edits.key'), function toggleHighlightEdited() { - d3_event.preventDefault(); - context.map().toggleHighlightEdited(); - }); - var mapDataPane = uiPane('map-data', context) .key(t('map_data.key')) .title(t('map_data.title'))