GTree -> std::set
This commit is contained in:
parent
5fd64fb634
commit
1273e58d59
22
termite.cc
22
termite.cc
|
@ -4,6 +4,7 @@
|
|||
#include <functional>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -75,7 +76,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);
|
||||
|
@ -655,13 +655,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);
|
||||
|
||||
|
@ -677,18 +670,23 @@ GtkTreeModel *create_completion_model(VteTerminal *vte) {
|
|||
|
||||
char *s_ptr = content, *saveptr;
|
||||
|
||||
GTree *tree = g_tree_new((GCompareFunc)strcmp);
|
||||
auto less = [](const char *a, const char *b) { return strcmp(a, b) < 0; };
|
||||
std::set<const char *, decltype(less)> tokens(less);
|
||||
|
||||
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 (const 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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue