From fbc3280d7e50d6153d97c82f059864e5f54b880e Mon Sep 17 00:00:00 2001
From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com>
Date: Fri, 1 Sep 2006 12:37:47 -0500
Subject: [PATCH] Continuing output filter stuff
---
moo/mooedit/Makefile.am | 14 +-
moo/mooedit/language-specs/gvim.styles | 140 ++++++-------------
moo/mooedit/moocmdview.c | 58 +++++++-
moo/mooedit/moocmdview.h | 28 ++--
moo/mooedit/moocommand-exe-private.h | 49 +++++++
moo/mooedit/moocommand-exe-unix.c | 32 ++++-
moo/mooedit/moocommand-exe.h | 24 +---
moo/mooedit/moocommand.c | 133 ++++++++++++++++++
moo/mooedit/moocommand.h | 143 ++++++++++---------
moo/mooedit/moooutputfilter.c | 151 ++++++++++++++++++++-
moo/mooedit/moooutputfilter.h | 44 ++++--
moo/mooedit/moooutputfiltersimple.c | 42 ++++++
moo/mooedit/moooutputfiltersimple.h | 50 +++++++
moo/moopython/pygtk/moocommand.defs | 101 ++++++++++++++
moo/moopython/pygtk/mooedit-pygtk.override | 1 +
15 files changed, 789 insertions(+), 221 deletions(-)
create mode 100644 moo/mooedit/moocommand-exe-private.h
create mode 100644 moo/mooedit/moooutputfiltersimple.c
create mode 100644 moo/mooedit/moooutputfiltersimple.h
diff --git a/moo/mooedit/Makefile.am b/moo/mooedit/Makefile.am
index 42381f48..c6c97888 100644
--- a/moo/mooedit/Makefile.am
+++ b/moo/mooedit/Makefile.am
@@ -4,6 +4,15 @@ SUBDIRS = gtksourceview plugins language-specs
mooedit_toolsdir = $(MOO_DATA_DIR)
mooedit_tools_DATA = context.cfg menu.cfg
+dummy_targets = \
+ moocommand-exe.o \
+ moocommand-exe-private.o
+CLEANFILES = $(dummy_targets)
+moocommand-exe.o: moocommand-exe-unix.o
+ echo stamp > $(@F)
+moocommand-exe-private.o: moocommand-exe-unix.o
+ echo stamp > $(@F)
+
unix_sources = \
moocommand-exe-unix.c
@@ -24,6 +33,7 @@ mooedit_include_headers = \
moolinemark.h \
moolineview.h \
moooutputfilter.h \
+ moooutputfiltersimple.h \
mooplugin-loader.h \
mooplugin-macro.h \
mooplugin.h \
@@ -39,6 +49,7 @@ mooedit_noinst_headers = \
moocommand-exe.h \
moocommand-script.h \
moocommand-private.h \
+ moocommand-exe-private.h \
moocommand.h \
moocommanddisplay.h \
mooedit-private.h \
@@ -104,6 +115,7 @@ mooedit_sources = \
moolinemark.c \
moolineview.c \
moooutputfilter.c \
+ moooutputfiltersimple.c \
mooplugin-loader.c \
mooplugin.c \
mootextbox.c \
@@ -145,7 +157,7 @@ mooedit_enums_headers = \
mootextstyle.h \
mootextview.h
-CLEANFILES = stamp-mooedit-enums.h stamp-mooedit-enums.c mooedit-enums.h mooedit-enums.c
+CLEANFILES += stamp-mooedit-enums.h stamp-mooedit-enums.c mooedit-enums.h mooedit-enums.c
mooedit-enums.h: stamp-mooedit-enums.h
@true
mooedit-enums.c: stamp-mooedit-enums.c
diff --git a/moo/mooedit/language-specs/gvim.styles b/moo/mooedit/language-specs/gvim.styles
index fc12fbe8..c26bfe1f 100644
--- a/moo/mooedit/language-specs/gvim.styles
+++ b/moo/mooedit/language-specs/gvim.styles
@@ -1,112 +1,50 @@
-
+
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
-
diff --git a/moo/mooedit/moocmdview.c b/moo/mooedit/moocmdview.c
index 2af65fa2..08d333ce 100644
--- a/moo/mooedit/moocmdview.c
+++ b/moo/mooedit/moocmdview.c
@@ -23,10 +23,13 @@
struct _MooCmdViewPrivate {
MooCmd *cmd;
+
GtkTextTag *error_tag;
GtkTextTag *message_tag;
GtkTextTag *stdout_tag;
GtkTextTag *stderr_tag;
+
+ MooOutputFilter *filter;
};
static void moo_cmd_view_destroy (GtkObject *object);
@@ -182,6 +185,8 @@ moo_cmd_view_destroy (GtkObject *object)
{
MooCmdView *view = MOO_CMD_VIEW (object);
+ moo_cmd_view_set_filter (view, NULL);
+
if (view->priv->cmd)
{
_moo_cmd_abort (view->priv->cmd);
@@ -201,6 +206,34 @@ moo_cmd_view_new (void)
}
+void
+moo_cmd_view_set_filter (MooCmdView *view,
+ MooOutputFilter *filter)
+{
+ g_return_if_fail (MOO_IS_CMD_VIEW (view));
+ g_return_if_fail (!filter || MOO_IS_OUTPUT_FILTER (filter));
+
+ if (view->priv->filter == filter)
+ return;
+
+ if (view->priv->filter)
+ {
+ moo_output_filter_set_view (view->priv->filter, NULL);
+ g_object_unref (view->priv->filter);
+ view->priv->filter = NULL;
+ }
+
+ view->priv->filter = filter;
+
+ if (view->priv->filter)
+ {
+ g_object_ref (view->priv->filter);
+ moo_output_filter_set_view (view->priv->filter,
+ MOO_LINE_VIEW (view));
+ }
+}
+
+
static gboolean
cmd_exit_cb (MooCmd *cmd,
int status,
@@ -220,7 +253,7 @@ cmd_exit_cb (MooCmd *cmd,
static gboolean
-stdout_text_cb (MooCmd *cmd,
+stdout_line_cb (MooCmd *cmd,
const char *text,
MooCmdView *view)
{
@@ -232,7 +265,7 @@ stdout_text_cb (MooCmd *cmd,
static gboolean
-stderr_text_cb (MooCmd *cmd,
+stderr_line_cb (MooCmd *cmd,
const char *text,
MooCmdView *view)
{
@@ -308,12 +341,15 @@ moo_cmd_view_run_command_full (MooCmdView *view,
}
g_signal_connect (view->priv->cmd, "cmd-exit", G_CALLBACK (cmd_exit_cb), view);
- g_signal_connect (view->priv->cmd, "stdout-text", G_CALLBACK (stdout_text_cb), view);
- g_signal_connect (view->priv->cmd, "stderr-text", G_CALLBACK (stderr_text_cb), view);
+ g_signal_connect (view->priv->cmd, "stdout-line", G_CALLBACK (stdout_line_cb), view);
+ g_signal_connect (view->priv->cmd, "stderr-line", G_CALLBACK (stderr_line_cb), view);
result = TRUE;
g_signal_emit (view, signals[JOB_STARTED], 0, job_name);
+ if (view->priv->filter)
+ moo_output_filter_cmd_start (view->priv->filter);
+
out:
g_strfreev (argv);
return result;
@@ -342,6 +378,9 @@ static gboolean
moo_cmd_view_cmd_exit (MooCmdView *view,
int status)
{
+ if (view->priv->filter && moo_output_filter_cmd_exit (view->priv->filter, status))
+ return TRUE;
+
if (WIFEXITED (status))
{
guint8 exit_code = WEXITSTATUS (status);
@@ -397,6 +436,9 @@ static gboolean
moo_cmd_view_cmd_exit (MooCmdView *view,
int status)
{
+ if (view->priv->filter && moo_output_filter_cmd_exit (view->priv->filter, status))
+ return TRUE;
+
if (!status)
{
moo_line_view_write_line (MOO_LINE_VIEW (view),
@@ -439,8 +481,12 @@ static gboolean
moo_cmd_view_stdout_line (MooCmdView *view,
const char *line)
{
+ if (view->priv->filter && moo_output_filter_stdout_line (view->priv->filter, line))
+ return TRUE;
+
moo_line_view_write_line (MOO_LINE_VIEW (view), line, -1,
view->priv->stdout_tag);
+
return FALSE;
}
@@ -449,7 +495,11 @@ static gboolean
moo_cmd_view_stderr_line (MooCmdView *view,
const char *line)
{
+ if (view->priv->filter && moo_output_filter_stderr_line (view->priv->filter, line))
+ return TRUE;
+
moo_line_view_write_line (MOO_LINE_VIEW (view), line, -1,
view->priv->stderr_tag);
+
return FALSE;
}
diff --git a/moo/mooedit/moocmdview.h b/moo/mooedit/moocmdview.h
index ecad467d..1f846853 100644
--- a/moo/mooedit/moocmdview.h
+++ b/moo/mooedit/moocmdview.h
@@ -15,6 +15,7 @@
#define __MOO_CMD_VIEW__
#include
+#include
G_BEGIN_DECLS
@@ -61,19 +62,22 @@ GType moo_cmd_view_get_type (void) G_GNUC_CONST;
GtkWidget *moo_cmd_view_new (void);
-gboolean moo_cmd_view_run_command (MooCmdView *view,
- const char *cmd,
- const char *working_dir,
- const char *job_name);
-gboolean moo_cmd_view_run_command_full (MooCmdView *view,
- const char *cmd,
- const char *display_cmd,
- const char *working_dir,
- char **envp,
- const char *job_name);
+void moo_cmd_view_set_filter (MooCmdView *view,
+ MooOutputFilter *filter);
-void moo_cmd_view_abort (MooCmdView *view);
-gboolean moo_cmd_view_running (MooCmdView *view);
+gboolean moo_cmd_view_run_command (MooCmdView *view,
+ const char *cmd,
+ const char *working_dir,
+ const char *job_name);
+gboolean moo_cmd_view_run_command_full (MooCmdView *view,
+ const char *cmd,
+ const char *display_cmd,
+ const char *working_dir,
+ char **envp,
+ const char *job_name);
+
+void moo_cmd_view_abort (MooCmdView *view);
+gboolean moo_cmd_view_running (MooCmdView *view);
G_END_DECLS
diff --git a/moo/mooedit/moocommand-exe-private.h b/moo/mooedit/moocommand-exe-private.h
new file mode 100644
index 00000000..edccf2e2
--- /dev/null
+++ b/moo/mooedit/moocommand-exe-private.h
@@ -0,0 +1,49 @@
+/*
+ * moocommand-exe-private.h
+ *
+ * Copyright (C) 2004-2006 by Yevgen Muntyan
+ *
+ * This program is free software; you can 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.
+ *
+ * See COPYING file that comes with this distribution.
+ */
+
+#ifndef __MOO_COMMAND_EXE_PRIVATE_H__
+#define __MOO_COMMAND_EXE_PRIVATE_H__
+
+#include
+
+G_BEGIN_DECLS
+
+
+typedef enum
+{
+ MOO_COMMAND_EXE_INPUT_NONE,
+ MOO_COMMAND_EXE_INPUT_LINES,
+ MOO_COMMAND_EXE_INPUT_SELECTION,
+ MOO_COMMAND_EXE_INPUT_DOC
+} MooCommandExeInput;
+
+typedef enum
+{
+ MOO_COMMAND_EXE_OUTPUT_NONE,
+ MOO_COMMAND_EXE_OUTPUT_NONE_ASYNC,
+ MOO_COMMAND_EXE_OUTPUT_PANE,
+ MOO_COMMAND_EXE_OUTPUT_INSERT,
+ MOO_COMMAND_EXE_OUTPUT_NEW_DOC
+} MooCommandExeOutput;
+
+
+MooCommand *_moo_command_exe_new (const char *exe,
+ MooCommandOptions options,
+ MooCommandExeInput input,
+ MooCommandExeOutput output,
+ const char *output_filter);
+
+
+G_END_DECLS
+
+#endif /* __MOO_COMMAND_EXE_PRIVATE_H__ */
diff --git a/moo/mooedit/moocommand-exe-unix.c b/moo/mooedit/moocommand-exe-unix.c
index 9ae8160b..132a33a7 100644
--- a/moo/mooedit/moocommand-exe-unix.c
+++ b/moo/mooedit/moocommand-exe-unix.c
@@ -12,7 +12,7 @@
*/
#include "config.h"
-#include "mooedit/moocommand-exe.h"
+#include "mooedit/moocommand-exe-private.h"
#include "mooedit/mooeditor.h"
#include "mooedit/mooedittools-glade.h"
#include "mooedit/moocmdview.h"
@@ -36,17 +36,19 @@
enum {
KEY_INPUT,
KEY_OUTPUT,
+ KEY_FILTER,
N_KEYS
};
static const char *data_keys[] = {
- "input", "output", NULL
+ "input", "output", "filter", NULL
};
struct _MooCommandExePrivate {
char *cmd_line;
MooCommandExeInput input;
MooCommandExeOutput output;
+ char *filter;
};
@@ -72,6 +74,7 @@ moo_command_exe_finalize (GObject *object)
{
MooCommandExe *cmd = MOO_COMMAND_EXE (object);
+ g_free (cmd->priv->filter);
g_free (cmd->priv->cmd_line);
G_OBJECT_CLASS (moo_command_exe_parent_class)->finalize (object);
@@ -216,15 +219,23 @@ run_in_pane (MooCommandExe *cmd,
/* XXX */
if (!moo_cmd_view_running (MOO_CMD_VIEW (output)))
{
+ MooOutputFilter *filter;
+
cmd_line = make_cmd (cmd, ctx);
g_return_if_fail (cmd_line != NULL);
moo_line_view_clear (MOO_LINE_VIEW (output));
moo_edit_window_present_output (window);
+
+ filter = cmd->priv->filter ? moo_command_filter_create (cmd->priv->filter) : NULL;
+ moo_cmd_view_set_filter (MOO_CMD_VIEW (output), filter);
+
moo_cmd_view_run_command_full (MOO_CMD_VIEW (output),
cmd_line, cmd->priv->cmd_line,
working_dir, envp, "Command");
+ if (filter)
+ g_object_unref (filter);
g_free (cmd_line);
}
}
@@ -513,6 +524,8 @@ moo_command_exe_class_init (MooCommandExeClass *klass)
type = g_object_new (_moo_command_type_exe_get_type (), NULL);
moo_command_type_register ("exe", _("Shell command"), type, (char**) data_keys);
g_object_unref (type);
+
+// moo_command_filter_register ("something", _("Something"), SOME_TYPE);
}
@@ -595,7 +608,10 @@ exe_type_create_command (G_GNUC_UNUSED MooCommandType *type,
if (!parse_output (moo_command_data_get (data, KEY_OUTPUT), &output))
g_return_val_if_reached (NULL);
- cmd = moo_command_exe_new (cmd_line, moo_command_options_parse (options), input, output);
+ cmd = _moo_command_exe_new (cmd_line,
+ moo_command_options_parse (options),
+ input, output,
+ moo_command_data_get (data, KEY_FILTER));
g_return_val_if_fail (cmd != NULL, NULL);
return cmd;
@@ -767,10 +783,11 @@ _moo_command_type_exe_class_init (MooCommandTypeExeClass *klass)
MooCommand *
-moo_command_exe_new (const char *cmd_line,
- MooCommandOptions options,
- MooCommandExeInput input,
- MooCommandExeInput output)
+_moo_command_exe_new (const char *cmd_line,
+ MooCommandOptions options,
+ MooCommandExeInput input,
+ MooCommandExeOutput output,
+ const char *filter)
{
MooCommandExe *cmd;
@@ -783,6 +800,7 @@ moo_command_exe_new (const char *cmd_line,
cmd->priv->cmd_line = g_strdup (cmd_line);
cmd->priv->input = input;
cmd->priv->output = output;
+ cmd->priv->filter = g_strdup (filter);
return MOO_COMMAND (cmd);
}
diff --git a/moo/mooedit/moocommand-exe.h b/moo/mooedit/moocommand-exe.h
index 6eb28d93..1a7c94d2 100644
--- a/moo/mooedit/moocommand-exe.h
+++ b/moo/mooedit/moocommand-exe.h
@@ -30,23 +30,6 @@ typedef struct _MooCommandExe MooCommandExe;
typedef struct _MooCommandExePrivate MooCommandExePrivate;
typedef struct _MooCommandExeClass MooCommandExeClass;
-typedef enum
-{
- MOO_COMMAND_EXE_INPUT_NONE,
- MOO_COMMAND_EXE_INPUT_LINES,
- MOO_COMMAND_EXE_INPUT_SELECTION,
- MOO_COMMAND_EXE_INPUT_DOC
-} MooCommandExeInput;
-
-typedef enum
-{
- MOO_COMMAND_EXE_OUTPUT_NONE,
- MOO_COMMAND_EXE_OUTPUT_NONE_ASYNC,
- MOO_COMMAND_EXE_OUTPUT_PANE,
- MOO_COMMAND_EXE_OUTPUT_INSERT,
- MOO_COMMAND_EXE_OUTPUT_NEW_DOC
-} MooCommandExeOutput;
-
struct _MooCommandExe {
MooCommand base;
MooCommandExePrivate *priv;
@@ -57,12 +40,7 @@ struct _MooCommandExeClass {
};
-GType moo_command_exe_get_type (void) G_GNUC_CONST;
-
-MooCommand *moo_command_exe_new (const char *exe,
- MooCommandOptions options,
- MooCommandExeInput input,
- MooCommandExeInput output);
+GType moo_command_exe_get_type (void) G_GNUC_CONST;
G_END_DECLS
diff --git a/moo/mooedit/moocommand.c b/moo/mooedit/moocommand.c
index 31657a78..9d6c6d70 100644
--- a/moo/mooedit/moocommand.c
+++ b/moo/mooedit/moocommand.c
@@ -16,6 +16,7 @@
#include "mooedit/moocommand-script.h"
#include "mooedit/moocommand-exe.h"
#include "mooedit/mooeditwindow.h"
+#include "mooedit/moooutputfiltersimple.h"
#include "mooedit/mooedit-enums.h"
#include
#include
@@ -58,8 +59,16 @@ struct _MooCommandData {
char *code;
};
+typedef struct {
+ char *name;
+ MooCommandFilterFactory factory_func;
+ gpointer data;
+ GDestroyNotify data_notify;
+} FilterInfo;
+
static GHashTable *registered_types;
+static GHashTable *registered_filters;
static Variable *variable_new (const GValue *value);
@@ -1087,6 +1096,130 @@ _moo_command_init (void)
#ifndef __WIN32__
g_type_class_unref (g_type_class_ref (MOO_TYPE_COMMAND_EXE));
#endif
+ _moo_command_filter_simple_init ();
been_here = TRUE;
}
}
+
+
+static void
+filters_init (void)
+{
+ if (!registered_filters)
+ registered_filters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+}
+
+
+static FilterInfo *
+filter_lookup (const char *id)
+{
+ g_return_val_if_fail (id != NULL, NULL);
+
+ if (registered_filters)
+ return g_hash_table_lookup (registered_filters, id);
+ else
+ return NULL;
+}
+
+
+void
+moo_command_filter_register (const char *id,
+ const char *name,
+ MooCommandFilterFactory factory_func,
+ gpointer data,
+ GDestroyNotify data_notify)
+{
+ FilterInfo *info;
+
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (name != NULL);
+ g_return_if_fail (factory_func != NULL);
+
+ filters_init ();
+
+ if (filter_lookup (id))
+ {
+ g_message ("reregistering filter '%s'", id);
+ moo_command_filter_unregister (id);
+ }
+
+ info = g_new0 (FilterInfo, 1);
+ info->name = g_strdup (name);
+ info->factory_func = factory_func;
+ info->data = data;
+ info->data_notify = data_notify;
+
+ g_hash_table_insert (registered_filters, g_strdup (id), info);
+}
+
+
+void
+moo_command_filter_unregister (const char *id)
+{
+ FilterInfo *info;
+
+ g_return_if_fail (id != NULL);
+
+ info = filter_lookup (id);
+
+ if (!info)
+ {
+ g_warning ("filter '%s' not registered", id);
+ return;
+ }
+
+ g_hash_table_remove (registered_filters, id);
+
+ if (info->data_notify)
+ info->data_notify (info->data);
+
+ g_free (info->name);
+ g_free (info);
+}
+
+
+const char *
+moo_command_filter_lookup (const char *id)
+{
+ FilterInfo *info;
+
+ g_return_val_if_fail (id != NULL, 0);
+
+ info = filter_lookup (id);
+
+ return info ? info->name : NULL;
+}
+
+
+static void
+prepend_filter_id (const char *id,
+ G_GNUC_UNUSED gpointer info,
+ GSList **list)
+{
+ *list = g_slist_prepend (*list, g_strdup (id));
+}
+
+GSList *
+moo_command_filter_list (void)
+{
+ GSList *list = NULL;
+
+ if (registered_filters)
+ g_hash_table_foreach (registered_filters, (GHFunc) prepend_filter_id, &list);
+
+ return list;
+}
+
+
+MooOutputFilter *
+moo_command_filter_create (const char *id)
+{
+ FilterInfo *info;
+
+ g_return_val_if_fail (id != NULL, NULL);
+
+ info = filter_lookup (id);
+ g_return_val_if_fail (info != NULL, NULL);
+
+ return info->factory_func (id, info->data);
+}
diff --git a/moo/mooedit/moocommand.h b/moo/mooedit/moocommand.h
index 4de3318f..fb5c7dda 100644
--- a/moo/mooedit/moocommand.h
+++ b/moo/mooedit/moocommand.h
@@ -15,6 +15,7 @@
#define __MOO_COMMAND_H__
#include
+#include
G_BEGIN_DECLS
@@ -112,83 +113,99 @@ struct _MooCommandTypeClass {
};
-GType moo_command_get_type (void) G_GNUC_CONST;
-GType moo_command_context_get_type(void) G_GNUC_CONST;
-GType moo_command_data_get_type (void) G_GNUC_CONST;
-GType moo_command_type_get_type (void) G_GNUC_CONST;
+GType moo_command_get_type (void) G_GNUC_CONST;
+GType moo_command_context_get_type (void) G_GNUC_CONST;
+GType moo_command_data_get_type (void) G_GNUC_CONST;
+GType moo_command_type_get_type (void) G_GNUC_CONST;
-MooCommand *moo_command_create (const char *name,
- const char *options,
- MooCommandData *data);
+MooCommand *moo_command_create (const char *name,
+ const char *options,
+ MooCommandData *data);
-void moo_command_run (MooCommand *cmd,
- MooCommandContext *ctx);
-gboolean moo_command_check_context (MooCommand *cmd,
- MooCommandContext *ctx);
-gboolean moo_command_check_sensitive (MooCommand *cmd,
- gpointer doc,
- gpointer window);
+void moo_command_run (MooCommand *cmd,
+ MooCommandContext *ctx);
+gboolean moo_command_check_context (MooCommand *cmd,
+ MooCommandContext *ctx);
+gboolean moo_command_check_sensitive (MooCommand *cmd,
+ gpointer doc,
+ gpointer window);
-void moo_command_set_options (MooCommand *cmd,
- MooCommandOptions options);
-MooCommandOptions moo_command_get_options (MooCommand *cmd);
+void moo_command_set_options (MooCommand *cmd,
+ MooCommandOptions options);
+MooCommandOptions moo_command_get_options (MooCommand *cmd);
-MooCommandOptions moo_command_options_parse (const char *string);
+MooCommandOptions moo_command_options_parse (const char *string);
-void moo_command_type_register (const char *name,
- const char *display_name,
- MooCommandType *type,
- char **data_keys);
-MooCommandType *moo_command_type_lookup (const char *name);
+void moo_command_type_register (const char *name,
+ const char *display_name,
+ MooCommandType *type,
+ char **data_keys);
+MooCommandType *moo_command_type_lookup (const char *name);
/* returns list of MooCommandType instances, list should be freed */
-GSList *moo_command_list_types (void);
+GSList *moo_command_list_types (void);
-MooCommandData *moo_command_data_new (guint len);
+MooCommandData *moo_command_data_new (guint len);
-MooCommandData *moo_command_data_ref (MooCommandData *data);
-void moo_command_data_unref (MooCommandData *data);
-void moo_command_data_set (MooCommandData *data,
- guint index_,
- const char *value);
-void moo_command_data_set_code (MooCommandData *data,
- const char *code);
-const char *moo_command_data_get (MooCommandData *data,
- guint index_);
-const char *moo_command_data_get_code (MooCommandData *data);
-void moo_command_data_clear (MooCommandData *data);
+MooCommandData *moo_command_data_ref (MooCommandData *data);
+void moo_command_data_unref (MooCommandData *data);
+void moo_command_data_set (MooCommandData *data,
+ guint index_,
+ const char *value);
+void moo_command_data_set_code (MooCommandData *data,
+ const char *code);
+const char *moo_command_data_get (MooCommandData *data,
+ guint index_);
+const char *moo_command_data_get_code (MooCommandData *data);
+void moo_command_data_clear (MooCommandData *data);
-MooCommandContext *moo_command_context_new (gpointer doc,
- gpointer window);
+MooCommandContext *moo_command_context_new (gpointer doc,
+ gpointer window);
-void moo_command_context_set_doc (MooCommandContext *ctx,
- gpointer doc);
-void moo_command_context_set_window (MooCommandContext *ctx,
- gpointer window);
-gpointer moo_command_context_get_doc (MooCommandContext *ctx);
-gpointer moo_command_context_get_window (MooCommandContext *ctx);
+void moo_command_context_set_doc (MooCommandContext *ctx,
+ gpointer doc);
+void moo_command_context_set_window (MooCommandContext *ctx,
+ gpointer window);
+gpointer moo_command_context_get_doc (MooCommandContext *ctx);
+gpointer moo_command_context_get_window (MooCommandContext *ctx);
-void moo_command_context_set (MooCommandContext *ctx,
- const char *name,
- const GValue *value);
-gboolean moo_command_context_get (MooCommandContext *ctx,
- const char *name,
- GValue *value);
-void moo_command_context_unset (MooCommandContext *ctx,
- const char *name);
-void moo_command_context_set_string (MooCommandContext *ctx,
- const char *name,
- const char *value);
-const char *moo_command_context_get_string (MooCommandContext *ctx,
- const char *name);
+void moo_command_context_set (MooCommandContext *ctx,
+ const char *name,
+ const GValue *value);
+gboolean moo_command_context_get (MooCommandContext *ctx,
+ const char *name,
+ GValue *value);
+void moo_command_context_unset (MooCommandContext *ctx,
+ const char *name);
+void moo_command_context_set_string (MooCommandContext *ctx,
+ const char *name,
+ const char *value);
+const char *moo_command_context_get_string (MooCommandContext *ctx,
+ const char *name);
-typedef void (*MooCommandContextForeachFunc) (const char *name,
- const GValue *value,
- gpointer data);
-void moo_command_context_foreach (MooCommandContext *ctx,
- MooCommandContextForeachFunc func,
- gpointer data);
+typedef void (*MooCommandContextForeachFunc) (const char *name,
+ const GValue *value,
+ gpointer data);
+void moo_command_context_foreach (MooCommandContext *ctx,
+ MooCommandContextForeachFunc func,
+ gpointer data);
+
+
+typedef MooOutputFilter *(*MooCommandFilterFactory) (const char *id,
+ gpointer data);
+
+void moo_command_filter_register (const char *id,
+ const char *name,
+ MooCommandFilterFactory factory_func,
+ gpointer data,
+ GDestroyNotify data_notify);
+void moo_command_filter_unregister (const char *id);
+/* returns name */
+const char *moo_command_filter_lookup (const char *id);
+/* list of ids, must be freed together with content */
+GSList *moo_command_filter_list (void);
+MooOutputFilter *moo_command_filter_create (const char *id);
G_END_DECLS
diff --git a/moo/mooedit/moooutputfilter.c b/moo/mooedit/moooutputfilter.c
index 1df2cc51..79b7ae75 100644
--- a/moo/mooedit/moooutputfilter.c
+++ b/moo/mooedit/moooutputfilter.c
@@ -12,14 +12,64 @@
*/
#include "mooedit/moooutputfilter.h"
+#include "mooutils/moomarshals.h"
+#include
G_DEFINE_TYPE (MooOutputFilter, moo_output_filter, G_TYPE_OBJECT)
+enum {
+ STDOUT_LINE,
+ STDERR_LINE,
+ CMD_START,
+ CMD_EXIT,
+ N_SIGNALS
+};
+
+static guint signals[N_SIGNALS];
+
static void
-moo_output_filter_class_init (G_GNUC_UNUSED MooOutputFilterClass *klass)
+moo_output_filter_class_init (MooOutputFilterClass *klass)
{
+ signals[STDOUT_LINE] =
+ g_signal_new ("stdout-line",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (MooOutputFilterClass, stdout_line),
+ g_signal_accumulator_true_handled, NULL,
+ _moo_marshal_BOOL__STRING,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+ signals[STDERR_LINE] =
+ g_signal_new ("stderr-line",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (MooOutputFilterClass, stderr_line),
+ g_signal_accumulator_true_handled, NULL,
+ _moo_marshal_BOOL__STRING,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+ signals[CMD_START] =
+ g_signal_new ("cmd-start",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (MooOutputFilterClass, cmd_start),
+ g_signal_accumulator_true_handled, NULL,
+ _moo_marshal_BOOL__VOID,
+ G_TYPE_BOOLEAN, 0);
+
+ signals[CMD_EXIT] =
+ g_signal_new ("cmd-exit",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (MooOutputFilterClass, cmd_exit),
+ g_signal_accumulator_true_handled, NULL,
+ _moo_marshal_BOOL__INT,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_INT);
}
@@ -27,3 +77,102 @@ static void
moo_output_filter_init (G_GNUC_UNUSED MooOutputFilter *cmd)
{
}
+
+
+void
+moo_output_filter_set_view (MooOutputFilter *filter,
+ MooLineView *view)
+{
+ g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter));
+ g_return_if_fail (!view || MOO_IS_LINE_VIEW (view));
+
+ if (filter->view == view)
+ return;
+
+ if (filter->view)
+ {
+ if (MOO_OUTPUT_FILTER_GET_CLASS (filter)->detach)
+ MOO_OUTPUT_FILTER_GET_CLASS (filter)->detach (filter);
+ }
+
+ filter->view = view;
+
+ if (view)
+ {
+ if (MOO_OUTPUT_FILTER_GET_CLASS (filter)->attach)
+ MOO_OUTPUT_FILTER_GET_CLASS (filter)->attach (filter);
+ }
+}
+
+
+MooLineView *
+moo_output_filter_get_view (MooOutputFilter *filter)
+{
+ g_return_val_if_fail (MOO_IS_OUTPUT_FILTER (filter), NULL);
+ return filter->view;
+}
+
+
+static gboolean
+moo_output_filter_output_line (MooOutputFilter *filter,
+ const char *line,
+ guint sig)
+{
+ gboolean result = FALSE;
+
+ if (line[strlen(line) - 1] == '\n')
+ g_warning ("%s: oops", G_STRLOC);
+
+ g_signal_emit (filter, signals[sig], 0, line, &result);
+
+ return result;
+}
+
+
+gboolean
+moo_output_filter_stdout_line (MooOutputFilter *filter,
+ const char *line)
+{
+ g_return_val_if_fail (MOO_IS_OUTPUT_FILTER (filter), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
+ return moo_output_filter_output_line (filter, line, STDOUT_LINE);
+}
+
+
+gboolean
+moo_output_filter_stderr_line (MooOutputFilter *filter,
+ const char *line)
+{
+ g_return_val_if_fail (MOO_IS_OUTPUT_FILTER (filter), FALSE);
+ g_return_val_if_fail (line != NULL, FALSE);
+ return moo_output_filter_output_line (filter, line, STDERR_LINE);
+}
+
+
+void
+moo_output_filter_cmd_start (MooOutputFilter *filter)
+{
+ g_return_if_fail (MOO_IS_OUTPUT_FILTER (filter));
+ g_signal_emit (filter, signals[CMD_START], 0);
+}
+
+
+gboolean
+moo_output_filter_cmd_exit (MooOutputFilter *filter,
+ int status)
+{
+ gboolean result = FALSE;
+
+ g_return_val_if_fail (MOO_IS_OUTPUT_FILTER (filter), FALSE);
+
+ g_signal_emit (filter, signals[CMD_EXIT], 0, status, &result);
+
+ return result;
+}
+
+
+MooOutputFilter *
+moo_output_filter_new (void)
+{
+ return g_object_new (MOO_TYPE_OUTPUT_FILTER, NULL);
+}
diff --git a/moo/mooedit/moooutputfilter.h b/moo/mooedit/moooutputfilter.h
index 897c637e..23c58eb0 100644
--- a/moo/mooedit/moooutputfilter.h
+++ b/moo/mooedit/moooutputfilter.h
@@ -19,26 +19,52 @@
G_BEGIN_DECLS
-#define MOO_TYPE_OUTPUT_FILTER (moo_output_filter_get_type ())
-#define MOO_OUTPUT_FILTER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_OUTPUT_FILTER, MooOutputFilter))
-#define MOO_OUTPUT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_OUTPUT_FILTER, MooOutputFilterClass))
-#define MOO_IS_OUTPUT_FILTER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_OUTPUT_FILTER))
-#define MOO_IS_OUTPUT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_OUTPUT_FILTER))
-#define MOO_OUTPUT_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_OUTPUT_FILTER, MooOutputFilterClass))
+#define MOO_TYPE_OUTPUT_FILTER (moo_output_filter_get_type ())
+#define MOO_OUTPUT_FILTER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_OUTPUT_FILTER, MooOutputFilter))
+#define MOO_OUTPUT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_OUTPUT_FILTER, MooOutputFilterClass))
+#define MOO_IS_OUTPUT_FILTER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_OUTPUT_FILTER))
+#define MOO_IS_OUTPUT_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_OUTPUT_FILTER))
+#define MOO_OUTPUT_FILTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_OUTPUT_FILTER, MooOutputFilterClass))
-typedef struct _MooOutputFilter MooOutputFilter;
-typedef struct _MooOutputFilterClass MooOutputFilterClass;
+typedef struct _MooOutputFilter MooOutputFilter;
+typedef struct _MooOutputFilterClass MooOutputFilterClass;
struct _MooOutputFilter {
GObject base;
+ MooLineView *view;
};
struct _MooOutputFilterClass {
GObjectClass base_class;
+
+ void (*attach) (MooOutputFilter *filter);
+ void (*detach) (MooOutputFilter *filter);
+
+ void (*cmd_start) (MooOutputFilter *filter);
+ gboolean (*cmd_exit) (MooOutputFilter *filter,
+ int status);
+ gboolean (*stdout_line) (MooOutputFilter *filter,
+ const char *line);
+ gboolean (*stderr_line) (MooOutputFilter *filter,
+ const char *line);
};
-GType moo_output_filter_get_type (void) G_GNUC_CONST;
+GType moo_output_filter_get_type (void) G_GNUC_CONST;
+
+MooOutputFilter *moo_output_filter_new (void);
+
+void moo_output_filter_set_view (MooOutputFilter *filter,
+ MooLineView *view);
+MooLineView *moo_output_filter_get_view (MooOutputFilter *filter);
+
+gboolean moo_output_filter_stdout_line (MooOutputFilter *filter,
+ const char *line);
+gboolean moo_output_filter_stderr_line (MooOutputFilter *filter,
+ const char *line);
+void moo_output_filter_cmd_start (MooOutputFilter *filter);
+gboolean moo_output_filter_cmd_exit (MooOutputFilter *filter,
+ int status);
G_END_DECLS
diff --git a/moo/mooedit/moooutputfiltersimple.c b/moo/mooedit/moooutputfiltersimple.c
new file mode 100644
index 00000000..b688dfc3
--- /dev/null
+++ b/moo/mooedit/moooutputfiltersimple.c
@@ -0,0 +1,42 @@
+/*
+ * moooutputfiltersimple.c
+ *
+ * Copyright (C) 2004-2006 by Yevgen Muntyan
+ *
+ * This program is free software; you can 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.
+ *
+ * See COPYING file that comes with this distribution.
+ */
+
+#include "mooedit/moooutputfiltersimple.h"
+#include
+
+
+G_DEFINE_TYPE (MooOutputFilterSimple, moo_output_filter_simple, G_TYPE_OBJECT)
+
+
+static void
+moo_output_filter_simple_class_init (G_GNUC_UNUSED MooOutputFilterSimpleClass *klass)
+{
+}
+
+
+static void
+moo_output_filter_simple_init (G_GNUC_UNUSED MooOutputFilterSimple *filter)
+{
+}
+
+
+void
+_moo_command_filter_simple_init (void)
+{
+ static gboolean been_here = FALSE;
+
+ if (been_here)
+ return;
+
+ been_here = TRUE;
+}
diff --git a/moo/mooedit/moooutputfiltersimple.h b/moo/mooedit/moooutputfiltersimple.h
new file mode 100644
index 00000000..f93b5fd4
--- /dev/null
+++ b/moo/mooedit/moooutputfiltersimple.h
@@ -0,0 +1,50 @@
+/*
+ * moooutputfiltersimple.h
+ *
+ * Copyright (C) 2004-2006 by Yevgen Muntyan
+ *
+ * This program is free software; you can 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.
+ *
+ * See COPYING file that comes with this distribution.
+ */
+
+#ifndef __MOO_OUTPUT_FILTER_SIMPLE_SIMPLE_H__
+#define __MOO_OUTPUT_FILTER_SIMPLE_SIMPLE_H__
+
+#include
+
+G_BEGIN_DECLS
+
+
+#define MOO_TYPE_OUTPUT_FILTER_SIMPLE (moo_output_filter_simple_get_type ())
+#define MOO_OUTPUT_FILTER_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_OUTPUT_FILTER_SIMPLE, MooOutputFilterSimple))
+#define MOO_OUTPUT_FILTER_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_OUTPUT_FILTER_SIMPLE, MooOutputFilterSimpleClass))
+#define MOO_IS_OUTPUT_FILTER_SIMPLE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_OUTPUT_FILTER_SIMPLE))
+#define MOO_IS_OUTPUT_FILTER_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_OUTPUT_FILTER_SIMPLE))
+#define MOO_OUTPUT_FILTER_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_OUTPUT_FILTER_SIMPLE, MooOutputFilterSimpleClass))
+
+typedef struct _MooOutputFilterSimple MooOutputFilterSimple;
+typedef struct _MooOutputFilterSimplePrivate MooOutputFilterSimplePrivate;
+typedef struct _MooOutputFilterSimpleClass MooOutputFilterSimpleClass;
+
+struct _MooOutputFilterSimple {
+ MooOutputFilter base;
+ MooOutputFilterSimplePrivate *priv;
+};
+
+struct _MooOutputFilterSimpleClass {
+ MooOutputFilterClass base_class;
+};
+
+
+GType moo_output_filter_simple_get_type (void) G_GNUC_CONST;
+
+void _moo_command_filter_simple_init (void);
+
+
+G_END_DECLS
+
+#endif /* __MOO_OUTPUT_FILTER_SIMPLE_SIMPLE_H__ */
diff --git a/moo/moopython/pygtk/moocommand.defs b/moo/moopython/pygtk/moocommand.defs
index c767926f..6bc1725a 100644
--- a/moo/moopython/pygtk/moocommand.defs
+++ b/moo/moopython/pygtk/moocommand.defs
@@ -267,3 +267,104 @@
(c-name "moo_command_data_get_code")
(return-type "const-char*")
)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; MooOutputFilter
+;;
+
+(define-object OutputFilter
+ (in-module "Moo")
+ (parent "GObject")
+ (c-name "MooOutputFilter")
+ (gtype-id "MOO_TYPE_OUTPUT_FILTER")
+ (fields
+ '("MooLineView*" "view")
+ )
+)
+
+(define-virtual attach
+ (of-object "MooOutputFilter")
+ (return-type "none")
+)
+
+(define-virtual detach
+ (of-object "MooOutputFilter")
+ (return-type "none")
+)
+
+(define-virtual stdout_line
+ (of-object "MooOutputFilter")
+ (return-type "gboolean")
+ (parameters
+ '("const-char*" "line")
+ )
+)
+
+(define-virtual stderr_line
+ (of-object "MooOutputFilter")
+ (return-type "gboolean")
+ (parameters
+ '("const-char*" "line")
+ )
+)
+
+(define-virtual cmd_start
+ (of-object "MooOutputFilter")
+ (return-type "none")
+)
+
+(define-virtual cmd_exit
+ (of-object "MooOutputFilter")
+ (return-type "gboolean")
+ (parameters
+ '("int" "status")
+ )
+)
+
+(define-method set_view
+ (of-object "MooOutputFilter")
+ (c-name "moo_output_filter_set_view")
+ (return-type "none")
+ (parameters
+ '("MooLineView*" "view" (null-ok))
+ )
+)
+
+(define-method get_view
+ (of-object "MooOutputFilter")
+ (c-name "moo_output_filter_get_view")
+ (return-type "MooLineView*")
+)
+
+(define-method stdout_line
+ (of-object "MooOutputFilter")
+ (c-name "moo_output_filter_stdout_line")
+ (return-type "gboolean")
+ (parameters
+ '("const-char*" "line")
+ )
+)
+
+(define-method stderr_line
+ (of-object "MooOutputFilter")
+ (c-name "moo_output_filter_stderr_line")
+ (return-type "gboolean")
+ (parameters
+ '("const-char*" "line")
+ )
+)
+
+(define-method cmd_start
+ (of-object "MooOutputFilter")
+ (c-name "moo_output_filter_cmd_start")
+ (return-type "none")
+)
+
+(define-method cmd_exit
+ (of-object "MooOutputFilter")
+ (c-name "moo_output_filter_cmd_exit")
+ (return-type "gboolean")
+ (parameters
+ '("int" "status")
+ )
+)
diff --git a/moo/moopython/pygtk/mooedit-pygtk.override b/moo/moopython/pygtk/mooedit-pygtk.override
index 2a7d247e..707685d9 100644
--- a/moo/moopython/pygtk/mooedit-pygtk.override
+++ b/moo/moopython/pygtk/mooedit-pygtk.override
@@ -14,6 +14,7 @@ headers
#include "mooedit/mooplugin.h"
#include "mooedit/moocommand.h"
#include "mooedit/mooedit-enums.h"
+#include "mooedit/moooutputfilter.h"
#include "moopython/moopython-utils.h"
#include "moopython/pygtk/moo-pygtk.h"