[anjuta/git-shell: 233/234] libanjuta: Introduce execution modes to AnjutaCommandQueue



commit b9b62d9b21b14f37b679b4d013f8c3ca18a26323
Author: James Liggett <jrliggett cox net>
Date:   Mon May 3 19:59:17 2010 -0700

    libanjuta: Introduce execution modes to AnjutaCommandQueue
    
    Clients can now choose to execute their command queues automatically or
    manually. In automatic mode, commands are executed as soon as they are
    pushed. In manual mode, commands are pushed, but are only executed when
    explciitly asked.

 libanjuta/anjuta-command-queue.c |   96 ++++++++++++++++++++++++++++++++++----
 libanjuta/anjuta-command-queue.h |   12 ++++-
 libanjuta/libanjuta.h            |    1 +
 plugins/git/plugin.c             |    2 +-
 4 files changed, 99 insertions(+), 12 deletions(-)
---
diff --git a/libanjuta/anjuta-command-queue.c b/libanjuta/anjuta-command-queue.c
index d7da3fb..22377fc 100644
--- a/libanjuta/anjuta-command-queue.c
+++ b/libanjuta/anjuta-command-queue.c
@@ -19,10 +19,20 @@
 
 #include "anjuta-command-queue.h"
 
+enum
+{
+	FINISHED,
+
+	LAST_SIGNAL
+};
+
+static guint anjuta_command_queue_signals[LAST_SIGNAL] = { 0 };
+
 struct _AnjutaCommandQueuePriv
 {
 	GQueue *queue;
 	gboolean busy;
+	AnjutaCommandQueueExecuteMode mode;
 };
 
 G_DEFINE_TYPE (AnjutaCommandQueue, anjuta_command_queue, G_TYPE_OBJECT);
@@ -58,11 +68,29 @@ anjuta_command_queue_finalize (GObject *object)
 }
 
 static void
+finished (AnjutaCommandQueue *queue)
+{
+
+}
+
+static void
 anjuta_command_queue_class_init (AnjutaCommandQueueClass *klass)
 {
 	GObjectClass* object_class = G_OBJECT_CLASS (klass);
 
 	object_class->finalize = anjuta_command_queue_finalize;
+	klass->finished = finished;
+
+	anjuta_command_queue_signals[FINISHED] = g_signal_new ("finished",
+	                                                       G_OBJECT_CLASS_TYPE (klass),
+	                                                       G_SIGNAL_RUN_FIRST,
+	                                                       G_STRUCT_OFFSET (AnjutaCommandQueueClass, finished),
+	                                                       NULL,
+	                                                       NULL,
+	                                                       g_cclosure_marshal_VOID__VOID,
+	                                                       G_TYPE_NONE,
+	                                                       0);
+	                                                       
 }
 
 static void
@@ -84,28 +112,76 @@ on_command_finished (AnjutaCommand *command, guint return_code,
 		g_object_unref (next_command);
 	}
 	else
+	{
 		self->priv->busy = FALSE;
+
+		if (self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL)
+			g_signal_emit_by_name (self, "finished");
+	}
 }
 
 AnjutaCommandQueue *
-anjuta_command_queue_new (void)
+anjuta_command_queue_new (AnjutaCommandQueueExecuteMode mode)
 {
-	return g_object_new (ANJUTA_TYPE_COMMAND_QUEUE, NULL);
+	AnjutaCommandQueue *self;
+
+	self = g_object_new (ANJUTA_TYPE_COMMAND_QUEUE, NULL);
+
+	self->priv->mode = mode;
+
+	return self;
 }
 
 void
 anjuta_command_queue_push (AnjutaCommandQueue *self, AnjutaCommand *command)
 {
-	if (!self->priv->busy)
+	if (self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_AUTOMATIC)
 	{
-		self->priv->busy = TRUE;
-
-		g_signal_connect (G_OBJECT (command), "command-finished",
-		                  G_CALLBACK (on_command_finished),
-		                  self);
-		
-		anjuta_command_start (command);
+		if (!self->priv->busy)
+		{
+			g_signal_connect (G_OBJECT (command), "command-finished",
+			                  G_CALLBACK (on_command_finished),
+			                  self);
+
+			if (self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_AUTOMATIC)
+			{
+				self->priv->busy = TRUE;
+				anjuta_command_start (command);
+			}
+		}
+		else
+			g_queue_push_tail (self->priv->queue, g_object_ref (command));
 	}
 	else
 		g_queue_push_tail (self->priv->queue, g_object_ref (command));
 }
