Hello
I've added a very simple url completion mode to surf, using a
GtkEntryCompletion object. It only completes urls from a file just now,
although I'm hoping to add history completion as well. It reads from
~/.surf/urls.txt and each address should be on a new line. Bear in mind that it
isn't very clever: if you add http://example.com to urls.txt you will have to
start typing http... to make it appear. I'm getting around this by only writing
example.com in the file.
I think this is pretty useful, hopefully someone else might as well.
Regards
Rory McCann
diff -r 561d9db3aae4 surf.c
--- a/surf.c Thu Sep 17 13:03:58 2009 +0200
+++ b/surf.c Fri Sep 18 19:56:41 2009 +0100
@@ -28,6 +28,8 @@
typedef struct Client {
GtkWidget *win, *scroll, *vbox, *urlbar, *searchbar, *indicator;
+ GtkEntryCompletion *urlcomplete;
+ GtkListStore *completeliststore;
WebKitWebView *view;
WebKitDownload *download;
gchar *title;
@@ -414,6 +416,31 @@
gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
g_signal_connect(G_OBJECT(c->urlbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
+ /* completeliststore */
+ c->completeliststore = gtk_list_store_new(1,G_TYPE_STRING);
+ GtkTreeIter iter;
+ int len = 0;
+ char buf[1024];
+ FILE* urlf;
+ if (( urlf = g_fopen(strcat(workdir,"/urls.txt"),"r")))
+ {
+ while (fgets(buf,sizeof buf,urlf))
+ {
+ len = strlen(buf);
+ if (buf[len - 1] == '\n')
+ buf[len - 1] = 0;
+ gtk_list_store_append(c->completeliststore,&iter);
+ gtk_list_store_set(c->completeliststore,&iter,0,buf,-1);
+ }
+ }
+ fclose(urlf);
+
+ /* urlcomplete */
+ c->urlcomplete = gtk_entry_completion_new();
+ gtk_entry_completion_set_model(GTK_ENTRY_COMPLETION(c->urlcomplete),GTK_TREE_MODEL(c->completeliststore));
+ gtk_entry_completion_set_text_column(GTK_ENTRY_COMPLETION(c->urlcomplete),0);
+ gtk_entry_set_completion(GTK_ENTRY(c->urlbar),GTK_ENTRY_COMPLETION(c->urlcomplete));
+
/* searchbar */
c->searchbar = gtk_entry_new();
gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
@@ -433,6 +460,10 @@
gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
+ /* Hints */
+ GdkGeometry hints = {1,1};
+ gtk_window_set_geometry_hints(GTK_WINDOW(c->win),NULL,&hints,GDK_HINT_MIN_SIZE);
+
/* Setup */
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);