Split mooedit-action.* into mooeditaction.* and mooeditaction-factory.*

master
Yevgen Muntyan 2006-08-19 00:59:53 -05:00
parent ddf49d7373
commit 4cb996dfb3
10 changed files with 292 additions and 229 deletions

View File

@ -19,7 +19,6 @@ completion = \
mooedit_include_headers = \
moocmdview.h \
mooedit-actions.h \
mooedit-script.h \
mooedit.h \
mooeditconfig.h \
@ -81,7 +80,10 @@ mooedit_sources = \
$(moocommand_stuff) \
gtksourceiter.c \
moocmdview.c \
mooedit-actions.c \
mooeditaction.h \
mooeditaction.c \
mooeditaction-factory.h \
mooeditaction-factory.c \
mooedit-script.c \
mooedit.c \
mooeditconfig.c \

View File

@ -12,7 +12,7 @@
*/
#define MOOEDIT_COMPILATION
#include "mooedit/mooedit-actions.h"
#include "mooedit/mooeditaction-factory.h"
#include "mooedit/mooedit-private.h"
#include "mooedit/mootextview-private.h"
#include "mooedit/mooeditdialogs.h"

View File

@ -1,5 +1,5 @@
/*
* mooedit-actions.c
* mooeditaction-factory.c
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
@ -12,13 +12,13 @@
*/
#define MOOEDIT_COMPILATION
#include "mooedit/mooedit-actions.h"
#include "mooedit/mooeditaction-factory.h"
#include "mooedit/mooeditaction.h"
#include "mooedit/mooedit-private.h"
#include "mooutils/mooutils-gobject.h"
#include "mooutils/moocompat.h"
#include "mooutils/moomarshals.h"
#include "mooutils/mooactionfactory.h"
#include "mooutils/mooactionbase.h"
#include "mooutils/moocompat.h"
#include <string.h>
#include <gobject/gvaluecollector.h>
@ -630,190 +630,6 @@ _moo_edit_class_init_actions (MooEditClass *klass)
}
/****************************************************************************/
/* MooEditAction
*/
G_DEFINE_TYPE (MooEditAction, moo_edit_action, MOO_TYPE_ACTION);
enum {
PROP_0,
PROP_DOC,
PROP_FLAGS,
PROP_LANGS
};
static void
moo_edit_action_finalize (GObject *object)
{
MooEditAction *action = MOO_EDIT_ACTION (object);
g_slist_foreach (action->langs, (GFunc) g_free, NULL);
g_slist_free (action->langs);
G_OBJECT_CLASS(moo_edit_action_parent_class)->finalize (object);
}
static void
moo_edit_action_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MooEditAction *action = MOO_EDIT_ACTION (object);
switch (prop_id)
{
case PROP_DOC:
g_value_set_object (value, action->doc);
break;
case PROP_FLAGS:
g_value_set_flags (value, action->flags);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
string_slist_free (GSList *list)
{
g_slist_foreach (list, (GFunc) g_free, NULL);
g_slist_free (list);
}
static void
moo_edit_action_set_langs (MooEditAction *action,
const char *string)
{
string_slist_free (action->langs);
action->langs = _moo_edit_parse_langs (string);
g_object_notify (G_OBJECT (action), "langs");
}
static void
moo_edit_action_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MooEditAction *action = MOO_EDIT_ACTION (object);
switch (prop_id)
{
case PROP_DOC:
action->doc = g_value_get_object (value);
g_object_notify (object, "doc");
break;
case PROP_FLAGS:
action->flags = g_value_get_flags (value);
g_object_notify (object, "flags");
break;
case PROP_LANGS:
moo_edit_action_set_langs (action, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
moo_edit_action_init (G_GNUC_UNUSED MooEditAction *action)
{
}
static void
moo_edit_action_check_state_real (MooEditAction *action)
{
gboolean sensitive = TRUE, visible = TRUE;
g_return_if_fail (action->doc != NULL);
if (action->langs)
{
MooLang *lang = moo_text_view_get_lang (MOO_TEXT_VIEW (action->doc));
if (!g_slist_find_custom (action->langs, moo_lang_id (lang),
(GCompareFunc) strcmp))
{
sensitive = FALSE;
visible = FALSE;
}
}
if (sensitive && action->flags)
sensitive = (action->flags & MOO_EDIT_ACTION_NEED_FILE) ?
moo_edit_get_filename (action->doc) != NULL : TRUE;
g_object_set (action, "visible", visible, "sensitive", sensitive, NULL);
}
static void
moo_edit_action_class_init (MooEditActionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = moo_edit_action_finalize;
gobject_class->set_property = moo_edit_action_set_property;
gobject_class->get_property = moo_edit_action_get_property;
klass->check_state = moo_edit_action_check_state_real;
g_object_class_install_property (gobject_class,
PROP_DOC,
g_param_spec_object ("doc",
"doc",
"doc",
MOO_TYPE_EDIT,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_FLAGS,
g_param_spec_flags ("flags",
"flags",
"flags",
MOO_TYPE_EDIT_ACTION_FLAGS, 0,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_LANGS,
g_param_spec_string ("langs",
"langs",
"langs",
NULL,
G_PARAM_WRITABLE));
}
GType
moo_edit_action_flags_get_type (void)
{
static GType type;
if (!type)
{
static GFlagsValue values[] = {
{ MOO_EDIT_ACTION_NEED_FILE, (char*) "MOO_EDIT_ACTION_NEED_FILE", (char*) "need-file" },
{ 0, NULL, NULL },
};
type = g_flags_register_static ("MooEditActionFlags", values);
}
return type;
}
static void
moo_edit_action_check_state (MooEditAction *action)
{

View File

@ -0,0 +1,45 @@
/*
* mooeditaction-factory.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_EDIT_ACTION_FACTORY_H__
#define __MOO_EDIT_ACTION_FACTORY_H__
#include <mooutils/mooaction.h>
#include <mooedit/mooedit.h>
#include <gtk/gtkactiongroup.h>
G_BEGIN_DECLS
typedef GtkAction *(*MooEditActionFunc) (MooEdit *edit,
gpointer data);
void moo_edit_class_new_action (MooEditClass *klass,
const char *id,
const char *first_prop_name,
...) G_GNUC_NULL_TERMINATED;
void moo_edit_class_new_action_type (MooEditClass *klass,
const char *id,
GType type);
void moo_edit_class_remove_action (MooEditClass *klass,
const char *id);
GtkActionGroup *moo_edit_get_actions (MooEdit *edit);
GtkAction *moo_edit_get_action_by_id (MooEdit *edit,
const char *action_id);
G_END_DECLS
#endif /* __MOO_EDIT_ACTION_FACTORY_H__ */

214
moo/mooedit/mooeditaction.c Normal file
View File

@ -0,0 +1,214 @@
/*
* mooeditaction.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.
*/
#define MOOEDIT_COMPILATION
#include "mooedit/mooeditaction.h"
#include <string.h>
struct _MooEditActionPrivate {
MooEdit *doc;
GSList *langs;
MooEditActionFlags flags;
};
G_DEFINE_TYPE (MooEditAction, moo_edit_action, MOO_TYPE_ACTION);
enum {
PROP_0,
PROP_DOC,
PROP_FLAGS,
PROP_LANGS
};
static void
moo_edit_action_finalize (GObject *object)
{
MooEditAction *action = MOO_EDIT_ACTION (object);
g_slist_foreach (action->priv->langs, (GFunc) g_free, NULL);
g_slist_free (action->priv->langs);
G_OBJECT_CLASS(moo_edit_action_parent_class)->finalize (object);
}
static void
moo_edit_action_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MooEditAction *action = MOO_EDIT_ACTION (object);
switch (prop_id)
{
case PROP_DOC:
g_value_set_object (value, action->priv->doc);
break;
case PROP_FLAGS:
g_value_set_flags (value, action->priv->flags);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
string_slist_free (GSList *list)
{
g_slist_foreach (list, (GFunc) g_free, NULL);
g_slist_free (list);
}
static void
moo_edit_action_set_langs (MooEditAction *action,
const char *string)
{
string_slist_free (action->priv->langs);
action->priv->langs = _moo_edit_parse_langs (string);
g_object_notify (G_OBJECT (action), "langs");
}
MooEdit *
moo_edit_action_get_doc (MooEditAction *action)
{
g_return_val_if_fail (MOO_IS_EDIT_ACTION (action), NULL);
return action->priv->doc;
}
static void
moo_edit_action_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MooEditAction *action = MOO_EDIT_ACTION (object);
switch (prop_id)
{
case PROP_DOC:
action->priv->doc = g_value_get_object (value);
g_object_notify (object, "doc");
break;
case PROP_FLAGS:
action->priv->flags = g_value_get_flags (value);
g_object_notify (object, "flags");
break;
case PROP_LANGS:
moo_edit_action_set_langs (action, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
moo_edit_action_init (MooEditAction *action)
{
action->priv = G_TYPE_INSTANCE_GET_PRIVATE (action, MOO_TYPE_EDIT_ACTION, MooEditActionPrivate);
}
static void
moo_edit_action_check_state_real (MooEditAction *action)
{
gboolean sensitive = TRUE, visible = TRUE;
g_return_if_fail (action->priv->doc != NULL);
if (action->priv->langs)
{
MooLang *lang = moo_text_view_get_lang (MOO_TEXT_VIEW (action->priv->doc));
if (!g_slist_find_custom (action->priv->langs, moo_lang_id (lang),
(GCompareFunc) strcmp))
{
sensitive = FALSE;
visible = FALSE;
}
}
if (sensitive && action->priv->flags)
sensitive = (action->priv->flags & MOO_EDIT_ACTION_NEED_FILE) ?
moo_edit_get_filename (action->priv->doc) != NULL : TRUE;
g_object_set (action, "visible", visible, "sensitive", sensitive, NULL);
}
static void
moo_edit_action_class_init (MooEditActionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = moo_edit_action_finalize;
gobject_class->set_property = moo_edit_action_set_property;
gobject_class->get_property = moo_edit_action_get_property;
klass->check_state = moo_edit_action_check_state_real;
g_type_class_add_private (klass, sizeof (MooEditActionPrivate));
g_object_class_install_property (gobject_class,
PROP_DOC,
g_param_spec_object ("doc",
"doc",
"doc",
MOO_TYPE_EDIT,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_FLAGS,
g_param_spec_flags ("flags",
"flags",
"flags",
MOO_TYPE_EDIT_ACTION_FLAGS, 0,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_LANGS,
g_param_spec_string ("langs",
"langs",
"langs",
NULL,
G_PARAM_WRITABLE));
}
GType
moo_edit_action_flags_get_type (void)
{
static GType type;
if (!type)
{
static GFlagsValue values[] = {
{ MOO_EDIT_ACTION_NEED_FILE, (char*) "MOO_EDIT_ACTION_NEED_FILE", (char*) "need-file" },
{ 0, NULL, NULL },
};
type = g_flags_register_static ("MooEditActionFlags", values);
}
return type;
}

View File

@ -1,5 +1,5 @@
/*
* mooedit-actions.h
* mooeditaction.h
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
*
@ -11,11 +11,10 @@
* See COPYING file that comes with this distribution.
*/
#ifndef __MOO_EDIT_ACTIONS_H__
#define __MOO_EDIT_ACTIONS_H__
#ifndef __MOO_EDIT_ACTION_H__
#define __MOO_EDIT_ACTION_H__
#include <mooutils/mooaction.h>
#include <mooutils/moouixml.h>
#include <mooedit/mooedit.h>
G_BEGIN_DECLS
@ -40,9 +39,7 @@ typedef enum {
struct _MooEditAction
{
MooAction parent;
MooEdit *doc;
GSList *langs;
MooEditActionFlags flags;
MooEditActionPrivate *priv;
};
struct _MooEditActionClass
@ -53,31 +50,15 @@ struct _MooEditActionClass
};
typedef GtkAction *(*MooEditActionFunc) (MooEdit *edit,
gpointer data);
GType moo_edit_action_get_type (void) G_GNUC_CONST;
GType moo_edit_action_flags_get_type (void) G_GNUC_CONST;
void moo_edit_class_new_action (MooEditClass *klass,
const char *id,
const char *first_prop_name,
...) G_GNUC_NULL_TERMINATED;
void moo_edit_class_new_action_type (MooEditClass *klass,
const char *id,
GType type);
void moo_edit_class_remove_action (MooEditClass *klass,
const char *id);
GtkActionGroup *moo_edit_get_actions (MooEdit *edit);
GtkAction *moo_edit_get_action_by_id (MooEdit *edit,
const char *action_id);
MooEdit *moo_edit_action_get_doc (MooEditAction *action);
/* defined in mooeditwindow.c */
GSList *_moo_edit_parse_langs (const char *string);
GSList *_moo_edit_parse_langs (const char *string);
G_END_DECLS
#endif /* __MOO_EDIT_ACTIONS_H__ */
#endif /* __MOO_EDIT_ACTION_H__ */

View File

@ -24,7 +24,7 @@
#include "mooedit/mooeditprefs.h"
#include "mooedit/mooplugin.h"
#include "mooedit/moocmdview.h"
#include "mooedit/mooedit-actions.h"
#include "mooedit/mooeditaction.h"
#include "mooutils/moonotebook.h"
#include "mooutils/moostock.h"
#include "mooutils/moomarshals.h"

View File

@ -14,7 +14,8 @@
#include "mooedit/moousertools.h"
#include "mooedit/moocommand.h"
#include "mooedit/mooeditor.h"
#include "mooedit/mooedit-actions.h"
#include "mooedit/mooeditaction.h"
#include "mooedit/mooeditaction-factory.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/mooaccel.h"
#include "mooutils/mooi18n.h"
@ -763,9 +764,10 @@ moo_tool_action_activate (GtkAction *gtkaction)
g_return_if_fail (action->cmd != NULL);
if (edit_action->doc)
doc = moo_edit_action_get_doc (edit_action);
if (doc)
{
doc = edit_action->doc;
window = moo_edit_get_window (doc);
}
else
@ -788,6 +790,7 @@ moo_tool_action_check_state (MooEditAction *edit_action)
{
gboolean sensitive;
MooToolAction *action = MOO_TOOL_ACTION (edit_action);
MooEdit *doc;
g_return_if_fail (action->cmd != NULL);
@ -796,9 +799,8 @@ moo_tool_action_check_state (MooEditAction *edit_action)
if (!gtk_action_is_visible (GTK_ACTION (action)))
return;
sensitive = moo_command_check_sensitive (action->cmd,
edit_action->doc,
moo_edit_get_window (edit_action->doc));
doc = moo_edit_action_get_doc (edit_action);
sensitive = moo_command_check_sensitive (action->cmd, doc, moo_edit_get_window (doc));
g_object_set (action, "sensitive", sensitive, NULL);
}

View File

@ -87,10 +87,6 @@
(parent "GtkAction")
(c-name "MooEditAction")
(gtype-id "MOO_TYPE_EDIT_ACTION")
(fields
'("MooEdit*" "doc")
'("MooEditActionFlags" "flags")
)
)
(define-object TextStyleScheme
@ -1453,6 +1449,12 @@
; (return-type "GtkAction*")
;)
(define-method get_doc
(of-object "MooEditAction")
(c-name "moo_edit_action_get_doc")
(return-type "MooEdit*")
)
(define-virtual check_state
(of-object "MooEditAction")
(return-type "none")

View File

@ -9,7 +9,8 @@ headers
#include "mooedit/mootextiter.h"
#include "mooedit/mooeditprefs.h"
#include "mooedit/moocmdview.h"
#include "mooedit/mooedit-actions.h"
#include "mooedit/mooeditaction-factory.h"
#include "mooedit/mooeditaction.h"
#include "mooedit/mooplugin.h"
#include "mooedit/moocommand.h"
#include "moopython/moopython-utils.h"