From 12fed78b4c9e9df27c6b2f35d0e432a839ec1b79 Mon Sep 17 00:00:00 2001
From: Can Koy <cankoy@ymail.com>
Date: Tue, 2 Mar 2010 02:21:22 +0200
Subject: [PATCH 5/5] Modify <Enter> key behaviour in Filebrowser plugin.

---
 plugins/filebrowser.c |   14 +++++++++-----
 src/document.c        |    9 +++++++--
 src/document.h        |    2 +-
 src/plugindata.h      |    2 +-
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/plugins/filebrowser.c b/plugins/filebrowser.c
index bed0eab..35192c2 100644
--- a/plugins/filebrowser.c
+++ b/plugins/filebrowser.c
@@ -444,10 +444,11 @@ static void on_external_open(GtkMenuItem *menuitem, gpointer user_data)
 
 
 /* We use document_open_files() as it's more efficient. */
-static void open_selected_files(GList *list)
+static void open_selected_files(GList *list, guint keyval)
 {
 	GSList *files = NULL;
 	GList *item;
+	GeanyDocument *doc;
 
 	for (item = list; item != NULL; item = g_list_next(item))
 	{
@@ -456,7 +457,10 @@ static void open_selected_files(GList *list)
 
 		files = g_slist_append(files, fname);
 	}
-	document_open_files(files, FALSE, NULL, NULL);
+	doc = document_open_files(files, FALSE, NULL, NULL);
+	if (doc && (keyval == GDK_Return || keyval == GDK_ISO_Enter || keyval == GDK_KP_Enter))
+		gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
+	
 	g_slist_foreach(files, (GFunc) g_free, NULL);	/* free filenames */
 	g_slist_free(files);
 }
@@ -493,7 +497,7 @@ static void on_open_clicked(GtkMenuItem *menuitem, gpointer user_data)
 		}
 	}
 	else
-		open_selected_files(list);
+		open_selected_files(list, (guint)user_data);
 
 	g_list_foreach(list, (GFunc) gtk_tree_path_free, NULL);
 	g_list_free(list);
@@ -625,7 +629,7 @@ static gboolean on_button_press(GtkWidget *widget, GdkEventButton *event, gpoint
 {
 	if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
 	{
-		on_open_clicked(NULL, NULL);
+		on_open_clicked(NULL, (gpointer)GDK_VoidSymbol);
 		return TRUE;
 	}
 	else if (event->button == 3)
@@ -649,7 +653,7 @@ static gboolean on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer dat
 		|| event->keyval == GDK_KP_Enter
 		|| event->keyval == GDK_space)
 	{
-		on_open_clicked(NULL, NULL);
+		on_open_clicked(NULL, (gpointer)event->keyval);
 		return TRUE;
 	}
 
diff --git a/src/document.c b/src/document.c
index a89cd51..f3ab2a9 100644
--- a/src/document.c
+++ b/src/document.c
@@ -1408,16 +1408,21 @@ void document_open_file_list(const gchar *data, gssize length)
  *  @param readonly Whether to open the document in read-only mode.
  *  @param ft The filetype for the document or @c NULL to auto-detect the filetype.
  *  @param forced_enc The file encoding to use or @c NULL to auto-detect the file encoding.
+ * 
+ *  @return The last document opened or @c NULL.
  **/
-void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
+GeanyDocument *document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
 		const gchar *forced_enc)
 {
 	const GSList *item;
+	GeanyDocument *doc = NULL;
 
 	for (item = filenames; item != NULL; item = g_slist_next(item))
 	{
-		document_open_file(item->data, readonly, ft, forced_enc);
+		doc = document_open_file(item->data, readonly, ft, forced_enc);
 	}
+	
+	return doc;
 }
 
 
diff --git a/src/document.h b/src/document.h
index f2791d5..7b614c4 100644
--- a/src/document.h
+++ b/src/document.h
@@ -207,7 +207,7 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename
 
 void document_open_file_list(const gchar *data, gssize length);
 
-void document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
+GeanyDocument *document_open_files(const GSList *filenames, gboolean readonly, GeanyFiletype *ft,
 		const gchar *forced_enc);
 
 gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gint flags, gboolean inc);
diff --git a/src/plugindata.h b/src/plugindata.h
index 5bb5a78..422bdbf 100644
--- a/src/plugindata.h
+++ b/src/plugindata.h
@@ -258,7 +258,7 @@ typedef struct DocumentFuncs
 	gboolean				(*document_save_file) (struct GeanyDocument *doc, gboolean force);
 	struct GeanyDocument*	(*document_open_file) (const gchar *locale_filename, gboolean readonly,
 			struct GeanyFiletype *ft, const gchar *forced_enc);
-	void		(*document_open_files) (const GSList *filenames, gboolean readonly,
+	GeanyDocument*			(*document_open_files) (const GSList *filenames, gboolean readonly,
 			struct GeanyFiletype *ft, const gchar *forced_enc);
 	gboolean	(*document_remove_page) (guint page_num);
 	gboolean	(*document_reload_file) (struct GeanyDocument *doc, const gchar *forced_enc);
-- 
1.6.3.3

