gedit r6262 - in trunk: . gedit plugins/filebrowser



Author: jessevdk
Date: Mon May  5 10:24:07 2008
New Revision: 6262
URL: http://svn.gnome.org/viewvc/gedit?rev=6262&view=rev

Log:
	* gedit/gedit-document.[ch]: added gedit_document_set_uri function which
	updates the documents uri
	
	* plugins/filebrowser/gedit-file-browser-marshal.list:
	* plugins/filebrowser/gedit-file-browser-store.[ch]:
	* plugins/filebrowser/gedit-file-browser-plugin.c:
	
	added support for resetting uris for open documents in gedit when
	a file is renamed from the file browser plugin


Modified:
   trunk/ChangeLog
   trunk/gedit/gedit-document.c
   trunk/gedit/gedit-document.h
   trunk/plugins/filebrowser/gedit-file-browser-marshal.list
   trunk/plugins/filebrowser/gedit-file-browser-plugin.c
   trunk/plugins/filebrowser/gedit-file-browser-store.c
   trunk/plugins/filebrowser/gedit-file-browser-store.h

Modified: trunk/gedit/gedit-document.c
==============================================================================
--- trunk/gedit/gedit-document.c	(original)
+++ trunk/gedit/gedit-document.c	Mon May  5 10:24:07 2008
@@ -852,6 +852,16 @@
 	return g_strdup (doc->priv->uri);
 }
 
+void
+gedit_document_set_uri (GeditDocument *doc,
+			const gchar   *uri)
+{
+	gchar * mime_type = g_strdup (doc->priv->mime_type);
+	set_uri (doc, uri, mime_type);
+	
+	g_free (mime_type);
+}
+
 /* Never returns NULL */
 gchar *
 gedit_document_get_uri_for_display (GeditDocument *doc)

Modified: trunk/gedit/gedit-document.h
==============================================================================
--- trunk/gedit/gedit-document.h	(original)
+++ trunk/gedit/gedit-document.h	Mon May  5 10:24:07 2008
@@ -154,6 +154,8 @@
 GeditDocument   *gedit_document_new 		(void);
 
 gchar		*gedit_document_get_uri 	(GeditDocument       *doc);
+void		 gedit_document_set_uri		(GeditDocument       *doc,
+						 const gchar 	     *uri);
 
 gchar		*gedit_document_get_uri_for_display
 						(GeditDocument       *doc);

Modified: trunk/plugins/filebrowser/gedit-file-browser-marshal.list
==============================================================================
--- trunk/plugins/filebrowser/gedit-file-browser-marshal.list	(original)
+++ trunk/plugins/filebrowser/gedit-file-browser-marshal.list	Mon May  5 10:24:07 2008
@@ -1,4 +1,5 @@
 VOID:UINT,STRING
+VOID:STRING,STRING
 BOOL:OBJECT,POINTER
 BOOL:POINTER
 BOOL:VOID

Modified: trunk/plugins/filebrowser/gedit-file-browser-plugin.c
==============================================================================
--- trunk/plugins/filebrowser/gedit-file-browser-plugin.c	(original)
+++ trunk/plugins/filebrowser/gedit-file-browser-plugin.c	Mon May  5 10:24:07 2008
@@ -26,6 +26,7 @@
 
 #include <gedit/gedit-commands.h>
 #include <gedit/gedit-utils.h>
+#include <gedit/gedit-app.h>
 #include <glib/gi18n-lib.h>
 #include <gedit/gedit-debug.h>
 #include <gconf/gconf-client.h>
@@ -83,6 +84,10 @@
 static void on_filter_mode_changed_cb    (GeditFileBrowserStore * model,
                                           GParamSpec * param,
                                           GeditWindow * window);
+static void on_rename_cb		 (GeditFileBrowserStore * model,
+					  const gchar * olduri,
+					  const gchar * newuri,
+					  GeditWindow * window);
 static void on_filter_pattern_changed_cb (GeditFileBrowserWidget * widget,
                                           GParamSpec * param,
                                           GeditWindow * window);
@@ -762,6 +767,11 @@
 	                  G_CALLBACK (on_filter_mode_changed_cb),
 	                  window);
 
+	g_signal_connect (store,
+			  "rename",
+			  G_CALLBACK (on_rename_cb),
+			  window);
+
 	g_signal_connect (window,
 	                  "tab-added",
 	                  G_CALLBACK (on_tab_added_cb),
@@ -961,6 +971,45 @@
 	
 }
 
