? patch-modified.diff
? patch-modified1.diff
? help/ru/.xml2po.mo
? help/ru/gedit.xml
? help/ru/legal.xml
? help/sv/.xml2po.mo
? help/sv/gedit.xml
? help/sv/legal.xml
Index: gedit/gedit-document.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.c,v
retrieving revision 1.135
diff -u -r1.135 gedit-document.c
--- gedit/gedit-document.c	24 Aug 2006 13:17:13 -0000	1.135
+++ gedit/gedit-document.c	6 Nov 2006 20:04:43 -0000
@@ -109,6 +109,11 @@
 
 	GTimeVal     time_of_last_save_or_load;
 
+	/* did we already notify the user that the file on disk
+	 * is different than what is in gedit? if we notified
+	 * the user, we won't notify again since user already knows. */
+	gboolean     user_notified_that_file_changed_on_disk;
+
 	guint        search_flags;
 	gchar       *search_text;
 	gint	     num_of_lines_search_text;
@@ -589,6 +594,8 @@
 
 	doc->priv->mtime = 0;
 
+	doc->priv->user_notified_that_file_changed_on_disk = FALSE;
+
 	g_get_current_time (&doc->priv->time_of_last_save_or_load);
 
 	doc->priv->encoding = gedit_encoding_get_utf8 ();
@@ -888,6 +895,47 @@
 	return doc->priv->readonly;
 }
 
+gboolean
+gedit_document_is_local_file (GeditDocument *doc)
+{
+	return gnome_vfs_uri_is_local (doc->priv->vfs_uri);
+}
+
+gboolean gedit_document_get_user_notified_that_file_changed_on_disk
+	(GeditDocument *doc)
+{
+	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE);
+
+	return doc->priv->user_notified_that_file_changed_on_disk;
+}
+void gedit_document_set_user_notified_that_file_changed_on_disk
+	(GeditDocument *doc, gboolean value)
+{
+	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+	doc->priv->user_notified_that_file_changed_on_disk = value;
+}
+
+gboolean gedit_document_changed_on_disk (GeditDocument *doc)
+{
+	GnomeVFSFileInfo *info;
+	GnomeVFSResult result;
+	gint file_mtime;
+	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
+
+	info = gnome_vfs_file_info_new ();
+	result = gnome_vfs_get_file_info_uri (doc->priv->vfs_uri, info,
+			GNOME_VFS_FILE_INFO_DEFAULT);
+	if (result != GNOME_VFS_OK)
+	{
+		gnome_vfs_file_info_unref (info);
+		return FALSE;
+	}
+	file_mtime = info->mtime;
+	gnome_vfs_file_info_unref (info);
+	return (file_mtime > doc->priv->mtime);
+}
+
 static void
 reset_temp_loading_data (GeditDocument       *doc)
 {
@@ -914,6 +962,8 @@
 
 		doc->priv->mtime = gedit_document_loader_get_mtime (loader);
 
+		doc->priv->user_notified_that_file_changed_on_disk = FALSE;
+
 		g_get_current_time (&doc->priv->time_of_last_save_or_load);
 
 		set_readonly (doc,
@@ -1073,6 +1123,8 @@
 
 			doc->priv->mtime = gedit_document_saver_get_mtime (saver);
 
+			doc->priv->user_notified_that_file_changed_on_disk = FALSE;
+
 			g_get_current_time (&doc->priv->time_of_last_save_or_load);
 
 			gedit_document_set_readonly (doc, FALSE);
@@ -1202,7 +1254,6 @@
 
 	return (doc->priv->uri == NULL);
 }
-
 
 gboolean
 gedit_document_get_deleted (GeditDocument *doc)
Index: gedit/gedit-document.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-document.h,v
retrieving revision 1.47
diff -u -r1.47 gedit-document.h
--- gedit/gedit-document.h	7 Aug 2006 18:04:07 -0000	1.47
+++ gedit/gedit-document.h	6 Nov 2006 20:04:43 -0000
@@ -154,6 +154,14 @@
 
 gboolean	 gedit_document_get_readonly 	(GeditDocument       *doc);
 
+gboolean	 gedit_document_is_local_file	(GeditDocument       *doc);
+
+gboolean	 gedit_document_get_user_notified_that_file_changed_on_disk
+						(GeditDocument       *doc);
+void	 gedit_document_set_user_notified_that_file_changed_on_disk
+						(GeditDocument       *doc,
+						 gboolean value);
+
 void		 gedit_document_load 		(GeditDocument       *doc,
 						 const gchar         *uri,
 						 const GeditEncoding *encoding,
@@ -183,6 +191,12 @@
 gboolean	 gedit_document_get_externally_modified
 						(GeditDocument       *doc);
 */
+
+/* Has the file changed on disk compared to our version?
+ * NOTE: will also check for remote files!
+ */
+gboolean	 gedit_document_changed_on_disk
+						(GeditDocument       *doc);
 
 gboolean	 gedit_document_goto_line 	(GeditDocument       *doc, 
 						 gint                 line);
Index: gedit/gedit-tab.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-tab.c,v
retrieving revision 1.17
diff -u -r1.17 gedit-tab.c
--- gedit/gedit-tab.c	25 Aug 2006 13:59:41 -0000	1.17
+++ gedit/gedit-tab.c	6 Nov 2006 20:04:48 -0000
@@ -450,6 +450,144 @@
 				   (gpointer *)&tab->priv->message_area);
 }
 
