2 * (C) Copyright 2009 David Kettler
4 * Use, modification, and distribution are subject to the terms specified in the
10 require("mode-line.js");
12 function button_widget (window) {
13 this.class_name = "button-widget";
14 text_widget.call(this, window);
16 button_widget.prototype = {
17 constructor: button_widget,
18 __proto__: text_widget.prototype,
20 make_element: function (window) {
21 var command = this.command;
22 var element = create_XUL(window, "image");
24 element.addEventListener("click", function (event) {
25 var I = new interactive_context(window.buffers.current);
26 co_call(call_interactively(I, command));
29 element.addEventListener("mouseover", function (event) {
30 var msg = "Button: " + command;
31 var keymaps = get_current_keymaps(window);
32 var list = keymap_lookup_command(keymaps, command);
34 msg += " (which is on key " + list.join(", ") + ")";
35 window.minibuffer.show(msg);
38 element.addEventListener("mouseout", function (event) {
39 window.minibuffer.show("");
42 element.setAttribute("id", "button-widget-" + command);
43 element.setAttribute("class", this.class_name);
44 for (var a in this.attributes) {
45 element.setAttribute(a, this.attributes[a]);
52 function make_button_widget (command, attributes) {
53 if (typeof attributes == "string")
55 attributes = { src: "moz-icon://stock/gtk-" + attributes };
57 function new_widget (window) {
58 button_widget.call(this, window);
60 new_widget.prototype = {
61 constructor: new_widget,
62 __proto__: button_widget.prototype,
64 attributes: attributes
66 new_widget.mode_line_adder = function (window) {
67 var widget = new new_widget(window);
68 window.mode_line.add_widget(widget, widget.make_element(window));
74 function mode_line_add_buttons (buttons, prepend) {
75 for (var i = 0, n = buttons.length; i < n; i++) {
76 var j = prepend ? n - i - 1 : i;
77 var w = make_button_widget(buttons[j][0], buttons[j][1]);
78 add_hook("mode_line_hook", mode_line_adder(w), prepend);
82 standard_mode_line_buttons = [
84 ["find-url-new-buffer", "new"],
86 ["forward", "go-forward"],
87 ["reload", "refresh"],
88 ["kill-current-buffer", "close"],
89 ["buffer-previous", "go-up"],
90 ["buffer-next", "go-down"],
91 ["help-page", "help"],
94 provide("mode-line-buttons");