Continuing output filter stuff

master
Yevgen Muntyan 2006-09-01 12:37:47 -05:00
parent 9507592658
commit fbc3280d7e
15 changed files with 789 additions and 221 deletions

View File

@ -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

View File

@ -1,112 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<style-scheme id="gvim" _name="GVim">
<style name="bracket-match" foreground="white" background="grey" bold="true"/>
<style name="bracket-match" foreground="white" background="grey" bold="true"/>
<style name="bracket-mismatch" foreground="white" background="red" bold="true"/>
<style name="Others" foreground="#2E8B57" bold="true"/>
<style name="Others 2" foreground="#008B8B"/>
<style name="Others 3" foreground="#6A5ACD"/>
<!-- legacy styles for old lang files -->
<style name="Others" foreground="#2E8B57" bold="true"/>
<style name="Others 2" foreground="#008B8B"/>
<style name="Others 3" foreground="#6A5ACD"/>
<style name="def:base-n-integer" foreground="#FF00FF"/>
<style name="def:character" foreground="#FF00FF"/>
<style name="def:comment" foreground="#0000FF"/>
<style name="def:data-type" foreground="#2E8B57" bold="true"/>
<style name="def:function" foreground="#008A8C"/>
<style name="def:decimal" foreground="#FF00FF"/>
<style name="def:floating-point" foreground="#FF00FF"/>
<style name="def:keyword" foreground="#A52A2A" bold="true"/>
<style name="def:string" foreground="#FF00FF"/>
<style name="def:specials" foreground="#FFFFFF" background="#FF0000"/>
<!-- <style name="def:others" foreground="#2E8B57" bold="true"/>-->
<!-- <style name="def:others2" foreground="#008B8B"/>-->
<!-- <style name="def:others3" foreground="#6A5ACD"/>-->
<style name="def:net-address-in-comment" foreground="#0000FF" italic="true" underline="true"/>
<style name="def:note" foreground="#0000FF" background="#FFFF00" bold="true"/>
<style name="def:error" background="#FF0000" bold="true"/>
<!-- <style name="def:package" foreground="#FF00FF" bold="true"/>-->
<style name="def:escape" foreground="#9010D0"/>
<style name="def:shebang" foreground="#0000FF" bold="true"/>
<style name="def:base-n-integer" foreground="#FF00FF"/>
<style name="def:character" foreground="#FF00FF"/>
<style name="def:comment" foreground="#0000FF"/>
<style name="def:data-type" foreground="#2E8B57" bold="true"/>
<style name="def:function" foreground="#008A8C"/>
<style name="def:decimal" foreground="#FF00FF"/>
<style name="def:floating-point" foreground="#FF00FF"/>
<style name="def:keyword" foreground="#A52A2A" bold="true"/>
<style name="def:string" foreground="#FF00FF"/>
<style name="def:specials" foreground="#FFFFFF" background="#FF0000"/>
<style name="def:net-address-in-comment" foreground="#0000FF" italic="true" underline="true"/>
<style name="def:note" foreground="#0000FF" background="#FFFF00" bold="true"/>
<style name="def:error" background="#FF0000" bold="true"/>
<style name="def:escape" foreground="#9010D0"/>
<style name="def:shebang" foreground="#0000FF" bold="true"/>
<style name="c:preprocessor" foreground="#A020F0"/>
<style name="c:preprocessor" foreground="#A020F0"/>
<style name="diff:added-line" use-style="Others 2"/>
<style name="diff:removed-line" use-style="Others 3"/>
<style name="diff:changed-line" use-style="c:preprocessor"/>
<style name="diff:special-case" use-style="def:string"/>
<style name="diff:location" use-style="def:keyword"/>
<style name="diff:diff-file" use-style="def:data-type"/>
<style name="diff:added-line" use-style="Others 2"/>
<style name="diff:removed-line" use-style="Others 3"/>
<style name="diff:changed-line" use-style="c:preprocessor"/>
<style name="diff:special-case" use-style="def:string"/>
<style name="diff:location" use-style="def:keyword"/>
<style name="diff:diff-file" use-style="def:data-type"/>
<style name="xml:attribute-name" foreground="#6A5ACD"/>
<style name="xml:tags" foreground="#008B8B"/>
<style name="xml:namespace" foreground="#2E8B57" bold="true"/>
<style name="xml:doctype" use-style="c:preprocessor"/>
<style name="xml:cdata-delim" use-style="c:preprocessor"/>
<style name="xml:processing-instruction" use-style="c:preprocessor"/>
<style name="xml:attribute-name" foreground="#6A5ACD"/>
<style name="xml:tags" foreground="#008B8B"/>
<style name="xml:namespace" foreground="#2E8B57" bold="true"/>
<style name="xml:doctype" use-style="c:preprocessor"/>
<style name="xml:cdata-delim" use-style="c:preprocessor"/>
<style name="xml:processing-instruction" use-style="c:preprocessor"/>
<style name="js:object" foreground="#2E8B57" bold="true"/>
<style name="js:constructors" foreground="#008B8B"/>
<style name="js:object" foreground="#2E8B57" bold="true"/>
<style name="js:constructors" foreground="#008B8B"/>
<style name="latex:command" foreground="#2E8B57" bold="true"/>
<style name="latex:command" foreground="#2E8B57" bold="true"/>
<style name="python:builtins" use-style="Others"/>
<style name="changelog:email" use-style="def:comment"/>
<style name="python:builtins" use-style="Others"/>
<style name="changelog:email" use-style="def:comment"/>
</style-scheme>
<!--
css.lang
<pattern-item _name="Unicode Character Reference" style="Others 2">
<pattern-item _name="Punctuators" style="Others 3">
<pattern-item _name="Attribute Value Delimiters" style="Others 2">
<pattern-item _name="Selector Grammar" style="Others 3">
<pattern-item _name="Unicode Range" style="Others 2">
diff.lang
<pattern-item _name="Removed line" style="Others 3">
<pattern-item _name="Added line" style="Others 2">
javascript.lang
<style id="object" _name="Object"
map-to="def:others"/>
<style id="constructors" _name="Constructors"
map-to="def:others2"/>
latex.lang
<style id="command" _name="Keyword"
map-to="def:others"/>
makefile.lang
<keyword-list _name = "Variable1" style = "Others 3" match-empty-string-at-beginning = "FALSE" match-empty-string-at-end = "FALSE">
<keyword-list _name = "Variable2" style = "Others 2" match-empty-string-at-beginning = "FALSE" match-empty-string-at-end = "FALSE">
msil.lang
<keyword-list name="Reserved Words - Group #1" style="Others" case-sensitive="TRUE">
<keyword-list name="Reserved Words - Group #2" style="Others" case-sensitive="TRUE">
perl.lang
<pattern-item _name = "Function Call" style = "Others">
<pattern-item _name = "Method Call" style = "Others">
php.lang
<pattern-item _name = "First Open PHP Tag" style = "Others">
<block-comment _name = "HTML Block" style = "Others">
po.lang
<line-comment _name = "Location" style= "Others 2">
python.lang
<keyword-list _name = "Builtins" style = "Others" case-sensitive="TRUE">
<style name="python:builtins" use-style="c:preprocessor"/>
R.lang
<pattern-item _name="Delimiter" style="Others 3">
ruby.lang
<keyword-list _name="Attribute Definitions" style="Others" case-sensitive="TRUE">
<keyword-list _name = "Builtins" style = "Others" case-sensitive="TRUE">
scheme.lang
<keyword-list _name="Function" style="Others"
sh.lang
<pattern-item _name = "Punctuator" style = "Others">
<keyword-list _name = "Redirection" style = "Others" match-empty-string-at-beginning = "FALSE" match-empty-string-at-end = "FALSE">
<keyword-list _name = "Variable1" style = "Others 3" match-empty-string-at-beginning = "FALSE" match-empty-string-at-end = "FALSE">
<keyword-list _name = "Variable2" style = "Others 2" match-empty-string-at-beginning = "FALSE" match-empty-string-at-end = "FALSE">
<keyword-list _name = "Common Command" style = "Others" case-sensitive="TRUE">
texinfo.lang
<pattern-item _name="Keyword" style="Others">
xml.lang
<style id="attribute-name" _name="Attribute Name"
map-to="def:others3"/>
<style id="tags" _name="Tag"
map-to="def:others2"/>
<style id="namespace" _name="Namespace"
map-to="def:others"/>
-->

View File

@ -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;
}

View File

@ -15,6 +15,7 @@
#define __MOO_CMD_VIEW__
#include <mooedit/moolineview.h>
#include <mooedit/moooutputfilter.h>
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

View File

@ -0,0 +1,49 @@
/*
* moocommand-exe-private.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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 <mooedit/moocommand-exe.h>
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__ */

View File

@ -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);
}

View File

@ -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

View File

@ -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 <gtk/gtkwindow.h>
#include <gtk/gtktextview.h>
@ -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);
}

View File

@ -15,6 +15,7 @@
#define __MOO_COMMAND_H__
#include <gtk/gtkwidget.h>
#include <mooedit/moooutputfilter.h>
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

View File

@ -12,14 +12,64 @@
*/
#include "mooedit/moooutputfilter.h"
#include "mooutils/moomarshals.h"
#include <string.h>
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);
}

View File

@ -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

View File

@ -0,0 +1,42 @@
/*
* moooutputfiltersimple.c
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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 <string.h>
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;
}

View File

@ -0,0 +1,50 @@
/*
* moooutputfiltersimple.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
* 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 <mooedit/moooutputfilter.h>
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__ */

View File

@ -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")
)
)

View File

@ -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"