enabling menu items

master
Mark MacKay 2021-02-22 11:42:38 -06:00
parent 9c48896059
commit 79d709c832
5 changed files with 41 additions and 25 deletions

View File

@ -86,14 +86,14 @@
<div class="menu">
<div class="menu_title">Edit</div>
<div class="menu_list" id="edit_menu">
<div class="menu_item" id="tool_undo">Undo <span class="shortcut">⌘Z</span></div>
<div class="menu_item" id="tool_redo">Redo <span class="shortcut">⌘Y</span></div>
<div data-action="undo" class="menu_item" id="tool_undo">Undo <span class="shortcut">⌘Z</span></div>
<div data-action="redo" class="menu_item" id="tool_redo">Redo <span class="shortcut">⌘Y</span></div>
<div class="separator"></div>
<div class="menu_item action_selected disabled" id="tool_cut">Cut <span class="shortcut">⌘X</span></div>
<div class="menu_item action_selected disabled" id="tool_copy">Copy <span class="shortcut">⌘C</span></div>
<div class="menu_item action_selected disabled" id="tool_paste">Paste <span class="shortcut">⌘V</span></div>
<div class="menu_item action_selected disabled" id="tool_clone">Duplicate <span class="shortcut">⌘D</span></div>
<div class="menu_item action_selected disabled" id="tool_delete">Delete <span></span></div>
<div data-action="cutSelected" class="menu_item action_selected disabled" id="tool_cut">Cut <span class="shortcut">⌘X</span></div>
<div data-action="copySelected" class="menu_item action_selected disabled" id="tool_copy">Copy <span class="shortcut">⌘C</span></div>
<div data-action="pasteSelected" class="menu_item action_selected disabled" id="tool_paste">Paste <span class="shortcut">⌘V</span></div>
<div data-action="duplicateSelected" class="menu_item action_selected disabled" id="tool_clone">Duplicate <span class="shortcut">⌘D</span></div>
<div data-action="deleteSelected" class="menu_item action_selected disabled" id="tool_delete">Delete <span></span></div>
</div>
</div>

View File

@ -24,6 +24,7 @@ MD.Keyboard = function(){
"cmd_c": ()=> editor.copySelected(),
"cmd_x": ()=> editor.cutSelected(),
"cmd_v": ()=> editor.pasteSelected(),
"cmd_d": ()=> editor.duplicateSelected(),
"cmd_u": ()=> editor.modal.viewSource(),
"cmd_a": ()=> svgCanvas.selectAllInCurrentLayer(),
"cmd_b": ()=> editor.text.setBold(),

View File

@ -19,8 +19,7 @@ MD.Menu = function(){
$(this).parent().addClass('open');
});
function blink(e) {
const el = e.target;
function blink(el) {
el.style.background = "#fff";
setTimeout(()=> el.style.background = "#ddd", 50);
setTimeout(()=> el.style.background = "#fff", 150);
@ -33,7 +32,7 @@ MD.Menu = function(){
function close(e){
if (e.target.nodeName && e.target.nodeName.toLowerCase() === "input") return false;
if (!$(e.target).hasClass("menu_title") && !$(e.target).parent().hasClass("menu_title")) {
if(!$(e.target).hasClass("disabled") && $(e.target).hasClass("menu_item")) blink(e)
if(!$(e.target).hasClass("disabled") && $(e.target).hasClass("menu_item")) blink(e.target)
else $('#menu_bar').removeClass('active')
}
}
@ -55,7 +54,14 @@ MD.Menu = function(){
});
}
$('.menu_item').on('click', blink);
$('.menu_item').on('click', function(e){
const action = this.getAttribute("data-action");
if (action && editor[action]) {
editor[action]();
blink(this);
}
});
$("body").on('mousedown', close);
this.flash = flash;

View File

@ -138,8 +138,7 @@ MD.Panel = function(){
var menu_items = $('#cmenu_canvas li');
$('.context_panel').hide();
$('.menu_item', '#edit_menu').addClass('disabled');
$('.menu_item', '#object_menu').addClass('disabled');
//hack to show the proper multialign box
if (multiselected) {
@ -293,21 +292,16 @@ MD.Panel = function(){
if (!elem) {
menu_items.disableContextMenuItems('#delete,#cut,#copy,#ungroup,#move_front,#move_up,#move_down,#move_back');
$('.menu_item', '#edit_menu').addClass('disabled');
$('.menu_item', '#object_menu').addClass('disabled');
}
// update history buttons
if (svgCanvas.undoMgr.getUndoStackSize() > 0) {
$('#tool_undo').removeClass( 'disabled');
}
else {
$('#tool_undo').addClass( 'disabled');
}
if (svgCanvas.undoMgr.getRedoStackSize() > 0) {
$('#tool_redo').removeClass( 'disabled');
}
else {
$('#tool_redo').addClass( 'disabled');
}
setTimeout(function(){
$('#tool_paste').toggleClass( 'disabled', !svgCanvas.clipBoard.length > 0);
}, 10)
$('#tool_undo').toggleClass( 'disabled', !svgCanvas.undoMgr.getUndoStackSize() > 0);
$('#tool_redo').toggleClass( 'disabled', !svgCanvas.undoMgr.getRedoStackSize() > 0);
svgCanvas.addedNew = false;

View File

@ -18,6 +18,19 @@ MD.Editor = function(){
svgCanvas.undoMgr.undo();
}
function redo(){
if (svgCanvas.undoMgr.getRedoStackSize() > 0) {
_self.menu.flash($('#edit_menu'));
svgCanvas.undoMgr.redo();
}
}
function duplicateSelected(){
if (!_self.selected.length) return false;
_self.menu.flash($('#edit_menu'));
svgCanvas.cloneSelectedElements(20,20);
};
function deleteSelected(){
if (svgCanvas.pathActions.getNodePoint()) svgCanvas.pathActions.deletePathNode();
else svgCanvas.deleteSelectedElements();
@ -296,6 +309,8 @@ MD.Editor = function(){
this.switchPaint = switchPaint;
this.save = save;
this.undo = undo;
this.redo = redo;
this.duplicateSelected = duplicateSelected;
this.deleteSelected = deleteSelected;
this.cutSelected = cutSelected;
this.copySelected = copySelected;