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

Merge pull request #1614 from node-red-hitachi/no-tabs

Fix the problem that the last flow tab can be deleted
This commit is contained in:
Nick O'Leary 2018-02-22 19:02:12 -08:00 committed by GitHub
commit af947879d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,7 +43,7 @@ RED.workspaces = (function() {
return ws; return ws;
} }
function deleteWorkspace(ws) { function deleteWorkspace(ws) {
if (workspace_tabs.count() == 1) { if (workspaceTabCount === 1) {
return; return;
} }
removeWorkspace(ws); removeWorkspace(ws);
@ -65,7 +65,7 @@ RED.workspaces = (function() {
buttons: [ buttons: [
{ {
id: "node-dialog-delete", id: "node-dialog-delete",
class: 'leftButton'+((workspace_tabs.count() == 1)?" disabled":""), class: 'leftButton'+((workspaceTabCount === 1)?" disabled":""),
text: RED._("common.label.delete"), //'<i class="fa fa-trash"></i>', text: RED._("common.label.delete"), //'<i class="fa fa-trash"></i>',
click: function() { click: function() {
deleteWorkspace(workspace); deleteWorkspace(workspace);
@ -214,6 +214,7 @@ RED.workspaces = (function() {
var workspace_tabs; var workspace_tabs;
var workspaceTabCount = 0;
function createWorkspaceTabs() { function createWorkspaceTabs() {
workspace_tabs = RED.tabs.create({ workspace_tabs = RED.tabs.create({
id: "workspace-tabs", id: "workspace-tabs",
@ -240,18 +241,24 @@ RED.workspaces = (function() {
} }
}, },
onadd: function(tab) { onadd: function(tab) {
if (tab.type === "tab") {
workspaceTabCount++;
}
$('<span class="workspace-disabled-icon"><i class="fa fa-ban"></i> </span>').prependTo("#red-ui-tab-"+(tab.id.replace(".","-"))+" .red-ui-tab-label"); $('<span class="workspace-disabled-icon"><i class="fa fa-ban"></i> </span>').prependTo("#red-ui-tab-"+(tab.id.replace(".","-"))+" .red-ui-tab-label");
if (tab.disabled) { if (tab.disabled) {
$("#red-ui-tab-"+(tab.id.replace(".","-"))).addClass('workspace-disabled'); $("#red-ui-tab-"+(tab.id.replace(".","-"))).addClass('workspace-disabled');
} }
RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() <= 1); RED.menu.setDisabled("menu-item-workspace-delete",workspaceTabCount <= 1);
if (workspace_tabs.count() === 1) { if (workspaceTabCount === 1) {
showWorkspace(); showWorkspace();
} }
}, },
onremove: function(tab) { onremove: function(tab) {
RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() <= 1); if (tab.type === "tab") {
if (workspace_tabs.count() === 0) { workspaceTabCount--;
}
RED.menu.setDisabled("menu-item-workspace-delete",workspaceTabCount <= 1);
if (workspaceTabCount === 0) {
hideWorkspace(); hideWorkspace();
} }
}, },
@ -266,6 +273,7 @@ RED.workspaces = (function() {
addWorkspace(); addWorkspace();
} }
}); });
workspaceTabCount = 0;
} }
function showWorkspace() { function showWorkspace() {
$("#workspace .red-ui-tabs").show() $("#workspace .red-ui-tabs").show()
@ -334,7 +342,7 @@ RED.workspaces = (function() {
return workspace_tabs.contains(id); return workspace_tabs.contains(id);
}, },
count: function() { count: function() {
return workspace_tabs.count(); return workspaceTabCount;
}, },
active: function() { active: function() {
return activeWorkspace return activeWorkspace