get rid of GTree

This commit is contained in:
Daniel Micay 2012-07-20 10:55:38 -04:00
parent d44ed632ae
commit 7e55478fb1
1 changed files with 9 additions and 12 deletions

View File

@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include <set>
#include <stdbool.h>
#include <string.h>
@ -66,7 +67,6 @@ static gboolean button_press_cb(VteTerminal *vte, GdkEventButton *event, gboolea
static void beep_cb(GtkWidget *vte, gboolean *urgent_on_bell);
static gboolean focus_cb(GtkWindow *window);
static gboolean add_to_list_store(char *key, void *, GtkListStore *store);
static GtkTreeModel *create_completion_model(VteTerminal *vte);
static void search(VteTerminal *vte, const char *pattern, bool reverse);
static void overlay_show(search_panel_info *info, overlay_mode mode, bool complete);
@ -382,13 +382,6 @@ gboolean focus_cb(GtkWindow *window) {
}
/* }}} */
gboolean add_to_list_store(char *key, void *, GtkListStore *store) {
GtkTreeIter iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, key, -1);
return FALSE;
}
GtkTreeModel *create_completion_model(VteTerminal *vte) {
GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
@ -404,18 +397,22 @@ GtkTreeModel *create_completion_model(VteTerminal *vte) {
char *s_ptr = content, *saveptr;
GTree *tree = g_tree_new((GCompareFunc)strcmp);
std::set<char *> tokens;
for (; ; s_ptr = NULL) {
char *token = strtok_r(s_ptr, " \n\t", &saveptr);
if (!token) {
break;
}
g_tree_insert(tree, token, NULL);
tokens.insert(token);
}
for (char *token : tokens) {
GtkTreeIter iter;
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, token, -1);
}
g_tree_foreach(tree, (GTraverseFunc)add_to_list_store, store);
g_tree_destroy(tree);
g_free(content);
return GTK_TREE_MODEL(store);
}