+static void 
+file_modified_on_disk_message_area_response (GeditMessageArea *message_area,
+						gint              response_id,
+						GeditTab         *tab)
+{
+	GeditView *view;
+	GeditDocument *doc;
+
+	doc = gedit_tab_get_document (tab);
+	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+	set_message_area (tab, NULL);
+	view = gedit_tab_get_view (tab);
+	gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+
+	if (response_id == GTK_RESPONSE_OK)
+	{
+		_gedit_tab_revert (tab);
+	}
+	else
+	{
+		gedit_document_set_user_notified_that_file_changed_on_disk (doc, TRUE);
+	}
+
+	gtk_widget_grab_focus (GTK_WIDGET (view));
+}
+
+void
+gedit_tab_focused_in (GeditTab    *tab)
+{
+	GeditDocument *doc;
+	gchar *uri;
+
+	if ( (tab->priv->state == GEDIT_TAB_STATE_FILE_CHANGED)
+	 	|| (tab->priv->state == GEDIT_TAB_STATE_LOADING)
+		|| (tab->priv->state == GEDIT_TAB_STATE_REVERTING) )
+	{
+		return;
+	}
+	
+	doc = gedit_tab_get_document (tab);
+	g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
+
+	uri = gedit_document_get_uri (doc);
+	if (uri == NULL)
+	{	// file has no disk saving: nothing to do
+		return;
+	}
+	g_free (uri);
+
+	if (!gedit_document_is_local_file (doc))
+	{	// file is not local: bailing out
+		// (checking remote files is too slow)
+		return;
+	}
+
+	if ( (!gedit_document_changed_on_disk (doc))
+		|| (gedit_document_get_user_notified_that_file_changed_on_disk (doc)) )
+	{	// document didn't change: nothing to do
+		return;
+	}
+
+	gedit_tab_set_state (tab,
+		 GEDIT_TAB_STATE_FILE_CHANGED);
+
+	const gchar *primary_text = "The file changed on disk";
+	const gchar *secondary_text = "Which version do you want to edit?";
+
+	GtkWidget *message_area;
+	GtkWidget *hbox_content;
+	GtkWidget *image;
+	GtkWidget *vbox;
+	gchar *primary_markup;
+	gchar *secondary_markup;
+	GtkWidget *primary_label;
+	GtkWidget *secondary_label;
+	
+	message_area = gedit_message_area_new ();
+
+	gedit_message_area_add_stock_button_with_text (GEDIT_MESSAGE_AREA (message_area),
+						       _("_Refresh from disk"),
+						       GTK_STOCK_REFRESH,
+						       GTK_RESPONSE_OK);
+	gedit_message_area_add_button (GEDIT_MESSAGE_AREA (message_area),
+				       _("_Keep changes"),
+				       GTK_RESPONSE_CANCEL);
+				      
+	hbox_content = gtk_hbox_new (FALSE, 8);
+	gtk_widget_show (hbox_content);				
+	
+	image = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG);
+	gtk_widget_show (image);
+	gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
+	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
+  
+	vbox = gtk_vbox_new (FALSE, 6);
+	gtk_widget_show (vbox);
+	gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
+	
+	primary_markup = g_strdup_printf ("<b>%s</b>", primary_text);
+	primary_label = gtk_label_new (primary_markup);
+	g_free (primary_markup);
+	gtk_widget_show (primary_label);
+	gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
+	gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
+	gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
+	gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
+	GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
+	gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
+  
+  	if (secondary_text != NULL)
+  	{
+  		secondary_markup = g_strdup_printf ("<small>%s</small>",
+  						    secondary_text);
+		secondary_label = gtk_label_new (secondary_markup);
+		g_free (secondary_markup);
+		gtk_widget_show (secondary_label);
+		gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
+		GTK_WIDGET_SET_FLAGS (secondary_label, GTK_CAN_FOCUS);
+		gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
+		gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
+		gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
+		gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);
+	}
+
+	gedit_message_area_set_contents (GEDIT_MESSAGE_AREA (message_area),
+					 hbox_content);
+
+	tab->priv->message_area = NULL;
+	set_message_area (tab, message_area);
+	gtk_widget_show (message_area);
+
+	g_signal_connect (message_area,
+			  "response",
+			  G_CALLBACK (file_modified_on_disk_message_area_response),
+			  tab);
+}
+
 static void
 remove_tab (GeditTab *tab)
 {
Index: gedit/gedit-tab.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-tab.h,v
retrieving revision 1.4
diff -u -r1.4 gedit-tab.h
--- gedit/gedit-tab.h	19 Feb 2006 18:01:09 -0000	1.4
+++ gedit/gedit-tab.h	6 Nov 2006 20:04:48 -0000
@@ -54,6 +54,7 @@
 	GEDIT_TAB_STATE_SAVING_ERROR,
 	GEDIT_TAB_STATE_GENERIC_ERROR,
 	GEDIT_TAB_STATE_CLOSING,
+	GEDIT_TAB_STATE_FILE_CHANGED,
 	GEDIT_TAB_NUM_OF_STATES /* This is not a valid state */
 } GeditTabState;
 
