diff --git a/moo/mooedit/mooeditor.c b/moo/mooedit/mooeditor.c index e597b836..6aee6627 100644 --- a/moo/mooedit/mooeditor.c +++ b/moo/mooedit/mooeditor.c @@ -87,6 +87,7 @@ static void activate_history_item (MooEditor *editor, struct _MooEditorPrivate { + WindowInfo *windowless; GSList *windows; /* WindowInfo* */ GHashTable *loaders; GHashTable *savers; @@ -222,6 +223,7 @@ static void moo_editor_init (MooEditor *editor) G_CALLBACK (activate_history_item), editor); editor->priv->windows = NULL; + editor->priv->windowless = window_info_new (NULL); editor->priv->loaders = g_hash_table_new_full (g_direct_hash, g_direct_equal, @@ -341,6 +343,8 @@ static void moo_editor_finalize (GObject *object) window_list_free (editor); } + window_info_free (editor->priv->windowless); + g_hash_table_destroy (editor->priv->loaders); g_hash_table_destroy (editor->priv->savers); @@ -622,10 +626,14 @@ window_list_find_doc (MooEditor *editor, { GSList *l = g_slist_find_custom (editor->priv->windows, edit, (GCompareFunc) doc_cmp); + if (l) return l->data; - else - return NULL; + + if (g_slist_find (editor->priv->windowless->docs, edit)) + return editor->priv->windowless; + + return NULL; } @@ -661,10 +669,11 @@ window_list_find_filename (MooEditor *editor, if (edit) *edit = data.edit; return l->data; } - else - { - return NULL; - } + + if (window_info_find (editor->priv->windowless, filename)) + return editor->priv->windowless; + + return NULL; } @@ -735,9 +744,18 @@ moo_editor_add_doc (MooEditor *editor, MooEditLoader *loader, MooEditSaver *saver) { - WindowInfo *info = window_list_find (editor, window); + WindowInfo *info; + + if (window) + { + info = window_list_find (editor, window); + g_return_if_fail (info != NULL); + } + else + { + info = editor->priv->windowless; + } - g_return_if_fail (info != NULL); g_return_if_fail (g_slist_find (info->docs, doc) == NULL); window_info_add (info, doc); @@ -779,6 +797,25 @@ moo_editor_new_window (MooEditor *editor) } +/* this creates MooEdit instance which can not be put into a window */ +MooEdit* +moo_editor_create_doc (MooEditor *editor) +{ + MooEdit *doc; + + g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); + + doc = g_object_new (get_doc_type (editor), "editor", editor, NULL); + + moo_editor_add_doc (editor, NULL, doc, + moo_edit_loader_get_default (), + moo_edit_saver_get_default ()); + _moo_doc_attach_plugins (NULL, doc); + + return doc; +} + + MooEdit* moo_editor_new_doc (MooEditor *editor, MooEditWindow *window) @@ -980,6 +1017,7 @@ moo_editor_set_active_doc (MooEditor *editor, info = window_list_find_doc (editor, doc); g_return_if_fail (info != NULL); + g_return_if_fail (info->window != NULL); gtk_window_present (GTK_WINDOW (info->window)); moo_edit_window_set_active_doc (info->window, doc); @@ -1009,7 +1047,9 @@ moo_editor_close_window (MooEditor *editor, } else if (!modified->next) { - moo_edit_window_set_active_doc (info->window, modified->data); + if (info->window) + moo_edit_window_set_active_doc (info->window, modified->data); + response = moo_edit_save_changes_dialog (modified->data); switch (response) @@ -1101,7 +1141,12 @@ do_close_doc (MooEditor *editor, WindowInfo *info = window_list_find_doc (editor, doc); g_return_if_fail (info != NULL); window_info_remove (info, doc); - _moo_edit_window_remove_doc (info->window, doc); + + if (info->window) + _moo_edit_window_remove_doc (info->window, doc); + else + _moo_doc_detach_plugins (NULL, doc); + g_hash_table_remove (editor->priv->loaders, doc); g_hash_table_remove (editor->priv->savers, doc); } @@ -1145,7 +1190,8 @@ moo_editor_close_docs (MooEditor *editor, if (close_docs_real (editor, list)) { - if (!moo_edit_window_num_docs (info->window) && + if (info->window && + !moo_edit_window_num_docs (info->window) && !editor->priv->allow_empty_window) { MooEdit *doc = g_object_new (get_doc_type (editor), @@ -1184,7 +1230,9 @@ close_docs_real (MooEditor *editor, WindowInfo *info = window_list_find_doc (editor, modified->data); g_return_val_if_fail (info != NULL, FALSE); - moo_edit_window_set_active_doc (info->window, modified->data); + if (info->window) + moo_edit_window_set_active_doc (info->window, modified->data); + response = moo_edit_save_changes_dialog (modified->data); switch (response) diff --git a/moo/mooedit/mooeditor.h b/moo/mooedit/mooeditor.h index e17ff32f..7beb151b 100644 --- a/moo/mooedit/mooeditor.h +++ b/moo/mooedit/mooeditor.h @@ -51,6 +51,9 @@ GType moo_editor_get_type (void) G_GNUC_CONST; MooEditor *moo_editor_instance (void); +/* this creates 'windowless' MooEdit instance */ +MooEdit *moo_editor_create_doc (MooEditor *editor); + MooEditWindow *moo_editor_new_window (MooEditor *editor); MooEdit *moo_editor_new_doc (MooEditor *editor, MooEditWindow *window); diff --git a/moo/mooedit/mooplugin.c b/moo/mooedit/mooplugin.c index b0ab1062..94a567b1 100644 --- a/moo/mooedit/mooplugin.c +++ b/moo/mooedit/mooplugin.c @@ -372,7 +372,7 @@ plugin_attach_doc (MooPlugin *plugin, MooDocPlugin *doc_plugin; GType dtype; - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (doc)); g_return_if_fail (MOO_IS_PLUGIN (plugin)); @@ -414,7 +414,7 @@ plugin_detach_doc (MooPlugin *plugin, MooDocPlugin *doc_plugin; g_return_if_fail (MOO_IS_PLUGIN (plugin)); - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (doc)); if (!moo_plugin_enabled (plugin)) @@ -871,7 +871,7 @@ _moo_doc_attach_plugins (MooEditWindow *window, { GSList *l; - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (doc)); plugin_store_init (); diff --git a/moo/moopython/mooeditor.defs b/moo/moopython/mooeditor.defs index d1bddd9b..154dac52 100644 --- a/moo/moopython/mooeditor.defs +++ b/moo/moopython/mooeditor.defs @@ -18,6 +18,12 @@ ) ) +(define-method create_doc + (of-object "MooEditor") + (c-name "moo_editor_create_doc") + (return-type "MooEdit*") +) + (define-method open (of-object "MooEditor") (c-name "moo_editor_open") diff --git a/moo/moopython/mooplugin-python.c b/moo/moopython/mooplugin-python.c index deb90ef0..67fde548 100644 --- a/moo/moopython/mooplugin-python.c +++ b/moo/moopython/mooplugin-python.c @@ -77,7 +77,7 @@ call_hooks (MooPythonPlugin *plugin, GSList *l; PyObject *py_win, *py_doc; - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (!doc || MOO_IS_EDIT (doc)); g_return_if_fail (type < HOOK_LAST); @@ -134,7 +134,7 @@ void _moo_python_attach_doc (MooEditWindow *window, MooEdit *doc) { - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (doc)); call_hooks (&python_plugin, window, doc, HOOK_NEW_DOC); } @@ -144,7 +144,7 @@ void _moo_python_detach_doc (MooEditWindow *window, MooEdit *doc) { - g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); + g_return_if_fail (!window || MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (doc)); call_hooks (&python_plugin, window, doc, HOOK_CLOSE_DOC); }