[anjuta] file-manager: Use current editor's directory as default directory



commit 241c531761f2fd33efd4fd75c1276cf2f457d4d8
Author: Johannes Schmid <jhs gnome org>
Date:   Fri Jun 12 00:22:37 2009 +0200

    file-manager: Use current editor's directory as default directory
    
    Set the open dialog to use the current editor's filename as directory if available. Don't call chdir().

 plugins/file-loader/plugin.c |   52 ++++++++++++++++++++++++++++++++++++-----
 plugins/file-loader/plugin.h |    5 +++-
 2 files changed, 49 insertions(+), 8 deletions(-)
---
diff --git a/plugins/file-loader/plugin.c b/plugins/file-loader/plugin.c
index 2c38786..91a63d0 100644
--- a/plugins/file-loader/plugin.c
+++ b/plugins/file-loader/plugin.c
@@ -203,6 +203,39 @@ RowSeparatorFunc (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 }
 
 static void
+on_value_added_current_doc (AnjutaPlugin *plugin, const gchar *name,
+                            const GValue *value, gpointer data)
+{
+	AnjutaFileLoaderPlugin *fplugin = ANJUTA_PLUGIN_FILE_LOADER (plugin);
+	IAnjutaDocument* doc = IANJUTA_DOCUMENT(g_value_get_object (value));
+
+	g_free (fplugin->dm_current_uri);
+
+	if (IANJUTA_IS_FILE (doc))
+	{
+		GFile* file = ianjuta_file_get_file(IANJUTA_FILE (doc), NULL);
+		GFile* parent = g_file_get_parent (file);
+		fplugin->dm_current_uri = g_file_get_uri (parent);
+		g_object_unref (parent);
+		g_object_unref (file);
+	}
+	else
+	{
+
+		fplugin->dm_current_uri = NULL;
+	}	
+}
+
+static void
+on_value_removed_current_doc (AnjutaPlugin *plugin, const gchar *name,
+                              gpointer data)
+{
+	AnjutaFileLoaderPlugin *fplugin = ANJUTA_PLUGIN_FILE_LOADER (plugin);
+	g_free (fplugin->dm_current_uri);
+	fplugin->dm_current_uri = NULL;
+}
+
+static void
 open_with_dialog (AnjutaFileLoaderPlugin *plugin, const gchar *uri,
 				  const gchar *mime_type)
 {
@@ -388,16 +421,9 @@ open_with_dialog (AnjutaFileLoaderPlugin *plugin, const gchar *uri,
 static void
 open_file (AnjutaFileLoaderPlugin *plugin, const gchar *uri)
 {
-	gchar *dirname;
-	gchar *path;
 	GFile* file;
 	
 	file = g_file_new_for_uri (uri);
-	path = g_file_get_path (file);
-	dirname = g_path_get_dirname (uri);
-	chdir (dirname);
-	g_free (path);
-	g_free (dirname);
 	
 	ianjuta_file_loader_load (IANJUTA_FILE_LOADER (plugin),
 							  file, FALSE, NULL);
@@ -568,6 +594,11 @@ create_file_open_dialog_gui(GtkWindow* parent, AnjutaFileLoaderPlugin* plugin)
 									GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 									NULL);
 	gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER(dialog), TRUE);
+	if (plugin->dm_current_uri)
+	{
+		gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog),
+		                                         plugin->dm_current_uri);
+	}
 	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
 	gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
 	gtk_window_set_destroy_with_parent (GTK_WINDOW(dialog), TRUE);
@@ -1287,6 +1318,12 @@ activate_plugin (AnjutaPlugin *plugin)
 		anjuta_plugin_add_watch (plugin, IANJUTA_PROJECT_MANAGER_CURRENT_URI,
 								 value_added_pm_current_uri,
 								 value_removed_pm_current_uri, NULL);
+	loader_plugin->dm_watch_id = 
+		anjuta_plugin_add_watch (plugin,
+								  IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT,
+								 on_value_added_current_doc,
+								 on_value_removed_current_doc,
+								 plugin);
 	
 	/* Connect to session */
 	g_signal_connect (G_OBJECT (plugin->shell), "load_session",
@@ -1343,6 +1380,7 @@ anjuta_file_loader_plugin_instance_init (GObject *obj)
 	
 	plugin->fm_current_uri = NULL;
 	plugin->pm_current_uri = NULL;
+	plugin->dm_current_uri = NULL;	
 }
 
 static void
diff --git a/plugins/file-loader/plugin.h b/plugins/file-loader/plugin.h
index 5b46013..06d3e6f 100644
--- a/plugins/file-loader/plugin.h
+++ b/plugins/file-loader/plugin.h
@@ -23,11 +23,14 @@ struct _AnjutaFileLoaderPlugin{
 	
 	gchar *fm_current_uri;
 	gchar *pm_current_uri;
-	
+	gchar *dm_current_uri;
+  
 	gint fm_watch_id;
 	gint pm_watch_id;
+  	gint dm_watch_id;
 	
 	gint uiid;
+
 };
 
 struct _AnjutaFileLoaderPluginClass{



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