2 * (C) Copyright 2009 David Kettler
3 * (C) Copyright 2010-2011 Peter Lunicks
5 * Use, modification, and distribution are subject to the terms specified in the
9 require("mode-line.js");
11 function button_widget (window) {
12 this.class_name = "button-widget";
13 text_widget.call(this, window);
15 button_widget.prototype = {
16 constructor: button_widget,
17 __proto__: text_widget.prototype,
19 make_element: function (window) {
20 var command = this.command;
21 var element = create_XUL(window, "image");
23 element.addEventListener("click", function (event) {
24 var I = new interactive_context(window.buffers.current);
25 co_call(call_interactively(I, command));
28 element.addEventListener("mouseover", function (event) {
29 var msg = "Button: " + command;
30 var keymaps = get_current_keymaps(window);
31 var list = keymap_lookup_command(keymaps, command);
33 msg += " (which is on key " + list.join(", ") + ")";
34 window.minibuffer.show(msg);
37 element.addEventListener("mouseout", function (event) {
38 window.minibuffer.show("");
41 element.setAttribute("id", "button-widget-" + command);
42 element.setAttribute("class", this.class_name);
43 for (var a in this.attributes) {
44 element.setAttribute(a, this.attributes[a]);
51 function make_button_widget (command, attributes, update) {
52 if (typeof attributes == "string")
54 attributes = { src: "moz-icon://stock/gtk-" + attributes };
56 function new_widget (window) {
57 button_widget.call(this, window);
59 new_widget.prototype = {
60 constructor: new_widget,
61 __proto__: button_widget.prototype,
63 attributes: attributes,
66 new_widget.prototype.add_hook = function (hook_name, handler) {
69 handler = function () { obj.update(); };
70 add_hook.call(this.window, hook_name, handler);
71 this.window_hooks.push([hook_name, handler]);
73 new_widget.mode_line_adder = function (window) {
74 var widget = new new_widget(window);
75 if (new_widget.prototype.update) {
76 widget.add_hook("content_buffer_started_loading_hook");
77 widget.add_hook("content_buffer_finished_loading_hook");
78 widget.add_hook("kill_buffer_hook");
79 widget.add_hook("select_buffer_hook");
81 window.mode_line.add_widget(widget, widget.make_element(window));
87 function mode_line_add_buttons (buttons, prepend) {
88 for (var i = 0, n = buttons.length; i < n; i++) {
89 var j = prepend ? n - i - 1 : i;
90 var w = make_button_widget(buttons[j][0], buttons[j][1], buttons[j][2]);
91 add_hook("mode_line_hook", mode_line_adder(w), prepend);
95 standard_mode_line_buttons = [
97 ["find-url-new-buffer", "new"],
99 ["forward", "go-forward"],
100 ["reload", "refresh"],
101 ["kill-current-buffer", "close"],
102 ["buffer-previous", "go-up"],
103 ["buffer-next", "go-down"],
104 ["help-page", "help"],
107 provide("mode-line-buttons");