1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add main menu customisation

This commit is contained in:
Nick O'Leary 2015-04-13 13:55:17 +01:00
parent b0de8abb63
commit a2aa78afd4
4 changed files with 87 additions and 53 deletions

View File

@ -59,7 +59,14 @@ RED.keyboard = (function() {
} }
var dialog = $('<div id="keyboard-help-dialog" class="hide">'+ var dialog = null;
function showKeyboardHelp() {
if (!RED.settings.theme("menu.btn-keyboard-shortcuts",true)) {
return;
}
if (!dialog) {
dialog = $('<div id="keyboard-help-dialog" class="hide">'+
'<div style="vertical-align: top;display:inline-block; box-sizing: border-box; width:50%; padding: 10px;">'+ '<div style="vertical-align: top;display:inline-block; box-sizing: border-box; width:50%; padding: 10px;">'+
'<table class="keyboard-shortcuts">'+ '<table class="keyboard-shortcuts">'+
'<tr><td><span class="help-key">Ctrl/&#8984;</span> + <span class="help-key">a</span></td><td>Select all nodes</td></tr>'+ '<tr><td><span class="help-key">Ctrl/&#8984;</span> + <span class="help-key">a</span></td><td>Select all nodes</td></tr>'+
@ -97,8 +104,8 @@ RED.keyboard = (function() {
RED.keyboard.enable(); RED.keyboard.enable();
} }
}); });
}
function showKeyboardHelp() {
dialog.dialog("open"); dialog.dialog("open");
} }

View File

@ -402,7 +402,9 @@ RED.library = (function() {
} }
}); });
if (RED.settings.theme("menu.btn-import-library") !== false) {
loadFlowLibrary(); loadFlowLibrary();
}
}, },
create: createUI, create: createUI,
loadFlowLibrary: loadFlowLibrary, loadFlowLibrary: loadFlowLibrary,

View File

@ -23,6 +23,13 @@ RED.menu = (function() {
function createMenuItem(opt) { function createMenuItem(opt) {
var item; var item;
if (opt !== null && opt.id) {
var themeSetting = RED.settings.theme("menu."+opt.id);
if (themeSetting === false) {
return null;
}
}
function setState() { function setState() {
var savedStateActive = isSavedStateActive(opt.id); var savedStateActive = isSavedStateActive(opt.id);
if (savedStateActive) { if (savedStateActive) {
@ -113,7 +120,10 @@ RED.menu = (function() {
var submenu = $('<ul id="'+opt.id+'-submenu" class="dropdown-menu"></ul>').appendTo(item); var submenu = $('<ul id="'+opt.id+'-submenu" class="dropdown-menu"></ul>').appendTo(item);
for (var i=0;i<opt.options.length;i++) { for (var i=0;i<opt.options.length;i++) {
createMenuItem(opt.options[i]).appendTo(submenu); var li = createMenuItem(opt.options[i]);
if (li) {
li.appendTo(submenu);
}
} }
} }
if (opt.disabled) { if (opt.disabled) {
@ -148,9 +158,16 @@ RED.menu = (function() {
var topMenu = $("<ul/>",{id:options.id+"-submenu", class:"dropdown-menu pull-right"}).insertAfter(button); var topMenu = $("<ul/>",{id:options.id+"-submenu", class:"dropdown-menu pull-right"}).insertAfter(button);
var lastAddedSeparator = false;
for (var i=0;i<options.options.length;i++) { for (var i=0;i<options.options.length;i++) {
var opt = options.options[i]; var opt = options.options[i];
createMenuItem(opt).appendTo(topMenu); if (opt !== null || !lastAddedSeparator) {
var li = createMenuItem(opt);
if (li) {
li.appendTo(topMenu);
lastAddedSeparator = (opt === null);
}
}
} }
} }
@ -176,7 +193,7 @@ RED.menu = (function() {
} else { } else {
$("#"+id).removeClass("active"); $("#"+id).removeClass("active");
} }
if (opt.onselect) { if (opt && opt.onselect) {
opt.onselect.call(opt,state); opt.onselect.call(opt,state);
} }
setSavedState(id, state); setSavedState(id, state);
@ -198,7 +215,9 @@ RED.menu = (function() {
} }
function setAction(id,action) { function setAction(id,action) {
menuItems[id].onselect = action; var opt = menuItems[id];
if (opt) {
opt.onselect = action;
$("#"+id).click(function() { $("#"+id).click(function() {
if ($(this).parent().hasClass("disabled")) { if ($(this).parent().hasClass("disabled")) {
return; return;
@ -210,6 +229,7 @@ RED.menu = (function() {
} }
}); });
} }
}
return { return {
init: createMenu, init: createMenu,

View File

@ -145,6 +145,11 @@ module.exports = {
if (theme.help) { if (theme.help) {
themeSettings.help = theme.help; themeSettings.help = theme.help;
} }
if (theme.hasOwnProperty("menu")) {
themeSettings.menu = theme.menu;
}
return themeApp; return themeApp;
} }
}, },