anjuta r4636 - in trunk: . plugins/document-manager plugins/scintilla src



Author: sgranjoux
Date: Sun Jan 25 14:40:34 2009
New Revision: 4636
URL: http://svn.gnome.org/viewvc/anjuta?rev=4636&view=rev

Log:
	* plugins/scintilla/text_editor.h,
	plugins/scintilla/text_editor.c:
	Fix #491491 â Auto save's problem (reload automatically)
	Fix #549958 â user is not notified if a file is removed from
	filesystem

	* plugins/document-manager/anjuta-docman.c:
	Display a warning icon when a message area is displayed

	* src/anjuta.c:
	Open file pass on command line


Modified:
   trunk/ChangeLog
   trunk/plugins/document-manager/anjuta-docman.c
   trunk/plugins/scintilla/text_editor.c
   trunk/plugins/scintilla/text_editor.h
   trunk/src/anjuta.c

Modified: trunk/plugins/document-manager/anjuta-docman.c
==============================================================================
--- trunk/plugins/document-manager/anjuta-docman.c	(original)
+++ trunk/plugins/document-manager/anjuta-docman.c	Sun Jan 25 14:40:34 2009
@@ -1200,6 +1200,29 @@
 	}
 }
 
+static void
+on_destroy_message_area (gpointer data, GObject *finalized_object)
+{
+	AnjutaDocmanPage *page = (AnjutaDocmanPage *)data;
+	GFile *file;
+       
+	file = ianjuta_file_get_file (IANJUTA_FILE (page->doc), NULL);
+	if (file)
+	{
+		GdkPixbuf* pixbuf = anjuta_docman_get_pixbuf_for_file (file);
+
+		if (pixbuf)
+		{
+			gtk_image_set_from_pixbuf (GTK_IMAGE(page->menu_icon), pixbuf);
+			gtk_image_set_from_pixbuf (GTK_IMAGE(page->mime_icon), pixbuf);
+			g_object_unref (pixbuf);
+		}
+
+		g_object_unref (file);
+	}
+	page->message_area = NULL;
+}
+
 void
 anjuta_docman_set_message_area (AnjutaDocman *docman, IAnjutaDocument* doc, 
                                 GtkWidget *message_area)
@@ -1226,8 +1249,10 @@
 			                    FALSE,
 			                    0);
 			
-			g_object_add_weak_pointer (G_OBJECT (page->message_area), 
-				   					   (gpointer *)&page->message_area);
+			gtk_image_set_from_stock (GTK_IMAGE (page->menu_icon), GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
+			gtk_image_set_from_stock (GTK_IMAGE (page->mime_icon), GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_MENU);
+			g_object_weak_ref (G_OBJECT (page->message_area),
+				       on_destroy_message_area, page);
 		}
 	}
 }

Modified: trunk/plugins/scintilla/text_editor.c
==============================================================================
--- trunk/plugins/scintilla/text_editor.c	(original)
+++ trunk/plugins/scintilla/text_editor.c	Sun Jan 25 14:40:34 2009
@@ -132,6 +132,8 @@
 	te->encoding = NULL;
 	te->gconf_notify_ids = NULL;
 	te->hover_tip_on = FALSE;
+	te->force_not_saved = FALSE;
+	te->message_area = NULL;
 }
 
 static void
@@ -312,9 +314,31 @@
 	{
 		text_editor_load_file (te);
 	}
-	gtk_widget_destroy (message_area);
-	te->file_modified_widget = NULL;
-	/* DEBUG_PRINT ("%s", "File modified dialog responded"); */
+	else
+	{
+		gtk_widget_destroy (message_area);
+		te->message_area = NULL;
+	}
+}
+
+static void
+on_close_dialog_response (GtkWidget *message_area, gint res, TextEditor *te)
+{
+	if (res == GTK_RESPONSE_YES)
+	{
+		IAnjutaDocumentManager *docman;
+		
+		docman = anjuta_shell_get_interface (te->shell, IAnjutaDocumentManager, NULL);
+		if (docman == NULL) return;
+
+		ianjuta_document_manager_remove_document (docman, IANJUTA_DOCUMENT (te), FALSE, NULL);
+	}
+	else
+	{
+		text_editor_set_saved (te, FALSE);
+		gtk_widget_destroy (message_area);
+		te->message_area = NULL;
+	}
 }
 
 static void
@@ -327,50 +351,91 @@
 	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;
