0.8.9claws5
[claws.git] / src / prefs_actions.c
index c1db9f10f299770cb2b6606276d8dd5068c14ddd..f78545c10aa0ffecd746247e4c15756f34451e5f 100644 (file)
@@ -50,6 +50,7 @@
 #include "procmsg.h"
 #include "gtkstext.h"
 #include "mimeview.h"
+#include "description_window.h"
 #include "textview.h"
 
 typedef enum
@@ -83,7 +84,6 @@ typedef struct _ChildInfo ChildInfo;
 
 struct _Children
 {
-       GtkWidget       *window;
        GtkWidget       *dialog;
        GtkWidget       *text;
        GtkWidget       *input_entry;
@@ -158,16 +158,21 @@ static void update_actions_menu           (GtkItemFactory *ifactory,
                                         gchar          *branch_path,
                                         gpointer        callback,
                                         gpointer        data);
+static void compose_actions_execute_cb (Compose        *compose,
+                                        guint           action_nb,
+                                        GtkWidget      *widget);
 static void mainwin_actions_execute_cb         (MainWindow     *mainwin,
                                         guint           action_nb,
                                         GtkWidget      *widget);
-static void compose_actions_execute_cb (Compose        *compose,
+static void msgview_actions_execute_cb (MessageView    *msgview, 
                                         guint           action_nb,
-                                        GtkWidget      *widget);
+                                        GtkWidget      *widget);
+static void message_actions_execute    (MessageView    *msgview,
+                                        guint           action_nb,
+                                        GtkCTree       *ctree);
 static guint get_action_type           (gchar          *action);
 
 static gboolean execute_actions                (gchar          *action, 
-                                        GtkWidget      *window,
                                         GtkCTree       *ctree, 
                                         GtkWidget      *text,
                                         GdkFont        *msgfont,
@@ -203,7 +208,9 @@ static void update_io_dialog                (Children       *children);
 
 static void hide_io_dialog_cb          (GtkWidget      *widget,
                                         gpointer        data);
-
+static gint io_dialog_key_pressed_cb   (GtkWidget      *widget,
+                                        GdkEventKey    *event,
+                                        gpointer        data);
 static void catch_output               (gpointer                data,
                                         gint                    source,
                                         GdkInputCondition       cond);
@@ -214,6 +221,7 @@ static void catch_status            (gpointer                data,
                                         gint                    source,
                                         GdkInputCondition       cond);
 
+
 void prefs_actions_open(MainWindow *mainwin)
 {
 #if 0
@@ -261,9 +269,7 @@ static void prefs_actions_create(MainWindow *mainwin)
        GtkWidget *cond_scrolledwin;
        GtkWidget *cond_clist;
 
-       GtkWidget *help_vbox;
-       GtkWidget *help_label;
-       GtkWidget *help_toggle;
+       GtkWidget *help_button;
 
        GtkWidget *btn_vbox;
        GtkWidget *up_btn;
@@ -330,30 +336,6 @@ static void prefs_actions_create(MainWindow *mainwin)
 
        gtk_widget_show_all(entry_vbox);
 
-       help_vbox = gtk_vbox_new(FALSE, 8);
-       gtk_box_pack_start(GTK_BOX(vbox1), help_vbox, FALSE, FALSE, 0);
-
-       help_label = gtk_label_new
-               (_("Menu name:\n"
-                  " Use / in menu name to make submenus.\n"
-                  "Command line:\n"
-                  " Begin with:\n"
-                  "   | to send message body or selection to command\n"
-                  "   > to send user provided text to command\n"
-                  "   * to send user provided hidden text to command\n"
-                  " End with:\n"
-                  "   | to replace message body or selection with command output\n"
-                  "   > to insert command's output without replacing old text\n"
-                  "   & to run command asynchronously\n"
-                  " Use %f for message file name\n"
-                  "   %F for the list of the file names of selected messages\n"
-                  "   %p for the selected message MIME part."));
-       gtk_misc_set_alignment(GTK_MISC(help_label), 0, 0.5);
-       gtk_label_set_justify(GTK_LABEL(help_label), GTK_JUSTIFY_LEFT);
-       gtk_widget_show(help_label);
-       gtk_box_pack_start(GTK_BOX(help_vbox), help_label, FALSE, FALSE, 0);
-       gtk_widget_hide(help_vbox);
-
        /* register / substitute / delete */
 
        reg_hbox = gtk_hbox_new(FALSE, 4);
@@ -388,11 +370,11 @@ static void prefs_actions_create(MainWindow *mainwin)
        gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
                           GTK_SIGNAL_FUNC(prefs_actions_delete_cb), NULL);
 
-       help_toggle = gtk_toggle_button_new_with_label(_(" Syntax help "));
-       gtk_widget_show(help_toggle);
-       gtk_box_pack_end(GTK_BOX(reg_hbox), help_toggle, FALSE, FALSE, 0);
-       gtk_signal_connect(GTK_OBJECT(help_toggle), "toggled",
-                          GTK_SIGNAL_FUNC(prefs_actions_help_cb), help_vbox);
+       help_button = gtk_button_new_with_label(_(" Syntax help "));
+       gtk_widget_show(help_button);
+       gtk_box_pack_end(GTK_BOX(reg_hbox), help_button, FALSE, FALSE, 0);
+       gtk_signal_connect(GTK_OBJECT(help_button), "clicked",
+                          GTK_SIGNAL_FUNC(prefs_actions_help_cb), NULL);
 
        cond_hbox = gtk_hbox_new(FALSE, 8);
        gtk_widget_show(cond_hbox);
@@ -449,13 +431,6 @@ static void prefs_actions_create(MainWindow *mainwin)
        actions.actions_clist = cond_clist;
 }
 
-static void prefs_actions_help_cb(GtkWidget *w, gpointer data)
-{
-       if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)))
-               gtk_widget_show(GTK_WIDGET(data));
-       else
-               gtk_widget_hide(GTK_WIDGET(data));
-}
 
 void prefs_actions_read_config(void)
 {
@@ -513,7 +488,7 @@ void prefs_actions_write_config(void)
                if (fputs(act, pfile->fp) == EOF ||
                    fputc('\n', pfile->fp) == EOF) {
                        FILE_OP_ERROR(rcpath, "fputs || fputc");
-                       prefs_write_close_revert(pfile);
+                       prefs_file_close_revert(pfile);
                        g_free(rcpath);
                        return;
                }
@@ -521,7 +496,7 @@ void prefs_actions_write_config(void)
        
        g_free(rcpath);
 
-       if (prefs_write_close(pfile) < 0) {
+       if (prefs_file_close(pfile) < 0) {
                g_warning("failed to write configuration to file\n");
                return;
        }
@@ -576,8 +551,6 @@ static guint get_action_type(gchar *action)
                } else if (p[0] == '&') {
                        if (p[1] == 0x00)
                                action_type |= ACTION_ASYNC;
-                       else
-                               action_type = ACTION_ERROR;
                }
                p++;
        }
