Moved hint mode and usage params to the hint instantiation.
authorDaniel Carl <danielcarl@gmx.de>
Sat, 9 Mar 2013 00:15:25 +0000 (01:15 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 9 Mar 2013 00:15:25 +0000 (01:15 +0100)
It's better to set those settings to the constructor of the hinting object
instead of giving this to the hints create function. Also the config object
was emoved to keep the JavaScript a little smaller.

src/config.h
src/hints.c
src/hints.js
src/history.c

index 85a4fb1..9be97d0 100644 (file)
@@ -28,7 +28,9 @@
 #define SETTING_MAX_CONNS           25
 #define SETTING_MAX_CONNS_PER_HOST  5
 
-const int COMMAND_HISTORY_SIZE = 30;
+const unsigned int MAXIMUM_HINTS = 500;
+
+const unsigned int COMMAND_HISTORY_SIZE = 30;
 
 const struct {
     char* command;
index cbe4801..82fc2ad 100644 (file)
@@ -27,6 +27,8 @@
 #define HINT_VAR "VpHint"
 #define HINT_FILE NULL
 
+extern const unsigned int MAXIMUM_HINTS;
+
 static void hints_run_script(Client* c, char* js);
 static void hints_fire(Client* c);
 static void hints_observe_input(Client* c, gboolean observe);
@@ -64,20 +66,30 @@ void hints_clear(Client* c)
 void hints_create(Client* c, const char* input, guint mode, const guint prefixLength)
 {
     char* js = NULL;
-    char  type, usage;
     if (CLEAN_MODE(c->state.mode) != VP_MODE_HINTING) {
         Style* style = &core.style;
         c->hints.prefixLength = prefixLength;
         c->hints.mode         = mode;
         c->hints.num          = 0;
 
+        char type, usage;
+        /* convert the mode into the type chare used in the hint script */
+        type = mode & HINTS_TYPE_LINK ? 'l' : 'i';
+
+        if (mode & HINTS_PROCESS_OPEN) {
+            usage = mode & HINTS_OPEN_NEW ? 'T' : 'O';
+        } else {
+            usage = 'U';
+        }
+
         js = g_strdup_printf(
-            "%s = new VimpHints('%s', '%s', '%s', '%s');",
-            HINT_VAR,
+            "%s = new VimpHints('%c', '%c', '%s', '%s', '%s', '%s', %d);",
+            HINT_VAR, type, usage,
             style->hint_bg,
             style->hint_bg_focus,
             style->hint_fg,
-            style->hint_style
+            style->hint_style,
+            MAXIMUM_HINTS
         );
         hints_run_script(c, js);
         g_free(js);
@@ -85,25 +97,8 @@ void hints_create(Client* c, const char* input, guint mode, const guint prefixLe
         hints_observe_input(c, TRUE);
     }
 
-    /* convert the mode into the type chare used in the hint script */
-    if (mode & HINTS_TYPE_LINK) {
-        type = 'l';
-    } else if (HINTS_TYPE_IMAGE) {
-        type = 'i';
-    }
-
-    if (mode & HINTS_PROCESS_OPEN) {
-        usage = mode & HINTS_OPEN_NEW ? 'T' : 'O';
-    } else {
-        usage = 'U';
-    }
 
-    js = g_strdup_printf(
-        "%s.create('%s', '%c', '%c');",
-        HINT_VAR,
-        input ? input : "", type,
-        usage
-    );
+    js = g_strdup_printf("%s.create('%s');", HINT_VAR, input ? input : "");
     hints_run_script(c, js);
     g_free(js);
 }
index 019c71a..91cb8ad 100644 (file)
@@ -1,31 +1,15 @@
-VimpHints = function Hints(bg, bgf, fg, style) {
+/* mode: l - links, i - images */
+/* usage: O - open, T - open in new window, U - use source */
+VimpHints = function Hints(mode, usage, bg, bgf, fg, style, maxHints) {
     "use strict";
-    var config = {
-        maxHints: 200,
-        hintCss: style,
-        hintClass: "__hint",
-        hintClassFocus: "__hint_container",
-        eBg: bg,
-        eBgf: bgf,
-        eFg: fg
-    };
-
+    var hClass = "__hint";
+    var hClassFocus = "__hint_container";
     var hCont;
     var curFocusNum = 1;
     var hints = [];
-    var mode;
-    /* O - open, T - open in new window, U - use source */
-    var usage;
 
-    this.create = function(inputText, hintMode, resultUsage)
+    this.create = function(inputText)
     {
-        if (hintMode) {
-            mode = hintMode;
-        }
-        if (resultUsage) {
-            usage = resultUsage;
-        }
-
         var topwin = window;
         var top_height = topwin.innerHeight;
         var top_width = topwin.innerWidth;
@@ -63,13 +47,13 @@ VimpHints = function Hints(bg, bgf, fg, style) {
 
             /* generate basic hint element which will be cloned and updated later */
             var hintSpan = doc.createElement("span");
-            hintSpan.setAttribute("class", config.hintClass);
-            hintSpan.style.cssText = config.hintCss;
+            hintSpan.setAttribute("class", hClass);
+            hintSpan.style.cssText = style;
 
             /* due to the different XPath result type, we will need two counter variables */
             var rect, elem, text, node, show_text;
             for (i = 0; i < res.snapshotLength; i++) {
-                if (hintCount >= config.maxHints) {
+                if (hintCount >= maxHints) {
                     break;
                 }
 
@@ -79,8 +63,8 @@ VimpHints = function Hints(bg, bgf, fg, style) {
                     continue;
                 }
 
-                var style = topwin.getComputedStyle(elem, "");
-                if (style.display === "none" || style.visibility !== "visible") {
+                var cStyle = topwin.getComputedStyle(elem, "");
+                if (cStyle.display === "none" || cStyle.visibility !== "visible") {
                     continue;
                 }
 
@@ -105,8 +89,8 @@ VimpHints = function Hints(bg, bgf, fg, style) {
                 );
 
                 /* make the link black to ensure it's readable */
-                elem.style.color = config.eFg;
-                elem.style.background = config.eBg;
+                elem.style.color = fg;
+                elem.style.background = bg;
             }
 
             doc.documentElement.appendChild(hCont);
@@ -260,8 +244,8 @@ VimpHints = function Hints(bg, bgf, fg, style) {
         /* reset previous focused hint */
         var hint = _getHintByNumber(curFocusNum);
         if (hint !== null) {
-            hint.elem.className = hint.elem.className.replace(config.hintClassFocus, config.hintClass);
-            hint.elem.style.background = config.eBg;
+            hint.elem.className = hint.elem.className.replace(hClassFocus, hClass);
+            hint.elem.style.background = bg;
             _mouseEvent(hint.elem, "mouseout");
         }
 
@@ -270,8 +254,8 @@ VimpHints = function Hints(bg, bgf, fg, style) {
         /* mark new hint as focused */
         hint = _getHintByNumber(curFocusNum);
         if (hint !== null) {
-            hint.elem.className = hint.elem.className.replace(config.hintClass, config.hintClassFocus);
-            hint.elem.style.background = config.eBgf;
+            hint.elem.className = hint.elem.className.replace(hClass, hClassFocus);
+            hint.elem.style.background = bgf;
             _mouseEvent(hint.elem, "mouseover");
             var source = _getSrc(hint.elem);
 
@@ -358,13 +342,6 @@ VimpHints = function Hints(bg, bgf, fg, style) {
                     expr = "//img[@src and contains(., '" + s + "')]";
                 }
                 break;
-            default:
-                if (s === "") {
-                    expr = "//*[@role='link' or @href] | //a[href] | //area | //img[not(ancestor::a)]";
-                } else {
-                    expr = "//*[(@role='link' or @href) and contains(., '" + s + "')] | //a[@href and contains(., '" + s + "')] | //area[contains(., '" + s + "')] | //img[not(ancestor::a) and contains(., '" + s + "')]";
-                }
-                break;
         }
         return expr;
     }
index f8099a4..d74dd7a 100644 (file)
@@ -20,7 +20,7 @@
 #include "main.h"
 #include "history.h"
 
-extern const int COMMAND_HISTORY_SIZE;
+extern const unsigned int COMMAND_HISTORY_SIZE;
 
 void history_cleanup(void)
 {