Thu, 12 Dec 2024 20:01:43 +0100
update toolkit
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2017 Olaf Wintermann. All rights reserved. |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include <stdio.h> |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | #include <stdlib.h> |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include <string.h> |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include <stdarg.h> |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "../common/context.h" |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "../common/object.h" |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "container.h" |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
90
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
38 | #include <cx/array_list.h> |
100 | 39 | #include <cx/linked_list.h> |
90
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
40 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include "list.h" |
51
e324291ca9f8
add resource preview window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
50
diff
changeset
|
42 | #include "icon.h" |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
43 | #include "menu.h" |
90
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
44 | #include "dnd.h" |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | void* ui_strmodel_getvalue(void *elm, int column) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | return column == 0 ? elm : NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | static GtkListStore* create_list_store(UiList *list, UiModel *model) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | int columns = model->columns; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | GType types[2*columns]; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | int c = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | for(int i=0;i<columns;i++,c++) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | switch(model->types[i]) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | case UI_STRING: |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | case UI_STRING_FREE: types[c] = G_TYPE_STRING; break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | case UI_INTEGER: types[c] = G_TYPE_INT; break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | case UI_ICON: types[c] = G_TYPE_OBJECT; break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | case UI_ICON_TEXT: |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | case UI_ICON_TEXT_FREE: { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | types[c] = G_TYPE_OBJECT; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | types[++c] = G_TYPE_STRING; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | GtkListStore *store = gtk_list_store_newv(c, types); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | if(list) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | void *elm = list->first(list); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | while(elm) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | // insert new row |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | GtkTreeIter iter; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | gtk_list_store_insert (store, &iter, -1); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | // set column values |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | int c = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | for(int i=0;i<columns;i++,c++) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | void *data = model->getvalue(elm, c); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | GValue value = G_VALUE_INIT; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | switch(model->types[i]) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | case UI_STRING: |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | case UI_STRING_FREE: { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | g_value_init(&value, G_TYPE_STRING); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | g_value_set_string(&value, data); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | if(model->types[i] == UI_STRING_FREE) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | free(data); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | case UI_INTEGER: { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | g_value_init(&value, G_TYPE_INT); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | int *intptr = data; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | g_value_set_int(&value, *intptr); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | case UI_ICON: { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | g_value_init(&value, G_TYPE_OBJECT); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | UiIcon *icon = data; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | #if GTK_MAJOR_VERSION >= 4 |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | g_value_set_object(&value, icon->info); // TODO: does this work? |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | #else |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | if(!icon->pixbuf && icon->info) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | GError *error = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | icon->pixbuf = pixbuf; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | if(icon->pixbuf) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | g_value_set_object(&value, icon->pixbuf); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | #endif |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | case UI_ICON_TEXT: |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | case UI_ICON_TEXT_FREE: { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | UiIcon *icon = data; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | #if GTK_MAJOR_VERSION >= 4 |
50
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
122 | if(icon) { |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
123 | GValue iconvalue = G_VALUE_INIT; |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
124 | g_value_init(&iconvalue, G_TYPE_OBJECT); |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
125 | g_value_set_object(&iconvalue, ui_icon_pixbuf(icon)); |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
126 | gtk_list_store_set_value(store, &iter, c, &iconvalue); |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
127 | } |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | #else |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | GValue pixbufvalue = G_VALUE_INIT; |
50
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
130 | if(icon) { |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
131 | if(!icon->pixbuf && icon->info) { |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
132 | GError *error = NULL; |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
133 | GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error); |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
134 | icon->pixbuf = pixbuf; |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
135 | } |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
136 | g_value_init(&pixbufvalue, G_TYPE_OBJECT); |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
137 | g_value_set_object(&pixbufvalue, icon->pixbuf); |
9c25e2616bfa
fix startup in case the dav config doesn't exist
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
46
diff
changeset
|
138 | gtk_list_store_set_value(store, &iter, c, &pixbufvalue); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | #endif |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | c++; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | char *str = model->getvalue(elm, c); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | g_value_init(&value, G_TYPE_STRING); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | g_value_set_string(&value, str); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | if(model->types[i] == UI_ICON_TEXT_FREE) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | free(str); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | break; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | gtk_list_store_set_value(store, &iter, c, &value); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | // next row |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | elm = list->next(list); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | return store; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | UIWIDGET ui_listview_create(UiObject *obj, UiListArgs args) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | UiObject* current = uic_current_obj(obj); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | // create treeview |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | GtkWidget *view = gtk_tree_view_new(); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
170 | ui_set_name_and_style(view, args.name, args.style_class); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
171 | ui_set_widget_groups(obj->ctx, view, args.groups); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes(NULL, renderer, "text", 0, NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | #ifdef UI_GTK3 |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | #if GTK_MINOR_VERSION >= 8 |
71
9e19ac687b9f
fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
179 | //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | #else |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | // TODO: implement for older gtk3 |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | #endif |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | #else |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | // TODO: implement for gtk2 |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | #endif |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
188 | model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | UiList *list = var ? var->value : NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | GtkListStore *listmodel = create_list_store(list, model); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); |
71
9e19ac687b9f
fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
195 | g_object_unref(listmodel); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | UiListView *listview = malloc(sizeof(UiListView)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | listview->obj = obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | listview->widget = view; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | listview->var = var; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | listview->model = model; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | view, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | "destroy", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | G_CALLBACK(ui_listview_destroy), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | listview); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | // bind var |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | list->update = ui_listview_update; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | list->getselection = ui_listview_getselection; |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
211 | list->setselection = ui_listview_setselection; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | list->obj = listview; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | // add callback |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
215 | UiTreeEventData *event = malloc(sizeof(UiTreeEventData)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
216 | event->obj = obj; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
217 | event->activate = args.onactivate; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
218 | event->activatedata = args.onactivatedata; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
219 | event->selection = args.onselection; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
220 | event->selectiondata = args.onselectiondata; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
221 | g_signal_connect( |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
222 | view, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
223 | "destroy", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
224 | G_CALLBACK(ui_destroy_userdata), |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
225 | event); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
226 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | if(args.onactivate) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | view, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | "row-activated", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | G_CALLBACK(ui_listview_activate_event), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
234 | if(args.onselection) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
235 | GtkTreeSelection *selection = gtk_tree_view_get_selection( |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
236 | GTK_TREE_VIEW(view)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
237 | g_signal_connect( |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
238 | selection, |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
239 | "changed", |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
240 | G_CALLBACK(ui_listview_selection_event), |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
241 | event); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
242 | } |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
243 | if(args.contextmenu) { |
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
244 | UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, view); |
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
245 | ui_widget_set_contextmenu(view, menu); |
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
246 | } |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
247 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
249 | // add widget to the current container |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | gtk_scrolled_window_set_policy( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | GTK_SCROLLED_WINDOW(scroll_area), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | GTK_POLICY_AUTOMATIC, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | UI_APPLY_LAYOUT1(current, args); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | current->container->add(current->container, scroll_area, FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | // ct->current should point to view, not scroll_area, to make it possible |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | // to add a context menu |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | current->container->current = view; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | return scroll_area; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | /* |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | static void drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer udata) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
269 | printf("drag begin\n"); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
270 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | static void drag_end( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | GtkWidget *widget, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | GdkDragContext *context, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | guint time, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | gpointer udata) |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | printf("drag end\n"); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | */ |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | /* |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | static GtkTargetEntry targetentries[] = |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | { "STRING", 0, 0 }, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | { "text/plain", 0, 1 }, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | { "text/uri-list", 0, 2 }, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | }; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | */ |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | UIWIDGET ui_table_create(UiObject *obj, UiListArgs args) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | UiObject* current = uic_current_obj(obj); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | // create treeview |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
297 | GtkWidget *view = gtk_tree_view_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | UiModel *model = args.model; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
300 | int columns = model ? model->columns : 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | int addi = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | for(int i=0;i<columns;i++) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
304 | GtkTreeViewColumn *column = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
305 | if(model->types[i] == UI_ICON_TEXT) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
306 | column = gtk_tree_view_column_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
307 | gtk_tree_view_column_set_title(column, model->titles[i]); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
308 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
310 | GtkCellRenderer *textrenderer = gtk_cell_renderer_text_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
311 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | gtk_tree_view_column_pack_end(column, textrenderer, TRUE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | gtk_tree_view_column_pack_start(column, iconrenderer, FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
314 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
315 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
316 | gtk_tree_view_column_add_attribute(column, iconrenderer, "pixbuf", i); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
317 | gtk_tree_view_column_add_attribute(column, textrenderer, "text", i+1); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
318 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
319 | addi++; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | } else if (model->types[i] == UI_ICON) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | GtkCellRenderer *iconrenderer = gtk_cell_renderer_pixbuf_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
322 | column = gtk_tree_view_column_new_with_attributes( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
323 | model->titles[i], |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | iconrenderer, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
325 | "pixbuf", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
326 | i + addi, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
328 | } else { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
330 | column = gtk_tree_view_column_new_with_attributes( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
331 | model->titles[i], |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
332 | renderer, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
333 | "text", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
334 | i + addi, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
335 | NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
336 | } |
80
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
337 | |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
338 | int colsz = model->columnsize[i]; |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
339 | if(colsz > 0) { |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
340 | gtk_tree_view_column_set_fixed_width(column, colsz); |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
341 | } else if(colsz < 0) { |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
342 | gtk_tree_view_column_set_expand(column, TRUE); |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
343 | } |
1a908b060122
adjust browser columns
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
71
diff
changeset
|
344 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
345 | gtk_tree_view_column_set_resizable(column, TRUE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | //gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | #ifdef UI_GTK3 |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
351 | //gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(view), TRUE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | #else |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | #endif |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | UiList *list = var ? var->value : NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
359 | GtkListStore *listmodel = create_list_store(list, model); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(listmodel)); |
71
9e19ac687b9f
fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
361 | g_object_unref(listmodel); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | //g_signal_connect(view, "drag-begin", G_CALLBACK(drag_begin), NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | //g_signal_connect(view, "drag-end", G_CALLBACK(drag_end), NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | // add TreeView as observer to the UiList to update the TreeView if the |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | // data changes |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | UiListView *tableview = malloc(sizeof(UiListView)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | tableview->obj = obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | tableview->widget = view; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | tableview->var = var; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | tableview->model = model; |
90
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
373 | tableview->ondragstart = args.ondragstart; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
374 | tableview->ondragstartdata = args.ondragstartdata; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
375 | tableview->ondragcomplete = args.ondragcomplete; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
376 | tableview->ondragcompletedata = args.ondragcompletedata; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
377 | tableview->ondrop = args.ondrop; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
378 | tableview->ondropdata = args.ondropsdata; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | view, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | "destroy", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | G_CALLBACK(ui_listview_destroy), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | tableview); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | // bind var |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
386 | list->update = ui_listview_update; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | list->getselection = ui_listview_getselection; |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
388 | list->setselection = ui_listview_setselection; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | list->obj = tableview; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | // add callback |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | UiTreeEventData *event = ui_malloc(obj->ctx, sizeof(UiTreeEventData)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | event->obj = obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | event->activate = args.onactivate; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | event->selection = args.onselection; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | event->activatedata = args.onactivatedata; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | event->selectiondata = args.onselectiondata; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | if(args.onactivate) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
400 | view, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
401 | "row-activated", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
402 | G_CALLBACK(ui_listview_activate_event), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
403 | event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
404 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
405 | if(args.onselection) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
406 | GtkTreeSelection *selection = gtk_tree_view_get_selection( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
407 | GTK_TREE_VIEW(view)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
408 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
409 | selection, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
410 | "changed", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
411 | G_CALLBACK(ui_listview_selection_event), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
412 | event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
413 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
414 | // TODO: destroy callback |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | |
90
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
416 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
417 | if(args.ondragstart) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
418 | ui_listview_add_dnd(tableview, &args); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
419 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
420 | if(args.ondrop) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
421 | ui_listview_enable_drop(tableview, &args); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
422 | } |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
423 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
424 | GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view)); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
425 | if(args.multiselection) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
426 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
427 | } |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
428 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
429 | // add widget to the current container |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
430 | GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
431 | gtk_scrolled_window_set_policy( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
432 | GTK_SCROLLED_WINDOW(scroll_area), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
433 | GTK_POLICY_AUTOMATIC, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
434 | GTK_POLICY_AUTOMATIC); // GTK_POLICY_ALWAYS |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
435 | SCROLLEDWINDOW_SET_CHILD(scroll_area, view); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
436 | |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
437 | if(args.contextmenu) { |
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
438 | UIMENU menu = ui_contextmenu_create(args.contextmenu, obj, scroll_area); |
98
16e84fac48bd
in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
439 | #if GTK_MAJOR_VERSION >= 4 |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
440 | ui_widget_set_contextmenu(scroll_area, menu); |
98
16e84fac48bd
in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
441 | #else |
16e84fac48bd
in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
442 | ui_widget_set_contextmenu(view, menu); |
16e84fac48bd
in the repo list, show the stored-user if no user is configured
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
90
diff
changeset
|
443 | #endif |
88
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
444 | } |
e27526429d85
add context menu, implement 'Select All'
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
445 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
446 | UI_APPLY_LAYOUT1(current, args); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
447 | current->container->add(current->container, scroll_area, FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
448 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
449 | // ct->current should point to view, not scroll_area, to make it possible |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
450 | // to add a context menu |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
451 | current->container->current = view; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
452 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
453 | return scroll_area; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
454 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
455 | |
90
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
456 | #if GTK_MAJOR_VERSION >= 4 |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
457 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
458 | static GdkContentProvider *ui_listview_dnd_prepare(GtkDragSource *source, double x, double y, void *data) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
459 | //printf("drag prepare\n"); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
460 | UiListView *listview = data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
461 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
462 | UiDnD *dnd = ui_create_dnd(); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
463 | GdkContentProvider *provider = NULL; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
464 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
465 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
466 | if(listview->ondragstart) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
467 | UiEvent event; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
468 | event.obj = listview->obj; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
469 | event.window = event.obj->window; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
470 | event.document = event.obj->ctx->document; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
471 | event.eventdata = dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
472 | event.intval = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
473 | listview->ondragstart(&event, listview->ondragstartdata); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
474 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
475 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
476 | size_t numproviders = cxListSize(dnd->providers); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
477 | if(numproviders > 0) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
478 | GdkContentProvider **providers = (GdkContentProvider**)cxListAt(dnd->providers, 0); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
479 | provider = gdk_content_provider_new_union(providers, numproviders); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
480 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
481 | ui_dnd_free(dnd); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
482 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
483 | return provider; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
484 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
485 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
486 | static void ui_listview_drag_begin(GtkDragSource *self, GdkDrag *drag, gpointer userdata) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
487 | //printf("drag begin\n"); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
488 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
489 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
490 | static void ui_listview_drag_end(GtkDragSource *self, GdkDrag *drag, gboolean delete_data, gpointer user_data) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
491 | //printf("drag end\n"); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
492 | UiListView *listview = user_data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
493 | if(listview->ondragcomplete) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
494 | UiDnD dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
495 | dnd.target = NULL; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
496 | dnd.value = NULL; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
497 | dnd.providers = NULL; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
498 | dnd.selected_action = gdk_drag_get_selected_action(drag); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
499 | dnd.delete = delete_data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
500 | dnd.accept = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
501 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
502 | UiEvent event; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
503 | event.obj = listview->obj; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
504 | event.window = event.obj->window; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
505 | event.document = event.obj->ctx->document; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
506 | event.eventdata = &dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
507 | event.intval = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
508 | listview->ondragcomplete(&event, listview->ondragcompletedata); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
509 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
510 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
511 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
512 | static gboolean ui_listview_drop( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
513 | GtkDropTarget *target, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
514 | const GValue* value, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
515 | gdouble x, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
516 | gdouble y, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
517 | gpointer user_data) |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
518 | { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
519 | UiListView *listview = user_data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
520 | UiDnD dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
521 | dnd.providers = NULL; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
522 | dnd.target = target; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
523 | dnd.value = value; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
524 | dnd.selected_action = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
525 | dnd.delete = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
526 | dnd.accept = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
527 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
528 | if(listview->ondrop) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
529 | dnd.accept = TRUE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
530 | UiEvent event; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
531 | event.obj = listview->obj; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
532 | event.window = event.obj->window; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
533 | event.document = event.obj->ctx->document; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
534 | event.eventdata = &dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
535 | event.intval = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
536 | listview->ondrop(&event, listview->ondropdata); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
537 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
538 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
539 | return dnd.accept; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
540 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
541 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
542 | void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
543 | GtkDragSource *dragsource = gtk_drag_source_new(); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
544 | gtk_widget_add_controller(listview->widget, GTK_EVENT_CONTROLLER(dragsource)); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
545 | g_signal_connect (dragsource, "prepare", G_CALLBACK (ui_listview_dnd_prepare), listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
546 | g_signal_connect( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
547 | dragsource, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
548 | "drag-begin", |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
549 | G_CALLBACK(ui_listview_drag_begin), |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
550 | listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
551 | g_signal_connect( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
552 | dragsource, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
553 | "drag-end", |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
554 | G_CALLBACK(ui_listview_drag_end), |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
555 | listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
556 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
557 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
558 | void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
559 | GtkDropTarget *target = gtk_drop_target_new(G_TYPE_INVALID, GDK_ACTION_COPY); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
560 | gtk_widget_add_controller(listview->widget, GTK_EVENT_CONTROLLER(target)); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
561 | GType default_types[2] = { GDK_TYPE_FILE_LIST, G_TYPE_STRING }; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
562 | gtk_drop_target_set_gtypes(target, default_types, 2); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
563 | g_signal_connect(target, "drop", G_CALLBACK(ui_listview_drop), listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
564 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
565 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
566 | #else |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
567 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
568 | static GtkTargetEntry targetentries[] = |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
569 | { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
570 | { "STRING", 0, 0 }, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
571 | { "text/plain", 0, 1 }, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
572 | { "text/uri-list", 0, 2 }, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
573 | }; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
574 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
575 | static void ui_listview_drag_getdata( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
576 | GtkWidget* self, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
577 | GdkDragContext* context, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
578 | GtkSelectionData* data, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
579 | guint info, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
580 | guint time, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
581 | gpointer user_data) |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
582 | { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
583 | UiListView *listview = user_data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
584 | UiDnD dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
585 | dnd.context = context; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
586 | dnd.data = data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
587 | dnd.selected_action = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
588 | dnd.delete = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
589 | dnd.accept = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
590 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
591 | if(listview->ondragstart) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
592 | UiEvent event; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
593 | event.obj = listview->obj; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
594 | event.window = event.obj->window; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
595 | event.document = event.obj->ctx->document; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
596 | event.eventdata = &dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
597 | event.intval = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
598 | listview->ondragstart(&event, listview->ondragstartdata); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
599 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
600 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
601 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
602 | static void ui_listview_drag_end( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
603 | GtkWidget *widget, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
604 | GdkDragContext *context, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
605 | guint time, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
606 | gpointer user_data) |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
607 | { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
608 | UiListView *listview = user_data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
609 | UiDnD dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
610 | dnd.context = context; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
611 | dnd.data = NULL; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
612 | dnd.selected_action = gdk_drag_context_get_selected_action(context); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
613 | dnd.delete = dnd.selected_action == UI_DND_ACTION_MOVE ? TRUE : FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
614 | dnd.accept = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
615 | if(listview->ondragcomplete) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
616 | UiEvent event; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
617 | event.obj = listview->obj; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
618 | event.window = event.obj->window; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
619 | event.document = event.obj->ctx->document; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
620 | event.eventdata = &dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
621 | event.intval = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
622 | listview->ondragcomplete(&event, listview->ondragcompletedata); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
623 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
624 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
625 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
626 | void ui_listview_add_dnd(UiListView *listview, UiListArgs *args) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
627 | gtk_tree_view_enable_model_drag_source( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
628 | GTK_TREE_VIEW(listview->widget), |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
629 | GDK_BUTTON1_MASK, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
630 | targetentries, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
631 | 2, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
632 | GDK_ACTION_COPY); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
633 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
634 | g_signal_connect(listview->widget, "drag-data-get", G_CALLBACK(ui_listview_drag_getdata), listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
635 | g_signal_connect(listview->widget, "drag-end", G_CALLBACK(ui_listview_drag_end), listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
636 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
637 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
638 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
639 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
640 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
641 | static void ui_listview_drag_data_received( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
642 | GtkWidget *self, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
643 | GdkDragContext *context, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
644 | gint x, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
645 | gint y, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
646 | GtkSelectionData *data, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
647 | guint info, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
648 | guint time, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
649 | gpointer user_data) |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
650 | { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
651 | UiListView *listview = user_data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
652 | UiDnD dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
653 | dnd.context = context; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
654 | dnd.data = data; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
655 | dnd.selected_action = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
656 | dnd.delete = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
657 | dnd.accept = FALSE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
658 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
659 | if(listview->ondrop) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
660 | dnd.accept = TRUE; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
661 | UiEvent event; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
662 | event.obj = listview->obj; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
663 | event.window = event.obj->window; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
664 | event.document = event.obj->ctx->document; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
665 | event.eventdata = &dnd; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
666 | event.intval = 0; |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
667 | listview->ondrop(&event, listview->ondropdata); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
668 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
669 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
670 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
671 | void ui_listview_enable_drop(UiListView *listview, UiListArgs *args) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
672 | gtk_tree_view_enable_model_drag_dest( |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
673 | GTK_TREE_VIEW(listview->widget), |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
674 | targetentries, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
675 | 3, |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
676 | GDK_ACTION_COPY); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
677 | if(listview->ondrop) { |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
678 | g_signal_connect(listview->widget, "drag_data_received", G_CALLBACK(ui_listview_drag_data_received), listview); |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
679 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
680 | } |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
681 | |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
682 | #endif |
f501f0efc9a8
implement gtk dnd
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
88
diff
changeset
|
683 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
684 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
685 | GtkWidget* ui_get_tree_widget(UIWIDGET widget) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
686 | return SCROLLEDWINDOW_GET_CHILD(widget); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
687 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
688 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
689 | static char** targets2array(char *target0, va_list ap, int *nelm) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
690 | int al = 16; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
691 | char **targets = calloc(16, sizeof(char*)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
692 | targets[0] = target0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
693 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
694 | int i = 1; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
695 | char *target; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
696 | while((target = va_arg(ap, char*)) != NULL) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
697 | if(i >= al) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
698 | al *= 2; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
699 | targets = realloc(targets, al*sizeof(char*)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
700 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
701 | targets[i] = target; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
702 | i++; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
703 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
704 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
705 | *nelm = i; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
706 | return targets; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
707 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
708 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
709 | /* |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
710 | static GtkTargetEntry* targetstr2gtktargets(char **str, int nelm) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
711 | GtkTargetEntry *targets = calloc(nelm, sizeof(GtkTargetEntry)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
712 | for(int i=0;i<nelm;i++) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
713 | targets[i].target = str[i]; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
714 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
715 | return targets; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
716 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
717 | */ |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
718 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
719 | void ui_table_dragsource(UIWIDGET tablewidget, int actions, char *target0, ...) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
720 | va_list ap; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
721 | va_start(ap, target0); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
722 | int nelm; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
723 | char **targets = targets2array(target0, ap, &nelm); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
724 | va_end(ap); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
725 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
726 | // disabled |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
727 | //ui_table_dragsource_a(tablewidget, actions, targets, nelm); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
728 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
729 | free(targets); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
730 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
731 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
732 | /* |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
733 | void ui_table_dragsource_a(UIWIDGET tablewidget, int actions, char **targets, int nelm) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
734 | GtkTargetEntry* t = targetstr2gtktargets(targets, nelm); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
735 | gtk_tree_view_enable_model_drag_source( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
736 | GTK_TREE_VIEW(ui_get_tree_widget(tablewidget)), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
737 | GDK_BUTTON1_MASK, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
738 | t, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
739 | nelm, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
740 | GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_LINK); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
741 | free(t); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
742 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
743 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
744 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
745 | void ui_table_dragdest(UIWIDGET tablewidget, int actions, char *target0, ...) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
746 | va_list ap; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
747 | va_start(ap, target0); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
748 | int nelm; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
749 | char **targets = targets2array(target0, ap, &nelm); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
750 | va_end(ap); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
751 | ui_table_dragdest_a(tablewidget, actions, targets, nelm); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
752 | free(targets); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
753 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
754 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
755 | void ui_table_dragdest_a(UIWIDGET tablewidget, int actions, char **targets, int nelm) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
756 | GtkTargetEntry* t = targetstr2gtktargets(targets, nelm); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
757 | gtk_tree_view_enable_model_drag_dest( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
758 | GTK_TREE_VIEW(ui_get_tree_widget(tablewidget)), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
759 | t, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
760 | nelm, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
761 | GDK_ACTION_COPY|GDK_ACTION_MOVE|GDK_ACTION_LINK); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
762 | free(t); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
763 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
764 | */ |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
765 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
766 | void ui_listview_update(UiList *list, int i) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
767 | UiListView *view = list->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
768 | GtkListStore *store = create_list_store(list, view->model); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
769 | gtk_tree_view_set_model(GTK_TREE_VIEW(view->widget), GTK_TREE_MODEL(store)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
770 | g_object_unref(G_OBJECT(store)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
771 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
772 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
773 | UiListSelection ui_listview_getselection(UiList *list) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
774 | UiListView *view = list->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
775 | UiListSelection selection = ui_listview_selection( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
776 | gtk_tree_view_get_selection(GTK_TREE_VIEW(view->widget)), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
777 | NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
778 | return selection; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
779 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
780 | |
65
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
781 | void ui_listview_setselection(UiList *list, UiListSelection selection) { |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
782 | UiListView *view = list->obj; |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
783 | GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view->widget)); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
784 | GtkTreePath *path = gtk_tree_path_new_from_indicesv(selection.rows, selection.count); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
785 | gtk_tree_selection_select_path(sel, path); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
786 | //g_object_unref(path); |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
787 | } |
48f43130b4a2
implement UI for credentials settings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
60
diff
changeset
|
788 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
789 | void ui_listview_destroy(GtkWidget *w, UiListView *v) { |
71
9e19ac687b9f
fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
790 | //gtk_tree_view_set_model(GTK_TREE_VIEW(w), NULL); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
791 | ui_destroy_boundvar(v->obj->ctx, v->var); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
792 | free(v); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
793 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
794 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
795 | void ui_combobox_destroy(GtkWidget *w, UiListView *v) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
796 | ui_destroy_boundvar(v->obj->ctx, v->var); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
797 | free(v); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
798 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
799 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
800 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
801 | void ui_listview_activate_event( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
802 | GtkTreeView *treeview, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
803 | GtkTreePath *path, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
804 | GtkTreeViewColumn *column, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
805 | UiTreeEventData *event) |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
806 | { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
807 | UiListSelection selection = ui_listview_selection( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
808 | gtk_tree_view_get_selection(treeview), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
809 | event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
810 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
811 | UiEvent e; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
812 | e.obj = event->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
813 | e.window = event->obj->window; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
814 | e.document = event->obj->ctx->document; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
815 | e.eventdata = &selection; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
816 | e.intval = selection.count > 0 ? selection.rows[0] : -1; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
817 | event->activate(&e, event->activatedata); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
818 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
819 | if(selection.count > 0) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
820 | free(selection.rows); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
821 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
822 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
823 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
824 | void ui_listview_selection_event( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
825 | GtkTreeSelection *treeselection, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
826 | UiTreeEventData *event) |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
827 | { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
828 | UiListSelection selection = ui_listview_selection(treeselection, event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
829 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
830 | UiEvent e; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
831 | e.obj = event->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
832 | e.window = event->obj->window; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
833 | e.document = event->obj->ctx->document; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
834 | e.eventdata = &selection; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
835 | e.intval = selection.count > 0 ? selection.rows[0] : -1; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
836 | event->selection(&e, event->selectiondata); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
837 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
838 | if(selection.count > 0) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
839 | free(selection.rows); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
840 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
841 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
842 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
843 | UiListSelection ui_listview_selection( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
844 | GtkTreeSelection *selection, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
845 | UiTreeEventData *event) |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
846 | { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
847 | GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
848 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
849 | UiListSelection ls; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
850 | ls.count = g_list_length(rows); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
851 | ls.rows = calloc(ls.count, sizeof(int)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
852 | GList *r = rows; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
853 | int i = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
854 | while(r) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
855 | GtkTreePath *path = r->data; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
856 | ls.rows[i] = ui_tree_path_list_index(path); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
857 | r = r->next; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
858 | i++; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
859 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
860 | return ls; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
861 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
862 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
863 | int ui_tree_path_list_index(GtkTreePath *path) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
864 | int depth = gtk_tree_path_get_depth(path); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
865 | if(depth == 0) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
866 | fprintf(stderr, "UiError: treeview selection: depth == 0\n"); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
867 | return -1; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
868 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
869 | int *indices = gtk_tree_path_get_indices(path); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
870 | return indices[depth - 1]; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
871 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
872 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
873 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
874 | /* --------------------------- ComboBox --------------------------- */ |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
875 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
876 | UIWIDGET ui_combobox_create(UiObject *obj, UiListArgs args) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
877 | UiObject* current = uic_current_obj(obj); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
878 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
879 | UiModel *model = ui_model(obj->ctx, UI_STRING, "", -1); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
880 | model->getvalue = args.getvalue ? args.getvalue : ui_strmodel_getvalue; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
881 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
882 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
883 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
884 | GtkWidget *combobox = ui_create_combobox(obj, model, var, args.onactivate, args.onactivatedata); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
885 | ui_set_name_and_style(combobox, args.name, args.style_class); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
886 | ui_set_widget_groups(obj->ctx, combobox, args.groups); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
887 | UI_APPLY_LAYOUT1(current, args); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
888 | current->container->add(current->container, combobox, FALSE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
889 | current->container->current = combobox; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
890 | return combobox; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
891 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
892 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
893 | GtkWidget* ui_create_combobox(UiObject *obj, UiModel *model, UiVar *var, ui_callback f, void *udata) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
894 | GtkWidget *combobox = gtk_combo_box_new(); |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
895 | |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
896 | UiListView *uicbox = malloc(sizeof(UiListView)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
897 | uicbox->obj = obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
898 | uicbox->widget = combobox; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
899 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
900 | UiList *list = var ? var->value : NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
901 | GtkListStore *listmodel = create_list_store(list, model); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
902 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
903 | if(listmodel) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
904 | gtk_combo_box_set_model(GTK_COMBO_BOX(combobox), GTK_TREE_MODEL(listmodel)); |
71
9e19ac687b9f
fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
905 | g_object_unref(listmodel); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
906 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
907 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
908 | uicbox->var = var; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
909 | uicbox->model = model; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
910 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
911 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
912 | combobox, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
913 | "destroy", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
914 | G_CALLBACK(ui_combobox_destroy), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
915 | uicbox); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
916 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
917 | // bind var |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
918 | if(list) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
919 | list->update = ui_combobox_modelupdate; |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
920 | list->getselection = ui_combobox_getselection; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
921 | list->setselection = ui_combobox_setselection; |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
922 | list->obj = uicbox; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
923 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
924 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
925 | GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
926 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, TRUE); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
927 | gtk_cell_layout_set_attributes( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
928 | GTK_CELL_LAYOUT(combobox), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
929 | renderer, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
930 | "text", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
931 | 0, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
932 | NULL); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
933 | gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
934 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
935 | // add callback |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
936 | if(f) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
937 | UiEventData *event = ui_malloc(obj->ctx, sizeof(UiEventData)); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
938 | event->obj = obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
939 | event->userdata = udata; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
940 | event->callback = f; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
941 | event->value = 0; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
942 | event->customdata = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
943 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
944 | g_signal_connect( |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
945 | combobox, |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
946 | "changed", |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
947 | G_CALLBACK(ui_combobox_change_event), |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
948 | event); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
949 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
950 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
951 | return combobox; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
952 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
953 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
954 | void ui_combobox_change_event(GtkComboBox *widget, UiEventData *e) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
955 | UiEvent event; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
956 | event.obj = e->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
957 | event.window = event.obj->window; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
958 | event.document = event.obj->ctx->document; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
959 | event.eventdata = NULL; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
960 | event.intval = gtk_combo_box_get_active(widget); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
961 | e->callback(&event, e->userdata); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
962 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
963 | |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
964 | void ui_combobox_modelupdate(UiList *list, int i) { |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
965 | UiListView *view = list->obj; |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
966 | GtkListStore *store = create_list_store(view->var->value, view->model); |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
967 | gtk_combo_box_set_model(GTK_COMBO_BOX(view->widget), GTK_TREE_MODEL(store)); |
71
9e19ac687b9f
fix crash when closing the preferences window (GTK3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
968 | g_object_unref(store); |
46
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
969 | } |
31bc86844659
implement action_newfile
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
970 | |
60
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
971 | UiListSelection ui_combobox_getselection(UiList *list) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
972 | UiListView *combobox = list->obj; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
973 | UiListSelection ret; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
974 | ret.rows = malloc(sizeof(int*)); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
975 | ret.count = 1; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
976 | ret.rows[0] = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox->widget)); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
977 | return ret; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
978 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
979 | |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
980 | void ui_combobox_setselection(UiList *list, UiListSelection selection) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
981 | UiListView *combobox = list->obj; |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
982 | if(selection.count > 0) { |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
983 | gtk_combo_box_set_active(GTK_COMBO_BOX(combobox->widget), selection.rows[0]); |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
984 | } |
ee4e4742391e
add settings window and implement repository editing
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
51
diff
changeset
|
985 | } |
100 | 986 | |
987 | ||
988 | /* ------------------------------ Source List ------------------------------ */ | |
989 | ||
990 | static void ui_destroy_sourcelist(GtkWidget *w, UiListBox *v) { | |
991 | cxListDestroy(v->sublists); | |
992 | free(v); | |
993 | } | |
994 | ||
995 | static void sublist_destroy(UiObject *obj, UiListBoxSubList *sublist) { | |
996 | free(sublist->header); | |
997 | ui_destroy_boundvar(obj->ctx, sublist->var); | |
998 | cxListDestroy(sublist->widgets); | |
999 | } | |
1000 | ||
1001 | static void listbox_create_header(GtkListBoxRow* row, GtkListBoxRow* before, gpointer user_data) { | |
1002 | // first rows in sublists have the ui_listbox property | |
1003 | UiListBox *listbox = g_object_get_data(G_OBJECT(row), "ui_listbox"); | |
1004 | if(!listbox) { | |
1005 | return; | |
1006 | } | |
1007 | ||
1008 | UiListBoxSubList *sublist = g_object_get_data(G_OBJECT(row), "ui_listbox_sublist"); | |
1009 | if(!sublist) { | |
1010 | return; | |
1011 | } | |
1012 | ||
1013 | if(sublist->separator) { | |
1014 | GtkWidget *separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); | |
1015 | gtk_list_box_row_set_header(row, separator); | |
1016 | } else if(sublist->header) { | |
1017 | GtkWidget *header = gtk_label_new(sublist->header); | |
1018 | gtk_widget_set_halign(header, GTK_ALIGN_START); | |
1019 | if(row == listbox->first_row) { | |
1020 | WIDGET_ADD_CSS_CLASS(header, "ui-listbox-header-first"); | |
1021 | } else { | |
1022 | WIDGET_ADD_CSS_CLASS(header, "ui-listbox-header"); | |
1023 | } | |
1024 | gtk_list_box_row_set_header(row, header); | |
1025 | } | |
1026 | } | |
1027 | ||
1028 | #ifdef UI_GTK3 | |
1029 | typedef struct _UiSidebarListBoxClass { | |
1030 | GtkListBoxClass parent_class; | |
1031 | } UiSidebarListBoxClass; | |
1032 | ||
1033 | typedef struct _UiSidebarListBox { | |
1034 | GtkListBox parent_instance; | |
1035 | } UiSidebarListBox; | |
1036 | ||
1037 | G_DEFINE_TYPE(UiSidebarListBox, ui_sidebar_list_box, GTK_TYPE_LIST_BOX) | |
1038 | ||
1039 | /* Initialize the instance */ | |
1040 | static void ui_sidebar_list_box_class_init(UiSidebarListBoxClass *klass) { | |
1041 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); | |
1042 | gtk_widget_class_set_css_name (widget_class, "placessidebar"); | |
1043 | } | |
1044 | ||
1045 | static void ui_sidebar_list_box_init(UiSidebarListBox *self) { | |
1046 | ||
1047 | } | |
1048 | #endif | |
1049 | ||
1050 | UIEXPORT UIWIDGET ui_sourcelist_create(UiObject *obj, UiSourceListArgs args) { | |
1051 | UiObject* current = uic_current_obj(obj); | |
1052 | ||
1053 | #ifdef UI_GTK3 | |
1054 | GtkWidget *listbox = g_object_new(ui_sidebar_list_box_get_type(), NULL); | |
1055 | #else | |
1056 | GtkWidget *listbox = gtk_list_box_new(); | |
1057 | #endif | |
1058 | if(!args.style_class) { | |
1059 | #if GTK_MAJOR_VERSION >= 4 | |
1060 | WIDGET_ADD_CSS_CLASS(listbox, "navigation-sidebar"); | |
1061 | #else | |
1062 | WIDGET_ADD_CSS_CLASS(listbox, "sidebar"); | |
1063 | #endif | |
1064 | } | |
1065 | gtk_list_box_set_header_func(GTK_LIST_BOX(listbox), listbox_create_header, NULL, NULL); | |
1066 | GtkWidget *scroll_area = SCROLLEDWINDOW_NEW(); | |
1067 | SCROLLEDWINDOW_SET_CHILD(scroll_area, listbox); | |
1068 | ||
1069 | ui_set_name_and_style(listbox, args.name, args.style_class); | |
1070 | ui_set_widget_groups(obj->ctx, listbox, args.groups); | |
1071 | UI_APPLY_LAYOUT1(current, args); | |
1072 | current->container->add(current->container, scroll_area, TRUE); | |
1073 | ||
1074 | UiListBox *uilistbox = malloc(sizeof(UiListBox)); | |
1075 | uilistbox->obj = obj; | |
1076 | uilistbox->listbox = GTK_LIST_BOX(listbox); | |
1077 | uilistbox->getvalue = args.getvalue; | |
1078 | uilistbox->onactivate = args.onactivate; | |
1079 | uilistbox->onactivatedata = args.onactivatedata; | |
1080 | uilistbox->onbuttonclick = args.onbuttonclick; | |
1081 | uilistbox->onbuttonclickdata = args.onbuttonclickdata; | |
1082 | uilistbox->sublists = cxArrayListCreateSimple(sizeof(UiListBoxSubList), 4); | |
1083 | uilistbox->sublists->collection.advanced_destructor = (cx_destructor_func2)sublist_destroy; | |
1084 | uilistbox->sublists->collection.destructor_data = obj; | |
1085 | uilistbox->first_row = NULL; | |
1086 | ||
1087 | if(args.numsublists == 0 && args.sublists) { | |
1088 | args.numsublists = INT_MAX; | |
1089 | } | |
1090 | for(int i=0;i<args.numsublists;i++) { | |
1091 | UiSubList sublist = args.sublists[i]; | |
1092 | if(!sublist.varname && !sublist.value) { | |
1093 | break; | |
1094 | } | |
1095 | ||
1096 | UiListBoxSubList uisublist; | |
1097 | uisublist.var = uic_widget_var( | |
1098 | obj->ctx, | |
1099 | current->ctx, | |
1100 | sublist.value, | |
1101 | sublist.varname, | |
1102 | UI_VAR_LIST); | |
1103 | uisublist.numitems = 0; | |
1104 | uisublist.header = sublist.header ? strdup(sublist.header) : NULL; | |
1105 | uisublist.separator = sublist.separator; | |
1106 | uisublist.widgets = cxLinkedListCreateSimple(CX_STORE_POINTERS); | |
1107 | uisublist.listbox = uilistbox; | |
1108 | uisublist.userdata = sublist.userdata; | |
1109 | uisublist.index = i; | |
1110 | ||
1111 | cxListAdd(uilistbox->sublists, &uisublist); | |
1112 | ||
1113 | // bind UiList | |
1114 | UiListBoxSubList *sublist_ptr = cxListAt(uilistbox->sublists, cxListSize(uilistbox->sublists)-1); | |
1115 | UiList *list = uisublist.var->value; | |
1116 | if(list) { | |
1117 | list->obj = sublist_ptr; | |
1118 | list->update = ui_listbox_list_update; | |
1119 | } | |
1120 | } | |
1121 | // fill items | |
1122 | ui_listbox_update(uilistbox, 0, cxListSize(uilistbox->sublists)); | |
1123 | ||
1124 | // register uilistbox for both widgets, so it doesn't matter which | |
1125 | // widget is used later | |
1126 | g_object_set_data(G_OBJECT(scroll_area), "ui_listbox", uilistbox); | |
1127 | g_object_set_data(G_OBJECT(listbox), "ui_listbox", uilistbox); | |
1128 | ||
1129 | // signals | |
1130 | g_signal_connect( | |
1131 | listbox, | |
1132 | "destroy", | |
1133 | G_CALLBACK(ui_destroy_sourcelist), | |
1134 | uilistbox); | |
1135 | ||
1136 | if(args.onactivate) { | |
1137 | g_signal_connect( | |
1138 | listbox, | |
1139 | "row-activated", | |
1140 | G_CALLBACK(ui_listbox_row_activate), | |
1141 | NULL); | |
1142 | } | |
1143 | ||
1144 | return scroll_area; | |
1145 | } | |
1146 | ||
1147 | void ui_listbox_update(UiListBox *listbox, int from, int to) { | |
1148 | CxIterator i = cxListIterator(listbox->sublists); | |
1149 | size_t pos = 0; | |
1150 | cx_foreach(UiListBoxSubList *, sublist, i) { | |
1151 | if(i.index < from) { | |
1152 | pos += sublist->numitems; | |
1153 | continue; | |
1154 | } | |
1155 | if(i.index > to) { | |
1156 | break; | |
1157 | } | |
1158 | ||
1159 | // reload sublist | |
1160 | ui_listbox_update_sublist(listbox, sublist, pos); | |
1161 | pos += sublist->numitems; | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | static GtkWidget* create_listbox_row(UiListBox *listbox, UiListBoxSubList *sublist, UiSubListItem *item, int index) { | |
1166 | GtkWidget *hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10); | |
1167 | if(item->icon) { | |
1168 | GtkWidget *icon = ICON_IMAGE(item->icon); | |
1169 | BOX_ADD(hbox, icon); | |
1170 | } | |
1171 | GtkWidget *label = gtk_label_new(item->label); | |
1172 | gtk_widget_set_halign(label, GTK_ALIGN_START); | |
1173 | BOX_ADD_EXPAND(hbox, label); | |
1174 | // TODO: badge, button | |
1175 | GtkWidget *row = gtk_list_box_row_new(); | |
1176 | LISTBOX_ROW_SET_CHILD(row, hbox); | |
1177 | ||
1178 | // signals | |
1179 | UiEventDataExt *event = malloc(sizeof(UiEventDataExt)); | |
1180 | memset(event, 0, sizeof(UiEventDataExt)); | |
1181 | event->obj = listbox->obj; | |
1182 | event->customdata0 = sublist; | |
1183 | event->customdata1 = sublist->var; | |
1184 | event->customdata2 = item->eventdata; | |
1185 | event->callback = listbox->onactivate; | |
1186 | event->userdata = listbox->onactivatedata; | |
1187 | event->callback2 = listbox->onbuttonclick; | |
1188 | event->userdata2 = listbox->onbuttonclickdata; | |
1189 | event->value0 = index; | |
1190 | ||
1191 | g_signal_connect( | |
1192 | row, | |
1193 | "destroy", | |
1194 | G_CALLBACK(ui_destroy_userdata), | |
1195 | event); | |
1196 | ||
1197 | g_object_set_data(G_OBJECT(row), "ui-listbox-row-eventdata", event); | |
1198 | ||
1199 | return row; | |
1200 | } | |
1201 | ||
1202 | void ui_listbox_update_sublist(UiListBox *listbox, UiListBoxSubList *sublist, size_t listbox_insert_index) { | |
1203 | // clear sublist | |
1204 | CxIterator r = cxListIterator(sublist->widgets); | |
1205 | cx_foreach(GtkWidget*, widget, r) { | |
1206 | LISTBOX_REMOVE(listbox->listbox, widget); | |
1207 | } | |
1208 | cxListClear(sublist->widgets); | |
1209 | ||
1210 | sublist->numitems = 0; | |
1211 | ||
1212 | // create items for each UiList element | |
1213 | UiList *list = sublist->var->value; | |
1214 | if(!list) { | |
1215 | return; | |
1216 | } | |
1217 | ||
1218 | size_t index = 0; | |
1219 | void *elm = list->first(list); | |
1220 | while(elm) { | |
1221 | UiSubListItem item = { NULL, NULL, NULL, NULL, NULL, NULL }; | |
1222 | listbox->getvalue(sublist->userdata, elm, index, &item); | |
1223 | ||
1224 | // create listbox item | |
1225 | GtkWidget *row = create_listbox_row(listbox, sublist, &item, (int)index); | |
1226 | if(index == 0) { | |
1227 | // first row in the sublist, set ui_listbox data to the row | |
1228 | // which is then used by the headerfunc | |
1229 | g_object_set_data(G_OBJECT(row), "ui_listbox", listbox); | |
1230 | g_object_set_data(G_OBJECT(row), "ui_listbox_sublist", sublist); | |
1231 | ||
1232 | if(listbox_insert_index == 0) { | |
1233 | // first row in the GtkListBox | |
1234 | listbox->first_row = GTK_LIST_BOX_ROW(row); | |
1235 | } | |
1236 | } | |
1237 | intptr_t rowindex = listbox_insert_index + index; | |
1238 | g_object_set_data(G_OBJECT(row), "ui_listbox_row_index", (gpointer)rowindex); | |
1239 | gtk_list_box_insert(listbox->listbox, row, listbox_insert_index + index); | |
1240 | cxListAdd(sublist->widgets, row); | |
1241 | ||
1242 | // cleanup | |
1243 | free(item.label); | |
1244 | free(item.icon); | |
1245 | free(item.button_label); | |
1246 | free(item.button_icon); | |
1247 | free(item.badge); | |
1248 | ||
1249 | // next row | |
1250 | elm = list->next(list); | |
1251 | index++; | |
1252 | } | |
1253 | ||
1254 | sublist->numitems = cxListSize(sublist->widgets); | |
1255 | } | |
1256 | ||
1257 | void ui_listbox_list_update(UiList *list, int i) { | |
1258 | UiListBoxSubList *sublist = list->obj; | |
1259 | } | |
1260 | ||
1261 | void ui_listbox_row_activate(GtkListBox *self, GtkListBoxRow *row, gpointer user_data) { | |
1262 | UiEventDataExt *data = g_object_get_data(G_OBJECT(row), "ui-listbox-row-eventdata"); | |
1263 | if(!data) { | |
1264 | return; | |
1265 | } | |
1266 | UiListBoxSubList *sublist = data->customdata0; | |
1267 | ||
1268 | UiEvent event; | |
1269 | event.obj = data->obj; | |
1270 | event.window = event.obj->window; | |
1271 | event.document = event.obj->ctx->document; | |
1272 | event.eventdata = data->customdata2; | |
1273 | event.intval = data->value0; | |
1274 | ||
1275 | if(data->callback) { | |
1276 | data->callback(&event, data->userdata); | |
1277 | } | |
1278 | } |