Made MooPlugin more binding-friendly.
parent
559f0faebc
commit
c4daae67ae
|
@ -1,5 +1,4 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
|
||||
*
|
||||
/*
|
||||
* mooplugin-macro.h
|
||||
*
|
||||
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
|
@ -22,25 +21,15 @@
|
|||
description__,author__,version__, \
|
||||
langs__) \
|
||||
\
|
||||
static MooPluginParams plugin_name__##_plugin_params = { \
|
||||
TRUE, \
|
||||
TRUE \
|
||||
}; \
|
||||
\
|
||||
static MooPluginPrefsParams plugin_name__##_plugin_prefs_params = { \
|
||||
TRUE \
|
||||
}; \
|
||||
\
|
||||
static MooPluginInfo plugin_name__##_plugin_info = { \
|
||||
id__, \
|
||||
name__, \
|
||||
description__, \
|
||||
author__, \
|
||||
version__, \
|
||||
langs__, \
|
||||
&plugin_name__##_plugin_params, \
|
||||
&plugin_name__##_plugin_prefs_params \
|
||||
};
|
||||
static struct { \
|
||||
const char *id; \
|
||||
const char *name; \
|
||||
const char *description; \
|
||||
const char *author; \
|
||||
const char *version; \
|
||||
const char *langs; \
|
||||
} plugin_name__##_plugin_info = {id__, name__, description__, \
|
||||
author__, version__, langs__};
|
||||
|
||||
|
||||
#define MOO_PLUGIN_DEFINE_FULL(Name__,name__, \
|
||||
|
@ -61,7 +50,7 @@ name__##_plugin_class_init (MooPluginClass *klass) \
|
|||
{ \
|
||||
name__##_plugin_parent_class = g_type_class_peek_parent (klass); \
|
||||
\
|
||||
klass->plugin_system_version = MOO_PLUGIN_CURRENT_VERSION; \
|
||||
/* klass->plugin_system_version = MOO_PLUGIN_CURRENT_VERSION; */ \
|
||||
\
|
||||
klass->init = (MooPluginInitFunc) init__; \
|
||||
klass->deinit = (MooPluginDeinitFunc) deinit__; \
|
||||
|
@ -75,7 +64,15 @@ name__##_plugin_class_init (MooPluginClass *klass) \
|
|||
static void \
|
||||
name__##_plugin_instance_init (MooPlugin *plugin) \
|
||||
{ \
|
||||
plugin->info = &name__##_plugin_info; \
|
||||
plugin->info = \
|
||||
moo_plugin_info_new (name__##_plugin_info.id, \
|
||||
name__##_plugin_info.name, \
|
||||
name__##_plugin_info.description, \
|
||||
name__##_plugin_info.author, \
|
||||
name__##_plugin_info.version, \
|
||||
name__##_plugin_info.langs, \
|
||||
TRUE, TRUE); \
|
||||
\
|
||||
plugin->win_plugin_type = WIN_PLUGIN_TYPE__; \
|
||||
plugin->doc_plugin_type = DOC_PLUGIN_TYPE__; \
|
||||
} \
|
||||
|
|
|
@ -182,6 +182,8 @@ moo_plugin_finalize (GObject *object)
|
|||
if (plugin->langs)
|
||||
g_hash_table_destroy (plugin->langs);
|
||||
|
||||
moo_plugin_info_free (plugin->info);
|
||||
|
||||
G_OBJECT_CLASS(parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -207,13 +209,13 @@ moo_plugin_register (GType type)
|
|||
klass = g_type_class_ref (type);
|
||||
g_return_val_if_fail (klass != NULL, FALSE);
|
||||
|
||||
if (klass->plugin_system_version != MOO_PLUGIN_CURRENT_VERSION)
|
||||
{
|
||||
g_message ("%s: plugin %s of version %d is incompatible with "
|
||||
"current version %d", G_STRLOC, g_type_name (type),
|
||||
klass->plugin_system_version, MOO_PLUGIN_CURRENT_VERSION);
|
||||
return FALSE;
|
||||
}
|
||||
// if (klass->plugin_system_version != MOO_PLUGIN_CURRENT_VERSION)
|
||||
// {
|
||||
// g_message ("%s: plugin %s of version %d is incompatible with "
|
||||
// "current version %d", G_STRLOC, g_type_name (type),
|
||||
// klass->plugin_system_version, MOO_PLUGIN_CURRENT_VERSION);
|
||||
// return FALSE;
|
||||
// }
|
||||
|
||||
if (moo_plugin_registered (type))
|
||||
{
|
||||
|
@ -670,7 +672,7 @@ plugin_info_check (MooPluginInfo *info)
|
|||
g_utf8_validate (info->id, -1, NULL) &&
|
||||
info->name && g_utf8_validate (info->name, -1, NULL) &&
|
||||
info->description && g_utf8_validate (info->description, -1, NULL) &&
|
||||
info->params && info->prefs_params;
|
||||
info->params;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1070,6 +1072,149 @@ moo_plugin_visible (MooPlugin *plugin)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
moo_plugin_set_info (MooPlugin *plugin,
|
||||
MooPluginInfo *info)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_PLUGIN (plugin));
|
||||
|
||||
if (plugin->info != info)
|
||||
{
|
||||
moo_plugin_info_free (plugin->info);
|
||||
plugin->info = moo_plugin_info_copy (info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_plugin_set_doc_plugin_type (MooPlugin *plugin,
|
||||
GType type)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_PLUGIN (plugin));
|
||||
g_return_if_fail (g_type_is_a (type, MOO_TYPE_DOC_PLUGIN));
|
||||
plugin->doc_plugin_type = type;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_plugin_set_win_plugin_type (MooPlugin *plugin,
|
||||
GType type)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_PLUGIN (plugin));
|
||||
g_return_if_fail (g_type_is_a (type, MOO_TYPE_WIN_PLUGIN));
|
||||
plugin->win_plugin_type = type;
|
||||
}
|
||||
|
||||
|
||||
MooPluginInfo *
|
||||
moo_plugin_info_new (const char *id,
|
||||
const char *name,
|
||||
const char *description,
|
||||
const char *author,
|
||||
const char *version,
|
||||
const char *langs,
|
||||
gboolean enabled,
|
||||
gboolean visible)
|
||||
{
|
||||
MooPluginInfo *info;
|
||||
|
||||
g_return_val_if_fail (id && name, NULL);
|
||||
|
||||
info = g_new0 (MooPluginInfo, 1);
|
||||
info->id = g_strdup (id);
|
||||
info->name = g_strdup (name);
|
||||
info->description = description ? g_strdup (description) : g_strdup ("");
|
||||
info->author = author ? g_strdup (author) : g_strdup ("");
|
||||
info->version = version ? g_strdup (version) : g_strdup ("");
|
||||
info->langs = g_strdup (langs);
|
||||
info->params = moo_plugin_params_new (enabled, visible);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
MooPluginInfo *
|
||||
moo_plugin_info_copy (MooPluginInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (info != NULL, NULL);
|
||||
g_return_val_if_fail (info->params != NULL, NULL);
|
||||
return moo_plugin_info_new (info->id, info->name, info->description,
|
||||
info->author, info->version, info->langs,
|
||||
info->params->enabled, info->params->visible);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_plugin_info_free (MooPluginInfo *info)
|
||||
{
|
||||
if (info)
|
||||
{
|
||||
g_free (info->id);
|
||||
g_free (info->name);
|
||||
g_free (info->description);
|
||||
g_free (info->author);
|
||||
g_free (info->version);
|
||||
g_free (info->langs);
|
||||
moo_plugin_params_free (info->params);
|
||||
g_free (info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MooPluginParams *
|
||||
moo_plugin_params_new (gboolean enabled,
|
||||
gboolean visible)
|
||||
{
|
||||
MooPluginParams *params = g_new0 (MooPluginParams, 1);
|
||||
params->enabled = enabled != 0;
|
||||
params->visible = visible != 0;
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
MooPluginParams *
|
||||
moo_plugin_params_copy (MooPluginParams *params)
|
||||
{
|
||||
g_return_val_if_fail (params != NULL, NULL);
|
||||
return moo_plugin_params_new (params->enabled, params->visible);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_plugin_params_free (MooPluginParams *params)
|
||||
{
|
||||
g_free (params);
|
||||
}
|
||||
|
||||
|
||||
GType
|
||||
moo_plugin_info_get_type (void)
|
||||
{
|
||||
static GType type;
|
||||
|
||||
if (!type)
|
||||
type = g_boxed_type_register_static ("MooPluginInfo",
|
||||
(GBoxedCopyFunc) moo_plugin_info_copy,
|
||||
(GBoxedFreeFunc) moo_plugin_info_free);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
GType
|
||||
moo_plugin_params_get_type (void)
|
||||
{
|
||||
static GType type;
|
||||
|
||||
if (!type)
|
||||
type = g_boxed_type_register_static ("MooPluginParams",
|
||||
(GBoxedCopyFunc) moo_plugin_params_copy,
|
||||
(GBoxedFreeFunc) moo_plugin_params_free);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/* Preferences dialog
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
#define MOO_PLUGIN_PREFS_ROOT "Plugins"
|
||||
#define MOO_PLUGIN_CURRENT_VERSION 17
|
||||
#define MOO_PLUGIN_CURRENT_VERSION 18
|
||||
#define MOO_PLUGIN_DIR_BASENAME "plugins"
|
||||
|
||||
#define MOO_PLUGIN_INIT_FUNC moo_module_init
|
||||
|
@ -48,11 +48,13 @@ G_BEGIN_DECLS
|
|||
#define MOO_IS_DOC_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_DOC_PLUGIN))
|
||||
#define MOO_DOC_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_DOC_PLUGIN, MooDocPluginClass))
|
||||
|
||||
#define MOO_TYPE_PLUGIN_INFO (moo_plugin_info_get_type ())
|
||||
#define MOO_TYPE_PLUGIN_PARAMS (moo_plugin_params_get_type ())
|
||||
|
||||
|
||||
typedef struct _MooPlugin MooPlugin;
|
||||
typedef struct _MooPluginInfo MooPluginInfo;
|
||||
typedef struct _MooPluginParams MooPluginParams;
|
||||
typedef struct _MooPluginPrefsParams MooPluginPrefsParams;
|
||||
typedef struct _MooPluginClass MooPluginClass;
|
||||
typedef struct _MooWinPlugin MooWinPlugin;
|
||||
typedef struct _MooWinPluginClass MooWinPluginClass;
|
||||
|
@ -89,25 +91,18 @@ struct _MooPluginParams
|
|||
gboolean visible;
|
||||
};
|
||||
|
||||
struct _MooPluginPrefsParams
|
||||
{
|
||||
/* it's needed to make sizeof() > 0 */
|
||||
guint dummy : 1;
|
||||
};
|
||||
|
||||
struct _MooPluginInfo
|
||||
{
|
||||
const char *id;
|
||||
char *id;
|
||||
|
||||
const char *name;
|
||||
const char *description;
|
||||
const char *author;
|
||||
const char *version;
|
||||
char *name;
|
||||
char *description;
|
||||
char *author;
|
||||
char *version;
|
||||
|
||||
const char *langs;
|
||||
char *langs;
|
||||
|
||||
MooPluginParams *params;
|
||||
MooPluginPrefsParams *prefs_params;
|
||||
};
|
||||
|
||||
struct _MooPlugin
|
||||
|
@ -144,8 +139,6 @@ struct _MooPluginClass
|
|||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
guint plugin_system_version;
|
||||
|
||||
MooPluginInitFunc init;
|
||||
MooPluginDeinitFunc deinit;
|
||||
MooPluginAttachWinFunc attach_win;
|
||||
|
@ -175,6 +168,8 @@ struct _MooDocPluginClass
|
|||
GType moo_plugin_get_type (void) G_GNUC_CONST;
|
||||
GType moo_win_plugin_get_type (void) G_GNUC_CONST;
|
||||
GType moo_doc_plugin_get_type (void) G_GNUC_CONST;
|
||||
GType moo_plugin_info_get_type (void) G_GNUC_CONST;
|
||||
GType moo_plugin_params_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean moo_plugin_register (GType type);
|
||||
void moo_plugin_unregister (GType type);
|
||||
|
@ -205,6 +200,28 @@ const char *moo_plugin_version (MooPlugin *plugin);
|
|||
char **moo_plugin_get_dirs (void);
|
||||
void moo_plugin_read_dirs (void);
|
||||
|
||||
void moo_plugin_set_info (MooPlugin *plugin,
|
||||
MooPluginInfo *info);
|
||||
void moo_plugin_set_doc_plugin_type (MooPlugin *plugin,
|
||||
GType type);
|
||||
void moo_plugin_set_win_plugin_type (MooPlugin *plugin,
|
||||
GType type);
|
||||
|
||||
MooPluginInfo *moo_plugin_info_new (const char *id,
|
||||
const char *name,
|
||||
const char *description,
|
||||
const char *author,
|
||||
const char *version,
|
||||
const char *langs,
|
||||
gboolean enabled,
|
||||
gboolean visible);
|
||||
MooPluginInfo *moo_plugin_info_copy (MooPluginInfo *info);
|
||||
void moo_plugin_info_free (MooPluginInfo *info);
|
||||
MooPluginParams *moo_plugin_params_new (gboolean enabled,
|
||||
gboolean visible);
|
||||
MooPluginParams *moo_plugin_params_copy (MooPluginParams *params);
|
||||
void moo_plugin_params_free (MooPluginParams *params);
|
||||
|
||||
void _moo_window_attach_plugins (MooEditWindow *window);
|
||||
void _moo_window_detach_plugins (MooEditWindow *window);
|
||||
void _moo_doc_attach_plugins (MooEditWindow *window,
|
||||
|
|
|
@ -94,7 +94,7 @@
|
|||
<Keyword style="Keyword" context="#stay" keyword="keywords"/>
|
||||
<Keyword style="Data Type" context="#stay" keyword="types"/>
|
||||
<Keyword keyword="CommonMacro" style="Common Macro" context="#stay"/>
|
||||
<Regex pattern="&func_pattern;" style="Function"/>
|
||||
<!-- <Regex pattern="&func_pattern;" style="Function"/>-->
|
||||
<Identifier/>
|
||||
<Float style="Float" context="#stay">
|
||||
<AnyChar chars="fF" style="Float" context="#stay"/>
|
||||
|
@ -171,7 +171,7 @@
|
|||
<style name="String Char" default-style="Char"/>
|
||||
<style name="Comment" default-style="Comment"/>
|
||||
<style name="Symbol" default-style="Normal"/>
|
||||
<style name="Preprocessor" default-style="Others"/>
|
||||
<style name="Preprocessor" default-style="Others" italic="False"/>
|
||||
<style name="Prep. Lib" default-style="Others"/>
|
||||
<style name="Common Macro" default-style="Keyword" foreground="#0095ff" bold="1" italic="0"/>
|
||||
<style name="Function" default-style="Function"/>
|
||||
|
|
Loading…
Reference in New Issue