From ab1018041700e50e56ed04b4782dbc36086938e2 Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Thu, 29 Oct 2009 22:52:27 +0100 Subject: vimperator: add buftabs plugin Buftabs plugin from Lucas de Vries provides a tabbar replacement, integrated into the statusbar. Original plugin is hosted on: http://git.glacicle.com/configs/ --- vimperator/plugin/buftabs.js | 191 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 vimperator/plugin/buftabs.js (limited to 'vimperator') diff --git a/vimperator/plugin/buftabs.js b/vimperator/plugin/buftabs.js new file mode 100644 index 0000000..cb3adcf --- /dev/null +++ b/vimperator/plugin/buftabs.js @@ -0,0 +1,191 @@ +// PLUGIN_INFO {{{ +let PLUGIN_INFO = + + Buftabs + Add buffer tabs to the statusline to save space. + 1.0 + GGLucas + WTFPL version 2 (http://sam.zoy.org/wtfpl/) + 2.2 + 2.2 + } + + and + + :style * .buftab_selected { } + + == Length == + You can set the max length of a title before it is cut off with the buftabs_maxlength + option. It is set to 25 by default. + + ]]> +; +// }}} + +buftabs = { + // Update the tabs + updateUrl: function (url) + { + // Get buftabbar + var buftabs = document.getElementById("liberator-statusline-buftabs"); + var urlWidget = document.getElementById("liberator-statusline-field-url"); + var maxlength = options.get("buftabs_maxlength").get(); + var tabvalue, position=0, selpos; + + //// Empty the tabbar + while (buftabs.lastChild != null) + buftabs.removeChild(buftabs.lastChild); + + // Create the new tabs + for (let [i, browser] in tabs.browsers) + { + // Title + if (browser.webProgress.isLoadingDocument) + tabvalue = "Loading..."; + else + tabvalue = browser.contentTitle || "Untitled"; + + // Check length + if (tabvalue.length > maxlength) + tabvalue = tabvalue.substr(0, maxlength-3)+"..."; + + // Bookmark icon + if (liberator.has("bookmarks")) + if (bookmarks.isBookmarked(browser.contentDocument.location.href)) + tabvalue += "\u2764"; + + // Brackets and index + tabvalue = "["+(i+1)+"-"+tabvalue+"]"; + + // Create label + var label = document.createElement("label"); + label.tabpos = i; + label.setAttribute("value", tabvalue); + buftabs.appendChild(label); + + label.onclick = function () + { + tabs.select(this.tabpos); + } + + if (tabs.index() == i) + { + selpos = [position, label.clientWidth+position]; + label.className = "buftab_selected"; + } else { + label.className = "buftab"; + } + + position += label.clientWidth; + } + + // Scroll + if (selpos[0] < buftabs.scrollLeft || selpos[1] > buftabs.scrollLeft+buftabs.clientWidth) + buftabs.scrollLeft = selpos[0]; + + // Show the entire line if possible + if (buftabs.scrollWidth == buftabs.clientWidth) + buftabs.scrollLeft = 0; + + // Empty url label + urlWidget.value = ""; + }, + + // Create the horizontal box for adding the tabs to + createBar: function() + { + var statusline = document.getElementById("liberator-statusline"); + var buftabs = document.getElementById("liberator-statusline-buftabs"); + var urlWidget = document.getElementById("liberator-statusline-field-url"); + + // Only create if it doesn't exist yet + if (!buftabs) + { + buftabs = document.createElement("hbox"); + buftabs.setAttribute("id", "liberator-statusline-buftabs"); + buftabs.setAttribute("flex", "1"); + buftabs.style.overflow = "hidden" + + statusline.insertBefore(buftabs, urlWidget); + } + }, + + destroyBar: function() + { + var statusline = document.getElementById("liberator-statusline"); + var buftabs = document.getElementById("liberator-statusline-buftabs"); + + if (buftabs) + statusline.removeChild(buftabs); + } +} + +var tabContainer = tabs.getBrowser().mTabContainer; +buftabs._statusline_updateUrl = statusline.updateUrl; + +tabContainer.addEventListener("TabMove", function (event) { + if (options.get("buftabs").get()) + statusline.updateUrl(); +}, false); +tabContainer.addEventListener("TabOpen", function (event) { + if (options.get("buftabs").get()) + statusline.updateUrl(); +}, false); +tabContainer.addEventListener("TabClose", function (event) { + if (options.get("buftabs").get()) + setTimeout(statusline.updateUrl, 0); +}, false); +tabContainer.addEventListener("TabSelect", function (event) { + if (options.get("buftabs").get()) + statusline.updateUrl(); +}, false); + +/// Options +options.add(["buftabs", "buftabs"], + "Control whether to use buftabs in the statusline", + "number", "1", + { + setter: function (value) + { + if (value) + { + buftabs.createBar(); + buftabs.updateUrl(null); + + statusline.updateUrl = buftabs.updateUrl; + } else { + buftabs.destroyBar(); + statusline.updateUrl = buftabs._statusline_updateUrl; + } + + return value; + }, + + completer: function (context) + [ + ["0", "Don't show buftabs, show the url"], + ["1", "Show buftabs"] + ], + + validator: Option.validateCompleter + }); + +options.add(["buftabs_maxlength", "buftabs_maxlength"], + "Max length of an entry in the buftabs list", + "number", "25", + { + setter: function (value) + { + buftabs.updateUrl(); + return value; + } + }); -- cgit v1.2.3