+
+gboolean
+anjuta_command_queue_start (AnjutaCommandQueue *self)
+{
+	gboolean ret;
+	AnjutaCommand *first_command;
+
+	ret = FALSE;
+
+	if ((self->priv->mode == ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL) &&
+	    (!self->priv->busy))
+	{
+		first_command = g_queue_pop_head (self->priv->queue);
+
+		if (first_command)
+		{
+			g_signal_connect (G_OBJECT (first_command), "command-finished",
+			                  G_CALLBACK (on_command_finished),
+			                  self);
+
+			self->priv->busy = TRUE;
+			ret = TRUE;
+
+			anjuta_command_start (first_command);
+		}
+	}
+
+	return ret;
+		
+}
\ No newline at end of file
diff --git a/libanjuta/anjuta-command-queue.h b/libanjuta/anjuta-command-queue.h
index a10b07e..a7645a2 100644
--- a/libanjuta/anjuta-command-queue.h
+++ b/libanjuta/anjuta-command-queue.h
@@ -39,6 +39,9 @@ typedef struct _AnjutaCommandQueuePriv AnjutaCommandQueuePriv;
 struct _AnjutaCommandQueueClass
 {
 	GObjectClass parent_class;
+
+	/* Signals */
+	void (*finished) (AnjutaCommandQueue *queue);
 };
 
 struct _AnjutaCommandQueue
@@ -48,10 +51,17 @@ struct _AnjutaCommandQueue
 	AnjutaCommandQueuePriv *priv;
 };
 
+typedef enum
+{
+	ANJUTA_COMMAND_QUEUE_EXECUTE_AUTOMATIC,
+	ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL
+} AnjutaCommandQueueExecuteMode;
+
 GType anjuta_command_queue_get_type (void) G_GNUC_CONST;
-AnjutaCommandQueue * anjuta_command_queue_new (void);
+AnjutaCommandQueue * anjuta_command_queue_new (AnjutaCommandQueueExecuteMode mode);
 void anjuta_command_queue_push (AnjutaCommandQueue *self, 
                                 AnjutaCommand *command);
+gboolean anjuta_command_queue_start (AnjutaCommandQueue *self);
 
 G_END_DECLS
 
diff --git a/libanjuta/libanjuta.h b/libanjuta/libanjuta.h
index 64d8f1c..308e719 100644
--- a/libanjuta/libanjuta.h
+++ b/libanjuta/libanjuta.h
@@ -51,5 +51,6 @@
 #include <libanjuta/anjuta-sync-command.h>
 #include <libanjuta/gbf-project.h>
 #include <libanjuta/anjuta-project.h>
+#include <libanjuta/anjuta-command-queue.h>
 
 #endif
diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c
index 1b953a0..f1cc000 100644
--- a/plugins/git/plugin.c
+++ b/plugins/git/plugin.c
@@ -915,7 +915,7 @@ git_instance_init (GObject *obj)
 	Git *plugin = ANJUTA_PLUGIN_GIT (obj);
 	plugin->uiid = 0;
 
-	plugin->command_queue = anjuta_command_queue_new ();
+	plugin->command_queue = anjuta_command_queue_new (ANJUTA_COMMAND_QUEUE_EXECUTE_AUTOMATIC);
 }
 
 static void



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