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

Add core:hide-other-tabs and handle multiple tab selection

This commit is contained in:
Nick O'Leary 2021-08-27 11:46:30 +01:00
parent 0874ba7a03
commit c880cc0987
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 84 additions and 12 deletions

View File

@ -896,6 +896,17 @@ RED.tabs = (function() {
return $.makeArray(ul.children().map(function() { return $(this).data('tabId');}));
},
selection: getSelection,
clearSelection: function() {
if (options.onselect) {
var selection = ul.find("li.red-ui-tab.selected");
console.log(selection.length)
if (selection.length > 0) {
selection.removeClass("selected");
selectionChanged();
}
}
},
order: function(order) {
preferredOrder = order;
var existingTabOrder = $.makeArray(ul.children().map(function() { return $(this).data('tabId');}));

View File

@ -33,6 +33,24 @@ RED.workspaces = (function() {
viewStackPos = viewStack.length;
}
function removeFromHideStack(id) {
hideStack = hideStack.filter(function(v) {
if (v === id) {
return false;
} else if (Array.isArray(v)) {
var i = v.indexOf(id);
if (i > -1) {
v.splice(i,1);
}
if (v.length === 0) {
return false;
}
return true
}
return true;
})
}
function addWorkspace(ws,skipHistoryEntry,targetIndex) {
if (ws) {
if (!ws.closeable) {
@ -329,10 +347,7 @@ RED.workspaces = (function() {
RED.events.emit("workspace:hide",{workspace: tab.id})
},
onshow: function(tab) {
var i = hideStack.indexOf(tab.id);
if (i > -1) {
hideStack.splice(i,1);
}
removeFromHideStack(tab.id);
RED.events.emit("workspace:show",{workspace: tab.id})
},
minimumActiveTabWidth: 150,
@ -396,12 +411,54 @@ RED.workspaces = (function() {
RED.actions.add("core:enable-flow",enableWorkspace);
RED.actions.add("core:disable-flow",disableWorkspace);
RED.actions.add("core:hide-tab", function() { RED.workspaces.hide(); })
RED.actions.add("core:hide-tab", function() {
var selection = workspace_tabs.selection();
if (selection.length === 0) {
selection = [{id:activeWorkspace}]
}
var hiddenTabs = [];
selection.forEach(function(ws) {
RED.workspaces.hide(ws.id);
hideStack.pop();
hiddenTabs.push(ws.id);
})
if (hiddenTabs.length > 0) {
hideStack.push(hiddenTabs);
}
workspace_tabs.clearSelection();
})
RED.actions.add("core:hide-other-tabs", function() {
var selection = workspace_tabs.selection();
if (selection.length === 0) {
selection = [{id:activeWorkspace}]
}
var selected = new Set(selection.map(function(ws) { return ws.id }))
var currentTabs = workspace_tabs.listTabs();
var hiddenTabs = [];
currentTabs.forEach(function(id) {
if (!selected.has(id)) {
RED.workspaces.hide(id);
hideStack.pop();
hiddenTabs.push(id);
}
})
if (hiddenTabs.length > 0) {
hideStack.push(hiddenTabs);
}
})
RED.actions.add("core:hide-all-tabs", function() {
var currentTabs = workspace_tabs.listTabs();
currentTabs.forEach(function(id) {
RED.workspaces.hide(id)
RED.workspaces.hide(id);
hideStack.pop();
})
if (currentTabs.length > 0) {
hideStack.push(currentTabs);
}
workspace_tabs.clearSelection();
})
RED.actions.add("core:show-all-tabs", function() {
var currentTabs = workspace_tabs.listTabs();
@ -422,7 +479,15 @@ RED.workspaces = (function() {
})
RED.actions.add("core:show-last-hidden-tab", function() {
var id = hideStack.pop();
RED.workspaces.show(id);
if (id) {
if (typeof id === 'string') {
RED.workspaces.show(id);
} else {
id.forEach(function(i) {
RED.workspaces.show(i);
})
}
}
})
RED.actions.add("core:list-flows",function() {
@ -555,11 +620,7 @@ RED.workspaces = (function() {
null,
workspace_tabs.activeIndex()+1
);
var i = hideStack.indexOf(id);
if (i > -1) {
hideStack.splice(i,1);
}
removeFromHideStack(id);
} else {
return;
}