[anjuta] run-program: bgo #666336 - Add Execute project more than one



commit 4f8933c2876e147d09db15f0e3e675198676c725
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sun Dec 18 18:11:41 2011 +0100

    run-program: bgo #666336 - Add Execute project more than one

 plugins/run-program/execute.c |   87 +++++++++++++++++++++--------------------
 plugins/run-program/plugin.c  |   72 ++++++++++++++++-----------------
 2 files changed, 79 insertions(+), 80 deletions(-)
---
diff --git a/plugins/run-program/execute.c b/plugins/run-program/execute.c
index 1d230bf..3595a8d 100644
--- a/plugins/run-program/execute.c
+++ b/plugins/run-program/execute.c
@@ -84,12 +84,12 @@ get_local_executable (GtkWindow *parent, const gchar *uri)
 	}
 
 	if (err_msg)
-	{	
+	{
 		anjuta_util_dialog_error (parent, err_msg, local == NULL ? uri : local);
 		g_free (local);
 		local = NULL;
 	}
-	
+
 	return local;
 }
 
@@ -108,12 +108,12 @@ get_local_directory (GtkWindow *parent, const gchar *uri)
 			err_msg = _("Program directory '%s' is not local");
 		}
 	}
-	
+
 	if (err_msg)
 	{
 		anjuta_util_dialog_error (parent, err_msg, uri);
 	}
-	
+
 	return local;
 }
 
