Mercurial > geeqie
annotate src/desktop_file.c @ 1490:b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
author | zas_ |
---|---|
date | Mon, 30 Mar 2009 17:05:31 +0000 |
parents | d062522699dc |
children | f057c235426f |
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)); |
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
|
121 gboolean modified = (!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
|
122 |
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
|
123 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
|
124 { |
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
|
125 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
|
126 } |
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 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
|
129 ew->modified = modified; |
1479 | 130 } |
131 | |
132 static void editor_window_new(const gchar *src_path, const gchar *desktop_name) | |
133 { | |
134 EditorWindow *ew; | |
135 GtkWidget *win_vbox; | |
136 GtkWidget *hbox; | |
137 GtkWidget *button; | |
138 GtkWidget *ct_button; | |
139 GtkWidget *button_hbox; | |
140 GtkWidget *scrolled; | |
141 GtkWidget *text_view; | |
142 gchar *text; | |
143 gsize size; | |
144 | |
145 ew = g_new0(EditorWindow, 1); | |
146 | |
147 | |
148 ew->window = window_new(GTK_WINDOW_TOPLEVEL, "Desktop", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Desktop file")); | |
149 gtk_window_set_type_hint(GTK_WINDOW(ew->window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
150 | |
151 g_signal_connect(G_OBJECT(ew->window), "delete_event", | |
152 G_CALLBACK(editor_window_delete_cb), ew); | |
153 | |
154 gtk_window_set_default_size(GTK_WINDOW(ew->window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); | |
155 gtk_window_set_resizable(GTK_WINDOW(ew->window), TRUE); | |
156 gtk_container_set_border_width(GTK_CONTAINER(ew->window), PREF_PAD_BORDER); | |
157 | |
158 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
159 gtk_container_add(GTK_CONTAINER(ew->window), win_vbox); | |
160 gtk_widget_show(win_vbox); | |
161 | |
162 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
163 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
164 gtk_widget_show(hbox); | |
165 | |
166 ew->entry = gtk_entry_new(); | |
167 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
|
168 ew->desktop_name = NULL; |
1479 | 169 if (desktop_name) |
170 { | |
171 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
|
172 ew->desktop_name = g_strdup(desktop_name); |
1479 | 173 } |
174 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
|
175 g_signal_connect(G_OBJECT(ew->entry), "changed", G_CALLBACK(editor_window_entry_changed_cb), ew); |
1479 | 176 |
177 button_hbox = gtk_hbutton_box_new(); | |
178 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END); | |
179 gtk_box_set_spacing(GTK_BOX(button_hbox), PREF_PAD_BUTTON_GAP); | |
180 gtk_box_pack_end(GTK_BOX(hbox), button_hbox, FALSE, FALSE, 0); | |
181 gtk_widget_show(button_hbox); | |
182 | |
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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 ct_button = ew->save_button; |
1479 | 190 |
191 button = pref_button_new(NULL, GTK_STOCK_CANCEL, NULL, FALSE, | |
192 G_CALLBACK(editor_window_close_cb), ew); | |
193 gtk_container_add(GTK_CONTAINER(button_hbox), button); | |
194 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
195 gtk_widget_show(button); | |
196 | |
197 if (!generic_dialog_get_alternative_button_order(ew->window)) | |
198 { | |
199 gtk_box_reorder_child(GTK_BOX(button_hbox), ct_button, -1); | |
200 } | |
201 | |
202 | |
203 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
204 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
205 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
206 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
207 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
208 gtk_widget_show(scrolled); | |
209 | |
210 text_view = gtk_text_view_new(); | |
211 gtk_container_add(GTK_CONTAINER(scrolled), text_view); | |
212 gtk_widget_show(text_view); | |
213 | |
214 ew->buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); | |
215 if (g_file_get_contents(src_path, &text, &size, NULL)) | |
216 { | |
217 gtk_text_buffer_set_text(ew->buffer, text, size); | |
218 } | |
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
|
219 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
|
220 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
|
221 G_CALLBACK(editor_window_text_modified_cb), ew); |
1479 | 222 |
223 gtk_widget_show(ew->window); | |
224 } | |
225 | |
226 | |
227 static void editor_list_window_close_cb(GtkWidget *widget, gpointer data) | |
228 { | |
229 gtk_widget_destroy(editor_list_window); | |
230 editor_list_window = NULL; | |
231 editor_list_view = NULL; | |
232 } | |
233 | |
234 static gboolean editor_list_window_delete(GtkWidget *widget, GdkEventAny *event, gpointer data) | |
235 { | |
236 editor_list_window_close_cb(NULL, NULL); | |
237 return TRUE; | |
238 } | |
239 | |
240 static void editor_list_window_edit_cb(GtkWidget *widget, gpointer data) | |
241 { | |
242 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(editor_list_view)); | |
243 GtkTreeIter iter; | |
244 | |
245 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
246 { | |
247 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(editor_list_view)); | |
248 gchar *path; | |
249 gchar *key; | |
250 | |
251 gtk_tree_model_get(store, &iter, | |
252 DESKTOP_FILE_COLUMN_PATH, &path, | |
253 DESKTOP_FILE_COLUMN_KEY, &key, -1); | |
254 editor_window_new(path, key); | |
255 g_free(key); | |
256 g_free(path); | |
257 } | |
258 } | |
259 | |
260 static void editor_list_window_new_cb(GtkWidget *widget, gpointer data) | |
261 { | |
262 editor_window_new(DESKTOP_FILE_TEMPLATE, _("new.desktop")); | |
263 } | |
264 | |
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
|
265 |
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
|
266 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
|
267 { |
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
|
268 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
|
269 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
|
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 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
|
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 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
|
274 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
|
275 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
|
276 { |
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 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
|
278 |
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 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
|
280 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
|
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 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
|
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 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
|
285 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
|
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 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
|
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 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
|
290 } |
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 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
|
293 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
|
294 } |
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 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
|
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 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
|
298 { |
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 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
|
300 |
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 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
|
302 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
|
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 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 } |
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 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
|
312 |
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 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
|
314 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
|
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 |
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 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
|
318 } |
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 |
1479 | 320 static void editor_list_window_create(void) |
321 { | |
322 GtkWidget *win_vbox; | |
323 GtkWidget *hbox; | |
324 GtkWidget *button; | |
325 GtkWidget *scrolled; | |
326 GtkCellRenderer *renderer; | |
327 GtkTreeSelection *selection; | |
328 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
|
329 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
|
330 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
|
331 |
1479 | 332 editor_list_window = window_new(GTK_WINDOW_TOPLEVEL, "editors", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Editors")); |
333 gtk_window_set_type_hint(GTK_WINDOW(editor_list_window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
334 g_signal_connect(G_OBJECT(editor_list_window), "delete_event", | |
335 G_CALLBACK(editor_list_window_delete), NULL); | |
336 gtk_window_set_default_size(GTK_WINDOW(editor_list_window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); | |
337 gtk_window_set_resizable(GTK_WINDOW(editor_list_window), TRUE); | |
338 gtk_container_set_border_width(GTK_CONTAINER(editor_list_window), PREF_PAD_BORDER); | |
339 | |
340 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
341 gtk_container_add(GTK_CONTAINER(editor_list_window), win_vbox); | |
342 gtk_widget_show(win_vbox); | |
343 | |
344 hbox = gtk_hbutton_box_new(); | |
345 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); | |
346 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_BUTTON_GAP); | |
347 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
348 gtk_widget_show(hbox); | |
349 | |
350 | |
351 button = pref_button_new(NULL, GTK_STOCK_NEW, NULL, FALSE, | |
352 G_CALLBACK(editor_list_window_new_cb), NULL); | |
353 gtk_container_add(GTK_CONTAINER(hbox), button); | |
354 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
355 gtk_widget_show(button); | |
356 | |
357 button = pref_button_new(NULL, GTK_STOCK_EDIT, NULL, FALSE, | |
358 G_CALLBACK(editor_list_window_edit_cb), NULL); | |
359 gtk_container_add(GTK_CONTAINER(hbox), button); | |
360 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
361 gtk_widget_show(button); | |
362 | |
363 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, | |
364 G_CALLBACK(editor_list_window_close_cb), NULL); | |
365 gtk_container_add(GTK_CONTAINER(hbox), button); | |
366 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
367 gtk_widget_show(button); | |
368 | |
369 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
370 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
371 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
372 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
373 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
374 gtk_widget_show(scrolled); | |
375 | |
376 editor_list_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(desktop_file_list)); | |
377 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(editor_list_view)); | |
378 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); | |
379 | |
380 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(editor_list_view), FALSE); | |
381 | |
382 column = gtk_tree_view_column_new(); | |
383 gtk_tree_view_column_set_title(column, _("Desktop file")); | |
384 gtk_tree_view_column_set_resizable(column, TRUE); | |
385 renderer = gtk_cell_renderer_text_new(); | |
386 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
387 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_KEY); | |
388 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
|
389 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_KEY); |
1479 | 390 |
391 column = gtk_tree_view_column_new(); | |
392 gtk_tree_view_column_set_title(column, _("Hidden")); | |
393 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
394 renderer = gtk_cell_renderer_toggle_new(); | |
395 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
396 gtk_tree_view_column_add_attribute(column, renderer, "active", DESKTOP_FILE_COLUMN_HIDDEN); | |
397 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
|
398 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_HIDDEN); |
1479 | 399 |
400 column = gtk_tree_view_column_new(); | |
401 gtk_tree_view_column_set_title(column, _("Name")); | |
402 gtk_tree_view_column_set_resizable(column, TRUE); | |
403 renderer = gtk_cell_renderer_text_new(); | |
404 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
405 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_NAME); | |
406 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
|
407 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_NAME); |
1479 | 408 |
409 column = gtk_tree_view_column_new(); | |
410 gtk_tree_view_column_set_title(column, _("Path")); | |
411 gtk_tree_view_column_set_resizable(column, TRUE); | |
412 renderer = gtk_cell_renderer_text_new(); | |
413 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
414 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_PATH); | |
415 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
|
416 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
|
417 |
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
|
418 /* 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 |
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 /* 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
|
431 gtk_tree_sortable_set_sort_column_id(sortable, DESKTOP_FILE_COLUMN_KEY, GTK_SORT_ASCENDING); |
1479 | 432 |
433 gtk_container_add(GTK_CONTAINER(scrolled), editor_list_view); | |
434 gtk_widget_show(editor_list_view); | |
435 | |
436 gtk_widget_show(editor_list_window); | |
437 } | |
438 | |
439 /* | |
440 *----------------------------------------------------------------------------- | |
441 * config window show (public) | |
442 *----------------------------------------------------------------------------- | |
443 */ | |
444 | |
445 void show_editor_list_window(void) | |
446 { | |
447 if (editor_list_window) | |
448 { | |
449 gtk_window_present(GTK_WINDOW(editor_list_window)); | |
450 return; | |
451 } | |
452 | |
453 editor_list_window_create(); | |
454 } |