This commit was manufactured by cvs2svn to create branch 'gtk2'.
[claws.git] / src / prefs_actions.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto & The Sylpheed Claws Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
33
34 #include "intl.h"
35 #include "prefs_gtk.h"
36 #include "inc.h"
37 #include "utils.h"
38 #include "gtkutils.h"
39 #include "manage_window.h"
40 #include "mainwindow.h"
41 #include "prefs_common.h"
42 #include "alertpanel.h"
43 #include "prefs_actions.h"
44 #include "action.h"
45 #include "description_window.h"
46
47 static struct Actions
48 {
49         GtkWidget *window;
50
51         GtkWidget *ok_btn;
52
53         GtkWidget *name_entry;
54         GtkWidget *cmd_entry;
55
56         GtkWidget *actions_clist;
57 } actions;
58
59 /* widget creating functions */
60 static void prefs_actions_create        (MainWindow *mainwin);
61 static void prefs_actions_set_dialog    (void);
62 static gint prefs_actions_clist_set_row (gint row);
63
64 /* callback functions */
65 static void prefs_actions_help_cb       (GtkWidget      *w,
66                                          gpointer        data);
67 static void prefs_actions_register_cb   (GtkWidget      *w,
68                                          gpointer        data);
69 static void prefs_actions_substitute_cb (GtkWidget      *w,
70                                          gpointer        data);
71 static void prefs_actions_delete_cb     (GtkWidget      *w,
72                                          gpointer        data);
73 static void prefs_actions_up            (GtkWidget      *w,
74                                          gpointer        data);
75 static void prefs_actions_down          (GtkWidget      *w,
76                                          gpointer        data);
77 static void prefs_actions_select        (GtkCList       *clist,
78                                          gint            row,
79                                          gint            column,
80                                          GdkEvent       *event);
81 static void prefs_actions_row_move      (GtkCList       *clist,
82                                          gint            source_row,
83                                          gint            dest_row);
84 static gint prefs_actions_deleted       (GtkWidget      *widget,
85                                          GdkEventAny    *event,
86                                          gpointer       *data);
87 static gboolean prefs_actions_key_pressed(GtkWidget     *widget,
88                                           GdkEventKey   *event,
89                                           gpointer       data);
90 static void prefs_actions_cancel        (GtkWidget      *w,
91                                          gpointer        data);
92 static void prefs_actions_ok            (GtkWidget      *w,
93                                          gpointer        data);
94
95
96 void prefs_actions_open(MainWindow *mainwin)
97 {
98         inc_lock();
99
100         if (!actions.window)
101                 prefs_actions_create(mainwin);
102
103         manage_window_set_transient(GTK_WINDOW(actions.window));
104         gtk_widget_grab_focus(actions.ok_btn);
105
106         prefs_actions_set_dialog();
107
108         gtk_widget_show(actions.window);
109 }
110
111 static void prefs_actions_create(MainWindow *mainwin)
112 {
113         GtkWidget *window;
114         GtkWidget *vbox;
115         GtkWidget *ok_btn;
116         GtkWidget *cancel_btn;
117         GtkWidget *confirm_area;
118
119         GtkWidget *vbox1;
120
121         GtkWidget *entry_vbox;
122         GtkWidget *hbox;
123         GtkWidget *name_label;
124         GtkWidget *name_entry;
125         GtkWidget *cmd_label;
126         GtkWidget *cmd_entry;
127
128         GtkWidget *reg_hbox;
129         GtkWidget *btn_hbox;
130         GtkWidget *arrow;
131         GtkWidget *reg_btn;
132         GtkWidget *subst_btn;
133         GtkWidget *del_btn;
134
135         GtkWidget *cond_hbox;
136         GtkWidget *cond_scrolledwin;
137         GtkWidget *cond_clist;
138
139         GtkWidget *help_button;
140
141         GtkWidget *btn_vbox;
142         GtkWidget *up_btn;
143         GtkWidget *down_btn;
144
145         gchar *title[1];
146
147         debug_print("Creating actions configuration window...\n");
148
149         window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
150
151         gtk_container_set_border_width(GTK_CONTAINER (window), 8);
152         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
153         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
154         gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
155         gtk_window_set_default_size(GTK_WINDOW(window), 400, -1);
156
157         vbox = gtk_vbox_new(FALSE, 6);
158         gtk_widget_show(vbox);
159         gtk_container_add(GTK_CONTAINER(window), vbox);
160
161         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
162                                 &cancel_btn, _("Cancel"), NULL, NULL);
163         gtk_widget_show(confirm_area);
164         gtk_box_pack_end(GTK_BOX(vbox), confirm_area, FALSE, FALSE, 0);
165         gtk_widget_grab_default(ok_btn);
166
167         gtk_window_set_title(GTK_WINDOW(window), _("Actions configuration"));
168         g_signal_connect(G_OBJECT(window), "delete_event",
169                          G_CALLBACK(prefs_actions_deleted), NULL);
170         g_signal_connect(G_OBJECT(window), "key_press_event",
171                          G_CALLBACK(prefs_actions_key_pressed), NULL);
172         MANAGE_WINDOW_SIGNALS_CONNECT(window);
173         g_signal_connect(G_OBJECT(ok_btn), "clicked",
174                          G_CALLBACK(prefs_actions_ok), mainwin);
175         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
176                          G_CALLBACK(prefs_actions_cancel), NULL);
177
178         vbox1 = gtk_vbox_new(FALSE, 8);
179         gtk_widget_show(vbox1);
180         gtk_box_pack_start(GTK_BOX(vbox), vbox1, TRUE, TRUE, 0);
181         gtk_container_set_border_width(GTK_CONTAINER(vbox1), 2);
182
183         entry_vbox = gtk_vbox_new(FALSE, 4);
184         gtk_box_pack_start(GTK_BOX(vbox1), entry_vbox, FALSE, FALSE, 0);
185
186         hbox = gtk_hbox_new(FALSE, 8);
187         gtk_box_pack_start(GTK_BOX(entry_vbox), hbox, FALSE, FALSE, 0);
188
189         name_label = gtk_label_new(_("Menu name:"));
190         gtk_box_pack_start(GTK_BOX(hbox), name_label, FALSE, FALSE, 0);
191
192         name_entry = gtk_entry_new();
193         gtk_box_pack_start(GTK_BOX(hbox), name_entry, TRUE, TRUE, 0);
194
195         hbox = gtk_hbox_new(FALSE, 8);
196         gtk_box_pack_start(GTK_BOX(entry_vbox), hbox, TRUE, TRUE, 0);
197
198         cmd_label = gtk_label_new(_("Command line:"));
199         gtk_box_pack_start(GTK_BOX(hbox), cmd_label, FALSE, FALSE, 0);
200
201         cmd_entry = gtk_entry_new();
202         gtk_box_pack_start(GTK_BOX(hbox), cmd_entry, TRUE, TRUE, 0);
203
204         gtk_widget_show_all(entry_vbox);
205
206         /* register / substitute / delete */
207
208         reg_hbox = gtk_hbox_new(FALSE, 4);
209         gtk_widget_show(reg_hbox);
210         gtk_box_pack_start(GTK_BOX(vbox1), reg_hbox, FALSE, FALSE, 0);
211
212         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
213         gtk_widget_show(arrow);
214         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
215         gtk_widget_set_size_request(arrow, -1, 16);
216
217         btn_hbox = gtk_hbox_new(TRUE, 4);
218         gtk_widget_show(btn_hbox);
219         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
220
221         reg_btn = gtk_button_new_with_label(_("Add"));
222         gtk_widget_show(reg_btn);
223         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
224         g_signal_connect(G_OBJECT(reg_btn), "clicked",
225                          G_CALLBACK(prefs_actions_register_cb), NULL);
226
227         subst_btn = gtk_button_new_with_label(_(" Replace "));
228         gtk_widget_show(subst_btn);
229         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
230         g_signal_connect(G_OBJECT(subst_btn), "clicked",
231                          G_CALLBACK(prefs_actions_substitute_cb),
232                          NULL);
233
234         del_btn = gtk_button_new_with_label(_("Delete"));
235         gtk_widget_show(del_btn);
236         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
237         g_signal_connect(G_OBJECT(del_btn), "clicked",
238                          G_CALLBACK(prefs_actions_delete_cb), NULL);
239
240         help_button = gtk_button_new_with_label(_(" Syntax help "));
241         gtk_widget_show(help_button);
242         gtk_box_pack_end(GTK_BOX(reg_hbox), help_button, FALSE, FALSE, 0);
243         g_signal_connect(G_OBJECT(help_button), "clicked",
244                          G_CALLBACK(prefs_actions_help_cb), NULL);
245
246         cond_hbox = gtk_hbox_new(FALSE, 8);
247         gtk_widget_show(cond_hbox);
248         gtk_box_pack_start(GTK_BOX(vbox1), cond_hbox, TRUE, TRUE, 0);
249
250         cond_scrolledwin = gtk_scrolled_window_new(NULL, NULL);
251         gtk_widget_show(cond_scrolledwin);
252         gtk_widget_set_size_request(cond_scrolledwin, -1, 150);
253         gtk_box_pack_start(GTK_BOX(cond_hbox), cond_scrolledwin,
254                            TRUE, TRUE, 0);
255         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (cond_scrolledwin),
256                                        GTK_POLICY_AUTOMATIC,
257                                        GTK_POLICY_AUTOMATIC);
258
259         title[0] = _("Current actions");
260         cond_clist = gtk_clist_new_with_titles(1, title);
261         gtk_widget_show(cond_clist);
262         gtk_container_add(GTK_CONTAINER (cond_scrolledwin), cond_clist);
263         gtk_clist_set_column_width(GTK_CLIST (cond_clist), 0, 80);
264         gtk_clist_set_selection_mode(GTK_CLIST (cond_clist),
265                                      GTK_SELECTION_BROWSE);
266         GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(cond_clist)->column[0].button,
267                                GTK_CAN_FOCUS);
268         g_signal_connect(G_OBJECT(cond_clist), "select_row",
269                          G_CALLBACK(prefs_actions_select), NULL);
270         g_signal_connect_after(G_OBJECT(cond_clist), "row_move",
271                                G_CALLBACK(prefs_actions_row_move),
272                                NULL);
273
274         btn_vbox = gtk_vbox_new(FALSE, 8);
275         gtk_widget_show(btn_vbox);
276         gtk_box_pack_start(GTK_BOX(cond_hbox), btn_vbox, FALSE, FALSE, 0);
277
278         up_btn = gtk_button_new_with_label(_("Up"));
279         gtk_widget_show(up_btn);
280         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 0);
281         g_signal_connect(G_OBJECT(up_btn), "clicked",
282                          G_CALLBACK(prefs_actions_up), NULL);
283
284         down_btn = gtk_button_new_with_label(_("Down"));
285         gtk_widget_show(down_btn);
286         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
287         g_signal_connect(G_OBJECT(down_btn), "clicked",
288                          G_CALLBACK(prefs_actions_down), NULL);
289
290         gtk_widget_show(window);
291
292         actions.window = window;
293         actions.ok_btn = ok_btn;
294
295         actions.name_entry = name_entry;
296         actions.cmd_entry  = cmd_entry;
297
298         actions.actions_clist = cond_clist;
299 }
300
301
302 void prefs_actions_read_config(void)
303 {
304         gchar *rcpath;
305         FILE *fp;
306         gchar buf[PREFSBUFSIZE];
307         gchar *act;
308
309         debug_print("Reading actions configurations...\n");
310
311         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
312         if ((fp = fopen(rcpath, "rb")) == NULL) {
313                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
314                 g_free(rcpath);
315                 return;
316         }
317         g_free(rcpath);
318
319         while (prefs_common.actions_list != NULL) {
320                 act = (gchar *)prefs_common.actions_list->data;
321                 prefs_common.actions_list =
322                         g_slist_remove(prefs_common.actions_list, act);
323                 g_free(act);
324         }
325
326         while (fgets(buf, sizeof(buf), fp) != NULL) {
327                 const gchar *src_codeset = conv_get_current_charset_str();
328                 const gchar *dest_codeset = CS_UTF_8;
329                 gchar *tmp;
330
331                 tmp = conv_codeset_strdup(buf, src_codeset, dest_codeset);
332                 if (!tmp) {
333                         g_warning("Faild to convert character set of action configuration\n");
334                         tmp = g_strdup(buf);
335                 }
336
337                 g_strchomp(tmp);
338                 act = strstr(tmp, ": ");
339                 if (act && act[2] && 
340                     action_get_type(&act[2]) != ACTION_ERROR)
341                         prefs_common.actions_list =
342                                 g_slist_append(prefs_common.actions_list,
343                                                tmp);
344                 else
345                         g_free(tmp);
346         }
347         fclose(fp);
348 }
349
350 void prefs_actions_write_config(void)
351 {
352         gchar *rcpath;
353         PrefFile *pfile;
354         GSList *cur;
355
356         debug_print("Writing actions configuration...\n");
357
358         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
359         if ((pfile= prefs_write_open(rcpath)) == NULL) {
360                 g_warning("failed to write configuration to file\n");
361                 g_free(rcpath);
362                 return;
363         }
364
365         for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
366                 gchar *tmp = (gchar *)cur->data;
367                 const gchar *src_codeset = CS_UTF_8;
368                 const gchar *dest_codeset = conv_get_current_charset_str();
369                 gchar *act;
370
371                 act = conv_codeset_strdup(tmp, src_codeset, dest_codeset);
372                 if (!act) {
373                         g_warning("Faild to convert character set of action configuration\n");
374                         act = g_strdup(act);
375                 }
376
377                 if (fputs(act, pfile->fp) == EOF ||
378                     fputc('\n', pfile->fp) == EOF) {
379                         FILE_OP_ERROR(rcpath, "fputs || fputc");
380                         prefs_file_close_revert(pfile);
381                         g_free(rcpath);
382                         return;
383                 }
384                 g_free(act);
385         }
386         
387         g_free(rcpath);
388
389         if (prefs_file_close(pfile) < 0) {
390                 g_warning("failed to write configuration to file\n");
391                 return;
392         }
393 }
394
395 static void prefs_actions_set_dialog(void)
396 {
397         GtkCList *clist = GTK_CLIST(actions.actions_clist);
398         GSList *cur;
399         gchar *action_str[1];
400         gint row;
401
402         gtk_clist_freeze(clist);
403         gtk_clist_clear(clist);
404
405         action_str[0] = _("(New)");
406         row = gtk_clist_append(clist, action_str);
407         gtk_clist_set_row_data(clist, row, NULL);
408
409         for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
410                 gchar *action[1];
411
412                 action[0] = (gchar *)cur->data;
413                 row = gtk_clist_append(clist, action);
414                 gtk_clist_set_row_data(clist, row, action[0]);
415         }
416
417         gtk_clist_thaw(clist);
418 }
419
420 static void prefs_actions_set_list(void)
421 {
422         gint row = 1;
423         gchar *action;
424
425         g_slist_free(prefs_common.actions_list);
426         prefs_common.actions_list = NULL;
427
428         while ((action = (gchar *)gtk_clist_get_row_data
429                 (GTK_CLIST(actions.actions_clist), row)) != NULL) {
430                 prefs_common.actions_list =
431                         g_slist_append(prefs_common.actions_list, action);
432                 row++;
433         }
434 }
435
436 #define GET_ENTRY(entry) \
437         entry_text = gtk_entry_get_text(GTK_ENTRY(entry))
438
439 static gint prefs_actions_clist_set_row(gint row)
440 {
441         GtkCList *clist = GTK_CLIST(actions.actions_clist);
442         const gchar *entry_text;
443         gint len;
444         gchar action[PREFSBUFSIZE];
445         gchar *buf[1];
446
447         g_return_val_if_fail(row != 0, -1);
448
449         GET_ENTRY(actions.name_entry);
450         if (entry_text[0] == '\0') {
451                 alertpanel_error(_("Menu name is not set."));
452                 return -1;
453         }
454
455         if (strchr(entry_text, ':')) {
456                 alertpanel_error(_("Colon ':' is not allowed in the menu name."));
457                 return -1;
458         }
459
460         strncpy(action, entry_text, PREFSBUFSIZE - 1);
461         g_strstrip(action);
462
463         /* Keep space for the ': ' delimiter */
464         len = strlen(action) + 2;
465         if (len >= PREFSBUFSIZE - 1) {
466                 alertpanel_error(_("Menu name is too long."));
467                 return -1;
468         }
469
470         strcat(action, ": ");
471
472         GET_ENTRY(actions.cmd_entry);
473
474         if (entry_text[0] == '\0') {
475                 alertpanel_error(_("Command line not set."));
476                 return -1;
477         }
478
479         if (len + strlen(entry_text) >= PREFSBUFSIZE - 1) {
480                 alertpanel_error(_("Menu name and command are too long."));
481                 return -1;
482         }
483
484         if (action_get_type(entry_text) == ACTION_ERROR) {
485                 alertpanel_error(_("The command\n%s\nhas a syntax error."), 
486                                  entry_text);
487                 return -1;
488         }
489
490         strcat(action, entry_text);
491
492         buf[0] = action;
493         if (row < 0)
494                 row = gtk_clist_append(clist, buf);
495         else {
496                 gchar *old_action;
497                 gtk_clist_set_text(clist, row, 0, action);
498                 old_action = (gchar *) gtk_clist_get_row_data(clist, row);
499                 if (old_action)
500                         g_free(old_action);
501         }
502
503         buf[0] = g_strdup(action);
504
505         gtk_clist_set_row_data(clist, row, buf[0]);
506
507         prefs_actions_set_list();
508
509         return 0;
510 }
511
512 /* callback functions */
513
514 static void prefs_actions_register_cb(GtkWidget *w, gpointer data)
515 {
516         prefs_actions_clist_set_row(-1);
517 }
518
519 static void prefs_actions_substitute_cb(GtkWidget *w, gpointer data)
520 {
521         GtkCList *clist = GTK_CLIST(actions.actions_clist);
522         gchar *action;
523         gint row;
524
525         if (!clist->selection) return;
526
527         row = GPOINTER_TO_INT(clist->selection->data);
528         if (row == 0) return;
529
530         action = gtk_clist_get_row_data(clist, row);
531         if (!action) return;
532
533         prefs_actions_clist_set_row(row);
534 }
535
536 static void prefs_actions_delete_cb(GtkWidget *w, gpointer data)
537 {
538         GtkCList *clist = GTK_CLIST(actions.actions_clist);
539         gchar *action;
540         gint row;
541
542         if (!clist->selection) return;
543         row = GPOINTER_TO_INT(clist->selection->data);
544         if (row == 0) return;
545
546         if (alertpanel(_("Delete action"),
547                        _("Do you really want to delete this action?"),
548                        _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
549                 return;
550
551         action = gtk_clist_get_row_data(clist, row);
552         g_free(action);
553         gtk_clist_remove(clist, row);
554         prefs_common.actions_list = g_slist_remove(prefs_common.actions_list,
555                                                    action);
556 }
557
558 static void prefs_actions_up(GtkWidget *w, gpointer data)
559 {
560         GtkCList *clist = GTK_CLIST(actions.actions_clist);
561         gint row;
562
563         if (!clist->selection) return;
564
565         row = GPOINTER_TO_INT(clist->selection->data);
566         if (row > 1)
567                 gtk_clist_row_move(clist, row, row - 1);
568 }
569
570 static void prefs_actions_down(GtkWidget *w, gpointer data)
571 {
572         GtkCList *clist = GTK_CLIST(actions.actions_clist);
573         gint row;
574
575         if (!clist->selection) return;
576
577         row = GPOINTER_TO_INT(clist->selection->data);
578         if (row > 0 && row < clist->rows - 1)
579                 gtk_clist_row_move(clist, row, row + 1);
580 }
581
582 #define ENTRY_SET_TEXT(entry, str) \
583         gtk_entry_set_text(GTK_ENTRY(entry), str ? str : "")
584
585 static void prefs_actions_select(GtkCList *clist, gint row, gint column,
586                                  GdkEvent *event)
587 {
588         gchar *action;
589         gchar *cmd;
590         gchar buf[PREFSBUFSIZE];
591         action = gtk_clist_get_row_data(clist, row);
592
593         if (!action) {
594                 ENTRY_SET_TEXT(actions.name_entry, "");
595                 ENTRY_SET_TEXT(actions.cmd_entry, "");
596                 return;
597         }
598
599         strncpy(buf, action, PREFSBUFSIZE - 1);
600         buf[PREFSBUFSIZE - 1] = 0x00;
601         cmd = strstr(buf, ": ");
602
603         if (cmd && cmd[2])
604                 ENTRY_SET_TEXT(actions.cmd_entry, &cmd[2]);
605         else
606                 return;
607
608         *cmd = 0x00;
609         ENTRY_SET_TEXT(actions.name_entry, buf);
610 }
611
612 static void prefs_actions_row_move(GtkCList *clist,
613                                    gint source_row, gint dest_row)
614 {
615         prefs_actions_set_list();
616         if (gtk_clist_row_is_visible(clist, dest_row) != GTK_VISIBILITY_FULL) {
617                 gtk_clist_moveto(clist, dest_row, -1,
618                                  source_row < dest_row ? 1.0 : 0.0, 0.0);
619         }
620 }
621
622 static gint prefs_actions_deleted(GtkWidget *widget, GdkEventAny *event,
623                                   gpointer *data)
624 {
625         prefs_actions_cancel(widget, data);
626         return TRUE;
627 }
628
629 static gboolean prefs_actions_key_pressed(GtkWidget *widget, GdkEventKey *event,
630                                           gpointer data)
631 {
632         if (event && event->keyval == GDK_Escape)
633                 prefs_actions_cancel(widget, data);
634         return FALSE;
635 }
636
637 static void prefs_actions_cancel(GtkWidget *w, gpointer data)
638 {
639         prefs_actions_read_config();
640         gtk_widget_hide(actions.window);
641         inc_unlock();
642 }
643
644 static void prefs_actions_ok(GtkWidget *widget, gpointer data)
645 {
646         MainWindow *mainwin = (MainWindow *) data;
647         GList *list;
648         GList *iter;
649         MessageView *msgview;
650         Compose *compose;
651
652         prefs_actions_write_config();
653
654         /* Update mainwindow actions menu */
655         main_window_update_actions_menu(mainwin);
656
657         /* Update separated message view actions menu */
658         list = messageview_get_msgview_list();
659         for (iter = list; iter; iter = iter->next) {
660                 msgview = (MessageView *) iter->data;
661                 messageview_update_actions_menu(msgview);
662         }
663
664         /* Update compose windows actions menu */
665         list = compose_get_compose_list();
666         for (iter = list; iter; iter = iter->next) {
667                 compose = (Compose *) iter->data;
668                 compose_update_actions_menu(compose);
669         }
670
671         gtk_widget_hide(actions.window);
672         inc_unlock();
673 }
674
675 /*
676  * Strings describing action format strings
677  * 
678  * When adding new lines, remember to put one string for each line
679  */
680 static gchar *actions_desc_strings[] = {
681         N_("MENU NAME:"), NULL,
682         "      ",   N_("Use / in menu name to make submenus."),
683         "", NULL,
684         N_("COMMAND LINE:"), NULL,
685         N_("Begin with:"), NULL,
686         "     |",   N_("to send message body or selection to command's standard input"),
687         "     >",   N_("to send user provided text to command's standard input"),
688         "     *",   N_("to send user provided hidden text to command's standard input"),
689         N_("End with:"), NULL, 
690         "     |",   N_("to replace message body or selection with command's standard output"),
691         "     >",   N_("to insert command's standard output without replacing old text"),
692         "     &",   N_("to run command asynchronously"),
693         N_("Use:"), NULL, 
694         "     %f",  N_("for the file of the selected message in RFC822/2822 format "),
695         "     %F",  N_("for the list of the files of the selected messages in RFC822/2822 format"),
696         "     %p",  N_("for the file of the selected decoded message MIME part"),
697         "     %u",  N_("for a user provided argument"),
698         "     %h",  N_("for a user provided hidden argument (e.g. password)"),
699         "     %s",  N_("for the text selection"),
700         "  %as{}",  N_("apply filtering actions between {} to selected messages"),
701         NULL
702 };
703
704
705 static DescriptionWindow actions_desc_win = { 
706         NULL, 
707         2,
708         N_("Description of symbols"),
709         actions_desc_strings
710 };
711
712
713 static void prefs_actions_help_cb(GtkWidget *w, gpointer data)
714 {
715         description_window_create(&actions_desc_win);
716 }