anjuta r4506 - in trunk: . plugins/editor



Author: sgranjoux
Date: Wed Dec 31 09:34:19 2008
New Revision: 4506
URL: http://svn.gnome.org/viewvc/anjuta?rev=4506&view=rev

Log:
	* plugins/editor/text_editor.h,
	plugins/editor/text_editor.c,
	plugins/editor/plugin.c:
	Fix #529181 â refresh dialog pops over all windows
	Remove 1s delay on changed file


Modified:
   trunk/ChangeLog
   trunk/plugins/editor/plugin.c
   trunk/plugins/editor/text_editor.c
   trunk/plugins/editor/text_editor.h

Modified: trunk/plugins/editor/plugin.c
==============================================================================
--- trunk/plugins/editor/plugin.c	(original)
+++ trunk/plugins/editor/plugin.c	Wed Dec 31 09:34:19 2008
@@ -105,7 +105,7 @@
 	AnjutaStatus *status = anjuta_shell_get_status (shell, NULL);
 	/* file can be NULL, if we open a buffer, not a file */
 	gchar* uri = file ? g_file_get_uri (file) : NULL;
-	IAnjutaEditor* editor = IANJUTA_EDITOR(text_editor_new(status, prefs,
+	IAnjutaEditor* editor = IANJUTA_EDITOR(text_editor_new(status, prefs, shell,
 														   uri, filename));
 	g_free(uri);
 	return editor;

Modified: trunk/plugins/editor/text_editor.c
==============================================================================
--- trunk/plugins/editor/text_editor.c	(original)
+++ trunk/plugins/editor/text_editor.c	Wed Dec 31 09:34:19 2008
@@ -35,6 +35,9 @@
 #include <libanjuta/anjuta-encodings.h>
 #include <libanjuta/anjuta-convert.h>
 #include <libanjuta/anjuta-debug.h>
+#include <libanjuta/anjuta-message-area.h>
+#include <libanjuta/anjuta-shell.h>
+#include <libanjuta/interfaces/ianjuta-document-manager.h>
 #include <libanjuta/interfaces/ianjuta-editor.h>
 #include <libanjuta/interfaces/ianjuta-editor-selection.h>
 #include <libanjuta/interfaces/ianjuta-editor-convert.h>
@@ -303,61 +306,16 @@
 }
 
 static void
-on_reload_dialog_response (GtkWidget *dlg, gint res, TextEditor *te)
+on_reload_dialog_response (GtkWidget *message_area, gint res, TextEditor *te)
 {
 	if (res == GTK_RESPONSE_YES)
 	{
 		text_editor_load_file (te);
 	}
-	gtk_widget_destroy (dlg);
-	te->file_modified_widget = NULL;
+	gtk_widget_destroy (message_area);
 	/* DEBUG_PRINT ("%s", "File modified dialog responded"); */
 }
 
-static gboolean
-on_text_editor_uri_changed_prompt (TextEditor *te)
-{
-	GtkWidget *dlg;
-	GtkWidget *parent;
-	gchar *buff;
-	
-	buff =
-		g_strdup_printf (_
-						 ("The file '%s' on the disk is more recent than\n"
-						  "the current buffer.\nDo you want to reload it?"),
-						 te->filename);
-	
-	parent = gtk_widget_get_toplevel (GTK_WIDGET (te));
-	
-	dlg = gtk_message_dialog_new (GTK_WINDOW (parent),
-								  GTK_DIALOG_DESTROY_WITH_PARENT,
-								  GTK_MESSAGE_WARNING,
-								  GTK_BUTTONS_NONE, buff);
-	gtk_dialog_add_button (GTK_DIALOG (dlg),
-						   GTK_STOCK_NO,
-						   GTK_RESPONSE_NO);
-	anjuta_util_dialog_add_button (GTK_DIALOG (dlg),
-								   _("_Reload"),
-								   GTK_STOCK_REFRESH,
-								   GTK_RESPONSE_YES);
-	g_free (buff);
-	
-	gtk_window_set_transient_for (GTK_WINDOW (dlg),
-								  GTK_WINDOW (parent));
-	
-	g_signal_connect (dlg, "response",
-					  G_CALLBACK (on_reload_dialog_response),
-					  te);
-	g_signal_connect_swapped (dlg, "delete-event",
-					  G_CALLBACK (gtk_widget_destroy),
-					  dlg);
-	gtk_widget_show (dlg);
-	
-	te->file_modified_widget = dlg;
-
-	return FALSE;
-}
-
 static void
 on_text_editor_uri_changed (GFileMonitor *monitor,
 							GFile *file,
@@ -366,33 +324,42 @@
 							gpointer user_data)
 {
 	TextEditor *te = TEXT_EDITOR (user_data);
+	GtkWidget *message_area;
+	IAnjutaDocumentManager *docman;
+	IAnjutaDocument *doc;
+	gchar *buff;
 	
 	/* DEBUG_PRINT ("%s", "File changed!!!"); */
 	
 	if (!(event_type == G_FILE_MONITOR_EVENT_CHANGED ||
 		  event_type == G_FILE_MONITOR_EVENT_CREATED))
 		return;
+
+	buff =
+		g_strdup_printf (_
+						 ("The file '%s' on the disk is more recent than\n"
+						  "the current buffer.\nDo you want to reload it?"),
+						 te->filename);
 	
-	if (!anjuta_util_diff (te->uri, te->last_saved_content))
-	{
-		/* The file content is same. Remove any previous prompt for reload */
-		if (te->file_modified_widget)
-			gtk_widget_destroy (te->file_modified_widget);
-		te->file_modified_widget = NULL;
-		return;
-	}
-	
-	/* If the file modified dialog is already shown, don't bother showing it
-	 * again.
-	 */
-	if (te->file_modified_widget)
-		return;
+	docman = anjuta_shell_get_interface (te->shell, IAnjutaDocumentManager, NULL);
+	if (!docman)
+  		return;
+  	doc = IANJUTA_DOCUMENT (te);
+
+	message_area = anjuta_message_area_new (buff, GTK_STOCK_DIALOG_WARNING);
+	anjuta_message_area_add_button (ANJUTA_MESSAGE_AREA (message_area),
+									GTK_STOCK_REFRESH,
+									GTK_RESPONSE_YES);
+	anjuta_message_area_add_button (ANJUTA_MESSAGE_AREA (message_area),
+								    GTK_STOCK_CANCEL,
+									GTK_RESPONSE_NO);
+	g_free (buff);	
 	
-	/* Set up 1 sec timer */
-	if (te->file_modified_timer > 0)
- 		g_source_remove (te->file_modified_timer);
-	te->file_modified_timer = g_timeout_add_seconds (1,
-													 (GSourceFunc)on_text_editor_uri_changed_prompt, te);
+	g_signal_connect (G_OBJECT(message_area), "response",
+					  G_CALLBACK (on_reload_dialog_response),
+					  te);					  
+	ianjuta_document_manager_set_message_area (docman, doc, message_area, NULL);
+
 }
 
 static void
@@ -430,13 +397,14 @@
 }
 
 GtkWidget *
