Mercurial > geeqie
annotate src/bar_keywords.c @ 1456:b24391991f7f
improved expanding and hiding of helper keywords
author | nadvornik |
---|---|
date | Tue, 17 Mar 2009 18:58:15 +0000 |
parents | 2545780d4779 |
children | e015b6573d36 |
rev | line source |
---|---|
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1 /* |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
2 * Geeqie |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
3 * (C) 2004 John Ellis |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
4 * Copyright (C) 2008 - 2009 The Geeqie Team |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
5 * |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
6 * Author: John Ellis |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
7 * |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
8 * This software is released under the GNU General Public License (GNU GPL). |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
9 * Please read the included file COPYING for more information. |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
10 * This software comes with no warranty of any kind, use at your own risk! |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
11 */ |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
12 |
1305 | 13 #include <glib/gprintf.h> |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
14 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
15 #include "main.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
16 #include "bar_keywords.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
17 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
18 #include "filedata.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
19 #include "history_list.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
20 #include "metadata.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
21 #include "misc.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
22 #include "ui_fileops.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
23 #include "ui_misc.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
24 #include "ui_utildlg.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
25 #include "utilops.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
26 #include "bar.h" |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
27 #include "ui_menu.h" |
1309 | 28 #include "rcfile.h" |
1387 | 29 #include "layout.h" |
1392 | 30 #include "dnd.h" |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
31 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
32 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
33 static void bar_pane_keywords_keyword_update_all(void); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
34 static void bar_pane_keywords_changed(GtkTextBuffer *buffer, gpointer data); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
35 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
36 /* |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
37 *------------------------------------------------------------------- |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
38 * keyword / comment utils |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
39 *------------------------------------------------------------------- |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
40 */ |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
41 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
42 |
1292
4a3ae0e6f1eb
droped Preferences dialog, sidebar should replace it completely
nadvornik
parents:
1291
diff
changeset
|
43 GList *keyword_list_pull(GtkWidget *text_widget) |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
44 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
45 GList *list; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
46 gchar *text; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
47 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
48 text = text_widget_text_pull(text_widget); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
49 list = string_to_keywords_list(text); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
50 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
51 g_free(text); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
52 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
53 return list; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
54 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
55 |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
56 /* the "changed" signal should be blocked before calling this */ |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
57 static void keyword_list_push(GtkWidget *textview, GList *list) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
58 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
59 GtkTextBuffer *buffer; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
60 GtkTextIter start, end; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
61 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
62 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
63 gtk_text_buffer_get_bounds(buffer, &start, &end); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
64 gtk_text_buffer_delete(buffer, &start, &end); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
65 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
66 while (list) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
67 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
68 const gchar *word = list->data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
69 GtkTextIter iter; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
70 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
71 gtk_text_buffer_get_end_iter(buffer, &iter); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
72 if (word) gtk_text_buffer_insert(buffer, &iter, word, -1); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
73 gtk_text_buffer_get_end_iter(buffer, &iter); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
74 gtk_text_buffer_insert(buffer, &iter, "\n", -1); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
75 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
76 list = list->next; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
77 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
78 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
79 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
80 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
81 /* |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
82 *------------------------------------------------------------------- |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
83 * info bar |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
84 *------------------------------------------------------------------- |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
85 */ |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
86 |
1391 | 87 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
88 enum { |
1391 | 89 FILTER_KEYWORD_COLUMN_TOGGLE = 0, |
90 FILTER_KEYWORD_COLUMN_MARK, | |
91 FILTER_KEYWORD_COLUMN_NAME, | |
92 FILTER_KEYWORD_COLUMN_IS_KEYWORD, | |
93 FILTER_KEYWORD_COLUMN_COUNT | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
94 }; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
95 |
1391 | 96 static GType filter_keyword_column_types[] = {G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN}; |
97 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
98 typedef struct _PaneKeywordsData PaneKeywordsData; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
99 struct _PaneKeywordsData |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
100 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
101 PaneData pane; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
102 GtkWidget *widget; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
103 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
104 GtkWidget *keyword_view; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
105 GtkWidget *keyword_treeview; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
106 |
1414 | 107 GtkTreePath *click_tpath; |
108 | |
1428 | 109 gboolean expand_checked; |
110 gboolean collapse_unchecked; | |
111 gboolean hide_unchecked; | |
1455 | 112 |
113 gint idle_id; | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
114 FileData *fd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
115 gchar *key; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
116 }; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
117 |
1421 | 118 typedef struct _ConfDialogData ConfDialogData; |
119 struct _ConfDialogData | |
120 { | |
121 PaneKeywordsData *pkd; | |
122 GtkTreePath *click_tpath; | |
123 | |
124 /* dialog parts */ | |
125 GenericDialog *gd; | |
126 GtkWidget *edit_widget; | |
127 gboolean is_keyword; | |
128 | |
129 gboolean edit_existing; | |
130 }; | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
131 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
132 static GList *bar_list = NULL; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
133 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
134 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
135 static void bar_pane_keywords_write(PaneKeywordsData *pkd) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
136 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
137 GList *list; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
138 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
139 if (!pkd->fd) return; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
140 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
141 list = keyword_list_pull(pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
142 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
143 metadata_write_list(pkd->fd, KEYWORD_KEY, list); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
144 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
145 string_list_free(list); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
146 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
147 |
1428 | 148 gboolean bar_keyword_tree_expand_if_set_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
149 { |
1391 | 150 PaneKeywordsData *pkd = data; |
151 gboolean set; | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
152 |
1391 | 153 gtk_tree_model_get(model, iter, FILTER_KEYWORD_COLUMN_TOGGLE, &set, -1); |
154 | |
155 if (set && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(pkd->keyword_treeview), path)) | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
156 { |
1391 | 157 gtk_tree_view_expand_to_path(GTK_TREE_VIEW(pkd->keyword_treeview), path); |
158 } | |
159 return FALSE; | |
160 } | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
161 |
1428 | 162 gboolean bar_keyword_tree_collapse_if_unset_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) |
163 { | |
164 PaneKeywordsData *pkd = data; | |
165 gboolean set; | |
166 | |
1456
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1455
diff
changeset
|
167 gtk_tree_model_get(model, iter, FILTER_KEYWORD_COLUMN_TOGGLE, &set, -1); |
1428 | 168 |
1456
b24391991f7f
improved expanding and hiding of helper keywords
nadvornik
parents:
1455
diff
changeset
|
169 if (!set && gtk_tree_view_row_expanded(GTK_TREE_VIEW(pkd->keyword_treeview), path)) |
1428 | 170 { |
171 gtk_tree_view_collapse_row(GTK_TREE_VIEW(pkd->keyword_treeview), path); | |
172 } | |
173 return FALSE; | |
174 } | |
175 | |
1391 | 176 static void bar_keyword_tree_sync(PaneKeywordsData *pkd) |
177 { | |
1428 | 178 GtkTreeModel *model; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
179 |
1428 | 180 GtkTreeModel *keyword_tree; |
181 GList *keywords; | |
182 | |
183 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
184 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
1391 | 185 |
1428 | 186 keywords = keyword_list_pull(pkd->keyword_view); |
187 keyword_show_set_in(GTK_TREE_STORE(keyword_tree), model, keywords); | |
188 if (pkd->hide_unchecked) keyword_hide_unset_in(GTK_TREE_STORE(keyword_tree), model, keywords); | |
189 string_list_free(keywords); | |
190 | |
191 gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(model)); | |
192 | |
193 if (pkd->expand_checked) gtk_tree_model_foreach(model, bar_keyword_tree_expand_if_set_cb, pkd); | |
194 if (pkd->collapse_unchecked) gtk_tree_model_foreach(model, bar_keyword_tree_collapse_if_unset_cb, pkd); | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
195 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
196 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
197 static void bar_pane_keywords_keyword_update_all(void) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
198 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
199 GList *work; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
200 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
201 work = bar_list; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
202 while (work) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
203 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
204 PaneKeywordsData *pkd; |
1391 | 205 // GList *keywords; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
206 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
207 pkd = work->data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
208 work = work->next; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
209 |
1391 | 210 bar_keyword_tree_sync(pkd); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
211 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
212 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
213 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
214 static void bar_pane_keywords_update(PaneKeywordsData *pkd) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
215 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
216 GList *keywords = NULL; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
217 GtkTextBuffer *keyword_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pkd->keyword_view)); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
218 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
219 g_signal_handlers_block_by_func(keyword_buffer, bar_pane_keywords_changed, pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
220 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
221 keywords = metadata_read_list(pkd->fd, KEYWORD_KEY, METADATA_PLAIN); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
222 keyword_list_push(pkd->keyword_view, keywords); |
1391 | 223 bar_keyword_tree_sync(pkd); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
224 string_list_free(keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
225 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
226 g_signal_handlers_unblock_by_func(keyword_buffer, bar_pane_keywords_changed, pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
227 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
228 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
229 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
230 void bar_pane_keywords_set_fd(GtkWidget *pane, FileData *fd) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
231 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
232 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
233 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
234 pkd = g_object_get_data(G_OBJECT(pane), "pane_data"); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
235 if (!pkd) return; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
236 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
237 file_data_unref(pkd->fd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
238 pkd->fd = file_data_ref(fd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
239 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
240 bar_pane_keywords_update(pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
241 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
242 |
1309 | 243 static void bar_pane_keywords_write_config(GtkWidget *pane, GString *outstr, gint indent) |
244 { | |
245 PaneKeywordsData *pkd; | |
246 | |
247 pkd = g_object_get_data(G_OBJECT(pane), "pane_data"); | |
248 if (!pkd) return; | |
249 | |
1314 | 250 WRITE_STRING("<pane_keywords\n"); |
1309 | 251 indent++; |
1343 | 252 write_char_option(outstr, indent, "pane.title", gtk_label_get_text(GTK_LABEL(pkd->pane.title))); |
1309 | 253 WRITE_BOOL(*pkd, pane.expanded); |
254 WRITE_CHAR(*pkd, key); | |
255 indent--; | |
1314 | 256 WRITE_STRING("/>\n"); |
1309 | 257 } |
258 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
259 gint bar_pane_keywords_event(GtkWidget *bar, GdkEvent *event) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
260 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
261 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
262 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
263 pkd = g_object_get_data(G_OBJECT(bar), "pane_data"); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
264 if (!pkd) return FALSE; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
265 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
266 if (GTK_WIDGET_HAS_FOCUS(pkd->keyword_view)) return gtk_widget_event(pkd->keyword_view, event); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
267 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
268 return FALSE; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
269 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
270 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
271 static void bar_pane_keywords_keyword_toggle(GtkCellRendererToggle *toggle, const gchar *path, gpointer data) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
272 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
273 PaneKeywordsData *pkd = data; |
1391 | 274 GtkTreeModel *model; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
275 GtkTreeIter iter; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
276 GtkTreePath *tpath; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
277 gboolean active; |
1391 | 278 GList *list; |
279 GtkTreeIter child_iter; | |
280 GtkTreeModel *keyword_tree; | |
281 | |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
282 GtkTextBuffer *keyword_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pkd->keyword_view)); |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
283 |
1391 | 284 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
285 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
286 tpath = gtk_tree_path_new_from_string(path); |
1391 | 287 gtk_tree_model_get_iter(model, &iter, tpath); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
288 gtk_tree_path_free(tpath); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
289 |
1391 | 290 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_TOGGLE, &active, -1); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
291 active = (!active); |
1391 | 292 |
293 | |
294 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
295 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter); | |
296 | |
297 list = keyword_list_pull(pkd->keyword_view); | |
298 if (active) | |
299 keyword_tree_set(keyword_tree, &child_iter, &list); | |
300 else | |
301 keyword_tree_reset(keyword_tree, &child_iter, &list); | |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
302 |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
303 g_signal_handlers_block_by_func(keyword_buffer, bar_pane_keywords_changed, pkd); |
1391 | 304 keyword_list_push(pkd->keyword_view, list); |
305 string_list_free(list); | |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
306 g_signal_handlers_unblock_by_func(keyword_buffer, bar_pane_keywords_changed, pkd); |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
307 |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
308 /* call this just once in the end */ |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
309 bar_pane_keywords_changed(keyword_buffer, pkd); |
1392 | 310 /* |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
311 bar_pane_keywords_change calls bar_keyword_tree_sync, no need to do it again |
1391 | 312 bar_keyword_tree_sync(pkd); |
1392 | 313 */ |
1391 | 314 } |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
315 |
1391 | 316 void bar_pane_keywords_filter_modify(GtkTreeModel *model, GtkTreeIter *iter, GValue *value, gint column, gpointer data) |
317 { | |
318 PaneKeywordsData *pkd = data; | |
319 GtkTreeModel *keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
320 GtkTreeIter child_iter; | |
1392 | 321 |
1391 | 322 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, iter); |
323 | |
324 memset(value, 0, sizeof (GValue)); | |
325 | |
326 switch (column) | |
327 { | |
328 case FILTER_KEYWORD_COLUMN_TOGGLE: | |
329 { | |
330 GList *keywords = keyword_list_pull(pkd->keyword_view); | |
331 gboolean set = keyword_tree_is_set(keyword_tree, &child_iter, keywords); | |
332 string_list_free(keywords); | |
333 | |
334 g_value_init(value, G_TYPE_BOOLEAN); | |
335 g_value_set_boolean(value, set); | |
336 break; | |
337 } | |
338 case FILTER_KEYWORD_COLUMN_MARK: | |
339 gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_MARK, value); | |
340 break; | |
341 case FILTER_KEYWORD_COLUMN_NAME: | |
342 gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_NAME, value); | |
343 break; | |
344 case FILTER_KEYWORD_COLUMN_IS_KEYWORD: | |
345 gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_IS_KEYWORD, value); | |
346 break; | |
347 } | |
348 return; | |
349 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
350 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
351 |
1428 | 352 gboolean bar_pane_keywords_filter_visible(GtkTreeModel *keyword_tree, GtkTreeIter *iter, gpointer data) |
353 { | |
354 GtkTreeModel *filter = data; | |
355 | |
356 return !keyword_is_hidden_in(keyword_tree, iter, filter); | |
357 } | |
358 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
359 static void bar_pane_keywords_set_selection(PaneKeywordsData *pkd, gboolean append) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
360 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
361 GList *keywords = NULL; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
362 GList *list = NULL; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
363 GList *work; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
364 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
365 keywords = keyword_list_pull(pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
366 |
1387 | 367 list = layout_selection_list(pkd->pane.lw); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
368 work = list; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
369 while (work) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
370 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
371 FileData *fd = work->data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
372 work = work->next; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
373 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
374 if (append) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
375 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
376 metadata_append_list(fd, KEYWORD_KEY, keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
377 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
378 else |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
379 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
380 metadata_write_list(fd, KEYWORD_KEY, keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
381 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
382 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
383 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
384 filelist_free(list); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
385 string_list_free(keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
386 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
387 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
388 static void bar_pane_keywords_sel_add_cb(GtkWidget *button, gpointer data) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
389 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
390 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
391 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
392 bar_pane_keywords_set_selection(pkd, TRUE); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
393 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
394 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
395 static void bar_pane_keywords_sel_replace_cb(GtkWidget *button, gpointer data) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
396 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
397 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
398 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
399 bar_pane_keywords_set_selection(pkd, FALSE); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
400 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
401 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
402 static void bar_pane_keywords_populate_popup_cb(GtkTextView *textview, GtkMenu *menu, gpointer data) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
403 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
404 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
405 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
406 menu_item_add_divider(GTK_WIDGET(menu)); |
1295 | 407 menu_item_add_stock(GTK_WIDGET(menu), _("Add keywords to selected files"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_sel_add_cb), pkd); |
408 menu_item_add_stock(GTK_WIDGET(menu), _("Replace existing keywords in selected files"), GTK_STOCK_CONVERT, G_CALLBACK(bar_pane_keywords_sel_replace_cb), pkd); | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
409 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
410 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
411 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
412 static void bar_pane_keywords_notify_cb(FileData *fd, NotifyType type, gpointer data) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
413 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
414 PaneKeywordsData *pkd = data; |
1450 | 415 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pkd->fd) bar_pane_keywords_update(pkd); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
416 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
417 |
1455 | 418 static gboolean bar_pane_keywords_changed_idle_cb(gpointer data) |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
419 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
420 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
421 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
422 file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
423 bar_pane_keywords_write(pkd); |
1391 | 424 bar_keyword_tree_sync(pkd); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
425 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW); |
1455 | 426 pkd->idle_id = -1; |
427 return FALSE; | |
428 } | |
429 | |
430 static void bar_pane_keywords_changed(GtkTextBuffer *buffer, gpointer data) | |
431 { | |
432 PaneKeywordsData *pkd = data; | |
433 | |
434 if (pkd->idle_id != -1) return; | |
435 /* higher prio than redraw */ | |
436 pkd->idle_id = g_idle_add_full(G_PRIORITY_HIGH_IDLE, bar_pane_keywords_changed_idle_cb, pkd, NULL); | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
437 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
438 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
439 |
1421 | 440 /* |
441 *------------------------------------------------------------------- | |
442 * dnd | |
443 *------------------------------------------------------------------- | |
444 */ | |
445 | |
1392 | 446 |
447 static GtkTargetEntry bar_pane_keywords_drag_types[] = { | |
448 { TARGET_APP_KEYWORD_PATH_STRING, GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH }, | |
449 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
450 }; | |
451 static gint n_keywords_drag_types = 2; | |
452 | |
453 | |
454 static GtkTargetEntry bar_pane_keywords_drop_types[] = { | |
455 { TARGET_APP_KEYWORD_PATH_STRING, GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH }, | |
456 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
457 }; | |
458 static gint n_keywords_drop_types = 2; | |
459 | |
460 | |
461 static void bar_pane_keywords_dnd_get(GtkWidget *tree_view, GdkDragContext *context, | |
462 GtkSelectionData *selection_data, guint info, | |
463 guint time, gpointer data) | |
464 { | |
465 GtkTreeIter iter; | |
466 GtkTreeModel *model; | |
467 GtkTreeIter child_iter; | |
468 GtkTreeModel *keyword_tree; | |
469 | |
470 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | |
471 | |
472 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) return; | |
473 | |
474 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
475 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter); | |
476 | |
477 switch (info) | |
478 { | |
479 case TARGET_APP_KEYWORD_PATH: | |
480 { | |
481 GList *path = keyword_tree_get_path(keyword_tree, &child_iter); | |
482 gtk_selection_data_set(selection_data, selection_data->target, | |
483 8, (gpointer) &path, sizeof(path)); | |
484 break; | |
485 } | |
486 | |
487 case TARGET_TEXT_PLAIN: | |
488 default: | |
489 { | |
490 gchar *name = keyword_get_name(keyword_tree, &child_iter); | |
491 gtk_selection_data_set_text(selection_data, name, -1); | |
492 g_free(name); | |
493 } | |
494 break; | |
495 } | |
496 } | |
497 | |
1393 | 498 static void bar_pane_keywords_dnd_begin(GtkWidget *tree_view, GdkDragContext *context, gpointer data) |
1392 | 499 { |
1393 | 500 GtkTreeIter iter; |
501 GtkTreeModel *model; | |
502 GtkTreeIter child_iter; | |
503 GtkTreeModel *keyword_tree; | |
504 gchar *name; | |
505 | |
506 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | |
507 | |
508 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) return; | |
509 | |
510 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
511 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter); | |
512 | |
513 name = keyword_get_name(keyword_tree, &child_iter); | |
514 | |
515 dnd_set_drag_label(tree_view, context, name); | |
516 g_free(name); | |
517 | |
1392 | 518 } |
519 | |
520 static void bar_pane_keywords_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
521 { | |
522 } | |
523 | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
524 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
525 static gboolean bar_pane_keywords_dnd_can_move(GtkTreeModel *keyword_tree, GtkTreeIter *src_kw_iter, GtkTreeIter *dest_kw_iter) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
526 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
527 gchar *src_name; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
528 GtkTreeIter parent; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
529 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
530 if (dest_kw_iter && keyword_same_parent(keyword_tree, src_kw_iter, dest_kw_iter)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
531 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
532 return TRUE; /* reordering of siblings is ok */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
533 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
534 if (!dest_kw_iter && !gtk_tree_model_iter_parent(keyword_tree, &parent, src_kw_iter)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
535 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
536 return TRUE; /* reordering of top-level siblings is ok */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
537 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
538 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
539 src_name = keyword_get_name(keyword_tree, src_kw_iter); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
540 if (keyword_exists(keyword_tree, NULL, dest_kw_iter, src_name, FALSE)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
541 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
542 g_free(src_name); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
543 return FALSE; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
544 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
545 g_free(src_name); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
546 return TRUE; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
547 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
548 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
549 static gboolean bar_pane_keywords_dnd_skip_existing(GtkTreeModel *keyword_tree, GtkTreeIter *dest_kw_iter, GList **keywords) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
550 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
551 /* we have to find at least one keyword that does not already exist as a sibling of dest_kw_iter */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
552 GList *work = *keywords; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
553 while (work) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
554 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
555 gchar *keyword = work->data; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
556 if (keyword_exists(keyword_tree, NULL, dest_kw_iter, keyword, FALSE)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
557 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
558 GList *next = work->next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
559 g_free(keyword); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
560 *keywords = g_list_delete_link(*keywords, work); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
561 work = next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
562 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
563 else |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
564 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
565 work = work->next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
566 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
567 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
568 return !!*keywords; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
569 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
570 |
1392 | 571 static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *context, |
572 gint x, gint y, | |
573 GtkSelectionData *selection_data, guint info, | |
574 guint time, gpointer data) | |
575 { | |
1396 | 576 PaneKeywordsData *pkd = data; |
1392 | 577 GtkTreePath *tpath = NULL; |
578 GtkTreeViewDropPosition pos; | |
579 GtkTreeModel *model; | |
580 | |
581 GtkTreeModel *keyword_tree; | |
582 gboolean src_valid = FALSE; | |
1394 | 583 GList *new_keywords = NULL; |
584 GList *work; | |
1392 | 585 |
586 /* iterators for keyword_tree */ | |
587 GtkTreeIter src_kw_iter; | |
588 GtkTreeIter dest_kw_iter; | |
589 GtkTreeIter new_kw_iter; | |
590 | |
591 g_signal_stop_emission_by_name(tree_view, "drag_data_received"); | |
592 | |
593 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); | |
594 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
595 | |
596 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); | |
1430 | 597 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), NULL, pos); |
1392 | 598 |
599 switch (info) | |
600 { | |
601 case TARGET_APP_KEYWORD_PATH: | |
602 { | |
603 GList *path = *(gpointer *)selection_data->data; | |
604 src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path); | |
605 string_list_free(path); | |
606 break; | |
607 } | |
608 default: | |
1394 | 609 new_keywords = string_to_keywords_list((gchar *)selection_data->data); |
1392 | 610 break; |
611 } | |
612 | |
613 if (tpath) | |
614 { | |
615 GtkTreeIter dest_iter; | |
616 gtk_tree_model_get_iter(model, &dest_iter, tpath); | |
617 gtk_tree_path_free(tpath); | |
618 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &dest_kw_iter, &dest_iter); | |
619 | |
1395 | 620 if (src_valid && gtk_tree_store_is_ancestor(GTK_TREE_STORE(keyword_tree), &src_kw_iter, &dest_kw_iter)) |
621 { | |
622 /* can't move to it's own child */ | |
623 return; | |
624 } | |
1392 | 625 |
1396 | 626 if (src_valid && keyword_compare(keyword_tree, &src_kw_iter, &dest_kw_iter) == 0) |
627 { | |
628 /* can't move to itself */ | |
629 return; | |
630 } | |
631 | |
1392 | 632 if ((pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) && |
633 !gtk_tree_model_iter_has_child(keyword_tree, &dest_kw_iter)) | |
634 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
635 /* the node has no children, all keywords can be added */ |
1392 | 636 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &dest_kw_iter); |
637 } | |
638 else | |
639 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
640 if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, &dest_kw_iter)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
641 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
642 /* the keyword can't be moved if the same name already exist */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
643 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
644 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
645 if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, &dest_kw_iter, &new_keywords)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
646 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
647 /* the keywords can't be added if the same name already exist */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
648 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
649 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
650 |
1392 | 651 switch (pos) |
652 { | |
653 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
654 case GTK_TREE_VIEW_DROP_BEFORE: | |
655 gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); | |
656 break; | |
657 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
658 case GTK_TREE_VIEW_DROP_AFTER: | |
659 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); | |
660 break; | |
661 } | |
662 } | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
663 |
1392 | 664 } |
665 else | |
666 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
667 if (src_valid && !bar_pane_keywords_dnd_can_move(keyword_tree, &src_kw_iter, NULL)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
668 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
669 /* the keyword can't be moved if the same name already exist */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
670 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
671 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
672 if (new_keywords && !bar_pane_keywords_dnd_skip_existing(keyword_tree, NULL, &new_keywords)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
673 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
674 /* the keywords can't be added if the same name already exist */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
675 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
676 } |
1392 | 677 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL); |
678 } | |
679 | |
680 | |
681 if (src_valid) | |
682 { | |
683 keyword_move_recursive(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &src_kw_iter); | |
684 } | |
685 | |
1394 | 686 work = new_keywords; |
687 while (work) | |
1392 | 688 { |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
689 gchar *keyword = work->data; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
690 keyword_set(GTK_TREE_STORE(keyword_tree), &new_kw_iter, keyword, TRUE); |
1394 | 691 work = work->next; |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
692 |
1394 | 693 if (work) |
694 { | |
695 GtkTreeIter add; | |
696 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &new_kw_iter); | |
697 new_kw_iter = add; | |
698 } | |
1392 | 699 } |
1394 | 700 string_list_free(new_keywords); |
1396 | 701 bar_keyword_tree_sync(pkd); |
1392 | 702 } |
703 | |
704 static gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *context, | |
705 gint x, gint y, guint time, gpointer data) | |
706 { | |
707 GtkTreePath *tpath = NULL; | |
708 GtkTreeViewDropPosition pos; | |
709 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); | |
710 if (tpath) | |
711 { | |
712 GtkTreeModel *model; | |
713 GtkTreeIter dest_iter; | |
714 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); | |
715 gtk_tree_model_get_iter(model, &dest_iter, tpath); | |
716 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE && gtk_tree_model_iter_has_child(model, &dest_iter)) | |
717 pos = GTK_TREE_VIEW_DROP_BEFORE; | |
718 | |
719 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER && gtk_tree_model_iter_has_child(model, &dest_iter)) | |
720 pos = GTK_TREE_VIEW_DROP_AFTER; | |
721 } | |
722 | |
723 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), tpath, pos); | |
724 gtk_tree_path_free(tpath); | |
1395 | 725 |
726 if (tree_view == gtk_drag_get_source_widget(context)) | |
727 gdk_drag_status(context, GDK_ACTION_MOVE, time); | |
728 else | |
729 gdk_drag_status(context, GDK_ACTION_COPY, time); | |
730 | |
1392 | 731 return TRUE; |
732 } | |
733 | |
1421 | 734 /* |
735 *------------------------------------------------------------------- | |
736 * edit dialog | |
737 *------------------------------------------------------------------- | |
738 */ | |
739 | |
740 static void bar_pane_keywords_edit_destroy_cb(GtkWidget *widget, gpointer data) | |
741 { | |
742 ConfDialogData *cdd = data; | |
743 gtk_tree_path_free(cdd->click_tpath); | |
744 g_free(cdd); | |
745 } | |
746 | |
747 | |
748 static void bar_pane_keywords_edit_cancel_cb(GenericDialog *gd, gpointer data) | |
749 { | |
750 } | |
751 | |
752 | |
753 static void bar_pane_keywords_edit_ok_cb(GenericDialog *gd, gpointer data) | |
754 { | |
755 ConfDialogData *cdd = data; | |
756 PaneKeywordsData *pkd = cdd->pkd; | |
757 GtkTreeModel *model; | |
758 | |
759 GtkTreeModel *keyword_tree; | |
760 GtkTreeIter kw_iter; | |
761 | |
762 gboolean have_dest = FALSE; | |
763 | |
764 GList *keywords; | |
765 | |
766 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
767 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
768 | |
769 if (cdd->click_tpath) | |
770 { | |
771 GtkTreeIter iter; | |
772 if (gtk_tree_model_get_iter(model, &iter, cdd->click_tpath)) | |
773 { | |
774 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
775 have_dest = TRUE; | |
776 } | |
777 } | |
778 | |
779 if (cdd->edit_existing && !have_dest) return; | |
780 | |
781 keywords = keyword_list_pull(cdd->edit_widget); | |
782 | |
783 if (cdd->edit_existing) | |
784 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
785 if (keywords && keywords->data && /* there should be one keyword */ |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
786 !keyword_exists(keyword_tree, NULL, &kw_iter, keywords->data, TRUE)) |
1421 | 787 { |
788 keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, keywords->data, cdd->is_keyword); | |
789 } | |
790 } | |
791 else | |
792 { | |
793 GList *work = keywords; | |
794 | |
795 while (work) | |
796 { | |
797 GtkTreeIter add; | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
798 if (keyword_exists(keyword_tree, NULL, have_dest ? &kw_iter : NULL, work->data, FALSE)) |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
799 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
800 work = work->next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
801 continue; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
802 } |
1421 | 803 if (have_dest) |
804 { | |
805 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &kw_iter); | |
806 } | |
807 else | |
808 { | |
809 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, NULL); | |
810 have_dest = TRUE; | |
811 } | |
812 kw_iter = add; | |
813 keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, work->data, cdd->is_keyword); | |
814 work = work->next; | |
815 } | |
816 } | |
817 string_list_free(keywords); | |
818 } | |
819 | |
820 static void bar_pane_keywords_conf_set_helper(GtkWidget *widget, gpointer data) | |
821 { | |
822 ConfDialogData *cdd = data; | |
823 cdd->is_keyword = FALSE; | |
824 } | |
825 | |
826 static void bar_pane_keywords_conf_set_kw(GtkWidget *widget, gpointer data) | |
1414 | 827 { |
1421 | 828 ConfDialogData *cdd = data; |
829 cdd->is_keyword = TRUE; | |
830 } | |
831 | |
832 | |
833 | |
834 static void bar_pane_keywords_edit_dialog(PaneKeywordsData *pkd, gboolean edit_existing) | |
835 { | |
836 ConfDialogData *cdd; | |
837 GenericDialog *gd; | |
838 GtkWidget *table; | |
839 GtkWidget *group; | |
840 GtkWidget *button; | |
841 | |
842 gchar *name = NULL; | |
843 gboolean is_keyword = TRUE; | |
844 | |
845 | |
846 if (edit_existing && pkd->click_tpath) | |
847 { | |
848 GtkTreeModel *model; | |
849 GtkTreeIter iter; | |
850 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
851 | |
852 if (gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) | |
853 { | |
854 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, | |
855 FILTER_KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1); | |
856 } | |
857 else | |
858 { | |
859 return; | |
860 } | |
861 } | |
862 | |
863 if (edit_existing && !name) return; | |
864 | |
865 | |
866 cdd = g_new0(ConfDialogData, 1); | |
867 cdd->pkd =pkd; | |
868 cdd->click_tpath = pkd->click_tpath; | |
869 pkd->click_tpath = NULL; | |
870 cdd->is_keyword = is_keyword; | |
871 cdd->edit_existing = edit_existing; | |
872 | |
873 cdd->gd = gd = generic_dialog_new(name ? _("Edit keyword") : _("Add keywords"), "keyword_edit", | |
874 pkd->widget, TRUE, | |
875 bar_pane_keywords_edit_cancel_cb, cdd); | |
876 g_signal_connect(G_OBJECT(gd->dialog), "destroy", | |
877 G_CALLBACK(bar_pane_keywords_edit_destroy_cb), cdd); | |
878 | |
879 | |
880 generic_dialog_add_message(gd, NULL, name ? _("Configure keyword") : _("Add keyword"), NULL); | |
881 | |
882 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, | |
883 bar_pane_keywords_edit_ok_cb, TRUE); | |
884 | |
885 table = pref_table_new(gd->vbox, 3, 1, FALSE, TRUE); | |
886 pref_table_label(table, 0, 0, _("Keyword:"), 1.0); | |
887 cdd->edit_widget = gtk_entry_new(); | |
888 gtk_widget_set_size_request(cdd->edit_widget, 300, -1); | |
889 if (name) gtk_entry_set_text(GTK_ENTRY(cdd->edit_widget), name); | |
890 gtk_table_attach_defaults(GTK_TABLE(table), cdd->edit_widget, 1, 2, 0, 1); | |
891 /* here could eventually be a text view instead of entry */ | |
892 generic_dialog_attach_default(gd, cdd->edit_widget); | |
893 gtk_widget_show(cdd->edit_widget); | |
894 | |
895 group = pref_group_new(gd->vbox, FALSE, _("Keyword type:"), GTK_ORIENTATION_VERTICAL); | |
896 | |
897 button = pref_radiobutton_new(group, NULL, _("Active keyword"), | |
898 (cdd->is_keyword), | |
899 G_CALLBACK(bar_pane_keywords_conf_set_kw), cdd); | |
900 button = pref_radiobutton_new(group, button, _("Helper"), | |
901 (!cdd->is_keyword), | |
902 G_CALLBACK(bar_pane_keywords_conf_set_helper), cdd); | |
903 g_free(name); | |
904 | |
905 gtk_widget_show(gd->dialog); | |
906 } | |
907 | |
908 | |
909 | |
910 | |
911 /* | |
912 *------------------------------------------------------------------- | |
913 * popup menu | |
914 *------------------------------------------------------------------- | |
915 */ | |
916 | |
917 static void bar_pane_keywords_edit_dialog_cb(GtkWidget *menu_widget, gpointer data) | |
918 { | |
919 PaneKeywordsData *pkd = data; | |
920 bar_pane_keywords_edit_dialog(pkd, TRUE); | |
921 } | |
922 | |
923 static void bar_pane_keywords_add_dialog_cb(GtkWidget *menu_widget, gpointer data) | |
924 { | |
925 PaneKeywordsData *pkd = data; | |
926 bar_pane_keywords_edit_dialog(pkd, FALSE); | |
1414 | 927 } |
928 | |
1425 | 929 static void bar_pane_keywords_connect_mark_cb(GtkWidget *menu_widget, gpointer data) |
930 { | |
931 PaneKeywordsData *pkd = data; | |
932 | |
933 GtkTreeModel *model; | |
934 GtkTreeIter iter; | |
935 | |
936 GtkTreeModel *keyword_tree; | |
937 GtkTreeIter kw_iter; | |
938 | |
939 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_widget), "mark")) - 1; | |
940 | |
941 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
942 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
943 | |
944 if (!pkd->click_tpath) return; | |
945 if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return; | |
946 | |
947 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
948 | |
949 file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd); | |
950 | |
951 meta_data_connect_mark_with_keyword(keyword_tree, &kw_iter, mark); | |
952 | |
953 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW); | |
954 // bar_pane_keywords_update(pkd); | |
955 } | |
956 | |
957 | |
1414 | 958 static void bar_pane_keywords_delete_cb(GtkWidget *menu_widget, gpointer data) |
959 { | |
960 PaneKeywordsData *pkd = data; | |
961 GtkTreeModel *model; | |
962 GtkTreeIter iter; | |
963 | |
964 GtkTreeModel *keyword_tree; | |
965 GtkTreeIter kw_iter; | |
966 | |
967 if (!pkd->click_tpath) return; | |
968 | |
969 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
970 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
971 | |
972 if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return; | |
973 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
974 | |
975 keyword_delete(GTK_TREE_STORE(keyword_tree), &kw_iter); | |
976 } | |
977 | |
1428 | 978 static void bar_pane_keywords_hide_cb(GtkWidget *menu_widget, gpointer data) |
979 { | |
980 PaneKeywordsData *pkd = data; | |
981 GtkTreeModel *model; | |
982 GtkTreeIter iter; | |
983 | |
984 GtkTreeModel *keyword_tree; | |
985 GtkTreeIter kw_iter; | |
986 | |
987 if (!pkd->click_tpath) return; | |
988 | |
989 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
990 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
991 | |
992 if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return; | |
993 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
994 | |
995 keyword_hide_in(GTK_TREE_STORE(keyword_tree), &kw_iter, model); | |
996 } | |
997 | |
998 static void bar_pane_keywords_show_all_cb(GtkWidget *menu_widget, gpointer data) | |
999 { | |
1000 PaneKeywordsData *pkd = data; | |
1001 GtkTreeModel *model; | |
1002 | |
1003 GtkTreeModel *keyword_tree; | |
1004 | |
1005 pkd->hide_unchecked = FALSE; | |
1006 | |
1007 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1008 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
1009 | |
1010 keyword_show_all_in(GTK_TREE_STORE(keyword_tree), model); | |
1430 | 1011 |
1012 if (!pkd->collapse_unchecked) gtk_tree_view_expand_all(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1428 | 1013 bar_keyword_tree_sync(pkd); |
1014 } | |
1015 | |
1016 static void bar_pane_keywords_expand_checked_cb(GtkWidget *menu_widget, gpointer data) | |
1017 { | |
1018 PaneKeywordsData *pkd = data; | |
1019 GtkTreeModel *model; | |
1020 | |
1021 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1022 gtk_tree_model_foreach(model, bar_keyword_tree_expand_if_set_cb, pkd); | |
1023 } | |
1024 | |
1025 static void bar_pane_keywords_collapse_unchecked_cb(GtkWidget *menu_widget, gpointer data) | |
1026 { | |
1027 PaneKeywordsData *pkd = data; | |
1028 GtkTreeModel *model; | |
1029 | |
1030 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1031 gtk_tree_model_foreach(model, bar_keyword_tree_collapse_if_unset_cb, pkd); | |
1032 } | |
1033 | |
1034 static void bar_pane_keywords_hide_unchecked_cb(GtkWidget *menu_widget, gpointer data) | |
1035 { | |
1036 PaneKeywordsData *pkd = data; | |
1037 GtkTreeModel *model; | |
1038 | |
1039 GtkTreeModel *keyword_tree; | |
1040 GList *keywords; | |
1041 | |
1042 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1043 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
1044 | |
1045 keywords = keyword_list_pull(pkd->keyword_view); | |
1046 keyword_hide_unset_in(GTK_TREE_STORE(keyword_tree), model, keywords); | |
1047 string_list_free(keywords); | |
1048 bar_keyword_tree_sync(pkd); | |
1049 } | |
1050 | |
1051 static void bar_pane_keywords_expand_checked_toggle_cb(GtkWidget *menu_widget, gpointer data) | |
1052 { | |
1053 PaneKeywordsData *pkd = data; | |
1054 pkd->expand_checked = !pkd->expand_checked; | |
1055 bar_keyword_tree_sync(pkd); | |
1056 } | |
1057 | |
1058 static void bar_pane_keywords_collapse_unchecked_toggle_cb(GtkWidget *menu_widget, gpointer data) | |
1059 { | |
1060 PaneKeywordsData *pkd = data; | |
1061 pkd->collapse_unchecked = !pkd->collapse_unchecked; | |
1062 bar_keyword_tree_sync(pkd); | |
1063 } | |
1064 | |
1065 static void bar_pane_keywords_hide_unchecked_toggle_cb(GtkWidget *menu_widget, gpointer data) | |
1066 { | |
1067 PaneKeywordsData *pkd = data; | |
1068 pkd->hide_unchecked = !pkd->hide_unchecked; | |
1069 bar_keyword_tree_sync(pkd); | |
1070 } | |
1071 | |
1414 | 1072 static void bar_pane_keywords_menu_popup(GtkWidget *widget, PaneKeywordsData *pkd, gint x, gint y) |
1073 { | |
1074 GtkWidget *menu; | |
1428 | 1075 GtkWidget *item; |
1076 GtkWidget *submenu; | |
1414 | 1077 GtkTreeViewDropPosition pos; |
1078 | |
1079 if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath); | |
1080 pkd->click_tpath = NULL; | |
1081 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(pkd->keyword_treeview), x, y, &pkd->click_tpath, &pos); | |
1082 | |
1083 menu = popup_menu_short_lived(); | |
1084 | |
1085 if (pkd->click_tpath) | |
1086 { | |
1087 /* for the entry */ | |
1425 | 1088 gchar *text; |
1089 gchar *mark; | |
1090 gint i; | |
1091 | |
1414 | 1092 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); |
1093 | |
1094 GtkTreeIter iter; | |
1095 gtk_tree_model_get_iter(model, &iter, pkd->click_tpath); | |
1096 gchar *name; | |
1097 | |
1425 | 1098 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, |
1099 FILTER_KEYWORD_COLUMN_MARK, &mark, -1); | |
1100 | |
1428 | 1101 text = g_strdup_printf(_("Hide \"%s\""), name); |
1102 menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_hide_cb), pkd); | |
1425 | 1103 g_free(text); |
1414 | 1104 |
1425 | 1105 submenu = gtk_menu_new(); |
1106 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) | |
1107 { | |
1108 text = g_strdup_printf(_("Mark %d"), i + 1); | |
1109 item = menu_item_add(submenu, text, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd); | |
1110 g_object_set_data(G_OBJECT(item), "mark", GINT_TO_POINTER(i + 1)); | |
1111 g_free(text); | |
1112 } | |
1113 text = g_strdup_printf(_("Connect \"%s\" to mark"), name); | |
1114 item = menu_item_add(menu, text, NULL, NULL); | |
1115 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
1116 g_free(text); | |
1428 | 1117 |
1118 menu_item_add_divider(menu); | |
1119 | |
1120 text = g_strdup_printf(_("Edit \"%s\""), name); | |
1121 menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd); | |
1122 g_free(text); | |
1123 text = g_strdup_printf(_("Delete \"%s\""), name); | |
1124 menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd); | |
1125 g_free(text); | |
1126 | |
1425 | 1127 |
1128 if (mark && mark[0]) | |
1129 { | |
1130 text = g_strdup_printf(_("Disconnect \"%s\" from mark %s"), name, mark); | |
1131 menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd); | |
1132 g_free(text); | |
1133 } | |
1134 | |
1414 | 1135 menu_item_add_divider(menu); |
1425 | 1136 g_free(mark); |
1414 | 1137 g_free(name); |
1138 } | |
1139 /* for the pane */ | |
1428 | 1140 |
1141 | |
1142 menu_item_add(menu, _("Expand checked"), G_CALLBACK(bar_pane_keywords_expand_checked_cb), pkd); | |
1143 menu_item_add(menu, _("Collapse unchecked"), G_CALLBACK(bar_pane_keywords_collapse_unchecked_cb), pkd); | |
1144 menu_item_add(menu, _("Hide unchecked"), G_CALLBACK(bar_pane_keywords_hide_unchecked_cb), pkd); | |
1145 menu_item_add(menu, _("Show all"), G_CALLBACK(bar_pane_keywords_show_all_cb), pkd); | |
1146 | |
1147 submenu = gtk_menu_new(); | |
1148 item = menu_item_add(menu, _("On any change"), NULL, NULL); | |
1149 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
1150 | |
1151 menu_item_add_check(submenu, _("Expand checked"), pkd->expand_checked, G_CALLBACK(bar_pane_keywords_expand_checked_toggle_cb), pkd); | |
1152 menu_item_add_check(submenu, _("Collapse unchecked"), pkd->collapse_unchecked, G_CALLBACK(bar_pane_keywords_collapse_unchecked_toggle_cb), pkd); | |
1153 menu_item_add_check(submenu, _("Hide unchecked"), pkd->hide_unchecked, G_CALLBACK(bar_pane_keywords_hide_unchecked_toggle_cb), pkd); | |
1154 | |
1155 menu_item_add_divider(menu); | |
1156 | |
1421 | 1157 menu_item_add_stock(menu, _("Add keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd); |
1414 | 1158 |
1159 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME); | |
1160 } | |
1161 | |
1162 | |
1163 static gboolean bar_pane_keywords_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1164 { | |
1165 PaneKeywordsData *pkd = data; | |
1166 if (bevent->button == MOUSE_BUTTON_RIGHT) | |
1167 { | |
1168 bar_pane_keywords_menu_popup(widget, pkd, bevent->x, bevent->y); | |
1169 return TRUE; | |
1170 } | |
1171 return FALSE; | |
1172 } | |
1173 | |
1421 | 1174 /* |
1175 *------------------------------------------------------------------- | |
1176 * init | |
1177 *------------------------------------------------------------------- | |
1178 */ | |
1392 | 1179 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1180 void bar_pane_keywords_close(GtkWidget *bar) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1181 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1182 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1183 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1184 pkd = g_object_get_data(G_OBJECT(bar), "pane_data"); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1185 if (!pkd) return; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1186 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1187 gtk_widget_destroy(pkd->widget); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1188 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1189 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1190 static void bar_pane_keywords_destroy(GtkWidget *widget, gpointer data) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1191 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1192 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1193 |
1414 | 1194 if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath); |
1455 | 1195 if (pkd->idle_id != -1) g_source_remove(pkd->idle_id); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1196 file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1197 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1198 file_data_unref(pkd->fd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1199 g_free(pkd->key); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1200 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1201 g_free(pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1202 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1203 |
1391 | 1204 |
1309 | 1205 GtkWidget *bar_pane_keywords_new(const gchar *title, const gchar *key, gboolean expanded) |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1206 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1207 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1208 GtkWidget *hbox; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1209 GtkWidget *scrolled; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1210 GtkTextBuffer *buffer; |
1391 | 1211 GtkTreeModel *store; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1212 GtkTreeViewColumn *column; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1213 GtkCellRenderer *renderer; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1214 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1215 pkd = g_new0(PaneKeywordsData, 1); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1216 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1217 pkd->pane.pane_set_fd = bar_pane_keywords_set_fd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1218 pkd->pane.pane_event = bar_pane_keywords_event; |
1309 | 1219 pkd->pane.pane_write_config = bar_pane_keywords_write_config; |
1389
c44f21235ffe
Use a common function bar_pane_expander_title() to set expanders title widget.
zas_
parents:
1387
diff
changeset
|
1220 pkd->pane.title = bar_pane_expander_title(title); |
1387 | 1221 |
1309 | 1222 pkd->pane.expanded = expanded; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1223 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1224 pkd->key = g_strdup(key); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1225 |
1428 | 1226 pkd->expand_checked = TRUE; |
1455 | 1227 |
1228 pkd->idle_id = -1; | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1229 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1230 hbox = gtk_hbox_new(FALSE, PREF_PAD_GAP); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1231 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1232 pkd->widget = hbox; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1233 g_object_set_data(G_OBJECT(pkd->widget), "pane_data", pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1234 g_signal_connect(G_OBJECT(pkd->widget), "destroy", |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1235 G_CALLBACK(bar_pane_keywords_destroy), pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1236 gtk_widget_show(hbox); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1237 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1238 scrolled = gtk_scrolled_window_new(NULL, NULL); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1239 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1240 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1241 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1242 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1243 gtk_widget_show(scrolled); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1244 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1245 pkd->keyword_view = gtk_text_view_new(); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1246 gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1247 g_signal_connect(G_OBJECT(pkd->keyword_view), "populate-popup", |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1248 G_CALLBACK(bar_pane_keywords_populate_popup_cb), pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1249 gtk_widget_show(pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1250 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1251 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pkd->keyword_view)); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1252 g_signal_connect(G_OBJECT(buffer), "changed", |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1253 G_CALLBACK(bar_pane_keywords_changed), pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1254 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1255 scrolled = gtk_scrolled_window_new(NULL, NULL); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1256 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1257 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1258 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1259 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1260 gtk_widget_show(scrolled); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1261 |
1391 | 1262 |
1263 if (!keyword_tree) keyword_tree_new_default(); | |
1264 | |
1265 store = gtk_tree_model_filter_new(GTK_TREE_MODEL(keyword_tree), NULL); | |
1266 | |
1267 gtk_tree_model_filter_set_modify_func(GTK_TREE_MODEL_FILTER(store), | |
1268 FILTER_KEYWORD_COLUMN_COUNT, | |
1269 filter_keyword_column_types, | |
1270 bar_pane_keywords_filter_modify, | |
1271 pkd, | |
1272 NULL); | |
1428 | 1273 gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(store), |
1274 bar_pane_keywords_filter_visible, | |
1275 store, | |
1276 NULL); | |
1391 | 1277 |
1278 pkd->keyword_treeview = gtk_tree_view_new_with_model(store); | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1279 g_object_unref(store); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1280 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1281 gtk_widget_set_size_request(pkd->keyword_treeview, -1, 400); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1282 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1283 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(pkd->keyword_treeview), FALSE); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1284 |
1391 | 1285 // gtk_tree_view_set_search_column(GTK_TREE_VIEW(pkd->keyword_treeview), FILTER_KEYWORD_COLUMN_); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1286 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1287 column = gtk_tree_view_column_new(); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1288 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1289 |
1425 | 1290 renderer = gtk_cell_renderer_text_new(); |
1291 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1292 |
1391 | 1293 gtk_tree_view_column_add_attribute(column, renderer, "text", FILTER_KEYWORD_COLUMN_MARK); |
1425 | 1294 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1295 gtk_tree_view_append_column(GTK_TREE_VIEW(pkd->keyword_treeview), column); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1296 |
1391 | 1297 column = gtk_tree_view_column_new(); |
1298 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1299 renderer = gtk_cell_renderer_toggle_new(); | |
1300 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1301 gtk_tree_view_column_add_attribute(column, renderer, "active", FILTER_KEYWORD_COLUMN_TOGGLE); | |
1302 gtk_tree_view_column_add_attribute(column, renderer, "visible", FILTER_KEYWORD_COLUMN_IS_KEYWORD); | |
1303 g_signal_connect(G_OBJECT(renderer), "toggled", | |
1304 G_CALLBACK(bar_pane_keywords_keyword_toggle), pkd); | |
1305 | |
1306 renderer = gtk_cell_renderer_text_new(); | |
1307 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1308 gtk_tree_view_column_add_attribute(column, renderer, "text", FILTER_KEYWORD_COLUMN_NAME); | |
1309 | |
1310 gtk_tree_view_append_column(GTK_TREE_VIEW(pkd->keyword_treeview), column); | |
1311 gtk_tree_view_set_expander_column(GTK_TREE_VIEW(pkd->keyword_treeview), column); | |
1312 | |
1392 | 1313 gtk_drag_source_set(pkd->keyword_treeview, |
1314 GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
1315 bar_pane_keywords_drag_types, n_keywords_drag_types, | |
1316 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
1317 | |
1318 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_data_get", | |
1319 G_CALLBACK(bar_pane_keywords_dnd_get), pkd); | |
1320 | |
1321 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_begin", | |
1322 G_CALLBACK(bar_pane_keywords_dnd_begin), pkd); | |
1323 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_end", | |
1324 G_CALLBACK(bar_pane_keywords_dnd_end), pkd); | |
1325 | |
1326 gtk_drag_dest_set(pkd->keyword_treeview, | |
1327 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, | |
1328 bar_pane_keywords_drop_types, n_keywords_drop_types, | |
1329 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
1330 | |
1331 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_data_received", | |
1332 G_CALLBACK(bar_pane_keywords_dnd_receive), pkd); | |
1333 | |
1334 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_motion", | |
1335 G_CALLBACK(bar_pane_keywords_dnd_motion), pkd); | |
1336 | |
1414 | 1337 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "button_press_event", |
1338 G_CALLBACK(bar_pane_keywords_menu_cb), pkd); | |
1339 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1340 gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_treeview); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1341 gtk_widget_show(pkd->keyword_treeview); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1342 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1343 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1344 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1345 return pkd->widget; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1346 } |
1309 | 1347 |
1348 GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, const gchar **attribute_values) | |
1349 { | |
1350 gchar *title = g_strdup(_("NoName")); | |
1351 gchar *key = g_strdup(COMMENT_KEY); | |
1352 gboolean expanded = TRUE; | |
1353 | |
1354 while (*attribute_names) | |
1355 { | |
1356 const gchar *option = *attribute_names++; | |
1357 const gchar *value = *attribute_values++; | |
1358 | |
1315 | 1359 if (READ_CHAR_FULL("pane.title", title)) continue; |
1360 if (READ_CHAR_FULL("key", key)) continue; | |
1361 if (READ_BOOL_FULL("pane.expanded", expanded)) continue; | |
1309 | 1362 |
1363 | |
1364 DEBUG_1("unknown attribute %s = %s", option, value); | |
1365 } | |
1366 | |
1367 return bar_pane_keywords_new(title, key, expanded); | |
1368 } | |
1369 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1370 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |