anjuta r4204 - in trunk: . plugins/gdb plugins/run-program



Author: sgranjoux
Date: Mon Sep  1 19:52:44 2008
New Revision: 4204
URL: http://svn.gnome.org/viewvc/anjuta?rev=4204&view=rev

Log:
	* plugins/gdb/plugin.c,
	plugins/run-program/execute.c:
	Use gnome-terminal if terminal plugin is missing


Modified:
   trunk/ChangeLog
   trunk/plugins/gdb/plugin.c
   trunk/plugins/run-program/execute.c

Modified: trunk/plugins/gdb/plugin.c
==============================================================================
--- trunk/plugins/gdb/plugin.c	(original)
+++ trunk/plugins/gdb/plugin.c	Mon Sep  1 19:52:44 2008
@@ -70,6 +70,8 @@
 /* Terminal functions
  *---------------------------------------------------------------------------*/
 
+#define PREF_TERMINAL_COMMAND "anjuta.command.terminal"
+
 static void
 gdb_plugin_stop_terminal (GdbPlugin* plugin)
 {
@@ -85,7 +87,7 @@
 gdb_plugin_start_terminal (GdbPlugin* plugin)
 {
 	gchar *file, *cmd;
-       	gchar *tty = NULL;
+	gchar *tty = NULL;
 	IAnjutaTerminal *term;
 
 	DEBUG_PRINT ("In function: gdb_plugin_start_terminal() previous pid %d", plugin->term_pid);
@@ -93,17 +95,6 @@
 	/* Close previous terminal if needed */
 	gdb_plugin_stop_terminal (plugin);
 
-	/* Get terminal plugin */	
-	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
-	if (term == NULL)
-	{
-
-		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
-					  _("Anjuta terminal plugin is not installed. The program will be run without a terminal."));
-
-		return NULL;
-	}
-
 	/* Check if anjuta launcher is here */
 	if (anjuta_util_prog_is_installed ("anjuta_launcher", TRUE) == FALSE)
 	{
@@ -122,8 +113,59 @@
 
 	/* Launch terminal */
 	cmd = g_strconcat ("anjuta_launcher --__debug_terminal ", file, NULL);
-	plugin->term_pid = ianjuta_terminal_execute_command (term, NULL, cmd, NULL, NULL);
-	g_free (cmd);
+	
+	/* Get terminal plugin */	
+	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
+	if (term == NULL)
+	{
+		/* Use gnome terminal or another user defined one */
+		AnjutaPreferences *pref;
+		gchar *term_cmd;
+		gchar **argv;
+		
+		pref = anjuta_shell_get_preferences (ANJUTA_PLUGIN (plugin)->shell, NULL);
+		term_cmd = anjuta_preferences_get (pref, PREF_TERMINAL_COMMAND);
+		if (!term_cmd)
+		{
+			term_cmd = g_strdup ("gnome-terminal --disable-factory -e %s");
+		}
+		if (g_shell_parse_argv (term_cmd, NULL, &argv, NULL))
+		{
+			GPid gpid;
+			gchar **arg;
+			
+			/* Replace %s by command */
+			for (arg = argv; *arg != NULL; arg++)
+			{
+				if (strcmp(*arg, "%s") == 0)
+				{
+					g_free (*arg);
+					*arg = cmd;
+				}
+			}
+			
+			if (g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, &gpid, NULL))
+			{
+				plugin->term_pid = gpid;
+			}
+			else
+			{
+				plugin->term_pid = -1;
+			}
+			g_strfreev (argv);
+		}
+		else
+		{
+			plugin->term_pid = -1;
+		}
+		g_free (term_cmd);
+	}
+	else
+	{
+		/* Use Anjuta terminal plugin */
+		plugin->term_pid = ianjuta_terminal_execute_command (term, NULL, cmd, NULL, NULL);
+		g_free (cmd);
+	}
 
 	if (plugin->term_pid > 0)
 	{

Modified: trunk/plugins/run-program/execute.c
==============================================================================
--- trunk/plugins/run-program/execute.c	(original)
+++ trunk/plugins/run-program/execute.c	Mon Sep  1 19:52:44 2008
@@ -40,6 +40,8 @@
 #define PREF_USE_SB "build.use_scratchbox"
 #define PREF_SB_PATH "build.scratchbox.path"
 
+#define PREF_TERMINAL_COMMAND "anjuta.command.terminal"
+
 /*----------------------------------------------------------------------------
  * Type definitions
  */
@@ -157,71 +159,10 @@
 	run_plugin_update_menu_sensitivity (plugin);
 }
 
-static void
-on_child_terminated (GPid pid, gint status, gpointer user_data)
-{
-	RunProgramPlugin *plugin = (RunProgramPlugin *)user_data;
-	
-	run_plugin_child_free (plugin, pid);
-}
-
-static void
-on_child_terminated_signal (IAnjutaTerminal *term, GPid pid, gint status, gpointer user_data)
+/* Merge some environment variable in env with current environment */
+static gchar **
+merge_environment_variable (gchar ** env)
 {
-	on_child_terminated (pid, status, user_data);
-}
-
-static GPid
-execute_with_terminal (RunProgramPlugin *plugin,
-					   const gchar *dir, const gchar *cmd, gchar **env)
-{
-	IAnjutaTerminal *term;
-	GPid pid = 0;
-		
-	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
-										   IAnjutaTerminal, NULL);
-	if (term)
-	{
-		gchar* launcher_path = g_find_program_in_path("anjuta_launcher");
-		gchar *new_cmd;
-		RunProgramChild *child;
-	
-		if (launcher_path != NULL)
-		{
-			new_cmd = g_strconcat ("anjuta_launcher ", cmd, NULL);
-			g_free (launcher_path);
-		}
-		else
-		{
-			DEBUG_PRINT("Missing anjuta_launcher");
-			new_cmd = g_strdup (cmd);
-		}
-
-		if (plugin->child_exited_connection == 0)
-		{
-			g_signal_connect (term, "child-exited", G_CALLBACK (on_child_terminated_signal), plugin);
-		}
-		plugin->child_exited_connection++;
-		child = g_new0 (RunProgramChild, 1);
-		child->use_signal = TRUE;
-		plugin->child = g_list_prepend (plugin->child, child);
-		
-		pid = ianjuta_terminal_execute_command (term, dir, new_cmd, env, NULL);
-		child->pid = pid;
-		g_free (new_cmd);
-	}
-	
-	return pid;
-}
-
-static GPid
-execute_without_terminal (RunProgramPlugin *plugin,
-					   const gchar *dir, gchar *cmd, gchar **env)
-{
-	char *user_shell;
-	char * argv[4];
-	GPid pid;
-	RunProgramChild *child;
 	gsize len;
 	gchar **new_env;
 	gchar **old_env;
@@ -274,6 +215,120 @@
 		}	
 	}
 	new_env[i] = NULL;
