[anjuta/git-shell] git: Make the remote list command self-startable
- From: James Liggett <jrliggett src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta/git-shell] git: Make the remote list command self-startable
- Date: Tue, 6 Jul 2010 02:05:06 +0000 (UTC)
commit 395b7526b331575488ae7d2b56e1a5e4b6b47537
Author: James Liggett <jrliggett cox net>
Date: Fri Jun 25 22:37:23 2010 -0700
git: Make the remote list command self-startable
plugins/git/git-remote-list-command.c | 73 ++++++++++++++++++++++++++++++++-
plugins/git/git-remote-list-command.h | 4 ++
2 files changed, 76 insertions(+), 1 deletions(-)
---
diff --git a/plugins/git/git-remote-list-command.c b/plugins/git/git-remote-list-command.c
index 56a1b9d..1ec84af 100644
--- a/plugins/git/git-remote-list-command.c
+++ b/plugins/git/git-remote-list-command.c
@@ -24,17 +24,30 @@
#include "git-remote-list-command.h"
+struct _GitRemoteListCommandPriv
+{
+ GFileMonitor *file_monitor;
+};
+
G_DEFINE_TYPE (GitRemoteListCommand, git_remote_list_command, GIT_TYPE_RAW_OUTPUT_COMMAND);
static void
git_remote_list_command_init (GitRemoteListCommand *self)
{
-
+ self->priv = g_new0 (GitRemoteListCommandPriv, 1);
}
static void
git_remote_list_command_finalize (GObject *object)
{
+ GitRemoteListCommand *self;
+
+ self = GIT_REMOTE_LIST_COMMAND (object);
+
+ anjuta_command_stop_automatic_monitor (ANJUTA_COMMAND (self));
+
+ g_free (self->priv);
+
G_OBJECT_CLASS (git_remote_list_command_parent_class)->finalize (object);
}
@@ -47,6 +60,62 @@ git_remote_list_command_run (AnjutaCommand *command)
}
static void
+on_file_monitor_changed (GFileMonitor *monitor, GFile *file, GFile *other_file,
+ GFileMonitorEvent event, AnjutaCommand *command)
+{
+ /* Git recreates the config file when it changes */
+ if (event == G_FILE_MONITOR_EVENT_CREATED)
+ anjuta_command_start (command);
+}
+
+static gboolean
+git_remote_list_command_start_automatic_monitor (AnjutaCommand *command)
+{
+ GitRemoteListCommand *self;
+ gchar *working_directory;
+ gchar *git_config_path;
+ GFile *git_config_file;
+
+ self = GIT_REMOTE_LIST_COMMAND (command);
+ g_object_get (G_OBJECT (self), "working-directory", &working_directory,
+ NULL);
+ git_config_path = g_strjoin (G_DIR_SEPARATOR_S,
+ working_directory,
+ ".git",
+ "config",
+ NULL);
+ git_config_file = g_file_new_for_path (git_config_path);
+
+ g_free (git_config_path);
+
+ self->priv->file_monitor = g_file_monitor_file (git_config_file, 0, NULL,
+ NULL);
+
+ g_signal_connect (G_OBJECT (self->priv->file_monitor ), "changed",
+ G_CALLBACK (on_file_monitor_changed),
+ self);
+
+ g_object_unref (git_config_file);
+
+ return TRUE;
+}
+
+static void
+git_remote_list_command_stop_automatic_monitor (AnjutaCommand *command)
+{
+ GitRemoteListCommand *self;
+
+ self = GIT_REMOTE_LIST_COMMAND (command);
+
+ if (self->priv->file_monitor)
+ {
+ g_file_monitor_cancel (self->priv->file_monitor);
+ g_object_unref (self->priv->file_monitor);
+ self->priv->file_monitor = NULL;
+ }
+}
+
+static void
git_remote_list_command_class_init (GitRemoteListCommandClass *klass)
{
GObjectClass* object_class = G_OBJECT_CLASS (klass);
@@ -54,6 +123,8 @@ git_remote_list_command_class_init (GitRemoteListCommandClass *klass)
object_class->finalize = git_remote_list_command_finalize;
command_class->run = git_remote_list_command_run;
+ command_class->start_automatic_monitor = git_remote_list_command_start_automatic_monitor;
+ command_class->stop_automatic_monitor = git_remote_list_command_stop_automatic_monitor;
}
diff --git a/plugins/git/git-remote-list-command.h b/plugins/git/git-remote-list-command.h
index 3ba37e7..93e7cfa 100644
--- a/plugins/git/git-remote-list-command.h
+++ b/plugins/git/git-remote-list-command.h
@@ -26,6 +26,7 @@
#define _GIT_REMOTE_LIST_COMMAND_H_
#include <glib-object.h>
+#include <gio/gio.h>
#include "git-raw-output-command.h"
G_BEGIN_DECLS
@@ -39,6 +40,7 @@ G_BEGIN_DECLS
typedef struct _GitRemoteListCommandClass GitRemoteListCommandClass;
typedef struct _GitRemoteListCommand GitRemoteListCommand;
+typedef struct _GitRemoteListCommandPriv GitRemoteListCommandPriv;
struct _GitRemoteListCommandClass
{
@@ -48,6 +50,8 @@ struct _GitRemoteListCommandClass
struct _GitRemoteListCommand
{
GitRawOutputCommand parent_instance;
+
+ GitRemoteListCommandPriv *priv;
};
GType git_remote_list_command_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]