contrib/modules/mode-line-buttons.js: whitespace
[conkeror/arlinius.git] / contrib / modules / mode-line-buttons.js
blob90dafd73b7b00276e2b06c6e0bd5d00b95d7c0db
1 /**
2  * (C) Copyright 2009 David Kettler
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 require("mode-line.js");
10 function button_widget (window) {
11     this.class_name = "button-widget";
12     text_widget.call(this, window);
14 button_widget.prototype = {
15     __proto__: text_widget.prototype,
17     make_element: function (window) {
18         var command = this.command;
19         var element = create_XUL(window, "image");
21         element.addEventListener("click", function (event) {
22             var I = new interactive_context(window.buffers.current);
23             co_call(call_interactively(I, command));
24         }, false);
26         element.addEventListener("mouseover", function (event) {
27             var msg = "Button: " + command;
28             var keymaps = get_current_keymaps(window);
29             var list = keymap_lookup_command(keymaps, command);
30             if (list.length)
31                 msg += " (which is on key " + list.join(", ") + ")";
32             window.minibuffer.show(msg);
33         }, false);
35         element.addEventListener("mouseout", function (event) {
36             window.minibuffer.show("");
37         }, false);
39         element.setAttribute("id", "button-widget-" + command);
40         element.setAttribute("class", this.class_name);
41         for (var a in this.attributes) {
42             element.setAttribute(a, this.attributes[a]);
43         }
45         return element;
46     }
49 function make_button_widget (command, attributes) {
50     if (typeof attributes == "string")
51         // Simple case
52         attributes = { src: "moz-icon://stock/gtk-" + attributes };
54     function new_widget (window) {
55         button_widget.call(this, window);
56     }
57     new_widget.prototype = {
58         __proto__: button_widget.prototype,
59         command: command,
60         attributes: attributes
61     }
62     new_widget.mode_line_adder = function (window) {
63         var widget = new new_widget(window);
64         window.mode_line.add_widget(widget, widget.make_element(window));
65     }
67     return new_widget;
70 function mode_line_add_buttons (buttons, prepend) {
71     for (var i = 0, n = buttons.length; i < n; i++) {
72         var j = prepend ? n - i - 1 : i;
73         var w = make_button_widget(buttons[j][0], buttons[j][1]);
74         add_hook("mode_line_hook", mode_line_adder(w), prepend);
75     }
78 standard_mode_line_buttons = [
79     ["find-url", "open"],
80     ["find-url-new-buffer", "new"],
81     ["back", "go-back"],
82     ["forward", "go-forward"],
83     ["reload", "refresh"],
84     ["kill-current-buffer", "close"],
85     ["buffer-previous", "go-up"],
86     ["buffer-next", "go-down"],
87     ["help-page", "help"],