+static void
+on_rename_cb (GeditFileBrowserStore * store,
+	      const gchar * olduri,
+	      const gchar * newuri,
+	      GeditWindow * window)
+{
+	GeditApp * app;
+	GList * documents;
+	GList * item;
+	GeditDocument * doc;
+	GFile * docfile;
+	GFile * oldfile;
+	gchar * uri;
+	
+	/* Find all documents and set its uri to newuri where it matches olduri */
+	app = gedit_app_get_default ();
+	documents = gedit_app_get_documents (app);
+	
+	oldfile = g_file_new_for_uri (olduri);
+	
+	for (item = documents; item; item = item->next) {
+		doc = GEDIT_DOCUMENT (item->data);
+		uri = gedit_document_get_uri (doc);
+		
+		docfile = g_file_new_for_uri (uri);
+		
+		if (g_file_equal (docfile, oldfile)) {
+			gedit_document_set_uri (doc, newuri);
+
+			gedit_debug_message (DEBUG_PLUGINS, "Renamed %s to %s", olduri, newuri);
+		}
+		
+		g_free (uri);
+		g_object_unref (docfile);
+	}
+	
+	g_list_free (documents);
+}
+
 static void 
 on_filter_pattern_changed_cb (GeditFileBrowserWidget * widget,
                               GParamSpec * param,

Modified: trunk/plugins/filebrowser/gedit-file-browser-store.c
==============================================================================
--- trunk/plugins/filebrowser/gedit-file-browser-store.c	(original)
+++ trunk/plugins/filebrowser/gedit-file-browser-store.c	Mon May  5 10:24:07 2008
@@ -206,6 +206,7 @@
 	END_LOADING,
 	ERROR,
 	NO_TRASH,
+	RENAME,
 	NUM_SIGNALS
 };
 
@@ -355,6 +356,16 @@
 					   no_trash), g_signal_accumulator_true_handled, NULL,
 			  gedit_file_browser_marshal_BOOL__POINTER,
 			  G_TYPE_BOOLEAN, 1, G_TYPE_POINTER);
+	model_signals[RENAME] =
+	    g_signal_new ("rename",
+			  G_OBJECT_CLASS_TYPE (object_class),
+			  G_SIGNAL_RUN_LAST,
+			  G_STRUCT_OFFSET (GeditFileBrowserStoreClass,
+					   rename), NULL, NULL,
+			  gedit_file_browser_marshal_VOID__STRING_STRING, 
+			  G_TYPE_NONE, 2,
+			  G_TYPE_STRING,
+			  G_TYPE_STRING);
 
 	g_type_class_add_private (object_class,
 				  sizeof (GeditFileBrowserStorePrivate));
@@ -2829,7 +2840,10 @@
 	FileBrowserNode *node;
 	GFile * file;
 	GFile * parent;
+	GFile * previous;
 	GError * err = NULL;
+	gchar * olduri;
+	gchar * newuri;
 	GtkTreePath *path;
 
 	g_return_val_if_fail (GEDIT_IS_FILE_BROWSER_STORE (model), FALSE);
@@ -2852,16 +2866,13 @@
 	if (g_file_move (node->file, file, G_FILE_COPY_NONE, NULL, NULL, NULL, &err)) {
 		/* TODO: make sure to also re'path all the child nodes that
 		   might be there! */
-		parent = node->file;
+		previous = node->file;
 		node->file = file;
 
 		/* This makes sure the actual info for the node is requeried */
 		file_browser_node_set_name (node);
 		file_browser_node_set_from_info (model, node, NULL, TRUE);
 
-		/* Free the old nodes' GFile */
-		g_object_unref (parent);
-		
 		if (model_node_visibility (model, node)) {
 			path = gedit_file_browser_store_get_path_real (model, node);
 			gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter);
@@ -2870,6 +2881,8 @@
 			/* Reorder this item */
 			model_resort_node (model, node);
 		} else {
+			g_object_unref (previous);
+			
 			if (error != NULL)
 				*error = g_error_new_literal (gedit_file_browser_store_error_quark (),
 							      GEDIT_FILE_BROWSER_ERROR_RENAME,
@@ -2877,6 +2890,15 @@
 			return FALSE;
 		}
 
+		olduri = g_file_get_uri (previous);
+		newuri = g_file_get_uri (node->file);
+
+		g_signal_emit (model, model_signals[RENAME], 0, olduri, newuri);
+
+		g_object_unref (previous);
+		g_free (olduri);
+		g_free (newuri);
+
 		return TRUE;
 	} else {
 		g_object_unref (file);

Modified: trunk/plugins/filebrowser/gedit-file-browser-store.h
==============================================================================
--- trunk/plugins/filebrowser/gedit-file-browser-store.h	(original)
+++ trunk/plugins/filebrowser/gedit-file-browser-store.h	Mon May  5 10:24:07 2008
@@ -105,6 +105,9 @@
 		                      gchar * message);
 	gboolean (*no_trash)	     (GeditFileBrowserStore * model,
 				      GList * files);
+	void (*rename)		     (GeditFileBrowserStore * model,
+				      const gchar * olduri,
+				      const gchar * newuri);
 };
 
 GType gedit_file_browser_store_get_type               (void) G_GNUC_CONST;



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