From 176528be2d8aa150ca87f770639d5d4d461ee44b Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Tue, 26 Aug 2008 13:51:05 -0500 Subject: [PATCH] Use a global instance of MooLangMgr too --- .hgignore | 1 + moo/mooedit/mooedit.c | 19 +++++++++-------- moo/mooedit/mooeditor.c | 10 +-------- moo/mooedit/mooeditor.h | 3 --- moo/mooedit/mooeditprefs.c | 3 ++- moo/mooedit/mooeditprefspage.c | 24 ++++++++++------------ moo/mooedit/mooeditwindow.c | 5 +++-- moo/mooedit/moolangmgr.c | 9 ++++++++ moo/mooedit/moolangmgr.h | 1 + moo/mooedit/moooutputfilterregex.c | 3 ++- moo/mooedit/mootextview.c | 3 ++- moo/moopython/{Makefile.am => Makefile.ug} | 2 +- moo/moopython/pygtk/Makefile.incl | 8 ++++++-- moo/moopython/pygtk/mooedit-pygtk.defs | 5 +++++ moo/moopython/pygtk/mooeditor.defs | 6 ------ 15 files changed, 55 insertions(+), 47 deletions(-) rename moo/moopython/{Makefile.am => Makefile.ug} (99%) diff --git a/.hgignore b/.hgignore index fee68371..e12c3aff 100644 --- a/.hgignore +++ b/.hgignore @@ -45,6 +45,7 @@ syntax: regexp ^moo/Makefile\.am ^moo/mooedit/Makefile\.am ^moo/mooedit/plugins/Makefile\.am +^moo/moopython/Makefile\.am ^moo/moofileview/Makefile\.am ^moo/moolua/Makefile\.am ^moo/mooapp/Makefile\.am diff --git a/moo/mooedit/mooedit.c b/moo/mooedit/mooedit.c index 9ae30cd6..b6cb1f72 100644 --- a/moo/mooedit/mooedit.c +++ b/moo/mooedit/mooedit.c @@ -20,6 +20,7 @@ #include "mooedit/mootextbuffer.h" #include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditor-private.h" +#include "mooedit/moolangmgr.h" #include "marshals.h" #include "mooutils/mooi18n.h" #include "mooutils/mooutils-misc.h" @@ -891,7 +892,7 @@ parse_emacs_mode_string (MooEdit *edit, g_strstrip (string); - mgr = moo_editor_get_lang_mgr (edit->priv->editor); + mgr = moo_lang_mgr_default (); if (_moo_lang_mgr_find_lang (mgr, string)) set_emacs_var (edit, "mode", string); @@ -1029,8 +1030,9 @@ moo_edit_set_lang (MooEdit *edit, if (old_lang != lang) { moo_text_view_set_lang (MOO_TEXT_VIEW (edit), lang); - _moo_lang_mgr_update_config (moo_editor_get_lang_mgr (edit->priv->editor), - edit->config, _moo_lang_id (lang)); + _moo_lang_mgr_update_config (moo_lang_mgr_default (), + edit->config, + _moo_lang_id (lang)); _moo_edit_update_config_from_global (edit); g_object_notify (G_OBJECT (edit), "has-comments"); } @@ -1041,7 +1043,7 @@ static void moo_edit_apply_lang_config (MooEdit *edit) { const char *lang_id = moo_edit_config_get_string (edit->config, "lang"); - MooLangMgr *mgr = moo_editor_get_lang_mgr (edit->priv->editor); + MooLangMgr *mgr = moo_lang_mgr_default (); MooLang *lang = lang_id ? _moo_lang_mgr_find_lang (mgr, lang_id) : NULL; moo_edit_set_lang (edit, lang); } @@ -1121,7 +1123,7 @@ _moo_edit_update_lang_config (void) for (l = _moo_edit_instances; l != NULL; l = l->next) { MooEdit *edit = l->data; - _moo_lang_mgr_update_config (moo_editor_get_lang_mgr (edit->priv->editor), edit->config, + _moo_lang_mgr_update_config (moo_lang_mgr_default (), edit->config, _moo_lang_id (moo_text_view_get_lang (MOO_TEXT_VIEW (edit)))); } } @@ -1145,7 +1147,7 @@ moo_edit_filename_changed (MooEdit *edit, if (filename) { - MooLangMgr *mgr = moo_editor_get_lang_mgr (edit->priv->editor); + MooLangMgr *mgr = moo_lang_mgr_default (); lang = moo_lang_mgr_get_lang_for_file (mgr, filename); lang_id = lang ? _moo_lang_id (lang) : NULL; filter_config = _moo_edit_filter_settings_get_for_file (filename); @@ -1169,8 +1171,9 @@ moo_edit_filename_changed (MooEdit *edit, if (!lang_changed) { - _moo_lang_mgr_update_config (moo_editor_get_lang_mgr (edit->priv->editor), - edit->config, _moo_lang_id (lang)); + _moo_lang_mgr_update_config (moo_lang_mgr_default (), + edit->config, + _moo_lang_id (lang)); _moo_edit_update_config_from_global (edit); } diff --git a/moo/mooedit/mooeditor.c b/moo/mooedit/mooeditor.c index c458ca33..1f9e55d1 100644 --- a/moo/mooedit/mooeditor.c +++ b/moo/mooedit/mooeditor.c @@ -298,7 +298,7 @@ moo_editor_init (MooEditor *editor) moo_ui_xml_add_ui_from_string (editor->priv->doc_ui_xml, mooedit_ui_xml, -1); - editor->priv->lang_mgr = moo_lang_mgr_new (); + editor->priv->lang_mgr = g_object_ref (moo_lang_mgr_default ()); g_signal_connect_swapped (editor->priv->lang_mgr, "loaded", G_CALLBACK (moo_editor_apply_prefs), editor); @@ -2513,14 +2513,6 @@ moo_editor_get_doc (MooEditor *editor, } -MooLangMgr* -moo_editor_get_lang_mgr (MooEditor *editor) -{ - g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); - return editor->priv->lang_mgr; -} - - void moo_editor_set_window_type (MooEditor *editor, GType type) diff --git a/moo/mooedit/mooeditor.h b/moo/mooedit/mooeditor.h index 1cb294a7..6ba877bf 100644 --- a/moo/mooedit/mooeditor.h +++ b/moo/mooedit/mooeditor.h @@ -14,7 +14,6 @@ #define MOO_EDITOR_H #include -#include #include G_BEGIN_DECLS @@ -129,8 +128,6 @@ MooUIXML *moo_editor_get_doc_ui_xml (MooEditor *editor); MooEditor *moo_edit_window_get_editor (MooEditWindow *window); MooEditor *moo_edit_get_editor (MooEdit *doc); -MooLangMgr *moo_editor_get_lang_mgr (MooEditor *editor); - void moo_editor_set_window_type (MooEditor *editor, GType type); void moo_editor_set_edit_type (MooEditor *editor, diff --git a/moo/mooedit/mooeditprefs.c b/moo/mooedit/mooeditprefs.c index 804b9583..6ad7de6d 100644 --- a/moo/mooedit/mooeditprefs.c +++ b/moo/mooedit/mooeditprefs.c @@ -17,6 +17,7 @@ #include "mooedit/mootextview-private.h" #include "mooedit/mooedit-enums.h" #include "mooedit/mootextbuffer.h" +#include "mooedit/moolangmgr.h" #include "mooutils/mooencodings.h" #include @@ -218,7 +219,7 @@ _moo_edit_apply_prefs (MooEdit *edit) _moo_text_view_set_line_numbers_font (MOO_TEXT_VIEW (edit), get_string (MOO_EDIT_PREFS_LINE_NUMBERS_FONT)); - mgr = moo_editor_get_lang_mgr (edit->priv->editor); + mgr = moo_lang_mgr_default (); scheme = moo_lang_mgr_get_active_scheme (mgr); if (scheme) diff --git a/moo/mooedit/mooeditprefspage.c b/moo/mooedit/mooeditprefspage.c index 429285d5..fbbc2810 100644 --- a/moo/mooedit/mooeditprefspage.c +++ b/moo/mooedit/mooeditprefspage.c @@ -43,8 +43,7 @@ static gboolean moo_edit_prefs_page_help (GtkWidget *widget); static void prefs_page_apply_lang_prefs (PrefsPage *page); static void apply_filter_settings (PrefsPage *page); -static void scheme_combo_init (GtkComboBox *combo, - MooEditor *editor); +static void scheme_combo_init (GtkComboBox *combo); static void scheme_combo_data_func (GtkCellLayout *layout, GtkCellRenderer *cell, GtkTreeModel *model, @@ -62,7 +61,7 @@ static void lang_combo_init (GtkComboBox *combo, static void filter_treeview_init (MooGladeXML *xml); -static GtkTreeModel *create_lang_model (MooEditor *editor); +static GtkTreeModel *create_lang_model (void); static void save_encoding_combo_init (MooGladeXML *xml); static void save_encoding_combo_apply (MooGladeXML *xml); @@ -206,7 +205,7 @@ moo_edit_prefs_page_new (MooEditor *editor) gtk_container_add (GTK_CONTAINER (prefs_page), GTK_WIDGET (data->notebook)); data->editor = g_object_ref (editor); - data->lang_mgr = g_object_ref (moo_editor_get_lang_mgr (editor)); + data->lang_mgr = g_object_ref (moo_lang_mgr_default ()); for (i = 0; i < G_N_ELEMENTS (prefs_pages); i++) { @@ -230,7 +229,7 @@ moo_edit_prefs_page_new (MooEditor *editor) gtk_label_new (_(info->label))); page->editor = g_object_ref (editor); - page->lang_mgr = g_object_ref (moo_editor_get_lang_mgr (editor)); + page->lang_mgr = g_object_ref (moo_lang_mgr_default ()); data->n_pages++; } @@ -293,7 +292,7 @@ page_view_init (PrefsPage *page) g_return_if_fail (scheme != NULL); scheme_combo = moo_glade_xml_get_widget (page->page->xml, "color_scheme_combo"); - scheme_combo_init (scheme_combo, page->editor); + scheme_combo_init (scheme_combo); scheme_combo_set_scheme (scheme_combo, scheme); } @@ -349,15 +348,14 @@ page_langs_apply (PrefsPage *page) static void -scheme_combo_init (GtkComboBox *combo, - MooEditor *editor) +scheme_combo_init (GtkComboBox *combo) { GtkListStore *store; MooLangMgr *mgr; GSList *list, *l; GtkCellRenderer *cell; - mgr = moo_editor_get_lang_mgr (editor); + mgr = moo_lang_mgr_default (); list = moo_lang_mgr_list_schemes (mgr); g_return_if_fail (list != NULL); @@ -422,7 +420,7 @@ page_get_lang_model (PrefsPage *page) if (!model) { - model = create_lang_model (page->editor); + model = create_lang_model (); g_object_set_data_full (G_OBJECT (page->master), "moo-lang-model", model, g_object_unref); } @@ -581,7 +579,7 @@ lang_cmp (MooLang *lang1, } static GtkTreeModel * -create_lang_model (MooEditor *editor) +create_lang_model (void) { GtkTreeStore *store; MooLangMgr *mgr; @@ -590,7 +588,7 @@ create_lang_model (MooEditor *editor) const char *config; char *ext, *mime; - mgr = moo_editor_get_lang_mgr (editor); + mgr = moo_lang_mgr_default (); langs = g_slist_sort (moo_lang_mgr_get_available_langs (mgr), (GCompareFunc) lang_cmp); sections = moo_lang_mgr_get_sections (mgr); @@ -947,7 +945,7 @@ prefs_page_apply_lang_prefs (PrefsPage *page) model = page_get_lang_model (page); g_return_if_fail (model != NULL); - mgr = moo_editor_get_lang_mgr (page->editor); + mgr = moo_lang_mgr_default (); gtk_tree_model_foreach (model, (GtkTreeModelForeachFunc) apply_one_lang, mgr); _moo_lang_mgr_save_config (mgr); _moo_edit_update_lang_config (); diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index 5243c7c7..ac44b1c5 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -26,6 +26,7 @@ #include "mooedit/moocmdview.h" #include "mooedit/mooeditaction.h" #include "mooedit/mooedit-bookmarks.h" +#include "mooedit/moolangmgr.h" #include "mooutils/moonotebook.h" #include "mooutils/moostock.h" #include "marshals.h" @@ -3049,14 +3050,14 @@ lang_item_activated (MooEditWindow *window, static GtkAction* -create_lang_action (MooEditWindow *window) +create_lang_action (MooEditWindow *window) { GtkAction *action; MooMenuMgr *menu_mgr; MooLangMgr *lang_mgr; GSList *langs, *sections, *l; - lang_mgr = moo_editor_get_lang_mgr (window->priv->editor); + lang_mgr = moo_lang_mgr_default (); /* TODO display names, etc. */ sections = moo_lang_mgr_get_sections (lang_mgr); diff --git a/moo/mooedit/moolangmgr.c b/moo/mooedit/moolangmgr.c index fb36843e..1afe2cfb 100644 --- a/moo/mooedit/moolangmgr.c +++ b/moo/mooedit/moolangmgr.c @@ -125,6 +125,15 @@ moo_lang_mgr_new (void) return g_object_new (MOO_TYPE_LANG_MGR, NULL); } +MooLangMgr * +moo_lang_mgr_default (void) +{ + static MooLangMgr *instance; + if (!instance) + instance = moo_lang_mgr_new (); + return instance; +} + static LangInfo * lang_info_new (void) diff --git a/moo/mooedit/moolangmgr.h b/moo/mooedit/moolangmgr.h index ced3a69e..7d92bf99 100644 --- a/moo/mooedit/moolangmgr.h +++ b/moo/mooedit/moolangmgr.h @@ -30,6 +30,7 @@ typedef struct _MooLangMgr MooLangMgr; GType moo_lang_mgr_get_type (void) G_GNUC_CONST; MooLangMgr *moo_lang_mgr_new (void); +MooLangMgr *moo_lang_mgr_default (void); MooLang *moo_lang_mgr_get_lang (MooLangMgr *mgr, const char *lang_id); diff --git a/moo/mooedit/moooutputfilterregex.c b/moo/mooedit/moooutputfilterregex.c index 3bb39c28..c1539fc9 100644 --- a/moo/mooedit/moooutputfilterregex.c +++ b/moo/mooedit/moooutputfilterregex.c @@ -16,6 +16,7 @@ #include "mooedit/moocommand.h" #include "mooedit/mookeyfile.h" #include "mooedit/mooeditprefs.h" +#include "mooedit/moolangmgr.h" #include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-misc.h" #include "mooutils/moomarkup.h" @@ -375,7 +376,7 @@ get_tag (MooLineView *view, MooTextStyle *style = NULL; tag = moo_line_view_create_tag (view, name, NULL); - lang_mgr = moo_editor_get_lang_mgr (moo_editor_instance ()); + lang_mgr = moo_lang_mgr_default (); scheme = moo_lang_mgr_get_active_scheme (lang_mgr); if (scheme) diff --git a/moo/mooedit/mootextview.c b/moo/mooedit/mootextview.c index b6eb5607..a217e868 100644 --- a/moo/mooedit/mootextview.c +++ b/moo/mooedit/mootextview.c @@ -20,6 +20,7 @@ #include "mooedit/mooedit-enums.h" #include "mooedit/mooeditprefs.h" #include "mooedit/mootextbox.h" +#include "mooedit/moolangmgr.h" #include "marshals.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mooundo.h" @@ -2740,7 +2741,7 @@ moo_text_view_set_lang_by_id (MooTextView *view, editor = moo_editor_instance (); g_return_if_fail (editor != NULL); - mgr = moo_editor_get_lang_mgr (editor); + mgr = moo_lang_mgr_default (); lang = moo_lang_mgr_get_lang (mgr, lang_id); scheme = moo_lang_mgr_get_active_scheme (mgr); diff --git a/moo/moopython/Makefile.am b/moo/moopython/Makefile.ug similarity index 99% rename from moo/moopython/Makefile.am rename to moo/moopython/Makefile.ug index ad61094d..5b5fadef 100644 --- a/moo/moopython/Makefile.am +++ b/moo/moopython/Makefile.ug @@ -93,7 +93,7 @@ nodist_libmoopython_la_SOURCES = $(nodist_libmoopython_la_sources) libmoopython_la_LIBADD = $(PYTHON_LIBS) $(PYTHON_EXTRA_LIBS) libmoopython_la_LDFLAGS = $(PYTHON_LDFLAGS) $(PYTHON_EXTRA_LDFLAGS) -EXTRA_DIST = \ +EXTRA_DIST += \ moo-mod.c \ moopython-mod.c \ moopython-builtin.h \ diff --git a/moo/moopython/pygtk/Makefile.incl b/moo/moopython/pygtk/Makefile.incl index a85a5881..082c446a 100644 --- a/moo/moopython/pygtk/Makefile.incl +++ b/moo/moopython/pygtk/Makefile.incl @@ -6,14 +6,13 @@ moopygtk_sources = \ pygtk/mooutils-mod.h \ pygtk/moo-mod.h -BUILT_SOURCES = \ +BUILT_SOURCES += \ pygtk/mooapp-mod.h \ pygtk/mooedit-mod.h \ pygtk/mooutils-mod.h \ pygtk/moo-mod.h nodist_moopygtk_sources = -CLEANFILES = mooedit_defs_files = \ pygtk/mooeditor.defs \ @@ -119,6 +118,11 @@ pygtk/%-mod.h: $(srcdir)/pygtk/%-mod.py $(PY2H) $(SHELL) $(PY2H) `echo $* | tr '[a-z]' '[A-Z]'`_PY $(srcdir)/pygtk/$*-mod.py > $@.tmp && \ mv $@.tmp $@ +UGLY_SUBDIRS += pygtk + +mooeditor.lo mooplugin.lo moocommand.lo: mooedit-pygtk.lo ; @true +moopaned.lo moofileview.lo: mooutils-pygtk.lo ; @true + # noinst_LTLIBRARIES += libmoopygtk.la # # libmoopygtk_la_SOURCES = $(moopygtk_sources) diff --git a/moo/moopython/pygtk/mooedit-pygtk.defs b/moo/moopython/pygtk/mooedit-pygtk.defs index 562e0fa7..d7a4b8a2 100644 --- a/moo/moopython/pygtk/mooedit-pygtk.defs +++ b/moo/moopython/pygtk/mooedit-pygtk.defs @@ -634,6 +634,11 @@ (return-type "MooLangMgr*") ) +(define-function lang_mgr_default + (c-name "moo_lang_mgr_default") + (return-type "MooLangMgr*") +) + (define-method get_available_langs (of-object "MooLangMgr") (c-name "moo_lang_mgr_get_available_langs") diff --git a/moo/moopython/pygtk/mooeditor.defs b/moo/moopython/pygtk/mooeditor.defs index f89b9a5f..969561aa 100644 --- a/moo/moopython/pygtk/mooeditor.defs +++ b/moo/moopython/pygtk/mooeditor.defs @@ -248,12 +248,6 @@ (return-type "MooEditor*") ) -(define-method get_lang_mgr - (of-object "MooEditor") - (c-name "moo_editor_get_lang_mgr") - (return-type "MooLangMgr*") -) - (define-method set_window_type (of-object "MooEditor") (c-name "moo_editor_set_window_type")