@@ -1017,6 +990,7 @@ void update_compose_actions_menu(GtkItemFactory *ifactory,
                            compose);
 }
 
+
 void actions_execute(gpointer data, 
                     guint action_nb,
                     GtkWidget *widget,
@@ -1024,9 +998,10 @@ void actions_execute(gpointer data,
 {
        if (source == TOOLBAR_MAIN) 
                mainwin_actions_execute_cb((MainWindow*)data, action_nb, widget);
-
        else if (source == TOOLBAR_COMPOSE)
                compose_actions_execute_cb((Compose*)data, action_nb, widget);
+       else if (source == TOOLBAR_MSGVIEW)
+               msgview_actions_execute_cb((MessageView*)data, action_nb, widget);      
 }
 
 
@@ -1100,18 +1075,33 @@ static void compose_actions_execute_cb(Compose *compose, guint action_nb,
                return;
        }
 
-       execute_actions(action, compose->window, NULL, compose->text, NULL, 0,
-                       NULL);
+       execute_actions(action, NULL, compose->text, NULL, 0, NULL);
 }
 
 static void mainwin_actions_execute_cb(MainWindow *mainwin, guint action_nb,
                                       GtkWidget *widget)
 {
-       MessageView *messageview = mainwin->messageview;
+       message_actions_execute(mainwin->messageview, action_nb,
+                               GTK_CTREE(mainwin->summaryview->ctree));
+}
+
+static void msgview_actions_execute_cb(MessageView *msgview, guint action_nb,
+                                      GtkWidget *widget)
+{
+       message_actions_execute(msgview, action_nb, NULL);
+       
+}
+
+static void message_actions_execute(MessageView *msgview, guint action_nb,
+                                   GtkCTree *ctree)
+{
        TextView    *textview = NULL;
        gchar       *buf,
                    *action;
        MimeView    *mimeview = NULL;
+       GdkFont     *msgfont  = NULL;
+       guint        body_pos = 0;
+       GtkWidget   *text     = NULL;
 
        g_return_if_fail(action_nb < g_slist_length(prefs_common.actions_list));
 
@@ -1123,31 +1113,37 @@ static void mainwin_actions_execute_cb(MainWindow *mainwin, guint action_nb,
        /* Point to the beginning of the command-line */
        action += 2;
 
-       switch (messageview->type) {
+       switch (msgview->type) {
        case MVIEW_TEXT:
-               if (messageview->textview && messageview->textview->text)
-                       textview = messageview->textview;
+               if (msgview->textview && msgview->textview->text)
+                       textview = msgview->textview;
                break;
        case MVIEW_MIME:
-               if (messageview->mimeview) {
-                       mimeview = messageview->mimeview;
-                       if (messageview->mimeview->type == MIMEVIEW_TEXT &&
-                                       messageview->mimeview->textview &&
-                                       messageview->mimeview->textview->text)
-                               textview = messageview->mimeview->textview;
+               if (msgview->mimeview) {
+                       mimeview = msgview->mimeview;
+                       if (msgview->mimeview->type == MIMEVIEW_TEXT &&
+                           msgview->mimeview->textview &&
+                           msgview->mimeview->textview->text)
+                               textview = msgview->mimeview->textview;
                } 
                break;
        }
 
-       execute_actions(action, mainwin->window,
-                       GTK_CTREE(mainwin->summaryview->ctree), textview->text,
-                       textview->msgfont, textview->body_pos, mimeview);
+       if (textview) {
+               text     = textview->text;
+               msgfont  = textview->msgfont;
+               body_pos = textview->body_pos;
+       }
+       
+       execute_actions(action, ctree, text, msgfont, body_pos, mimeview);
 }
 
-static gboolean execute_actions(gchar *action, GtkWidget *window,
-                               GtkCTree *ctree, GtkWidget *text, 
-                               GdkFont *msgfont, gint body_pos,
-                               MimeView *mimeview)
+static gboolean execute_actions(gchar    *action, 
+                               GtkCTree  *ctree,
+                               GtkWidget *text, 
+                               GdkFont   *msgfont,
+                               gint       body_pos,
+                               MimeView  *mimeview)
 {
        GList *cur, *selection = NULL;
        GSList *children_list = NULL;
@@ -1235,7 +1231,6 @@ static gboolean execute_actions(gchar *action, GtkWidget *window,
                GSList *cur;
 
                children->action  = g_strdup(action);
-               children->window  = window;
                children->dialog  = NULL;
                children->list    = children_list;
                children->nb      = g_slist_length(children_list);
@@ -1528,6 +1523,15 @@ static void hide_io_dialog_cb(GtkWidget *w, gpointer data)
        }
 }
 
+static gint io_dialog_key_pressed_cb(GtkWidget *widget,
+                                    GdkEventKey        *event,
+                                    gpointer    data)
+{
+       if (event && event->keyval == GDK_Escape)
+               hide_io_dialog_cb(widget, data);
+       return TRUE;    
+}
+
 static void childinfo_close_pipes(ChildInfo *child_info)
 {
        if (child_info->tag_in > 0)
@@ -1572,6 +1576,11 @@ static void update_io_dialog(Children *children)
                gtk_widget_set_sensitive(children->close_btn, TRUE);
                if (children->input_hbox)
                        gtk_widget_set_sensitive(children->input_hbox, FALSE);
+               gtk_widget_grab_focus(children->close_btn);
+               gtk_signal_connect(GTK_OBJECT(children->dialog), 
+                                  "key_press_event",
+                                  GTK_SIGNAL_FUNC(io_dialog_key_pressed_cb),
+                                  children);
        }
 
        if (children->output) {
@@ -1792,3 +1801,42 @@ static void catch_output(gpointer data, gint source, GdkInputCondition cond)
        }
        wait_for_children(child_info->children);
 }
+
+/*
+ * Strings describing action format strings
+ * 
+ * When adding new lines, remember to put one string for each line
+ */
+static gchar *actions_desc_strings[] = {
+       N_("Menu name:"), NULL,
+       "      ",   N_("Use / in menu name to make submenus."),
+       "", NULL,
+       N_("Command line:"), NULL,
+       N_("* Begin with:"), NULL,
+       "     |",   N_("to send message body or selection to command"),
+       "     >",   N_("to send user provided text to command"),
+       "     *",   N_("to send user provided hidden text to command"),
+       N_("* End with:"), NULL, 
+       "     |",   N_("to replace message body or selection with command output"),
+       "     >",   N_("to insert command's output without replacing old text"),
+       "     &",   N_("to run command asynchronously"),
+       N_("* Use:"), NULL, 
+       "     %f",  N_("for message file name"),
+       "     %F",  N_("for the list of the file names of selected messages"),
+       "     %p",  N_("for the selected message MIME part."),
+       NULL
+};
+
+
+static DescriptionWindow actions_desc_win = { 
+        NULL, 
+        2,
+        N_("Description of symbols"),
+        actions_desc_strings
+};
+
+
+static void prefs_actions_help_cb(GtkWidget *w, gpointer data)
+{
+       description_window_create(&actions_desc_win);
+}