Mercurial > geeqie.yaz
annotate src/desktop_file.c @ 1737:fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
author | zas_ |
---|---|
date | Fri, 04 Dec 2009 20:40:02 +0000 |
parents | 80ba6b99478f |
children |
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 | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
43 typedef struct _EditorListWindow EditorListWindow; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
44 struct _EditorListWindow |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
45 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
46 GtkWidget *window; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
47 GtkWidget *view; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
48 GenericDialog *gd; /* any open confirm dialogs ? */ |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
49 GtkWidget *delete_button; |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
50 GtkWidget *edit_button; |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
51 }; |
1479 | 52 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
53 typedef struct _EditorWindowDel_Data EditorWindowDel_Data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
54 struct _EditorWindowDel_Data |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
55 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
56 EditorListWindow *ewl; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
57 gchar *path; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
58 }; |
1479 | 59 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
60 static EditorListWindow *editor_list_window = NULL; |
1479 | 61 |
62 static gboolean editor_window_save(EditorWindow *ew) | |
63 { | |
1637
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
64 gchar *dir; |
1479 | 65 gchar *path; |
66 gchar *text; | |
67 GtkTextIter start, end; | |
68 GError *error = NULL; | |
69 gboolean ret = TRUE; | |
70 const gchar *name = gtk_entry_get_text(GTK_ENTRY(ew->entry)); | |
71 | |
72 if (!name || !name[0]) | |
73 { | |
74 file_util_warning_dialog(_("Can't save"), _("Please specify file name."), GTK_STOCK_DIALOG_ERROR, NULL); | |
75 return FALSE; | |
76 } | |
77 | |
78 gtk_text_buffer_get_bounds(ew->buffer, &start, &end); | |
79 text = gtk_text_buffer_get_text(ew->buffer, &start, &end, FALSE); | |
80 | |
1637
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
81 dir = g_build_filename(get_rc_dir(), "applications", NULL); |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
82 path = g_build_filename(dir, name, NULL); |
1479 | 83 |
1637
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
84 if (!recursive_mkdir_if_not_exists(dir, 0755)) |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
85 { |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
86 file_util_warning_dialog(_("Can't save"), _("Could not create directory"), GTK_STOCK_DIALOG_ERROR, NULL); |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
87 ret = FALSE; |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
88 } |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
89 |
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
90 if (ret && !g_file_set_contents(path, text, -1, &error)) |
1479 | 91 { |
92 file_util_warning_dialog(_("Can't save"), error->message, GTK_STOCK_DIALOG_ERROR, NULL); | |
93 g_error_free(error); | |
94 ret = FALSE; | |
95 } | |
96 | |
97 g_free(path); | |
1637
80ba6b99478f
make sure that a directory exists on saving desktop files
nadvornik
parents:
1625
diff
changeset
|
98 g_free(dir); |
1479 | 99 g_free(text); |
100 layout_editors_reload_all(); | |
101 return ret; | |
102 } | |
103 | |
104 static void editor_window_close_cb(GtkWidget *widget, gpointer data) | |
105 { | |
106 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
|
107 |
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
|
108 g_free(ew->desktop_name); |
1479 | 109 gtk_widget_destroy(ew->window); |
110 g_free(ew); | |
111 } | |
112 | |
113 static gint editor_window_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
114 { | |
115 editor_window_close_cb(w, data); | |
116 return TRUE; | |
117 } | |
118 | |
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
|
119 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
|
120 { |
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 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
|
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 (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
|
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 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
|
126 } |
1569 | 127 |
128 gtk_widget_set_sensitive(ew->save_button, FALSE); | |
129 ew->modified = FALSE; | |
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
|
130 } |
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 static void editor_window_text_modified_cb(GtkWidget *widget, gpointer data) |
1479 | 133 { |
134 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
|
135 |
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
|
136 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
|
137 { |
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
|
138 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
|
139 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
|
140 } |
1479 | 141 } |
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
|
142 |
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
|
143 static void editor_window_entry_changed_cb(GtkWidget *widget, gpointer data) |
1479 | 144 { |
145 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
|
146 const gchar *content = gtk_entry_get_text(GTK_ENTRY(ew->entry)); |
1491 | 147 gboolean modified = ew->modified; |
148 | |
149 if (!modified) | |
150 { | |
151 modified = (!ew->desktop_name && *content); | |
152 } | |
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
|
153 |
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
|
154 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
|
155 { |
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
|
156 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
|
157 } |
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
|
158 |
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
|
159 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
|
160 ew->modified = modified; |
1479 | 161 } |
162 | |
163 static void editor_window_new(const gchar *src_path, const gchar *desktop_name) | |
164 { | |
165 EditorWindow *ew; | |
166 GtkWidget *win_vbox; | |
167 GtkWidget *hbox; | |
168 GtkWidget *button; | |
169 GtkWidget *ct_button; | |
170 GtkWidget *button_hbox; | |
171 GtkWidget *scrolled; | |
172 GtkWidget *text_view; | |
173 gchar *text; | |
174 gsize size; | |
175 | |
176 ew = g_new0(EditorWindow, 1); | |
177 | |
178 | |
179 ew->window = window_new(GTK_WINDOW_TOPLEVEL, "Desktop", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Desktop file")); | |
180 gtk_window_set_type_hint(GTK_WINDOW(ew->window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
181 | |
182 g_signal_connect(G_OBJECT(ew->window), "delete_event", | |
183 G_CALLBACK(editor_window_delete_cb), ew); | |
184 | |
185 gtk_window_set_default_size(GTK_WINDOW(ew->window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); | |
186 gtk_window_set_resizable(GTK_WINDOW(ew->window), TRUE); | |
187 gtk_container_set_border_width(GTK_CONTAINER(ew->window), PREF_PAD_BORDER); | |
188 | |
189 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
190 gtk_container_add(GTK_CONTAINER(ew->window), win_vbox); | |
191 gtk_widget_show(win_vbox); | |
192 | |
193 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
194 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
195 gtk_widget_show(hbox); | |
196 | |
197 ew->entry = gtk_entry_new(); | |
198 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
|
199 ew->desktop_name = NULL; |
1479 | 200 if (desktop_name) |
201 { | |
202 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
|
203 ew->desktop_name = g_strdup(desktop_name); |
1479 | 204 } |
205 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
|
206 g_signal_connect(G_OBJECT(ew->entry), "changed", G_CALLBACK(editor_window_entry_changed_cb), ew); |
1479 | 207 |
208 button_hbox = gtk_hbutton_box_new(); | |
209 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END); | |
210 gtk_box_set_spacing(GTK_BOX(button_hbox), PREF_PAD_BUTTON_GAP); | |
211 gtk_box_pack_end(GTK_BOX(hbox), button_hbox, FALSE, FALSE, 0); | |
212 gtk_widget_show(button_hbox); | |
213 | |
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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 ct_button = ew->save_button; |
1479 | 221 |
1569 | 222 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, |
1479 | 223 G_CALLBACK(editor_window_close_cb), ew); |
224 gtk_container_add(GTK_CONTAINER(button_hbox), button); | |
225 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
226 gtk_widget_show(button); | |
227 | |
228 if (!generic_dialog_get_alternative_button_order(ew->window)) | |
229 { | |
230 gtk_box_reorder_child(GTK_BOX(button_hbox), ct_button, -1); | |
231 } | |
232 | |
233 | |
234 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
235 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
236 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
237 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
238 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
239 gtk_widget_show(scrolled); | |
240 | |
241 text_view = gtk_text_view_new(); | |
242 gtk_container_add(GTK_CONTAINER(scrolled), text_view); | |
243 gtk_widget_show(text_view); | |
244 | |
245 ew->buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); | |
246 if (g_file_get_contents(src_path, &text, &size, NULL)) | |
247 { | |
248 gtk_text_buffer_set_text(ew->buffer, text, size); | |
249 } | |
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
|
250 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
|
251 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
|
252 G_CALLBACK(editor_window_text_modified_cb), ew); |
1479 | 253 |
254 gtk_widget_show(ew->window); | |
255 } | |
256 | |
257 | |
258 static void editor_list_window_close_cb(GtkWidget *widget, gpointer data) | |
259 { | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
260 gtk_widget_destroy(editor_list_window->window); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
261 g_free(editor_list_window); |
1479 | 262 editor_list_window = NULL; |
263 } | |
264 | |
265 static gboolean editor_list_window_delete(GtkWidget *widget, GdkEventAny *event, gpointer data) | |
266 { | |
267 editor_list_window_close_cb(NULL, NULL); | |
268 return TRUE; | |
269 } | |
270 | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
271 static void editor_list_window_delete_dlg_cancel(GenericDialog *gd, gpointer data); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
272 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
273 static void editor_list_window_delete_dlg_cancel(GenericDialog *gd, gpointer data) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
274 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
275 EditorWindowDel_Data *ewdl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
276 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
277 ewdl->ewl->gd = NULL; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
278 g_free(ewdl->path); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
279 g_free(ewdl); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
280 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
281 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
282 static void editor_list_window_delete_dlg_ok_cb(GenericDialog *gd, gpointer data) |
1479 | 283 { |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
284 EditorWindowDel_Data *ewdl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
285 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
286 if (!unlink_file(ewdl->path)) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
287 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
288 gchar *text = g_strdup_printf(_("Unable to delete file:\n%s"), ewdl->path); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
289 warning_dialog(_("File deletion failed"), text, GTK_STOCK_DIALOG_WARNING, NULL); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
290 g_free(text); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
291 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
292 else |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
293 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
294 /* refresh list */ |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
295 layout_editors_reload_all(); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
296 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
297 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
298 editor_list_window_delete_dlg_cancel(gd, data); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
299 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
300 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
301 static void editor_list_window_delete_cb(GtkWidget *widget, gpointer data) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
302 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
303 EditorListWindow *ewl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
304 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
1479 | 305 GtkTreeIter iter; |
306 | |
307 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
308 { | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
309 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
310 gchar *path; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
311 gchar *key; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
312 gchar *text; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
313 EditorWindowDel_Data *ewdl; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
314 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
315 gtk_tree_model_get(store, &iter, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
316 DESKTOP_FILE_COLUMN_PATH, &path, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
317 DESKTOP_FILE_COLUMN_KEY, &key, -1); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
318 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
319 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
320 ewdl = g_new(EditorWindowDel_Data, 1); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
321 ewdl->ewl = ewl; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
322 ewdl->path = path; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
323 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
324 if (ewl->gd) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
325 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
326 GenericDialog *gd = ewl->gd; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
327 editor_list_window_delete_dlg_cancel(ewl->gd, ewl->gd->data); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
328 generic_dialog_close(gd); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
329 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
330 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
331 ewl->gd = generic_dialog_new(_("Delete file"), "dlg_confirm", |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
332 NULL, TRUE, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
333 editor_list_window_delete_dlg_cancel, ewdl); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
334 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
335 generic_dialog_add_button(ewl->gd, GTK_STOCK_DELETE, NULL, editor_list_window_delete_dlg_ok_cb, TRUE); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
336 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
337 text = g_strdup_printf(_("About to delete the file:\n %s"), path); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
338 generic_dialog_add_message(ewl->gd, GTK_STOCK_DIALOG_QUESTION, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
339 _("Delete file"), text); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
340 g_free(text); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
341 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
342 gtk_widget_show(ewl->gd->dialog); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
343 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
344 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
345 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
346 static void editor_list_window_edit_cb(GtkWidget *widget, gpointer data) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
347 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
348 EditorListWindow *ewl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
349 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
350 GtkTreeIter iter; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
351 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
352 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
353 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
354 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); |
1479 | 355 gchar *path; |
356 gchar *key; | |
357 | |
358 gtk_tree_model_get(store, &iter, | |
359 DESKTOP_FILE_COLUMN_PATH, &path, | |
360 DESKTOP_FILE_COLUMN_KEY, &key, -1); | |
361 editor_window_new(path, key); | |
362 g_free(key); | |
363 g_free(path); | |
364 } | |
365 } | |
366 | |
367 static void editor_list_window_new_cb(GtkWidget *widget, gpointer data) | |
368 { | |
369 editor_window_new(DESKTOP_FILE_TEMPLATE, _("new.desktop")); | |
370 } | |
371 | |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
372 static void editor_list_window_selection_changed_cb(GtkWidget *widget, gpointer data) |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
373 { |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
374 EditorListWindow *ewl = data; |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
375 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
376 GtkTreeIter iter; |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
377 |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
378 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
379 { |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
380 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
381 gchar *path; |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
382 |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
383 gtk_tree_model_get(store, &iter, |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
384 DESKTOP_FILE_COLUMN_PATH, &path, |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
385 -1); |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
386 |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
387 gtk_widget_set_sensitive(ewl->delete_button, access_file(path, W_OK)); |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
388 gtk_widget_set_sensitive(ewl->edit_button, TRUE); |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
389 g_free(path); |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
390 } |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
391 |
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
392 } |
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
|
393 |
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 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
|
395 { |
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
|
396 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
|
397 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
|
398 |
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
|
399 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
|
400 { |
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
|
401 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
|
402 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
|
403 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
|
404 { |
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
|
405 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
|
406 |
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_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
|
408 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
|
409 |
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
|
410 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
|
411 { |
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 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
|
413 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
|
414 } |
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
|
415 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
|
416 { |
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 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
|
418 } |
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 |
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 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
|
421 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
|
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 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
|
424 |
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 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
|
426 { |
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 *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
|
428 |
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 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
|
430 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
|
431 |
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 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 } |
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
|
439 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
|
440 |
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
|
441 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
|
442 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
|
443 } |
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
|
444 |
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
|
445 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
|
446 } |
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
|
447 |
1479 | 448 static void editor_list_window_create(void) |
449 { | |
450 GtkWidget *win_vbox; | |
451 GtkWidget *hbox; | |
452 GtkWidget *button; | |
453 GtkWidget *scrolled; | |
454 GtkCellRenderer *renderer; | |
455 GtkTreeSelection *selection; | |
456 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
|
457 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
|
458 GtkTreeSortable *sortable; |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
459 EditorListWindow *ewl; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
460 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
461 editor_list_window = ewl = g_new0(EditorListWindow, 1); |
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
|
462 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
463 ewl->window = window_new(GTK_WINDOW_TOPLEVEL, "editors", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Editors")); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
464 gtk_window_set_type_hint(GTK_WINDOW(ewl->window), GDK_WINDOW_TYPE_HINT_DIALOG); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
465 g_signal_connect(G_OBJECT(ewl->window), "delete_event", |
1479 | 466 G_CALLBACK(editor_list_window_delete), NULL); |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
467 gtk_window_set_default_size(GTK_WINDOW(ewl->window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
468 gtk_window_set_resizable(GTK_WINDOW(ewl->window), TRUE); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
469 gtk_container_set_border_width(GTK_CONTAINER(ewl->window), PREF_PAD_BORDER); |
1479 | 470 |
471 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
472 gtk_container_add(GTK_CONTAINER(ewl->window), win_vbox); |
1479 | 473 gtk_widget_show(win_vbox); |
474 | |
475 hbox = gtk_hbutton_box_new(); | |
476 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); | |
477 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_BUTTON_GAP); | |
478 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
479 gtk_widget_show(hbox); | |
480 | |
481 | |
482 button = pref_button_new(NULL, GTK_STOCK_NEW, NULL, FALSE, | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
483 G_CALLBACK(editor_list_window_new_cb), ewl); |
1479 | 484 gtk_container_add(GTK_CONTAINER(hbox), button); |
485 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
486 gtk_widget_show(button); | |
487 | |
488 button = pref_button_new(NULL, GTK_STOCK_EDIT, NULL, FALSE, | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
489 G_CALLBACK(editor_list_window_edit_cb), ewl); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
490 gtk_container_add(GTK_CONTAINER(hbox), button); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
491 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
492 gtk_widget_set_sensitive(button, FALSE); |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
493 gtk_widget_show(button); |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
494 ewl->edit_button = button; |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
495 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
496 button = pref_button_new(NULL, GTK_STOCK_DELETE, NULL, FALSE, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
497 G_CALLBACK(editor_list_window_delete_cb), ewl); |
1479 | 498 gtk_container_add(GTK_CONTAINER(hbox), button); |
499 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
500 gtk_widget_set_sensitive(button, FALSE); |
1479 | 501 gtk_widget_show(button); |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
502 ewl->delete_button = button; |
1479 | 503 |
504 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
505 G_CALLBACK(editor_list_window_close_cb), ewl); |
1479 | 506 gtk_container_add(GTK_CONTAINER(hbox), button); |
507 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
508 gtk_widget_show(button); | |
509 | |
510 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
511 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
512 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
513 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
514 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
515 gtk_widget_show(scrolled); | |
516 | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
517 ewl->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(desktop_file_list)); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
518 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
1479 | 519 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); |
1737
fad7d30676c3
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1637
diff
changeset
|
520 g_signal_connect(selection, "changed", G_CALLBACK(editor_list_window_selection_changed_cb), ewl); |
1479 | 521 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
522 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ewl->view), FALSE); |
1479 | 523 |
524 column = gtk_tree_view_column_new(); | |
1625 | 525 gtk_tree_view_column_set_title(column, _("Desktop file")); |
1479 | 526 gtk_tree_view_column_set_resizable(column, TRUE); |
527 renderer = gtk_cell_renderer_text_new(); | |
528 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1625 | 529 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_KEY); |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
530 gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->view), column); |
1625 | 531 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_KEY); |
1479 | 532 |
533 column = gtk_tree_view_column_new(); | |
534 gtk_tree_view_column_set_title(column, _("Hidden")); | |
535 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
536 renderer = gtk_cell_renderer_toggle_new(); | |
1499
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
537 g_object_set(G_OBJECT(renderer), |
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
538 "activatable", FALSE, // not clickable for now |
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
539 "xalign", 0.5, // centered |
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
540 NULL); |
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
541 gtk_tree_view_column_pack_start(column, renderer, TRUE); // TRUE needed for centering |
1479 | 542 gtk_tree_view_column_add_attribute(column, renderer, "active", DESKTOP_FILE_COLUMN_HIDDEN); |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
543 gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->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
|
544 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_HIDDEN); |
1499
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
545 gtk_tree_view_column_set_alignment(column, 0.5); |
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
546 |
1479 | 547 column = gtk_tree_view_column_new(); |
1625 | 548 gtk_tree_view_column_set_title(column, _("Name")); |
1479 | 549 gtk_tree_view_column_set_resizable(column, TRUE); |
550 renderer = gtk_cell_renderer_text_new(); | |
551 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1625 | 552 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_NAME); |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
553 gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->view), column); |
1625 | 554 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_NAME); |
1479 | 555 |
556 column = gtk_tree_view_column_new(); | |
557 gtk_tree_view_column_set_title(column, _("Path")); | |
558 gtk_tree_view_column_set_resizable(column, TRUE); | |
559 renderer = gtk_cell_renderer_text_new(); | |
560 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
561 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_PATH); | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
562 gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->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
|
563 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
|
564 |
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
|
565 /* set up sorting */ |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
566 store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); |
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
|
567 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
|
568 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 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
|
576 |
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
|
577 /* set initial sort order */ |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
578 //gtk_tree_sortable_set_sort_column_id(sortable, DESKTOP_FILE_COLUMN_KEY, GTK_SORT_ASCENDING); |
1479 | 579 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
580 gtk_container_add(GTK_CONTAINER(scrolled), ewl->view); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
581 gtk_widget_show(ewl->view); |
1479 | 582 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
583 gtk_widget_show(ewl->window); |
1479 | 584 } |
585 | |
586 /* | |
587 *----------------------------------------------------------------------------- | |
588 * config window show (public) | |
589 *----------------------------------------------------------------------------- | |
590 */ | |
591 | |
592 void show_editor_list_window(void) | |
593 { | |
594 if (editor_list_window) | |
595 { | |
596 gtk_window_present(GTK_WINDOW(editor_list_window)); | |
597 return; | |
598 } | |
599 | |
600 editor_list_window_create(); | |
601 } | |
1611 | 602 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |