"use strict"; var INFO = [ "plugin", { name: "treestyletabs", version: "0.1", href: "", summary: "TreeStyleTabs integration for Pentadactyl", xmlns: "dactyl" }, [ "author", { email: "nelo@wallus.de" }, "Nelo-T. Wallus" ], [ "license", { href: "http://opensource.org/licenses/mit-license.php" }, "MIT" ], [ "project", { name: "Pentadactyl", "min-version": "1.0" } ], ]; // pass true to close, false to open function fold_collapse_expand_target(tab, collapse, children = false) { if (children) { let children = TreeStyleTabService.getDescendantTabs(tab); for (let x in children) { gBrowser.treeStyleTab.collapseExpandSubtree(children[x], collapse); } } gBrowser.treeStyleTab.collapseExpandSubtree(tab, collapse); } function fold_collapse_expand(collapse, children = false) { let tab = gBrowser.tabContainer.selectedItem; if (!TreeStyleTabService.hasChildTabs(tab)) { tab = TreeStyleTabService.getParentTab(tab); gBrowser.tabContainer.selectedIndex = gBrowser.tabContainer.getIndexOfItem(tab); } fold_collapse_expand_target( tab, collapse, children ); } function fold_collapse_expand_toggle(children = false) { fold_collapse_expand( !TreeStyleTabService.isSubtreeCollapsed(gBrowser.tabContainer.selectedItem), children ); } function create_command_and_mapping(command, description, funcref, mapping, command_option = {}) { group.commands.add([command], description, funcref, command_option, true ); if (mapping != "") group.mappings.add([modes.NORMAL], [mapping], description, funcref); } create_command_and_mapping( "foldopen", "Open fold under tab", function () { fold_collapse_expand(false); }, "zo" ); create_command_and_mapping( "foldopenrecursively", "Open fold under tab recursively", function () { fold_collapse_expand(false, true); }, "zO" ); create_command_and_mapping( "foldclose", "Close fold under tab", function () { fold_collapse_expand(true); }, "zc" ); create_command_and_mapping( "foldcloserecursively", "Close fold under tab recursively", function () { fold_collapse_expand(true, true); }, "zC" ); create_command_and_mapping( "foldtoggle", "Toggle fold under tab", function () { fold_collapse_expand_toggle(); }, "za" ); create_command_and_mapping( "foldtogglerecursively", "Toggle fold under tab recursively", function () { fold_collapse_expand_toggle(true); }, "zA" ); create_command_and_mapping( "foldcloseall", "Close all folds", function () { let roots = TreeStyleTabService.rootTabs; for (let x in roots) { fold_collapse_expand_target(roots[x], true, true); } }, "zM" ); create_command_and_mapping( "foldopenall", "Open all folds", function () { let roots = TreeStyleTabService.rootTabs; for (let x in roots) { fold_collapse_expand_target(roots[x], false, true); } }, "zR" ); create_command_and_mapping( "tabpromote", "Promote current tab", function () { TreeStyleTabService.promoteCurrentTab(); }, "<" ); create_command_and_mapping( "tabdemote", "Demote current tab", function () { TreeStyleTabService.demoteCurrentTab(); }, ">" ); create_command_and_mapping( "tabchildopen", "Open one or more URLs in a new child tab", function (args) { let tab = gBrowser.tabContainer.selectedItem; TreeStyleTabService.readyToOpenChildTab(tab, true); dactyl.open(args[0] || "about:blank", { from: "tabopen", where: dactyl.NEW_TAB, background: args.bang }); TreeStyleTabService.stopToOpenChildTab(); }, "", { bang: true, completer: function (context) { completion.url(context); }, domains: function (args) { return commands.get("open").domains(args); }, literal: 0, privateData: true } ); create_command_and_mapping( "tabbartoggle", "Toggle tab bar", function () { gBrowser.treeStyleTab.tabbarShown=!gBrowser.treeStyleTab.tabbarShown; }, "" ); create_command_and_mapping( "tabclosechildren", "Close children of current tab", function () { let tab = gBrowser.tabContainer.selectedItem; let children = TreeStyleTabService.getDescendantTabs(tab); for (let child in children) { config.removeTab(children[child]); } }, "" ) create_command_and_mapping( "tabclosewithchildren", "Close children and current tab", function () { let tab = gBrowser.tabContainer.selectedItem; let children = TreeStyleTabService.getDescendantTabs(tab); for (let child in children) { config.removeTab(children[child]); } config.removeTab(tab); }, "" ) create_command_and_mapping( "tabnextvisible", "Switch to the next visible tab", function () { let tab = TreeStyleTabService.getNextVisibleTab(gBrowser.tabContainer.selectedItem); gBrowser.tabContainer.selectedIndex = gBrowser.tabContainer.getIndexOfItem(tab); }, "" ) create_command_and_mapping( "tabpreviousvisible", "Switch to the previous visible tab", function () { let tab = TreeStyleTabService.getPreviousVisibleTab(gBrowser.tabContainer.selectedItem); gBrowser.tabContainer.selectedIndex = gBrowser.tabContainer.getIndexOfItem(tab); }, "" )