Allow to set the maximum number of completion items to runtime.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 23 Dec 2012 22:56:44 +0000 (23:56 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 23 Dec 2012 22:57:53 +0000 (23:57 +0100)
src/completion.c
src/main.h
src/setting.c

index 304ae8a..26f4984 100644 (file)
@@ -144,11 +144,11 @@ static GList* completion_update(GList* completion, GList* active, gboolean back)
     GList *old, *new;
     Completion *c;
 
-    int length = g_list_length(completion);
-    int max = 15;
-    int items = MAX(length, max);
-    int r = (max) % 2;
-    int offset = max / 2 - 1 + r;
+    gint length = g_list_length(completion);
+    gint max    = vp.config.max_completion_items;
+    gint items  = MAX(length, max);
+    gint r      = (max) % 2;
+    gint offset = max / 2 - 1 + r;
 
     old = active;
     int position = g_list_position(completion, active) + 1;
@@ -216,17 +216,16 @@ static GList* completion_update(GList* completion, GList* active, gboolean back)
 /* allow to chenge the direction of display */
 static void completion_show(gboolean back)
 {
-    /* TODO make this configurable */
-    const gint max_items = 15;
+    guint max = vp.config.max_completion_items;
     gint i = 0;
     if (back) {
         vp.comps.active = g_list_last(vp.comps.completions);
-        for (GList *l = vp.comps.active; l && i < max_items; l = l->prev, i++) {
+        for (GList *l = vp.comps.active; l && i < max; l = l->prev, i++) {
             gtk_widget_show_all(((Completion*)l->data)->event);
         }
     } else {
         vp.comps.active = g_list_first(vp.comps.completions);
-        for (GList *l = vp.comps.active; l && i < max_items; l = l->next, i++) {
+        for (GList *l = vp.comps.active; l && i < max; l = l->next, i++) {
             gtk_widget_show_all(((Completion*)l->data)->event);
         }
     }
@@ -269,7 +268,6 @@ static void completion_set_entry_text(Completion* completion)
 
 static Completion* completion_get_new(const gchar* label, const gchar* prefix)
 {
-    /* TODO make this configurable */
     const gint padding = 2;
     Completion* c = g_new0(Completion, 1);
 
index 7120caf..2d5236e 100644 (file)
@@ -202,6 +202,7 @@ typedef struct {
     time_t cookie_timeout;
 #endif
     gint   scrollstep;
+    guint  max_completion_items;
 } Config;
 
 typedef struct {
@@ -214,6 +215,7 @@ typedef struct {
     VpColor               input_fg[VP_MSG_LAST];
     VpColor               input_bg[VP_MSG_LAST];
     PangoFontDescription* input_font[VP_MSG_LAST];
+    /* completion */
     VpColor               comp_fg[VP_COMP_LAST];
     VpColor               comp_bg[VP_COMP_LAST];
     PangoFontDescription* comp_font[VP_COMP_LAST];
@@ -246,11 +248,6 @@ typedef struct {
     Style         style;
     GHashTable*   settings;
     Hints         hints;
-#if 0
-    Ssl           ssl;
-    Communication comm;
-    Info          info;
-#endif
 } VpCore;
 
 /* main object */
index 7ef26e7..40b8ca5 100644 (file)
@@ -97,6 +97,7 @@ static Setting default_settings[] = {
     {NULL, "completion-fg-active", TYPE_CHAR, setting_completion_style, {.s = "#fff"}},
     {NULL, "completion-bg-normal", TYPE_CHAR, setting_completion_style, {.s = "#656565"}},
     {NULL, "completion-bg-active", TYPE_CHAR, setting_completion_style, {.s = "#777777"}},
+    {NULL, "max-completion-items", TYPE_INTEGER, setting_completion_style, {.i = 15}},
     {NULL, "hint-bg", TYPE_CHAR, setting_hint_style, {.s = "#ff0"}},
     {NULL, "hint-bg-focus", TYPE_CHAR, setting_hint_style, {.s = "#8f0"}},
     {NULL, "hint-fg", TYPE_CHAR, setting_hint_style, {.s = "#000"}},
@@ -273,6 +274,8 @@ static gboolean setting_completion_style(const Setting* s)
             pango_font_description_free(style->comp_font[type]);
         }
         style->comp_font[type] = pango_font_description_from_string(s->arg.s);
+    } else if (!g_strcmp0(s->name, "max-completion-items")) {
+        vp.config.max_completion_items = s->arg.i;
     }
 
     return TRUE;