2 * (C) Copyright 2009 David Kettler
4 * Use, modification, and distribution are subject to the terms specified in the
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));
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);
31 msg += " (which is on key " + list.join(", ") + ")";
32 window.minibuffer.show(msg);
35 element.addEventListener("mouseout", function (event) {
36 window.minibuffer.show("");
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]);
49 function make_button_widget(command, attributes) {
50 if (typeof(attributes) == "string")
52 attributes = {src: "moz-icon://stock/gtk-" + attributes};
54 function new_widget(window) {
55 button_widget.call(this, window);
57 new_widget.prototype = {
58 __proto__ : button_widget.prototype,
60 attributes : attributes
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));
70 function mode_line_add_buttons(buttons, prepend) {
71 for (var i = 0; i < buttons.length; i++) {
72 var j = prepend ? buttons.length - 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);
78 standard_mode_line_buttons = [
80 ["find-url-new-buffer", "new"],
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"],