Mercurial > geeqie.yaz
annotate src/bar_keywords.c @ 1526:51b9d42ed79b
Fix the is_keyword bug
The is_keyword would be new set when placing the radio buttons. This
Patch fix it by setting the variable afterwards.
author | mow |
---|---|
date | Mon, 06 Apr 2009 23:59:38 +0000 |
parents | bd8001efdccc |
children | 12b0eeb5d528 |
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 |
1523 | 113 guint idle_id; /* event source 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 | |
1461 | 250 WRITE_NL(); WRITE_STRING("<pane_keywords "); |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
251 write_char_option(outstr, indent, "id", pkd->pane.id); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
252 write_char_option(outstr, indent, "title", gtk_label_get_text(GTK_LABEL(pkd->pane.title))); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
253 WRITE_BOOL(pkd->pane, expanded); |
1309 | 254 WRITE_CHAR(*pkd, key); |
1461 | 255 WRITE_STRING("/>"); |
1309 | 256 } |
257 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
258 gint bar_pane_keywords_event(GtkWidget *bar, GdkEvent *event) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
259 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
260 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
261 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
262 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
|
263 if (!pkd) return FALSE; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
264 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
265 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
|
266 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
267 return FALSE; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
268 } |
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 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
|
271 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
272 PaneKeywordsData *pkd = data; |
1391 | 273 GtkTreeModel *model; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
274 GtkTreeIter iter; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
275 GtkTreePath *tpath; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
276 gboolean active; |
1391 | 277 GList *list; |
278 GtkTreeIter child_iter; | |
279 GtkTreeModel *keyword_tree; | |
280 | |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
281 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
|
282 |
1391 | 283 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
|
284 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
285 tpath = gtk_tree_path_new_from_string(path); |
1391 | 286 gtk_tree_model_get_iter(model, &iter, tpath); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
287 gtk_tree_path_free(tpath); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
288 |
1391 | 289 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
|
290 active = (!active); |
1391 | 291 |
292 | |
293 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
294 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter); | |
295 | |
296 list = keyword_list_pull(pkd->keyword_view); | |
297 if (active) | |
298 keyword_tree_set(keyword_tree, &child_iter, &list); | |
299 else | |
300 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
|
301 |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
302 g_signal_handlers_block_by_func(keyword_buffer, bar_pane_keywords_changed, pkd); |
1391 | 303 keyword_list_push(pkd->keyword_view, list); |
304 string_list_free(list); | |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
305 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
|
306 |
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
307 /* 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
|
308 bar_pane_keywords_changed(keyword_buffer, pkd); |
1392 | 309 /* |
1449
76da5ba54a1d
call the notify function just once when the keywords are pushed to the
nadvornik
parents:
1430
diff
changeset
|
310 bar_pane_keywords_change calls bar_keyword_tree_sync, no need to do it again |
1391 | 311 bar_keyword_tree_sync(pkd); |
1392 | 312 */ |
1391 | 313 } |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
314 |
1391 | 315 void bar_pane_keywords_filter_modify(GtkTreeModel *model, GtkTreeIter *iter, GValue *value, gint column, gpointer data) |
316 { | |
317 PaneKeywordsData *pkd = data; | |
318 GtkTreeModel *keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
319 GtkTreeIter child_iter; | |
1392 | 320 |
1391 | 321 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, iter); |
322 | |
323 memset(value, 0, sizeof (GValue)); | |
324 | |
325 switch (column) | |
326 { | |
327 case FILTER_KEYWORD_COLUMN_TOGGLE: | |
328 { | |
329 GList *keywords = keyword_list_pull(pkd->keyword_view); | |
330 gboolean set = keyword_tree_is_set(keyword_tree, &child_iter, keywords); | |
331 string_list_free(keywords); | |
332 | |
333 g_value_init(value, G_TYPE_BOOLEAN); | |
334 g_value_set_boolean(value, set); | |
335 break; | |
336 } | |
337 case FILTER_KEYWORD_COLUMN_MARK: | |
338 gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_MARK, value); | |
339 break; | |
340 case FILTER_KEYWORD_COLUMN_NAME: | |
341 gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_NAME, value); | |
342 break; | |
343 case FILTER_KEYWORD_COLUMN_IS_KEYWORD: | |
344 gtk_tree_model_get_value(keyword_tree, &child_iter, KEYWORD_COLUMN_IS_KEYWORD, value); | |
345 break; | |
346 } | |
347 return; | |
348 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
349 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
350 |
1428 | 351 gboolean bar_pane_keywords_filter_visible(GtkTreeModel *keyword_tree, GtkTreeIter *iter, gpointer data) |
352 { | |
353 GtkTreeModel *filter = data; | |
354 | |
355 return !keyword_is_hidden_in(keyword_tree, iter, filter); | |
356 } | |
357 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
358 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
|
359 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
360 GList *keywords = NULL; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
361 GList *list = NULL; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
362 GList *work; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
363 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
364 keywords = keyword_list_pull(pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
365 |
1387 | 366 list = layout_selection_list(pkd->pane.lw); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
367 work = list; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
368 while (work) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
369 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
370 FileData *fd = work->data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
371 work = work->next; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
372 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
373 if (append) |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
374 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
375 metadata_append_list(fd, KEYWORD_KEY, keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
376 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
377 else |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
378 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
379 metadata_write_list(fd, KEYWORD_KEY, keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
380 } |
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 filelist_free(list); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
384 string_list_free(keywords); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
385 } |
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 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
|
388 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
389 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
390 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
391 bar_pane_keywords_set_selection(pkd, TRUE); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
392 } |
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 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
|
395 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
396 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
397 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
398 bar_pane_keywords_set_selection(pkd, FALSE); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
399 } |
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 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
|
402 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
403 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
404 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
405 menu_item_add_divider(GTK_WIDGET(menu)); |
1295 | 406 menu_item_add_stock(GTK_WIDGET(menu), _("Add keywords to selected files"), GTK_STOCK_ADD, G_CALLBACK(bar_pane_keywords_sel_add_cb), pkd); |
407 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
|
408 } |
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 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
|
412 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
413 PaneKeywordsData *pkd = data; |
1498 | 414 if ((type & (NOTIFY_REREAD | NOTIFY_CHANGE | NOTIFY_METADATA)) && fd == pkd->fd) |
415 { | |
416 DEBUG_1("Notify pane_keywords: %s %04x", fd->path, type); | |
417 bar_pane_keywords_update(pkd); | |
418 } | |
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 |
1455 | 421 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
|
422 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
423 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
424 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
425 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
|
426 bar_pane_keywords_write(pkd); |
1391 | 427 bar_keyword_tree_sync(pkd); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
428 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW); |
1523 | 429 pkd->idle_id = 0; |
1455 | 430 return FALSE; |
431 } | |
432 | |
433 static void bar_pane_keywords_changed(GtkTextBuffer *buffer, gpointer data) | |
434 { | |
435 PaneKeywordsData *pkd = data; | |
436 | |
1523 | 437 if (pkd->idle_id) return; |
1455 | 438 /* higher prio than redraw */ |
439 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
|
440 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
441 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
442 |
1421 | 443 /* |
444 *------------------------------------------------------------------- | |
445 * dnd | |
446 *------------------------------------------------------------------- | |
447 */ | |
448 | |
1392 | 449 |
450 static GtkTargetEntry bar_pane_keywords_drag_types[] = { | |
451 { TARGET_APP_KEYWORD_PATH_STRING, GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH }, | |
452 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
453 }; | |
454 static gint n_keywords_drag_types = 2; | |
455 | |
456 | |
457 static GtkTargetEntry bar_pane_keywords_drop_types[] = { | |
458 { TARGET_APP_KEYWORD_PATH_STRING, GTK_TARGET_SAME_WIDGET, TARGET_APP_KEYWORD_PATH }, | |
459 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
460 }; | |
461 static gint n_keywords_drop_types = 2; | |
462 | |
463 | |
464 static void bar_pane_keywords_dnd_get(GtkWidget *tree_view, GdkDragContext *context, | |
465 GtkSelectionData *selection_data, guint info, | |
466 guint time, gpointer data) | |
467 { | |
468 GtkTreeIter iter; | |
469 GtkTreeModel *model; | |
470 GtkTreeIter child_iter; | |
471 GtkTreeModel *keyword_tree; | |
472 | |
473 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | |
474 | |
475 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) return; | |
476 | |
477 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
478 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter); | |
479 | |
480 switch (info) | |
481 { | |
482 case TARGET_APP_KEYWORD_PATH: | |
483 { | |
484 GList *path = keyword_tree_get_path(keyword_tree, &child_iter); | |
485 gtk_selection_data_set(selection_data, selection_data->target, | |
486 8, (gpointer) &path, sizeof(path)); | |
487 break; | |
488 } | |
489 | |
490 case TARGET_TEXT_PLAIN: | |
491 default: | |
492 { | |
493 gchar *name = keyword_get_name(keyword_tree, &child_iter); | |
494 gtk_selection_data_set_text(selection_data, name, -1); | |
495 g_free(name); | |
496 } | |
497 break; | |
498 } | |
499 } | |
500 | |
1393 | 501 static void bar_pane_keywords_dnd_begin(GtkWidget *tree_view, GdkDragContext *context, gpointer data) |
1392 | 502 { |
1393 | 503 GtkTreeIter iter; |
504 GtkTreeModel *model; | |
505 GtkTreeIter child_iter; | |
506 GtkTreeModel *keyword_tree; | |
507 gchar *name; | |
508 | |
509 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); | |
510 | |
511 if (!gtk_tree_selection_get_selected(sel, &model, &iter)) return; | |
512 | |
513 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
514 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &child_iter, &iter); | |
515 | |
516 name = keyword_get_name(keyword_tree, &child_iter); | |
517 | |
518 dnd_set_drag_label(tree_view, context, name); | |
519 g_free(name); | |
520 | |
1392 | 521 } |
522 | |
523 static void bar_pane_keywords_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
524 { | |
525 } | |
526 | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
527 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
528 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
|
529 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
530 gchar *src_name; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
531 GtkTreeIter parent; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
532 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
533 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
|
534 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
535 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
|
536 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
537 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
|
538 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
539 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
|
540 } |
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 src_name = keyword_get_name(keyword_tree, src_kw_iter); |
1465 | 543 if (keyword_exists(keyword_tree, NULL, dest_kw_iter, src_name, FALSE, NULL)) |
1429
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 FALSE; |
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 g_free(src_name); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
549 return TRUE; |
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 |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
552 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
|
553 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
554 /* 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
|
555 GList *work = *keywords; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
556 while (work) |
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 gchar *keyword = work->data; |
1465 | 559 if (keyword_exists(keyword_tree, NULL, dest_kw_iter, keyword, FALSE, NULL)) |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
560 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
561 GList *next = work->next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
562 g_free(keyword); |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
563 *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
|
564 work = next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
565 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
566 else |
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 work = work->next; |
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 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
571 return !!*keywords; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
572 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
573 |
1392 | 574 static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *context, |
575 gint x, gint y, | |
576 GtkSelectionData *selection_data, guint info, | |
577 guint time, gpointer data) | |
578 { | |
1396 | 579 PaneKeywordsData *pkd = data; |
1392 | 580 GtkTreePath *tpath = NULL; |
581 GtkTreeViewDropPosition pos; | |
582 GtkTreeModel *model; | |
583 | |
584 GtkTreeModel *keyword_tree; | |
585 gboolean src_valid = FALSE; | |
1394 | 586 GList *new_keywords = NULL; |
587 GList *work; | |
1392 | 588 |
589 /* iterators for keyword_tree */ | |
590 GtkTreeIter src_kw_iter; | |
591 GtkTreeIter dest_kw_iter; | |
592 GtkTreeIter new_kw_iter; | |
593 | |
594 g_signal_stop_emission_by_name(tree_view, "drag_data_received"); | |
595 | |
596 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); | |
597 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
598 | |
599 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); | |
1430 | 600 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), NULL, pos); |
1392 | 601 |
602 switch (info) | |
603 { | |
604 case TARGET_APP_KEYWORD_PATH: | |
605 { | |
606 GList *path = *(gpointer *)selection_data->data; | |
607 src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path); | |
608 string_list_free(path); | |
609 break; | |
610 } | |
611 default: | |
1394 | 612 new_keywords = string_to_keywords_list((gchar *)selection_data->data); |
1392 | 613 break; |
614 } | |
615 | |
616 if (tpath) | |
617 { | |
618 GtkTreeIter dest_iter; | |
619 gtk_tree_model_get_iter(model, &dest_iter, tpath); | |
620 gtk_tree_path_free(tpath); | |
621 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &dest_kw_iter, &dest_iter); | |
622 | |
1395 | 623 if (src_valid && gtk_tree_store_is_ancestor(GTK_TREE_STORE(keyword_tree), &src_kw_iter, &dest_kw_iter)) |
624 { | |
625 /* can't move to it's own child */ | |
626 return; | |
627 } | |
1392 | 628 |
1396 | 629 if (src_valid && keyword_compare(keyword_tree, &src_kw_iter, &dest_kw_iter) == 0) |
630 { | |
631 /* can't move to itself */ | |
632 return; | |
633 } | |
634 | |
1392 | 635 if ((pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) && |
636 !gtk_tree_model_iter_has_child(keyword_tree, &dest_kw_iter)) | |
637 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
638 /* the node has no children, all keywords can be added */ |
1392 | 639 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &dest_kw_iter); |
640 } | |
641 else | |
642 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
643 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
|
644 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
645 /* 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
|
646 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
647 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
648 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
|
649 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
650 /* 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
|
651 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
652 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
653 |
1392 | 654 switch (pos) |
655 { | |
656 case GTK_TREE_VIEW_DROP_INTO_OR_BEFORE: | |
657 case GTK_TREE_VIEW_DROP_BEFORE: | |
658 gtk_tree_store_insert_before(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); | |
659 break; | |
660 case GTK_TREE_VIEW_DROP_INTO_OR_AFTER: | |
661 case GTK_TREE_VIEW_DROP_AFTER: | |
662 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL, &dest_kw_iter); | |
663 break; | |
664 } | |
665 } | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
666 |
1392 | 667 } |
668 else | |
669 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
670 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
|
671 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
672 /* 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
|
673 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
674 } |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
675 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
|
676 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
677 /* 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
|
678 return; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
679 } |
1392 | 680 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &new_kw_iter, NULL); |
681 } | |
682 | |
683 | |
684 if (src_valid) | |
685 { | |
686 keyword_move_recursive(GTK_TREE_STORE(keyword_tree), &new_kw_iter, &src_kw_iter); | |
687 } | |
688 | |
1394 | 689 work = new_keywords; |
690 while (work) | |
1392 | 691 { |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
692 gchar *keyword = work->data; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
693 keyword_set(GTK_TREE_STORE(keyword_tree), &new_kw_iter, keyword, TRUE); |
1394 | 694 work = work->next; |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
695 |
1394 | 696 if (work) |
697 { | |
698 GtkTreeIter add; | |
699 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &new_kw_iter); | |
700 new_kw_iter = add; | |
701 } | |
1392 | 702 } |
1394 | 703 string_list_free(new_keywords); |
1396 | 704 bar_keyword_tree_sync(pkd); |
1392 | 705 } |
706 | |
707 static gint bar_pane_keywords_dnd_motion(GtkWidget *tree_view, GdkDragContext *context, | |
708 gint x, gint y, guint time, gpointer data) | |
709 { | |
710 GtkTreePath *tpath = NULL; | |
711 GtkTreeViewDropPosition pos; | |
712 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(tree_view), x, y, &tpath, &pos); | |
713 if (tpath) | |
714 { | |
715 GtkTreeModel *model; | |
716 GtkTreeIter dest_iter; | |
717 model = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); | |
718 gtk_tree_model_get_iter(model, &dest_iter, tpath); | |
719 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE && gtk_tree_model_iter_has_child(model, &dest_iter)) | |
720 pos = GTK_TREE_VIEW_DROP_BEFORE; | |
721 | |
722 if (pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER && gtk_tree_model_iter_has_child(model, &dest_iter)) | |
723 pos = GTK_TREE_VIEW_DROP_AFTER; | |
724 } | |
725 | |
726 gtk_tree_view_set_drag_dest_row(GTK_TREE_VIEW(tree_view), tpath, pos); | |
727 gtk_tree_path_free(tpath); | |
1395 | 728 |
729 if (tree_view == gtk_drag_get_source_widget(context)) | |
730 gdk_drag_status(context, GDK_ACTION_MOVE, time); | |
731 else | |
732 gdk_drag_status(context, GDK_ACTION_COPY, time); | |
733 | |
1392 | 734 return TRUE; |
735 } | |
736 | |
1421 | 737 /* |
738 *------------------------------------------------------------------- | |
739 * edit dialog | |
740 *------------------------------------------------------------------- | |
741 */ | |
742 | |
743 static void bar_pane_keywords_edit_destroy_cb(GtkWidget *widget, gpointer data) | |
744 { | |
745 ConfDialogData *cdd = data; | |
746 gtk_tree_path_free(cdd->click_tpath); | |
747 g_free(cdd); | |
748 } | |
749 | |
750 | |
751 static void bar_pane_keywords_edit_cancel_cb(GenericDialog *gd, gpointer data) | |
752 { | |
753 } | |
754 | |
755 | |
756 static void bar_pane_keywords_edit_ok_cb(GenericDialog *gd, gpointer data) | |
757 { | |
758 ConfDialogData *cdd = data; | |
759 PaneKeywordsData *pkd = cdd->pkd; | |
760 GtkTreeModel *model; | |
761 | |
762 GtkTreeModel *keyword_tree; | |
763 GtkTreeIter kw_iter; | |
764 | |
765 gboolean have_dest = FALSE; | |
766 | |
767 GList *keywords; | |
768 | |
769 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
770 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
771 | |
772 if (cdd->click_tpath) | |
773 { | |
774 GtkTreeIter iter; | |
775 if (gtk_tree_model_get_iter(model, &iter, cdd->click_tpath)) | |
776 { | |
777 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
778 have_dest = TRUE; | |
779 } | |
780 } | |
781 | |
782 if (cdd->edit_existing && !have_dest) return; | |
783 | |
784 keywords = keyword_list_pull(cdd->edit_widget); | |
785 | |
786 if (cdd->edit_existing) | |
787 { | |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
788 if (keywords && keywords->data && /* there should be one keyword */ |
1465 | 789 !keyword_exists(keyword_tree, NULL, &kw_iter, keywords->data, TRUE, NULL)) |
1421 | 790 { |
791 keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, keywords->data, cdd->is_keyword); | |
792 } | |
793 } | |
794 else | |
795 { | |
796 GList *work = keywords; | |
797 | |
798 while (work) | |
799 { | |
800 GtkTreeIter add; | |
1465 | 801 if (keyword_exists(keyword_tree, NULL, have_dest ? &kw_iter : NULL, work->data, FALSE, NULL)) |
1429
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
802 { |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
803 work = work->next; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
804 continue; |
985366bccfb8
do not allow to add keywords with the same name as siblings
nadvornik
parents:
1428
diff
changeset
|
805 } |
1421 | 806 if (have_dest) |
807 { | |
808 gtk_tree_store_insert_after(GTK_TREE_STORE(keyword_tree), &add, NULL, &kw_iter); | |
809 } | |
810 else | |
811 { | |
812 gtk_tree_store_append(GTK_TREE_STORE(keyword_tree), &add, NULL); | |
813 have_dest = TRUE; | |
814 } | |
815 kw_iter = add; | |
816 keyword_set(GTK_TREE_STORE(keyword_tree), &kw_iter, work->data, cdd->is_keyword); | |
817 work = work->next; | |
818 } | |
819 } | |
820 string_list_free(keywords); | |
821 } | |
822 | |
823 static void bar_pane_keywords_conf_set_helper(GtkWidget *widget, gpointer data) | |
824 { | |
825 ConfDialogData *cdd = data; | |
826 cdd->is_keyword = FALSE; | |
827 } | |
828 | |
829 static void bar_pane_keywords_conf_set_kw(GtkWidget *widget, gpointer data) | |
1414 | 830 { |
1421 | 831 ConfDialogData *cdd = data; |
832 cdd->is_keyword = TRUE; | |
833 } | |
834 | |
835 | |
836 | |
837 static void bar_pane_keywords_edit_dialog(PaneKeywordsData *pkd, gboolean edit_existing) | |
838 { | |
839 ConfDialogData *cdd; | |
840 GenericDialog *gd; | |
841 GtkWidget *table; | |
842 GtkWidget *group; | |
843 GtkWidget *button; | |
844 | |
845 gchar *name = NULL; | |
846 gboolean is_keyword = TRUE; | |
847 | |
848 | |
849 if (edit_existing && pkd->click_tpath) | |
850 { | |
851 GtkTreeModel *model; | |
852 GtkTreeIter iter; | |
853 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
854 | |
855 if (gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) | |
856 { | |
857 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, | |
858 FILTER_KEYWORD_COLUMN_IS_KEYWORD, &is_keyword, -1); | |
859 } | |
860 else | |
861 { | |
862 return; | |
863 } | |
864 } | |
865 | |
866 if (edit_existing && !name) return; | |
867 | |
868 | |
869 cdd = g_new0(ConfDialogData, 1); | |
870 cdd->pkd =pkd; | |
871 cdd->click_tpath = pkd->click_tpath; | |
872 pkd->click_tpath = NULL; | |
873 cdd->edit_existing = edit_existing; | |
874 | |
875 cdd->gd = gd = generic_dialog_new(name ? _("Edit keyword") : _("Add keywords"), "keyword_edit", | |
876 pkd->widget, TRUE, | |
877 bar_pane_keywords_edit_cancel_cb, cdd); | |
878 g_signal_connect(G_OBJECT(gd->dialog), "destroy", | |
879 G_CALLBACK(bar_pane_keywords_edit_destroy_cb), cdd); | |
880 | |
881 | |
882 generic_dialog_add_message(gd, NULL, name ? _("Configure keyword") : _("Add keyword"), NULL); | |
883 | |
884 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, | |
885 bar_pane_keywords_edit_ok_cb, TRUE); | |
886 | |
887 table = pref_table_new(gd->vbox, 3, 1, FALSE, TRUE); | |
888 pref_table_label(table, 0, 0, _("Keyword:"), 1.0); | |
889 cdd->edit_widget = gtk_entry_new(); | |
890 gtk_widget_set_size_request(cdd->edit_widget, 300, -1); | |
891 if (name) gtk_entry_set_text(GTK_ENTRY(cdd->edit_widget), name); | |
892 gtk_table_attach_defaults(GTK_TABLE(table), cdd->edit_widget, 1, 2, 0, 1); | |
893 /* here could eventually be a text view instead of entry */ | |
894 generic_dialog_attach_default(gd, cdd->edit_widget); | |
895 gtk_widget_show(cdd->edit_widget); | |
896 | |
897 group = pref_group_new(gd->vbox, FALSE, _("Keyword type:"), GTK_ORIENTATION_VERTICAL); | |
898 | |
899 button = pref_radiobutton_new(group, NULL, _("Active keyword"), | |
1526 | 900 (is_keyword), |
1421 | 901 G_CALLBACK(bar_pane_keywords_conf_set_kw), cdd); |
902 button = pref_radiobutton_new(group, button, _("Helper"), | |
1526 | 903 (!is_keyword), |
1421 | 904 G_CALLBACK(bar_pane_keywords_conf_set_helper), cdd); |
1526 | 905 |
906 cdd->is_keyword = is_keyword; | |
907 | |
1421 | 908 g_free(name); |
909 | |
1525 | 910 gtk_widget_grab_focus(cdd->edit_widget); |
911 | |
1421 | 912 gtk_widget_show(gd->dialog); |
913 } | |
914 | |
915 | |
916 | |
917 | |
918 /* | |
919 *------------------------------------------------------------------- | |
920 * popup menu | |
921 *------------------------------------------------------------------- | |
922 */ | |
923 | |
924 static void bar_pane_keywords_edit_dialog_cb(GtkWidget *menu_widget, gpointer data) | |
925 { | |
926 PaneKeywordsData *pkd = data; | |
927 bar_pane_keywords_edit_dialog(pkd, TRUE); | |
928 } | |
929 | |
930 static void bar_pane_keywords_add_dialog_cb(GtkWidget *menu_widget, gpointer data) | |
931 { | |
932 PaneKeywordsData *pkd = data; | |
933 bar_pane_keywords_edit_dialog(pkd, FALSE); | |
1414 | 934 } |
935 | |
1425 | 936 static void bar_pane_keywords_connect_mark_cb(GtkWidget *menu_widget, gpointer data) |
937 { | |
938 PaneKeywordsData *pkd = data; | |
939 | |
940 GtkTreeModel *model; | |
941 GtkTreeIter iter; | |
942 | |
943 GtkTreeModel *keyword_tree; | |
944 GtkTreeIter kw_iter; | |
945 | |
946 gint mark = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_widget), "mark")) - 1; | |
947 | |
948 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
949 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
950 | |
951 if (!pkd->click_tpath) return; | |
952 if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return; | |
953 | |
954 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
955 | |
956 file_data_unregister_notify_func(bar_pane_keywords_notify_cb, pkd); | |
957 | |
958 meta_data_connect_mark_with_keyword(keyword_tree, &kw_iter, mark); | |
959 | |
960 file_data_register_notify_func(bar_pane_keywords_notify_cb, pkd, NOTIFY_PRIORITY_LOW); | |
961 // bar_pane_keywords_update(pkd); | |
962 } | |
963 | |
964 | |
1414 | 965 static void bar_pane_keywords_delete_cb(GtkWidget *menu_widget, gpointer data) |
966 { | |
967 PaneKeywordsData *pkd = data; | |
968 GtkTreeModel *model; | |
969 GtkTreeIter iter; | |
970 | |
971 GtkTreeModel *keyword_tree; | |
972 GtkTreeIter kw_iter; | |
973 | |
974 if (!pkd->click_tpath) return; | |
975 | |
976 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
977 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
978 | |
979 if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return; | |
980 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
981 | |
982 keyword_delete(GTK_TREE_STORE(keyword_tree), &kw_iter); | |
983 } | |
984 | |
1428 | 985 static void bar_pane_keywords_hide_cb(GtkWidget *menu_widget, gpointer data) |
986 { | |
987 PaneKeywordsData *pkd = data; | |
988 GtkTreeModel *model; | |
989 GtkTreeIter iter; | |
990 | |
991 GtkTreeModel *keyword_tree; | |
992 GtkTreeIter kw_iter; | |
993 | |
994 if (!pkd->click_tpath) return; | |
995 | |
996 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
997 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
998 | |
999 if (!gtk_tree_model_get_iter(model, &iter, pkd->click_tpath)) return; | |
1000 gtk_tree_model_filter_convert_iter_to_child_iter(GTK_TREE_MODEL_FILTER(model), &kw_iter, &iter); | |
1001 | |
1002 keyword_hide_in(GTK_TREE_STORE(keyword_tree), &kw_iter, model); | |
1003 } | |
1004 | |
1005 static void bar_pane_keywords_show_all_cb(GtkWidget *menu_widget, gpointer data) | |
1006 { | |
1007 PaneKeywordsData *pkd = data; | |
1008 GtkTreeModel *model; | |
1009 | |
1010 GtkTreeModel *keyword_tree; | |
1011 | |
1012 pkd->hide_unchecked = FALSE; | |
1013 | |
1014 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1015 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
1016 | |
1017 keyword_show_all_in(GTK_TREE_STORE(keyword_tree), model); | |
1430 | 1018 |
1019 if (!pkd->collapse_unchecked) gtk_tree_view_expand_all(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1428 | 1020 bar_keyword_tree_sync(pkd); |
1021 } | |
1022 | |
1023 static void bar_pane_keywords_expand_checked_cb(GtkWidget *menu_widget, gpointer data) | |
1024 { | |
1025 PaneKeywordsData *pkd = data; | |
1026 GtkTreeModel *model; | |
1027 | |
1028 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1029 gtk_tree_model_foreach(model, bar_keyword_tree_expand_if_set_cb, pkd); | |
1030 } | |
1031 | |
1032 static void bar_pane_keywords_collapse_unchecked_cb(GtkWidget *menu_widget, gpointer data) | |
1033 { | |
1034 PaneKeywordsData *pkd = data; | |
1035 GtkTreeModel *model; | |
1036 | |
1037 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1038 gtk_tree_model_foreach(model, bar_keyword_tree_collapse_if_unset_cb, pkd); | |
1039 } | |
1040 | |
1041 static void bar_pane_keywords_hide_unchecked_cb(GtkWidget *menu_widget, gpointer data) | |
1042 { | |
1043 PaneKeywordsData *pkd = data; | |
1044 GtkTreeModel *model; | |
1045 | |
1046 GtkTreeModel *keyword_tree; | |
1047 GList *keywords; | |
1048 | |
1049 model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); | |
1050 keyword_tree = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(model)); | |
1051 | |
1052 keywords = keyword_list_pull(pkd->keyword_view); | |
1053 keyword_hide_unset_in(GTK_TREE_STORE(keyword_tree), model, keywords); | |
1054 string_list_free(keywords); | |
1055 bar_keyword_tree_sync(pkd); | |
1056 } | |
1057 | |
1058 static void bar_pane_keywords_expand_checked_toggle_cb(GtkWidget *menu_widget, gpointer data) | |
1059 { | |
1060 PaneKeywordsData *pkd = data; | |
1061 pkd->expand_checked = !pkd->expand_checked; | |
1062 bar_keyword_tree_sync(pkd); | |
1063 } | |
1064 | |
1065 static void bar_pane_keywords_collapse_unchecked_toggle_cb(GtkWidget *menu_widget, gpointer data) | |
1066 { | |
1067 PaneKeywordsData *pkd = data; | |
1068 pkd->collapse_unchecked = !pkd->collapse_unchecked; | |
1069 bar_keyword_tree_sync(pkd); | |
1070 } | |
1071 | |
1072 static void bar_pane_keywords_hide_unchecked_toggle_cb(GtkWidget *menu_widget, gpointer data) | |
1073 { | |
1074 PaneKeywordsData *pkd = data; | |
1075 pkd->hide_unchecked = !pkd->hide_unchecked; | |
1076 bar_keyword_tree_sync(pkd); | |
1077 } | |
1078 | |
1414 | 1079 static void bar_pane_keywords_menu_popup(GtkWidget *widget, PaneKeywordsData *pkd, gint x, gint y) |
1080 { | |
1081 GtkWidget *menu; | |
1428 | 1082 GtkWidget *item; |
1083 GtkWidget *submenu; | |
1414 | 1084 GtkTreeViewDropPosition pos; |
1085 | |
1086 if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath); | |
1087 pkd->click_tpath = NULL; | |
1088 gtk_tree_view_get_dest_row_at_pos(GTK_TREE_VIEW(pkd->keyword_treeview), x, y, &pkd->click_tpath, &pos); | |
1089 | |
1090 menu = popup_menu_short_lived(); | |
1091 | |
1092 if (pkd->click_tpath) | |
1093 { | |
1094 /* for the entry */ | |
1425 | 1095 gchar *text; |
1096 gchar *mark; | |
1097 gint i; | |
1098 | |
1414 | 1099 GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(pkd->keyword_treeview)); |
1100 | |
1101 GtkTreeIter iter; | |
1102 gtk_tree_model_get_iter(model, &iter, pkd->click_tpath); | |
1103 gchar *name; | |
1104 | |
1425 | 1105 gtk_tree_model_get(model, &iter, FILTER_KEYWORD_COLUMN_NAME, &name, |
1106 FILTER_KEYWORD_COLUMN_MARK, &mark, -1); | |
1107 | |
1428 | 1108 text = g_strdup_printf(_("Hide \"%s\""), name); |
1109 menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_hide_cb), pkd); | |
1425 | 1110 g_free(text); |
1414 | 1111 |
1425 | 1112 submenu = gtk_menu_new(); |
1113 for (i = 0; i < FILEDATA_MARKS_SIZE; i++) | |
1114 { | |
1115 text = g_strdup_printf(_("Mark %d"), i + 1); | |
1116 item = menu_item_add(submenu, text, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd); | |
1117 g_object_set_data(G_OBJECT(item), "mark", GINT_TO_POINTER(i + 1)); | |
1118 g_free(text); | |
1119 } | |
1120 text = g_strdup_printf(_("Connect \"%s\" to mark"), name); | |
1121 item = menu_item_add(menu, text, NULL, NULL); | |
1122 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
1123 g_free(text); | |
1428 | 1124 |
1125 menu_item_add_divider(menu); | |
1126 | |
1127 text = g_strdup_printf(_("Edit \"%s\""), name); | |
1128 menu_item_add_stock(menu, text, GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_edit_dialog_cb), pkd); | |
1129 g_free(text); | |
1130 text = g_strdup_printf(_("Delete \"%s\""), name); | |
1131 menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_delete_cb), pkd); | |
1132 g_free(text); | |
1133 | |
1425 | 1134 |
1135 if (mark && mark[0]) | |
1136 { | |
1137 text = g_strdup_printf(_("Disconnect \"%s\" from mark %s"), name, mark); | |
1138 menu_item_add_stock(menu, text, GTK_STOCK_DELETE, G_CALLBACK(bar_pane_keywords_connect_mark_cb), pkd); | |
1139 g_free(text); | |
1140 } | |
1141 | |
1414 | 1142 menu_item_add_divider(menu); |
1425 | 1143 g_free(mark); |
1414 | 1144 g_free(name); |
1145 } | |
1146 /* for the pane */ | |
1428 | 1147 |
1148 | |
1149 menu_item_add(menu, _("Expand checked"), G_CALLBACK(bar_pane_keywords_expand_checked_cb), pkd); | |
1150 menu_item_add(menu, _("Collapse unchecked"), G_CALLBACK(bar_pane_keywords_collapse_unchecked_cb), pkd); | |
1151 menu_item_add(menu, _("Hide unchecked"), G_CALLBACK(bar_pane_keywords_hide_unchecked_cb), pkd); | |
1152 menu_item_add(menu, _("Show all"), G_CALLBACK(bar_pane_keywords_show_all_cb), pkd); | |
1153 | |
1154 submenu = gtk_menu_new(); | |
1155 item = menu_item_add(menu, _("On any change"), NULL, NULL); | |
1156 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
1157 | |
1158 menu_item_add_check(submenu, _("Expand checked"), pkd->expand_checked, G_CALLBACK(bar_pane_keywords_expand_checked_toggle_cb), pkd); | |
1159 menu_item_add_check(submenu, _("Collapse unchecked"), pkd->collapse_unchecked, G_CALLBACK(bar_pane_keywords_collapse_unchecked_toggle_cb), pkd); | |
1160 menu_item_add_check(submenu, _("Hide unchecked"), pkd->hide_unchecked, G_CALLBACK(bar_pane_keywords_hide_unchecked_toggle_cb), pkd); | |
1161 | |
1162 menu_item_add_divider(menu); | |
1163 | |
1421 | 1164 menu_item_add_stock(menu, _("Add keyword"), GTK_STOCK_EDIT, G_CALLBACK(bar_pane_keywords_add_dialog_cb), pkd); |
1414 | 1165 |
1166 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, GDK_CURRENT_TIME); | |
1167 } | |
1168 | |
1169 | |
1170 static gboolean bar_pane_keywords_menu_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1171 { | |
1172 PaneKeywordsData *pkd = data; | |
1173 if (bevent->button == MOUSE_BUTTON_RIGHT) | |
1174 { | |
1175 bar_pane_keywords_menu_popup(widget, pkd, bevent->x, bevent->y); | |
1176 return TRUE; | |
1177 } | |
1178 return FALSE; | |
1179 } | |
1180 | |
1421 | 1181 /* |
1182 *------------------------------------------------------------------- | |
1183 * init | |
1184 *------------------------------------------------------------------- | |
1185 */ | |
1392 | 1186 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1187 void bar_pane_keywords_close(GtkWidget *bar) |
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 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1190 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1191 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
|
1192 if (!pkd) return; |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1193 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1194 g_free(pkd->pane.id); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1195 gtk_widget_destroy(pkd->widget); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1196 } |
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 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
|
1199 { |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1200 PaneKeywordsData *pkd = data; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1201 |
1414 | 1202 if (pkd->click_tpath) gtk_tree_path_free(pkd->click_tpath); |
1523 | 1203 if (pkd->idle_id) g_source_remove(pkd->idle_id); |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1204 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
|
1205 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1206 file_data_unref(pkd->fd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1207 g_free(pkd->key); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1208 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1209 g_free(pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1210 } |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1211 |
1391 | 1212 |
1485 | 1213 static GtkWidget *bar_pane_keywords_new(const gchar *id, const gchar *title, const gchar *key, gboolean expanded) |
1291
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 PaneKeywordsData *pkd; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1216 GtkWidget *hbox; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1217 GtkWidget *scrolled; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1218 GtkTextBuffer *buffer; |
1391 | 1219 GtkTreeModel *store; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1220 GtkTreeViewColumn *column; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1221 GtkCellRenderer *renderer; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1222 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1223 pkd = g_new0(PaneKeywordsData, 1); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1224 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1225 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
|
1226 pkd->pane.pane_event = bar_pane_keywords_event; |
1309 | 1227 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
|
1228 pkd->pane.title = bar_pane_expander_title(title); |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1229 pkd->pane.id = g_strdup(id); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1230 pkd->pane.type = PANE_KEYWORDS; |
1387 | 1231 |
1309 | 1232 pkd->pane.expanded = expanded; |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1233 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1234 pkd->key = g_strdup(key); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1235 |
1428 | 1236 pkd->expand_checked = TRUE; |
1455 | 1237 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1238 hbox = gtk_hbox_new(FALSE, PREF_PAD_GAP); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1239 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1240 pkd->widget = hbox; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1241 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
|
1242 g_signal_connect(G_OBJECT(pkd->widget), "destroy", |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1243 G_CALLBACK(bar_pane_keywords_destroy), pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1244 gtk_widget_show(hbox); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1245 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1246 scrolled = gtk_scrolled_window_new(NULL, NULL); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1247 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
|
1248 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1249 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1250 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
|
1251 gtk_widget_show(scrolled); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1252 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1253 pkd->keyword_view = gtk_text_view_new(); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1254 gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1255 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
|
1256 G_CALLBACK(bar_pane_keywords_populate_popup_cb), pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1257 gtk_widget_show(pkd->keyword_view); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1258 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1259 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
|
1260 g_signal_connect(G_OBJECT(buffer), "changed", |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1261 G_CALLBACK(bar_pane_keywords_changed), pkd); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1262 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1263 scrolled = gtk_scrolled_window_new(NULL, NULL); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1264 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
|
1265 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1266 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1267 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
|
1268 gtk_widget_show(scrolled); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1269 |
1391 | 1270 |
1271 if (!keyword_tree) keyword_tree_new_default(); | |
1272 | |
1273 store = gtk_tree_model_filter_new(GTK_TREE_MODEL(keyword_tree), NULL); | |
1274 | |
1275 gtk_tree_model_filter_set_modify_func(GTK_TREE_MODEL_FILTER(store), | |
1276 FILTER_KEYWORD_COLUMN_COUNT, | |
1277 filter_keyword_column_types, | |
1278 bar_pane_keywords_filter_modify, | |
1279 pkd, | |
1280 NULL); | |
1428 | 1281 gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(store), |
1282 bar_pane_keywords_filter_visible, | |
1283 store, | |
1284 NULL); | |
1391 | 1285 |
1286 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
|
1287 g_object_unref(store); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1288 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1289 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
|
1290 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1291 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
|
1292 |
1391 | 1293 // 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
|
1294 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1295 column = gtk_tree_view_column_new(); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1296 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
|
1297 |
1425 | 1298 renderer = gtk_cell_renderer_text_new(); |
1299 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
|
1300 |
1391 | 1301 gtk_tree_view_column_add_attribute(column, renderer, "text", FILTER_KEYWORD_COLUMN_MARK); |
1425 | 1302 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1303 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
|
1304 |
1391 | 1305 column = gtk_tree_view_column_new(); |
1306 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1307 renderer = gtk_cell_renderer_toggle_new(); | |
1308 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1309 gtk_tree_view_column_add_attribute(column, renderer, "active", FILTER_KEYWORD_COLUMN_TOGGLE); | |
1310 gtk_tree_view_column_add_attribute(column, renderer, "visible", FILTER_KEYWORD_COLUMN_IS_KEYWORD); | |
1311 g_signal_connect(G_OBJECT(renderer), "toggled", | |
1312 G_CALLBACK(bar_pane_keywords_keyword_toggle), pkd); | |
1313 | |
1314 renderer = gtk_cell_renderer_text_new(); | |
1315 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1316 gtk_tree_view_column_add_attribute(column, renderer, "text", FILTER_KEYWORD_COLUMN_NAME); | |
1317 | |
1318 gtk_tree_view_append_column(GTK_TREE_VIEW(pkd->keyword_treeview), column); | |
1319 gtk_tree_view_set_expander_column(GTK_TREE_VIEW(pkd->keyword_treeview), column); | |
1320 | |
1392 | 1321 gtk_drag_source_set(pkd->keyword_treeview, |
1322 GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
1323 bar_pane_keywords_drag_types, n_keywords_drag_types, | |
1324 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
1325 | |
1326 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_data_get", | |
1327 G_CALLBACK(bar_pane_keywords_dnd_get), pkd); | |
1328 | |
1329 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_begin", | |
1330 G_CALLBACK(bar_pane_keywords_dnd_begin), pkd); | |
1331 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_end", | |
1332 G_CALLBACK(bar_pane_keywords_dnd_end), pkd); | |
1333 | |
1334 gtk_drag_dest_set(pkd->keyword_treeview, | |
1335 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, | |
1336 bar_pane_keywords_drop_types, n_keywords_drop_types, | |
1337 GDK_ACTION_COPY | GDK_ACTION_MOVE); | |
1338 | |
1339 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_data_received", | |
1340 G_CALLBACK(bar_pane_keywords_dnd_receive), pkd); | |
1341 | |
1342 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "drag_motion", | |
1343 G_CALLBACK(bar_pane_keywords_dnd_motion), pkd); | |
1344 | |
1414 | 1345 g_signal_connect(G_OBJECT(pkd->keyword_treeview), "button_press_event", |
1346 G_CALLBACK(bar_pane_keywords_menu_cb), pkd); | |
1347 | |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1348 gtk_container_add(GTK_CONTAINER(scrolled), pkd->keyword_treeview); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1349 gtk_widget_show(pkd->keyword_treeview); |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1350 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1351 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
|
1352 |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1353 return pkd->widget; |
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1354 } |
1309 | 1355 |
1356 GtkWidget *bar_pane_keywords_new_from_config(const gchar **attribute_names, const gchar **attribute_values) | |
1357 { | |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1358 gchar *id = g_strdup("keywords"); |
1471 | 1359 gchar *title = NULL; |
1309 | 1360 gchar *key = g_strdup(COMMENT_KEY); |
1361 gboolean expanded = TRUE; | |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1362 GtkWidget *ret; |
1309 | 1363 |
1364 while (*attribute_names) | |
1365 { | |
1366 const gchar *option = *attribute_names++; | |
1367 const gchar *value = *attribute_values++; | |
1368 | |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1369 if (READ_CHAR_FULL("id", id)) continue; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1370 if (READ_CHAR_FULL("title", title)) continue; |
1315 | 1371 if (READ_CHAR_FULL("key", key)) continue; |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1372 if (READ_BOOL_FULL("expanded", expanded)) continue; |
1309 | 1373 |
1374 | |
1464 | 1375 log_printf("unknown attribute %s = %s\n", option, value); |
1309 | 1376 } |
1377 | |
1471 | 1378 bar_pane_translate_title(PANE_KEYWORDS, id, &title); |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1379 ret = bar_pane_keywords_new(id, title, key, expanded); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1380 g_free(id); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1381 g_free(title); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1382 g_free(key); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1383 return ret; |
1309 | 1384 } |
1385 | |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1386 void bar_pane_keywords_update_from_config(GtkWidget *pane, const gchar **attribute_names, const gchar **attribute_values) |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1387 { |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1388 PaneKeywordsData *pkd; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1389 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1390 pkd = g_object_get_data(G_OBJECT(pane), "pane_data"); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1391 if (!pkd) return; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1392 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1393 gchar *title = NULL; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1394 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1395 while (*attribute_names) |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1396 { |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1397 const gchar *option = *attribute_names++; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1398 const gchar *value = *attribute_values++; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1399 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1400 if (READ_CHAR_FULL("title", title)) continue; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1401 if (READ_CHAR_FULL("key", pkd->key)) continue; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1402 if (READ_BOOL_FULL("expanded", pkd->pane.expanded)) continue; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1403 if (READ_CHAR_FULL("id", pkd->pane.id)) continue; |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1404 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1405 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1406 log_printf("unknown attribute %s = %s\n", option, value); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1407 } |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1408 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1409 if (title) |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1410 { |
1471 | 1411 bar_pane_translate_title(PANE_KEYWORDS, pkd->pane.id, &title); |
1469
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1412 gtk_label_set_text(GTK_LABEL(pkd->pane.title), title); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1413 g_free(title); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1414 } |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1415 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1416 bar_update_expander(pane); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1417 bar_pane_keywords_update(pkd); |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1418 } |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1419 |
607c60506863
added a possibility to update existing bars from config
nadvornik
parents:
1465
diff
changeset
|
1420 |
1291
50ae02a4a675
replaced bar_info with an universal bar, restored the original
nadvornik
parents:
diff
changeset
|
1421 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |