[anjuta] run-program: Keep a weak reference to the IAnjutaTerminal we run the program in.



commit 7842a4ebef7dda49b4db168482cf45c4302d4a84
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Tue Nov 27 00:35:09 2012 +0100

    run-program: Keep a weak reference to the IAnjutaTerminal we run the program in.
    
    So that we can disconnect our signal handlers from it without reloading it if it has already
    been unloaded.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=689054

 plugins/run-program/execute.c |   17 ++++++++---------
 plugins/run-program/plugin.c  |    1 +
 plugins/run-program/plugin.h  |    4 ++++
 3 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/plugins/run-program/execute.c b/plugins/run-program/execute.c
index 674d32c..8aae15d 100644
--- a/plugins/run-program/execute.c
+++ b/plugins/run-program/execute.c
@@ -138,11 +138,8 @@ run_plugin_child_free (RunProgramPlugin *plugin, GPid pid)
 				plugin->child_exited_connection--;
 				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);
+					if (plugin->terminal)
+						g_signal_handlers_disconnect_by_func (plugin->terminal, on_child_terminated, plugin);
 				}
 			}
 			else if (((RunProgramChild *)child->data)->source)
@@ -309,6 +306,10 @@ execute_with_terminal (RunProgramPlugin *plugin,
 		pid = ianjuta_terminal_execute_command (term, dir, new_cmd, env, NULL);
 
 		g_free (new_cmd);
+
+		plugin->terminal = term;
+		g_object_add_weak_pointer (G_OBJECT (plugin->terminal),
+		                           (void **)&plugin->terminal);
 	}
 
 	if (pid > 0)
@@ -583,12 +584,10 @@ void
 run_free_all_children (RunProgramPlugin *plugin)
 {
 	GList *child;
-	IAnjutaTerminal *term;
 
 	/* Remove terminal child-exited handle */
-	term = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
-										IAnjutaTerminal, NULL);
-	if (term != NULL) g_signal_handlers_disconnect_by_func (term, on_child_terminated, plugin);
+	if (plugin->terminal != NULL)
+		g_signal_handlers_disconnect_by_func (plugin->terminal, on_child_terminated, plugin);
 	plugin->child_exited_connection = 0;
 
 	/* Remove all child-exited source */
diff --git a/plugins/run-program/plugin.c b/plugins/run-program/plugin.c
index 04e70a1..b4ee5c0 100644
--- a/plugins/run-program/plugin.c
+++ b/plugins/run-program/plugin.c
@@ -364,6 +364,7 @@ run_plugin_instance_init (GObject *obj)
 	self->child = NULL;
 
 	self->build_uri = NULL;
+	self->terminal = NULL;
 }
 
 /* dispose is used to unref object created with instance_init */
diff --git a/plugins/run-program/plugin.h b/plugins/run-program/plugin.h
index 0957f60..dc8a051 100644
--- a/plugins/run-program/plugin.h
+++ b/plugins/run-program/plugin.h
@@ -22,6 +22,7 @@
 #define _PLUGIN_H_
 
 #include <libanjuta/anjuta-plugin.h>
+#include <libanjuta/interfaces/ianjuta-terminal.h>
 
 /* Anjuta Shell value set by this plugin */
 
@@ -65,6 +66,9 @@ struct _RunProgramPlugin
 	/* Build data */
 	gchar *build_uri;
 	gpointer build_handle;
+
+	/* IAnjutaTerminal object */
+	IAnjutaTerminal *terminal;
 };
 
 void run_plugin_update_shell_value (RunProgramPlugin *plugin);



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