2005-07-11 [paul] 1.9.12cvs34
[claws.git] / src / prefs_template.c
index badbd8adda4d5fff81fa4b66de129dd67a247254..d65a01b9055eedfc09c8a8d805443a7529beda62 100644 (file)
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <string.h>
 #include <dirent.h>
 #include <sys/stat.h>
 
-#include "intl.h"
 #include "template.h"
 #include "main.h"
 #include "inc.h"
@@ -38,6 +38,7 @@
 #include "compose.h"
 #include "addr_compl.h"
 #include "quote_fmt.h"
+#include "prefs_common.h"
 
 enum {
        TEMPL_TEXT,
@@ -58,6 +59,8 @@ static struct Templates {
        GtkWidget *text_value;
 } templates;
 
+static int modified = FALSE;
+
 /* widget creating functions */
 static void prefs_template_window_create       (void);
 static void prefs_template_window_setup                (void);
@@ -196,8 +199,10 @@ static void prefs_template_window_create(void)
        scroll2 = gtk_scrolled_window_new(NULL, NULL);
        gtk_widget_show(scroll2);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll2),
-                                      GTK_POLICY_NEVER,
+                                      GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll2),
+                                           GTK_SHADOW_IN);
        gtk_box_pack_start(GTK_BOX(vbox1), scroll2, TRUE, TRUE, 0);
 
        text_value = gtk_text_view_new();
@@ -240,7 +245,7 @@ static void prefs_template_window_create(void)
                         G_CALLBACK(prefs_template_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(hbox3), del_btn, FALSE, TRUE, 0);
        g_signal_connect(G_OBJECT(del_btn), "clicked",
@@ -301,8 +306,6 @@ static void prefs_template_window_setup(void)
 {
        GSList *tmpl_list;
        GSList *cur;
-       gchar *title[1];
-       gint row;
        Template *tmpl;
        GtkListStore *store;
 
@@ -351,6 +354,13 @@ static gboolean prefs_template_key_pressed_cb(GtkWidget *widget,
 {
        if (event && event->keyval == GDK_Escape)
                prefs_template_cancel_cb();
+       else {
+               GtkWidget *focused = gtkut_get_focused_child(
+                                       GTK_CONTAINER(widget));
+               if (focused && GTK_IS_EDITABLE(focused)) {
+                       modified = TRUE;
+               }
+       }
        return FALSE;
 }
 
@@ -358,6 +368,12 @@ static void prefs_template_ok_cb(void)
 {
        GSList *tmpl_list;
 
+       if (modified && alertpanel(_("Entry not saved"),
+                                _("The entry was not saved. Close anyway?"),
+                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT) {
+               return;
+       }
+       modified = FALSE;
        tmpl_list = prefs_template_get_list();
        template_set_config(tmpl_list);
        compose_reflect_prefs_all();
@@ -368,6 +384,12 @@ static void prefs_template_ok_cb(void)
 
 static void prefs_template_cancel_cb(void)
 {
+       if (modified && alertpanel(_("Entry not saved"),
+                                _("The entry was not saved. Close anyway?"),
+                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT) {
+               return;
+       }
+       modified = FALSE;
        prefs_template_clear();
        gtk_widget_hide(templates.window);
        inc_unlock();
@@ -426,7 +448,6 @@ static GSList *prefs_template_get_list(void)
 static void prefs_template_list_view_set_row(GtkTreeIter *row)
 {
        Template *tmpl;
-       Template *tmp_tmpl;
        gchar *name;
        gchar *subject;
        gchar *to;
@@ -503,6 +524,7 @@ static void prefs_template_list_view_set_row(GtkTreeIter *row)
 static void prefs_template_register_cb(void)
 {
        prefs_template_list_view_set_row(NULL);
+       modified = FALSE;
 }
 
 static void prefs_template_substitute_cb(void)
@@ -525,6 +547,7 @@ static void prefs_template_substitute_cb(void)
        if (!tmpl) return;
 
        prefs_template_list_view_set_row(&row);
+       modified = FALSE;
 }
 
 static void prefs_template_delete_cb(void)
@@ -604,7 +627,7 @@ static GtkWidget *prefs_template_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);