Disable Undo/Redo when map is not editable

(closes #4358)
This commit is contained in:
Bryan Housel
2017-09-18 22:00:35 -04:00
parent 1d3c921481
commit 9fa1b567a0
+14 -5
View File
@@ -1,4 +1,5 @@
import * as d3 from 'd3';
import _ from 'lodash';
import { d3keybinding } from '../lib/d3.keybinding.js';
import { t, textDirection } from '../util/locale';
import { svgIcon } from '../svg/index';
@@ -11,18 +12,18 @@ export function uiUndoRedo(context) {
var commands = [{
id: 'undo',
cmd: uiCmd('⌘Z'),
action: function() { if (!saving()) context.undo(); },
action: function() { if (editable()) context.undo(); },
annotation: function() { return context.history().undoAnnotation(); }
}, {
id: 'redo',
cmd: uiCmd('⌘⇧Z'),
action: function() { if (!saving()) context.redo(); },
action: function() { if (editable()) context.redo(); },
annotation: function() { return context.history().redoAnnotation(); }
}];
function saving() {
return context.mode().id === 'save';
function editable() {
return context.editable() && context.mode().id !== 'save';
}
@@ -64,15 +65,23 @@ export function uiUndoRedo(context) {
d3.select(document)
.call(keybinding);
var debouncedUpdate = _.debounce(update, 500, { leading: true, trailing: true });
context.map()
.on('move.undo_redo', debouncedUpdate)
.on('drawn.undo_redo', debouncedUpdate);
context.history()
.on('change.undo_redo', update);
context
.on('enter.undo_redo', update);
function update() {
buttons
.property('disabled', saving())
.property('disabled', !editable())
.classed('disabled', function(d) { return !d.annotation(); })
.each(function() {
var selection = d3.select(this);