move sys/wait.h within #define
[xombrero.git] / completion.c
blob09f3b6c0ac2280ea5f46d6c84a0ddf700881f430
1 /*
2 * Copyright (c) 2010, 2011 Marco Peereboom <marco@peereboom.us>
3 * Copyright (c) 2011 Stevan Andjelkovic <stevan@student.chalmers.se>
4 * Copyright (c) 2010, 2011 Edd Barrett <vext01@gmail.com>
5 * Copyright (c) 2011 Todd T. Fries <todd@fries.net>
6 * Copyright (c) 2011 Raphael Graf <r@undefined.ch>
7 * Copyright (c) 2011 Michal Mazurek <akfaew@jasminek.net>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #include "xxxterm.h"
24 gboolean
25 completion_select_cb(GtkEntryCompletion *widget, GtkTreeModel *model,
26 GtkTreeIter *iter, struct tab *t)
28 gchar *value;
30 gtk_tree_model_get(model, iter, 0, &value, -1);
31 load_uri(t, value);
32 g_free(value);
34 return (FALSE);
37 gboolean
38 completion_hover_cb(GtkEntryCompletion *widget, GtkTreeModel *model,
39 GtkTreeIter *iter, struct tab *t)
41 gchar *value;
43 gtk_tree_model_get(model, iter, 0, &value, -1);
44 gtk_entry_set_text(GTK_ENTRY(t->uri_entry), value);
45 gtk_editable_set_position(GTK_EDITABLE(t->uri_entry), -1);
46 g_free(value);
48 return (TRUE);
51 void
52 completion_add_uri(const gchar *uri)
54 GtkTreeIter iter;
56 /* add uri to list_store */
57 gtk_list_store_append(completion_model, &iter);
58 gtk_list_store_set(completion_model, &iter, 0, uri, -1);
61 gboolean
62 completion_match(GtkEntryCompletion *completion, const gchar *key,
63 GtkTreeIter *iter, gpointer user_data)
65 gchar *value;
66 gboolean match = FALSE;
68 gtk_tree_model_get(GTK_TREE_MODEL(completion_model), iter, 0, &value,
69 -1);
71 if (value == NULL)
72 return FALSE;
74 match = match_uri(value, key);
76 g_free(value);
77 return (match);
80 void
81 completion_add(struct tab *t)
83 /* enable completion for tab */
84 t->completion = gtk_entry_completion_new();
85 gtk_entry_completion_set_text_column(t->completion, 0);
86 gtk_entry_set_completion(GTK_ENTRY(t->uri_entry), t->completion);
87 gtk_entry_completion_set_model(t->completion,
88 GTK_TREE_MODEL(completion_model));
89 gtk_entry_completion_set_match_func(t->completion, completion_match,
90 NULL, NULL);
91 gtk_entry_completion_set_minimum_key_length(t->completion, 1);
92 gtk_entry_completion_set_inline_selection(t->completion, TRUE);
93 g_signal_connect(G_OBJECT (t->completion), "match-selected",
94 G_CALLBACK(completion_select_cb), t);
95 g_signal_connect(G_OBJECT (t->completion), "cursor-on-match",
96 G_CALLBACK(completion_hover_cb), t);