[PATCH] Provide buttons on the mode-line for basic browser control.

View: New views
2 Messages — Rating Filter:   Alert me  

[PATCH] Provide buttons on the mode-line for basic browser control.

by David Kettler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.
Hopefully they are useful for novices and casual users.

They can be enabled with:
  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.

---

There is no change in functionality compared with the previous version
of this patch, but the code makes better use of prototypes.

When I turn this on now, I don't use it.  But when I first started
using conkeror I would have found it helpful.
---
 modules/mode-line.js |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/modules/mode-line.js b/modules/mode-line.js
index 72315f7..cbe45b6 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;
@@ -224,6 +227,66 @@ loading_count_widget.prototype.update = function () {
         this.view.text = "";
 };
 
+
+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 ctx = { window: window, key_sequence: [], sticky_modifiers: 0 };
+            call_interactively(ctx, command);
+        }, false);
+
+        element.addEventListener("mouseover", function (event) {
+            var msg = "Button: " + command;
+            var list = find_command_in_keymap(window.buffers.current, 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_adder(widget_constructor) {
     if (!('mode_line_adder' in widget_constructor))
         widget_constructor.mode_line_adder = function (window) {
@@ -232,6 +295,26 @@ function mode_line_adder(widget_constructor) {
     return widget_constructor.mode_line_adder;
 }
 
+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"],
+    ["go-back", "go-back"],
+    ["go-forward", "go-forward"],
+    ["reload", "refresh"],
+    ["kill-current-buffer", "close"],
+    ["buffer-previous", "go-up"],
+    ["buffer-next", "go-down"],
+    ["help-page", "help"],
+];
+
 add_hook("mode_line_hook", mode_line_adder(current_buffer_name_widget));
 add_hook("mode_line_hook", mode_line_adder(clock_widget));
 add_hook("mode_line_hook", mode_line_adder(current_buffer_scroll_position_widget));
--
1.6.2.4

_______________________________________________
Conkeror mailing list
Conkeror@...
https://www.mozdev.org/mailman/listinfo/conkeror

[PATCH] buttons: use interactive_context

by David Kettler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Squash onto parent (Provide buttons on the mode-line for basic browser
control, 2009-05-08).  Needed after b26bd26 (interactive_context:
construct with `new' instead of ad-hoc, 2009-05-29).
---
 modules/mode-line.js |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/modules/mode-line.js b/modules/mode-line.js
index cbe45b6..591f805 100644
--- a/modules/mode-line.js
+++ b/modules/mode-line.js
@@ -240,7 +240,7 @@ button_widget.prototype = {
         var element = create_XUL(window, "image");
 
         element.addEventListener("click", function (event) {
-            var ctx = { window: window, key_sequence: [], sticky_modifiers: 0 };
+            var ctx = new interactive_context(window.buffers.current);
             call_interactively(ctx, command);
         }, false);
 
--
1.6.3.3

_______________________________________________
Conkeror mailing list
Conkeror@...
https://www.mozdev.org/mailman/listinfo/conkeror