2005-09-14 [paul] 1.9.14cvs26
[claws.git] / src / prefs_actions.c
index 5a7bf676d9e86b5627ed7c4ebc2a0c13d9654422..dbba7e8d6155115bafbdf359f91b56cf5dc052ac 100644 (file)
@@ -24,6 +24,7 @@
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <stdio.h>
@@ -31,7 +32,6 @@
 #include <string.h>
 #include <errno.h>
 
-#include "intl.h"
 #include "prefs_gtk.h"
 #include "inc.h"
 #include "utils.h"
@@ -43,6 +43,7 @@
 #include "prefs_actions.h"
 #include "action.h"
 #include "description_window.h"
+#include "gtkutils.h"
 
 enum {
        PREFS_ACTIONS_STRING,   /*!< string pointer managed by list store, 
@@ -67,6 +68,8 @@ static struct Actions
        GtkWidget *actions_list_view;
 } actions;
 
+static int modified = FALSE;
+
 /* widget creating functions */
 static void prefs_actions_create       (MainWindow *mainwin);
 static void prefs_actions_set_dialog   (void);
@@ -248,7 +251,7 @@ static void prefs_actions_create(MainWindow *mainwin)
                         G_CALLBACK(prefs_actions_substitute_cb),
                         NULL);
 
-       del_btn = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
+       del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
        gtk_widget_show(del_btn);
        gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT(del_btn), "clicked",
@@ -315,7 +318,7 @@ void prefs_actions_read_config(void)
        debug_print("Reading actions configurations...\n");
 
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACTIONS_RC, NULL);
-       if ((fp = fopen(rcpath, "rb")) == NULL) {
+       if ((fp = g_fopen(rcpath, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
                g_free(rcpath);
                return;
@@ -429,7 +432,6 @@ static void prefs_actions_set_dialog(void)
 
 static void prefs_actions_set_list(void)
 {
-       gchar *action;
        GtkTreeIter iter;
        GtkListStore *store;
        
@@ -486,6 +488,15 @@ static gint prefs_actions_clist_set_row(GtkTreeIter *row)
        }
 
        strncpy(action, entry_text, PREFSBUFSIZE - 1);
+       
+       while (strstr(action, "//")) {
+               char *to_move = strstr(action, "//")+1;
+               char *where = strstr(action, "//");
+               int old_len = strlen(action);
+               memmove(where, to_move, strlen(to_move));
+               action[old_len-1] = '\0';
+       }
+       
        g_strstrip(action);
 
        /* Keep space for the ': ' delimiter */
@@ -531,6 +542,7 @@ static gint prefs_actions_clist_set_row(GtkTreeIter *row)
 static void prefs_actions_register_cb(GtkWidget *w, gpointer data)
 {
        prefs_actions_clist_set_row(NULL);
+       modified = FALSE;
 }
 
 static void prefs_actions_substitute_cb(GtkWidget *w, gpointer data)
@@ -555,6 +567,7 @@ static void prefs_actions_substitute_cb(GtkWidget *w, gpointer data)
 
        gtk_tree_path_free(path_sel);
        gtk_tree_path_free(path_new);
+       modified = FALSE;
 }
 
 static void prefs_actions_delete_cb(GtkWidget *w, gpointer data)
@@ -588,13 +601,13 @@ static void prefs_actions_up(GtkWidget *w, gpointer data)
 {
        GtkTreePath *prev, *sel, *try;
        GtkTreeIter isel;
-       GtkListStore *store;
+       GtkListStore *store = NULL;
        GtkTreeIter iprev;
        
        if (!gtk_tree_selection_get_selected
                (gtk_tree_view_get_selection
                        (GTK_TREE_VIEW(actions.actions_list_view)),
-                (GtkTreeModel **) &store,      
+                (GtkTreeModel **)(GtkListStore *) store,       
                 &isel))
                return;
 
@@ -630,14 +643,14 @@ static void prefs_actions_up(GtkWidget *w, gpointer data)
 
 static void prefs_actions_down(GtkWidget *w, gpointer data)
 {
-       GtkListStore *store;
+       GtkListStore *store = NULL;
        GtkTreeIter next, sel;
        GtkTreePath *try;
        
        if (!gtk_tree_selection_get_selected
                (gtk_tree_view_get_selection
                        (GTK_TREE_VIEW(actions.actions_list_view)),
-                (GtkTreeModel **) &store,
+                (GtkTreeModel **)(GtkListStore *) store,
                 &sel))
                return;
 
@@ -672,11 +685,24 @@ static gboolean prefs_actions_key_pressed(GtkWidget *widget, GdkEventKey *event,
 {
        if (event && event->keyval == GDK_Escape)
                prefs_actions_cancel(widget, data);
+       else {
+               GtkWidget *focused = gtkut_get_focused_child(
+                                       GTK_CONTAINER(widget));
+               if (focused && GTK_IS_EDITABLE(focused)) {
+                       modified = TRUE;
+               }
+       }
        return FALSE;
 }
 
 static void prefs_actions_cancel(GtkWidget *w, gpointer data)
 {
+       if (modified && alertpanel(_("Entry not saved"),
+                                _("The entry was not saved. Close anyway?"),
+                                GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT) {
+               return;
+       }
+       modified = FALSE;
        prefs_actions_read_config();
        gtk_widget_hide(actions.window);
        inc_unlock();
@@ -690,6 +716,12 @@ static void prefs_actions_ok(GtkWidget *widget, gpointer data)
        MessageView *msgview;
        Compose *compose;
 
+       if (modified && alertpanel(_("Entry not saved"),
+                                _("The entry was not saved. Close anyway?"),
+                                GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT) {
+               return;
+       }
+       modified = FALSE;
        prefs_actions_write_config();
 
        /* Update mainwindow actions menu */
@@ -808,7 +840,7 @@ static GtkWidget *prefs_actions_list_view_create(void)
        list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model));
        g_object_unref(model);  
        
-       gtk_tree_view_set_rules_hint(list_view, TRUE);
+       gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
        
        selector = gtk_tree_view_get_selection(list_view);
        gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
@@ -873,7 +905,7 @@ static gboolean prefs_actions_selected(GtkTreeSelection *selector,
        if (cmd && cmd[2])
                ENTRY_SET_TEXT(actions.cmd_entry, &cmd[2]);
        else
-               return;
+               return TRUE;
 
        *cmd = 0x00;
        ENTRY_SET_TEXT(actions.name_entry, buf);