-text_editor_new (AnjutaStatus *status, AnjutaPreferences *eo, const gchar *uri, const gchar *name)
+text_editor_new (AnjutaStatus *status, AnjutaPreferences *eo, AnjutaShell *shell, const gchar *uri, const gchar *name)
 {
 	gint zoom_factor;
 	static guint new_file_count;
 	TextEditor *te = TEXT_EDITOR (gtk_widget_new (TYPE_TEXT_EDITOR, NULL));
 	
 	te->status = status; 
+	te->shell = shell;
 	
 	te->preferences = eo;
 	te->props_base = text_editor_get_props();
@@ -491,11 +459,6 @@
 text_editor_dispose (GObject *obj)
 {
 	TextEditor *te = TEXT_EDITOR (obj);
-	if (te->file_modified_timer > 0)
-	{
-		g_source_remove (te->file_modified_timer);
-		te->file_modified_timer = 0;
-	}
 	if (te->monitor)
 	{
 		text_editor_update_monitor (te, TRUE);
@@ -551,7 +514,6 @@
 	g_free (te->filename);
 	g_free (te->uri);
 	g_free (te->force_hilite);
-	g_free (te->last_saved_content);
 	
 	G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
@@ -1266,7 +1228,6 @@
 	GFileInfo *info;
 	gsize nchars;
 	gint dos_filter, editor_mode;
-	gchar *file_content = NULL;
 	gchar *buffer = NULL;
 	guint64 size; 
 
@@ -1322,7 +1283,6 @@
 	if (buffer)
 	{
 		buffer[size] = '\0';
-		file_content = g_strdup (buffer);
 	}
 	
 	if (size != nchars)
@@ -1358,7 +1318,6 @@
 			{
 				/* bail out */
 				g_free (buffer);
-				g_free (file_content);
 				*err = g_strdup (_("The file does not look like a text file or the file encoding is not supported."
 								   " Please check if the encoding of file is in the supported encodings list."
 								   " If not, add it from the preferences."));
@@ -1380,10 +1339,6 @@
 	
 	g_free (buffer);
 	
-	/* Save the buffer as last saved content */
-	g_free (te->last_saved_content);
-	te->last_saved_content = file_content;
-	
 	g_object_unref (gio_uri);
 
 	return TRUE;
@@ -1483,9 +1438,7 @@
 		}
 	}
 	
-	/* Set last content saved to data */
-	g_free (te->last_saved_content);
-	te->last_saved_content = data;
+	g_free (data);
 	
 	if (result)
 		result = g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, error);

Modified: trunk/plugins/editor/text_editor.h
==============================================================================
--- trunk/plugins/editor/text_editor.h	(original)
+++ trunk/plugins/editor/text_editor.h	Wed Dec 31 09:34:19 2008
@@ -25,6 +25,7 @@
 
 #include <gio/gio.h>
 #include <libanjuta/anjuta-preferences.h>
+#include <libanjuta/anjuta-shell.h>
 
 #include "aneditor.h"
 
@@ -63,6 +64,7 @@
 	GFileMonitor *monitor;
 	
 	AnjutaStatus *status;
+	AnjutaShell *shell;
 	
 	/* File extension that will be used to force hilite type */
 	gchar *force_hilite;
@@ -98,19 +100,6 @@
 	/* Current zoom factor */
 	gint zoom_factor;
 	
-	/* Last saved content for comparision on external modifications on
-	 * the file. The content is copied here during file saves.
-	 */
-	gchar *last_saved_content;
-	
-	/* When a file is saved, gio also notifies changes to the file
-	 * resulting in unneccessary processing. To avoid this, file modified
-	 * notifications from gio are dampped for 1 sec. After the 1 sec
-	 * timeout, if the file is still different, the user is notified.
-	 */
-	gint file_modified_timer;
-	GtkWidget *file_modified_widget;
-	
 	gboolean hover_tip_on;
 };
 
@@ -122,7 +111,7 @@
 GType text_editor_get_type (void);
 
 /* New instance of TextEditor */
-GtkWidget* text_editor_new (AnjutaStatus *status, AnjutaPreferences * pr, const gchar *uri,
+GtkWidget* text_editor_new (AnjutaStatus *status, AnjutaPreferences * pr, AnjutaShell* shell, const gchar *uri,
 							const gchar *tab_name);
 
 /* Freeze and thaw editor */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]