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

Revise the fix for the problem that the last flow tab can be deleted

This commit is contained in:
Kazuki-Nakanishi 2018-02-16 11:54:52 +09:00
parent c316284924
commit 2ab93acca8
2 changed files with 12 additions and 10 deletions

View File

@ -333,9 +333,7 @@ RED.tabs = (function() {
previousTab: activatePreviousTab, previousTab: activatePreviousTab,
resize: updateTabWidths, resize: updateTabWidths,
count: function() { count: function() {
var numOfTabs = ul.find("li.red-ui-tab").size(); return ul.find("li.red-ui-tab").size();
var numOfSubflow = ul.find('img[src="red/images/subflow_tab.png"]').size();
return numOfTabs - numOfSubflow;
}, },
contains: function(id) { contains: function(id) {
return ul.find("a[href='#"+id+"']").length > 0; return ul.find("a[href='#"+id+"']").length > 0;

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,20 @@ RED.workspaces = (function() {
} }
}, },
onadd: function(tab) { onadd: function(tab) {
workspaceTabCount = tab.type === "tab"?workspaceTabCount+1: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); workspaceTabCount = tab.type === "tab"?workspaceTabCount-1:workspaceTabCount;
if (workspace_tabs.count() === 0) { RED.menu.setDisabled("menu-item-workspace-delete",workspaceTabCount <= 1);
if (workspaceTabCount === 0) {
hideWorkspace(); hideWorkspace();
} }
}, },
@ -266,6 +269,7 @@ RED.workspaces = (function() {
addWorkspace(); addWorkspace();
} }
}); });
workspaceTabCount = 0;
} }
function showWorkspace() { function showWorkspace() {
$("#workspace .red-ui-tabs").show() $("#workspace .red-ui-tabs").show()
@ -334,7 +338,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