-
-	if (!anjuta_util_diff (te->uri, te->last_saved_content))
+	switch (event_type)
 	{
-		/* 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;
+		case G_FILE_MONITOR_EVENT_CREATED:
+		case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
+			if (text_editor_is_saved (te))
+			{
+				/* If a saved file is changed reload it automatically */
+				text_editor_load_file (te);
+			
+				return;
+			}
+			else
+			{
+				buff = g_strdup_printf (_("The file '%s' has been changed.\n"
+								  "Do you want to loose your changes and reload it ?"),
+								 te->filename);
+				message_area = anjuta_message_area_new (buff, GTK_STOCK_DIALOG_WARNING);
+				g_free (buff);
+				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_signal_connect (G_OBJECT(message_area), "response",
+								  G_CALLBACK (on_reload_dialog_response),
+								  te);
+			}
+			break;
+		case G_FILE_MONITOR_EVENT_DELETED:
+			if (text_editor_is_saved (te))
+			{
+				buff = g_strdup_printf (_
+							 ("The file '%s' has been deleted.\n"
+							  "Do you confirm and close it ?"),
+							 te->filename);
+			}
+			else
+			{
+				buff = g_strdup_printf (_
+							 ("The file '%s' has been deleted.\n"
+							  "Do you want to loose your changes and close it ?"),
+							 te->filename);
+			}
+			message_area = anjuta_message_area_new (buff, GTK_STOCK_DIALOG_WARNING);
+			g_free (buff);
+			anjuta_message_area_add_button (ANJUTA_MESSAGE_AREA (message_area),
+											GTK_STOCK_DELETE,
+											GTK_RESPONSE_YES);
+			anjuta_message_area_add_button (ANJUTA_MESSAGE_AREA (message_area),
+											GTK_STOCK_CANCEL,
+											GTK_RESPONSE_NO);
+			g_signal_connect (G_OBJECT(message_area), "response",
+							  G_CALLBACK (on_close_dialog_response),
+							  te);
+			break;
+		case G_FILE_MONITOR_EVENT_CHANGED:
+		case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
+		case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
+		case G_FILE_MONITOR_EVENT_UNMOUNTED:
+			return;
+		default:
+			g_warn_if_reached ();
+			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 (te->message_area != NULL)
+	{
+		gtk_widget_destroy (te->message_area);
+		te->message_area = NULL;
+	}
+
 	docman = anjuta_shell_get_interface (te->shell, IAnjutaDocumentManager, NULL);
 	if (!docman)
+	{
+		gtk_widget_destroy (message_area);
   		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);	
-	te->file_modified_widget = message_area;
-	
-	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);
+	}
 
+	ianjuta_document_manager_set_message_area (docman, IANJUTA_DOCUMENT (te), message_area, NULL);
+	te->message_area = message_area;
 }
 
 static void
@@ -382,6 +447,12 @@
 		g_file_monitor_cancel (te->monitor);
 		te->monitor = NULL;
 	}
+	if (te->message_area) 
+	{
+		/* Remove existing message area */
+		gtk_widget_destroy (te->message_area);
+		te->message_area = NULL;
+	}
 	if (te->uri && !disable_it)
 	{
 		GFile *gio_uri;
@@ -426,10 +497,8 @@
 	if (uri && strlen(uri) > 0)
 	{	
 		new_file_count--;
-		if (te->filename)
-			g_free (te->filename);
-		if (te->uri)
-			g_free (te->uri);
+		g_free (te->filename);
+		g_free (te->uri);
 
 		GFile *gio_uri;
 		gio_uri = g_file_new_for_uri (uri);
@@ -525,7 +594,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);
 }
@@ -1355,8 +1423,7 @@
 	g_free (buffer);
 
 	/* Save the buffer as last saved content */
-	g_free (te->last_saved_content);
-	te->last_saved_content = file_content;
+	g_free (file_content);
 	
 	g_object_unref (gio_uri);
 
@@ -1458,8 +1525,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);
@@ -1501,6 +1567,7 @@
 	text_editor_thaw (te);
 	scintilla_send_message (SCINTILLA (te->scintilla),
 							SCI_SETSAVEPOINT, 0, 0);
+	te->force_not_saved = FALSE;
 	scintilla_send_message (SCINTILLA (te->scintilla),
 							SCI_EMPTYUNDOBUFFER, 0, 0);
 	text_editor_set_hilite_type (te, NULL);
@@ -1550,6 +1617,7 @@
 		text_editor_thaw (te);
 		scintilla_send_message (SCINTILLA (te->scintilla),
 								SCI_SETSAVEPOINT, 0, 0);
+		te->force_not_saved = FALSE;
 		g_signal_emit_by_name (G_OBJECT (te), "saved", file);
 		g_object_unref (file);
 		anjuta_status (te->status, _("File saved successfully"), 5);
