From cdf1ec18b302b9fe102ac6b5cca525ebb82a8c87 Mon Sep 17 00:00:00 2001 From: John Foerch Date: Wed, 29 Dec 2010 16:46:39 -0500 Subject: [PATCH] buffer_icon_widget: new mode-line widget (non-default) Mode-line widget for showing icon of current buffer, if any. Example of usage: require("favicon"); add_hook("mode_line_hook", mode_line_adder(buffer_icon_widget), true); --- modules/mode-line.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/mode-line.js b/modules/mode-line.js index 74c268a..7eb8630 100644 --- a/modules/mode-line.js +++ b/modules/mode-line.js @@ -1,6 +1,7 @@ /** * (C) Copyright 2005 Shawn Betts * (C) Copyright 2007-2008 Jeremy Maitin-Shepard + * (C) Copyright 2010 John J. Foerch * * Use, modification, and distribution are subject to the terms specified in the * COPYING file. @@ -236,6 +237,34 @@ loading_count_widget.prototype.update = function () { this.view.text = ""; }; + +/** + * buffer_icon_widget shows the icon for the current buffer, if any, in + * the mode-line. + */ +function buffer_icon_widget (window) { + this.class_name = "buffer-icon-widget"; + text_widget.call(this, window); + this.add_hook("current_buffer_icon_change_hook"); + this.add_hook("select_buffer_hook"); +} +buffer_icon_widget.prototype.__proto__ = text_widget.prototype; +buffer_icon_widget.prototype.update = function () { + var buffer = this.window.buffers.current; + if (buffer.icon) + this.view.element.setAttribute("src", buffer.icon); + else + this.view.element.removeAttribute("src"); +}; +buffer_icon_widget.mode_line_adder = function (window) { + var element = create_XUL(window, "image"); + element.setAttribute("class", "buffer-icon-widget"); + element.setAttribute("width", "16"); + element.setAttribute("height", "16"); + window.mode_line.add_widget(new buffer_icon_widget(window), element); +}; + + function mode_line_adder (widget_constructor) { if (!('mode_line_adder' in widget_constructor)) widget_constructor.mode_line_adder = function (window) { -- 2.11.4.GIT