mirror of
https://github.com/FoggedLens/iD.git
synced 2026-04-29 23:17:53 +02:00
+32
-29
@@ -1,47 +1,50 @@
|
||||
iD.ui.UndoRedo = function(context) {
|
||||
var commands = [{
|
||||
id: 'undo',
|
||||
cmd: iD.ui.cmd('⌘Z'),
|
||||
action: context.undo,
|
||||
annotation: function() { return context.history().undoAnnotation(); }
|
||||
}, {
|
||||
id: 'redo',
|
||||
cmd: iD.ui.cmd('⌘⇧Z'),
|
||||
action: context.redo,
|
||||
annotation: function() { return context.history().redoAnnotation(); }
|
||||
}];
|
||||
|
||||
return function(selection) {
|
||||
var tooltip = bootstrap.tooltip()
|
||||
.placement('bottom')
|
||||
.html(true);
|
||||
.html(true)
|
||||
.title(function (d) {
|
||||
return iD.ui.tooltipHtml(d.annotation() || t('nothing_to_' + d.id), d.cmd);
|
||||
});
|
||||
|
||||
var undoButton = selection.append('button')
|
||||
var buttons = selection.selectAll('button')
|
||||
.data(commands)
|
||||
.enter().append('button')
|
||||
.attr('class', 'col6 disabled')
|
||||
.html('<span class="undo icon"/>')
|
||||
.on('click', context.undo)
|
||||
.on('click', function(d) { return d.action(); })
|
||||
.call(tooltip);
|
||||
|
||||
var redoButton = selection.append('button')
|
||||
.attr('class', 'col6 disabled')
|
||||
.html('<span class="redo icon"/>')
|
||||
.on('click', context.redo)
|
||||
.call(tooltip);
|
||||
buttons.append('span')
|
||||
.attr('class', function(d) { return 'icon ' + d.id; });
|
||||
|
||||
var keybinding = d3.keybinding('undo')
|
||||
.on(iD.ui.cmd('⌘Z'), context.undo)
|
||||
.on(iD.ui.cmd('⌘⇧Z'), context.redo);
|
||||
.on(commands[0].cmd, commands[0].action)
|
||||
.on(commands[1].cmd, commands[1].action);
|
||||
|
||||
d3.select(document)
|
||||
.call(keybinding);
|
||||
|
||||
context.history().on('change.editor', function() {
|
||||
var undo = context.history().undoAnnotation(),
|
||||
redo = context.history().redoAnnotation();
|
||||
|
||||
function refreshTooltip(selection) {
|
||||
if (selection.property('tooltipVisible')) {
|
||||
selection.call(tooltip.show);
|
||||
}
|
||||
}
|
||||
|
||||
undoButton
|
||||
.classed('disabled', !undo)
|
||||
.attr('data-original-title', iD.ui.tooltipHtml(undo || t('nothing_to_undo'), iD.ui.cmd('⌘Z')))
|
||||
.call(refreshTooltip);
|
||||
|
||||
redoButton
|
||||
.classed('disabled', !redo)
|
||||
.attr('data-original-title', iD.ui.tooltipHtml(redo || t('nothing_to_redo'), iD.ui.cmd('⌘⇧Z')))
|
||||
.call(refreshTooltip);
|
||||
buttons
|
||||
.classed('disabled', function(d) { return !d.annotation(); })
|
||||
.each(function() {
|
||||
var selection = d3.select(this);
|
||||
if (selection.property('tooltipVisible')) {
|
||||
selection.call(tooltip.show);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user