Show page title in history and bookmark completion (#46).
authorDaniel Carl <danielcarl@gmx.de>
Tue, 16 Jul 2013 15:28:27 +0000 (17:28 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 16 Jul 2013 15:37:25 +0000 (17:37 +0200)
src/bookmark.c
src/completion.c
src/completion.h
src/history.c

index 9983827..1f1b6cd 100644 (file)
@@ -119,7 +119,11 @@ gboolean bookmark_fill_completion(GtkListStore *store, const char *input)
         for (GList *l = src; l; l = l->next) {
             bm = (Bookmark*)l->data;
             gtk_list_store_append(store, &iter);
-            gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, bm->uri, -1);
+            gtk_list_store_set(
+                store, &iter,
+                COMPLETION_STORE_FIRST, bm->uri,
+                COMPLETION_STORE_SECOND, bm->title, -1
+            );
             found = true;
         }
     } else {
@@ -132,7 +136,11 @@ gboolean bookmark_fill_completion(GtkListStore *store, const char *input)
                 && util_array_contains_all_tags(bm->tags, g_strv_length(bm->tags), parts, len)
             ) {
                 gtk_list_store_append(store, &iter);
-                gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, bm->uri, -1);
+                gtk_list_store_set(
+                    store, &iter,
+                    COMPLETION_STORE_FIRST, bm->uri,
+                    COMPLETION_STORE_SECOND, bm->title, -1
+                );
                 found = true;
             }
         }
index a24effa..af58b8c 100644 (file)
@@ -72,7 +72,7 @@ gboolean completion_complete(gboolean back)
     }
 
     /* create the list store model */
-    store = gtk_list_store_new(1, G_TYPE_STRING);
+    store = gtk_list_store_new(COMPLETION_STORE_NUM, G_TYPE_STRING, G_TYPE_STRING);
     if (type == VB_INPUT_SET) {
         res = setting_fill_completion(store, suffix);
     } else if (type == VB_INPUT_OPEN || type == VB_INPUT_TABOPEN) {
@@ -123,8 +123,9 @@ static void init_completion(GtkTreeModel *model)
 {
     GtkCellRenderer *renderer;
     GtkTreeSelection *selection;
+    GtkTreeViewColumn *column;
     GtkRequisition size;
-    int height;
+    int height, width;
 
     /* prepare the tree view */
     comp.win  = gtk_scrolled_window_new(NULL, NULL);
@@ -151,23 +152,41 @@ static void init_completion(GtkTreeModel *model)
     gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE);
     gtk_tree_selection_set_select_function(selection, tree_selection_func, NULL, NULL);
 
-    /* prepare the column renderer */
+    /* get window dimension */
+    gtk_window_get_size(GTK_WINDOW(vb.gui.window), &width, &height);
+
+    /* prepare first column */
+    column = gtk_tree_view_column_new();
+    gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(comp.tree), column);
+
     renderer = gtk_cell_renderer_text_new();
     g_object_set(renderer,
         "font-desc", vb.style.comp_font,
         "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
         NULL
     );
-    gtk_tree_view_insert_column_with_attributes(
-        GTK_TREE_VIEW(comp.tree), -1, "", renderer,
-        "text", COMPLETION_STORE_FIRST,
+    gtk_tree_view_column_pack_start(column, renderer, true);
+    gtk_tree_view_column_add_attribute(column, renderer, "text", COMPLETION_STORE_FIRST);
+    gtk_tree_view_column_set_min_width(column, 2 * width/3);
+
+    /* prepare second column */
+    column = gtk_tree_view_column_new();
+    gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
+    gtk_tree_view_append_column(GTK_TREE_VIEW(comp.tree), column);
+
+    renderer = gtk_cell_renderer_text_new();
+    g_object_set(renderer,
+        "font-desc", vb.style.comp_font,
+        "ellipsize", PANGO_ELLIPSIZE_END,
         NULL
     );
+    gtk_tree_view_column_pack_start(column, renderer, true);
+    gtk_tree_view_column_add_attribute(column, renderer, "text", COMPLETION_STORE_SECOND);
 
     /* use max 1/3 of window height for the completion */
 #ifdef HAS_GTK3
     gtk_widget_get_preferred_size(comp.tree, NULL, &size);
-    gtk_window_get_size(GTK_WINDOW(vb.gui.window), NULL, &height);
     height /= 3;
     gtk_scrolled_window_set_min_content_height(
         GTK_SCROLLED_WINDOW(comp.win),
@@ -175,7 +194,6 @@ static void init_completion(GtkTreeModel *model)
     );
 #else
     gtk_widget_size_request(comp.tree, &size);
-    gtk_window_get_size(GTK_WINDOW(vb.gui.window), NULL, &height);
     height /= 3;
     if (size.height > height) {
         gtk_widget_set_size_request(comp.win, -1, height);
index 7074d99..7a3ea26 100644 (file)
@@ -24,7 +24,8 @@
 
 enum {
     COMPLETION_STORE_FIRST,
-    COMPLETION_STORE_SECOND
+    COMPLETION_STORE_SECOND,
+    COMPLETION_STORE_NUM
 };
 
 void completion_clean(void);
index 9e8a32e..b05241c 100644 (file)
@@ -137,7 +137,11 @@ gboolean history_fill_completion(GtkListStore *store, HistoryType type, const ch
         for (GList *l = src; l; l = l->next) {
             item = l->data;
             gtk_list_store_append(store, &iter);
-            gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, item->first, -1);
+            gtk_list_store_set(
+                store, &iter,
+                COMPLETION_STORE_FIRST, item->first,
+                COMPLETION_STORE_SECOND, item->second, -1
+            );
             found = true;
         }
     } else if (HISTORY_URL == type) {
@@ -148,7 +152,11 @@ gboolean history_fill_completion(GtkListStore *store, HistoryType type, const ch
             item = l->data;
             if (util_string_contains_all_tags(item->first, parts, len)) {
                 gtk_list_store_append(store, &iter);
-                gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, item->first, -1);
+                gtk_list_store_set(
+                    store, &iter,
+                    COMPLETION_STORE_FIRST, item->first,
+                    COMPLETION_STORE_SECOND, item->second, -1
+                );
                 found = true;
             }
         }
@@ -158,7 +166,11 @@ gboolean history_fill_completion(GtkListStore *store, HistoryType type, const ch
             item = l->data;
             if (g_str_has_prefix(item->first, input)) {
                 gtk_list_store_append(store, &iter);
-                gtk_list_store_set(store, &iter, COMPLETION_STORE_FIRST, item->first, -1);
+                gtk_list_store_set(
+                    store, &iter,
+                    COMPLETION_STORE_FIRST, item->first,
+                    COMPLETION_STORE_SECOND, item->second, -1
+                );
                 found = true;
             }
         }