@@ -127,7 +127,7 @@ static void
 run_plugin_child_free (RunProgramPlugin *plugin, GPid pid)
 {
 	GList *child;
-	
+
 	for (child = g_list_first (plugin->child); child != NULL; child = g_list_next (child))
 	{
 		if (((RunProgramChild *)child->data)->pid == pid)
@@ -139,7 +139,7 @@ run_plugin_child_free (RunProgramPlugin *plugin, GPid pid)
 				if (plugin->child_exited_connection == 0)
 				{
 					IAnjutaTerminal *term;
-		
+
 					term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
 													   IAnjutaTerminal, NULL);
 					g_signal_handlers_disconnect_by_func (term, on_child_terminated, plugin);
@@ -165,31 +165,31 @@ merge_environment_variable (gchar ** env)
 	gsize len;
 	gchar **new_env;
 	gchar **old_env;
-	gchar **p;	
+	gchar **p;
 	gint i;
 
 	/* Create environment variable array */
 	old_env = g_listenv();
 	len = old_env ? g_strv_length (old_env) : 0;
 	len += env ? g_strv_length (env) : 0;
-	len ++;	
+	len ++;
 	new_env = g_new (char *, len);
-	
+
 	/* Remove some environment variables, Move other in new_env */
 	i = 0;
 	for (p = old_env; *p; p++)
 	{
 		const gchar *value;
-		
+
 		value = g_getenv (*p);
 		if (env != NULL)
 		{
 			gchar **q;
-		
+
 			for (q = env; *q; q++)
 			{
 				gsize len;
-				
+
 				len = strlen (*p);
 				if ((strlen (*q) > len + 1) &&
 					(strncmp (*q, *p, len) == 0) &&
@@ -200,18 +200,18 @@ merge_environment_variable (gchar ** env)
 				}
 			}
 		}
-		
+
 		new_env[i++] = g_strconcat (*p, "=", value, NULL);
 	}
 	g_strfreev (old_env);
-	
+
 	/* Add new user variable */
 	if (env)
 	{
 		for (p = env; *p; p++)
 		{
 			new_env[i++] = g_strdup (*p);
-		}	
+		}
 	}
 	new_env[i] = NULL;
 
@@ -222,7 +222,7 @@ static void
 on_child_terminated (GPid pid, gint status, gpointer user_data)
 {
 	RunProgramPlugin *plugin = (RunProgramPlugin *)user_data;
-	
+
 	run_plugin_child_free (plugin, pid);
 }
 
@@ -241,7 +241,7 @@ execute_with_terminal (RunProgramPlugin *plugin,
 	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);
@@ -256,22 +256,23 @@ execute_with_terminal (RunProgramPlugin *plugin,
 	child = g_new0 (RunProgramChild, 1);
 	plugin->child = g_list_prepend (plugin->child, child);
 
-	/* Get terminal plugin */	
+	/* Get terminal plugin */
 	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaTerminal, NULL);
-	if (term == NULL)
+	if ((term == NULL) ||
+	    (g_list_length (plugin->child) > 1))			/* Only one program can use Anjuta terminal */
 	{
 		/* Use gnome terminal or another user defined one */
 		GSettings* settings = g_settings_new (PREF_SCHEMA);
 		gchar *term_cmd;
 		gchar **argv;
-		
+
 		term_cmd = g_settings_get_string (settings, PREF_TERMINAL_COMMAND);
 		g_object_unref (settings);
 		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++)
 			{
@@ -284,7 +285,7 @@ execute_with_terminal (RunProgramPlugin *plugin,
 
 			/* 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))
 			{
@@ -304,9 +305,9 @@ execute_with_terminal (RunProgramPlugin *plugin,
 		}
 		plugin->child_exited_connection++;
 		child->use_signal = TRUE;
-	
+
 		pid = ianjuta_terminal_execute_command (term, dir, new_cmd, env, NULL);
-		
+
 		g_free (new_cmd);
 	}
 
@@ -319,7 +320,7 @@ execute_with_terminal (RunProgramPlugin *plugin,
 		on_child_terminated (0, 0, plugin);
 		pid = 0;
 	}
-	
+
 	return pid;
 }
 
@@ -335,7 +336,7 @@ execute_without_terminal (RunProgramPlugin *plugin,
 
 	/* 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 ();
 	argv[0] = user_shell;
@@ -345,7 +346,7 @@ execute_without_terminal (RunProgramPlugin *plugin,
 
 	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_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
 									NULL, NULL, &pid, NULL, NULL, NULL, NULL))
 	{
@@ -357,10 +358,10 @@ execute_without_terminal (RunProgramPlugin *plugin,
 		on_child_terminated (0, 0, plugin);
 		pid = 0;
 	}
-	
+
 	g_free (user_shell);
 	g_strfreev (new_env);
-	
+
 	return pid;
 }
 
@@ -376,7 +377,7 @@ run_program (RunProgramPlugin *plugin)
 	gchar *cmd;
 	gboolean run_in_terminal = 0;
 	GPid pid;
-	
+
 	target = get_local_executable (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
 								plugin->build_uri);
 	g_free (plugin->build_uri);
@@ -398,18 +399,18 @@ run_program (RunProgramPlugin *plugin)
 	{
 		dir = g_path_get_dirname (target);
 	}
-	
+
 	/* Get other parameters from shell */
 	anjuta_shell_get (ANJUTA_PLUGIN (plugin)->shell,
 					RUN_PROGRAM_ARGS, G_TYPE_STRING, &args,
 					RUN_PROGRAM_ENV, G_TYPE_STRV, &env,
 					RUN_PROGRAM_NEED_TERM, G_TYPE_BOOLEAN, &run_in_terminal,
 					NULL);
-	
+
 	/* Quote target name */
 	quote_target = g_shell_quote (target);
 	g_free (target);
-	
+
 	if (args && strlen (args) > 0)
 		cmd = g_strconcat (quote_target, " ", args, NULL);
 	else
@@ -428,14 +429,14 @@ run_program (RunProgramPlugin *plugin)
 		const gchar* real_dir = strstr(dir, "/home");
 		gchar* oldcmd = cmd;
 		gchar* olddir = dir;
-		
+
 		cmd = g_strdup_printf("%s/login -d %s \"%s\"", sb_path,
 									  real_dir, oldcmd);
 		g_free(oldcmd);
 		dir = g_strdup(real_dir);
 		g_free (olddir);
 	}
-#endif	
+#endif
 	if (run_in_terminal)
 	{
 		pid = execute_with_terminal (plugin, dir, cmd, env);
@@ -448,14 +449,14 @@ run_program (RunProgramPlugin *plugin)
 	{
 		pid = execute_without_terminal (plugin, dir, cmd, env);
 	}
-	
+
 	if (pid == 0)
 	{
 		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
 								  "Unable to execute %s", cmd);
 	}
 	run_plugin_update_menu_sensitivity (plugin);
-	
+
 	g_free (dir);
 	g_strfreev (env);
 	g_free (cmd);
@@ -511,7 +512,7 @@ check_target (RunProgramPlugin *plugin)
 
 	anjuta_shell_get (ANJUTA_PLUGIN (plugin)->shell,
 					  RUN_PROGRAM_URI, G_TYPE_STRING, &prog_uri, NULL);
-	
+
 	builder = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell, IAnjutaBuilder, NULL);
 	if (builder != NULL)
 	{
@@ -529,7 +530,7 @@ check_target (RunProgramPlugin *plugin)
 				ianjuta_builder_cancel (builder, plugin->build_handle, NULL);
 			}
 		}
-		
+
 		plugin->build_uri = prog_uri;
 
 		/* Check if target is up to date */
