Simple GUI buttons are provided for controlling conkeror.  They are
intended to be unobtrusive and to steal as little screen space as
possible.  Clicking on them executes a conkeror command.  Hovering
over them tells you the command and the corresponding keystroke.

The buttons are intended to make conkeror usable for a casual user and
also to aid the novice user while they become familiar with conkeror's
interface.

They can be enabled with:
  require("mode-line-buttons.js");
  add_mode_line_buttons(standard_mode_line_buttons, true);
---

Problems:
  - The icons used do not clearly indicate their function.
  - The names of the commands are also probably unclear for novices.
  - There are probably too many buttons.  It might be better to have
    just a few, together with a popup menu.
---
 modules/mode-line-buttons.js |   88 ++++++++++++++++++++++++++++++++++++++++++
 modules/mode-line.js         |    3 +
 2 files changed, 91 insertions(+), 0 deletions(-)
 create mode 100644 modules/mode-line-buttons.js

diff --git a/modules/mode-line-buttons.js b/modules/mode-line-buttons.js
new file mode 100644
index 0000000..82ee4e9
--- /dev/null
+++ b/modules/mode-line-buttons.js
@@ -0,0 +1,88 @@
+/**
+ * (C) Copyright 2009 David Kettler
+ *
+ * Use, modification, and distribution are subject to the terms specified in 
the
+ * COPYING file.
+**/
+
+require("mode-line.js");
+
+function button_widget(window) {
+    this.class_name = "button-widget";
+    text_widget.call(this, window);
+}
+button_widget.prototype = {
+    __proto__ : text_widget.prototype,
+
+    make_element : function (window) {
+        var command = this.command;
+        var element = create_XUL(window, "image");
+
+        element.addEventListener("click", function (event) {
+            var I = new interactive_context(window.buffers.current);
+            co_call(call_interactively(I, command));
+        }, false);
+
+        element.addEventListener("mouseover", function (event) {
+            var msg = "Button: " + command;
+            var keymaps = get_current_keymaps(window);
+            var list = keymap_lookup_command(keymaps, command);
+            if (list.length)
+                msg += " (which is on key " + list.join(", ") + ")";
+            window.minibuffer.show(msg);
+        }, false);
+
+        element.addEventListener("mouseout", function (event) {
+            window.minibuffer.show("");
+        }, false);
+
+        element.setAttribute("id", "button-widget-" + command);
+        element.setAttribute("class", this.class_name);
+        for (var a in this.attributes) {
+            element.setAttribute(a, this.attributes[a]);
+        }
+
+        return element;
+    }
+};
+
+function make_button_widget(command, attributes) {
+    if (typeof(attributes) == "string")
+        // Simple case
+        attributes = {src: "moz-icon://stock/gtk-" + attributes};
+
+    function new_widget(window) {
+        button_widget.call(this, window);
+    }
+    new_widget.prototype = {
+        __proto__ : button_widget.prototype,
+        command : command,
+        attributes : attributes
+    }
+    new_widget.mode_line_adder = function (window) {
+        var widget = new new_widget(window);
+        window.mode_line.add_widget(widget, widget.make_element(window));
+    }
+
+    return new_widget;
+}
+
+function mode_line_add_buttons(buttons, prepend) {
+    for (var i = 0; i < buttons.length; i++) {
+        var j = prepend ? buttons.length - i - 1 : i;
+        var w = make_button_widget(buttons[j][0], buttons[j][1]);
+        add_hook("mode_line_hook", mode_line_adder(w), prepend);
+    }
+}
+
+standard_mode_line_buttons = [
+    ["find-url", "open"],
+    ["find-url-new-buffer", "new"],
+    ["back", "go-back"],
+    ["forward", "go-forward"],
+    ["reload", "refresh"],
+    ["kill-current-buffer", "close"],
+    ["buffer-previous", "go-up"],
+    ["buffer-next", "go-down"],
+    ["help-page", "help"],
+];
diff --git a/modules/mode-line.js b/modules/mode-line.js
index 7c04d7b..53e607a 100644
--- a/modules/mode-line.js
+++ b/modules/mode-line.js
@@ -33,6 +33,9 @@ generic_element_widget_container.prototype = {
             element.setAttribute("class", class_name);
         if (crop)
             element.setAttribute("crop", crop);
+        return this.add_widget(widget, element);
+    },
+    add_widget : function (widget, element) {
         element.conkeror_widget = new generic_widget_element(element, widget);
         this.container.appendChild(element);
         return element.conkeror_widget;
-- 
1.6.5

_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to