@@ -121,6 +122,8 @@
 void		 gedit_tab_set_auto_save_interval 
 						(GeditTab            *tab, 
 						 gint                interval);
+
+void		 gedit_tab_focused_in		(GeditTab            *tab);
 
 /*
  * Non exported methods
Index: gedit/gedit-view.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-view.c,v
retrieving revision 1.72
diff -u -r1.72 gedit-view.c
--- gedit/gedit-view.c	9 Aug 2006 15:17:37 -0000	1.72
+++ gedit/gedit-view.c	6 Nov 2006 20:04:51 -0000
@@ -116,6 +116,8 @@
 
 static gint	gedit_view_expose	 	(GtkWidget       *widget,
 						 GdkEventExpose  *event);
+static gint	gedit_view_focus_in	 	(GtkWidget       *widget,
+						 GdkEventFocus *event);
 static void 	search_highlight_updated_cb	(GeditDocument   *doc,
 						 GtkTextIter     *start,
 						 GtkTextIter     *end,
@@ -165,6 +167,7 @@
 
 	widget_class->focus_out_event = gedit_view_focus_out;
 	widget_class->expose_event = gedit_view_expose;
+	widget_class->focus_in_event = gedit_view_focus_in;
 
 	klass->start_interactive_search = start_interactive_search;
 	klass->start_interactive_goto_line = start_interactive_goto_line;
@@ -1836,6 +1839,23 @@
 	}
 
 	return (* GTK_WIDGET_CLASS (gedit_view_parent_class)->expose_event)(widget, event);
+}
+
+static gint
+gedit_view_focus_in (GtkWidget      *widget,
+		 GdkEventFocus *event)
+{
+	GtkTextView *text_view;
+	GeditDocument *doc;
+	GeditTab *tab;
+	
+	text_view = GTK_TEXT_VIEW (widget);
+	
+	doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (text_view));
+	tab = gedit_tab_get_from_document (doc);
+	gedit_tab_focused_in (tab);
+
+	return (* GTK_WIDGET_CLASS (gedit_view_parent_class)->focus_in_event)(widget, event);
 }
 
 static void 	
