Index: gedit/gedit-commands-file.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands-file.c,v
retrieving revision 1.15
diff -u -p -u -p -r1.15 gedit-commands-file.c
--- gedit/gedit-commands-file.c	7 Dec 2006 23:33:28 -0000	1.15
+++ gedit/gedit-commands-file.c	9 Dec 2006 18:29:40 -0000
@@ -958,7 +958,8 @@ _gedit_cmd_file_save_as (GtkAction   *ac
  */
 void
 _gedit_cmd_file_save_documents_list (GeditWindow *window,
-				     GList       *docs)
+				     GList       *docs,
+				     gboolean     save_unmodified)
 {
 	GList *l;
 	GSList *tabs_to_save_as = NULL;
@@ -1005,7 +1006,19 @@ _gedit_cmd_file_save_documents_list (Ged
 			}
 			else
 			{
-				file_save (t, window);			
+				/* Skip unmodified docs unless we are
+				 * told otherwise or unless the file
+				 * was changed externally.
+				 * Note: we always save remote files
+				 * just to be sure, since there checking
+				 * external modifications is too slow.
+				 */
+				if (save_unmodified ||
+				    gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)) ||
+				    _gedit_document_check_externally_modified (doc, TRUE))
+				{
+					file_save (t, window);
+				}
 			}
 		}
 		else
@@ -1074,7 +1087,7 @@ _gedit_cmd_file_save_all (GtkAction   *a
 
 	docs = gedit_window_get_documents (window);
 
-	_gedit_cmd_file_save_documents_list (window, docs);
+	_gedit_cmd_file_save_documents_list (window, docs, FALSE);
 
 	g_list_free (docs);
 }
Index: gedit/gedit-commands.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands.h,v
retrieving revision 1.20
diff -u -p -u -p -r1.20 gedit-commands.h
--- gedit/gedit-commands.h	2 Dec 2006 15:03:22 -0000	1.20
+++ gedit/gedit-commands.h	9 Dec 2006 18:29:40 -0000
@@ -149,7 +149,8 @@ void		_gedit_cmd_file_close_tab 		(Gedit
 							 GeditWindow *window);
 
 void		_gedit_cmd_file_save_documents_list	(GeditWindow *window,
-							 GList       *docs);
+							 GList       *docs,
+							 gboolean     save_unmodified);
 
 G_END_DECLS
 
Index: gedit/gedit-document.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.c,v
retrieving revision 1.136
diff -u -p -u -p -r1.136 gedit-document.c
--- gedit/gedit-document.c	8 Nov 2006 15:15:54 -0000	1.136
+++ gedit/gedit-document.c	9 Dec 2006 18:29:41 -0000
@@ -1951,3 +1951,51 @@ gedit_document_get_enable_search_highlig
 	
 	return (doc->priv->to_search_region != NULL);
 }
+
+/*
+ * This function check if the document has been modified on disk
+ * by another program.
+ * NOTE: the check is done *only* for local files, for remote
+ * files @res_for_remotes is returned.
+ */
+gboolean
+_gedit_document_check_externally_modified (GeditDocument *doc,
+					   gboolean       res_for_remotes)
+{
+	GnomeVFSFileInfo *info;
+	GnomeVFSResult result;
+	gint file_mtime;
+
+	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+
+	if (doc->priv->uri == NULL)
+	{
+		return FALSE;
+	}
+
+	if (!gedit_utils_uri_has_file_scheme (doc->priv->uri))
+	{
+		/* Not a local file. Skip the check */
+		return res_for_remotes;
+	}
+
+	info = gnome_vfs_file_info_new ();
+
+	result = gnome_vfs_get_file_info_uri (doc->priv->vfs_uri,
+					      info,
+					      GNOME_VFS_FILE_INFO_DEFAULT |
+					      GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
+
+	if (result != GNOME_VFS_OK)
+	{
+		gnome_vfs_file_info_unref (info);
+		return res_for_remotes;
+	}
+
+	file_mtime = info->mtime;
+
+	gnome_vfs_file_info_unref (info);
+
+	return (file_mtime > doc->priv->mtime);
+}
+
Index: gedit/gedit-document.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.h,v
retrieving revision 1.47
diff -u -p -u -p -r1.47 gedit-document.h
--- gedit/gedit-document.h	7 Aug 2006 18:04:07 -0000	1.47
+++ gedit/gedit-document.h	9 Dec 2006 18:29:41 -0000
@@ -241,6 +241,10 @@ glong		 _gedit_document_get_seconds_sinc
 void		_gedit_document_search_region   (GeditDocument       *doc,
 						 const GtkTextIter   *start,
 						 const GtkTextIter   *end);
+
+gboolean	_gedit_document_check_externally_modified
+						(GeditDocument       *doc,
+						 gboolean             res_for_remotes);
 						  
 /* Search macros */
 #define GEDIT_SEARCH_IS_DONT_SET_FLAGS(sflags) ((sflags & GEDIT_SEARCH_DONT_SET_FLAGS) != 0)
Index: gedit/gedit-session.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-session.c,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 gedit-session.c
--- gedit/gedit-session.c	22 May 2006 15:53:10 -0000	1.13
+++ gedit/gedit-session.c	9 Dec 2006 18:29:42 -0000
@@ -393,7 +393,7 @@ close_confirmation_dialog_response_handl
 					   GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE,
 					   selected_documents);
 
-			_gedit_cmd_file_save_documents_list (window, selected_documents);
+			_gedit_cmd_file_save_documents_list (window, selected_documents, TRUE);
 
 			/* FIXME: also need to lock the window to prevent further changes... */
 
