-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
150 lines (116 loc) · 4.03 KB
/
list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "list.h"
#include <string.h>
static GtkWidget *treeview;
static GtkListStore *store; // model1
//static GtkTreeModel *model; // model2
static GtkCellRenderer *renderer;
static GtkTreeViewColumn *column;
static GtkTreeSelection *selection;
static GtkTreeIter current;
GtkWidget *List_Create()
{
store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
//model = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store));
treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("File name", renderer, "text", NAME_COLUMN,
"foreground", COLOR_COLUMN, NULL);
//gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), PATH_COLUMN, GTK_SORT_DESCENDING);
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
//gtk_tree_view_set_enable_search(GTK_TREE_VIEW(treeview), FALSE);
gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
return treeview;
}
void List_Add_File(gchar *name, gchar* path, gboolean invert)
{
GtkTreeIter iter;
if (invert)
{
gtk_list_store_prepend(store, &iter);
}
else
{
gtk_list_store_append(store, &iter);
}
gchar *nameutf8 = g_locale_to_utf8(name, strlen(name), NULL, NULL, NULL);
gtk_list_store_set(store, &iter, NAME_COLUMN, nameutf8, PATH_COLUMN, path,
COLOR_COLUMN, ROW_COLOR, -1);
g_free(nameutf8);
}
gboolean List_Remove_File()
{
// deberia separar las cosas...
GtkTreeIter iter;
gboolean current_deleted = FALSE;
gtk_tree_selection_get_selected(selection, NULL, &iter);
GtkTreePath *selectedpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
GtkTreePath *currentpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), ¤t);
if (gtk_tree_path_compare(currentpath, selectedpath) == 0)
{
current_deleted = TRUE;
}
gtk_list_store_remove(store, &iter);
gtk_tree_path_free(selectedpath);
gtk_tree_path_free(currentpath);
return current_deleted;
}
gboolean List_Is_Empty()
{
GtkTreeIter tmp = current;
return ! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &tmp);
}
void List_Select_First()
{
// quiza el problema de select first se solucione permitiendo que no halla seleccion
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), ¤t);
gtk_list_store_set(store, ¤t, COLOR_COLUMN, SEL_ROW_COLOR, -1);
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), ¤t);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path, column, TRUE, 0.5, 0.5);
gtk_tree_path_free(path);
}
void List_Select_This(GtkTreePath *path)
{
gtk_list_store_set(store, ¤t, COLOR_COLUMN, ROW_COLOR, -1);
gtk_tree_model_get_iter(GTK_TREE_MODEL(store), ¤t, path);
gtk_list_store_set(store, ¤t, COLOR_COLUMN, SEL_ROW_COLOR, -1);
}
gboolean List_Select_Previous()
{
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), ¤t);
gboolean result;
if ((result = gtk_tree_path_prev(path)))
{
gtk_list_store_set(store, ¤t, COLOR_COLUMN, ROW_COLOR, -1);
gtk_tree_model_get_iter(GTK_TREE_MODEL(store), ¤t, path);
gtk_list_store_set(store, ¤t, COLOR_COLUMN, SEL_ROW_COLOR, -1);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path, column, TRUE, 0.5, 0.5);
}
gtk_tree_path_free(path);
return result;
}
gboolean List_Select_Next()
{
GtkTreeIter tmp = current;
if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), ¤t))
{
gtk_list_store_set(store, &tmp, COLOR_COLUMN, ROW_COLOR, -1);
gtk_list_store_set(store, ¤t, COLOR_COLUMN, SEL_ROW_COLOR, -1);
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), ¤t);
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path, column, TRUE, 0.5, 0.5);
gtk_tree_path_free(path);
return TRUE;
}
else
{
current = tmp;
return FALSE;
}
}
void List_Get_Current(GString *file)
{
gchar *tmp;
gtk_tree_model_get(GTK_TREE_MODEL(store), ¤t, PATH_COLUMN, &tmp, -1);
g_string_assign(file, tmp);
g_free(tmp);
}