Mercurial > geeqie
annotate src/desktop_file.c @ 1491:f057c235426f
Fix up previous patch.
author | zas_ |
---|---|
date | Mon, 30 Mar 2009 17:52:14 +0000 |
parents | b924293cf6c8 |
children | 03c22c05c6b6 |
rev | line source |
---|---|
1479 | 1 /* |
2 * Geeqie | |
3 * (C) 2004 John Ellis | |
4 * Copyright (C) 2008 - 2009 The Geeqie Team | |
5 * | |
6 * Author: Vladimir Nadvornik | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 #include "main.h" | |
14 #include "desktop_file.h" | |
15 | |
16 #include "editors.h" | |
17 #include "filedata.h" | |
18 #include "misc.h" | |
19 #include "ui_misc.h" | |
20 #include "ui_fileops.h" | |
21 #include "ui_utildlg.h" | |
22 #include "pixbuf_util.h" | |
23 #include "window.h" | |
24 #include "utilops.h" | |
25 #include "layout_util.h" | |
26 | |
27 #define CONFIG_WINDOW_DEF_WIDTH 700 | |
28 #define CONFIG_WINDOW_DEF_HEIGHT 400 | |
29 | |
30 | |
31 | |
32 typedef struct _EditorWindow EditorWindow; | |
33 struct _EditorWindow | |
34 { | |
35 GtkWidget *window; | |
36 GtkWidget *entry; | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
37 GtkWidget *save_button; |
1479 | 38 GtkTextBuffer *buffer; |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
39 gchar *desktop_name; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
40 gboolean modified; |
1479 | 41 }; |
42 | |
43 | |
44 static GtkWidget *editor_list_window = NULL; | |
45 GtkWidget *editor_list_view = NULL; | |
46 | |
47 | |
48 static gboolean editor_window_save(EditorWindow *ew) | |
49 { | |
50 gchar *path; | |
51 gchar *text; | |
52 GtkTextIter start, end; | |
53 GError *error = NULL; | |
54 gboolean ret = TRUE; | |
55 const gchar *name = gtk_entry_get_text(GTK_ENTRY(ew->entry)); | |
56 | |
57 if (!name || !name[0]) | |
58 { | |
59 file_util_warning_dialog(_("Can't save"), _("Please specify file name."), GTK_STOCK_DIALOG_ERROR, NULL); | |
60 return FALSE; | |
61 } | |
62 | |
63 gtk_text_buffer_get_bounds(ew->buffer, &start, &end); | |
64 text = gtk_text_buffer_get_text(ew->buffer, &start, &end, FALSE); | |
65 | |
66 path = g_build_filename(get_rc_dir(), "applications", name, NULL); | |
67 | |
68 if (!g_file_set_contents(path, text, -1, &error)) | |
69 { | |
70 file_util_warning_dialog(_("Can't save"), error->message, GTK_STOCK_DIALOG_ERROR, NULL); | |
71 g_error_free(error); | |
72 ret = FALSE; | |
73 } | |
74 | |
75 g_free(path); | |
76 g_free(text); | |
77 layout_editors_reload_all(); | |
78 return ret; | |
79 } | |
80 | |
81 static void editor_window_close_cb(GtkWidget *widget, gpointer data) | |
82 { | |
83 EditorWindow *ew = data; | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
84 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
85 g_free(ew->desktop_name); |
1479 | 86 gtk_widget_destroy(ew->window); |
87 g_free(ew); | |
88 } | |
89 | |
90 static gint editor_window_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
91 { | |
92 editor_window_close_cb(w, data); | |
93 return TRUE; | |
94 } | |
95 | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
96 static void editor_window_save_cb(GtkWidget *widget, gpointer data) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
97 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
98 EditorWindow *ew = data; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
99 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
100 if (ew->modified) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
101 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
102 editor_window_save(ew); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
103 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
104 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
105 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
106 static void editor_window_text_modified_cb(GtkWidget *widget, gpointer data) |
1479 | 107 { |
108 EditorWindow *ew = data; | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
109 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
110 if (gtk_text_buffer_get_modified(ew->buffer)) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
111 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
112 gtk_widget_set_sensitive(ew->save_button, TRUE); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
113 ew->modified = TRUE; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
114 } |
1479 | 115 } |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
116 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
117 static void editor_window_entry_changed_cb(GtkWidget *widget, gpointer data) |
1479 | 118 { |
119 EditorWindow *ew = data; | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
120 const gchar *content = gtk_entry_get_text(GTK_ENTRY(ew->entry)); |
1491 | 121 gboolean modified = ew->modified; |
122 | |
123 if (!modified) | |
124 { | |
125 modified = (!ew->desktop_name && *content); | |
126 } | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
127 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
128 if (!modified) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
129 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
130 modified = strcmp(ew->desktop_name, content); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
131 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
132 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
133 gtk_widget_set_sensitive(ew->save_button, modified); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
134 ew->modified = modified; |
1479 | 135 } |
136 | |
137 static void editor_window_new(const gchar *src_path, const gchar *desktop_name) | |
138 { | |
139 EditorWindow *ew; | |
140 GtkWidget *win_vbox; | |
141 GtkWidget *hbox; | |
142 GtkWidget *button; | |
143 GtkWidget *ct_button; | |
144 GtkWidget *button_hbox; | |
145 GtkWidget *scrolled; | |
146 GtkWidget *text_view; | |
147 gchar *text; | |
148 gsize size; | |
149 | |
150 ew = g_new0(EditorWindow, 1); | |
151 | |
152 | |
153 ew->window = window_new(GTK_WINDOW_TOPLEVEL, "Desktop", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Desktop file")); | |
154 gtk_window_set_type_hint(GTK_WINDOW(ew->window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
155 | |
156 g_signal_connect(G_OBJECT(ew->window), "delete_event", | |
157 G_CALLBACK(editor_window_delete_cb), ew); | |
158 | |
159 gtk_window_set_default_size(GTK_WINDOW(ew->window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); | |
160 gtk_window_set_resizable(GTK_WINDOW(ew->window), TRUE); | |
161 gtk_container_set_border_width(GTK_CONTAINER(ew->window), PREF_PAD_BORDER); | |
162 | |
163 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
164 gtk_container_add(GTK_CONTAINER(ew->window), win_vbox); | |
165 gtk_widget_show(win_vbox); | |
166 | |
167 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
168 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
169 gtk_widget_show(hbox); | |
170 | |
171 ew->entry = gtk_entry_new(); | |
172 gtk_box_pack_start(GTK_BOX(hbox), ew->entry, TRUE, TRUE, 0); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
173 ew->desktop_name = NULL; |
1479 | 174 if (desktop_name) |
175 { | |
176 gtk_entry_set_text(GTK_ENTRY(ew->entry), desktop_name); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
177 ew->desktop_name = g_strdup(desktop_name); |
1479 | 178 } |
179 gtk_widget_show(ew->entry); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
180 g_signal_connect(G_OBJECT(ew->entry), "changed", G_CALLBACK(editor_window_entry_changed_cb), ew); |
1479 | 181 |
182 button_hbox = gtk_hbutton_box_new(); | |
183 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END); | |
184 gtk_box_set_spacing(GTK_BOX(button_hbox), PREF_PAD_BUTTON_GAP); | |
185 gtk_box_pack_end(GTK_BOX(hbox), button_hbox, FALSE, FALSE, 0); | |
186 gtk_widget_show(button_hbox); | |
187 | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
188 ew->save_button = pref_button_new(NULL, GTK_STOCK_SAVE, NULL, FALSE, |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
189 G_CALLBACK(editor_window_save_cb), ew); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
190 gtk_container_add(GTK_CONTAINER(button_hbox), ew->save_button); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
191 GTK_WIDGET_SET_FLAGS(ew->save_button, GTK_CAN_DEFAULT); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
192 gtk_widget_set_sensitive(ew->save_button, FALSE); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
193 gtk_widget_show(ew->save_button); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
194 ct_button = ew->save_button; |
1479 | 195 |
196 button = pref_button_new(NULL, GTK_STOCK_CANCEL, NULL, FALSE, | |
197 G_CALLBACK(editor_window_close_cb), ew); | |
198 gtk_container_add(GTK_CONTAINER(button_hbox), button); | |
199 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
200 gtk_widget_show(button); | |
201 | |
202 if (!generic_dialog_get_alternative_button_order(ew->window)) | |
203 { | |
204 gtk_box_reorder_child(GTK_BOX(button_hbox), ct_button, -1); | |
205 } | |
206 | |
207 | |
208 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
209 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
210 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
211 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
212 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
213 gtk_widget_show(scrolled); | |
214 | |
215 text_view = gtk_text_view_new(); | |
216 gtk_container_add(GTK_CONTAINER(scrolled), text_view); | |
217 gtk_widget_show(text_view); | |
218 | |
219 ew->buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); | |
220 if (g_file_get_contents(src_path, &text, &size, NULL)) | |
221 { | |
222 gtk_text_buffer_set_text(ew->buffer, text, size); | |
223 } | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
224 gtk_text_buffer_set_modified(ew->buffer, FALSE); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
225 g_signal_connect(G_OBJECT(ew->buffer), "modified-changed", |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
226 G_CALLBACK(editor_window_text_modified_cb), ew); |
1479 | 227 |
228 gtk_widget_show(ew->window); | |
229 } | |
230 | |
231 | |
232 static void editor_list_window_close_cb(GtkWidget *widget, gpointer data) | |
233 { | |
234 gtk_widget_destroy(editor_list_window); | |
235 editor_list_window = NULL; | |
236 editor_list_view = NULL; | |
237 } | |
238 | |
239 static gboolean editor_list_window_delete(GtkWidget *widget, GdkEventAny *event, gpointer data) | |
240 { | |
241 editor_list_window_close_cb(NULL, NULL); | |
242 return TRUE; | |
243 } | |
244 | |
245 static void editor_list_window_edit_cb(GtkWidget *widget, gpointer data) | |
246 { | |
247 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(editor_list_view)); | |
248 GtkTreeIter iter; | |
249 | |
250 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
251 { | |
252 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(editor_list_view)); | |
253 gchar *path; | |
254 gchar *key; | |
255 | |
256 gtk_tree_model_get(store, &iter, | |
257 DESKTOP_FILE_COLUMN_PATH, &path, | |
258 DESKTOP_FILE_COLUMN_KEY, &key, -1); | |
259 editor_window_new(path, key); | |
260 g_free(key); | |
261 g_free(path); | |
262 } | |
263 } | |
264 | |
265 static void editor_list_window_new_cb(GtkWidget *widget, gpointer data) | |
266 { | |
267 editor_window_new(DESKTOP_FILE_TEMPLATE, _("new.desktop")); | |
268 } | |
269 | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
270 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
271 static gint editor_list_window_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
272 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
273 gint n = GPOINTER_TO_INT(data); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
274 gint ret = 0; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
275 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
276 switch (n) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
277 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
278 case DESKTOP_FILE_COLUMN_KEY: |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
279 case DESKTOP_FILE_COLUMN_NAME: |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
280 case DESKTOP_FILE_COLUMN_PATH: |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
281 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
282 gchar *s1, *s2; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
283 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
284 gtk_tree_model_get(model, a, n, &s1, -1); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
285 gtk_tree_model_get(model, b, n, &s2, -1); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
286 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
287 if (!s1 || !s2) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
288 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
289 if (!s1 && !s2) break; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
290 ret = s1 ? 1 : -1; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
291 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
292 else |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
293 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
294 ret = g_utf8_collate(s1, s2); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
295 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
296 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
297 g_free(s1); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
298 g_free(s2); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
299 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
300 break; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
301 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
302 case DESKTOP_FILE_COLUMN_HIDDEN: |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
303 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
304 gint *v1, *v2; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
305 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
306 gtk_tree_model_get(model, a, n, &v1, -1); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
307 gtk_tree_model_get(model, b, n, &v2, -1); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
308 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
309 if (v1 == v2) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
310 ret = 0; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
311 else if (v1 < v2) |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
312 ret = 1; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
313 else |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
314 ret = -1; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
315 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
316 break; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
317 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
318 default: |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
319 g_return_val_if_reached(0); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
320 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
321 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
322 return ret; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
323 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
324 |
1479 | 325 static void editor_list_window_create(void) |
326 { | |
327 GtkWidget *win_vbox; | |
328 GtkWidget *hbox; | |
329 GtkWidget *button; | |
330 GtkWidget *scrolled; | |
331 GtkCellRenderer *renderer; | |
332 GtkTreeSelection *selection; | |
333 GtkTreeViewColumn *column; | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
334 GtkTreeModel *store; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
335 GtkTreeSortable *sortable; |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
336 |
1479 | 337 editor_list_window = window_new(GTK_WINDOW_TOPLEVEL, "editors", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Editors")); |
338 gtk_window_set_type_hint(GTK_WINDOW(editor_list_window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
339 g_signal_connect(G_OBJECT(editor_list_window), "delete_event", | |
340 G_CALLBACK(editor_list_window_delete), NULL); | |
341 gtk_window_set_default_size(GTK_WINDOW(editor_list_window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); | |
342 gtk_window_set_resizable(GTK_WINDOW(editor_list_window), TRUE); | |
343 gtk_container_set_border_width(GTK_CONTAINER(editor_list_window), PREF_PAD_BORDER); | |
344 | |
345 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
346 gtk_container_add(GTK_CONTAINER(editor_list_window), win_vbox); | |
347 gtk_widget_show(win_vbox); | |
348 | |
349 hbox = gtk_hbutton_box_new(); | |
350 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); | |
351 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_BUTTON_GAP); | |
352 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
353 gtk_widget_show(hbox); | |
354 | |
355 | |
356 button = pref_button_new(NULL, GTK_STOCK_NEW, NULL, FALSE, | |
357 G_CALLBACK(editor_list_window_new_cb), NULL); | |
358 gtk_container_add(GTK_CONTAINER(hbox), button); | |
359 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
360 gtk_widget_show(button); | |
361 | |
362 button = pref_button_new(NULL, GTK_STOCK_EDIT, NULL, FALSE, | |
363 G_CALLBACK(editor_list_window_edit_cb), NULL); | |
364 gtk_container_add(GTK_CONTAINER(hbox), button); | |
365 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
366 gtk_widget_show(button); | |
367 | |
368 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, | |
369 G_CALLBACK(editor_list_window_close_cb), NULL); | |
370 gtk_container_add(GTK_CONTAINER(hbox), button); | |
371 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
372 gtk_widget_show(button); | |
373 | |
374 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
375 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
376 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
377 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
378 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
379 gtk_widget_show(scrolled); | |
380 | |
381 editor_list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(desktop_file_list)); | |
382 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(editor_list_view)); | |
383 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
384 | |
385 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(editor_list_view), FALSE); | |
386 | |
387 column = gtk_tree_view_column_new(); | |
388 gtk_tree_view_column_set_title(column, _("Desktop file")); | |
389 gtk_tree_view_column_set_resizable(column, TRUE); | |
390 renderer = gtk_cell_renderer_text_new(); | |
391 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
392 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_KEY); | |
393 gtk_tree_view_append_column(GTK_TREE_VIEW(editor_list_view), column); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
394 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_KEY); |
1479 | 395 |
396 column = gtk_tree_view_column_new(); | |
397 gtk_tree_view_column_set_title(column, _("Hidden")); | |
398 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
399 renderer = gtk_cell_renderer_toggle_new(); | |
400 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
401 gtk_tree_view_column_add_attribute(column, renderer, "active", DESKTOP_FILE_COLUMN_HIDDEN); | |
402 gtk_tree_view_append_column(GTK_TREE_VIEW(editor_list_view), column); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
403 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_HIDDEN); |
1479 | 404 |
405 column = gtk_tree_view_column_new(); | |
406 gtk_tree_view_column_set_title(column, _("Name")); | |
407 gtk_tree_view_column_set_resizable(column, TRUE); | |
408 renderer = gtk_cell_renderer_text_new(); | |
409 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
410 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_NAME); | |
411 gtk_tree_view_append_column(GTK_TREE_VIEW(editor_list_view), column); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
412 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_NAME); |
1479 | 413 |
414 column = gtk_tree_view_column_new(); | |
415 gtk_tree_view_column_set_title(column, _("Path")); | |
416 gtk_tree_view_column_set_resizable(column, TRUE); | |
417 renderer = gtk_cell_renderer_text_new(); | |
418 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
419 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_PATH); | |
420 gtk_tree_view_append_column(GTK_TREE_VIEW(editor_list_view), column); | |
1490
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
421 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_PATH); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
422 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
423 /* set up sorting */ |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
424 store = gtk_tree_view_get_model(GTK_TREE_VIEW(editor_list_view)); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
425 sortable = GTK_TREE_SORTABLE(store); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
426 gtk_tree_sortable_set_sort_func(sortable, DESKTOP_FILE_COLUMN_KEY, editor_list_window_sort_cb, |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
427 GINT_TO_POINTER(DESKTOP_FILE_COLUMN_KEY), NULL); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
428 gtk_tree_sortable_set_sort_func(sortable, DESKTOP_FILE_COLUMN_HIDDEN, editor_list_window_sort_cb, |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
429 GINT_TO_POINTER(DESKTOP_FILE_COLUMN_HIDDEN), NULL); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
430 gtk_tree_sortable_set_sort_func(sortable, DESKTOP_FILE_COLUMN_NAME, editor_list_window_sort_cb, |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
431 GINT_TO_POINTER(DESKTOP_FILE_COLUMN_NAME), NULL); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
432 gtk_tree_sortable_set_sort_func(sortable, DESKTOP_FILE_COLUMN_PATH, editor_list_window_sort_cb, |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
433 GINT_TO_POINTER(DESKTOP_FILE_COLUMN_PATH), NULL); |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
434 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
435 /* set initial sort order */ |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
436 gtk_tree_sortable_set_sort_column_id(sortable, DESKTOP_FILE_COLUMN_KEY, GTK_SORT_ASCENDING); |
1479 | 437 |
438 gtk_container_add(GTK_CONTAINER(scrolled), editor_list_view); | |
439 gtk_widget_show(editor_list_view); | |
440 | |
441 gtk_widget_show(editor_list_window); | |
442 } | |
443 | |
444 /* | |
445 *----------------------------------------------------------------------------- | |
446 * config window show (public) | |
447 *----------------------------------------------------------------------------- | |
448 */ | |
449 | |
450 void show_editor_list_window(void) | |
451 { | |
452 if (editor_list_window) | |
453 { | |
454 gtk_window_present(GTK_WINDOW(editor_list_window)); | |
455 return; | |
456 } | |
457 | |
458 editor_list_window_create(); | |
459 } |