From dd6ec93f43a4dd6d957078483ab075cb039c62a4 Mon Sep 17 00:00:00 2001 From: hiro Date: Wed, 21 Jul 2010 02:53:19 +0000 Subject: src/prefs_template.c: confirm on cancel if templates are modified. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2629 ee746299-78ed-0310-b773-934348b2243d --- src/prefs_template.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/prefs_template.c') diff --git a/src/prefs_template.c b/src/prefs_template.c index 4d2d3764..d64a9356 100644 --- a/src/prefs_template.c +++ b/src/prefs_template.c @@ -1,7 +1,7 @@ /* * Sylpheed templates subsystem * Copyright (C) 2001 Alexander Barinov - * Copyright (C) 2001-2006 Hiroyuki Yamamoto + * Copyright (C) 2001-2010 Hiroyuki Yamamoto * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -55,6 +55,9 @@ static struct Templates { GtkWidget *confirm_area; GtkWidget *ok_btn; GtkWidget *cancel_btn; + + gboolean entry_modified; + gboolean list_modified; } templates; /* widget creating functions */ @@ -71,6 +74,8 @@ static gint prefs_template_deleted_cb (GtkWidget *widget, static gboolean prefs_template_key_pressed_cb (GtkWidget *widget, GdkEventKey *event, gpointer data); +static void prefs_template_changed_cb (GtkEditable *editable, + gpointer data); static void prefs_template_cancel_cb (void); static void prefs_template_ok_cb (void); static void prefs_template_select_cb (GtkCList *clist, @@ -105,6 +110,8 @@ void prefs_template_open(void) gtk_widget_show(entry); \ gtk_table_attach(GTK_TABLE(table), entry, 1, 2, row, (row + 1), \ GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \ + g_signal_connect(G_OBJECT(entry), "changed", \ + G_CALLBACK(prefs_template_changed_cb), NULL); \ } static void prefs_template_window_create(void) @@ -138,6 +145,8 @@ static void prefs_template_window_create(void) GtkWidget *ok_btn; GtkWidget *cancel_btn; + GtkTextBuffer *buffer; + gchar *title[1]; /* main window */ @@ -168,6 +177,8 @@ static void prefs_template_window_create(void) entry_name = gtk_entry_new(); gtk_widget_show(entry_name); gtk_box_pack_start(GTK_BOX(hbox1), entry_name, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(entry_name), "changed", + G_CALLBACK(prefs_template_changed_cb), NULL); /* table for headers */ table = gtk_table_new(5, 2, FALSE); @@ -203,6 +214,9 @@ static void prefs_template_window_create(void) gtk_widget_set_size_request(text_value, 360, 120); gtk_container_add(GTK_CONTAINER(scroll2), text_value); gtk_text_view_set_editable(GTK_TEXT_VIEW(text_value), TRUE); + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_value)); + g_signal_connect(G_OBJECT(buffer), "changed", + G_CALLBACK(prefs_template_changed_cb), NULL); /* vbox for buttons and templates list */ vbox2 = gtk_vbox_new(FALSE, 6); @@ -304,6 +318,8 @@ static void prefs_template_window_create(void) templates.confirm_area = confirm_area; templates.ok_btn = ok_btn; templates.cancel_btn = cancel_btn; + templates.entry_modified = FALSE; + templates.list_modified = FALSE; } static void prefs_template_window_setup(void) @@ -339,6 +355,9 @@ static void prefs_template_window_setup(void) g_slist_free(tmpl_list); gtk_clist_thaw(clist); + + templates.entry_modified = FALSE; + templates.list_modified = FALSE; } static void prefs_template_clear(void) @@ -370,6 +389,11 @@ static gboolean prefs_template_key_pressed_cb(GtkWidget *widget, return FALSE; } +static void prefs_template_changed_cb(GtkEditable *editable, gpointer data) +{ + templates.entry_modified = TRUE; +} + static void prefs_template_ok_cb(void) { GSList *tmpl_list; @@ -385,6 +409,14 @@ static void prefs_template_ok_cb(void) static void prefs_template_cancel_cb(void) { + if (templates.entry_modified || templates.list_modified) { + if (alertpanel(_("Templates are modified"), + _("Really discard modification to templates?"), + GTK_STOCK_YES, GTK_STOCK_NO, NULL) + != G_ALERTDEFAULT) + return; + } + prefs_template_clear(); gtk_widget_hide(templates.window); main_window_popup(main_window_get()); @@ -426,6 +458,8 @@ static void prefs_template_select_cb(GtkCList *clist, gint row, gint column, gtk_text_buffer_set_text(buffer, "", 0); gtk_text_buffer_get_start_iter(buffer, &iter); gtk_text_buffer_insert(buffer, &iter, tmpl->value, -1); + + templates.entry_modified = FALSE; } static GSList *prefs_template_get_list(void) @@ -527,6 +561,8 @@ static gint prefs_template_clist_set_row(gint row) } gtk_clist_set_row_data(clist, row, tmpl); + templates.list_modified = TRUE; + return row; } @@ -570,4 +606,5 @@ static void prefs_template_delete_cb(void) tmpl = gtk_clist_get_row_data(clist, row); template_free(tmpl); gtk_clist_remove(clist, row); + templates.list_modified = TRUE; } -- cgit v1.2.3