+
+	return new_env;
+}
+
+static void
+on_child_terminated (GPid pid, gint status, gpointer user_data)
+{
+	RunProgramPlugin *plugin = (RunProgramPlugin *)user_data;
+	
+	run_plugin_child_free (plugin, pid);
+}
+
+static void
+on_child_terminated_signal (IAnjutaTerminal *term, GPid pid, gint status, gpointer user_data)
+{
+	on_child_terminated (pid, status, user_data);
+}
+
+static GPid
+execute_with_terminal (RunProgramPlugin *plugin,
+					   const gchar *dir, const gchar *cmd, gchar **env)
+{
+	IAnjutaTerminal *term;
+	GPid pid = -1;
+	gchar* launcher_path = g_find_program_in_path("anjuta_launcher");
+	gchar *new_cmd;
+	RunProgramChild *child;
+	
+	if (launcher_path != NULL)
+	{
+		new_cmd = g_strconcat ("anjuta_launcher ", cmd, NULL);
+		g_free (launcher_path);
+	}
+	else
+	{
+		DEBUG_PRINT("Missing anjuta_launcher");
+		new_cmd = g_strdup (cmd);
+	}
+
+	child = g_new0 (RunProgramChild, 1);
+	plugin->child = g_list_prepend (plugin->child, child);
+
+	/* Get terminal plugin */	
+	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
+	if (term == NULL)
+	{
+		/* Use gnome terminal or another user defined one */
+		AnjutaPreferences *pref;
+		gchar *term_cmd;
+		gchar **argv;
+		
+		pref = anjuta_shell_get_preferences (ANJUTA_PLUGIN (plugin)->shell, NULL);
+		term_cmd = anjuta_preferences_get (pref, PREF_TERMINAL_COMMAND);
+		if (!term_cmd)
+		{
+			term_cmd = g_strdup ("gnome-terminal --disable-factory -e %s");
+		}
+		if (g_shell_parse_argv (term_cmd, NULL, &argv, NULL))
+		{
+			gchar **arg;
+			gchar **new_env;
+			
+			/* Replace %s by command */
+			for (arg = argv; *arg != NULL; arg++)
+			{
+				if (strcmp(*arg, "%s") == 0)
+				{
+					g_free (*arg);
+					*arg = new_cmd;
+				}
+			}
+
+			/* Create environment variable array with new user variable */
+			new_env = merge_environment_variable (env);
+			
+			if (g_spawn_async (dir, argv, new_env, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+								NULL, NULL, &pid, NULL))
+			{
+				child->source = g_child_watch_add (pid, on_child_terminated, plugin);
+			}
+			g_strfreev (argv);
+		}
+		g_free (term_cmd);
+	}
+	else
+	{
+		/* Use Anjuta terminal plugin */
+		if (plugin->child_exited_connection == 0)
+		{
+			g_signal_connect (term, "child-exited", G_CALLBACK (on_child_terminated_signal), plugin);
+		}
+		plugin->child_exited_connection++;
+		child->use_signal = TRUE;
+	
+		pid = ianjuta_terminal_execute_command (term, dir, new_cmd, env, NULL);
+		g_free (new_cmd);
+	}
+	child->pid = pid;
+	
+	return pid;
+}
+
+static GPid
+execute_without_terminal (RunProgramPlugin *plugin,
+					   const gchar *dir, gchar *cmd, gchar **env)
+{
+	char *user_shell;
+	char * argv[4];
+	GPid pid;
+	RunProgramChild *child;
+	gchar **new_env;
+
+	/* Create environment variable array with new user variable */
+	new_env = merge_environment_variable (env);
 	
 	/* Run user program using in a shell */
 	user_shell = anjuta_util_user_shell ();
@@ -285,7 +340,7 @@
 	child = g_new0 (RunProgramChild, 1);
 	plugin->child = g_list_prepend (plugin->child, child);
 	
-	if (g_spawn_async_with_pipes (dir, argv, new_env, G_SPAWN_DO_NOT_REAP_CHILD,
+	if (g_spawn_async_with_pipes (dir, argv, new_env, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
 									NULL, NULL, &pid, NULL, NULL, NULL, NULL))
 	{
 		child->pid = pid;



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