From 52d16f9669726e029859412c9ec2f9352b3a5edb Mon Sep 17 00:00:00 2001 From: James Liggett Date: Wed, 14 May 2008 16:44:42 -0700 Subject: [PATCH] Create a base class for commands that just pass raw output This is usually used for commands that just pass their raw output into a queue for an editor, like diff, ditt-tree, and cat. --- plugins/git/Makefile.am | 4 +- plugins/git/git-diff-command.c | 52 ++---------------- plugins/git/git-diff-command.h | 10 ++-- plugins/git/git-diff-dialog.c | 2 +- ...git-diff-command.c => git-raw-output-command.c} | 57 +++++++------------- plugins/git/git-raw-output-command.h | 61 ++++++++++++++++++++++ plugins/git/git-ui-utils.c | 6 +-- plugins/git/git-ui-utils.h | 4 +- 8 files changed, 95 insertions(+), 101 deletions(-) copy plugins/git/{git-diff-command.c => git-raw-output-command.c} (56%) create mode 100644 plugins/git/git-raw-output-command.h diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am index d242624f..736ea968 100644 --- a/plugins/git/Makefile.am +++ b/plugins/git/Makefile.am @@ -113,7 +113,9 @@ libanjuta_git_la_SOURCES = \ git-ref.h \ git-ref.c \ git-ref-command.c \ - git-ref-command.h + git-ref-command.h \ + git-raw-output-command.c \ + git-raw-output-command.h libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS) diff --git a/plugins/git/git-diff-command.c b/plugins/git/git-diff-command.c index 0dfb1b39..498b1a73 100644 --- a/plugins/git/git-diff-command.c +++ b/plugins/git/git-diff-command.c @@ -24,73 +24,35 @@ #include "git-diff-command.h" -struct _GitDiffCommandPriv -{ - GQueue *output_queue; -}; - -G_DEFINE_TYPE (GitDiffCommand, git_diff_command, GIT_TYPE_COMMAND); +G_DEFINE_TYPE (GitDiffCommand, git_diff_command, GIT_TYPE_RAW_OUTPUT_COMMAND); static void git_diff_command_init (GitDiffCommand *self) { - self->priv = g_new0 (GitDiffCommandPriv, 1); - self->priv->output_queue = g_queue_new (); + } static void git_diff_command_finalize (GObject *object) { - GitDiffCommand *self; - GList *current_output; - - self = GIT_DIFF_COMMAND (object); - current_output = self->priv->output_queue->head; - - while (current_output) - { - g_free (current_output->data); - current_output = g_list_next (current_output); - } - - g_queue_free (self->priv->output_queue); - g_free (self->priv); - G_OBJECT_CLASS (git_diff_command_parent_class)->finalize (object); } static guint git_diff_command_run (AnjutaCommand *command) -{ - GitDiffCommand *self; - - self = GIT_DIFF_COMMAND (command); - - git_command_add_arg (GIT_COMMAND (self), "diff"); +{ + git_command_add_arg (GIT_COMMAND (command), "diff"); return 0; } static void -git_diff_command_handle_output (GitCommand *git_command, const gchar *output) -{ - GitDiffCommand *self; - - self = GIT_DIFF_COMMAND (git_command); - - g_queue_push_tail (self->priv->output_queue, g_strdup (output)); - anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command)); -} - -static void git_diff_command_class_init (GitDiffCommandClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); - GitCommandClass* parent_class = GIT_COMMAND_CLASS (klass); AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass); object_class->finalize = git_diff_command_finalize; - parent_class->output_handler = git_diff_command_handle_output; command_class->run = git_diff_command_run; } @@ -102,9 +64,3 @@ git_diff_command_new (const gchar *working_directory) "working-directory", working_directory, NULL); } - -GQueue * -git_diff_command_get_output (GitDiffCommand *self) -{ - return self->priv->output_queue; -} diff --git a/plugins/git/git-diff-command.h b/plugins/git/git-diff-command.h index 292905a5..b96f06db 100644 --- a/plugins/git/git-diff-command.h +++ b/plugins/git/git-diff-command.h @@ -26,7 +26,7 @@ #define _GIT_DIFF_COMMAND_H_ #include -#include "git-command.h" +#include "git-raw-output-command.h" G_BEGIN_DECLS @@ -39,23 +39,19 @@ G_BEGIN_DECLS typedef struct _GitDiffCommandClass GitDiffCommandClass; typedef struct _GitDiffCommand GitDiffCommand; -typedef struct _GitDiffCommandPriv GitDiffCommandPriv; struct _GitDiffCommandClass { - GitCommandClass parent_class; + GitRawOutputCommandClass parent_class; }; struct _GitDiffCommand { - GitCommand parent_instance; - - GitDiffCommandPriv *priv; + GitRawOutputCommand parent_instance; }; GType git_diff_command_get_type (void) G_GNUC_CONST; GitDiffCommand *git_diff_command_new (const gchar *working_directory); -GQueue *git_diff_command_get_output (GitDiffCommand *self); G_END_DECLS diff --git a/plugins/git/git-diff-dialog.c b/plugins/git/git-diff-dialog.c index b0b43f5d..f39ff855 100644 --- a/plugins/git/git-diff-dialog.c +++ b/plugins/git/git-diff-dialog.c @@ -45,7 +45,7 @@ git_diff (Git *plugin) diff_command = git_diff_command_new (plugin->project_root_directory); g_signal_connect (G_OBJECT (diff_command), "data-arrived", - G_CALLBACK (send_diff_command_output_to_editor), + G_CALLBACK (send_raw_command_output_to_editor), editor); g_signal_connect (G_OBJECT (diff_command), "command_finished", diff --git a/plugins/git/git-diff-command.c b/plugins/git/git-raw-output-command.c similarity index 56% copy from plugins/git/git-diff-command.c copy to plugins/git/git-raw-output-command.c index 0dfb1b39..469d21c4 100644 --- a/plugins/git/git-diff-command.c +++ b/plugins/git/git-raw-output-command.c @@ -22,29 +22,30 @@ * Boston, MA 02110-1301, USA. */ -#include "git-diff-command.h" +#include "git-raw-output-command.h" -struct _GitDiffCommandPriv +struct _GitRawOutputCommandPriv { GQueue *output_queue; }; -G_DEFINE_TYPE (GitDiffCommand, git_diff_command, GIT_TYPE_COMMAND); +G_DEFINE_TYPE (GitRawOutputCommand, git_raw_output_command, GIT_TYPE_COMMAND); static void -git_diff_command_init (GitDiffCommand *self) +git_raw_output_command_init (GitRawOutputCommand *self) { - self->priv = g_new0 (GitDiffCommandPriv, 1); + self->priv = g_new0 (GitRawOutputCommandPriv, 1); self->priv->output_queue = g_queue_new (); } static void -git_diff_command_finalize (GObject *object) +git_raw_output_command_finalize (GObject *object) { - GitDiffCommand *self; + GitRawOutputCommand *self; GList *current_output; - self = GIT_DIFF_COMMAND (object); + self = GIT_RAW_OUTPUT_COMMAND (object); + current_output = self->priv->output_queue->head; while (current_output) @@ -56,55 +57,33 @@ git_diff_command_finalize (GObject *object) g_queue_free (self->priv->output_queue); g_free (self->priv); - G_OBJECT_CLASS (git_diff_command_parent_class)->finalize (object); -} - -static guint -git_diff_command_run (AnjutaCommand *command) -{ - GitDiffCommand *self; - - self = GIT_DIFF_COMMAND (command); - - git_command_add_arg (GIT_COMMAND (self), "diff"); - - return 0; + G_OBJECT_CLASS (git_raw_output_command_parent_class)->finalize (object); } static void -git_diff_command_handle_output (GitCommand *git_command, const gchar *output) +git_raw_output_command_handle_output (GitCommand *git_command, + const gchar *output) { - GitDiffCommand *self; + GitRawOutputCommand *self; - self = GIT_DIFF_COMMAND (git_command); + self = GIT_RAW_OUTPUT_COMMAND (git_command); g_queue_push_tail (self->priv->output_queue, g_strdup (output)); anjuta_command_notify_data_arrived (ANJUTA_COMMAND (git_command)); } static void -git_diff_command_class_init (GitDiffCommandClass *klass) +git_raw_output_command_class_init (GitRawOutputCommandClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); GitCommandClass* parent_class = GIT_COMMAND_CLASS (klass); - AnjutaCommandClass *command_class = ANJUTA_COMMAND_CLASS (klass); - - object_class->finalize = git_diff_command_finalize; - parent_class->output_handler = git_diff_command_handle_output; - command_class->run = git_diff_command_run; -} - -GitDiffCommand * -git_diff_command_new (const gchar *working_directory) -{ - return g_object_new (GIT_TYPE_DIFF_COMMAND, - "working-directory", working_directory, - NULL); + object_class->finalize = git_raw_output_command_finalize; + parent_class->output_handler = git_raw_output_command_handle_output; } GQueue * -git_diff_command_get_output (GitDiffCommand *self) +git_raw_output_command_get_output (GitRawOutputCommand *self) { return self->priv->output_queue; } diff --git a/plugins/git/git-raw-output-command.h b/plugins/git/git-raw-output-command.h new file mode 100644 index 00000000..9115a84c --- /dev/null +++ b/plugins/git/git-raw-output-command.h @@ -0,0 +1,61 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may redistribute it and/or modify it under the terms of the + * GNU General Public License, as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * anjuta is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GIT_RAW_OUTPUT_COMMAND_H_ +#define _GIT_RAW_OUTPUT_COMMAND_H_ + +#include +#include "git-command.h" + +G_BEGIN_DECLS + +#define GIT_TYPE_RAW_OUTPUT_COMMAND (git_raw_output_command_get_type ()) +#define GIT_RAW_OUTPUT_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_RAW_OUTPUT_COMMAND, GitRawOutputCommand)) +#define GIT_RAW_OUTPUT_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_RAW_OUTPUT_COMMAND, GitRawOutputCommandClass)) +#define GIT_IS_RAW_OUTPUT_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_RAW_OUTPUT_COMMAND)) +#define GIT_IS_RAW_OUTPUT_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_RAW_OUTPUT_COMMAND)) +#define GIT_RAW_OUTPUT_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_RAW_OUTPUT_COMMAND, GitRawOutputCommandClass)) + +typedef struct _GitRawOutputCommandClass GitRawOutputCommandClass; +typedef struct _GitRawOutputCommand GitRawOutputCommand; +typedef struct _GitRawOutputCommandPriv GitRawOutputCommandPriv; + +struct _GitRawOutputCommandClass +{ + GitCommandClass parent_class; +}; + +struct _GitRawOutputCommand +{ + GitCommand parent_instance; + + GitRawOutputCommandPriv *priv; +}; + +GType git_raw_output_command_get_type (void) G_GNUC_CONST; +GQueue *git_raw_output_command_get_output (GitRawOutputCommand *self); + +G_END_DECLS + +#endif /* _GIT_RAW_OUTPUT_COMMAND_H_ */ diff --git a/plugins/git/git-ui-utils.c b/plugins/git/git-ui-utils.c index 6c99c7e7..a5197e53 100644 --- a/plugins/git/git-ui-utils.c +++ b/plugins/git/git-ui-utils.c @@ -354,13 +354,13 @@ on_whole_project_toggled (GtkToggleButton* project, Git *plugin) } void -send_diff_command_output_to_editor (AnjutaCommand *command, - IAnjutaEditor *editor) +send_raw_command_output_to_editor (AnjutaCommand *command, + IAnjutaEditor *editor) { GQueue *output; gchar *line; - output = git_diff_command_get_output (GIT_DIFF_COMMAND (command)); + output = git_raw_output_command_get_output (GIT_RAW_OUTPUT_COMMAND (command)); while (g_queue_peek_head (output)) { diff --git a/plugins/git/git-ui-utils.h b/plugins/git/git-ui-utils.h index e572412f..64bd4e5e 100644 --- a/plugins/git/git-ui-utils.h +++ b/plugins/git/git-ui-utils.h @@ -76,8 +76,8 @@ void on_whole_project_toggled (GtkToggleButton* project, Git *plugin); void on_diff_command_finished (AnjutaCommand *command, guint return_code, Git *plugin); -void send_diff_command_output_to_editor (AnjutaCommand *command, - IAnjutaEditor *editor); +void send_raw_command_output_to_editor (AnjutaCommand *command, + IAnjutaEditor *editor); void stop_status_bar_progress_pulse (AnjutaCommand *command, guint return_code, gpointer timer_id); void hide_pulse_progress_bar (AnjutaCommand *command, guint return_code, -- 2.11.4.GIT