mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Support dbl-click in tab bar to add new flow in position
This commit is contained in:
parent
3fcacd8339
commit
5cfc52ea18
@ -298,10 +298,14 @@ RED.nodes = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
function addWorkspace(ws) {
|
||||
function addWorkspace(ws,targetIndex) {
|
||||
workspaces[ws.id] = ws;
|
||||
ws._def = RED.nodes.getType('tab');
|
||||
if (targetIndex === undefined) {
|
||||
workspacesOrder.push(ws.id);
|
||||
} else {
|
||||
workspacesOrder.splice(targetIndex,0,ws.id);
|
||||
}
|
||||
}
|
||||
function getWorkspace(id) {
|
||||
return workspaces[id];
|
||||
|
@ -52,6 +52,25 @@ RED.tabs = (function() {
|
||||
}
|
||||
RED.popover.tooltip(addButton,l,options.addButton);
|
||||
}
|
||||
ul.on("dblclick", function(evt) {
|
||||
var existingTabs = ul.children();
|
||||
var clickX = evt.clientX;
|
||||
var targetIndex = 0;
|
||||
existingTabs.each(function(index) {
|
||||
var pos = $(this).offset();
|
||||
if (pos.left > clickX) {
|
||||
return false;
|
||||
}
|
||||
targetIndex = index+1;
|
||||
})
|
||||
if (typeof options.addButton === 'function') {
|
||||
options.addButton({index:targetIndex});
|
||||
} else if (typeof options.addButton === 'string') {
|
||||
RED.actions.invoke(options.addButton,{index:targetIndex});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
var scrollLeft;
|
||||
var scrollRight;
|
||||
@ -321,9 +340,16 @@ RED.tabs = (function() {
|
||||
}
|
||||
|
||||
return {
|
||||
addTab: function(tab) {
|
||||
addTab: function(tab,targetIndex) {
|
||||
tabs[tab.id] = tab;
|
||||
var li = $("<li/>",{class:"red-ui-tab"}).appendTo(ul);
|
||||
var li = $("<li/>",{class:"red-ui-tab"});
|
||||
if (targetIndex === undefined) {
|
||||
li.appendTo(ul);
|
||||
} else if (targetIndex === 0) {
|
||||
li.prependTo(ul);
|
||||
} else {
|
||||
li.insertAfter(ul.find("li:nth-child("+(targetIndex)+")"));
|
||||
}
|
||||
li.attr('id',"red-ui-tab-"+(tab.id.replace(".","-")));
|
||||
li.data("tabId",tab.id);
|
||||
|
||||
|
@ -20,7 +20,7 @@ RED.workspaces = (function() {
|
||||
var activeWorkspace = 0;
|
||||
var workspaceIndex = 0;
|
||||
|
||||
function addWorkspace(ws,skipHistoryEntry) {
|
||||
function addWorkspace(ws,skipHistoryEntry,targetIndex) {
|
||||
if (ws) {
|
||||
workspace_tabs.addTab(ws);
|
||||
workspace_tabs.resize();
|
||||
@ -31,8 +31,8 @@ RED.workspaces = (function() {
|
||||
} while ($("#workspace-tabs a[title='"+RED._('workspace.defaultName',{number:workspaceIndex})+"']").size() !== 0);
|
||||
|
||||
ws = {type:"tab",id:tabId,disabled: false,info:"",label:RED._('workspace.defaultName',{number:workspaceIndex})};
|
||||
RED.nodes.addWorkspace(ws);
|
||||
workspace_tabs.addTab(ws);
|
||||
RED.nodes.addWorkspace(ws,targetIndex);
|
||||
workspace_tabs.addTab(ws,targetIndex);
|
||||
workspace_tabs.activateTab(tabId);
|
||||
if (!skipHistoryEntry) {
|
||||
RED.history.push({t:'add',workspaces:[ws],dirty:RED.nodes.dirty()});
|
||||
@ -320,7 +320,7 @@ RED.workspaces = (function() {
|
||||
workspace_tabs.resize();
|
||||
});
|
||||
|
||||
RED.actions.add("core:add-flow",addWorkspace);
|
||||
RED.actions.add("core:add-flow",function(opts) { addWorkspace(undefined,undefined,opts?opts.index:undefined)});
|
||||
RED.actions.add("core:edit-flow",editWorkspace);
|
||||
RED.actions.add("core:remove-flow",removeWorkspace);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user