Index: gedit-commands-file.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands-file.c,v
retrieving revision 1.10
diff -u -r1.10 gedit-commands-file.c
--- gedit-commands-file.c	31 May 2006 15:40:12 -0000	1.10
+++ gedit-commands-file.c	5 Aug 2006 13:38:30 -0000
@@ -88,6 +88,9 @@
 	gint           loaded_files = 0; /* Number of files to load */
 	gboolean       jump_to = TRUE; /* Whether to jump to the new tab */
 	gboolean       flash = TRUE;   /* Whether to flash a message in the statusbar */
+	const GList    *windows;       /* List of windows, used to check if file already open */
+	gboolean       file_already_open = FALSE;
+	GeditTab       *existing_tab;
 
 	gedit_debug (DEBUG_COMMANDS);
 
@@ -107,11 +110,30 @@
 
 			uri = (const gchar *)uris->data;
 
-			_gedit_tab_load (tab,
-					 uri,
-					 encoding,
-					 line_pos,
-					 create);
+			windows = gedit_app_get_windows (gedit_app_get_default ());
+			while (windows != NULL)
+			{
+				existing_tab = gedit_window_get_tab_from_uri (GEDIT_WINDOW (windows->data), uris->data);
+				if (existing_tab != NULL)
+				{
+					file_already_open = TRUE;
+					break;
+				}
+				windows = g_list_next (windows);
+			}
+
+			if (file_already_open == TRUE)
+			{
+				gedit_window_set_active_tab (GEDIT_WINDOW (windows->data), existing_tab);
+			}
+			else
+			{
+				_gedit_tab_load (tab,
+						 uri,
+						 encoding,
+						 line_pos,
+						 create);
+			}
 
 			uris = g_slist_next (uris);
 			jump_to = FALSE;
@@ -139,19 +161,39 @@
 
 	while (uris != NULL)
 	{
-		g_return_val_if_fail (uris->data != NULL, 0);
+		file_already_open = FALSE;
 		
-		tab = gedit_window_create_tab_from_uri (window,
-							(const gchar *)uris->data,
-							encoding,
-							line_pos,
-							create,
-							jump_to);
+		g_return_val_if_fail (uris->data != NULL, 0);
 
-		if (tab != NULL)
+		windows = gedit_app_get_windows (gedit_app_get_default ());
+		while (windows != NULL)
 		{
-			jump_to = FALSE;
-			++loaded_files;
+			existing_tab = gedit_window_get_tab_from_uri (GEDIT_WINDOW (windows->data), uris->data);
+			if (existing_tab != NULL)
+			{
+				file_already_open = TRUE;
+				break;
+			}
+			windows = g_list_next (windows);
+		}
+		
+		if (file_already_open == TRUE)
+		{
+			gedit_window_set_active_tab (GEDIT_WINDOW (windows->data), existing_tab);
+		}
+		else
+		{
+			tab = gedit_window_create_tab_from_uri (window,
+								(const gchar *)uris->data,
+								encoding,
+								line_pos,
+								create,
+								jump_to);
+			if (tab != NULL)
+			{
+				jump_to = FALSE;
+				++loaded_files;
+			}
 		}
 
 		uris = g_slist_next (uris);