@@ -540,10 +541,10 @@ check_target (RunProgramPlugin *plugin)
 	else
 	{
 		plugin->build_uri = prog_uri;
-		
+
 		/* Unable to build target, just run it */
 		return run_program (plugin);
-	}	
+	}
 }
 
 /* Public functions
@@ -562,7 +563,7 @@ run_plugin_kill_program (RunProgramPlugin *plugin, gboolean terminate)
 	if (plugin->child != NULL)
 	{
 		RunProgramChild *child = (RunProgramChild *)plugin->child->data;
-		
+
 		if (!child->terminated && terminate)
 		{
 			kill (child->pid, SIGTERM);
@@ -574,7 +575,7 @@ run_plugin_kill_program (RunProgramPlugin *plugin, gboolean terminate)
 			run_plugin_child_free (plugin, child->pid);
 		}
 	}
-	
+
 	return TRUE;
 }
 
diff --git a/plugins/run-program/plugin.c b/plugins/run-program/plugin.c
index 4b692e9..2b881e6 100644
--- a/plugins/run-program/plugin.c
+++ b/plugins/run-program/plugin.c
@@ -56,7 +56,7 @@ static void
 anjuta_session_set_limited_string_list (AnjutaSession *session, const gchar *section, const gchar *key, GList **value)
 {
 	GList *node;
-	
+
 	while ((node = g_list_nth (*value, MAX_RECENT_ITEM)) != NULL)
 	{
 		g_free (node->data);
@@ -69,7 +69,7 @@ static void
 anjuta_session_set_strv (AnjutaSession *session, const gchar *section, const gchar *key, gchar **value)
 {
 	GList *list = NULL;
-	
+
 	if (value != NULL)
 	{
 		for (; *value != NULL; value++)
@@ -78,7 +78,7 @@ anjuta_session_set_strv (AnjutaSession *session, const gchar *section, const gch
 		}
 		list = g_list_reverse (list);
 	}
-	
+
 	anjuta_session_set_string_list (session, section, key, list);
 	g_list_free (list);
 }
@@ -88,9 +88,9 @@ anjuta_session_get_strv (AnjutaSession *session, const gchar *section, const gch
 {
 	GList *list;
 	gchar **value = NULL;
-	
+
 	list = anjuta_session_get_string_list (session, section, key);
-	
+
 	if (list != NULL)
 	{
 		gchar **var;
@@ -105,7 +105,7 @@ anjuta_session_get_strv (AnjutaSession *session, const gchar *section, const gch
 		}
 		*var = NULL;
 	}
-			
+
 	return value;
 }
 
@@ -133,28 +133,28 @@ static void on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase, Anjut
 		return;
 
  	if (self->recent_args != NULL)
- 	{		
+ 	{
  		g_list_foreach (self->recent_args, (GFunc)g_free, NULL);
  		g_list_free (self->recent_args);
  	}
  	self->recent_args = anjuta_session_get_string_list (session, "Execution", "Program arguments");
 
  	if (self->recent_target != NULL)
- 	{		
+ 	{
  		g_list_foreach (self->recent_target, (GFunc)g_free, NULL);
  		g_list_free (self->recent_target);
  	}
  	self->recent_target = anjuta_session_get_string_list (session, "Execution", "Program uri");
-	
+
 	/* The flag is store as 1 == FALSE, 2 == TRUE */
 	run_in_terminal = anjuta_session_get_int (session, "Execution", "Run in terminal");
 	if (run_in_terminal == 0)
 		self->run_in_terminal = TRUE;	/* Default value */
 	else
 		self->run_in_terminal = run_in_terminal - 1;
-	
+
  	if (self->recent_dirs != NULL)
