commit: abb47b4c0faf2eadcdce62c285fea8af7edd8894
parent b6e995810f9cba4dac83d57643a5f9698699cbad
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 2 Nov 2019 22:01:00 +0100
Add completion
Diffstat:
5 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -25,8 +25,8 @@ INKSCAPE ?= inkscape
ICON_SIZES = icons/hicolor/24x24/apps/badwolf.png icons/hicolor/32x32/apps/badwolf.png icons/hicolor/48x48/apps/badwolf.png icons/hicolor/64x64/apps/badwolf.png icons/hicolor/128x128/apps/badwolf.png icons/hicolor/256x256/apps/badwolf.png
DEPS = gtk+-3.0 webkit2gtk-4.0 libsoup-2.4
-SRCS = uri.c uri_test.c keybindings.c downloads.c badwolf.c
-OBJS = uri.o keybindings.o downloads.o badwolf.o
+SRCS = bookmarks.c uri.c uri_test.c keybindings.c downloads.c badwolf.c
+OBJS = bookmarks.o uri.o keybindings.o downloads.o badwolf.o
OBJS_test = uri_test.o
EXE = badwolf
EXE_test = uri_test
diff --git a/badwolf.1 b/badwolf.1
@@ -75,6 +75,8 @@ A more generic variable name is also intended to be used in the future.
.El
.Sh FILES
.Bl -tag -width Ds -compact
+.It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/URLs.txt
+File containing a URL on each line. [UNSTABLE]
.It Pa ${XDG_DATA_HOME:-$HOME/.local/share}/badwolf/webkit-web-extensions/
Directory containing the
.Lk https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebExtension.html WebKitWebExtensions
diff --git a/badwolf.c b/badwolf.c
@@ -6,6 +6,7 @@
#include "config.h"
#include "downloads.h"
+#include "bookmarks.h"
#include "keybindings.h"
#include "uri.h"
@@ -738,6 +739,7 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b
gtk_entry_set_text(GTK_ENTRY(browser->location), target_url);
gtk_entry_set_input_purpose(GTK_ENTRY(browser->location), GTK_INPUT_PURPOSE_URL);
+ gtk_entry_set_completion(GTK_ENTRY(browser->location), location_completion);
gtk_entry_set_placeholder_text(GTK_ENTRY(browser->search), _("search in current page"));
@@ -930,6 +932,8 @@ main(int argc, char *argv[])
g_build_filename(g_get_user_data_dir(), "badwolf", "webkit-web-extension", NULL);
fprintf(stderr, _("webkit-web-extension directory set to: %s\n"), web_extensions_directory);
+ location_completion_init();
+
window->main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
window->notebook = gtk_notebook_new();
window->new_tab = gtk_button_new_from_icon_name("tab-new-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
diff --git a/bookmarks.c b/bookmarks.c
@@ -0,0 +1,45 @@
+#include "badwolf.h"
+#include "bookmarks.h"
+
+#include <gtk/gtk.h>
+#include <glib/gprintf.h> /* g_fprintf() */
+
+void
+location_completion_init()
+{
+ GtkTreeIter iter;
+ GtkListStore *list_store;
+ GIOChannel *file_channel;
+ GError *file_err = NULL;
+ gchar *file_line;
+
+ location_completion = gtk_entry_completion_new();
+
+ list_store = gtk_list_store_new(1, G_TYPE_STRING);
+
+ gchar *filename = g_build_filename(g_get_user_data_dir(), "badwolf", "URLs.txt", NULL);
+ g_fprintf(stderr, "URL Completion: loading at %s\n", filename);
+ file_channel = g_io_channel_new_file(filename, "r", &file_err);
+
+ if(file_channel != NULL)
+ {
+ while(G_IO_STATUS_NORMAL ==
+ g_io_channel_read_line(file_channel, &file_line, NULL, NULL, &file_err))
+ {
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set(list_store, &iter, 0, g_strchomp(file_line), -1);
+ }
+ g_free(file_line);
+ g_io_channel_unref(file_channel);
+ //g_io_channel_shutdown(file_channel, FALSE, &file_err);
+ g_fprintf(stderr, "URL Completion: Done.\n");
+ }
+ else
+ g_fprintf(stderr, "URL Completion: Failed to load file.\n");
+
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set(list_store, &iter, 0, homepage, -1);
+
+ gtk_entry_completion_set_model(location_completion, GTK_TREE_MODEL(list_store));
+ gtk_entry_completion_set_text_column(location_completion, 0);
+}
diff --git a/bookmarks.h b/bookmarks.h
@@ -0,0 +1,3 @@
+#include <gtk/gtk.h>
+GtkEntryCompletion *location_completion;
+void location_completion_init();