Made MooLangMgr and MooPlugin manage data dirs themselves; with single call to read the dirs.

This commit is contained in:
Yevgen Muntyan 2006-04-06 01:16:29 -05:00
parent 756cbc732e
commit fd235eb069
6 changed files with 48 additions and 49 deletions

View File

@ -793,31 +793,15 @@ moo_app_load_user_actions (void)
static void
moo_app_init_editor (MooApp *app)
{
char **dirs;
guint n_dirs, i;
MooLangMgr *lang_mgr;
app->priv->editor = moo_editor_instance ();
moo_editor_set_ui_xml (app->priv->editor,
moo_app_get_ui_xml (app));
moo_editor_set_app_name (app->priv->editor,
app->priv->info->short_name);
lang_mgr = moo_editor_get_lang_mgr (app->priv->editor);
moo_lang_mgr_read_dirs (moo_editor_get_lang_mgr (app->priv->editor));
dirs = moo_get_data_subdirs (MOO_LANG_DIR_BASENAME,
MOO_DATA_SHARE, &n_dirs);
for (i = 0; i < n_dirs; ++i)
moo_lang_mgr_add_dir (lang_mgr, dirs[i]);
moo_lang_mgr_read_dirs (lang_mgr);
g_strfreev (dirs);
dirs = moo_get_data_subdirs (MOO_PLUGIN_DIR_BASENAME,
MOO_DATA_LIB, &n_dirs);
moo_set_plugin_dirs (dirs);
moo_plugin_init_builtin ();
moo_plugin_read_dirs ();
g_strfreev (dirs);
}
@ -935,6 +919,7 @@ moo_app_init_real (MooApp *app)
#ifdef MOO_BUILD_EDIT
if (app->priv->use_editor)
moo_app_init_editor (app);
#endif
#if defined(__WIN32__) && defined(MOO_BUILD_TERM)
if (app->priv->use_terminal)
@ -988,7 +973,6 @@ start_io (MooApp *app)
moo_app_input = moo_app_input_new (app->priv->info->short_name);
moo_app_input_start (moo_app_input);
}
#endif /* MOO_BUILD_EDIT */
if (app->priv->run_output)
{

View File

@ -24,6 +24,7 @@
#include "mooutils/xdgmime/xdgmime.h"
#include "mooutils/mooprefs.h"
#include "mooutils/moomarshals.h"
#include "mooutils/mooutils-misc.h"
#include "mooutils/moocompat.h"
#include <string.h>
@ -117,7 +118,7 @@ moo_lang_mgr_finalize (GObject *object)
}
void
static void
moo_lang_mgr_add_dir (MooLangMgr *mgr,
const char *dir)
{
@ -697,9 +698,19 @@ moo_lang_mgr_read_dirs (MooLangMgr *mgr)
{
GHashTable *lang_xml_names;
GSList *lang_xml_list, *l;
char **dirs;
guint n_dirs, i;
g_return_if_fail (MOO_IS_LANG_MGR (mgr));
g_return_if_fail (!mgr->dirs_read);
if (mgr->dirs_read)
return;
dirs = moo_get_data_subdirs (MOO_LANG_DIR_BASENAME,
MOO_DATA_SHARE, &n_dirs);
for (i = 0; i < n_dirs; ++i)
moo_lang_mgr_add_dir (mgr, dirs[i]);
g_strfreev (dirs);
if (!mgr->lang_dirs)
return;

View File

@ -77,8 +77,6 @@ MooContext *moo_lang_mgr_get_context (MooLangMgr *mgr,
GSList *moo_lang_mgr_list_schemes (MooLangMgr *mgr);
void moo_lang_mgr_add_dir (MooLangMgr *mgr,
const char *dir);
void moo_lang_mgr_read_dirs (MooLangMgr *mgr);
MooTextStyle *moo_lang_mgr_get_style (MooLangMgr *mgr,

View File

@ -22,6 +22,7 @@
#include "moopython/mooplugin-python.h"
#include "mooutils/mooprefsdialog.h"
#include "mooutils/moostock.h"
#include "mooutils/mooutils-misc.h"
#include <string.h>
#include <gmodule.h>
@ -37,6 +38,7 @@ typedef struct {
GSList *list; /* MooPlugin* */
GHashTable *names;
char **dirs;
gboolean dirs_read;
} PluginStore;
static PluginStore *plugin_store = NULL;
@ -847,27 +849,49 @@ moo_plugin_read_dir (const char *path)
char **
moo_get_plugin_dirs (void)
moo_plugin_get_dirs (void)
{
plugin_store_init ();
return g_strdupv (plugin_store->dirs);
}
void
moo_set_plugin_dirs (char **dirs)
static void
moo_plugin_init_builtin (void)
{
plugin_store_init ();
g_strfreev (plugin_store->dirs);
plugin_store->dirs = g_strdupv (dirs);
#ifndef __WIN32__
_moo_find_plugin_init ();
#endif
#if GTK_CHECK_VERSION(2,6,0)
_moo_file_selector_plugin_init ();
#endif
_moo_active_strings_plugin_init ();
#ifdef MOO_USE_PYGTK
_moo_python_plugin_init ();
#endif
}
void
moo_plugin_read_dirs (void)
{
char **d;
char **d, **dirs;
guint n_dirs;
plugin_store_init ();
if (plugin_store->dirs_read)
return;
plugin_store->dirs_read = TRUE;
dirs = moo_get_data_subdirs (MOO_PLUGIN_DIR_BASENAME,
MOO_DATA_LIB, &n_dirs);
g_strfreev (plugin_store->dirs);
plugin_store->dirs = dirs;
moo_plugin_init_builtin ();
for (d = plugin_store->dirs; d && *d; ++d)
moo_plugin_read_dir (*d);
}
@ -933,22 +957,6 @@ _moo_doc_detach_plugins (MooEditWindow *window,
}
void
moo_plugin_init_builtin (void)
{
#ifndef __WIN32__
_moo_find_plugin_init ();
#endif
#if GTK_CHECK_VERSION(2,6,0)
_moo_file_selector_plugin_init ();
#endif
_moo_active_strings_plugin_init ();
#ifdef MOO_USE_PYGTK
_moo_python_plugin_init ();
#endif
}
static gboolean
moo_plugin_visible (MooPlugin *plugin)
{

View File

@ -195,10 +195,8 @@ const char *moo_plugin_description (MooPlugin *plugin);
const char *moo_plugin_author (MooPlugin *plugin);
const char *moo_plugin_version (MooPlugin *plugin);
char **moo_get_plugin_dirs (void);
void moo_set_plugin_dirs (char **dirs);
char **moo_plugin_get_dirs (void);
void moo_plugin_read_dirs (void);
void moo_plugin_init_builtin (void);
void _moo_window_attach_plugins (MooEditWindow *window);
void _moo_window_detach_plugins (MooEditWindow *window);

View File

@ -312,7 +312,7 @@ static void
moo_python_plugin_read_dirs (void)
{
char **d;
char **dirs = moo_get_plugin_dirs ();
char **dirs = moo_plugin_get_dirs ();
PyObject *sys = NULL, *path = NULL;
sys = PyImport_ImportModule ((char*) "sys");