? bug130748.patch
? depcomp
? gedit_210.diff
? intltool-extract.in
? intltool-merge.in
? intltool-update.in
? data/gedit.desktop.in
? gedit/ChangeLog.tmp
Index: gedit/ChangeLog
===================================================================
RCS file: /cvs/gnome/gedit/gedit/ChangeLog,v
retrieving revision 1.718
diff -u -p -r1.718 ChangeLog
--- gedit/ChangeLog	13 Dec 2004 18:43:12 -0000	1.718
+++ gedit/ChangeLog	13 Dec 2004 18:44:32 -0000
@@ -1,5 +1,26 @@
 2004-12-13  Paolo Maggi  <paolo@gnome.org>
 
+	Fixed bug #130748: Auto save settings are not reflecting immediately
+
+	* gedit-document.c (gedit_document_init)
+	(gedit_document_set_readonly) (gedit_document_real_loaded)
+	(gedit_document_auto_save)(gedit_document_save) 
+	(gedit_document_save_as):  use new auto_save and auto_save_interval 
+	member variable. 
+	(gedit_document_enable_auto_save): new function 
+	(gedit_document_set_auto_save_interval): new function 
+	(gedit_document_load_from_stdin): fixed a "typo" while checking the encoding
+
+	* gedit-document.h: Added prototype for	gedit_document_enable_auto_save (), 
+	and gedit_docuent_set_auto_save_interval ().
+
+	* gedit-prefs-manager-app.c (gedit_prefs_manager_app_init)
+	(gedit_prefs_manager_auto_save_changed): notifies when auto save is 
+	enabled and/or auto save interval is changed.
+	(gedit_prefs_manager_undo_changed): fixed a mem leak
+
+2004-12-13  Paolo Maggi  <paolo@gnome.org>
+
 	* dialogs/gedit-preferences-dialog.c (setup_editor_page): check for the 
 	validity of the auto_save interval.
 
Index: gedit/gedit-document.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.c,v
retrieving revision 1.106
diff -u -p -r1.106 gedit-document.c
--- gedit/gedit-document.c	6 Dec 2004 18:13:36 -0000	1.106
+++ gedit/gedit-document.c	13 Dec 2004 18:44:32 -0000
@@ -91,6 +91,9 @@ struct _GeditDocumentPrivate
 	gboolean  	     last_search_was_case_sensitive;
 	gboolean  	     last_search_was_entire_word;
 
+	gboolean             auto_save;
+	gint                 auto_save_interval;
+
 	guint		     auto_save_timeout;
 	gboolean	     last_save_was_manually; 
 
@@ -326,6 +329,13 @@ gedit_document_init (GeditDocument *docu
 					    gedit_prefs_manager_get_undo_actions_limit ());
 
 	gtk_source_buffer_set_check_brackets (GTK_SOURCE_BUFFER (document), FALSE);
+
+	document->priv->auto_save = gedit_prefs_manager_get_auto_save ();
+	document->priv->auto_save = (document->priv->auto_save != FALSE);
+
+	document->priv->auto_save_interval = gedit_prefs_manager_get_auto_save_interval ();
+	if (document->priv->auto_save_interval <= 0)
+		document->priv->auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
 }
 
 static void
