5 <description
>Add buffer tabs to the statusline to save space
.</description
>
7 <author mail
="lucas@tuple-typed.org" homepage
="http://tuple-typed.org/">Lucas de
Vries (GGLucas
)</author
>
8 <license
>WTFPL version
2 (http
://sam.zoy.org/wtfpl/)</license>
9 <minVersion
>2.2</minVersion
>
10 <maxVersion
>2.2</maxVersion
>
14 When the script is loaded it hijacks the statusline to display a list
of tabs
,
15 you can
use the
"buftabs" option to toggle it on or off
.
18 Use the BufTab and BufTabSelected highlight groups to style the buftabs
.
19 Make sure you
've called the "loadplugins" command before using the highlight
20 groups in your vimperatorrc.
23 You can set the max length of a title before it is cut off with the
24 buftabs_maxlength option. It is set to 25 by default.
32 updateUrl: function (url)
35 var btabs = document.getElementById("liberator-statusline-buftabs");
36 var urlWidget = document.getElementById("liberator-statusline-field-url");
37 var browsers = tabs.getBrowser().browsers;
38 var position=0, selpos;
40 // Make sure we have an appropriate amount of labels
41 while (btabs.childNodes.length > browsers.length)
43 btabs.removeChild(btabs.lastChild);
46 while (btabs.childNodes.length < browsers.length)
48 var label = document.createElement("label");
49 btabs.appendChild(label);
51 label.onclick = function (ev)
54 tabs.select(this.tabpos);
55 else if (ev.button == 1)
56 tabs.remove(tabs.getTab(this.tabpos), 1, false, 0);
60 // Create the new tabs
61 for (let i=0; i < browsers.length; i++)
64 var browser = browsers[i];
65 var label = btabs.childNodes[i];
68 if (browser.webProgress.isLoadingDocument)
70 browser._buftabs_label = label;
71 browser.contentDocument.addEventListener("load", function ()
73 buftabs.fillLabel(this._buftabs_label, this);
79 buftabs.fillLabel(label, browser);
81 if (tabs.index() == label.tabpos)
83 selpos = [position, label.clientWidth+position];
86 position += label.clientWidth;
90 if (selpos[0] < btabs.scrollLeft || selpos[1] > btabs.scrollLeft+btabs.clientWidth)
91 btabs.scrollLeft = selpos[0];
93 // Show the entire line if possible
94 if (btabs.scrollWidth == btabs.clientWidth)
101 // Fill a label with browser content
102 fillLabel: function(label, browser)
104 var maxlength = options.get("buftabs_maxlength").get();
108 if (browser.webProgress.isLoadingDocument)
110 tabvalue = "Loading...";
112 tabvalue = browser.contentTitle || "Untitled";
116 if (tabvalue.length > maxlength)
117 tabvalue = tabvalue.substr(0, maxlength-3)+"...";
120 if (bookmarks.isBookmarked(browser.contentDocument.location.href))
121 tabvalue += "\u2764";
123 // Brackets and index
124 tabvalue = "["+(label.tabpos+1)+"-"+tabvalue+"]";
126 label.setAttribute("value", tabvalue);
128 // Set the correct highlight group
129 if (tabs.index() == label.tabpos)
130 label.setAttributeNS(NS.uri, "highlight", "BufTabSelected");
132 label.setAttributeNS(NS.uri, "highlight", "BufTab");
137 // Create the horizontal box for adding the tabs to
138 createBar: function()
140 var statusline = document.getElementById("liberator-statusline");
141 var buftabs = document.getElementById("liberator-statusline-buftabs");
142 var urlWidget = document.getElementById("liberator-statusline-field-url");
144 // Only create if it doesn't exist yet
147 buftabs
= document
.createElement("hbox");
148 buftabs
.setAttribute("id", "liberator-statusline-buftabs");
149 buftabs
.setAttribute("flex", "1");
150 buftabs
.style
.overflow
= "hidden"
152 statusline
.insertBefore(buftabs
, urlWidget
);
156 destroyBar: function()
158 var statusline
= document
.getElementById("liberator-statusline");
159 var buftabs
= document
.getElementById("liberator-statusline-buftabs");
162 statusline
.removeChild(buftabs
);
166 /// Attach to events in order to update the tabline
167 var tabContainer
= tabs
.getBrowser().mTabContainer
;
168 buftabs
._statusline_updateUrl
= statusline
.updateUrl
;
170 tabContainer
.addEventListener("TabMove", function (event
) {
171 if (options
.get("buftabs").get())
172 statusline
.updateUrl();
174 tabContainer
.addEventListener("TabOpen", function (event
) {
175 if (options
.get("buftabs").get())
176 statusline
.updateUrl();
178 tabContainer
.addEventListener("TabClose", function (event
) {
179 if (options
.get("buftabs").get())
180 setTimeout(statusline
.updateUrl
, 0);
182 tabContainer
.addEventListener("TabSelect", function (event
) {
183 if (options
.get("buftabs").get())
184 statusline
.updateUrl();
187 tabs
.getBrowser().addEventListener("load", function (event
) {
188 if (options
.get("buftabs").get())
189 statusline
.updateUrl();
192 /// Initialise highlight groups
193 highlight
.loadCSS(String(<![CDATA
[
195 BufTabSelected font
-weight
: bold
;
199 options
.add(["buftabs"],
200 "Control whether to use buftabs in the statusline",
203 setter: function (value
)
208 buftabs
.updateUrl(null);
210 statusline
.updateUrl
= buftabs
.updateUrl
;
212 buftabs
.destroyBar();
213 statusline
.updateUrl
= buftabs
._statusline_updateUrl
;
220 completer: function (context
)
222 [false, "Don't show buftabs, show the url"],
223 [true, "Show buftabs"]
226 validator
: Option
.validateCompleter
229 options
.add(["buftabs_maxlength"],
230 "Max length of an entry in the buftabs list",
233 setter: function (value
)