Mercurial > geeqie
annotate src/desktop_file.c @ 1799:b85ff7951483
Update russian translation. Thanks to Denis Silakov.
author | zas_ |
---|---|
date | Tue, 16 Feb 2010 19:55:35 +0000 |
parents | f0e9f2dcfe8a |
children | 956aab097ea7 |
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 ? */ |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
49 GtkWidget *delete_button; |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
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 { | |
1641
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
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 | |
1641
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
81 dir = g_build_filename(get_rc_dir(), "applications", NULL); |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
82 path = g_build_filename(dir, name, NULL); |
1479 | 83 |
1641
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
84 if (!recursive_mkdir_if_not_exists(dir, 0755)) |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
85 { |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
86 file_util_warning_dialog(_("Can't save"), _("Could not create directory"), GTK_STOCK_DIALOG_ERROR, NULL); |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
87 ret = FALSE; |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
88 } |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
89 |
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
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); | |
1641
c8252313dcfa
make sure that a directory exists on saving desktop files
nadvornik
parents:
1624
diff
changeset
|
98 g_free(dir); |
1479 | 99 g_free(text); |
1736 | 100 layout_editors_reload_start(); |
101 /* idle function is not needed, everything should be cached */ | |
102 layout_editors_reload_finish(); | |
1479 | 103 return ret; |
104 } | |
105 | |
106 static void editor_window_close_cb(GtkWidget *widget, gpointer data) | |
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 g_free(ew->desktop_name); |
1479 | 111 gtk_widget_destroy(ew->window); |
112 g_free(ew); | |
113 } | |
114 | |
115 static gint editor_window_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
116 { | |
117 editor_window_close_cb(w, data); | |
118 return TRUE; | |
119 } | |
120 | |
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
|
121 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
|
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 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
|
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 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
|
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 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
|
128 } |
1569 | 129 |
130 gtk_widget_set_sensitive(ew->save_button, FALSE); | |
1746 | 131 gtk_text_buffer_set_modified(ew->buffer, FALSE); |
1569 | 132 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
|
133 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
134 |
b924293cf6c8
Desktop files 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 static void editor_window_text_modified_cb(GtkWidget *widget, gpointer data) |
1479 | 136 { |
137 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
|
138 |
b924293cf6c8
Desktop files 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 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
|
140 { |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
141 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
|
142 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
|
143 } |
1479 | 144 } |
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
|
145 |
b924293cf6c8
Desktop files 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 static void editor_window_entry_changed_cb(GtkWidget *widget, gpointer data) |
1479 | 147 { |
148 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
|
149 const gchar *content = gtk_entry_get_text(GTK_ENTRY(ew->entry)); |
1491 | 150 gboolean modified = ew->modified; |
151 | |
152 if (!modified) | |
153 { | |
154 modified = (!ew->desktop_name && *content); | |
155 } | |
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
|
156 |
b924293cf6c8
Desktop files 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 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
|
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 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
|
160 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
161 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
162 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
|
163 ew->modified = modified; |
1479 | 164 } |
165 | |
166 static void editor_window_new(const gchar *src_path, const gchar *desktop_name) | |
167 { | |
168 EditorWindow *ew; | |
169 GtkWidget *win_vbox; | |
170 GtkWidget *hbox; | |
171 GtkWidget *button; | |
172 GtkWidget *ct_button; | |
173 GtkWidget *button_hbox; | |
174 GtkWidget *scrolled; | |
175 GtkWidget *text_view; | |
176 gchar *text; | |
177 gsize size; | |
178 | |
179 ew = g_new0(EditorWindow, 1); | |
180 | |
181 | |
182 ew->window = window_new(GTK_WINDOW_TOPLEVEL, "Desktop", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Desktop file")); | |
183 gtk_window_set_type_hint(GTK_WINDOW(ew->window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
184 | |
185 g_signal_connect(G_OBJECT(ew->window), "delete_event", | |
186 G_CALLBACK(editor_window_delete_cb), ew); | |
187 | |
188 gtk_window_set_default_size(GTK_WINDOW(ew->window), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT); | |
189 gtk_window_set_resizable(GTK_WINDOW(ew->window), TRUE); | |
190 gtk_container_set_border_width(GTK_CONTAINER(ew->window), PREF_PAD_BORDER); | |
191 | |
192 win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE); | |
193 gtk_container_add(GTK_CONTAINER(ew->window), win_vbox); | |
194 gtk_widget_show(win_vbox); | |
195 | |
196 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
197 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
198 gtk_widget_show(hbox); | |
199 | |
200 ew->entry = gtk_entry_new(); | |
201 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
|
202 ew->desktop_name = NULL; |
1479 | 203 if (desktop_name) |
204 { | |
205 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
|
206 ew->desktop_name = g_strdup(desktop_name); |
1479 | 207 } |
208 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
|
209 g_signal_connect(G_OBJECT(ew->entry), "changed", G_CALLBACK(editor_window_entry_changed_cb), ew); |
1479 | 210 |
211 button_hbox = gtk_hbutton_box_new(); | |
212 gtk_button_box_set_layout(GTK_BUTTON_BOX(button_hbox), GTK_BUTTONBOX_END); | |
213 gtk_box_set_spacing(GTK_BOX(button_hbox), PREF_PAD_BUTTON_GAP); | |
214 gtk_box_pack_end(GTK_BOX(hbox), button_hbox, FALSE, FALSE, 0); | |
215 gtk_widget_show(button_hbox); | |
216 | |
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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 ct_button = ew->save_button; |
1479 | 224 |
1569 | 225 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, |
1479 | 226 G_CALLBACK(editor_window_close_cb), ew); |
227 gtk_container_add(GTK_CONTAINER(button_hbox), button); | |
228 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
229 gtk_widget_show(button); | |
230 | |
231 if (!generic_dialog_get_alternative_button_order(ew->window)) | |
232 { | |
233 gtk_box_reorder_child(GTK_BOX(button_hbox), ct_button, -1); | |
234 } | |
235 | |
236 | |
237 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
238 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
239 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
240 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
241 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
242 gtk_widget_show(scrolled); | |
243 | |
244 text_view = gtk_text_view_new(); | |
245 gtk_container_add(GTK_CONTAINER(scrolled), text_view); | |
246 gtk_widget_show(text_view); | |
247 | |
248 ew->buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view)); | |
249 if (g_file_get_contents(src_path, &text, &size, NULL)) | |
250 { | |
251 gtk_text_buffer_set_text(ew->buffer, text, size); | |
252 } | |
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
|
253 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
|
254 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
|
255 G_CALLBACK(editor_window_text_modified_cb), ew); |
1479 | 256 |
257 gtk_widget_show(ew->window); | |
258 } | |
259 | |
260 | |
261 static void editor_list_window_close_cb(GtkWidget *widget, gpointer data) | |
262 { | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
263 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
|
264 g_free(editor_list_window); |
1479 | 265 editor_list_window = NULL; |
266 } | |
267 | |
268 static gboolean editor_list_window_delete(GtkWidget *widget, GdkEventAny *event, gpointer data) | |
269 { | |
270 editor_list_window_close_cb(NULL, NULL); | |
271 return TRUE; | |
272 } | |
273 | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
274 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
|
275 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
276 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
|
277 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
278 EditorWindowDel_Data *ewdl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
279 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
280 ewdl->ewl->gd = NULL; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
281 g_free(ewdl->path); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
282 g_free(ewdl); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
283 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
284 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
285 static void editor_list_window_delete_dlg_ok_cb(GenericDialog *gd, gpointer data) |
1479 | 286 { |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
287 EditorWindowDel_Data *ewdl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
288 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
289 if (!unlink_file(ewdl->path)) |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
290 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
291 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
|
292 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
|
293 g_free(text); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
294 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
295 else |
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 /* refresh list */ |
1736 | 298 layout_editors_reload_start(); |
299 /* idle function is not needed, everything should be cached */ | |
300 layout_editors_reload_finish(); | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
301 } |
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 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
|
304 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
305 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
306 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
|
307 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
308 EditorListWindow *ewl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
309 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
1479 | 310 GtkTreeIter iter; |
311 | |
312 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) | |
313 { | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
314 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
|
315 gchar *path; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
316 gchar *key; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
317 gchar *text; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
318 EditorWindowDel_Data *ewdl; |
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 gtk_tree_model_get(store, &iter, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
321 DESKTOP_FILE_COLUMN_PATH, &path, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
322 DESKTOP_FILE_COLUMN_KEY, &key, -1); |
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 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
325 ewdl = g_new(EditorWindowDel_Data, 1); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
326 ewdl->ewl = ewl; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
327 ewdl->path = path; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
328 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
329 if (ewl->gd) |
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 GenericDialog *gd = ewl->gd; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
332 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
|
333 generic_dialog_close(gd); |
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 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
336 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
|
337 NULL, TRUE, |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
338 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
|
339 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
340 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
|
341 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
342 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
|
343 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
|
344 _("Delete file"), text); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
345 g_free(text); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
346 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
347 gtk_widget_show(ewl->gd->dialog); |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
348 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
349 } |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
350 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
351 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
|
352 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
353 EditorListWindow *ewl = data; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
354 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
|
355 GtkTreeIter iter; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
356 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
357 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
|
358 { |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
359 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); |
1479 | 360 gchar *path; |
361 gchar *key; | |
362 | |
363 gtk_tree_model_get(store, &iter, | |
364 DESKTOP_FILE_COLUMN_PATH, &path, | |
365 DESKTOP_FILE_COLUMN_KEY, &key, -1); | |
366 editor_window_new(path, key); | |
367 g_free(key); | |
368 g_free(path); | |
369 } | |
370 } | |
371 | |
372 static void editor_list_window_new_cb(GtkWidget *widget, gpointer data) | |
373 { | |
374 editor_window_new(DESKTOP_FILE_TEMPLATE, _("new.desktop")); | |
375 } | |
376 | |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
377 static void editor_list_window_selection_changed_cb(GtkWidget *widget, gpointer data) |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
378 { |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
379 EditorListWindow *ewl = data; |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
380 GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
381 GtkTreeIter iter; |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
382 |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
383 if (gtk_tree_selection_get_selected(sel, NULL, &iter)) |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
384 { |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
385 GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
386 gchar *path; |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
387 |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
388 gtk_tree_model_get(store, &iter, |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
389 DESKTOP_FILE_COLUMN_PATH, &path, |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
390 -1); |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
391 |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
392 gtk_widget_set_sensitive(ewl->delete_button, access_file(path, W_OK)); |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
393 gtk_widget_set_sensitive(ewl->edit_button, TRUE); |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
394 g_free(path); |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
395 } |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
396 |
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
397 } |
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 |
b924293cf6c8
Desktop files 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 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
|
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 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
|
402 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
|
403 |
b924293cf6c8
Desktop files 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 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
|
405 { |
b924293cf6c8
Desktop files 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 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
|
407 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
|
408 case DESKTOP_FILE_COLUMN_PATH: |
1765 | 409 case DESKTOP_FILE_COLUMN_HIDDEN: |
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
|
410 { |
b924293cf6c8
Desktop files 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 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
|
412 |
b924293cf6c8
Desktop files 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 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
|
414 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
|
415 |
b924293cf6c8
Desktop files 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 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
|
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 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
|
419 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
|
420 } |
b924293cf6c8
Desktop files 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 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
|
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 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
|
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 |
b924293cf6c8
Desktop files 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 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
|
427 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
|
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 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
|
430 |
b924293cf6c8
Desktop files 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 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
|
432 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
|
433 } |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
434 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
435 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
|
436 } |
b924293cf6c8
Desktop files 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 |
1479 | 438 static void editor_list_window_create(void) |
439 { | |
440 GtkWidget *win_vbox; | |
441 GtkWidget *hbox; | |
442 GtkWidget *button; | |
443 GtkWidget *scrolled; | |
444 GtkCellRenderer *renderer; | |
445 GtkTreeSelection *selection; | |
446 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
|
447 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
|
448 GtkTreeSortable *sortable; |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
449 EditorListWindow *ewl; |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
450 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
451 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
|
452 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
453 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
|
454 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
|
455 g_signal_connect(G_OBJECT(ewl->window), "delete_event", |
1479 | 456 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
|
457 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
|
458 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
|
459 gtk_container_set_border_width(GTK_CONTAINER(ewl->window), PREF_PAD_BORDER); |
1479 | 460 |
461 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
|
462 gtk_container_add(GTK_CONTAINER(ewl->window), win_vbox); |
1479 | 463 gtk_widget_show(win_vbox); |
464 | |
465 hbox = gtk_hbutton_box_new(); | |
466 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); | |
467 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_BUTTON_GAP); | |
468 gtk_box_pack_end(GTK_BOX(win_vbox), hbox, FALSE, FALSE, 0); | |
469 gtk_widget_show(hbox); | |
470 | |
471 | |
472 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
|
473 G_CALLBACK(editor_list_window_new_cb), ewl); |
1479 | 474 gtk_container_add(GTK_CONTAINER(hbox), button); |
475 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
476 gtk_widget_show(button); | |
477 | |
478 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
|
479 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
|
480 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
|
481 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
482 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
|
483 gtk_widget_show(button); |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
484 ewl->edit_button = button; |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
485 |
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
486 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
|
487 G_CALLBACK(editor_list_window_delete_cb), ewl); |
1479 | 488 gtk_container_add(GTK_CONTAINER(hbox), button); |
489 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
490 gtk_widget_set_sensitive(button, FALSE); |
1479 | 491 gtk_widget_show(button); |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
492 ewl->delete_button = button; |
1479 | 493 |
494 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
|
495 G_CALLBACK(editor_list_window_close_cb), ewl); |
1479 | 496 gtk_container_add(GTK_CONTAINER(hbox), button); |
497 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
498 gtk_widget_show(button); | |
499 | |
500 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
501 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
502 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
503 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
504 gtk_box_pack_start(GTK_BOX(win_vbox), scrolled, TRUE, TRUE, 5); | |
505 gtk_widget_show(scrolled); | |
506 | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
507 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
|
508 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); |
1479 | 509 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); |
1776
f0e9f2dcfe8a
Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected.
zas_
parents:
1765
diff
changeset
|
510 g_signal_connect(selection, "changed", G_CALLBACK(editor_list_window_selection_changed_cb), ewl); |
1479 | 511 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
512 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ewl->view), FALSE); |
1479 | 513 |
514 column = gtk_tree_view_column_new(); | |
1624 | 515 gtk_tree_view_column_set_title(column, _("Name")); |
1479 | 516 gtk_tree_view_column_set_resizable(column, TRUE); |
517 renderer = gtk_cell_renderer_text_new(); | |
518 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1624 | 519 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
|
520 gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->view), column); |
1624 | 521 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_NAME); |
1479 | 522 |
523 column = gtk_tree_view_column_new(); | |
524 gtk_tree_view_column_set_title(column, _("Hidden")); | |
525 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1765 | 526 renderer = gtk_cell_renderer_text_new(); |
527 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
528 gtk_tree_view_column_add_attribute(column, renderer, "text", DESKTOP_FILE_COLUMN_HIDDEN); | |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
529 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
|
530 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
|
531 gtk_tree_view_column_set_alignment(column, 0.5); |
56b534d71872
Make desktop window list checkboxes centered and not activatable.
zas_
parents:
1496
diff
changeset
|
532 |
1479 | 533 column = gtk_tree_view_column_new(); |
1624 | 534 gtk_tree_view_column_set_title(column, _("Desktop file")); |
1479 | 535 gtk_tree_view_column_set_resizable(column, TRUE); |
536 renderer = gtk_cell_renderer_text_new(); | |
537 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1624 | 538 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
|
539 gtk_tree_view_append_column(GTK_TREE_VIEW(ewl->view), column); |
1624 | 540 gtk_tree_view_column_set_sort_column_id(column, DESKTOP_FILE_COLUMN_KEY); |
1479 | 541 |
542 column = gtk_tree_view_column_new(); | |
543 gtk_tree_view_column_set_title(column, _("Path")); | |
544 gtk_tree_view_column_set_resizable(column, TRUE); | |
545 renderer = gtk_cell_renderer_text_new(); | |
546 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
547 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
|
548 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
|
549 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
|
550 |
b924293cf6c8
Desktop files window: make columns sortable, replace Apply and OK buttons by one Save button which is made sensitive when needed.
zas_
parents:
1479
diff
changeset
|
551 /* set up sorting */ |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 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
|
562 |
b924293cf6c8
Desktop files 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 /* set initial sort order */ |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
564 //gtk_tree_sortable_set_sort_column_id(sortable, DESKTOP_FILE_COLUMN_KEY, GTK_SORT_ASCENDING); |
1479 | 565 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
566 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
|
567 gtk_widget_show(ewl->view); |
1479 | 568 |
1496
03c22c05c6b6
Allow to delete an editor's desktop file from editors list window.
zas_
parents:
1491
diff
changeset
|
569 gtk_widget_show(ewl->window); |
1479 | 570 } |
571 | |
572 /* | |
573 *----------------------------------------------------------------------------- | |
574 * config window show (public) | |
575 *----------------------------------------------------------------------------- | |
576 */ | |
577 | |
578 void show_editor_list_window(void) | |
579 { | |
580 if (editor_list_window) | |
581 { | |
582 gtk_window_present(GTK_WINDOW(editor_list_window)); | |
583 return; | |
584 } | |
585 | |
586 editor_list_window_create(); | |
587 } | |
1613 | 588 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |