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 constructor: button_widget
,
16 __proto__
: text_widget
.prototype,
18 make_element: function (window
) {
19 var command
= this.command
;
20 var element
= create_XUL(window
, "image");
22 element
.addEventListener("click", function (event
) {
23 var I
= new interactive_context(window
.buffers
.current
);
24 co_call(call_interactively(I
, command
));
27 element
.addEventListener("mouseover", function (event
) {
28 var msg
= "Button: " + command
;
29 var keymaps
= get_current_keymaps(window
);
30 var list
= keymap_lookup_command(keymaps
, command
);
32 msg
+= " (which is on key " + list
.join(", ") + ")";
33 window
.minibuffer
.show(msg
);
36 element
.addEventListener("mouseout", function (event
) {
37 window
.minibuffer
.show("");
40 element
.setAttribute("id", "button-widget-" + command
);
41 element
.setAttribute("class", this.class_name
);
42 for (var a
in this.attributes
) {
43 element
.setAttribute(a
, this.attributes
[a
]);
50 function make_button_widget (command
, attributes
) {
51 if (typeof attributes
== "string")
53 attributes
= { src
: "moz-icon://stock/gtk-" + attributes
};
55 function new_widget (window
) {
56 button_widget
.call(this, window
);
58 new_widget
.prototype = {
59 constructor: new_widget
,
60 __proto__
: button_widget
.prototype,
62 attributes
: attributes
64 new_widget
.mode_line_adder = function (window
) {
65 var widget
= new new_widget(window
);
66 window
.mode_line
.add_widget(widget
, widget
.make_element(window
));
72 function mode_line_add_buttons (buttons
, prepend
) {
73 for (var i
= 0, n
= buttons
.length
; i
< n
; i
++) {
74 var j
= prepend
? n
- i
- 1 : i
;
75 var w
= make_button_widget(buttons
[j
][0], buttons
[j
][1]);
76 add_hook("mode_line_hook", mode_line_adder(w
), prepend
);
80 standard_mode_line_buttons
= [
82 ["find-url-new-buffer", "new"],
84 ["forward", "go-forward"],
85 ["reload", "refresh"],
86 ["kill-current-buffer", "close"],
87 ["buffer-previous", "go-up"],
88 ["buffer-next", "go-down"],
89 ["help-page", "help"],
92 provide("mode-line-buttons");