- 	{		
+ 	{
  		g_list_foreach (self->recent_dirs, (GFunc)g_free, NULL);
  		g_list_free (self->recent_dirs);
  	}
@@ -163,7 +163,7 @@ static void on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase, Anjut
 	{
 		/* Use project directory by default */
 		GValue value = {0,};
-	
+
 		anjuta_shell_get_value (ANJUTA_PLUGIN(self)->shell,
 		    IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI,
 		    &value,
@@ -176,7 +176,7 @@ static void on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase, Anjut
 
 	g_strfreev (self->environment_vars);
  	self->environment_vars = anjuta_session_get_strv (session, "Execution", "Environment variables");
-	
+
 	run_plugin_update_shell_value (self);
 }
 
@@ -188,14 +188,12 @@ on_run_program_activate (GtkAction* action, RunProgramPlugin* plugin)
 {
 	if (plugin->child != NULL)
 	{
-       gchar *msg = _("The program is running.\n"
-                      	"Do you want to restart it?");
+       gchar *msg = _("The program is already running.\n"
+                      	"Do you want to stop it before restarting a new instance?");
 		if (anjuta_util_dialog_boolean_question (GTK_WINDOW ( ANJUTA_PLUGIN (plugin)->shell), msg))
 		{
 			run_plugin_kill_program (plugin, FALSE);
 		}
-		else
-			return;
 	}
 	if (plugin->recent_target == NULL)
 	{
@@ -204,7 +202,7 @@ on_run_program_activate (GtkAction* action, RunProgramPlugin* plugin)
 			return;
 		}
 	}
-	
+
 	run_plugin_run_program(plugin);
 }
 
@@ -267,7 +265,7 @@ run_plugin_activate (AnjutaPlugin *plugin)
 {
 	RunProgramPlugin *self = ANJUTA_PLUGIN_RUN_PROGRAM (plugin);
 	AnjutaUI *ui;
-	
+
 	DEBUG_PRINT ("%s", "Run Program Plugin: Activating pluginâ");
 
 	/* Connect to session signal */
@@ -275,18 +273,18 @@ run_plugin_activate (AnjutaPlugin *plugin)
 					  G_CALLBACK (on_session_save), self);
     g_signal_connect (plugin->shell, "load-session",
 					  G_CALLBACK (on_session_load), self);
-	
+
 	/* Add actions */
 	ui = anjuta_shell_get_ui (plugin->shell, NULL);
 	self->action_group = anjuta_ui_add_action_group_entries (ui,
 									"ActionGroupRun", _("Run operations"),
 									actions_run, G_N_ELEMENTS (actions_run),
 									GETTEXT_PACKAGE, TRUE, self);
-	
+
 	self->uiid = anjuta_ui_merge (ui, UI_FILE);
 
 	run_plugin_update_menu_sensitivity (self);
-	
+
 	return TRUE;
 }
 
@@ -297,16 +295,16 @@ run_plugin_deactivate (AnjutaPlugin *plugin)
 	AnjutaUI *ui;
 
 	DEBUG_PRINT ("%s", "Run Program Plugin: Deactivating pluginâ");
-	
+
 	ui = anjuta_shell_get_ui (plugin->shell, NULL);
 	anjuta_ui_remove_action_group (ui, self->action_group);
-	
+
 	anjuta_ui_unmerge (ui, self->uiid);
-	
+
 	g_signal_handlers_disconnect_by_func (plugin->shell, G_CALLBACK (on_session_save), self);
     g_signal_handlers_disconnect_by_func (plugin->shell, G_CALLBACK (on_session_load), self);
-	
-	
+
+
 	return TRUE;
 }
 
@@ -320,14 +318,14 @@ static void
 run_plugin_instance_init (GObject *obj)
 {
 	RunProgramPlugin *self = ANJUTA_PLUGIN_RUN_PROGRAM (obj);
-	
+
 	self->recent_target = NULL;
 	self->recent_args = NULL;
 	self->recent_dirs = NULL;
 	self->environment_vars = NULL;
-	
+
 	self->child = NULL;
-	
+
 	self->build_uri = NULL;
 }
 
@@ -337,11 +335,11 @@ static void
 run_plugin_dispose (GObject *obj)
 {
 	RunProgramPlugin *plugin = ANJUTA_PLUGIN_RUN_PROGRAM (obj);
-	
+
 	/* Warning this function could be called several times */
 
 	run_free_all_children (plugin);
-	
+
 	G_OBJECT_CLASS (parent_class)->dispose (obj);
 }
 
@@ -349,7 +347,7 @@ static void
 run_plugin_finalize (GObject *obj)
 {
 	RunProgramPlugin *self = ANJUTA_PLUGIN_RUN_PROGRAM (obj);
-	
+
 	g_list_foreach (self->recent_target, (GFunc)g_free, NULL);
 	g_list_free (self->recent_target);
 	g_list_foreach (self->recent_args, (GFunc)g_free, NULL);
@@ -359,14 +357,14 @@ run_plugin_finalize (GObject *obj)
 	g_list_foreach (self->recent_dirs, (GFunc)g_free, NULL);
 	g_list_free (self->recent_dirs);
 	g_strfreev (self->environment_vars);
-	
+
 	G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
 
 /* finalize used to free object created with instance init is not used */
 
 static void
-run_plugin_class_init (GObjectClass *klass) 
+run_plugin_class_init (GObjectClass *klass)
 {
 	AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
 
@@ -383,7 +381,7 @@ run_plugin_class_init (GObjectClass *klass)
 
 ANJUTA_PLUGIN_BEGIN (RunProgramPlugin, run_plugin);
 ANJUTA_PLUGIN_END;
-					 
+
 ANJUTA_SIMPLE_PLUGIN (RunProgramPlugin, run_plugin);
 
 /* Public functions
@@ -407,7 +405,7 @@ run_plugin_update_menu_sensitivity (RunProgramPlugin *plugin)
 {
 	GtkAction *action;
 	action = gtk_action_group_get_action (plugin->action_group, "ActionStopProgram");
-	
+
 	gtk_action_set_sensitive (action, plugin->child != NULL);
 }
 



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