@@ -1560,6 +1628,17 @@
 	return ret;
 }
 
+void
+text_editor_set_saved (TextEditor *te, gboolean saved)
+{
+	if (saved)
+	{
+		scintilla_send_message (SCINTILLA (te->scintilla), SCI_SETSAVEPOINT, 0, 0);
+	}
+	te->force_not_saved = !saved;
+	g_signal_emit_by_name(G_OBJECT (te), "save_point", saved);
+}
+
 gboolean
 text_editor_save_yourself (TextEditor * te, FILE * stream)
 {
@@ -1630,7 +1709,7 @@
 text_editor_is_saved (TextEditor * te)
 {
 	return !(scintilla_send_message (SCINTILLA (te->scintilla),
-					 SCI_GETMODIFY, 0, 0));
+					 SCI_GETMODIFY, 0, 0)) && (!te->force_not_saved);
 }
 
 gboolean
@@ -2640,13 +2719,11 @@
 	/* Close current file and open new file in this editor */
 	TextEditor* text_editor;
 	text_editor = TEXT_EDITOR(editor);
-	
-	/* Do nothing if current file is not saved */
-	if (!text_editor_is_saved (text_editor))
-		return;
-	text_editor->uri = g_file_get_uri (file);
-	
+
 	/* Remove path */
+	g_free (text_editor->uri);
+	text_editor->uri = g_file_get_uri (file);
+	g_free (text_editor->filename);
 	text_editor->filename = g_file_get_basename (file);
 	text_editor_load_file (text_editor);
 }
@@ -2670,8 +2747,10 @@
 		ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (text_editor),
 											  NULL);
 	
-	text_editor->uri = g_file_get_uri (file);
 	/* Remove path */
+	g_free (text_editor->uri);
+	text_editor->uri = g_file_get_uri (file);
+	g_free (text_editor->filename);
 	text_editor->filename = g_file_get_basename (file);
 	text_editor_save_file (text_editor, FALSE);
 	text_editor_set_hilite_type (text_editor, NULL);
@@ -2692,13 +2771,14 @@
 isavable_is_dirty (IAnjutaFileSavable* editor, GError** e)
 {
 	TextEditor *text_editor = TEXT_EDITOR(editor);
-	return !text_editor_is_saved(text_editor);
+	return !text_editor_is_saved (text_editor);
 }
 
 static void
 isavable_set_dirty (IAnjutaFileSavable* editor, gboolean dirty, GError** e)
 {
-	/* DEBUG_PRINT("set_dirty: Not implemented in EditorPlugin"); */
+	TextEditor *text_editor = TEXT_EDITOR(editor);
+	text_editor_set_saved (text_editor, !dirty);
 }
 
 static gboolean

Modified: trunk/plugins/scintilla/text_editor.h
==============================================================================
--- trunk/plugins/scintilla/text_editor.h	(original)
+++ trunk/plugins/scintilla/text_editor.h	Sun Jan 25 14:40:34 2009
@@ -100,11 +100,11 @@
 	/* 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;
-	GtkWidget *file_modified_widget;
+	/* message area widget */
+	GtkWidget *message_area;
+	
+	/* Set buffer as modified until next save */
+	gboolean force_not_saved;
 	
 	gboolean hover_tip_on;
 };
@@ -189,6 +189,7 @@
 /* Save or load file */
 gboolean text_editor_load_file (TextEditor * te);
 gboolean text_editor_save_file (TextEditor * te, gboolean update);
+void text_editor_set_saved (TextEditor *te, gboolean saved);
 
 void text_editor_update_controls (TextEditor * te);
 gboolean text_editor_save_yourself (TextEditor * te, FILE * stream);

Modified: trunk/src/anjuta.c
==============================================================================
--- trunk/src/anjuta.c	(original)
+++ trunk/src/anjuta.c	Sun Jan 25 14:40:34 2009
@@ -397,13 +397,19 @@
 			}
 			else
 			{
-				files_load = g_list_prepend (files_load, filename);
+				GFile *file = g_file_new_for_path (filename);
+				gchar *uri;
+
+				uri = g_file_get_uri (file);
+				g_object_unref (file);
+				files_load = g_list_prepend (files_load, uri);
 			}
 		}
 		if (files_load)
 		{
 			anjuta_session_set_string_list (session, "File Loader", "Files",
 											files_load);
+			g_list_foreach (files_load, (GFunc)g_free, NULL);
 			g_list_free (files_load);
 		}
 		anjuta_session_sync (session);



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