Add sidebar menu and migrate existing panels to new api

This commit is contained in:
Nick O'Leary 2015-07-03 10:07:40 +01:00
parent 6cfa4976fe
commit 6359b90352
9 changed files with 139 additions and 63 deletions

View File

@ -160,7 +160,10 @@ var RED = (function() {
function loadEditor() { function loadEditor() {
RED.menu.init({id:"btn-sidemenu", RED.menu.init({id:"btn-sidemenu",
options: [ options: [
{id:"menu-item-sidebar",label:RED._("menu.label.sidebar"),toggle:true,onselect:RED.sidebar.toggleSidebar, selected: true}, {id:"menu-item-sidebar-menu",label:RED._("menu.label.sidebar.sidebar"),options:[
{id:"menu-item-sidebar",label:RED._("menu.label.sidebar.show"),toggle:true,onselect:RED.sidebar.toggleSidebar, selected: true},
null
]},
{id:"menu-item-status",label:RED._("menu.label.displayStatus"),toggle:true,onselect:toggleStatus, selected: true}, {id:"menu-item-status",label:RED._("menu.label.displayStatus"),toggle:true,onselect:toggleStatus, selected: true},
null, null,
{id:"menu-item-import",label:RED._("menu.label.import"),options:[ {id:"menu-item-import",label:RED._("menu.label.import"),options:[
@ -172,8 +175,6 @@ var RED = (function() {
{id:"menu-item-export-library",label:RED._("menu.label.library"),disabled:true,onselect:RED.library.export} {id:"menu-item-export-library",label:RED._("menu.label.library"),disabled:true,onselect:RED.library.export}
]}, ]},
null, null,
{id:"menu-item-config-nodes",label:RED._("menu.label.configurationNodes"),onselect:RED.sidebar.config.show},
null,
{id:"menu-item-subflow",label:RED._("menu.label.subflows"), options: [ {id:"menu-item-subflow",label:RED._("menu.label.subflows"), options: [
{id:"menu-item-subflow-create",label:RED._("menu.label.createSubflow"),onselect:RED.subflow.createSubflow}, {id:"menu-item-subflow-create",label:RED._("menu.label.createSubflow"),onselect:RED.subflow.createSubflow},
{id:"menu-item-subflow-convert",label:RED._("menu.label.selectionToSubflow"),disabled:true,onselect:RED.subflow.convertToSubflow}, {id:"menu-item-subflow-convert",label:RED._("menu.label.selectionToSubflow"),disabled:true,onselect:RED.subflow.convertToSubflow},

View File

@ -20,24 +20,65 @@ RED.sidebar = (function() {
id:"sidebar-tabs", id:"sidebar-tabs",
onchange:function(tab) { onchange:function(tab) {
$("#sidebar-content").children().hide(); $("#sidebar-content").children().hide();
$("#"+tab.id).show(); if (tab.onchange) {
tab.onchange.call(tab);
}
$(tab.content).show();
}, },
onremove: function(tab) { onremove: function(tab) {
$("#"+tab.id).remove(); $(tab.content).remove();
if (tab.onremove) {
tab.onremove.call(tab);
}
} }
}); });
function addTab(title,content,closeable) { var knownTabs = {
$("#sidebar-content").append(content);
$(content).hide(); };
var id = content.id || "tab-"+title.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, "\\$1" );
sidebar_tabs.addTab({id:id,label:title,closeable:closeable}); function addTab(title,content,closeable,visible) {
//content.style.position = "absolute"; var options;
//$('#sidebar').tabs("refresh"); if (typeof title === "string") {
// TODO: legacy support in case anyone uses this...
options = {
id: content.id,
label: title,
name: title,
content: content,
closeable: closeable,
visible: visible
}
} else if (typeof title === "object") {
options = title;
} }
function removeTab(title) {
sidebar_tabs.removeTab("tab-"+title);
$("#sidebar-content").append(options.content);
$(options.content).hide();
var id = options.id;
RED.menu.addItem("menu-item-sidebar-menu",{
id:"menu-item-sidebar-menu-"+options.id,
label:options.name,
onselect:function() {
showSidebar(options.id);
}
});
knownTabs[options.id] = options;
if (options.visible !== false) {
sidebar_tabs.addTab(knownTabs[options.id]);
}
}
function removeTab(id) {
sidebar_tabs.removeTab(id);
delete knownTabs[id];
RED.menu.removeItem("menu-item-sidebar-menu-"+id);
//TODO: remove menu item
} }
var sidebarSeparator = {}; var sidebarSeparator = {};
@ -130,18 +171,25 @@ RED.sidebar = (function() {
function showSidebar(id) { function showSidebar(id) {
if (id) { if (id) {
sidebar_tabs.activateTab("tab-"+id); if (!containsTab(id)) {
sidebar_tabs.addTab(knownTabs[id]);
}
sidebar_tabs.activateTab(id);
if (!RED.menu.isSelected("menu-item-sidebar")) {
RED.menu.setSelected("menu-item-sidebar",true);
}
} }
} }
function containsTab(id) { function containsTab(id) {
return sidebar_tabs.contains("tab-"+id); return sidebar_tabs.contains(id);
} }
function init () { function init () {
RED.keyboard.add(/* SPACE */ 32,{ctrl:true},function(){RED.menu.setSelected("menu-item-sidebar",!RED.menu.isSelected("menu-item-sidebar"));d3.event.preventDefault();}); RED.keyboard.add(/* SPACE */ 32,{ctrl:true},function(){RED.menu.setSelected("menu-item-sidebar",!RED.menu.isSelected("menu-item-sidebar"));d3.event.preventDefault();});
showSidebar(); showSidebar();
RED.sidebar.info.show(); RED.sidebar.info.init();
RED.sidebar.config.init();
// hide info bar at start if screen rather narrow... // hide info bar at start if screen rather narrow...
if ($(window).width() < 600) { toggleSidebar(); } if ($(window).width() < 600) { toggleSidebar(); }
} }

View File

@ -16,17 +16,24 @@
RED.sidebar.config = (function() { RED.sidebar.config = (function() {
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-config";
content.style.paddingTop = "4px"; content.style.paddingTop = "4px";
content.style.paddingLeft = "4px"; content.style.paddingLeft = "4px";
content.style.paddingRight = "4px"; content.style.paddingRight = "4px";
var list = $("<ul>",{class:"tab-config-list"}).appendTo(content); var list = $("<ul>",{class:"tab-config-list"}).appendTo(content);
function show() { function init() {
if (!RED.sidebar.containsTab("config")) { RED.sidebar.addTab({
RED.sidebar.addTab(RED._("sidebar.config.title"),content,true); id: "config",
label: RED._("sidebar.config.label"),
name: RED._("sidebar.config.name"),
content: content,
closeable: true,
visible: false,
onchange: function() { refresh(); }
});
} }
function show() {
refresh(); refresh();
RED.sidebar.show("config"); RED.sidebar.show("config");
} }
@ -78,6 +85,7 @@ RED.sidebar.config = (function() {
}); });
} }
return { return {
init:init,
show:show, show:show,
refresh:refresh refresh:refresh
} }

View File

@ -27,17 +27,23 @@ RED.sidebar.info = (function() {
}); });
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-info";
content.style.paddingTop = "4px"; content.style.paddingTop = "4px";
content.style.paddingLeft = "4px"; content.style.paddingLeft = "4px";
content.style.paddingRight = "4px"; content.style.paddingRight = "4px";
var propertiesExpanded = false; var propertiesExpanded = false;
function show() { function init() {
if (!RED.sidebar.containsTab("info")) { RED.sidebar.addTab({
RED.sidebar.addTab(RED._("sidebar.info.title"),content,false); id: "info",
label: RED._("sidebar.info.label"),
name: RED._("sidebar.info.name"),
content: content
});
} }
function show() {
RED.sidebar.show("info"); RED.sidebar.show("info");
} }
@ -184,6 +190,7 @@ RED.sidebar.info = (function() {
}); });
return { return {
init: init,
show: show, show: show,
refresh:refresh, refresh:refresh,
clear: clear clear: clear

View File

@ -28,6 +28,7 @@ RED.workspaces = (function() {
var tabId = RED.nodes.id(); var tabId = RED.nodes.id();
do { do {
workspaceIndex += 1; workspaceIndex += 1;
//TODO: nls of Sheet
} while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() !== 0); } while($("#workspace-tabs a[title='Sheet "+workspaceIndex+"']").size() !== 0);
ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex}; ws = {type:"tab",id:tabId,label:"Sheet "+workspaceIndex};

View File

@ -16,16 +16,18 @@
}, },
"menu": { "menu": {
"label": { "label": {
"sidebar": {
"sidebar": "Sidebar", "sidebar": "Sidebar",
"displayStatus": "Display node status", "show": "Toggle Sidebar"
},
"displayStatus": "Display Node Status",
"import": "Import", "import": "Import",
"export": "Export", "export": "Export",
"clipboard": "Clipboard", "clipboard": "Clipboard",
"library": "Library", "library": "Library",
"configurationNodes": "Configuration nodes",
"subflows": "Subflows", "subflows": "Subflows",
"createSubflow": "Create subflow", "createSubflow": "Create Subflow",
"selectionToSubflow": "Selection to subflow", "selectionToSubflow": "Selection to Subflow",
"workspaces": "Workspaces", "workspaces": "Workspaces",
"add": "Add", "add": "Add",
"rename": "Rename", "rename": "Rename",
@ -175,7 +177,8 @@
}, },
"sidebar": { "sidebar": {
"info": { "info": {
"title": "info", "name": "Node Information",
"label": "info",
"node": "Node", "node": "Node",
"type": "Type", "type": "Type",
"id": "ID", "id": "ID",
@ -186,7 +189,8 @@
"arrayItems": "__count__ items" "arrayItems": "__count__ items"
}, },
"config": { "config": {
"title": "config" "name": "Configuration nodes",
"label": "config"
} }
} }
} }

View File

@ -128,7 +128,6 @@
}, },
onpaletteadd: function() { onpaletteadd: function() {
var content = document.createElement("div"); var content = document.createElement("div");
content.id = "tab-debug";
var toolbar = document.createElement("div"); var toolbar = document.createElement("div");
toolbar.id = "debug-toolbar"; toolbar.id = "debug-toolbar";
@ -140,7 +139,12 @@
messages.id = "debug-content"; messages.id = "debug-content";
content.appendChild(messages); content.appendChild(messages);
RED.sidebar.addTab(this._("debug.sidebarTitle"),content); RED.sidebar.addTab({
id: "debug",
label: this._("debug.sidebar.label"),
name: this._("debug.sidebar.name"),
content: content
});
function getTimestamp() { function getTimestamp() {
var d = new Date(); var d = new Date();

View File

@ -81,7 +81,10 @@
"activated": "Successfully activated: __label__", "activated": "Successfully activated: __label__",
"deactivated": "Successfully deactivated: __label__" "deactivated": "Successfully deactivated: __label__"
}, },
"sidebarTitle": "debug" "sidebar": {
"label": "debug",
"name": "Debug messages"
}
}, },
"exec": { "exec": {
"spawnerr": "Spawn command must be just the command - no spaces or extra parameters", "spawnerr": "Spawn command must be just the command - no spaces or extra parameters",