@@ -470,18 +480,14 @@ gedit_document_new_with_uri (const gchar
 void 		
 gedit_document_set_readonly (GeditDocument *document, gboolean readonly)
 {
-	gboolean auto_save;
-	
 	gedit_debug (DEBUG_DOCUMENT, "");
 
 	g_return_if_fail (document != NULL);
 	g_return_if_fail (document->priv != NULL);
 
-	auto_save = gedit_prefs_manager_get_auto_save ();
-	
 	if (readonly) 
 	{
-		if (auto_save && (document->priv->auto_save_timeout > 0))
+		if (document->priv->auto_save_timeout > 0)
 		{
 			gedit_debug (DEBUG_DOCUMENT, "Remove autosave timeout");
 
@@ -491,17 +497,14 @@ gedit_document_set_readonly (GeditDocume
 	}
 	else
 	{
-		if (auto_save && (document->priv->auto_save_timeout <= 0))
+		if (document->priv->auto_save && 
+		    (document->priv->auto_save_timeout <= 0) && 
+                    !gedit_document_is_untitled (document))
 		{
-			gint auto_save_interval;
-			
 			gedit_debug (DEBUG_DOCUMENT, "Install autosave timeout");
 
-			auto_save_interval = 
-				gedit_prefs_manager_get_auto_save_interval ();
-				
 			document->priv->auto_save_timeout = g_timeout_add 
-				(auto_save_interval * 1000 * 60,
+				(document->priv->auto_save_interval * 1000 * 60,
 		 		 (GSourceFunc)gedit_document_auto_save,
 		  		 document);		
 		}
@@ -560,6 +563,7 @@ gedit_document_real_loaded (GeditDocumen
 	g_return_if_fail (document->priv->uri != NULL);
 
 	/* FIXME: commented since it does not work as expected - Paolo */
+	
 	/*
 	data = gedit_metadata_manager_get (document->priv->uri,
 					   "position");
@@ -725,10 +729,7 @@ gedit_document_auto_save (GeditDocument 
 
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
 	g_return_val_if_fail (!gedit_document_is_readonly (doc), FALSE);
-
-	/* Remove timeout if now auto_save is FALSE */
-	if (!gedit_prefs_manager_get_auto_save ()) 
-		return FALSE;
+	g_return_val_if_fail (!gedit_document_is_untitled (doc), FALSE);
 
 	if (!gedit_document_get_modified (doc))
 		return TRUE;
@@ -1376,7 +1377,7 @@ gedit_document_load_from_stdin (GeditDoc
 		const GeditEncoding *encoding;
 		gchar *converted_text;
 
-		if (gedit_encoding_get_current () != gedit_encoding_get_utf8 ())
+		if (gedit_encoding_get_current () == gedit_encoding_get_utf8 ())
 		{
 			if (g_utf8_validate (stdin_data, -1, NULL))
 			{
@@ -1519,7 +1520,6 @@ gedit_document_set_uri (GeditDocument* d
 gboolean 
 gedit_document_save (GeditDocument *doc, GError **error)
 {	
-	gboolean auto_save;
 	gboolean create_backup_copy;
 	const GeditEncoding *encoding;
 	
@@ -1535,16 +1535,12 @@ gedit_document_save (GeditDocument *doc,
 	encoding = gedit_document_get_encoding (doc);
 	g_return_val_if_fail (encoding != NULL, FALSE);
 	
-	auto_save = gedit_prefs_manager_get_auto_save ();
 	create_backup_copy = gedit_prefs_manager_get_create_backup_copy ();
 		
-	if (auto_save) 
+	if (doc->priv->auto_save_timeout > 0)
 	{
-		if (doc->priv->auto_save_timeout > 0)
-		{
-			g_source_remove (doc->priv->auto_save_timeout);
-			doc->priv->auto_save_timeout = 0;
-		}
+		g_source_remove (doc->priv->auto_save_timeout);
+		doc->priv->auto_save_timeout = 0;
 	}
 	
 	ret = gedit_document_save_as_real (doc, 
@@ -1559,13 +1555,10 @@ gedit_document_save (GeditDocument *doc,
 		g_get_current_time (&doc->priv->time_of_last_save_or_load);
 	}
 
-	if (auto_save && (doc->priv->auto_save_timeout <= 0)) 
+	if (doc->priv->auto_save && (doc->priv->auto_save_timeout <= 0)) 
 	{
-		gint auto_save_interval = 
-			gedit_prefs_manager_get_auto_save_interval ();
-
 		doc->priv->auto_save_timeout =
-			g_timeout_add (auto_save_interval * 1000 * 60,
+			g_timeout_add (doc->priv->auto_save_interval * 1000 * 60,
 				       (GSourceFunc) gedit_document_auto_save, 
 				       doc);
 	}
@@ -1577,7 +1570,6 @@ gboolean	
 gedit_document_save_as (GeditDocument* doc, const gchar *uri, 
 			const GeditEncoding *encoding, GError **error)
 {	
-	gboolean auto_save;
 	gboolean create_backup;
 
 	gboolean ret = FALSE;
@@ -1591,16 +1583,12 @@ gedit_document_save_as (GeditDocument* d
 	if (encoding == NULL)
 		encoding = gedit_document_get_encoding (doc);
 
-	auto_save = gedit_prefs_manager_get_auto_save ();
 	create_backup = gedit_prefs_manager_get_create_backup_copy ();
 
-	if (auto_save) 
+	if (doc->priv->auto_save_timeout > 0)
 	{
-		if (doc->priv->auto_save_timeout > 0)
-		{
-			g_source_remove (doc->priv->auto_save_timeout);
-			doc->priv->auto_save_timeout = 0;
-		}
+		g_source_remove (doc->priv->auto_save_timeout);
+		doc->priv->auto_save_timeout = 0;
 	}
 
 	if (gedit_document_save_as_real (doc, uri, encoding, create_backup, error))
@@ -1616,13 +1604,10 @@ gedit_document_save_as (GeditDocument* d
 		ret = TRUE;
 	}
 
-	if (auto_save && (doc->priv->auto_save_timeout <= 0)) 
+	if (doc->priv->auto_save && (doc->priv->auto_save_timeout <= 0)) 
 	{
-		gint auto_save_interval =
-			gedit_prefs_manager_get_auto_save_interval ();
-		
 		doc->priv->auto_save_timeout =
-			g_timeout_add (auto_save_interval * 1000 * 60,
+			g_timeout_add (doc->priv->auto_save_interval * 1000 * 60,
 				       (GSourceFunc)gedit_document_auto_save, doc);
 	}
 
@@ -2637,3 +2622,79 @@ gedit_document_get_seconds_since_last_sa
 	return (current_time.tv_sec - doc->priv->time_of_last_save_or_load.tv_sec);
 }
 
+void
+gedit_document_enable_auto_save (GeditDocument *doc, gboolean enable)
+{
+	gedit_debug (DEBUG_DOCUMENT, "");
+
+	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+	enable = (enable != FALSE);
+
+	if (doc->priv->auto_save == enable)
+		return;
+
+	doc->priv->auto_save = enable;
+
+	if (doc->priv->auto_save && 
+	    (doc->priv->auto_save_timeout <= 0) && 
+	    !gedit_document_is_untitled (doc) &&
+	    !gedit_document_is_readonly (doc))
+	{
+		gedit_debug (DEBUG_DOCUMENT, "Install autosave timeout");
+
+		doc->priv->auto_save_timeout = g_timeout_add 
+							(doc->priv->auto_save_interval * 1000 * 60,
+			 		 		 (GSourceFunc)gedit_document_auto_save,	
+					  		 doc);		
+
+		return;
+	}
+	
+	if (!doc->priv->auto_save && (doc->priv->auto_save_timeout > 0))
+	{
+		gedit_debug (DEBUG_DOCUMENT, "Remove autosave timeout");
+
+		g_source_remove (doc->priv->auto_save_timeout);
+		doc->priv->auto_save_timeout = 0;
+
+		return;
+	}
+
+	g_return_if_fail ((!doc->priv->auto_save && (doc->priv->auto_save_timeout <= 0)) || 
+			  gedit_document_is_untitled (doc) || gedit_document_is_readonly (doc));
+}
+
+void
+gedit_document_set_auto_save_interval (GeditDocument *doc, gint interval)
+{
+	gedit_debug (DEBUG_DOCUMENT, "");
+
+	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+	g_return_if_fail (interval > 0);
+
+	if (doc->priv->auto_save_interval == interval)
+		return;
+	
+	doc->priv->auto_save_interval = interval;
+		
+	if (!doc->priv->auto_save)
+		return;
+
+	if (doc->priv->auto_save_timeout > 0)
+	{
+		gedit_debug (DEBUG_DOCUMENT, "Remove autosave timeout");
+
+		g_source_remove (doc->priv->auto_save_timeout);
+	
+		gedit_debug (DEBUG_DOCUMENT, "Install new autosave timeout");
+
+		g_return_if_fail (!gedit_document_is_untitled (doc));
+		g_return_if_fail (!gedit_document_is_readonly (doc));
+
+		doc->priv->auto_save_timeout = g_timeout_add 
+						(doc->priv->auto_save_interval * 1000 * 60,
+		 		 		 (GSourceFunc)gedit_document_auto_save,	
+				  		 doc);		
+	}
+}
Index: gedit/gedit-document.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.h,v
retrieving revision 1.40
diff -u -p -r1.40 gedit-document.h
--- gedit/gedit-document.h	6 Dec 2004 18:13:36 -0000	1.40
+++ gedit/gedit-document.h	13 Dec 2004 18:44:32 -0000
@@ -4,7 +4,8 @@
  * This file is part of gedit
  *
  * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
- * Copyright (C) 2000, 2002 Chema Celorio, Paolo Maggi 
+ * Copyright (C) 2000-2002 Chema Celorio, Paolo Maggi 
+ * Copyright (C) 2003-2004 Paolo Maggi 
  *
  * 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
@@ -23,7 +24,7 @@
  */
  
 /*
- * Modified by the gedit Team, 1998-2002. See the AUTHORS file for a 
+ * Modified by the gedit Team, 1998-2004. See the AUTHORS file for a 
  * list of people on the gedit Team.  
  * See the ChangeLog files for a list of changes. 
  */
@@ -86,7 +87,7 @@ struct _GeditDocumentClass
 	/* File name (uri) changed */
 	void (* name_changed)		(GeditDocument    *document);
 
-	/* Connect to the followinf two signals for loading and reverting */
+	/* Connect to the following two signals for loading and reverting */
 	/* Document loaded */
 	void (* loaded)			(GeditDocument    *document,
 					 const GError     *error);
@@ -202,6 +203,13 @@ const GeditEncoding *gedit_document_get_
 
 glong		gedit_document_get_seconds_since_last_save_or_load 
 						(GeditDocument *doc);
+
+void		gedit_document_enable_auto_save	(GeditDocument *doc, 
+						 gboolean       enable);
+void		gedit_document_set_auto_save_interval 
+						(GeditDocument *doc, 
+						 gint           interval);
+
 
 #endif /* __GEDIT_DOCUMENT_H__ */
 
Index: gedit/gedit-mdi.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-mdi.c,v
retrieving revision 1.91
diff -u -p -r1.91 gedit-mdi.c
--- gedit/gedit-mdi.c	2 Dec 2004 10:42:48 -0000	1.91
+++ gedit/gedit-mdi.c	13 Dec 2004 18:44:33 -0000
@@ -1050,7 +1050,7 @@ gedit_mdi_add_child_handler (BonoboMDI *
 	g_signal_connect (G_OBJECT (child), "find_state_changed",
 			  G_CALLBACK (gedit_mdi_child_find_state_changed_handler), 
 			  NULL);
-
+		    
 	return TRUE;
 }
 
@@ -1096,7 +1096,7 @@ gedit_mdi_add_view_handler (BonoboMDI *m
 static gint 
 gedit_mdi_remove_child_handler (BonoboMDI *mdi, BonoboMDIChild *child)
 {
-	GeditDocument* doc;
+	GeditDocument *doc;
 	gboolean close = TRUE;
 	
 	gedit_debug (DEBUG_MDI, "");
Index: gedit/gedit-prefs-manager-app.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-prefs-manager-app.c,v
retrieving revision 1.5
diff -u -p -r1.5 gedit-prefs-manager-app.c
--- gedit/gedit-prefs-manager-app.c	13 Nov 2004 11:06:18 -0000	1.5
+++ gedit/gedit-prefs-manager-app.c	13 Dec 2004 18:44:33 -0000
@@ -86,7 +86,10 @@ static void 		gedit_prefs_manager_max_re
 								 guint cnxn_id, 
 								 GConfEntry *entry, 
 								 gpointer user_data);
-
+static void		gedit_prefs_manager_auto_save_changed (GConfClient *client,
+							       guint cnxn_id,
+							       GConfEntry *entry,
+							       gpointer user_data);
 static gint window_state = -1;
 static gint window_height = -1;
 static gint window_width = -1;
@@ -158,6 +161,11 @@ gedit_prefs_manager_app_init (void)
 				GPM_MAX_RECENTS,
 				gedit_prefs_manager_max_recents_changed,
 				NULL, NULL, NULL);
+
+		gconf_client_notify_add (gedit_prefs_manager->gconf_client,
+				GPM_SAVE_DIR,
+				gedit_prefs_manager_auto_save_changed,
+				NULL, NULL, NULL);
 	}
 
 	return gedit_prefs_manager != NULL;	
@@ -717,6 +725,7 @@ gedit_prefs_manager_undo_changed (GConfC
 	{
 		gint ul;
 		GList *docs;
+		GList *l;
 		
 		if (entry->value->type == GCONF_VALUE_INT)
 			ul = gconf_value_get_int (entry->value);
@@ -726,15 +735,17 @@ gedit_prefs_manager_undo_changed (GConfC
 		ul = CLAMP (ul, -1, 250);
 
 		docs = gedit_get_open_documents ();
-
-		while (docs != NULL)
+		l = docs;
+		while (l != NULL)
 		{
-			GeditDocument *d = GEDIT_DOCUMENT (docs->data);
+			GeditDocument *d = GEDIT_DOCUMENT (l->data);
 
 			gedit_document_set_max_undo_levels (d, ul);
 		
-			docs = g_list_next (docs);
+			l = g_list_next (l);
 		}
+
+		g_list_free (docs);
 	}
 }
 
@@ -903,3 +914,67 @@ gedit_prefs_manager_max_recents_changed 
 	}
 }
 
+static void
+gedit_prefs_manager_auto_save_changed (GConfClient *client,
+	guint cnxn_id, GConfEntry *entry, gpointer user_data)
+{
+	GList *docs;
+	GList *l;
+
+	gedit_debug (DEBUG_PREFS, "");
+
+	g_return_if_fail (entry->key != NULL);
+	g_return_if_fail (entry->value != NULL);
+
+	if (strcmp (entry->key, GPM_AUTO_SAVE) == 0)
+	{
+		gboolean auto_save;
+
+		if (entry->value->type == GCONF_VALUE_BOOL)
+			auto_save = gconf_value_get_bool (entry->value);
+		else
+			auto_save = GPM_DEFAULT_AUTO_SAVE;
+
+		docs = gedit_get_open_documents ();
+		l = docs;
+
+		while (l != NULL)
+		{
+			GeditDocument *doc = GEDIT_DOCUMENT (l->data);
+
+			gedit_document_enable_auto_save (doc, auto_save);
+
+			l = g_list_next (l);
+		}
+
+		g_list_free (docs);
+	}
+	else if (strcmp (entry->key,  GPM_AUTO_SAVE_INTERVAL) == 0)
+	{
+		gint auto_save_interval;
+
+		if (entry->value->type == GCONF_VALUE_INT)
+		{
+			auto_save_interval = gconf_value_get_int (entry->value);
+
+			if (auto_save_interval <= 0)
+				auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
+		}
+		else
+			auto_save_interval = GPM_DEFAULT_AUTO_SAVE_INTERVAL;
+
+		docs = gedit_get_open_documents ();
+		l = docs;
+		
+		while (l != NULL)
+		{
+			GeditDocument *doc = GEDIT_DOCUMENT (l->data);
+
+			gedit_document_set_auto_save_interval (doc, auto_save_interval);
+
+			l = g_list_next (l);
+		}
+
+		g_list_free (docs);
+	}
+}
