|
7303 | 7303 | }; |
7304 | 7304 | this.preInitListeners.push(this.preInitDebugAids); */ |
7305 | 7305 |
|
| 7306 | + |
| 7307 | + // region API |
| 7308 | + |
| 7309 | + this.api = { |
| 7310 | + getParentTab: function(tab) { |
| 7311 | + // Only tab in group has parent |
| 7312 | + if (tk.getTabGroupId(tab) == null) { return null } |
| 7313 | + |
| 7314 | + const tabs_in_group = tk.getGroupFromTab(tab) |
| 7315 | + // Should not happen just be safe |
| 7316 | + if (tabs_in_group == null) { return null } |
| 7317 | + |
| 7318 | + const possible_parent_tab_id = tab.getAttribute("possibleparent") |
| 7319 | + |
| 7320 | + return tabs_in_group.find((tab_in_group) => { |
| 7321 | + if (tab_in_group === tab) { return false } |
| 7322 | + |
| 7323 | + return tk.getTabId(tab_in_group) === possible_parent_tab_id |
| 7324 | + }) |
| 7325 | + }, |
| 7326 | + getChildTabs: function(tab) { |
| 7327 | + // Only tab in group has children |
| 7328 | + if (tk.getTabGroupId(tab) == null) { return null } |
| 7329 | + |
| 7330 | + const tabs_in_group = tk.getGroupFromTab(tab) |
| 7331 | + // Should not happen just be safe |
| 7332 | + if (tabs_in_group == null) { return null } |
| 7333 | + |
| 7334 | + const tab_id = tk.getTabId(tab) |
| 7335 | + |
| 7336 | + return tabs_in_group.filter((tab_in_group) => { |
| 7337 | + if (tab_in_group === tab) { return false } |
| 7338 | + |
| 7339 | + return tab_in_group.getAttribute("possibleparent") === tab_id |
| 7340 | + }) |
| 7341 | + }, |
| 7342 | + addChildTabs: function(tab, new_child_tabs) { |
| 7343 | + // For now we only allow adding tabs to an already grouped tabs |
| 7344 | + const tab_group_id = tk.getTabGroupId(tab) |
| 7345 | + if (tab_group_id == null) { return } |
| 7346 | + |
| 7347 | + const tabs_in_group = tk.getGroupFromTab(tab) |
| 7348 | + // Should not happen just be safe |
| 7349 | + if (tabs_in_group == null) { return } |
| 7350 | + |
| 7351 | + const tab_id = tk.getTabId(tab) |
| 7352 | + |
| 7353 | + new_child_tabs.forEach((new_child_tab) => { |
| 7354 | + new_child_tab.setAttribute("possibleparent", tab_id) |
| 7355 | + }) |
| 7356 | + // Not calling `updateIndents` for performance |
| 7357 | + // Expose it later if necessary |
| 7358 | + // tk.updateIndents() |
| 7359 | + }, |
| 7360 | + resetTab: function(tab) { |
| 7361 | + // Only call this before removing a tab AND |
| 7362 | + // children tabs have been handled manually (using API methods defined) |
| 7363 | + // |
| 7364 | + // Calling this should disable our built-in tree processing |
| 7365 | + // in event listeners like `sortgroup_onTabRemoved` |
| 7366 | + tab.removeAttribute("groupid") |
| 7367 | + tab.removeAttribute("tabid") |
| 7368 | + tab.removeAttribute("possibleparent") |
| 7369 | + }, |
| 7370 | + } |
| 7371 | + |
| 7372 | + // endregion API |
| 7373 | + |
| 7374 | + |
7306 | 7375 | //}########################## |
7307 | 7376 | //|### End of tabkit object |
7308 | 7377 | //|########################## |
|
0 commit comments