From 21bf45b7f732d44a95bc2371b6dc2743ea0d4656 Mon Sep 17 00:00:00 2001 From: Yevgen Muntyan <17531749+muntyan@users.noreply.github.com> Date: Tue, 23 Nov 2010 21:54:39 -0800 Subject: [PATCH] Some refactoring --- .hgignore | 1 + doc/help-sections.h | 1 - doc/script.texi | 1 - moo/medit-app/data/testmedit.lua | 10 - moo/medit-app/run-tests.h | 2 +- moo/mooapp/mooapp.c | 10 +- moo/mooedit/Makefile.incl | 11 +- moo/mooedit/mooedit-fileops.c | 62 +-- moo/mooedit/mooedit-fileops.h | 5 +- moo/mooedit/mooedit-impl.h | 10 - moo/mooedit/mooedit-misc.c | 3 + moo/mooedit/mooedit.c | 325 +----------- moo/mooedit/mooedit.h | 18 +- moo/mooedit/mooeditaction.h | 3 - ...{mooedit-bookmarks.c => mooeditbookmark.c} | 2 +- ...{mooedit-bookmarks.h => mooeditbookmark.h} | 8 +- moo/mooedit/mooeditconfig.c | 6 +- moo/mooedit/mooeditdialogs.c | 219 ++++---- moo/mooedit/mooeditdialogs.h | 16 +- moo/mooedit/mooeditfiltersettings.c | 62 ++- moo/mooedit/mooedithistoryitem.c | 50 ++ moo/mooedit/mooedithistoryitem.h | 17 + moo/mooedit/mooeditor-impl.h | 42 ++ moo/mooedit/mooeditor-private.h | 68 +-- moo/mooedit/mooeditor-tests.c | 265 ++++++++++ .../{mooedit-tests.h => mooeditor-tests.h} | 8 +- moo/mooedit/mooeditor.c | 483 ++++++++---------- moo/mooedit/mooeditor.h | 162 +++--- moo/mooedit/mooeditprefs.c | 29 ++ moo/mooedit/mooeditprefs.h | 3 + moo/mooedit/mooeditprefspage.c | 2 +- moo/mooedit/mooedittypes.h | 28 + moo/mooedit/mooeditwindow-impl.h | 21 + moo/mooedit/mooeditwindow.c | 96 ++-- moo/mooedit/mooeditwindow.h | 85 +-- moo/mooedit/moofileenc.c | 58 +++ moo/mooedit/moofileenc.h | 25 + moo/mooedit/mooindenter.c | 298 ++--------- moo/mooedit/mooindenter.h | 15 +- moo/mooedit/mooplugin-loader.c | 7 +- moo/mooedit/mooplugin-macro.h | 5 +- moo/mooedit/mooplugin.c | 152 ++---- moo/mooedit/mooplugin.h | 5 +- moo/mooedit/mootextview.c | 15 +- moo/moofileview/moofileview.c | 49 +- moo/moofileview/moofileview.h | 4 + moo/mooscript/mooscript-classes-impl.cpp | 209 ++------ moo/mooscript/mooscript.xml | 22 - moo/mooutils/Makefile.incl | 4 +- moo/mooutils/mooaction-private.h | 2 - moo/mooutils/mooaction.h | 2 + moo/mooutils/mooarray.h | 162 ++++-- moo/mooutils/mooatom.h | 9 + moo/mooutils/moofiledialog.c | 50 +- moo/mooutils/moofiledialog.h | 7 +- moo/mooutils/moofileicon.c | 2 +- moo/mooutils/moofileicon.h | 3 +- moo/mooutils/moofileloc.c | 0 ...file-private.h => moofilewriter-private.h} | 10 +- moo/mooutils/moofilewriter.c | 4 +- moo/mooutils/moofilewriter.h | 7 +- moo/mooutils/moomarkup.h | 2 +- moo/mooutils/mooprefs.c | 26 + moo/mooutils/mooprefs.h | 4 + moo/mooutils/mooutils-file.c | 28 + moo/mooutils/mooutils-file.h | 24 + moo/mooutils/mooutils-mem.h | 20 +- moo/mooutils/mooutils-messages.h | 24 + moo/mooutils/mooutils-misc.c | 4 +- moo/mooutils/mooutils.h | 8 + moo/plugins/ctags/ctags-doc.c | 7 +- moo/plugins/ctags/ctags-plugin.c | 2 +- moo/plugins/moofilelist.c | 20 +- moo/plugins/moofileselector.c | 205 ++++---- moo/plugins/moofind.c | 27 +- moo/plugins/mooluaplugin.cpp | 2 +- moo/plugins/moopythonplugin.c | 2 +- moo/plugins/usertools/moocommand.c | 11 +- moo/plugins/usertools/mookeyfile.c | 2 +- moo/plugins/usertools/moousertools.c | 2 +- 80 files changed, 1797 insertions(+), 1883 deletions(-) create mode 100644 moo/mooedit/mooedit-misc.c rename moo/mooedit/{mooedit-bookmarks.c => mooeditbookmark.c} (99%) rename moo/mooedit/{mooedit-bookmarks.h => mooeditbookmark.h} (96%) create mode 100644 moo/mooedit/mooedithistoryitem.c create mode 100644 moo/mooedit/mooedithistoryitem.h create mode 100644 moo/mooedit/mooeditor-impl.h create mode 100644 moo/mooedit/mooeditor-tests.c rename moo/mooedit/{mooedit-tests.h => mooeditor-tests.h} (86%) create mode 100644 moo/mooedit/mooedittypes.h create mode 100644 moo/mooedit/mooeditwindow-impl.h create mode 100644 moo/mooedit/moofileenc.c create mode 100644 moo/mooedit/moofileenc.h create mode 100644 moo/mooutils/moofileloc.c rename moo/mooutils/{mooutils-file-private.h => moofilewriter-private.h} (94%) create mode 100644 moo/mooutils/mooutils-file.c create mode 100644 moo/mooutils/mooutils-file.h create mode 100644 moo/mooutils/mooutils.h diff --git a/.hgignore b/.hgignore index 7f798ec2..2e5f1e6d 100644 --- a/.hgignore +++ b/.hgignore @@ -24,6 +24,7 @@ aclocal.m4 *.orig *.bak *.tmp +*.rej *.pyc .goutputstream-* po*/dist diff --git a/doc/help-sections.h b/doc/help-sections.h index 7c546465..3068b227 100644 --- a/doc/help-sections.h +++ b/doc/help-sections.h @@ -7,7 +7,6 @@ #define HELP_SECTION_DIALOG_FIND_IN_FILES "index.html" #define HELP_SECTION_DIALOG_REPLACE "index.html" #define HELP_SECTION_DOCUMENT "Document-object.html" -#define HELP_SECTION_DOCUMENT_VIEW "DocumentView-object.html" #define HELP_SECTION_EDITING_OPTIONS "Options-for-editing-text.html" #define HELP_SECTION_FILE_SELECTOR "index.html" #define HELP_SECTION_LICENSE_GPL "GNU-GPL.html" diff --git a/doc/script.texi b/doc/script.texi index 4fc96209..d924edd0 100644 --- a/doc/script.texi +++ b/doc/script.texi @@ -18,7 +18,6 @@ * Application object:: Application object * Editor object:: Editor object * DocumentWindow object:: DocumentWindow object -* DocumentView object:: DocumentView object * Document object:: Document object @end menu diff --git a/moo/medit-app/data/testmedit.lua b/moo/medit-app/data/testmedit.lua index 98f413ca..2ad1c28e 100644 --- a/moo/medit-app/data/testmedit.lua +++ b/moo/medit-app/data/testmedit.lua @@ -65,16 +65,6 @@ abcdefghij tassert(doc.selected_text() == 'abcdefg\n') end -local function test_views() - doc = editor.new_document() - add_doc_to_cleanup(doc) - window = doc.active_view().window() - tassert(doc.active_view() ~= nil) - tassert(#doc.views() == 1) - tassert(doc.views()[1] == doc.active_view()) -end - test_active_window() test_selection() -test_views() cleanup() diff --git a/moo/medit-app/run-tests.h b/moo/medit-app/run-tests.h index 40affa72..44c8661d 100644 --- a/moo/medit-app/run-tests.h +++ b/moo/medit-app/run-tests.h @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/moo/mooapp/mooapp.c b/moo/mooapp/mooapp.c index 04fcddf1..90e268e5 100644 --- a/moo/mooapp/mooapp.c +++ b/moo/mooapp/mooapp.c @@ -554,21 +554,21 @@ moo_app_get_editor (MooApp *app) static gboolean close_editor_window (MooApp *app) { - GSList *windows; + MooEditWindowArray *windows; gboolean ret = FALSE; if (!app->priv->running || app->priv->in_try_quit) return FALSE; - windows = moo_editor_list_windows (app->priv->editor); + windows = moo_editor_get_windows (app->priv->editor); - if (windows && !windows->next) + if (moo_edit_window_array_get_size (windows) == 1) { moo_app_quit (app); ret = TRUE; } - g_slist_free (windows); + moo_edit_window_array_free (windows); return ret; } @@ -582,7 +582,7 @@ init_plugins (MooApp *app) static void moo_app_init_editor (MooApp *app) { - app->priv->editor = moo_editor_create_instance (FALSE); + app->priv->editor = moo_editor_create (FALSE); g_signal_connect_swapped (app->priv->editor, "close-window", G_CALLBACK (close_editor_window), app); diff --git a/moo/mooedit/Makefile.incl b/moo/mooedit/Makefile.incl index 3a57ee73..007c7f68 100644 --- a/moo/mooedit/Makefile.incl +++ b/moo/mooedit/Makefile.incl @@ -4,8 +4,8 @@ moo_sources += \ mooedit/mooeditaction-factory.c \ mooedit/mooeditaction-factory.h \ mooedit/mooeditaction.h \ - mooedit/mooedit-bookmarks.c \ - mooedit/mooedit-bookmarks.h \ + mooedit/mooeditbookmark.c \ + mooedit/mooeditbookmark.h \ mooedit/mooedit.c \ mooedit/mooedit.h \ mooedit/mooeditconfig.c \ @@ -19,14 +19,19 @@ moo_sources += \ mooedit/mooedit-impl.h \ mooedit/mooeditor.c \ mooedit/mooeditor.h \ + mooedit/mooeditor-impl.h \ mooedit/mooeditor-private.h \ + mooedit/mooeditor-tests.c \ + mooedit/mooeditor-tests.h \ mooedit/mooeditprefs.c \ mooedit/mooeditprefs.h \ mooedit/mooeditprefspage.c \ mooedit/mooedit-private.h \ - mooedit/mooedit-tests.h \ + mooedit/mooeditor-tests.h \ mooedit/mooeditwindow.c \ mooedit/mooeditwindow.h \ + mooedit/moofileenc.c \ + mooedit/moofileenc.h \ mooedit/moofold.c \ mooedit/moofold.h \ mooedit/mooindenter.c \ diff --git a/moo/mooedit/mooedit-fileops.c b/moo/mooedit/mooedit-fileops.c index 4cc4d19f..89618929 100644 --- a/moo/mooedit/mooedit-fileops.c +++ b/moo/mooedit/mooedit-fileops.c @@ -19,7 +19,7 @@ #define MOOEDIT_COMPILATION #include "mooedit/mooedit-private.h" -#include "mooedit/mooeditor-private.h" +#include "mooedit/mooeditor-impl.h" #include "mooedit/mooedit-fileops.h" #include "mooedit/mooeditdialogs.h" #include "mooedit/mootextbuffer.h" @@ -261,27 +261,6 @@ static LoadResult load_binary (MooEdit *edit, GError **error); #endif -const char * -_moo_get_default_encodings (void) -{ - /* Translators: if translated, it should be a comma-separated list - of encodings to try when opening files. Encodings names should be - those understood by iconv, or "LOCALE" which means user's locale - charset. For instance, the default value is "UTF-8,LOCALE,ISO_8859-15,ISO_8859-1". - You want to add common preferred non-UTF8 encodings used in your locale. - Do not remove ISO_8859-15 and ISO_8859-1, instead leave them at the end, - these are common source files encodings. */ - const char *to_translate = N_("encodings_list"); - const char *encodings; - - encodings = _(to_translate); - - if (!strcmp (encodings, to_translate)) - encodings = "UTF-8," ENCODING_LOCALE ",ISO_8859-1,ISO_8859-15"; - - return encodings; -} - static GSList * get_encodings (void) { @@ -395,7 +374,7 @@ moo_edit_load_local (MooEdit *edit, MooLineEndType saved_le; moo_return_val_if_fail (MOO_IS_EDIT (edit), FALSE); - moo_return_val_if_fail (file != NULL, FALSE); + moo_return_val_if_fail (G_IS_FILE (file), FALSE); if (!check_regular (file, error)) return FALSE; @@ -753,8 +732,8 @@ moo_edit_reload_local (MooEdit *edit, gboolean result, enable_highlight; GFile *file; - file = _moo_edit_get_file (edit); - moo_return_val_if_fail (file != NULL, FALSE); + file = moo_edit_get_file (edit); + moo_return_val_if_fail (G_IS_FILE (file), FALSE); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit)); @@ -1233,29 +1212,15 @@ add_untitled (MooEdit *edit) } -const char * -_moo_edit_get_default_encoding (void) -{ - return moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_ENCODING_SAVE)); -} - - -char * -_moo_file_get_display_name (GFile *file) -{ - moo_return_val_if_fail (G_IS_FILE (file), NULL); - return g_file_get_parse_name (file); -} - -char * -_moo_file_get_display_basename (GFile *file) +static char * +moo_file_get_display_basename (GFile *file) { char *name; const char *slash; moo_return_val_if_fail (G_IS_FILE (file), NULL); - name = _moo_file_get_display_name (file); + name = moo_file_get_display_name (file); moo_return_val_if_fail (name != NULL, NULL); slash = strrchr (name, '/'); @@ -1339,8 +1304,8 @@ _moo_edit_set_file (MooEdit *edit, edit->priv->norm_filename = _moo_edit_normalize_filename_for_comparison (norm_name_tmp); free_list = g_slist_prepend (free_list, norm_name_tmp); - edit->priv->display_filename = _moo_file_get_display_name (file); - edit->priv->display_basename = _moo_file_get_display_basename (file); + edit->priv->display_filename = moo_file_get_display_name (file); + edit->priv->display_basename = moo_file_get_display_basename (file); } if (!encoding) @@ -1351,8 +1316,7 @@ _moo_edit_set_file (MooEdit *edit, g_signal_emit_by_name (edit, "filename-changed", edit->priv->filename, NULL); moo_edit_status_changed (edit); - if (tmp) - g_object_unref (tmp); + moo_file_free (tmp); g_slist_foreach (free_list, (GFunc) g_free, NULL); g_slist_free (free_list); @@ -1365,9 +1329,9 @@ _moo_edit_get_icon (MooEdit *doc, GtkIconSize size) { if (doc->priv->filename) - return moo_get_icon_for_file (doc->priv->filename, widget, size); + return moo_get_icon_for_path (doc->priv->filename, widget, size); else if (doc->priv->file) - return moo_get_icon_for_file (doc->priv->display_basename, widget, size); + return moo_get_icon_for_path (doc->priv->display_basename, widget, size); else - return moo_get_icon_for_file (NULL, widget, size); + return moo_get_icon_for_path (NULL, widget, size); } diff --git a/moo/mooedit/mooedit-fileops.h b/moo/mooedit/mooedit-fileops.h index e3719134..9aec45d5 100644 --- a/moo/mooedit/mooedit-fileops.h +++ b/moo/mooedit/mooedit-fileops.h @@ -50,7 +50,7 @@ gboolean _moo_edit_reload_file (MooEdit *edit, const char *encoding, GError **error); gboolean _moo_edit_save_file (MooEdit *edit, - GFile *file, + GFile *floc, const char *encoding, MooEditSaveFlags flags, GError **error); @@ -60,9 +60,6 @@ gboolean _moo_edit_save_file_copy (MooEdit *edit, MooEditSaveFlags flags, GError **error); -char *_moo_file_get_display_name (GFile *file); -char *_moo_file_get_display_basename (GFile *file); - G_END_DECLS diff --git a/moo/mooedit/mooedit-impl.h b/moo/mooedit/mooedit-impl.h index 6552d3b2..a1cde744 100644 --- a/moo/mooedit/mooedit-impl.h +++ b/moo/mooedit/mooedit-impl.h @@ -20,18 +20,10 @@ #include "mooedit/mooeditor.h" #include "mooedit/mootextview.h" #include "mooutils/mdhistorymgr.h" -#include "mooutils/moolist.h" #include G_BEGIN_DECLS -struct MooEditFileInfo { - GFile *file; - char *encoding; -}; - -MOO_DEFINE_SLIST(MooEditList, moo_edit_list, MooEdit) - extern MooEditList *_moo_edit_instances; void _moo_edit_add_class_actions (MooEdit *edit); @@ -92,8 +84,6 @@ void _moo_edit_apply_prefs (MooEdit *edit); /* File operations */ -GFile *_moo_edit_get_file (MooEdit *edit); - void _moo_edit_set_file (MooEdit *edit, GFile *file, const char *encoding); diff --git a/moo/mooedit/mooedit-misc.c b/moo/mooedit/mooedit-misc.c new file mode 100644 index 00000000..acf82145 --- /dev/null +++ b/moo/mooedit/mooedit-misc.c @@ -0,0 +1,3 @@ +#define MOOEDIT_COMPILATION +#include "mooedit-priv.h" + diff --git a/moo/mooedit/mooedit.c b/moo/mooedit/mooedit.c index fb2e16b7..ccd60a41 100644 --- a/moo/mooedit/mooedit.c +++ b/moo/mooedit/mooedit.c @@ -16,15 +16,14 @@ #define MOOEDIT_COMPILATION #include "mooedit/mooeditaction-factory.h" #include "mooedit/mooedit-private.h" -#include "mooedit/mooedit-bookmarks.h" +#include "mooedit/mooeditbookmark.h" #include "mooedit/mootextview-private.h" #include "mooedit/mooeditdialogs.h" #include "mooedit/mooeditprefs.h" #include "mooedit/mootextbuffer.h" #include "mooedit/mooeditfiltersettings.h" -#include "mooedit/mooeditor-private.h" +#include "mooedit/mooeditor-impl.h" #include "mooedit/moolangmgr.h" -#include "mooedit/mooedit-tests.h" #include "marshals.h" #include "mooutils/mooutils-fs.h" #include "mooutils/mooi18n.h" @@ -36,10 +35,10 @@ #include #include - #define KEY_ENCODING "encoding" #define KEY_LINE "line" +MOO_DEFINE_OBJECT_ARRAY (MooEditArray, moo_edit_array, MooEdit) MooEditList *_moo_edit_instances = NULL; @@ -118,7 +117,6 @@ enum { PROP_ENCODING }; -MOO_DEFINE_BOXED_TYPE_C (MooEditFileInfo, moo_edit_file_info) G_DEFINE_TYPE (MooEdit, moo_edit, MOO_TYPE_TEXT_VIEW) @@ -328,8 +326,7 @@ moo_edit_finalize (GObject *object) { MooEdit *edit = MOO_EDIT (object); - if (edit->priv->file) - g_object_unref (edit->priv->file); + moo_file_free (edit->priv->file); g_free (edit->priv->filename); g_free (edit->priv->norm_filename); g_free (edit->priv->display_filename); @@ -633,52 +630,8 @@ moo_edit_focus_out (GtkWidget *widget, } -static MooEditFileInfo * -moo_edit_file_info_new (GFile *file, - const char *encoding) -{ - MooEditFileInfo *info = moo_new (MooEditFileInfo); - info->file = file; - info->encoding = g_strdup (encoding); - return info; -} - -MooEditFileInfo * -moo_edit_file_info_new_path (const char *path, - const char *encoding) -{ - g_return_val_if_fail (path != NULL, NULL); - return moo_edit_file_info_new (g_file_new_for_path (path), encoding); -} - -MooEditFileInfo * -moo_edit_file_info_new_uri (const char *uri, - const char *encoding) -{ - g_return_val_if_fail (uri != NULL, NULL); - return moo_edit_file_info_new (g_file_new_for_uri (uri), encoding); -} - -MooEditFileInfo * -moo_edit_file_info_copy (MooEditFileInfo *info) -{ - return info ? moo_edit_file_info_new ((GFile*) g_object_ref (info->file), info->encoding) : NULL; -} - -void -moo_edit_file_info_free (MooEditFileInfo *info) -{ - if (info) - { - g_free (info->encoding); - g_object_unref (info->file); - moo_free (MooEditFileInfo, info); - } -} - - GFile * -_moo_edit_get_file (MooEdit *edit) +moo_edit_get_file (MooEdit *edit) { g_return_val_if_fail (MOO_IS_EDIT (edit), NULL); return edit->priv->file ? g_file_dup (edit->priv->file) : NULL; @@ -1063,6 +1016,13 @@ config_changed (MooEdit *edit, } +MooLang * +moo_edit_get_lang (MooEdit *doc) +{ + g_return_val_if_fail (MOO_IS_EDIT (doc), NULL); + return moo_text_view_get_lang (MOO_TEXT_VIEW (doc)); +} + static void moo_edit_set_lang (MooEdit *edit, MooLang *lang) @@ -1984,264 +1944,3 @@ moo_edit_ui_set_show_line_numbers (MooEdit *doc, "show-line-numbers", show, (char*) NULL); } - - -static struct { - char *working_dir; - char *encodings_dir; -} test_data; - -#ifdef __WIN32__ -#define LE "\r\n" -#else -#define LE "\n" -#endif - -#define TT1 "blah blah blah" -#define TT2 "blah blah blah" LE "blah blah blah" -#define TT3 LE LE LE LE -#define TT4 "lala\nlala\n" -#define TT5 "lala\r\nlala\r\n" -#define TT6 "lala\rlala\r" - -static void -check_contents (const char *filename, - const char *expected) -{ - char *contents; - GError *error = NULL; - - if (!g_file_get_contents (filename, &contents, NULL, &error)) - { - TEST_FAILED_MSG ("could not load file '%s': %s", - filename, error->message); - g_error_free (error); - return; - } - - TEST_ASSERT_STR_EQ (contents, expected); - - g_free (contents); -} - -static void -test_basic (void) -{ - MooEditor *editor; - MooEdit *doc, *doc2; - GtkTextBuffer *buffer; - char *filename; - - editor = moo_editor_instance (); - filename = g_build_filename (test_data.working_dir, "test.txt", NULL); - doc = moo_editor_new_file (editor, NULL, NULL, filename, NULL); - TEST_ASSERT (doc != NULL); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, ""); - - buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (doc)); - - gtk_text_buffer_set_text (buffer, TT1, -1); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT1); - - gtk_text_buffer_set_text (buffer, TT2, -1); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT2); - - gtk_text_buffer_set_text (buffer, TT2 LE, -1); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT2 LE); - - gtk_text_buffer_set_text (buffer, TT3, -1); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT3); - - doc2 = moo_editor_open_file (editor, NULL, NULL, filename, NULL); - TEST_ASSERT (doc2 == doc); - - TEST_ASSERT (moo_edit_close (doc, TRUE)); - TEST_ASSERT (moo_editor_get_doc (editor, filename) == NULL); - - g_file_set_contents (filename, TT4, -1, NULL); - doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL); - TEST_ASSERT (doc != NULL); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT4); - TEST_ASSERT (moo_edit_close (doc, TRUE)); - - g_file_set_contents (filename, TT5, -1, NULL); - doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL); - TEST_ASSERT (doc != NULL); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT5); - TEST_ASSERT (moo_edit_close (doc, TRUE)); - - g_file_set_contents (filename, TT6, -1, NULL); - doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL); - TEST_ASSERT (doc != NULL); - TEST_ASSERT (moo_edit_save (doc, NULL)); - check_contents (filename, TT6); - TEST_ASSERT (moo_edit_close (doc, TRUE)); - - g_free (filename); -} - -#define TEST_ASSERT_SAME_FILE_CONTENT(filename1, filename2) \ -{ \ - char *contents1__ = NULL; \ - char *contents2__ = NULL; \ - g_file_get_contents (filename1, &contents1__, NULL, NULL); \ - g_file_get_contents (filename2, &contents2__, NULL, NULL); \ - if (!contents1__) \ - moo_test_assert_msg (FALSE, __FILE__, __LINE__, \ - "could not open file %s", \ - filename1); \ - if (!contents2__) \ - moo_test_assert_msg (FALSE, __FILE__, __LINE__, \ - "could not open file %s", \ - filename2); \ - if (contents1__ && contents2__) \ - { \ - gboolean equal = strcmp (contents1__, contents2__) == 0; \ - TEST_ASSERT_MSG (equal, "contents of %s and %s differ", \ - filename1, filename2); \ - } \ - g_free (contents2__); \ - g_free (contents1__); \ -} - -static void -test_encodings_1 (const char *name, - const char *working_dir) -{ - char *filename; - char *filename2; - char *encoding; - const char *dot; - MooEditor *editor; - MooEdit *doc; - - if ((dot = strchr (name, '.'))) - encoding = g_strndup (name, dot - name); - else - encoding = g_strdup (name); - - filename = g_build_filename (test_data.encodings_dir, name, (char*)0); - filename2 = g_build_filename (working_dir, name, (char*)0); - - editor = moo_editor_instance (); - doc = moo_editor_open_file (editor, NULL, NULL, filename, encoding); - TEST_ASSERT_MSG (doc != NULL, - "file '%s', encoding '%s'", - TEST_FMT_STR (filename), - TEST_FMT_STR (encoding)); - - if (doc) - { - TEST_ASSERT (moo_edit_save_as (doc, filename2, NULL, NULL)); - TEST_ASSERT_SAME_FILE_CONTENT (filename2, filename); - TEST_ASSERT (moo_edit_close (doc, TRUE)); - } - - g_free (encoding); - g_free (filename2); - g_free (filename); -} - -static void -test_encodings (void) -{ - GDir *dir; - const char *name; - char *working_dir; - - dir = g_dir_open (test_data.encodings_dir, 0, NULL); - - if (!dir) - { - g_critical ("could not open encodings dir"); - TEST_ASSERT (FALSE); - return; - } - - working_dir = g_build_filename (test_data.working_dir, "encodings", (char*)0); - _moo_mkdir_with_parents (working_dir); - - while ((name = g_dir_read_name (dir))) - test_encodings_1 (name, working_dir); - - g_free (working_dir); - g_dir_close (dir); -} - -static gboolean -test_suite_init (G_GNUC_UNUSED gpointer data) -{ - test_data.working_dir = g_build_filename (moo_test_get_working_dir (), - "editor-work", (char*)0); - test_data.encodings_dir = g_build_filename (moo_test_get_data_dir (), - "encodings", (char*)0); - - if (_moo_mkdir_with_parents (test_data.working_dir) != 0) - { - g_critical ("could not create directory '%s'", - test_data.working_dir); - g_free (test_data.working_dir); - test_data.working_dir = NULL; - return FALSE; - } - - return TRUE; -} - -static void -test_suite_cleanup (G_GNUC_UNUSED gpointer data) -{ - char *recent_file; - MooEditor *editor; - GError *error = NULL; - - if (!_moo_remove_dir (test_data.working_dir, TRUE, &error)) - { - g_critical ("could not remove directory '%s': %s", - test_data.working_dir, error->message); - g_error_free (error); - error = NULL; - } - - g_free (test_data.working_dir); - g_free (test_data.encodings_dir); - test_data.working_dir = NULL; - test_data.encodings_dir = NULL; - - editor = moo_editor_instance (); -// moo_editor_close_all (editor, FALSE, FALSE); - recent_file = _md_history_mgr_get_filename (_moo_editor_get_history_mgr (editor)); - - if (!g_file_test (recent_file, G_FILE_TEST_EXISTS)) - g_critical ("recent file %s does not exist", recent_file); - -// cache_dir = moo_get_user_cache_dir (); -// if (!_moo_remove_dir (cache_dir, TRUE, &error)) -// { -// g_critical ("could not remove directory '%s': %s", -// cache_dir, error->message); -// g_error_free (error); -// error = NULL; -// } - - g_free (recent_file); -} - -void -moo_test_editor (void) -{ - MooTestSuite *suite = moo_test_suite_new ("Editor", - "Editor tests", - test_suite_init, - test_suite_cleanup, - NULL); - moo_test_suite_add_test (suite, "basic", "basic editor functionality", (MooTestFunc) test_basic, NULL); - moo_test_suite_add_test (suite, "encodings", "character encoding handling", (MooTestFunc) test_encodings, NULL); -} diff --git a/moo/mooedit/mooedit.h b/moo/mooedit/mooedit.h index cff122c1..9772cf9d 100644 --- a/moo/mooedit/mooedit.h +++ b/moo/mooedit/mooedit.h @@ -19,6 +19,7 @@ #include #include #include +#include #include G_BEGIN_DECLS @@ -37,7 +38,6 @@ G_BEGIN_DECLS #define MOO_EDIT_IS_CLEAN(edit) (moo_edit_get_status (edit) & MOO_EDIT_CLEAN) #define MOO_EDIT_IS_BUSY(edit) (moo_edit_get_state (edit) != MOO_EDIT_STATE_NORMAL) -typedef struct MooEdit MooEdit; typedef struct MooEditPrivate MooEditPrivate; typedef struct MooEditClass MooEditClass; @@ -73,6 +73,10 @@ struct MooEditClass GType moo_edit_get_type (void) G_GNUC_CONST; GType moo_edit_file_info_get_type (void) G_GNUC_CONST; +MooEditWindow *moo_edit_get_window (MooEdit *edit); + +GFile *moo_edit_get_file (MooEdit *edit); + char *moo_edit_get_uri (MooEdit *edit); char *moo_edit_get_filename (MooEdit *edit); char *moo_edit_get_norm_filename (MooEdit *edit); @@ -85,6 +89,10 @@ void moo_edit_set_encoding (MooEdit *edit, char *moo_edit_get_utf8_filename (MooEdit *edit); +MooLang *moo_edit_get_lang (MooEdit *edit); + +MooEditor *moo_edit_get_editor (MooEdit *doc); + #ifdef __WIN32__ #define MOO_LE_DEFAULT MOO_LE_WIN32 #else @@ -125,14 +133,6 @@ gboolean moo_edit_save_copy (MooEdit *edit, void moo_edit_comment (MooEdit *edit); void moo_edit_uncomment (MooEdit *edit); -typedef struct MooEditFileInfo MooEditFileInfo; -MooEditFileInfo *moo_edit_file_info_new_path (const char *path, - const char *encoding); -MooEditFileInfo *moo_edit_file_info_new_uri (const char *uri, - const char *encoding); -MooEditFileInfo *moo_edit_file_info_copy (MooEditFileInfo *info); -void moo_edit_file_info_free (MooEditFileInfo *info); - void moo_edit_ui_set_line_wrap_mode (MooEdit *edit, gboolean enabled); void moo_edit_ui_set_show_line_numbers (MooEdit *edit, diff --git a/moo/mooedit/mooeditaction.h b/moo/mooedit/mooeditaction.h index da104d43..2e6eeda5 100644 --- a/moo/mooedit/mooeditaction.h +++ b/moo/mooedit/mooeditaction.h @@ -54,9 +54,6 @@ GType moo_edit_action_get_type (void) G_GNUC_CONST; MooEdit *moo_edit_action_get_doc (MooEditAction *action); -/* defined in mooeditwindow.c */ -GSList *_moo_edit_parse_langs (const char *string); - G_END_DECLS diff --git a/moo/mooedit/mooedit-bookmarks.c b/moo/mooedit/mooeditbookmark.c similarity index 99% rename from moo/mooedit/mooedit-bookmarks.c rename to moo/mooedit/mooeditbookmark.c index accd1892..281b4b8e 100644 --- a/moo/mooedit/mooedit-bookmarks.c +++ b/moo/mooedit/mooeditbookmark.c @@ -14,7 +14,7 @@ */ #define MOOEDIT_COMPILATION -#include "mooedit/mooedit-bookmarks.h" +#include "mooedit/mooeditbookmark.h" #include "mooedit/mooedit-private.h" #include "mooedit/mootextbuffer.h" #include "mooutils/moostock.h" diff --git a/moo/mooedit/mooedit-bookmarks.h b/moo/mooedit/mooeditbookmark.h similarity index 96% rename from moo/mooedit/mooedit-bookmarks.h rename to moo/mooedit/mooeditbookmark.h index c2ed3a87..e6888eb4 100644 --- a/moo/mooedit/mooedit-bookmarks.h +++ b/moo/mooedit/mooeditbookmark.h @@ -1,5 +1,5 @@ /* - * mooedit-bookmarks.h + * mooeditbookmark.h * * Copyright (C) 2004-2010 by Yevgen Muntyan * @@ -13,8 +13,8 @@ * License along with medit. If not, see . */ -#ifndef MOO_EDIT_BOOKMARKS_H -#define MOO_EDIT_BOOKMARKS_H +#ifndef MOO_EDIT_BOOKMARK_H +#define MOO_EDIT_BOOKMARK_H #include #include @@ -74,4 +74,4 @@ char *_moo_edit_bookmark_get_text (MooEditBookmark *bookmark); G_END_DECLS -#endif /* MOO_EDIT_BOOKMARKS_H */ +#endif /* MOO_EDIT_BOOKMARK_H */ diff --git a/moo/mooedit/mooeditconfig.c b/moo/mooedit/mooeditconfig.c index 519678c4..47df067c 100644 --- a/moo/mooedit/mooeditconfig.c +++ b/moo/mooedit/mooeditconfig.c @@ -105,7 +105,7 @@ moo_edit_config_init (MooEditConfig *config) config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, MOO_TYPE_EDIT_CONFIG, MooEditConfigPrivate); - MOO_IP_ARRAY_INIT (config->priv, values, vars->len); + MOO_IP_ARRAY_INIT (Value, config->priv, values, vars->len); if (global) { @@ -231,7 +231,7 @@ update_prop_from_global (MooEditConfig *config, if (prop_id == config->priv->n_values) { - MOO_IP_ARRAY_GROW (config->priv, values, 1); + MOO_IP_ARRAY_GROW (Value, config->priv, values, 1); g_value_init (GVALUE (config, prop_id), G_VALUE_TYPE (GVALUE (global, prop_id))); VALUE (config, prop_id)->source = VALUE (global, prop_id)->source; @@ -270,7 +270,7 @@ global_add_prop (GParamSpec *pspec, { g_assert (global->priv->n_values == prop_id); - MOO_IP_ARRAY_GROW (global->priv, values, 1); + MOO_IP_ARRAY_GROW (Value, global->priv, values, 1); g_value_init (GVALUE (global, prop_id), G_PARAM_SPEC_VALUE_TYPE (pspec)); g_param_value_set_default (pspec, GVALUE (global, prop_id)); diff --git a/moo/mooedit/mooeditdialogs.c b/moo/mooedit/mooeditdialogs.c index aff4c10c..7035b9b9 100644 --- a/moo/mooedit/mooeditdialogs.c +++ b/moo/mooedit/mooeditdialogs.c @@ -17,10 +17,12 @@ #include "mooedit/mooeditdialogs.h" #include "mooedit/mooeditprefs.h" #include "mooedit/mooedit-fileops.h" +#include "mooedit/moofileenc.h" #include "mooutils/moodialogs.h" #include "mooutils/moostock.h" #include "mooutils/mooi18n.h" #include "mooutils/mooencodings.h" +#include "mooutils/mooutils.h" #include "mootextfind-prompt-gxml.h" #include "mooeditsavemult-gxml.h" #include @@ -28,37 +30,34 @@ #include -GSList * +MooFileEncArray * _moo_edit_open_dialog (GtkWidget *widget, MooEdit *current_doc) { MooFileDialog *dialog; - const char *start_dir = NULL; const char *encoding; - char *new_start; - char *freeme = NULL; - char **filenames = NULL, **p; - GSList *infos = NULL; + GFile *start = NULL; + MooFileArray *files = NULL; + MooFileEncArray *fencs = NULL; + guint i; moo_prefs_create_key (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), MOO_PREFS_STATE, G_TYPE_STRING, NULL); if (current_doc && moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC))) { - char *filename = moo_edit_get_filename (current_doc); + GFile *file = moo_edit_get_file (current_doc); - if (filename) - { - freeme = g_path_get_dirname (filename); - start_dir = freeme; - g_free (filename); - } + if (file) + start = g_file_get_parent (file); + + g_object_unref (file); } - if (!start_dir) - start_dir = moo_prefs_get_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR)); + if (!start) + start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR)); dialog = moo_file_dialog_new (MOO_FILE_DIALOG_OPEN, widget, - TRUE, GTK_STOCK_OPEN, start_dir, + TRUE, GTK_STOCK_OPEN, start, NULL); g_object_set (dialog, "enable-encodings", TRUE, NULL); moo_file_dialog_set_help_id (dialog, "dialog-open"); @@ -66,67 +65,64 @@ _moo_edit_open_dialog (GtkWidget *widget, moo_file_dialog_set_filter_mgr_id (dialog, "MooEdit"); - if (!moo_file_dialog_run (dialog)) - goto out; + if (moo_file_dialog_run (dialog)) + { + encoding = moo_file_dialog_get_encoding (dialog); - encoding = moo_file_dialog_get_encoding (dialog); + if (encoding && !strcmp (encoding, MOO_ENCODING_AUTO)) + encoding = NULL; - if (encoding && !strcmp (encoding, MOO_ENCODING_AUTO)) - encoding = NULL; + files = moo_file_dialog_get_files (dialog); + g_return_val_if_fail (files != NULL && files->n_elms != 0, NULL); - filenames = moo_file_dialog_get_filenames (dialog); - g_return_val_if_fail (filenames != NULL, NULL); + fencs = moo_file_enc_array_new (); + for (i = 0; i < files->n_elms; ++i) + moo_file_enc_array_take (fencs, moo_file_enc_new (files->elms[i], encoding)); - for (p = filenames; *p != NULL; ++p) - infos = g_slist_prepend (infos, moo_edit_file_info_new_path (*p, encoding)); - infos = g_slist_reverse (infos); + g_object_unref (start); + start = g_file_get_parent (files->elms[0]); + moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start); + } - new_start = g_path_get_dirname (filenames[0]); - moo_prefs_set_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), new_start); - g_free (new_start); - -out: - g_free (freeme); + g_object_unref (start); g_object_unref (dialog); - g_strfreev (filenames); - return infos; + moo_file_array_free (files); + return fencs; } -MooEditFileInfo * -_moo_edit_save_as_dialog (MooEdit *edit, +MooFileEnc * +_moo_edit_save_as_dialog (MooEdit *doc, const char *display_basename) { - const char *start = NULL; - char *filename = NULL; - char *freeme = NULL; const char *encoding; - char *new_start; MooFileDialog *dialog; - MooEditFileInfo *file_info; + MooFileEnc *fenc; + GFile *start = NULL; + GFile *file = NULL; + + g_return_val_if_fail (MOO_IS_EDIT (doc), NULL); moo_prefs_create_key (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), MOO_PREFS_STATE, G_TYPE_STRING, NULL); if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC))) { - char *this_filename = moo_edit_get_filename (edit); - - if (this_filename) - { - freeme = g_path_get_dirname (this_filename); - start = freeme; - g_free (this_filename); - } + file = moo_edit_get_file (doc); + if (file) + start = g_file_get_parent (file); + g_object_unref (file); + file = NULL; } if (!start) - start = moo_prefs_get_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR)); + start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR)); - dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE, GTK_WIDGET (edit), - FALSE, GTK_STOCK_SAVE_AS, start, display_basename); + dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE, GTK_WIDGET (doc), + FALSE, GTK_STOCK_SAVE_AS, + start, display_basename); g_object_set (dialog, "enable-encodings", TRUE, NULL); - moo_file_dialog_set_encoding (dialog, moo_edit_get_encoding (edit)); + moo_file_dialog_set_encoding (dialog, moo_edit_get_encoding (doc)); moo_file_dialog_set_help_id (dialog, "dialog-save"); moo_file_dialog_set_filter_mgr_id (dialog, "MooEdit"); @@ -134,32 +130,32 @@ _moo_edit_save_as_dialog (MooEdit *edit, if (!moo_file_dialog_run (dialog)) { g_object_unref (dialog); - g_free (freeme); + g_object_unref (start); return NULL; } encoding = moo_file_dialog_get_encoding (dialog); - filename = moo_file_dialog_get_filename (dialog); - g_return_val_if_fail (filename != NULL, NULL); - file_info = moo_edit_file_info_new_path (filename, encoding); + file = moo_file_dialog_get_file (dialog); + g_return_val_if_fail (file != NULL, NULL); + fenc = moo_file_enc_new (file, encoding); - new_start = g_path_get_dirname (filename); - moo_prefs_set_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), new_start); - g_free (new_start); + g_object_unref (start); + start = g_file_get_parent (file); + moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start); - g_free (filename); + g_object_unref (start); + g_object_unref (file); g_object_unref (dialog); - g_free (freeme); - return file_info; + return fenc; } MooSaveChangesDialogResponse -_moo_edit_save_changes_dialog (MooEdit *edit) +_moo_edit_save_changes_dialog (MooEdit *doc) { - g_return_val_if_fail (MOO_IS_EDIT (edit), MOO_SAVE_CHANGES_RESPONSE_CANCEL); - return moo_save_changes_dialog (moo_edit_get_display_basename (edit), - GTK_WIDGET (edit)); + g_return_val_if_fail (MOO_IS_EDIT (doc), MOO_SAVE_CHANGES_RESPONSE_CANCEL); + return moo_save_changes_dialog (moo_edit_get_display_basename (doc), + GTK_WIDGET (doc)); } @@ -179,13 +175,13 @@ name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *column, GtkTreeModel *model, GtkTreeIter *iter) { - MooEdit *edit = NULL; + MooEdit *doc = NULL; - gtk_tree_model_get (model, iter, COLUMN_EDIT, &edit, -1); - g_return_if_fail (MOO_IS_EDIT (edit)); + gtk_tree_model_get (model, iter, COLUMN_EDIT, &doc, -1); + g_return_if_fail (MOO_IS_EDIT (doc)); - g_object_set (cell, "text", moo_edit_get_display_basename (edit), NULL); - g_object_unref (edit); + g_object_set (cell, "text", moo_edit_get_display_basename (doc), NULL); + g_object_unref (doc); } @@ -244,22 +240,23 @@ save_toggled (GtkCellRendererToggle *cell, } static void -files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, GSList *docs) +files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, MooEditArray *docs) { GtkListStore *store; GtkTreeViewColumn *column; GtkCellRenderer *cell; - GSList *l; + guint i; store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_BOOLEAN, MOO_TYPE_EDIT); - for (l = docs; l != NULL; l = l->next) + for (i = 0; i < docs->n_elms; ++i) { GtkTreeIter iter; gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COLUMN_SAVE, TRUE, - COLUMN_EDIT, l->data, -1); + COLUMN_EDIT, docs->elms[i], + -1); } gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store)); @@ -286,36 +283,34 @@ files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, GSList *docs) } -static GSList * -files_treeview_get_to_save (GtkTreeView *treeview) +static void +files_treeview_get_to_save (GtkTreeView *treeview, + MooEditArray *to_save) { GtkTreeIter iter; GtkTreeModel *model; - GSList *list = NULL; model = gtk_tree_view_get_model (treeview); - g_return_val_if_fail (model != NULL, NULL); + g_return_if_fail (model != NULL); gtk_tree_model_get_iter_first (model, &iter); do { - MooEdit *edit = NULL; + MooEdit *doc = NULL; gboolean save = TRUE; gtk_tree_model_get (model, &iter, COLUMN_SAVE, &save, - COLUMN_EDIT, &edit, -1); - g_return_val_if_fail (MOO_IS_EDIT (edit), list); + COLUMN_EDIT, &doc, -1); + g_return_if_fail (MOO_IS_EDIT (doc)); if (save) - list = g_slist_prepend (list, edit); + moo_edit_array_append (to_save, doc); - g_object_unref (edit); + g_object_unref (doc); } while (gtk_tree_model_iter_next (model, &iter)); - - return g_slist_reverse (list); } @@ -341,27 +336,22 @@ find_widget_for_response (GtkDialog *dialog, } MooSaveChangesDialogResponse -_moo_edit_save_multiple_changes_dialog (GSList *docs, - GSList **to_save) +_moo_edit_save_multiple_changes_dialog (MooEditArray *docs, + MooEditArray *to_save) { - GSList *l; GtkWidget *dialog; char *msg, *question; int response; MooSaveChangesDialogResponse retval; SaveMultDialogXml *xml; - g_return_val_if_fail (docs != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL); - g_return_val_if_fail (docs->next != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL); + g_return_val_if_fail (docs != NULL && docs->n_elms > 1, MOO_SAVE_CHANGES_RESPONSE_CANCEL); g_return_val_if_fail (to_save != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL); - for (l = docs; l != NULL; l = l->next) - g_return_val_if_fail (MOO_IS_EDIT (l->data), MOO_SAVE_CHANGES_RESPONSE_CANCEL); - xml = save_mult_dialog_xml_new (); dialog = GTK_WIDGET (xml->SaveMultDialog); - moo_window_set_parent (dialog, docs->data); + moo_window_set_parent (dialog, GTK_WIDGET (docs->elms[0])); gtk_dialog_add_buttons (GTK_DIALOG (dialog), MOO_STOCK_SAVE_NONE, GTK_RESPONSE_NO, @@ -383,8 +373,8 @@ _moo_edit_save_multiple_changes_dialog (GSList *docs, "Save changes before closing?", "There are %u documents with unsaved changes. " "Save changes before closing?", - g_slist_length (docs)), - g_slist_length (docs)); + docs->n_elms), + (guint) docs->n_elms); msg = g_markup_printf_escaped ("%s", question); gtk_label_set_markup (xml->label, msg); @@ -405,7 +395,7 @@ _moo_edit_save_multiple_changes_dialog (GSList *docs, retval = MOO_SAVE_CHANGES_RESPONSE_DONT_SAVE; break; case GTK_RESPONSE_YES: - *to_save = files_treeview_get_to_save (xml->treeview); + files_treeview_get_to_save (xml->treeview, to_save); retval = MOO_SAVE_CHANGES_RESPONSE_SAVE; break; default: @@ -430,7 +420,7 @@ _moo_edit_save_error_dialog (GtkWidget *widget, { char *filename, *msg = NULL; - filename = _moo_file_get_display_name (file); + filename = moo_file_get_display_name (file); if (filename) /* Could not save file foo.txt */ @@ -454,7 +444,7 @@ _moo_edit_save_error_enc_dialog (GtkWidget *widget, g_return_if_fail (encoding != NULL); - filename = _moo_file_get_display_name (file); + filename = moo_file_get_display_name (file); if (filename) /* Error saving file foo.txt */ @@ -483,7 +473,7 @@ _moo_edit_open_error_dialog (GtkWidget *widget, char *filename, *msg = NULL; char *secondary; - filename = _moo_file_get_display_name (file); + filename = moo_file_get_display_name (file); if (filename) /* Could not open file foo.txt */ @@ -529,14 +519,15 @@ _moo_edit_reload_error_dialog (MooEdit *doc, if (!filename) { - g_critical ("%s: oops", G_STRLOC); + moo_critical ("oops"); filename = ""; } /* Could not reload file foo.txt */ msg = g_strdup_printf (_("Could not reload file\n%s"), filename); /* XXX */ - moo_error_dialog (GTK_WIDGET (doc), msg, error ? error->message : NULL); + moo_error_dialog (GTK_WIDGET (doc), + msg, error ? error->message : NULL); g_free (msg); } @@ -547,13 +538,13 @@ _moo_edit_reload_error_dialog (MooEdit *doc, */ static gboolean -moo_edit_question_dialog (MooEdit *edit, +moo_edit_question_dialog (MooEdit *doc, const char *text, const char *secondary, const char *button) { int res; - GtkWindow *parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (edit))); + GtkWindow *parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (doc))); GtkWidget *dialog; dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL, @@ -580,22 +571,22 @@ moo_edit_question_dialog (MooEdit *edit, } gboolean -_moo_edit_reload_modified_dialog (MooEdit *edit) +_moo_edit_reload_modified_dialog (MooEdit *doc) { const char *name; char *question; gboolean result; - name = moo_edit_get_display_basename (edit); + name = moo_edit_get_display_basename (doc); if (!name) { - g_critical ("%s: oops", G_STRLOC); + moo_critical ("oops"); name = ""; } question = g_strdup_printf (_("Discard changes in file '%s'?"), name); - result = moo_edit_question_dialog (edit, question, + result = moo_edit_question_dialog (doc, question, _("If you reload the document, changes will be discarded"), _("_Reload")); @@ -604,24 +595,24 @@ _moo_edit_reload_modified_dialog (MooEdit *edit) } gboolean -_moo_edit_overwrite_modified_dialog (MooEdit *edit) +_moo_edit_overwrite_modified_dialog (MooEdit *doc) { const char *name; char *question, *secondary; gboolean result; - name = moo_edit_get_display_basename (edit); + name = moo_edit_get_display_basename (doc); if (!name) { - g_critical ("%s: oops", G_STRLOC); + moo_critical ("%s: oops", G_STRLOC); name = ""; } question = g_strdup_printf (_("Overwrite modified file '%s'?"), name); secondary = g_strdup_printf (_("File '%s' was modified on disk by another process. If you save it, " "changes on disk will be lost."), name); - result = moo_edit_question_dialog (edit, question, secondary, _("Over_write")); + result = moo_edit_question_dialog (doc, question, secondary, _("Over_write")); g_free (question); g_free (secondary); diff --git a/moo/mooedit/mooeditdialogs.h b/moo/mooedit/mooeditdialogs.h index 3ac40279..b8b76024 100644 --- a/moo/mooedit/mooeditdialogs.h +++ b/moo/mooedit/mooeditdialogs.h @@ -17,25 +17,25 @@ #define MOO_EDIT_DIALOGS_H #include "mooutils/moodialogs.h" -#include "mooedit/mooedit.h" +#include "mooedit/mooedittypes.h" #include G_BEGIN_DECLS -MooEditFileInfo *_moo_edit_save_as_dialog (MooEdit *edit, +MooFileEnc *_moo_edit_save_as_dialog (MooEdit *doc, const char *display_basename); -GSList *_moo_edit_open_dialog (GtkWidget *widget, +MooFileEncArray *_moo_edit_open_dialog (GtkWidget *widget, MooEdit *current_doc); MooSaveChangesDialogResponse - _moo_edit_save_changes_dialog (MooEdit *edit); + _moo_edit_save_changes_dialog (MooEdit *doc); MooSaveChangesDialogResponse - _moo_edit_save_multiple_changes_dialog (GSList *docs, - GSList **to_save); + _moo_edit_save_multiple_changes_dialog (MooEditArray *docs, + MooEditArray *to_save); -gboolean _moo_edit_reload_modified_dialog (MooEdit *edit); -gboolean _moo_edit_overwrite_modified_dialog (MooEdit *edit); +gboolean _moo_edit_reload_modified_dialog (MooEdit *doc); +gboolean _moo_edit_overwrite_modified_dialog (MooEdit *doc); void _moo_edit_save_error_dialog (GtkWidget *widget, GFile *file, diff --git a/moo/mooedit/mooeditfiltersettings.c b/moo/mooedit/mooeditfiltersettings.c index 742fecac..df2429c6 100644 --- a/moo/mooedit/mooeditfiltersettings.c +++ b/moo/mooedit/mooeditfiltersettings.c @@ -17,13 +17,14 @@ #include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditprefs.h" #include "mooedit/mooeditaction.h" +#include "mooedit/moolang.h" +#include "mooedit/mooeditconfig.h" +#include "mooedit/mooedit.h" #include "mooutils/mooprefs.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-debug.h" #include #include -#include - MOO_DEBUG_INIT(filters, FALSE) @@ -133,6 +134,32 @@ _moo_edit_filter_new (const char *string) return _moo_edit_filter_new_full (string, FALSE); } +static GSList * +_moo_edit_parse_langs (const char *string) +{ + char **pieces, **p; + GSList *list = NULL; + + if (!string) + return NULL; + + pieces = g_strsplit_set (string, " \t\r\n;,", 0); + + if (!pieces) + return NULL; + + for (p = pieces; *p != NULL; ++p) + { + g_strstrip (*p); + + if (**p) + list = g_slist_prepend (list, _moo_lang_id_from_name (*p)); + } + + g_strfreev (pieces); + return g_slist_reverse (list); +} + MooEditFilter * _moo_edit_filter_new_langs (const char *string) { @@ -244,37 +271,21 @@ static gboolean moo_edit_filter_check_globs (GSList *globs, MooEdit *doc) { - char *name = NULL; - - name = moo_edit_get_filename (doc); - - if (name) - { - char *tmp = name; - name = g_path_get_basename (tmp); - g_free (tmp); - } + GFile *file = moo_edit_get_file (doc); while (globs) { - if (name) + if (!strcmp (globs->data, "*") || + (file && moo_file_fnmatch (file, globs->data))) { - if (fnmatch (globs->data, name, 0) == 0) - { - g_free (name); - return TRUE; - } - } - else - { - if (!strcmp (globs->data, "*")) - return TRUE; + g_object_unref (file); + return TRUE; } globs = globs->next; } - g_free (name); + moo_file_free (file); return FALSE; } @@ -282,7 +293,8 @@ static gboolean moo_edit_filter_check_langs (GSList *langs, MooEdit *doc) { - const char *lang_id = moo_edit_config_get_string (doc->config, "lang"); + MooLang *lang = moo_edit_get_lang (doc); + const char *lang_id = _moo_lang_id (lang); while (lang_id && langs) { diff --git a/moo/mooedit/mooedithistoryitem.c b/moo/mooedit/mooedithistoryitem.c new file mode 100644 index 00000000..e9151664 --- /dev/null +++ b/moo/mooedit/mooedithistoryitem.c @@ -0,0 +1,50 @@ +#include "mooedithistoryitem.h" +#include + +#define KEY_ENCODING "encoding" +#define KEY_LINE "line" + +void +_moo_edit_history_item_set_encoding (MdHistoryItem *item, + const char *encoding) +{ + g_return_if_fail (item != NULL); + md_history_item_set (item, KEY_ENCODING, encoding); +} + +void +_moo_edit_history_item_set_line (MdHistoryItem *item, + int line) +{ + char *value = NULL; + + g_return_if_fail (item != NULL); + + if (line >= 0) + value = g_strdup_printf ("%d", line + 1); + + md_history_item_set (item, KEY_LINE, value); + g_free (value); +} + +const char * +_moo_edit_history_item_get_encoding (MdHistoryItem *item) +{ + g_return_val_if_fail (item != NULL, NULL); + return md_history_item_get (item, KEY_ENCODING); +} + +int +_moo_edit_history_item_get_line (MdHistoryItem *item) +{ + const char *strval; + + g_return_val_if_fail (item != NULL, -1); + + strval = md_history_item_get (item, KEY_LINE); + + if (strval && strval[0]) + return strtol (strval, NULL, 10) - 1; + else + return -1; +} diff --git a/moo/mooedit/mooedithistoryitem.h b/moo/mooedit/mooedithistoryitem.h new file mode 100644 index 00000000..1ccba570 --- /dev/null +++ b/moo/mooedit/mooedithistoryitem.h @@ -0,0 +1,17 @@ +#ifndef MOO_EDIT_HISTORY_ITEM_H +#define MOO_EDIT_HISTORY_ITEM_H + +#include + +G_BEGIN_DECLS + +void _moo_edit_history_item_set_encoding (MdHistoryItem *item, + const char *encoding); +void _moo_edit_history_item_set_line (MdHistoryItem *item, + int line); +const char *_moo_edit_history_item_get_encoding (MdHistoryItem *item); +int _moo_edit_history_item_get_line (MdHistoryItem *item); + +G_END_DECLS + +#endif /* MOO_EDIT_HISTORY_ITEM_H */ diff --git a/moo/mooedit/mooeditor-impl.h b/moo/mooedit/mooeditor-impl.h new file mode 100644 index 00000000..cd3f371a --- /dev/null +++ b/moo/mooedit/mooeditor-impl.h @@ -0,0 +1,42 @@ +#ifndef MOO_EDITOR_IMPL_H +#define MOO_EDITOR_IMPL_H + +#ifndef MOOEDIT_COMPILATION +#error "This file may not be used directly" +#endif + +#include "mooedit/mooeditor.h" +#include "mooutils/mdhistorymgr.h" +#include "mooutils/moofilewatch.h" + +G_BEGIN_DECLS + +MdHistoryMgr *_moo_editor_get_history_mgr (MooEditor *editor); + +void _moo_editor_set_focused_doc (MooEditor *editor, + MooEdit *doc); +void _moo_editor_unset_focused_doc (MooEditor *editor, + MooEdit *doc); + +void _moo_editor_move_doc (MooEditor *editor, + MooEdit *doc, + MooEditWindow *dest, + gboolean focus); + +MooFileWatch *_moo_editor_get_file_watch (MooEditor *editor); +void _moo_editor_reload (MooEditor *editor, + MooEdit *doc, + const char *encoding, + GError **error); +gboolean _moo_editor_save (MooEditor *editor, + MooEdit *doc, + GError **error); +gboolean _moo_editor_save_as (MooEditor *editor, + MooEdit *doc, + const char *filename, + const char *encoding, + GError **error); + +G_END_DECLS + +#endif /* MOO_EDITOR_IMPL_H */ diff --git a/moo/mooedit/mooeditor-private.h b/moo/mooedit/mooeditor-private.h index f631749a..6e98690a 100644 --- a/moo/mooedit/mooeditor-private.h +++ b/moo/mooedit/mooeditor-private.h @@ -13,60 +13,42 @@ * License along with medit. If not, see . */ -#ifndef MOOEDIT_COMPILATION -#error "This file may not be used directly" -#endif - #ifndef MOO_EDITOR_PRIVATE_H #define MOO_EDITOR_PRIVATE_H -#include "mooedit/mooeditor.h" -#include "mooutils/mdhistorymgr.h" -#include "mooutils/moofilewatch.h" +#include "mooedit/mooeditor-impl.h" +#include "mooedit/moolangmgr.h" G_BEGIN_DECLS +typedef enum { + OPEN_SINGLE = 1 << 0, + ALLOW_EMPTY_WINDOW = 1 << 1, + SINGLE_WINDOW = 1 << 2, + SAVE_BACKUPS = 1 << 3, + STRIP_WHITESPACE = 1 << 4, + EMBEDDED = 1 << 5 +} MooEditorOptions; -MdHistoryMgr *_moo_editor_get_history_mgr (MooEditor *editor); +struct MooEditorPrivate { + MooEditArray *windowless; + MooEditWindowArray *windows; + MooUiXml *doc_ui_xml; + MooUiXml *ui_xml; + MdHistoryMgr *history; + MooFileWatch *file_watch; + MooEditorOptions opts; -void _moo_edit_window_insert_doc (MooEditWindow *window, - MooEdit *doc, - int position); -void _moo_edit_window_remove_doc (MooEditWindow *window, - MooEdit *doc, - gboolean destroy); -int _moo_edit_window_get_doc_no (MooEditWindow *window, - MooEdit *doc); -void _moo_edit_window_update_title (void); -void _moo_edit_window_set_use_tabs (void); + MooEdit *focused_doc; -void _moo_editor_set_focused_doc (MooEditor *editor, - MooEdit *doc); -void _moo_editor_unset_focused_doc (MooEditor *editor, - MooEdit *doc); + GType window_type; + GType doc_type; -void _moo_editor_move_doc (MooEditor *editor, - MooEdit *doc, - MooEditWindow *dest, - gboolean focus); - -MooFileWatch *_moo_editor_get_file_watch (MooEditor *editor); -void _moo_editor_reload (MooEditor *editor, - MooEdit *doc, - const char *encoding, - GError **error); -gboolean _moo_editor_save (MooEditor *editor, - MooEdit *doc, - GError **error); -gboolean _moo_editor_save_as (MooEditor *editor, - MooEdit *doc, - const char *filename, - const char *encoding, - GError **error); -void _moo_editor_post_message (MooEditor *editor, - GQuark domain, - const char *message); + MooLangMgr *lang_mgr; + char *default_lang; + guint prefs_idle; +}; G_END_DECLS diff --git a/moo/mooedit/mooeditor-tests.c b/moo/mooedit/mooeditor-tests.c new file mode 100644 index 00000000..7a9907e3 --- /dev/null +++ b/moo/mooedit/mooeditor-tests.c @@ -0,0 +1,265 @@ +#define MOOEDIT_COMPILATION +#include "mooedit/mooeditor-tests.h" +#include "mooedit/mooeditor-impl.h" +#include "mooutils/mooutils-fs.h" +#include "mooutils/mdhistorymgr.h" + +static struct { + char *working_dir; + char *encodings_dir; +} test_data; + +#ifdef __WIN32__ +#define LE "\r\n" +#else +#define LE "\n" +#endif + +#define TT1 "blah blah blah" +#define TT2 "blah blah blah" LE "blah blah blah" +#define TT3 LE LE LE LE +#define TT4 "lala\nlala\n" +#define TT5 "lala\r\nlala\r\n" +#define TT6 "lala\rlala\r" + +static void +check_contents (const char *filename, + const char *expected) +{ + char *contents; + GError *error = NULL; + + if (!g_file_get_contents (filename, &contents, NULL, &error)) + { + TEST_FAILED_MSG ("could not load file '%s': %s", + filename, error->message); + g_error_free (error); + return; + } + + TEST_ASSERT_STR_EQ (contents, expected); + + g_free (contents); +} + +static void +test_basic (void) +{ + MooEditor *editor; + MooEdit *doc, *doc2; + GtkTextBuffer *buffer; + char *filename; + + editor = moo_editor_instance (); + filename = g_build_filename (test_data.working_dir, "test.txt", NULL); + doc = moo_editor_new_file (editor, NULL, NULL, filename, NULL); + TEST_ASSERT (doc != NULL); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, ""); + + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (doc)); + + gtk_text_buffer_set_text (buffer, TT1, -1); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT1); + + gtk_text_buffer_set_text (buffer, TT2, -1); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT2); + + gtk_text_buffer_set_text (buffer, TT2 LE, -1); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT2 LE); + + gtk_text_buffer_set_text (buffer, TT3, -1); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT3); + + doc2 = moo_editor_open_file (editor, NULL, NULL, filename, NULL); + TEST_ASSERT (doc2 == doc); + + TEST_ASSERT (moo_edit_close (doc, TRUE)); + TEST_ASSERT (moo_editor_get_doc (editor, filename) == NULL); + + g_file_set_contents (filename, TT4, -1, NULL); + doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL); + TEST_ASSERT (doc != NULL); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT4); + TEST_ASSERT (moo_edit_close (doc, TRUE)); + + g_file_set_contents (filename, TT5, -1, NULL); + doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL); + TEST_ASSERT (doc != NULL); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT5); + TEST_ASSERT (moo_edit_close (doc, TRUE)); + + g_file_set_contents (filename, TT6, -1, NULL); + doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL); + TEST_ASSERT (doc != NULL); + TEST_ASSERT (moo_edit_save (doc, NULL)); + check_contents (filename, TT6); + TEST_ASSERT (moo_edit_close (doc, TRUE)); + + g_free (filename); +} + +#define TEST_ASSERT_SAME_FILE_CONTENT(filename1, filename2) \ +{ \ + char *contents1__ = NULL; \ + char *contents2__ = NULL; \ + g_file_get_contents (filename1, &contents1__, NULL, NULL); \ + g_file_get_contents (filename2, &contents2__, NULL, NULL); \ + if (!contents1__) \ + moo_test_assert_msg (FALSE, __FILE__, __LINE__, \ + "could not open file %s", \ + filename1); \ + if (!contents2__) \ + moo_test_assert_msg (FALSE, __FILE__, __LINE__, \ + "could not open file %s", \ + filename2); \ + if (contents1__ && contents2__) \ + { \ + gboolean equal = strcmp (contents1__, contents2__) == 0; \ + TEST_ASSERT_MSG (equal, "contents of %s and %s differ", \ + filename1, filename2); \ + } \ + g_free (contents2__); \ + g_free (contents1__); \ +} + +static void +test_encodings_1 (const char *name, + const char *working_dir) +{ + char *filename; + char *filename2; + char *encoding; + const char *dot; + MooEditor *editor; + MooEdit *doc; + + if ((dot = strchr (name, '.'))) + encoding = g_strndup (name, dot - name); + else + encoding = g_strdup (name); + + filename = g_build_filename (test_data.encodings_dir, name, (char*)0); + filename2 = g_build_filename (working_dir, name, (char*)0); + + editor = moo_editor_instance (); + doc = moo_editor_open_file (editor, NULL, NULL, filename, encoding); + TEST_ASSERT_MSG (doc != NULL, + "file '%s', encoding '%s'", + TEST_FMT_STR (filename), + TEST_FMT_STR (encoding)); + + if (doc) + { + TEST_ASSERT (moo_edit_save_as (doc, filename2, NULL, NULL)); + TEST_ASSERT_SAME_FILE_CONTENT (filename2, filename); + TEST_ASSERT (moo_edit_close (doc, TRUE)); + } + + g_free (encoding); + g_free (filename2); + g_free (filename); +} + +static void +test_encodings (void) +{ + GDir *dir; + const char *name; + char *working_dir; + + dir = g_dir_open (test_data.encodings_dir, 0, NULL); + + if (!dir) + { + g_critical ("could not open encodings dir"); + TEST_ASSERT (FALSE); + return; + } + + working_dir = g_build_filename (test_data.working_dir, "encodings", (char*)0); + _moo_mkdir_with_parents (working_dir); + + while ((name = g_dir_read_name (dir))) + test_encodings_1 (name, working_dir); + + g_free (working_dir); + g_dir_close (dir); +} + +static gboolean +test_suite_init (G_GNUC_UNUSED gpointer data) +{ + test_data.working_dir = g_build_filename (moo_test_get_working_dir (), + "editor-work", (char*)0); + test_data.encodings_dir = g_build_filename (moo_test_get_data_dir (), + "encodings", (char*)0); + + if (_moo_mkdir_with_parents (test_data.working_dir) != 0) + { + g_critical ("could not create directory '%s'", + test_data.working_dir); + g_free (test_data.working_dir); + test_data.working_dir = NULL; + return FALSE; + } + + return TRUE; +} + +static void +test_suite_cleanup (G_GNUC_UNUSED gpointer data) +{ + char *recent_file; + MooEditor *editor; + GError *error = NULL; + + if (!_moo_remove_dir (test_data.working_dir, TRUE, &error)) + { + g_critical ("could not remove directory '%s': %s", + test_data.working_dir, error->message); + g_error_free (error); + error = NULL; + } + + g_free (test_data.working_dir); + g_free (test_data.encodings_dir); + test_data.working_dir = NULL; + test_data.encodings_dir = NULL; + + editor = moo_editor_instance (); +// moo_editor_close_all (editor, FALSE, FALSE); + recent_file = _md_history_mgr_get_filename (_moo_editor_get_history_mgr (editor)); + + if (!g_file_test (recent_file, G_FILE_TEST_EXISTS)) + g_critical ("recent file %s does not exist", recent_file); + +// cache_dir = moo_get_user_cache_dir (); +// if (!_moo_remove_dir (cache_dir, TRUE, &error)) +// { +// g_critical ("could not remove directory '%s': %s", +// cache_dir, error->message); +// g_error_free (error); +// error = NULL; +// } + + g_free (recent_file); +} + +void +moo_test_editor (void) +{ + MooTestSuite *suite = moo_test_suite_new ("Editor", + "Editor tests", + test_suite_init, + test_suite_cleanup, + NULL); + moo_test_suite_add_test (suite, "basic", "basic editor functionality", (MooTestFunc) test_basic, NULL); + moo_test_suite_add_test (suite, "encodings", "character encoding handling", (MooTestFunc) test_encodings, NULL); +} diff --git a/moo/mooedit/mooedit-tests.h b/moo/mooedit/mooeditor-tests.h similarity index 86% rename from moo/mooedit/mooedit-tests.h rename to moo/mooedit/mooeditor-tests.h index 1dacc253..b9647a2b 100644 --- a/moo/mooedit/mooedit-tests.h +++ b/moo/mooedit/mooeditor-tests.h @@ -1,5 +1,5 @@ /* - * mooedit-tests.h + * mooeditor-tests.h * * Copyright (C) 2004-2010 by Yevgen Muntyan * @@ -13,8 +13,8 @@ * License along with medit. If not, see . */ -#ifndef MOO_EDIT_TESTS_H -#define MOO_EDIT_TESTS_H +#ifndef MOO_EDITOR_TESTS_H +#define MOO_EDITOR_TESTS_H #include "mooutils/moo-test-macros.h" @@ -25,4 +25,4 @@ void moo_test_editor (void); G_END_DECLS -#endif /* MOO_EDIT_TESTS_H */ +#endif /* MOO_EDITOR_TESTS_H */ diff --git a/moo/mooedit/mooeditor.c b/moo/mooedit/mooeditor.c index 9e56e379..d655aa32 100644 --- a/moo/mooedit/mooeditor.c +++ b/moo/mooedit/mooeditor.c @@ -15,14 +15,15 @@ #define MOOEDIT_COMPILATION #include "mooedit/mooeditor-private.h" +#include "mooedit/mooeditwindow-impl.h" #include "mooedit/mooeditdialogs.h" #include "mooedit/mooedit-fileops.h" #include "mooedit/mooplugin.h" #include "mooedit/mooeditprefs.h" #include "mooedit/mooedit-impl.h" #include "mooedit/mooedit-accels.h" -#include "mooedit/moolangmgr.h" #include "mooedit/mooeditfiltersettings.h" +#include "mooedit/moofileenc.h" #include "mooedit-ui.h" #include "medit-ui.h" #include "mooutils/moomenuaction.h" @@ -47,38 +48,6 @@ static gpointer editor_instance = NULL; -MOO_DEFINE_SLIST (DocList, doc_list, MooEdit) -MOO_DEFINE_SLIST (WindowList, window_list, MooEditWindow) - -typedef enum { - OPEN_SINGLE = 1 << 0, - ALLOW_EMPTY_WINDOW = 1 << 1, - SINGLE_WINDOW = 1 << 2, - SAVE_BACKUPS = 1 << 3, - STRIP_WHITESPACE = 1 << 4, - EMBEDDED = 1 << 5 -} MooEditorOptions; - -struct MooEditorPrivate { - DocList *windowless; - WindowList *windows; - MooUiXml *doc_ui_xml; - MooUiXml *ui_xml; - MdHistoryMgr *history; - MooLangMgr *lang_mgr; - MooFileWatch *file_watch; - MooEditorOptions opts; - - MooEdit *focused_doc; - - GType window_type; - GType doc_type; - - char *default_lang; - - guint prefs_idle; -}; - static void set_single_window (MooEditor *editor, gboolean single); @@ -98,9 +67,9 @@ static void do_close_window (MooEditor *editor, static void do_close_doc (MooEditor *editor, MooEdit *doc); static gboolean close_docs_real (MooEditor *editor, - DocList *docs, + MooEditArray *docs, gboolean ask_confirm); -static DocList *find_modified (DocList *docs); +static MooEditArray *find_modified (MooEditArray *docs); static void add_new_window_action (void); static void remove_new_window_action (void); @@ -237,6 +206,8 @@ static void moo_editor_init (MooEditor *editor) { editor->priv = G_TYPE_INSTANCE_GET_PRIVATE (editor, MOO_TYPE_EDITOR, MooEditorPrivate); + editor->priv->windows = moo_edit_window_array_new (); + editor->priv->windowless = moo_edit_array_new (); } static GObject * @@ -267,9 +238,6 @@ moo_editor_constructor (GType type, "name", "Editor", (const char*) NULL)); - editor->priv->windows = NULL; - editor->priv->windowless = NULL; - moo_prefs_new_key_string (moo_edit_setting (MOO_EDIT_PREFS_DEFAULT_LANG), MOO_LANG_NONE); @@ -396,11 +364,14 @@ moo_editor_finalize (GObject *object) moo_file_watch_unref (editor->priv->file_watch); } - if (editor->priv->windows) + if (editor->priv->windows->n_elms) g_critical ("finalizing editor while some windows are open"); - if (editor->priv->windowless) + if (editor->priv->windowless->n_elms) g_critical ("finalizing editor while some documents are open"); + moo_edit_window_array_free (editor->priv->windows); + moo_edit_array_free (editor->priv->windowless); + g_free (editor->priv->default_lang); if (editor->priv->prefs_idle) @@ -454,7 +425,7 @@ _moo_editor_get_file_watch (MooEditor *editor) MooEditor * -moo_editor_create_instance (gboolean embedded) +moo_editor_create (gboolean embedded) { if (!editor_instance) { @@ -544,27 +515,27 @@ static MooEditWindow * get_top_window (MooEditor *editor) { GtkWindow *window; + GSList *window_list; + guint i; - if (!editor->priv->windows) + if (moo_edit_window_array_is_empty (editor->priv->windows)) return NULL; - window = _moo_get_top_window (window_list_to_gslist (editor->priv->windows)); + for (window_list = NULL, i = 0; i < editor->priv->windows->n_elms; ++i) + window_list = g_slist_prepend (window_list, editor->priv->windows->elms[i]); + window_list = g_slist_reverse (window_list); + + window = _moo_get_top_window (window_list); if (!window) - window = GTK_WINDOW (editor->priv->windows->data); + window = GTK_WINDOW (editor->priv->windows->elms[0]); + + g_slist_free (window_list); return MOO_EDIT_WINDOW (window); } -static void -file_info_list_free (GSList *list) -{ - g_slist_foreach (list, (GFunc) moo_edit_file_info_free, NULL); - g_slist_free (list); -} - - MooUiXml * moo_editor_get_ui_xml (MooEditor *editor) { @@ -592,7 +563,7 @@ void moo_editor_set_ui_xml (MooEditor *editor, MooUiXml *xml) { - WindowList *l; + guint i; g_return_if_fail (MOO_IS_EDITOR (editor)); g_return_if_fail (MOO_IS_UI_XML (xml)); @@ -608,8 +579,9 @@ moo_editor_set_ui_xml (MooEditor *editor, if (editor->priv->ui_xml) g_object_ref (editor->priv->ui_xml); - for (l = editor->priv->windows; l != NULL; l = l->next) - moo_window_set_ui_xml (MOO_WINDOW (l->data), editor->priv->ui_xml); + for (i = 0; i < editor->priv->windows->n_elms; ++i) + moo_window_set_ui_xml (MOO_WINDOW (editor->priv->windows->elms[i]), + editor->priv->ui_xml); } @@ -737,7 +709,7 @@ create_window (MooEditor *editor) "editor", editor, "ui-xml", moo_editor_get_ui_xml (editor), (const char*) NULL)); - editor->priv->windows = window_list_append (editor->priv->windows, window); + moo_edit_window_array_append (editor->priv->windows, window); _moo_window_attach_plugins (window); gtk_widget_show (GTK_WIDGET (window)); return window; @@ -750,7 +722,7 @@ moo_editor_add_doc (MooEditor *editor, MooEdit *doc) { if (!window) - editor->priv->windowless = doc_list_prepend (editor->priv->windowless, doc); + moo_edit_array_append (editor->priv->windowless, doc); if (moo_edit_is_untitled (doc) && !moo_edit_config_get_string (doc->config, "lang") && @@ -813,8 +785,7 @@ moo_editor_create_doc (MooEditor *editor, moo_editor_add_doc (editor, NULL, doc); _moo_doc_attach_plugins (NULL, doc); - if (file) - g_object_unref (file); + g_object_unref (file); return doc; } @@ -932,7 +903,7 @@ static gboolean moo_editor_load_file (MooEditor *editor, MooEditWindow *window, GtkWidget *parent, - MooEditFileInfo *info, + MooFileEnc *fenc, gboolean silent, gboolean add_history, int line, @@ -946,7 +917,7 @@ moo_editor_load_file (MooEditor *editor, const char *recent_encoding = NULL; *docp = NULL; - uri = g_file_get_uri (info->file); + uri = g_file_get_uri (fenc->file); g_return_val_if_fail (uri != NULL, FALSE); if ((doc = moo_editor_get_doc_for_uri (editor, uri))) @@ -975,7 +946,7 @@ moo_editor_load_file (MooEditor *editor, new_doc = TRUE; } - if (!info->encoding) + if (!fenc->encoding) { MdHistoryItem *hist_item = md_history_mgr_find_uri (editor->priv->history, uri); if (hist_item) @@ -983,7 +954,7 @@ moo_editor_load_file (MooEditor *editor, } /* XXX open_single */ - if (!_moo_edit_load_file (doc, info->file, info->encoding, recent_encoding, &error)) + if (!_moo_edit_load_file (doc, fenc->file, fenc->encoding, recent_encoding, &error)) { if (!silent) { @@ -991,7 +962,7 @@ moo_editor_load_file (MooEditor *editor, window = moo_editor_get_active_window (editor); if (!parent && window) parent = GTK_WIDGET (window); - _moo_edit_open_error_dialog (parent, info->file, info->encoding, error); + _moo_edit_open_error_dialog (parent, fenc->file, fenc->encoding, error); } g_error_free (error); result = FALSE; @@ -1034,12 +1005,12 @@ moo_editor_load_file (MooEditor *editor, } gboolean -moo_editor_open (MooEditor *editor, - MooEditWindow *window, - GtkWidget *parent, - GSList *files) +moo_editor_open (MooEditor *editor, + MooEditWindow *window, + GtkWidget *parent, + MooFileEncArray *files) { - GSList *l; + guint i; MooEdit *bring_to_front = NULL; gboolean result = TRUE; @@ -1056,26 +1027,26 @@ moo_editor_open (MooEditor *editor, files = _moo_edit_open_dialog (parent, active); - if (!files) - return FALSE; - - result = moo_editor_open (editor, window, parent, files); - file_info_list_free (files); + if (files) + result = moo_editor_open (editor, window, parent, files); + else + result = FALSE; + moo_file_enc_array_free (files); return result; } bring_to_front = NULL; - for (l = files; l != NULL; l = l->next) + for (i = 0; i < files->n_elms; ++i) { - MooEditFileInfo *info = l->data; + MooFileEnc *fenc = files->elms[i]; MooEdit *doc = NULL; if (!window) window = moo_editor_get_active_window (editor); - if (moo_editor_load_file (editor, window, parent, info, + if (moo_editor_load_file (editor, window, parent, fenc, is_embedded (editor), TRUE, -1, &doc)) parent = GTK_WIDGET (doc); @@ -1155,67 +1126,56 @@ moo_editor_set_active_doc (MooEditor *editor, static MooEdit * -find_busy (DocList *docs) +find_busy (MooEditArray *docs) { - while (docs) - { - if (MOO_EDIT_IS_BUSY (docs->data)) - return docs->data; - docs = docs->next; - } - + guint i; + for (i = 0; i < docs->n_elms; ++i) + if (MOO_EDIT_IS_BUSY (docs->elms[i])) + return docs->elms[i]; return NULL; } - -inline static DocList * -window_list_docs (MooEditWindow *window) -{ - return doc_list_from_gslist (moo_edit_window_list_docs (window)); -} - - static gboolean close_window_handler (MooEditor *editor, MooEditWindow *window, gboolean ask_confirm) { MooSaveChangesDialogResponse response; - DocList *modified; - DocList *docs; + MooEditArray *modified; + MooEditArray *docs; gboolean do_close = FALSE; MooEdit *busy = NULL; g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE); g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE); - docs = window_list_docs (window); + docs = moo_edit_window_get_docs (window); busy = find_busy (docs); if (busy) { moo_editor_set_active_doc (editor, busy); - doc_list_free_links (docs); + moo_edit_array_free (docs); return TRUE; } modified = find_modified (docs); - if (!modified || !ask_confirm) + if (moo_edit_array_is_empty (modified) || !ask_confirm) { do_close = TRUE; } - else if (!modified->next) + else if (modified->n_elms == 1) { if (window) - moo_edit_window_set_active_doc (window, modified->data); + moo_edit_window_set_active_doc (window, modified->elms[0]); - response = _moo_edit_save_changes_dialog (modified->data); + response = _moo_edit_save_changes_dialog (modified->elms[0]); switch (response) { case MOO_SAVE_CHANGES_RESPONSE_SAVE: - if (_moo_editor_save (editor, modified->data, NULL)) + if (_moo_editor_save (editor, modified->elms[0], NULL)) do_close = TRUE; break; @@ -1229,25 +1189,24 @@ close_window_handler (MooEditor *editor, } else { - GSList *to_save = NULL, *l; + guint i; + MooEditArray *to_save; gboolean saved = TRUE; - response = _moo_edit_save_multiple_changes_dialog (doc_list_to_gslist (modified), &to_save); + to_save = moo_edit_array_new (); + response = _moo_edit_save_multiple_changes_dialog (modified, to_save); switch (response) { case MOO_SAVE_CHANGES_RESPONSE_SAVE: - for (l = to_save; l != NULL; l = l->next) - if (!_moo_editor_save (editor, l->data, NULL)) + for (i = 0; i < to_save->n_elms; ++i) + if (!_moo_editor_save (editor, to_save->elms[i], NULL)) { saved = FALSE; break; } - if (saved) do_close = TRUE; - - g_slist_free (to_save); break; case MOO_SAVE_CHANGES_RESPONSE_CANCEL: @@ -1257,10 +1216,12 @@ close_window_handler (MooEditor *editor, do_close = TRUE; break; } + + moo_edit_array_free (to_save); } - doc_list_free_links (modified); - doc_list_free_links (docs); + moo_edit_array_free (modified); + moo_edit_array_free (docs); return !do_close; } @@ -1275,14 +1236,14 @@ moo_editor_close_window (MooEditor *editor, g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE); g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE); - if (!window_list_find (editor->priv->windows, window)) + if (moo_edit_window_array_find (editor->priv->windows, window) < 0) return TRUE; g_object_ref (window); g_signal_emit (editor, signals[CLOSE_WINDOW], 0, window, ask_confirm, &stopped); - if (!stopped && window_list_find (editor->priv->windows, window)) + if (!stopped && moo_edit_window_array_find (editor->priv->windows, window) >= 0) do_close_window (editor, window); g_object_unref (window); @@ -1295,20 +1256,20 @@ static void do_close_window (MooEditor *editor, MooEditWindow *window) { - DocList *l, *list; + MooEditArray *docs; + guint i; - list = window_list_docs (window); + docs = moo_edit_window_get_docs (window); - for (l = list; l != NULL; l = l->next) - do_close_doc (editor, l->data); + for (i = 0; i < docs->n_elms; ++i) + do_close_doc (editor, docs->elms[i]); - editor->priv->windows = - window_list_remove (editor->priv->windows, window); + moo_edit_window_array_remove (editor->priv->windows, window); _moo_window_detach_plugins (window); gtk_widget_destroy (GTK_WIDGET (window)); - doc_list_free_links (list); + moo_edit_array_free (docs); } @@ -1322,8 +1283,8 @@ do_close_doc (MooEditor *editor, if (!window) { - g_assert (doc_list_find (editor->priv->windowless, doc)); - editor->priv->windowless = doc_list_remove (editor->priv->windowless, doc); + g_assert (moo_edit_array_find (editor->priv->windowless, doc) >= 0); + moo_edit_array_remove (editor->priv->windowless, doc); } update_history_item_for_doc (editor, doc, TRUE); @@ -1336,37 +1297,38 @@ do_close_doc (MooEditor *editor, gboolean -moo_editor_close_doc (MooEditor *editor, - MooEdit *doc, - gboolean ask_confirm) +moo_editor_close_doc (MooEditor *editor, + MooEdit *doc, + gboolean ask_confirm) { gboolean result; - GSList *list; + MooEditArray *docs; - list = g_slist_prepend (NULL, doc); - result = moo_editor_close_docs (editor, list, ask_confirm); - - g_slist_free (list); + docs = moo_edit_array_new (); + moo_edit_array_append (docs, doc); + result = moo_editor_close_docs (editor, docs, ask_confirm); + moo_edit_array_free (docs); return result; } gboolean -moo_editor_close_docs (MooEditor *editor, - GSList *list, - gboolean ask_confirm) +moo_editor_close_docs (MooEditor *editor, + MooEditArray *docs, + gboolean ask_confirm) { - GSList *l; + guint i; MooEditWindow *window; g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE); - if (!list) + if (moo_edit_array_is_empty (docs)) return TRUE; - for (l = list; l != NULL; l = l->next) + for (i = 0; i < docs->n_elms; ++i) { - MooEdit *doc = l->data; + MooEdit *doc = docs->elms[i]; + g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE); if (MOO_EDIT_IS_BUSY (doc)) @@ -1376,9 +1338,9 @@ moo_editor_close_docs (MooEditor *editor, } } - window = moo_edit_get_window (list->data); + window = moo_edit_get_window (docs->elms[0]); - if (close_docs_real (editor, doc_list_from_gslist (list), ask_confirm)) + if (close_docs_real (editor, docs, ask_confirm)) { if (window && !moo_edit_window_num_docs (window) && @@ -1401,33 +1363,33 @@ moo_editor_close_docs (MooEditor *editor, static gboolean -close_docs_real (MooEditor *editor, - DocList *docs, - gboolean ask_confirm) +close_docs_real (MooEditor *editor, + MooEditArray *docs, + gboolean ask_confirm) { MooSaveChangesDialogResponse response; - DocList *modified; + MooEditArray *modified; gboolean do_close = FALSE; modified = find_modified (docs); - if (!modified || !ask_confirm) + if (moo_edit_array_is_empty (modified) || !ask_confirm) { do_close = TRUE; } - else if (!modified->next) + else if (modified->n_elms == 1) { - MooEditWindow *window = moo_edit_get_window (modified->data); + MooEditWindow *window = moo_edit_get_window (modified->elms[0]); if (window) - moo_edit_window_set_active_doc (window, modified->data); + moo_edit_window_set_active_doc (window, modified->elms[0]); - response = _moo_edit_save_changes_dialog (modified->data); + response = _moo_edit_save_changes_dialog (modified->elms[0]); switch (response) { case MOO_SAVE_CHANGES_RESPONSE_SAVE: - if (_moo_editor_save (editor, modified->data, NULL)) + if (_moo_editor_save (editor, modified->elms[0], NULL)) do_close = TRUE; break; @@ -1441,26 +1403,24 @@ close_docs_real (MooEditor *editor, } else { - GSList *l; - GSList *to_save = NULL; + guint i; + MooEditArray *to_save; gboolean saved = TRUE; - response = _moo_edit_save_multiple_changes_dialog (doc_list_to_gslist (modified), &to_save); + to_save = moo_edit_array_new (); + response = _moo_edit_save_multiple_changes_dialog (modified, to_save); switch (response) { case MOO_SAVE_CHANGES_RESPONSE_SAVE: - for (l = to_save; l != NULL; l = l->next) - if (!_moo_editor_save (editor, l->data, NULL)) + for (i = 0; i < to_save->n_elms; ++i) + if (!_moo_editor_save (editor, to_save->elms[i], NULL)) { saved = FALSE; break; } - if (saved) do_close = TRUE; - - g_slist_free (to_save); break; case MOO_SAVE_CHANGES_RESPONSE_CANCEL: @@ -1470,66 +1430,69 @@ close_docs_real (MooEditor *editor, do_close = TRUE; break; } + + moo_edit_array_free (to_save); } if (do_close) { - DocList *l; - for (l = docs; l != NULL; l = l->next) - do_close_doc (editor, l->data); + guint i; + for (i = 0; i < docs->n_elms; ++i) + do_close_doc (editor, docs->elms[i]); } - doc_list_free_links (modified); + moo_edit_array_free (modified); return do_close; } -static DocList* -find_modified (DocList *docs) +static MooEditArray * +find_modified (MooEditArray *docs) { - DocList *modified = NULL, *l; - for (l = docs; l != NULL; l = l->next) - if (MOO_EDIT_IS_MODIFIED (l->data) && !MOO_EDIT_IS_CLEAN (l->data)) - modified = doc_list_prepend (modified, l->data); - return doc_list_reverse (modified); + guint i; + MooEditArray *modified = moo_edit_array_new (); + for (i = 0; i < docs->n_elms; ++i) + if (MOO_EDIT_IS_MODIFIED (docs->elms[i]) && !MOO_EDIT_IS_CLEAN (docs->elms[i])) + moo_edit_array_append (modified, docs->elms[i]); + return modified; } -/* XXX ask in each window, then close */ gboolean moo_editor_close_all (MooEditor *editor, gboolean ask_confirm, gboolean leave_one) { - GSList *windows, *l; + guint i; + MooEditWindowArray *windows; g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE); - windows = moo_editor_list_windows (editor); + windows = moo_editor_get_windows (editor); - for (l = windows; l != NULL; l = l->next) + for (i = 0; i < windows->n_elms; ++i) { gboolean closed = FALSE; - if (l->next || !leave_one || !ask_confirm) + if (i + 1 < windows->n_elms || !leave_one || !ask_confirm) { - closed = moo_editor_close_window (editor, l->data, ask_confirm); + closed = moo_editor_close_window (editor, windows->elms[i], ask_confirm); } else { - GSList *docs = moo_edit_window_list_docs (l->data); + MooEditArray *docs = moo_edit_window_get_docs (windows->elms[i]); closed = moo_editor_close_docs (editor, docs, ask_confirm); - g_slist_free (docs); + moo_edit_array_free (docs); } if (!closed) { - g_slist_free (windows); + moo_edit_window_array_free (windows); return FALSE; } } - g_slist_free (windows); + moo_edit_window_array_free (windows); return TRUE; } @@ -1569,7 +1532,7 @@ load_doc_session (MooEditor *editor, const char *encoding; char *freeme = NULL; MooEdit *doc = NULL; - MooEditFileInfo *info; + MooFileEnc *fenc; if (file_is_uri) { @@ -1594,11 +1557,11 @@ load_doc_session (MooEditor *editor, } encoding = moo_markup_get_prop (elm, "encoding"); - info = moo_edit_file_info_new_uri (uri, encoding); + fenc = moo_file_enc_new_for_uri (uri, encoding); - moo_editor_load_file (editor, window, GTK_WIDGET (window), info, TRUE, FALSE, -1, &doc); + moo_editor_load_file (editor, window, GTK_WIDGET (window), fenc, TRUE, FALSE, -1, &doc); - moo_edit_file_info_free (info); + moo_file_enc_free (fenc); g_free (freeme); return doc; } @@ -1666,26 +1629,26 @@ save_window_session (MooEditWindow *window, { MooMarkupNode *node; MooEdit *active_doc; - DocList *docs; + MooEditArray *docs; + guint i; active_doc = moo_edit_window_get_active_doc (window); - docs = window_list_docs (window); + docs = moo_edit_window_get_docs (window); node = moo_markup_create_element (elm, "window"); - while (docs) + for (i = 0; i < docs->n_elms; ++i) { MooMarkupNode *doc_node; - MooEdit *doc = docs->data; + MooEdit *doc = docs->elms[i]; doc_node = save_doc_session (doc, node); if (doc_node && doc == active_doc) moo_markup_set_bool_prop (doc_node, "active", TRUE); - - docs = doc_list_delete_link (docs, docs); } + moo_edit_array_free (docs); return node; } @@ -1739,60 +1702,60 @@ _moo_editor_save_session (MooEditor *editor, { MooMarkupNode *node; MooEditWindow *active_window; - GSList *windows; + MooEditWindowArray *windows; + guint i; g_return_if_fail (MOO_IS_EDITOR (editor)); g_return_if_fail (MOO_MARKUP_IS_ELEMENT (xml)); active_window = moo_editor_get_active_window (editor); - windows = moo_editor_list_windows (editor); + windows = moo_editor_get_windows (editor); node = moo_markup_create_element (xml, "editor"); moo_markup_set_prop (node, "version", CURRENT_SESSION_VERSION); - while (windows) + for (i = 0; i < windows->n_elms; ++i) { - MooEditWindow *window = windows->data; + MooEditWindow *window = windows->elms[i]; MooMarkupNode *window_node; window_node = save_window_session (window, node); if (window_node && window == active_window) moo_markup_set_bool_prop (window_node, "active", TRUE); - - windows = g_slist_delete_link (windows, windows); } + + moo_edit_window_array_free (windows); } -GSList * -moo_editor_list_windows (MooEditor *editor) +MooEditWindowArray * +moo_editor_get_windows (MooEditor *editor) { g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); - return window_list_to_gslist (window_list_copy_links (editor->priv->windows)); + return moo_edit_window_array_copy (editor->priv->windows); } - -GSList * -moo_editor_list_docs (MooEditor *editor) +MooEditArray * +moo_editor_get_docs (MooEditor *editor) { - DocList *docs = NULL, *list; - WindowList *l; + guint i; + MooEditArray *docs; g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); - for (l = editor->priv->windows; l != NULL; l = l->next) + docs = moo_edit_array_new (); + + for (i = 0; i < editor->priv->windows->n_elms; ++i) { - list = window_list_docs (l->data); - list = doc_list_reverse (list); - docs = doc_list_concat (list, docs); + MooEditArray *docs_here = moo_edit_window_get_docs (editor->priv->windows->elms[i]); + moo_edit_array_append_array (docs, docs_here); + moo_edit_array_free (docs_here); } - list = doc_list_copy_links (editor->priv->windowless); - list = doc_list_reverse (list); - docs = doc_list_concat (list, docs); + moo_edit_array_append_array (docs, editor->priv->windowless); - return g_slist_reverse (doc_list_to_gslist (docs)); + return docs; } @@ -1815,16 +1778,14 @@ moo_editor_open_file (MooEditor *editor, } else { - MooEditFileInfo *info; - GSList *list; + MooFileEncArray *list; - info = moo_edit_file_info_new_path (filename, encoding); - list = g_slist_prepend (NULL, info); + list = moo_file_enc_array_new (); + moo_file_enc_array_take (list, moo_file_enc_new_for_path (filename, encoding)); result = moo_editor_open (editor, window, parent, list); - moo_edit_file_info_free (info); - g_slist_free (list); + moo_file_enc_array_free (list); } if (!result) @@ -1842,7 +1803,7 @@ moo_editor_open_file_line (MooEditor *editor, { MooEdit *doc = NULL; char *freeme = NULL; - MooEditFileInfo *info = NULL; + MooFileEnc *fenc = NULL; g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); g_return_val_if_fail (filename != NULL, NULL); @@ -1864,8 +1825,8 @@ moo_editor_open_file_line (MooEditor *editor, if (!g_file_test (filename, G_FILE_TEST_EXISTS)) goto out; - info = moo_edit_file_info_new_path (filename, NULL); - moo_editor_load_file (editor, window, NULL, info, + fenc = moo_file_enc_new_for_path (filename, NULL); + moo_editor_load_file (editor, window, NULL, fenc, is_embedded (editor), TRUE, line, &doc); @@ -1876,7 +1837,7 @@ moo_editor_open_file_line (MooEditor *editor, gtk_widget_grab_focus (GTK_WIDGET (doc)); out: - moo_edit_file_info_free (info); + moo_file_enc_free (fenc); g_free (freeme); return doc; } @@ -1901,7 +1862,7 @@ moo_editor_new_uri (MooEditor *editor, return moo_editor_open_uri (editor, window, parent, NULL, NULL); file = g_file_new_for_uri (uri); - path = g_file_is_native (file) ? g_file_get_path (file) : NULL; + path = g_file_get_path (file); if (path && g_file_test (path, G_FILE_TEST_EXISTS)) { @@ -2143,7 +2104,7 @@ _moo_editor_save (MooEditor *editor, if (moo_edit_is_untitled (doc)) return _moo_editor_save_as (editor, doc, NULL, NULL, error); - file = _moo_edit_get_file (doc); + file = moo_edit_get_file (doc); encoding = g_strdup (moo_edit_get_encoding (doc)); if (!is_embedded (editor) && @@ -2155,8 +2116,7 @@ _moo_editor_save (MooEditor *editor, /* fall through */ out: - if (file) - g_object_unref (file); + g_object_unref (file); g_free (encoding); return result; } @@ -2169,7 +2129,7 @@ _moo_editor_save_as (MooEditor *editor, const char *encoding, GError **error) { - MooEditFileInfo *file_info = NULL; + MooFileEnc *fenc = NULL; gboolean result = FALSE; g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE); @@ -2179,25 +2139,25 @@ _moo_editor_save_as (MooEditor *editor, if (!filename) { - file_info = _moo_edit_save_as_dialog (doc, moo_edit_get_display_basename (doc)); + fenc = _moo_edit_save_as_dialog (doc, moo_edit_get_display_basename (doc)); - if (!file_info) + if (!fenc) goto out; } else { if (!encoding) encoding = moo_edit_get_encoding (doc); - file_info = moo_edit_file_info_new_path (filename, encoding); + fenc = moo_file_enc_new_for_path (filename, encoding); } update_history_item_for_doc (editor, doc, FALSE); - result = do_save (editor, doc, file_info->file, file_info->encoding, error); + result = do_save (editor, doc, fenc->file, fenc->encoding, error); /* fall through */ out: - moo_edit_file_info_free (file_info); + moo_file_enc_free (fenc); return result; } @@ -2224,23 +2184,25 @@ moo_editor_save_copy (MooEditor *editor, return retval; } - static MooEdit * -doc_list_find_filename (DocList *list, - const char *filename) +doc_array_find_filename (MooEditArray *docs, + const char *filename) { - while (list) + guint i; + + for (i = 0; i < docs->n_elms; ++i) { - char *tmp = moo_edit_get_norm_filename (list->data); + MooEdit *doc = docs->elms[i]; + char *tmp = moo_edit_get_norm_filename (doc); /* XXX */ if (tmp && strcmp (tmp, filename) == 0) { g_free (tmp); - return list->data; + return doc; } g_free (tmp); - list = list->next; } + return NULL; } @@ -2251,7 +2213,7 @@ moo_editor_get_doc (MooEditor *editor, char *freeme1 = NULL; char *freeme2 = NULL; MooEdit *doc = NULL; - WindowList *l; + guint i; g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); g_return_val_if_fail (filename != NULL, NULL); @@ -2260,14 +2222,14 @@ moo_editor_get_doc (MooEditor *editor, freeme2 = _moo_edit_normalize_filename_for_comparison (freeme1); filename = freeme2; - if ((doc = doc_list_find_filename (editor->priv->windowless, filename))) + if ((doc = doc_array_find_filename (editor->priv->windowless, filename))) goto out; - for (l = editor->priv->windows; l != NULL; l = l->next) + for (i = 0; i < editor->priv->windows->n_elms; ++i) { - DocList *docs = window_list_docs (l->data); - doc = doc_list_find_filename (docs, filename); - doc_list_free_links (docs); + MooEditArray *docs = moo_edit_window_get_docs (editor->priv->windows->elms[i]); + doc = doc_array_find_filename (docs, filename); + moo_edit_array_free (docs); if (doc) goto out; } @@ -2279,12 +2241,15 @@ out: } static MooEdit * -doc_list_find_uri (DocList *list, - const char *uri) +doc_array_find_uri (MooEditArray *docs, + const char *uri) { - while (list) + guint i; + + for (i = 0; i < docs->n_elms; ++i) { - char *freeme1 = moo_edit_get_uri (list->data); + MooEdit *doc = docs->elms[i]; + char *freeme1 = moo_edit_get_uri (doc); char *freeme2 = freeme1 ? _moo_edit_normalize_uri_for_comparison (freeme1) : NULL; const char *doc_uri = freeme2; /* XXX */ @@ -2292,12 +2257,12 @@ doc_list_find_uri (DocList *list, { g_free (freeme2); g_free (freeme1); - return list->data; + return doc; } g_free (freeme2); g_free (freeme1); - list = list->next; } + return NULL; } @@ -2306,8 +2271,8 @@ moo_editor_get_doc_for_uri (MooEditor *editor, const char *uri) { MooEdit *doc = NULL; - WindowList *l; char *freeme = NULL; + guint i; g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL); g_return_val_if_fail (uri != NULL, NULL); @@ -2315,14 +2280,14 @@ moo_editor_get_doc_for_uri (MooEditor *editor, freeme = _moo_edit_normalize_uri_for_comparison (uri); uri = freeme; - if ((doc = doc_list_find_uri (editor->priv->windowless, uri))) + if ((doc = doc_array_find_uri (editor->priv->windowless, uri))) goto out; - for (l = editor->priv->windows; l != NULL; l = l->next) + for (i = 0; i < editor->priv->windows->n_elms; ++i) { - DocList *docs = window_list_docs (l->data); - doc = doc_list_find_uri (docs, uri); - doc_list_free_links (docs); + MooEditArray *docs = moo_edit_window_get_docs (editor->priv->windows->elms[i]); + doc = doc_array_find_uri (docs, uri); + moo_edit_array_free (docs); if (doc) goto out; } @@ -2385,7 +2350,7 @@ moo_editor_queue_apply_prefs (MooEditor *editor) void moo_editor_apply_prefs (MooEditor *editor) { - GSList *docs; + MooEditArray *docs; gboolean backups; const char *color_scheme, *default_lang; @@ -2412,9 +2377,9 @@ moo_editor_apply_prefs (MooEditor *editor) if (color_scheme) _moo_lang_mgr_set_active_scheme (editor->priv->lang_mgr, color_scheme); - docs = moo_editor_list_docs (editor); - g_slist_foreach (docs, (GFunc) _moo_edit_apply_prefs, NULL); - g_slist_free (docs); + docs = moo_editor_get_docs (editor); + moo_edit_array_foreach (docs, (MooEditArrayForeach) _moo_edit_apply_prefs, NULL); + moo_edit_array_free (docs); backups = moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_MAKE_BACKUPS)); diff --git a/moo/mooedit/mooeditor.h b/moo/mooedit/mooeditor.h index f81ee05d..699ff80c 100644 --- a/moo/mooedit/mooeditor.h +++ b/moo/mooedit/mooeditor.h @@ -16,6 +16,7 @@ #ifndef MOO_EDITOR_H #define MOO_EDITOR_H +#include #include #include @@ -29,7 +30,6 @@ G_BEGIN_DECLS #define MOO_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_EDITOR)) #define MOO_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_EDITOR, MooEditorClass)) -typedef struct MooEditor MooEditor; typedef struct MooEditorPrivate MooEditorPrivate; typedef struct MooEditorClass MooEditorClass; @@ -49,104 +49,100 @@ struct MooEditorClass }; -GType moo_editor_get_type (void) G_GNUC_CONST; +GType moo_editor_get_type (void) G_GNUC_CONST; -MooEditor *moo_editor_instance (void); -MooEditor *moo_editor_create_instance (gboolean embedded); +MooEditor *moo_editor_instance (void); +MooEditor *moo_editor_create (gboolean embedded); /* this creates 'windowless' MooEdit instance */ -MooEdit *moo_editor_create_doc (MooEditor *editor, - const char *filename, - const char *encoding, - GError **error); +MooEdit *moo_editor_create_doc (MooEditor *editor, + const char *filename, + const char *encoding, + GError **error); -MooEditWindow *moo_editor_new_window (MooEditor *editor); -MooEdit *moo_editor_new_doc (MooEditor *editor, - MooEditWindow *window); +MooEditWindow *moo_editor_new_window (MooEditor *editor); +MooEdit *moo_editor_new_doc (MooEditor *editor, + MooEditWindow *window); -gboolean moo_editor_open (MooEditor *editor, - MooEditWindow *window, - GtkWidget *parent, - GSList *files); /* list of MooEditFileInfo* */ -MooEdit *moo_editor_open_file (MooEditor *editor, - MooEditWindow *window, - GtkWidget *parent, - const char *filename, - const char *encoding); -MooEdit *moo_editor_open_file_line (MooEditor *editor, - const char *filename, - int line, - MooEditWindow *window); -MooEdit *moo_editor_new_file (MooEditor *editor, - MooEditWindow *window, - GtkWidget *parent, - const char *filename, - const char *encoding); -MooEdit *moo_editor_open_uri (MooEditor *editor, - MooEditWindow *window, - GtkWidget *parent, - const char *uri, - const char *encoding); +gboolean moo_editor_open (MooEditor *editor, + MooEditWindow *window, + GtkWidget *parent, + MooFileEncArray *files); +MooEdit *moo_editor_open_file (MooEditor *editor, + MooEditWindow *window, + GtkWidget *parent, + const char *filename, + const char *encoding); +MooEdit *moo_editor_open_file_line (MooEditor *editor, + const char *filename, + int line, + MooEditWindow *window); +MooEdit *moo_editor_new_file (MooEditor *editor, + MooEditWindow *window, + GtkWidget *parent, + const char *filename, + const char *encoding); +MooEdit *moo_editor_open_uri (MooEditor *editor, + MooEditWindow *window, + GtkWidget *parent, + const char *uri, + const char *encoding); -MooEdit *moo_editor_get_doc (MooEditor *editor, - const char *filename); -MooEdit *moo_editor_get_doc_for_uri (MooEditor *editor, - const char *uri); +MooEdit *moo_editor_get_doc (MooEditor *editor, + const char *filename); +MooEdit *moo_editor_get_doc_for_uri (MooEditor *editor, + const char *uri); -MooEdit *moo_editor_get_active_doc (MooEditor *editor); -MooEditWindow *moo_editor_get_active_window (MooEditor *editor); +MooEdit *moo_editor_get_active_doc (MooEditor *editor); +MooEditWindow *moo_editor_get_active_window (MooEditor *editor); -void moo_editor_set_active_window (MooEditor *editor, - MooEditWindow *window); -void moo_editor_set_active_doc (MooEditor *editor, - MooEdit *doc); +void moo_editor_set_active_window (MooEditor *editor, + MooEditWindow *window); +void moo_editor_set_active_doc (MooEditor *editor, + MooEdit *doc); -void moo_editor_present (MooEditor *editor, - guint32 stamp); +void moo_editor_present (MooEditor *editor, + guint32 stamp); -/* lists must be freed, content must not be unrefed */ -GSList *moo_editor_list_windows (MooEditor *editor); -GSList *moo_editor_list_docs (MooEditor *editor); +MooEditWindowArray *moo_editor_get_windows (MooEditor *editor); +MooEditArray *moo_editor_get_docs (MooEditor *editor); -gboolean moo_editor_close_window (MooEditor *editor, - MooEditWindow *window, - gboolean ask_confirm); -gboolean moo_editor_close_doc (MooEditor *editor, - MooEdit *doc, - gboolean ask_confirm); -gboolean moo_editor_close_docs (MooEditor *editor, - GSList *list, - gboolean ask_confirm); -gboolean moo_editor_close_all (MooEditor *editor, - gboolean ask_confirm, - gboolean leave_one); +gboolean moo_editor_close_window (MooEditor *editor, + MooEditWindow *window, + gboolean ask_confirm); +gboolean moo_editor_close_doc (MooEditor *editor, + MooEdit *doc, + gboolean ask_confirm); +gboolean moo_editor_close_docs (MooEditor *editor, + MooEditArray *docs, + gboolean ask_confirm); +gboolean moo_editor_close_all (MooEditor *editor, + gboolean ask_confirm, + gboolean leave_one); -MooUiXml *moo_editor_get_ui_xml (MooEditor *editor); -void moo_editor_set_ui_xml (MooEditor *editor, - MooUiXml *xml); -MooUiXml *moo_editor_get_doc_ui_xml (MooEditor *editor); +MooUiXml *moo_editor_get_ui_xml (MooEditor *editor); +void moo_editor_set_ui_xml (MooEditor *editor, + MooUiXml *xml); +MooUiXml *moo_editor_get_doc_ui_xml (MooEditor *editor); -MooEditor *moo_edit_window_get_editor (MooEditWindow *window); -MooEditor *moo_edit_get_editor (MooEdit *doc); +void moo_editor_set_window_type (MooEditor *editor, + GType type); +void moo_editor_set_edit_type (MooEditor *editor, + GType type); -void moo_editor_set_window_type (MooEditor *editor, - GType type); -void moo_editor_set_edit_type (MooEditor *editor, - GType type); +gboolean moo_editor_save_copy (MooEditor *editor, + MooEdit *doc, + const char *filename, + const char *encoding, + GError **error); -gboolean moo_editor_save_copy (MooEditor *editor, - MooEdit *doc, - const char *filename, - const char *encoding, - GError **error); +void moo_editor_apply_prefs (MooEditor *editor); +void moo_editor_queue_apply_prefs (MooEditor *editor); -void moo_editor_apply_prefs (MooEditor *editor); -void moo_editor_queue_apply_prefs (MooEditor *editor); - -void _moo_editor_load_session (MooEditor *editor, - MooMarkupNode *xml); -void _moo_editor_save_session (MooEditor *editor, - MooMarkupNode *xml); +void _moo_editor_load_session (MooEditor *editor, + MooMarkupNode *xml); +void _moo_editor_save_session (MooEditor *editor, + MooMarkupNode *xml); enum { diff --git a/moo/mooedit/mooeditprefs.c b/moo/mooedit/mooeditprefs.c index aae11d3c..96822159 100644 --- a/moo/mooedit/mooeditprefs.c +++ b/moo/mooedit/mooeditprefs.c @@ -22,6 +22,7 @@ #include "mooedit/mootextbuffer.h" #include "mooedit/moolangmgr.h" #include "mooutils/mooencodings.h" +#include "mooutils/mooi18n.h" #include #ifdef __WIN32__ @@ -37,6 +38,34 @@ static guint settings[MOO_EDIT_LAST_SETTING]; guint *_moo_edit_settings = settings; +const char * +_moo_get_default_encodings (void) +{ + /* Translators: if translated, it should be a comma-separated list + of encodings to try when opening files. Encodings names should be + those understood by iconv, or "LOCALE" which means user's locale + charset. For instance, the default value is "UTF-8,LOCALE,ISO_8859-15,ISO_8859-1". + You want to add common preferred non-UTF8 encodings used in your locale. + Do not remove ISO_8859-15 and ISO_8859-1, instead leave them at the end, + these are common source files encodings. */ + const char *to_translate = N_("encodings_list"); + const char *encodings; + + encodings = _(to_translate); + + if (!strcmp (encodings, to_translate)) + encodings = "UTF-8," MOO_EDIT_ENCODING_LOCALE ",ISO_8859-1,ISO_8859-15"; + + return encodings; +} + +const char * +_moo_edit_get_default_encoding (void) +{ + return moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_ENCODING_SAVE)); +} + + void _moo_edit_init_config (void) { diff --git a/moo/mooedit/mooeditprefs.h b/moo/mooedit/mooeditprefs.h index da7eeb1a..393f2bd6 100644 --- a/moo/mooedit/mooeditprefs.h +++ b/moo/mooedit/mooeditprefs.h @@ -85,6 +85,9 @@ const char *moo_edit_setting (const char *setting_name); #define MOO_EDIT_PREFS_ENCODINGS "encodings" #define MOO_EDIT_PREFS_ENCODING_SAVE "encoding_save" +#define MOO_EDIT_ENCODING_LOCALE "LOCALE" +const char *_moo_get_default_encodings (void); +const char *_moo_edit_get_default_encoding (void); G_END_DECLS diff --git a/moo/mooedit/mooeditprefspage.c b/moo/mooedit/mooeditprefspage.c index 1bac40e3..e25b253e 100644 --- a/moo/mooedit/mooeditprefspage.c +++ b/moo/mooedit/mooeditprefspage.c @@ -15,7 +15,7 @@ #define MOOEDIT_COMPILATION #include "mooedit/mooedit-impl.h" -#include "mooedit/mooeditor-private.h" +#include "mooedit/mooeditor-impl.h" #include "mooedit/mooeditprefs.h" #include "mooedit/moolangmgr.h" #include "mooedit/mooeditfiltersettings.h" diff --git a/moo/mooedit/mooedittypes.h b/moo/mooedit/mooedittypes.h new file mode 100644 index 00000000..0f58ca4d --- /dev/null +++ b/moo/mooedit/mooedittypes.h @@ -0,0 +1,28 @@ +#ifndef MOO_EDIT_TYPES_H +#define MOO_EDIT_TYPES_H + +#include +#include +#include + +G_BEGIN_DECLS + +typedef struct MooFileEnc MooFileEnc; + +typedef struct MooEdit MooEdit; +typedef struct MooEditWindow MooEditWindow; +typedef struct MooEditor MooEditor; + +MOO_DECLARE_OBJECT_ARRAY (MooEditArray, moo_edit_array, MooEdit) +MOO_DECLARE_OBJECT_ARRAY (MooEditWindowArray, moo_edit_window_array, MooEditWindow) +MOO_DEFINE_SLIST (MooEditList, moo_edit_list, MooEdit) +MOO_DEFINE_SLIST (MooEditWindowList, moo_edit_window_list, MooEditWindow) + +MOO_DECLARE_PTR_ARRAY (MooFileEncArray, moo_file_enc_array, MooFileEnc) + +#define MOO_TYPE_LINE_END (moo_type_line_end ()) +GType moo_type_line_end (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* MOO_EDIT_TYPES_H */ diff --git a/moo/mooedit/mooeditwindow-impl.h b/moo/mooedit/mooeditwindow-impl.h new file mode 100644 index 00000000..a5d96b7e --- /dev/null +++ b/moo/mooedit/mooeditwindow-impl.h @@ -0,0 +1,21 @@ +#ifndef MOO_EDIT_WINDOW_IMPL_H +#define MOO_EDIT_WINDOW_IMPL_H + +#include "mooedit/mooeditwindow.h" + +G_BEGIN_DECLS + +void _moo_edit_window_insert_doc (MooEditWindow *window, + MooEdit *doc, + int position); +void _moo_edit_window_remove_doc (MooEditWindow *window, + MooEdit *doc, + gboolean destroy); +int _moo_edit_window_get_doc_no (MooEditWindow *window, + MooEdit *doc); +void _moo_edit_window_update_title (void); +void _moo_edit_window_set_use_tabs (void); + +G_END_DECLS + +#endif /* MOO_EDIT_WINDOW_IMPL_H */ diff --git a/moo/mooedit/mooeditwindow.c b/moo/mooedit/mooeditwindow.c index 6712fc00..8c363b79 100644 --- a/moo/mooedit/mooeditwindow.c +++ b/moo/mooedit/mooeditwindow.c @@ -19,15 +19,16 @@ #define MOOEDIT_COMPILATION #include "mooedit/mooedit-impl.h" +#include "mooedit/mooeditwindow-impl.h" #include "mooedit/mooedit-accels.h" -#include "mooedit/mooeditor-private.h" +#include "mooedit/mooeditor-impl.h" #include "mooedit/mooeditfiltersettings.h" #include "mooedit/moolang.h" #include "mooedit/mootextbuffer.h" #include "mooedit/mooeditprefs.h" #include "mooedit/mooplugin.h" #include "mooedit/mooeditaction.h" -#include "mooedit/mooedit-bookmarks.h" +#include "mooedit/mooeditbookmark.h" #include "mooedit/moolangmgr.h" #include "mooutils/moonotebook.h" #include "mooutils/moostock.h" @@ -39,7 +40,6 @@ #include "mooutils/mooaction-private.h" #include "mooutils/moofiledialog.h" #include "mooutils/mooencodings.h" -#include "mooutils/mooatom.h" #include "mooutils/moocompat.h" #include "moostatusbar-gxml.h" #include @@ -98,16 +98,17 @@ struct MooEditWindowPrivate { guint history_blocked : 1; }; +MOO_DEFINE_OBJECT_ARRAY (MooEditWindowArray, moo_edit_window_array, MooEditWindow) + enum { TARGET_MOO_EDIT_TAB = 1, TARGET_URI_LIST = 2 }; -#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ()) -MOO_DEFINE_ATOM (MOO_EDIT_TAB, moo_edit_tab) +MOO_DEFINE_ATOM_GLOBAL (MOO_EDIT_TAB, moo_edit_tab) static GtkTargetEntry dest_targets[] = { - {(char*) "MOO_EDIT_TAB", GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB}, + {(char*) MOO_EDIT_TAB_ATOM_NAME, GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB}, {(char*) "text/uri-list", 0, TARGET_URI_LIST} }; @@ -1106,15 +1107,15 @@ moo_edit_get_window (MooEdit *edit) gboolean moo_edit_window_close_all (MooEditWindow *window) { - GSList *docs; + MooEditArray *docs; gboolean result; g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE); - docs = moo_edit_window_list_docs (window); + docs = moo_edit_window_get_docs (window); result = moo_editor_close_docs (window->priv->editor, docs, TRUE); - g_slist_free (docs); + moo_edit_array_free (docs); return result; } @@ -1786,19 +1787,19 @@ static void close_others_activated (GtkWidget *item, MooEditWindow *window) { - GSList *list; + MooEditArray *others; MooEdit *edit = g_object_get_data (G_OBJECT (item), "moo-edit"); g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT (edit)); - list = moo_edit_window_list_docs (window); - list = g_slist_remove (list, edit); + others = moo_edit_window_get_docs (window); + moo_edit_array_remove (others, edit); - if (list) - moo_editor_close_docs (window->priv->editor, list, TRUE); + if (!moo_edit_array_is_empty (others)) + moo_editor_close_docs (window->priv->editor, others, TRUE); - g_slist_free (list); + moo_edit_array_free (others); } @@ -2184,6 +2185,23 @@ moo_edit_window_list_docs (MooEditWindow *window) return g_slist_reverse (list); } +MooEditArray * +moo_edit_window_get_docs (MooEditWindow *window) +{ + MooEditArray *docs; + int num, i; + + g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL); + + docs = moo_edit_array_new (); + num = moo_notebook_get_n_pages (window->priv->notebook); + + for (i = 0; i < num; i++) + moo_edit_array_append (docs, get_nth_tab (window, i)); + + return docs; +} + int moo_edit_window_num_docs (MooEditWindow *window) @@ -3315,33 +3333,6 @@ moo_edit_window_remove_action_check (const char *action_id, } -GSList * -_moo_edit_parse_langs (const char *string) -{ - char **pieces, **p; - GSList *list = NULL; - - if (!string) - return NULL; - - pieces = g_strsplit_set (string, " \t\r\n;,", 0); - - if (!pieces) - return NULL; - - for (p = pieces; *p != NULL; ++p) - { - g_strstrip (*p); - - if (**p) - list = g_slist_prepend (list, _moo_lang_id_from_name (*p)); - } - - g_strfreev (pieces); - return g_slist_reverse (list); -} - - static gboolean check_action_filter (G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED MooEditWindow *window, @@ -3627,9 +3618,10 @@ populate_window_menu (MooEditWindow *window, GtkWidget *no_docs_item) { MooEdit *active_doc; - GSList *docs; + MooEditArray *docs; GList *children, *l; int pos; + guint i; GtkWidget *item; children = g_list_copy (GTK_MENU_SHELL (menu)->children); @@ -3646,24 +3638,26 @@ populate_window_menu (MooEditWindow *window, g_list_free (children); + docs = moo_edit_window_get_docs (window); - docs = moo_edit_window_list_docs (window); - - if (!docs) + if (moo_edit_array_is_empty (docs)) + { + moo_edit_array_free (docs); return; + } item = gtk_separator_menu_item_new (); g_object_set_data (G_OBJECT (item), "moo-document-menu-item", GINT_TO_POINTER (TRUE)); gtk_widget_show (item); gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, ++pos); - docs = g_slist_sort (docs, (GCompareFunc) compare_docs_for_menu); + moo_edit_array_sort (docs, (GCompareFunc) compare_docs_for_menu); active_doc = ACTIVE_DOC (window); - while (docs) + for (i = 0; i < docs->n_elms; ++i) { int idx; - MooEdit *doc = docs->data; + MooEdit *doc = docs->elms[i]; idx = get_page_num (window, doc); @@ -3684,9 +3678,9 @@ populate_window_menu (MooEditWindow *window, gtk_action_get_accel_path (action)); g_free (action_name); } - - docs = g_slist_delete_link (docs, docs); } + + moo_edit_array_free (docs); } static void diff --git a/moo/mooedit/mooeditwindow.h b/moo/mooedit/mooeditwindow.h index becc4851..90263d13 100644 --- a/moo/mooedit/mooeditwindow.h +++ b/moo/mooedit/mooeditwindow.h @@ -16,10 +16,12 @@ #ifndef MOO_EDIT_WINDOW_H #define MOO_EDIT_WINDOW_H +#include #include #include #include #include +#include G_BEGIN_DECLS @@ -31,7 +33,6 @@ G_BEGIN_DECLS #define MOO_IS_EDIT_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_EDIT_WINDOW)) #define MOO_EDIT_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_EDIT_WINDOW, MooEditWindowClass)) -typedef struct MooEditWindow MooEditWindow; typedef struct MooEditWindowPrivate MooEditWindowPrivate; typedef struct MooEditWindowClass MooEditWindowClass; @@ -54,57 +55,61 @@ struct MooEditWindowClass void (*close_doc_after) (MooEditWindow *window); }; +#define MOO_EDIT_TAB_ATOM_NAME "MOO_EDIT_TAB" +#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ()) +MOO_DECLARE_ATOM_GLOBAL (MOO_EDIT_TAB, moo_edit_tab) -GType moo_edit_window_get_type (void) G_GNUC_CONST; +GType moo_edit_window_get_type (void) G_GNUC_CONST; -gboolean moo_edit_window_close_all (MooEditWindow *window); +gboolean moo_edit_window_close_all (MooEditWindow *window); -typedef gboolean (*MooActionCheckFunc) (GtkAction *action, - MooEditWindow *window, - MooEdit *doc, - gpointer data); -void moo_edit_window_set_action_check (const char *action_id, - MooActionCheckType type, - MooActionCheckFunc func, - gpointer data, - GDestroyNotify notify); -void moo_edit_window_set_action_filter (const char *action_id, - MooActionCheckType type, - const char *filter); +typedef gboolean (*MooActionCheckFunc) (GtkAction *action, + MooEditWindow *window, + MooEdit *doc, + gpointer data); +void moo_edit_window_set_action_check (const char *action_id, + MooActionCheckType type, + MooActionCheckFunc func, + gpointer data, + GDestroyNotify notify); +void moo_edit_window_set_action_filter (const char *action_id, + MooActionCheckType type, + const char *filter); -MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window); -void moo_edit_window_set_active_doc (MooEditWindow *window, - MooEdit *edit); -MooEditWindow *moo_edit_get_window (MooEdit *edit); +MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window); +void moo_edit_window_set_active_doc (MooEditWindow *window, + MooEdit *edit); -MooEdit *moo_edit_window_get_nth_doc (MooEditWindow *window, - guint n); +MooEditor *moo_edit_window_get_editor (MooEditWindow *window); + +MooEdit *moo_edit_window_get_nth_doc (MooEditWindow *window, + guint n); +MooEditArray *moo_edit_window_get_docs (MooEditWindow *window); /* list must be freed, elements must not be unref'ed */ -GSList *moo_edit_window_list_docs (MooEditWindow *window); -int moo_edit_window_num_docs (MooEditWindow *window); +GSList *moo_edit_window_list_docs (MooEditWindow *window); +int moo_edit_window_num_docs (MooEditWindow *window); -void moo_edit_window_set_title_prefix (MooEditWindow *window, - const char *prefix); +void moo_edit_window_set_title_prefix (MooEditWindow *window, + const char *prefix); /* sinks widget */ -MooPane *moo_edit_window_add_pane (MooEditWindow *window, - const char *user_id, - GtkWidget *widget, - MooPaneLabel *label, - MooPanePosition position); -gboolean moo_edit_window_remove_pane (MooEditWindow *window, - const char *user_id); -GtkWidget *moo_edit_window_get_pane (MooEditWindow *window, - const char *user_id); - +MooPane *moo_edit_window_add_pane (MooEditWindow *window, + const char *user_id, + GtkWidget *widget, + MooPaneLabel *label, + MooPanePosition position); +gboolean moo_edit_window_remove_pane (MooEditWindow *window, + const char *user_id); +GtkWidget *moo_edit_window_get_pane (MooEditWindow *window, + const char *user_id); typedef void (*MooAbortJobFunc) (gpointer job); -void moo_edit_window_add_stop_client (MooEditWindow *window, - gpointer client); -void moo_edit_window_remove_stop_client (MooEditWindow *window, - gpointer client); -void moo_edit_window_abort_jobs (MooEditWindow *window); +void moo_edit_window_add_stop_client (MooEditWindow *window, + gpointer client); +void moo_edit_window_remove_stop_client (MooEditWindow *window, + gpointer client); +void moo_edit_window_abort_jobs (MooEditWindow *window); G_END_DECLS diff --git a/moo/mooedit/moofileenc.c b/moo/mooedit/moofileenc.c new file mode 100644 index 00000000..f8af483d --- /dev/null +++ b/moo/mooedit/moofileenc.c @@ -0,0 +1,58 @@ +#include "config.h" +#include "moofileenc.h" + +MOO_DEFINE_PTR_ARRAY (MooFileEncArray, moo_file_enc_array, MooFileEnc, + moo_file_enc_copy, moo_file_enc_free) + +MooFileEnc * +moo_file_enc_new (GFile *file, + const char *encoding) +{ + MooFileEnc *fenc; + + g_return_val_if_fail (G_IS_FILE (file), NULL); + + fenc = g_slice_new0 (MooFileEnc); + fenc->file = g_file_dup (file); + fenc->encoding = g_strdup (encoding); + + return fenc; +} + +MooFileEnc * +moo_file_enc_copy (MooFileEnc *fenc) +{ + g_return_val_if_fail (fenc != NULL, NULL); + return moo_file_enc_new (fenc->file, fenc->encoding); +} + +void +moo_file_enc_free (MooFileEnc *fenc) +{ + if (fenc) + { + g_object_unref (fenc->file); + g_free (fenc->encoding); + g_slice_free (MooFileEnc, fenc); + } +} + +MooFileEnc * +moo_file_enc_new_for_path (const char *path, + const char *encoding) +{ + GFile *file = g_file_new_for_path (path); + MooFileEnc *fenc = moo_file_enc_new (file, encoding); + g_object_unref (file); + return fenc; +} + +MooFileEnc * +moo_file_enc_new_for_uri (const char *uri, + const char *encoding) +{ + GFile *file = g_file_new_for_uri (uri); + MooFileEnc *fenc = moo_file_enc_new (file, encoding); + g_object_unref (file); + return fenc; +} diff --git a/moo/mooedit/moofileenc.h b/moo/mooedit/moofileenc.h new file mode 100644 index 00000000..fcf392c2 --- /dev/null +++ b/moo/mooedit/moofileenc.h @@ -0,0 +1,25 @@ +#ifndef MOO_FILE_INFO_H +#define MOO_FILE_INFO_H + +#include +#include + +G_BEGIN_DECLS + +struct MooFileEnc { + GFile *file; + char *encoding; +}; + +MooFileEnc *moo_file_enc_new (GFile *file, + const char *encoding); +MooFileEnc *moo_file_enc_new_for_path (const char *path, + const char *encoding); +MooFileEnc *moo_file_enc_new_for_uri (const char *uri, + const char *encoding); +MooFileEnc *moo_file_enc_copy (MooFileEnc *fenc); +void moo_file_enc_free (MooFileEnc *fenc); + +G_END_DECLS + +#endif /* MOO_FILE_INFO_H */ diff --git a/moo/mooedit/mooindenter.c b/moo/mooedit/mooindenter.c index 364d1a63..4f6b7bac 100644 --- a/moo/mooedit/mooindenter.c +++ b/moo/mooedit/mooindenter.c @@ -21,46 +21,7 @@ /* XXX this doesn't take unicode control chars into account */ -static GObject *moo_indenter_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_param); -static void moo_indenter_finalize (GObject *object); -static void moo_indenter_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void moo_indenter_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void character_default (MooIndenter *indenter, - const char *inserted_char, - GtkTextIter *where); -static void config_changed_default (MooIndenter *indenter, - guint setting_id, - GParamSpec *pspec); - -static void config_notify (MooIndenter *indenter, - guint var_id, - GParamSpec *pspec); - - -enum { - CONFIG_CHANGED, - CHARACTER, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -enum { - PROP_0, - PROP_TAB_WIDTH, - PROP_USE_TABS, - PROP_INDENT, - PROP_DOC -}; +static void sync_settings (MooIndenter *indenter); enum { SETTING_USE_TABS, @@ -75,18 +36,8 @@ G_DEFINE_TYPE (MooIndenter, moo_indenter, G_TYPE_OBJECT) static void -moo_indenter_class_init (MooIndenterClass *klass) +moo_indenter_class_init (G_GNUC_UNUSED MooIndenterClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->constructor = moo_indenter_constructor; - gobject_class->finalize = moo_indenter_finalize; - gobject_class->set_property = moo_indenter_set_property; - gobject_class->get_property = moo_indenter_get_property; - - klass->character = character_default; - klass->config_changed = config_changed_default; - settings[SETTING_USE_TABS] = moo_edit_config_install_setting ( g_param_spec_boolean ("indent-use-tabs", "indent-use-tabs", "indent-use-tabs", TRUE, (GParamFlags) G_PARAM_READWRITE)); @@ -95,199 +46,29 @@ moo_indenter_class_init (MooIndenterClass *klass) settings[SETTING_INDENT_WIDTH] = moo_edit_config_install_setting ( g_param_spec_uint ("indent-width", "indent-width", "indent-width", 1, G_MAXUINT, 8, (GParamFlags) G_PARAM_READWRITE)); - - g_object_class_install_property (gobject_class, PROP_DOC, - g_param_spec_object ("doc", "doc", "doc", - MOO_TYPE_EDIT, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); - - g_object_class_install_property (gobject_class, PROP_TAB_WIDTH, - g_param_spec_uint ("tab-width", "tab-width", "tab-width", - 1, G_MAXUINT, 8, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT))); - - g_object_class_install_property (gobject_class, PROP_USE_TABS, - g_param_spec_boolean ("use-tabs", "use-tabs", "use-tabs", - TRUE, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT))); - - g_object_class_install_property (gobject_class, PROP_INDENT, - g_param_spec_uint ("indent", "indent", "indent", - 1, G_MAXUINT, 8, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT))); - - signals[CONFIG_CHANGED] = - g_signal_new ("config-changed", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (MooIndenterClass, config_changed), - NULL, NULL, - _moo_marshal_VOID__UINT_POINTER, - G_TYPE_NONE, 2, - G_TYPE_UINT, G_TYPE_POINTER); - - signals[CHARACTER] = - g_signal_new ("character", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (MooIndenterClass, character), - NULL, NULL, - _moo_marshal_VOID__STRING_BOXED, - G_TYPE_NONE, 2, - G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE, - GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE); } static void -moo_indenter_init (G_GNUC_UNUSED MooIndenter *indent) +moo_indenter_init (MooIndenter *indent) { -} - - -static GObject* -moo_indenter_constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *object; - MooIndenter *indent; - - object = G_OBJECT_CLASS(moo_indenter_parent_class)->constructor (type, n_props, props); - indent = MOO_INDENTER (object); - - if (indent->doc) - { - guint i; - GParamSpec *pspec; - guint id; - - for (i = 0; i < LAST_SETTING; ++i) - config_notify (indent, settings[i], NULL); - - pspec = moo_edit_config_lookup_spec ("tab-width", &id, FALSE); - g_return_val_if_fail (pspec != NULL, object); - config_notify (indent, id, pspec); - - g_signal_connect_swapped (indent->doc, "config-notify", - G_CALLBACK (config_notify), - indent); - } - - return object; -} - - -static void -moo_indenter_finalize (GObject *object) -{ - MooIndenter *indent = MOO_INDENTER (object); - - if (indent->doc) - g_signal_handlers_disconnect_by_func (indent->doc, - (gpointer) config_notify, - indent); - indent->doc = NULL; - - G_OBJECT_CLASS(moo_indenter_parent_class)->finalize (object); -} - - -static void moo_indenter_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - MooIndenter *indenter = MOO_INDENTER (object); - - switch (prop_id) - { - case PROP_DOC: - indenter->doc = g_value_get_object (value); - g_object_notify (object, "doc"); - break; - - case PROP_TAB_WIDTH: - indenter->tab_width = g_value_get_uint (value); - g_object_notify (object, "tab-width"); - break; - - case PROP_USE_TABS: - indenter->use_tabs = g_value_get_boolean (value); - g_object_notify (object, "use-tabs"); - break; - - case PROP_INDENT: - indenter->indent = g_value_get_uint (value); - g_object_notify (object, "indent"); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static void moo_indenter_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - MooIndenter *indenter = MOO_INDENTER (object); - - switch (prop_id) - { - case PROP_DOC: - g_value_set_object (value, indenter->doc); - break; - - case PROP_TAB_WIDTH: - g_value_set_uint (value, indenter->tab_width); - break; - - case PROP_USE_TABS: - g_value_set_boolean (value, indenter->use_tabs); - break; - - case PROP_INDENT: - g_value_set_uint (value, indenter->indent); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - - -static void -config_notify (MooIndenter *indenter, - guint var_id, - GParamSpec *pspec) -{ - if (!pspec) - pspec = moo_edit_config_get_spec (var_id); - g_return_if_fail (pspec != NULL); - g_signal_emit (indenter, signals[CONFIG_CHANGED], 0, var_id, pspec); -} - - -void -moo_indenter_character (MooIndenter *indenter, - const char *inserted_char, - GtkTextIter *where) -{ - g_return_if_fail (MOO_IS_INDENTER (indenter)); - MOO_INDENTER_GET_CLASS(indenter)->character (indenter, inserted_char, where); + indent->tab_width = 8; + indent->use_tabs = TRUE; + indent->indent = 8; } MooIndenter * -moo_indenter_new (gpointer doc) +moo_indenter_new (MooEdit *doc) { - g_return_val_if_fail (!doc || MOO_IS_EDIT (doc), NULL); - return MOO_INDENTER (g_object_new (MOO_TYPE_INDENTER, "doc", doc, (const char*) NULL)); + MooIndenter *indent; + + g_return_val_if_fail (MOO_IS_EDIT (doc), NULL); + + indent = g_object_new (MOO_TYPE_INDENTER, NULL); + indent->doc = doc; + + return indent; } @@ -295,7 +76,7 @@ moo_indenter_new (gpointer doc) /* Default implementation */ -char* +char * moo_indenter_make_space (MooIndenter *indenter, guint len, guint start) @@ -306,6 +87,8 @@ moo_indenter_make_space (MooIndenter *indenter, g_return_val_if_fail (MOO_IS_INDENTER (indenter), NULL); + sync_settings (indenter); + if (!len) return NULL; @@ -389,21 +172,27 @@ compute_line_offset (GtkTextIter *dest, } -static void -character_default (MooIndenter *indenter, - const char *inserted_char, - GtkTextIter *where) +void +moo_indenter_character (MooIndenter *indenter, + const char *inserted_char, + GtkTextIter *where) { char *indent_string = NULL; GtkTextBuffer *buffer = gtk_text_iter_get_buffer (where); guint offset; GtkTextIter iter; + g_return_if_fail (MOO_IS_INDENTER (indenter)); g_return_if_fail (inserted_char != NULL); if (*inserted_char != '\n') return; + buffer = gtk_text_iter_get_buffer (where); + g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer)); + + sync_settings (indenter); + iter = *where; gtk_text_iter_backward_line (&iter); compute_line_offset (&iter, indenter->tab_width, &offset); @@ -564,6 +353,8 @@ moo_indenter_tab (MooIndenter *indenter, guint indent = indenter->indent; char *text = NULL; + sync_settings (indenter); + gtk_text_buffer_get_iter_at_mark (buffer, &insert, gtk_text_buffer_get_insert (buffer)); start = insert; @@ -671,6 +462,8 @@ moo_indenter_shift_lines (MooIndenter *indenter, guint i; GtkTextIter iter; + sync_settings (indenter); + for (i = first_line; i <= last_line; ++i) { gtk_text_buffer_get_iter_at_line (buffer, &iter, i); @@ -683,27 +476,10 @@ moo_indenter_shift_lines (MooIndenter *indenter, static void -config_changed_default (MooIndenter *indenter, - guint var_id, - GParamSpec *pspec) +sync_settings (MooIndenter *indenter) { - MooEdit *doc = indenter->doc; - - g_return_if_fail (MOO_IS_EDIT (doc)); - - if (var_id == settings[SETTING_USE_TABS]) - { - gboolean use_tabs = moo_edit_config_get_bool (doc->config, "indent-use-tabs"); - g_object_set (indenter, "use-tabs", use_tabs, NULL); - } - else if (var_id == settings[SETTING_INDENT_WIDTH]) - { - guint width = moo_edit_config_get_uint (doc->config, "indent-width"); - g_object_set (indenter, "indent", width, NULL); - } - else if (!strcmp (pspec->name, "tab-width")) - { - guint tab_width = moo_edit_config_get_uint (doc->config, "tab-width"); - g_object_set (indenter, "tab-width", tab_width, NULL); - } + g_return_if_fail (MOO_IS_EDIT (indenter->doc)); + indenter->use_tabs = moo_edit_config_get_bool (indenter->doc->config, "indent-use-tabs"); + indenter->indent = moo_edit_config_get_uint (indenter->doc->config, "indent-width"); + indenter->tab_width = moo_edit_config_get_uint (indenter->doc->config, "tab-width"); } diff --git a/moo/mooedit/mooindenter.h b/moo/mooedit/mooindenter.h index 898ab278..b605e537 100644 --- a/moo/mooedit/mooindenter.h +++ b/moo/mooedit/mooindenter.h @@ -16,7 +16,7 @@ #ifndef MOO_INDENTER_H #define MOO_INDENTER_H -#include +#include G_BEGIN_DECLS @@ -29,20 +29,19 @@ G_BEGIN_DECLS #define MOO_INDENTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_INDENTER, MooIndenterClass)) -typedef struct _MooIndenter MooIndenter; -typedef struct _MooIndenterClass MooIndenterClass; +typedef struct MooIndenter MooIndenter; +typedef struct MooIndenterClass MooIndenterClass; -struct _MooIndenter +struct MooIndenter { GObject parent; - - gpointer doc; /* MooEdit* */ + MooEdit *doc; gboolean use_tabs; guint tab_width; guint indent; }; -struct _MooIndenterClass +struct MooIndenterClass { GObjectClass parent_class; @@ -57,7 +56,7 @@ struct _MooIndenterClass GType moo_indenter_get_type (void) G_GNUC_CONST; -MooIndenter *moo_indenter_new (gpointer doc); +MooIndenter *moo_indenter_new (MooEdit *doc); char *moo_indenter_make_space (MooIndenter *indenter, guint len, diff --git a/moo/mooedit/mooplugin-loader.c b/moo/mooedit/mooplugin-loader.c index 21bff40c..20c5c38c 100644 --- a/moo/mooedit/mooplugin-loader.c +++ b/moo/mooedit/mooplugin-loader.c @@ -38,7 +38,6 @@ #define KEY_DESCRIPTION "description" #define KEY_AUTHOR "author" #define KEY_VERSION "version" -#define KEY_LANGS "langs" #define KEY_ENABLED "enabled" #define KEY_VISIBLE "visible" @@ -169,7 +168,6 @@ parse_plugin_info (GKeyFile *key_file, char *description; char *author; char *version; - char *langs; gboolean enabled = TRUE; gboolean visible = TRUE; @@ -177,7 +175,6 @@ parse_plugin_info (GKeyFile *key_file, description = g_key_file_get_locale_string (key_file, GROUP_PLUGIN, KEY_DESCRIPTION, NULL, NULL); author = g_key_file_get_locale_string (key_file, GROUP_PLUGIN, KEY_AUTHOR, NULL, NULL); version = g_key_file_get_locale_string (key_file, GROUP_PLUGIN, KEY_VERSION, NULL, NULL); - langs = g_key_file_get_string (key_file, GROUP_PLUGIN, KEY_LANGS, NULL); if (g_key_file_has_key (key_file, GROUP_PLUGIN, KEY_ENABLED, NULL)) enabled = g_key_file_get_boolean (key_file, GROUP_PLUGIN, KEY_ENABLED, NULL); @@ -187,8 +184,7 @@ parse_plugin_info (GKeyFile *key_file, info = moo_plugin_info_new (name ? name : plugin_id, description ? description : "", author ? author : "", - version ? version : "", - langs); + version ? version : ""); params = moo_plugin_params_new (enabled, visible); *info_p = info; @@ -198,7 +194,6 @@ parse_plugin_info (GKeyFile *key_file, g_free (description); g_free (author); g_free (version); - g_free (langs); return TRUE; } diff --git a/moo/mooedit/mooplugin-macro.h b/moo/mooedit/mooplugin-macro.h index bd2540d8..d2bcc3c0 100644 --- a/moo/mooedit/mooplugin-macro.h +++ b/moo/mooedit/mooplugin-macro.h @@ -29,12 +29,11 @@ MOO_MODULE_INIT_FUNC (void) #define MOO_PLUGIN_DEFINE_INFO(plugin_name__,name__, \ - description__,author__,version__, \ - langs__) \ + description__,author__,version__) \ \ static const MooPluginInfo plugin_name__##_plugin_info = \ {(char*) name__, (char*) description__, \ - (char*) author__, (char*) version__, (char*) langs__}; + (char*) author__, (char*) version__}; #define MOO_PLUGIN_DEFINE_FULL(Name__,name__, \ diff --git a/moo/mooedit/mooplugin.c b/moo/mooedit/mooplugin.c index 127413d1..324fd4a5 100644 --- a/moo/mooedit/mooplugin.c +++ b/moo/mooedit/mooplugin.c @@ -191,9 +191,6 @@ moo_plugin_finalize (GObject *object) { MooPlugin *plugin = MOO_PLUGIN (object); - if (plugin->langs) - g_hash_table_destroy (plugin->langs); - g_free (plugin->id); moo_plugin_info_free (plugin->info); moo_plugin_params_free (plugin->params); @@ -219,7 +216,8 @@ moo_plugin_register (const char *id, MooPluginClass *klass; MooPlugin *plugin; char *prefs_key; - GSList *l, *windows; + MooEditWindowArray *windows; + guint i; g_return_val_if_fail (id != NULL && id[0] != 0, FALSE); g_return_val_if_fail (g_utf8_validate (id, -1, NULL), FALSE); @@ -249,43 +247,6 @@ moo_plugin_register (const char *id, plugin->params = params ? moo_plugin_params_copy ((MooPluginParams*) params) : moo_plugin_params_new (TRUE, TRUE); - if (info->langs) - { - char **langs, **p; - GHashTable *table; - - /* XXX */ - langs = g_strsplit_set (info->langs, " \t\r\n", 0); - table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - - for (p = langs; p && *p; ++p) - { - char *lang_id; - - if (!**p) - continue; - - lang_id = _moo_lang_id_from_name (*p); - - if (!g_hash_table_lookup (table, lang_id)) - g_hash_table_insert (table, lang_id, lang_id); - else - g_free (lang_id); - } - - if (!g_hash_table_size (table)) - { - g_warning ("%s: invalid langs string '%s'", G_STRLOC, info->langs); - g_hash_table_destroy (table); - } - else - { - plugin->langs = table; - } - - g_strfreev (langs); - } - if (moo_plugin_lookup (moo_plugin_id (plugin))) { _moo_message ("%s: plugin with id %s already registered", @@ -309,10 +270,10 @@ moo_plugin_register (const char *id, plugin_store_add (plugin); - windows = moo_editor_list_windows (plugin_store->editor); - for (l = windows; l != NULL; l = l->next) - plugin_attach_win (plugin, l->data); - g_slist_free (windows); + windows = moo_editor_get_windows (plugin_store->editor); + for (i = 0; i < windows->n_elms; ++i) + plugin_attach_win (plugin, windows->elms[i]); + moo_edit_window_array_free (windows); return TRUE; } @@ -369,7 +330,8 @@ plugin_attach_win (MooPlugin *plugin, MooWinPluginClass *wklass; MooWinPlugin *win_plugin; GType wtype; - GSList *l, *docs; + MooEditArray *docs; + guint i; g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_PLUGIN (plugin)); @@ -399,10 +361,10 @@ plugin_attach_win (MooPlugin *plugin, g_object_unref (win_plugin); } - docs = moo_edit_window_list_docs (window); - for (l = docs; l != NULL; l = l->next) - plugin_attach_doc (plugin, window, l->data); - g_slist_free (docs); + docs = moo_edit_window_get_docs (window); + for (i = 0; i < docs->n_elms; ++i) + plugin_attach_doc (plugin, window, docs->elms[i]); + moo_edit_array_free (docs); } @@ -413,7 +375,8 @@ plugin_detach_win (MooPlugin *plugin, MooPluginClass *klass; MooWinPluginClass *wklass; MooWinPlugin *win_plugin; - GSList *l, *docs; + MooEditArray *docs; + guint i; g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_PLUGIN (plugin)); @@ -421,10 +384,10 @@ plugin_detach_win (MooPlugin *plugin, if (!moo_plugin_enabled (plugin)) return; - docs = moo_edit_window_list_docs (window); - for (l = docs; l != NULL; l = l->next) - plugin_detach_doc (plugin, window, l->data); - g_slist_free (docs); + docs = moo_edit_window_get_docs (window); + for (i = 0; i < docs->n_elms; ++i) + plugin_detach_doc (plugin, window, docs->elms[i]); + moo_edit_array_free (docs); win_plugin = window_get_plugin (window, plugin); @@ -463,19 +426,6 @@ plugin_attach_doc (MooPlugin *plugin, if (!moo_plugin_enabled (plugin)) return; - /* XXX ! */ - if (plugin->langs) - { - MooLang *lang; - const char *id; - - lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc)); - id = _moo_lang_id (lang); - - if (!g_hash_table_lookup (plugin->langs, id)) - return; - } - plugin->docs = g_slist_prepend (plugin->docs, doc); klass = MOO_PLUGIN_GET_CLASS (plugin); @@ -738,7 +688,8 @@ moo_plugin_enabled (MooPlugin *plugin) static gboolean plugin_enable (MooPlugin *plugin) { - GSList *l, *windows; + MooEditWindowArray *windows; + guint i; g_return_val_if_fail (MOO_IS_PLUGIN (plugin), FALSE); @@ -755,10 +706,10 @@ plugin_enable (MooPlugin *plugin) return FALSE; } - windows = moo_editor_list_windows (plugin_store->editor); - for (l = windows; l != NULL; l = l->next) - plugin_attach_win (plugin, l->data); - g_slist_free (windows); + windows = moo_editor_get_windows (plugin_store->editor); + for (i = 0; i < windows->n_elms; ++i) + plugin_attach_win (plugin, windows->elms[i]); + moo_edit_window_array_free (windows); return TRUE; } @@ -767,7 +718,8 @@ plugin_enable (MooPlugin *plugin) static void plugin_disable (MooPlugin *plugin) { - GSList *l, *windows; + MooEditWindowArray *windows; + guint i; g_return_if_fail (MOO_IS_PLUGIN (plugin)); @@ -776,10 +728,10 @@ plugin_disable (MooPlugin *plugin) g_assert (plugin->initialized); - windows = moo_editor_list_windows (plugin_store->editor); - for (l = windows; l != NULL; l = l->next) - plugin_detach_win (plugin, l->data); - g_slist_free (windows); + windows = moo_editor_get_windows (plugin_store->editor); + for (i = 0; i < windows->n_elms; ++i) + plugin_detach_win (plugin, windows->elms[i]); + moo_edit_window_array_free (windows); plugin_deinit (plugin); plugin->params->enabled = FALSE; @@ -998,35 +950,6 @@ _moo_window_detach_plugins (MooEditWindow *window) } -static void -doc_lang_changed (MooEdit *doc) -{ - GSList *l; - MooLang *lang; - const char *id; - MooEditWindow *window = NULL; - - g_return_if_fail (MOO_IS_EDIT (doc)); - - window = moo_edit_get_window (doc); - lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc)); - id = _moo_lang_id (lang); - - for (l = plugin_store->list; l != NULL; l = l->next) - { - MooPlugin *plugin = l->data; - - if (moo_plugin_enabled (plugin) && plugin->langs) - { - if (g_hash_table_lookup (plugin->langs, id)) - plugin_attach_doc (plugin, window, doc); - else - plugin_detach_doc (plugin, window, doc); - } - } -} - - void _moo_doc_attach_plugins (MooEditWindow *window, MooEdit *doc) @@ -1038,10 +961,6 @@ _moo_doc_attach_plugins (MooEditWindow *window, plugin_store_init (); - g_signal_connect (doc, "config-notify::lang", - G_CALLBACK (doc_lang_changed), - plugin_store); - for (l = plugin_store->list; l != NULL; l = l->next) plugin_attach_doc (l->data, window, doc); } @@ -1058,10 +977,6 @@ _moo_doc_detach_plugins (MooEditWindow *window, plugin_store_init (); - g_signal_handlers_disconnect_by_func (doc, - (gpointer) doc_lang_changed, - plugin_store); - for (l = plugin_store->list; l != NULL; l = l->next) plugin_detach_doc (l->data, window, doc); } @@ -1113,8 +1028,7 @@ MooPluginInfo * moo_plugin_info_new (const char *name, const char *description, const char *author, - const char *version, - const char *langs) + const char *version) { MooPluginInfo *info; @@ -1125,7 +1039,6 @@ moo_plugin_info_new (const char *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); return info; } @@ -1136,7 +1049,7 @@ moo_plugin_info_copy (MooPluginInfo *info) { g_return_val_if_fail (info != NULL, NULL); return moo_plugin_info_new (info->name, info->description, - info->author, info->version, info->langs); + info->author, info->version); } @@ -1149,7 +1062,6 @@ moo_plugin_info_free (MooPluginInfo *info) g_free (info->description); g_free (info->author); g_free (info->version); - g_free (info->langs); g_free (info); } } diff --git a/moo/mooedit/mooplugin.h b/moo/mooedit/mooplugin.h index a174f056..6fb0dcde 100644 --- a/moo/mooedit/mooplugin.h +++ b/moo/mooedit/mooplugin.h @@ -110,7 +110,6 @@ struct _MooPluginInfo char *description; char *author; char *version; - char *langs; }; struct _MooPlugin @@ -123,7 +122,6 @@ struct _MooPlugin GQuark id_quark; MooPluginInfo *info; MooPluginParams *params; - GHashTable *langs; GSList *docs; GType win_plugin_type; GType doc_plugin_type; @@ -225,8 +223,7 @@ void moo_plugin_set_win_plugin_type (MooPlugin *plugin, MooPluginInfo *moo_plugin_info_new (const char *name, const char *description, const char *author, - const char *version, - const char *langs); + const char *version); MooPluginInfo *moo_plugin_info_copy (MooPluginInfo *info); void moo_plugin_info_free (MooPluginInfo *info); MooPluginParams *moo_plugin_params_new (gboolean enabled, diff --git a/moo/mooedit/mootextview.c b/moo/mooedit/mootextview.c index 966397f8..7408a769 100644 --- a/moo/mooedit/mootextview.c +++ b/moo/mooedit/mootextview.c @@ -20,9 +20,10 @@ #include "mooedit/mootextbuffer.h" #include "mooedit/mootextfind.h" #include "mooedit/mootext-private.h" -#include "mooedit/mooedit-enums.h" #include "mooedit/mooeditprefs.h" #include "mooedit/moolangmgr.h" +#include "mooedit/mooeditwindow.h" +#include "mooedit/mooedit.h" #include "marshals.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mooundo.h" @@ -32,6 +33,7 @@ #include "mooutils/mooatom.h" #include "mooutils/mootype-macros.h" #include "mooutils/moocompat.h" +#include "mooutils/mooutils-gobject.h" #include "mooquicksearch-gxml.h" #include #include @@ -2605,14 +2607,10 @@ void moo_text_view_set_lang_by_id (MooTextView *view, const char *lang_id) { - MooEditor *editor; MooLangMgr *mgr; MooLang *lang; MooTextStyleScheme *scheme; - editor = moo_editor_instance (); - g_return_if_fail (editor != NULL); - mgr = moo_lang_mgr_default (); lang = moo_lang_mgr_get_lang (mgr, lang_id); scheme = moo_lang_mgr_get_active_scheme (mgr); @@ -4116,12 +4114,7 @@ static void quick_search_message (MooTextView *view, const char *msg) { - GtkWidget *window; - - window = gtk_widget_get_toplevel (GTK_WIDGET (view)); - - if (MOO_IS_EDIT_WINDOW (window)) - moo_window_message (MOO_WINDOW (window), msg); + moo_text_view_message (view, msg); } diff --git a/moo/moofileview/moofileview.c b/moo/moofileview/moofileview.c index d71f2ae0..433a3507 100644 --- a/moo/moofileview/moofileview.c +++ b/moo/moofileview/moofileview.c @@ -1906,15 +1906,34 @@ static void size_data_func (G_GNUC_UNUSED GObject *column_or_iconvie gboolean -moo_file_view_chdir (MooFileView *fileview, - const char *dir, - GError **error) +moo_file_view_chdir (MooFileView *fileview, + GFile *file, + GError **error) +{ + gboolean result; + char *dir; + + moo_return_error_if_fail (MOO_IS_FILE_VIEW (fileview)); + + dir = g_file_get_path (file); + moo_return_error_if_fail (dir != NULL); + + result = moo_file_view_chdir_path (fileview, dir, error); + + g_free (dir); + return result; +} + +gboolean +moo_file_view_chdir_path (MooFileView *fileview, + const char *path, + GError **error) { gboolean result; - g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), FALSE); + moo_return_error_if_fail (MOO_IS_FILE_VIEW (fileview)); - g_signal_emit (fileview, signals[CHDIR], 0, dir, error, &result); + g_signal_emit (fileview, signals[CHDIR], 0, path, error, &result); return result; } @@ -1949,7 +1968,7 @@ moo_file_view_go_up (MooFileView *fileview) const char *path = _moo_folder_get_path (parent); char *name = g_path_get_basename (_moo_folder_get_path (fileview->priv->current_dir)); - if (moo_file_view_chdir (fileview, path, NULL)) + if (moo_file_view_chdir_path (fileview, path, NULL)) _moo_file_view_select_name (fileview, name); g_free (name); @@ -1967,7 +1986,7 @@ moo_file_view_go_home (MooFileView *fileview) if (fileview->priv->entry_state) stop_path_entry (fileview, TRUE); - if (!moo_file_view_chdir (fileview, moo_file_view_get_home_dir (fileview), &error)) + if (!moo_file_view_chdir_path (fileview, moo_file_view_get_home_dir (fileview), &error)) { g_warning ("%s: could not go home", G_STRLOC); @@ -2005,7 +2024,7 @@ file_list_row_activated (MooFileView *fileview, { GError *error = NULL; - if (!moo_file_view_chdir (fileview, _moo_file_name (file), &error)) + if (!moo_file_view_chdir_path (fileview, _moo_file_name (file), &error)) { g_warning ("%s: could not go into '%s'", G_STRLOC, _moo_file_name (file)); @@ -2216,7 +2235,7 @@ moo_file_view_go (MooFileView *fileview, { fileview->priv->history->block++; - if (!moo_file_view_chdir (fileview, dir, &error)) + if (!moo_file_view_chdir_path (fileview, dir, &error)) { g_warning ("%s: could not go into '%s'", G_STRLOC, dir); @@ -2262,7 +2281,7 @@ moo_file_view_set_property (GObject *object, switch (prop_id) { case PROP_CURRENT_DIRECTORY: - moo_file_view_chdir (fileview, g_value_get_string (value), NULL); + moo_file_view_chdir_path (fileview, g_value_get_string (value), NULL); break; case PROP_HOME_DIRECTORY: @@ -3746,7 +3765,7 @@ bookmark_activate (G_GNUC_UNUSED MooBookmarkMgr *mgr, if (activated != fileview) return; - moo_file_view_chdir (fileview, bookmark->path, NULL); + moo_file_view_chdir_path (fileview, bookmark->path, NULL); } @@ -3755,7 +3774,7 @@ bookmark_activated (MooFileView *fileview, MooBookmark *bookmark) { g_return_if_fail (bookmark != NULL && bookmark->path != NULL); - moo_file_view_chdir (fileview, bookmark->path, NULL); + moo_file_view_chdir_path (fileview, bookmark->path, NULL); } @@ -4567,7 +4586,7 @@ file_view_activate_filename (MooFileView *fileview, if (g_file_test (path, G_FILE_TEST_IS_DIR)) { - if (!moo_file_view_chdir (fileview, path, &error)) + if (!moo_file_view_chdir_path (fileview, path, &error)) { g_warning ("%s: could not chdir to %s", G_STRLOC, path); @@ -4593,7 +4612,7 @@ file_view_activate_filename (MooFileView *fileview, g_return_if_reached (); } - if (!moo_file_view_chdir (fileview, dirname, &error)) + if (!moo_file_view_chdir_path (fileview, dirname, &error)) { g_warning ("%s: could not chdir to %s", G_STRLOC, dirname); @@ -5127,7 +5146,7 @@ drop_open_timeout_func2 (MooFileView *fileview) g_warning ("%s: oops", G_STRLOC); } - if (goto_dir && moo_file_view_chdir (fileview, goto_dir, NULL)) + if (goto_dir && moo_file_view_chdir_path (fileview, goto_dir, NULL)) _moo_file_view_select_name (fileview, NULL); if (file) diff --git a/moo/moofileview/moofileview.h b/moo/moofileview/moofileview.h index 27642813..27e6ffa5 100644 --- a/moo/moofileview/moofileview.h +++ b/moo/moofileview/moofileview.h @@ -17,6 +17,7 @@ #define MOO_FILE_VIEW_H #include +#include G_BEGIN_DECLS @@ -34,6 +35,9 @@ typedef struct MooFileViewClass MooFileViewClass; GType moo_file_view_get_type (void) G_GNUC_CONST; gboolean moo_file_view_chdir (MooFileView *fileview, + GFile *dir, + GError **error); +gboolean moo_file_view_chdir_path (MooFileView *fileview, const char *dir, GError **error); diff --git a/moo/mooscript/mooscript-classes-impl.cpp b/moo/mooscript/mooscript-classes-impl.cpp index ac87a4ba..81431a42 100644 --- a/moo/mooscript/mooscript-classes-impl.cpp +++ b/moo/mooscript/mooscript-classes-impl.cpp @@ -1,6 +1,7 @@ #include "mooscript-classes.h" #include "mooscript-classes-util.h" #include "mooapp/mooapp.h" +#include "mooedit/moofileenc.h" #include "mooutils/mooutils-misc.h" #include "mooutils/moodialogs.h" #include @@ -89,6 +90,18 @@ static VariantArray wrap_gslist(GSList *list) return array; } +template +static VariantArray wrap_array(GArrayClass *ar) +{ + VariantArray array; + for (guint i = 0; i < ar->n_elms; ++i) + { + GClass *gobj = ar->elms[i]; + array.append(HObject(gobj ? Class::wrap(gobj)->id() : 0)); + } + return array; +} + static Index get_index(const Variant &val) { switch (val.vt()) @@ -534,42 +547,24 @@ void Editor::set_active_window(DocumentWindow &window) moo_editor_set_active_window(moo_editor_instance(), window.gobj()); } -/// @item Editor.active_view() -/// returns current active document view -DocumentView *Editor::active_view() -{ - return DocumentView::wrap(moo_editor_get_active_doc(moo_editor_instance())); -} - -/// @item Editor.set_active_view(view) -/// makes @param{view} active -void Editor::set_active_view(DocumentView &view) -{ - moo_editor_set_active_doc(moo_editor_instance(), view.gobj()); -} - /// @item Editor.documents() /// returns list of all open documents VariantArray Editor::documents() { - GSList *docs = moo_editor_list_docs(moo_editor_instance()); - return wrap_gslist(docs); -} - -/// @item Editor.views() -/// returns list of all open document views -VariantArray Editor::views() -{ - GSList *docs = moo_editor_list_docs(moo_editor_instance()); - return wrap_gslist(docs); + MooEditArray *docs = moo_editor_get_docs(moo_editor_instance()); + VariantArray ret = wrap_array(docs); + moo_edit_array_free(docs); + return ret; } /// @item Editor.windows() /// returns list of all document windows VariantArray Editor::windows() { - GSList *windows = moo_editor_list_windows(moo_editor_instance()); - return wrap_gslist(windows); + MooEditWindowArray *windows = moo_editor_get_windows(moo_editor_instance()); + VariantArray ret = wrap_array(windows); + moo_edit_window_array_free(windows); + return ret; } /// @item Editor.new_document(window=null) @@ -601,39 +596,37 @@ Document *Editor::get_document_by_uri(const String &uri) return Document::wrap(moo_editor_get_doc_for_uri(moo_editor_instance(), uri)); } -static GSList *get_file_info_list(const Variant &val, bool uri) +static MooFileEncArray *get_file_info_list(const Variant &val, bool uri) { moo::Vector filenames = get_string_list(val); if (filenames.empty()) return NULL; - GSList *files = NULL; + MooFileEncArray *files = moo_file_enc_array_new(); for (int i = 0, c = filenames.size(); i < c; ++i) { - MooEditFileInfo *fi = uri ? - moo_edit_file_info_new_uri(filenames[i], NULL) : - moo_edit_file_info_new_path(filenames[i], NULL); - if (!fi) + MooFileEnc *fenc = uri ? + moo_file_enc_new_for_uri(filenames[i], NULL) : + moo_file_enc_new_for_path(filenames[i], NULL); + if (!fenc) goto error; - files = g_slist_prepend(files, fi); + moo_file_enc_array_take(files, fenc); } - return g_slist_reverse(files); + return files; error: - g_slist_foreach(files, (GFunc) moo_edit_file_info_free, NULL); - g_slist_free(files); + moo_file_enc_array_free(files); Error::raise("error"); } static void open_files_or_uris(const VariantArray &file_array, DocumentWindow *window, bool uri) { - GSList *files = get_file_info_list(file_array, uri); + MooFileEncArray *files = get_file_info_list(file_array, uri); moo_editor_open(moo_editor_instance(), window ? window->gobj() : NULL, NULL, files); - g_slist_foreach(files, (GFunc) moo_edit_file_info_free, NULL); - g_slist_free(files); + moo_file_enc_array_free(files); } /// @item Editor.open_files(files, window=null) @@ -748,13 +741,12 @@ bool Editor::close_documents(const VariantArray &arr) for (int i = 0, c = arr.size(); i < c; ++i) pvec.append(get_object_arg(arr[i], "doc").gobj()); - GSList *docs = NULL; + MooEditArray *docs = moo_edit_array_new (); for (int i = 0, c = pvec.size(); i < c; ++i) - docs = g_slist_prepend (docs, pvec[i]); - docs = g_slist_reverse (docs); + moo_edit_array_append (docs, pvec[i]); bool retval = moo_editor_close_docs (moo_editor_instance(), docs, TRUE); - g_slist_free (docs); + moo_edit_array_free (docs); return retval; } @@ -788,50 +780,28 @@ Editor *DocumentWindow::editor() return &Editor::get_instance(); } -/// @item DocumentWindow.active_view() -/// returns current active document view in this window. -DocumentView *DocumentWindow::active_view() -{ - return DocumentView::wrap(moo_edit_window_get_active_doc(gobj())); -} - -/// @item DocumentWindow.set_active_view(view) -/// makes @param{view} active, i.e. switches to its tab. -void DocumentWindow::set_active_view(DocumentView &view) -{ - moo_edit_window_set_active_doc(gobj(), view.gobj()); -} - /// @item DocumentWindow.active_document() -/// returns current active document in this window, that is the document -/// whose view is the active one. +/// returns current active document in this window. Document *DocumentWindow::active_document() { return Document::wrap(moo_edit_window_get_active_doc(gobj())); } /// @item DocumentWindow.set_active_document(doc) -/// makes active a view of document @param{doc}. It picks arbitrary view -/// of @param{doc} if there are more than one in this window. +/// makes active document @param{doc}. void DocumentWindow::set_active_document(Document &doc) { moo_edit_window_set_active_doc(gobj(), doc.gobj()); } -/// @item DocumentWindow.views() -/// returns list of all document views in this window. -VariantArray DocumentWindow::views() -{ - GSList *docs = moo_edit_window_list_docs(gobj()); - return wrap_gslist(docs); -} - /// @item DocumentWindow.documents() /// returns list of all documents in this window. VariantArray DocumentWindow::documents() { - GSList *docs = moo_edit_window_list_docs(gobj()); - return wrap_gslist(docs); + MooEditArray *docs = moo_edit_window_get_docs(gobj()); + VariantArray ret = wrap_array(docs); + moo_edit_array_free(docs); + return ret; } /// @item DocumentWindow.is_active() @@ -852,84 +822,6 @@ void DocumentWindow::set_active() /// @end table /// -/////////////////////////////////////////////////////////////////////////////// -// -// DocumentView -// - -/// -/// @node DocumentView object -/// @section DocumentView object -/// @helpsection{DOCUMENT_VIEW} -/// @table @method -/// - -/// @item DocumentView.document() -/// returns document to which this view belongs. -Document *DocumentView::document() -{ - return Document::wrap(gobj()); -} - -/// @item DocumentView.window() -/// returns window which contains this view. -DocumentWindow *DocumentView::window() -{ - return DocumentWindow::wrap(moo_edit_get_window(gobj())); -} - -/// @item DocumentView.line_wrap_mode() -/// returns whether line wrapping is enabled. -bool DocumentView::line_wrap_mode() -{ - GtkWrapMode mode; - g_object_get(gobj(), "wrap-mode", &mode, (char*) NULL); - return mode != GTK_WRAP_NONE; -} - -/// @item DocumentView.set_line_wrap_mode(enabled) -/// enables or disables line wrapping. -void DocumentView::set_line_wrap_mode(bool wrap) -{ - moo_edit_ui_set_line_wrap_mode(gobj(), wrap); -} - -/// @item DocumentView.overwrite_mode() -/// returns whether overwrite mode is on. -bool DocumentView::overwrite_mode() -{ - gboolean overwrite; - g_object_get(gobj(), "overwrite", &overwrite, (char*) NULL); - return overwrite; -} - -/// @item DocumentView.set_overwrite_mode(enabled) -/// enables or disables overwrite mode. -void DocumentView::set_overwrite_mode(bool overwrite) -{ - g_object_set(gobj(), "overwrite", gboolean(overwrite), (char*) NULL); -} - -/// @item DocumentView.show_line_numbers() -/// returns whether line numbers are displayed. -bool DocumentView::show_line_numbers() -{ - gboolean show; - g_object_get(gobj(), "show-line-numbers", &show, (char*) NULL); - return show; -} - -/// @item DocumentView.set_show_line_numbers(show) -/// shows or hides line numbers. -void DocumentView::set_show_line_numbers(bool show) -{ - moo_edit_ui_set_show_line_numbers(gobj(), show); -} - -/// -/// @end table -/// - /////////////////////////////////////////////////////////////////////////////// // // Document @@ -948,25 +840,6 @@ static GtkTextBuffer *buffer(Document *doc) return gtk_text_view_get_buffer(GTK_TEXT_VIEW(doc->gobj())); } -/// @item Document.views() -/// returns list of views which display this document. -VariantArray Document::views() -{ - VariantArray views; - views.append(HObject(*DocumentView::wrap(gobj()))); - return views; -} - -/// @item Document.active_view() -/// returns active view of this document. If the document has a single -/// view, then that is returned; otherwise if the current active view -/// belongs to this document, then that view is returned; otherwise -/// a random view is picked. -DocumentView *Document::active_view() -{ - return DocumentView::wrap(gobj()); -} - /// @item Document.filename() /// returns full file path of the document or @null{} if the document /// has not been saved yet or if it can't be represented with a local diff --git a/moo/mooscript/mooscript.xml b/moo/mooscript/mooscript.xml index 5bedb953..1a893a73 100644 --- a/moo/mooscript/mooscript.xml +++ b/moo/mooscript/mooscript.xml @@ -15,13 +15,8 @@ - - - - - @@ -84,31 +79,14 @@ - - - - - - - - - - - - - - - - - diff --git a/moo/mooutils/Makefile.incl b/moo/mooutils/Makefile.incl index ecddc017..a797ac62 100644 --- a/moo/mooutils/Makefile.incl +++ b/moo/mooutils/Makefile.incl @@ -50,6 +50,9 @@ moo_sources += \ mooutils/moofileicon.h \ mooutils/moofilewatch.c \ mooutils/moofilewatch.h \ + mooutils/moofilewriter.c \ + mooutils/moofilewriter.h \ + mooutils/moofilewriter-private.h\ mooutils/moofiltermgr.c \ mooutils/moofiltermgr.h \ mooutils/moofontsel.c \ @@ -105,7 +108,6 @@ moo_sources += \ mooutils/mooutils-enums.h \ mooutils/mooutils-file.c \ mooutils/mooutils-file.h \ - mooutils/mooutils-file-private.h\ mooutils/mooutils-fs.c \ mooutils/mooutils-fs.h \ mooutils/mooutils-gobject-private.h \ diff --git a/moo/mooutils/mooaction-private.h b/moo/mooutils/mooaction-private.h index c03e32d4..e98f2f9d 100644 --- a/moo/mooutils/mooaction-private.h +++ b/moo/mooutils/mooaction-private.h @@ -28,8 +28,6 @@ void _moo_sync_toggle_action (GtkAction *action, const char *prop, gboolean invert); -gpointer _moo_action_get_window (gpointer action); - /* defined in mooactionbase.c */ gboolean _moo_action_get_dead (gpointer action); gboolean _moo_action_get_has_submenu (gpointer action); diff --git a/moo/mooutils/mooaction.h b/moo/mooutils/mooaction.h index 034f821e..26343563 100644 --- a/moo/mooutils/mooaction.h +++ b/moo/mooutils/mooaction.h @@ -86,6 +86,8 @@ GType moo_action_get_type (void) G_GNUC_CONST; GType moo_toggle_action_get_type (void) G_GNUC_CONST; GType moo_radio_action_get_type (void) G_GNUC_CONST; +gpointer _moo_action_get_window (gpointer action); + G_END_DECLS diff --git a/moo/mooutils/mooarray.h b/moo/mooutils/mooarray.h index 37862666..03292649 100644 --- a/moo/mooutils/mooarray.h +++ b/moo/mooutils/mooarray.h @@ -3,23 +3,63 @@ #include -#define MOO_DEFINE_PTR_ARRAY(ArrayType, array_type, ElmType, \ - copy_elm, free_elm) \ +#define MOO_DECLARE_PTR_ARRAY(ArrayType, array_type, ElmType) \ \ typedef struct ArrayType ArrayType; \ + \ struct ArrayType { \ MOO_IP_ARRAY_ELMS (ElmType*, elms); \ }; \ \ -inline static ArrayType * \ +ArrayType *array_type##_new (void); \ +void array_type##_free (ArrayType *ar); \ +void array_type##_append (ArrayType *ar, ElmType *elm); \ +void array_type##_take (ArrayType *ar, ElmType *elm); \ +void array_type##_append_array (ArrayType *ar, ArrayType *ar2); \ +ArrayType *array_type##_copy (ArrayType *ar); \ + \ +typedef void (*ArrayType##Foreach) (ElmType *elm, \ + gpointer data); \ + \ +inline static void \ +array_type##_foreach (const ArrayType *ar, \ + ArrayType##Foreach func, \ + gpointer data) \ +{ \ + guint i; \ + g_return_if_fail (ar != NULL && func != NULL); \ + for (i = 0; i < ar->n_elms; ++i) \ + func (ar->elms[i], data); \ +} \ + \ +void array_type##_sort (ArrayType *ar, GCompareFunc func); \ +int array_type##_find (const ArrayType *ar, ElmType *elm); \ +void array_type##_remove (ArrayType *ar, ElmType *elm); \ +guint array_type##_insert_sorted (ArrayType *ar, ElmType *elm, \ + GCompareFunc func); \ + \ +inline static gboolean array_type##_is_empty (ArrayType *ar) \ +{ \ + return !ar || !ar->n_elms; \ +} \ + \ +inline static gsize array_type##_get_size (ArrayType *ar) \ +{ \ + return ar ? ar->n_elms : 0; \ +} + +#define MOO_DEFINE_PTR_ARRAY(ArrayType, array_type, ElmType, \ + copy_elm, free_elm) \ + \ +ArrayType * \ array_type##_new (void) \ { \ ArrayType *ar = g_slice_new0 (ArrayType); \ - MOO_IP_ARRAY_INIT (ar, elms, 0); \ + MOO_IP_ARRAY_INIT (ElmType*, ar, elms, 0); \ return ar; \ } \ \ -inline static void \ +void \ array_type##_free (ArrayType *ar) \ { \ if (ar) \ @@ -32,23 +72,36 @@ array_type##_free (ArrayType *ar) \ } \ } \ \ -inline static void \ +void \ array_type##_append (ArrayType *ar, ElmType *elm) \ { \ g_return_if_fail (ar != NULL && elm != NULL); \ - MOO_IP_ARRAY_GROW (ar, elms, 1); \ + MOO_IP_ARRAY_GROW (ElmType*, ar, elms, 1); \ ar->elms[ar->n_elms - 1] = copy_elm (elm); \ } \ \ -inline static void \ +void array_type##_append_array (ArrayType *ar, ArrayType *ar2) \ +{ \ + guint i, old_size; \ + g_return_if_fail (ar != NULL && ar2 != NULL); \ + if (!ar2->n_elms) \ + return; \ + old_size = ar->n_elms; \ + MOO_IP_ARRAY_GROW (ElmType*, ar, elms, ar2->n_elms); \ + ar->n_elms += ar2->n_elms; \ + for (i = 0; i < ar2->n_elms; ++i) \ + ar->elms[old_size + i] = copy_elm (ar2->elms[i]); \ +} \ + \ +void \ array_type##_take (ArrayType *ar, ElmType *elm) \ { \ g_return_if_fail (ar != NULL && elm != NULL); \ - MOO_IP_ARRAY_GROW (ar, elms, 1); \ + MOO_IP_ARRAY_GROW (ElmType*, ar, elms, 1); \ ar->elms[ar->n_elms - 1] = elm; \ } \ \ -inline static ArrayType * \ +ArrayType * \ array_type##_copy (ArrayType *ar) \ { \ ArrayType *copy; \ @@ -60,7 +113,7 @@ array_type##_copy (ArrayType *ar) \ if (ar->n_elms) \ { \ guint i; \ - MOO_IP_ARRAY_GROW (copy, elms, ar->n_elms); \ + MOO_IP_ARRAY_GROW (ElmType*, copy, elms, ar->n_elms); \ for (i = 0; i < ar->n_elms; ++i) \ copy->elms[i] = copy_elm (ar->elms[i]); \ } \ @@ -68,39 +121,76 @@ array_type##_copy (ArrayType *ar) \ return copy; \ } \ \ -typedef void (*ArrayType##ForeachFunc) (ElmType *elm, \ - gpointer data); \ - \ -inline static void \ -array_type##_foreach (ArrayType *ar, \ - ArrayType##ForeachFunc func, \ - gpointer data) \ +void array_type##_remove (ArrayType *ar, ElmType *elm) \ { \ guint i; \ - g_return_if_fail (ar != NULL && func != NULL); \ + \ + g_return_if_fail (ar != NULL); \ + \ for (i = 0; i < ar->n_elms; ++i) \ - func (ar->elms[i], data); \ + { \ + if (ar->elms[i] == elm) \ + { \ + MOO_IP_ARRAY_REMOVE_INDEX (ar, elms, i); \ + free_elm (elm); \ + return; \ + } \ + } \ +} \ + \ +static int \ +array_type##_gcompare_data_func (gconstpointer a, \ + gconstpointer b, \ + gpointer user_data) \ +{ \ + GCompareFunc func = (GCompareFunc) user_data; \ + ElmType **ea = (ElmType **) a; \ + ElmType **eb = (ElmType **) b; \ + return func (*ea, *eb); \ +} \ + \ +void \ +array_type##_sort (ArrayType *ar, GCompareFunc func) \ +{ \ + g_return_if_fail (ar != NULL && func != NULL); \ + \ + if (ar->n_elms <= 1) \ + return; \ + \ + g_qsort_with_data (ar->elms, ar->n_elms, sizeof (*ar->elms), \ + array_type##_gcompare_data_func, \ + func); \ +} \ + \ +int array_type##_find (const ArrayType *ar, ElmType *elm) \ +{ \ + guint i; \ + g_return_val_if_fail (ar != NULL && elm != NULL, -1); \ + for (i = 0; i < ar->n_elms; ++i) \ + if (ar->elms[i] == elm) \ + return i; \ + return -1; \ } -#define MOO_DEFINE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \ - MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \ - g_object_ref, g_object_unref) +#define MOO_DECLARE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \ + MOO_DECLARE_PTR_ARRAY (ArrayType, array_type, ElmType) -#define MOO_DEFINE_PTR_ARRAY_NO_COPY(ArrayType, array_type, ElmType) \ -inline static ElmType * \ -array_type##_dummy_copy_elm__ (ElmType *elm) \ -{ \ - return elm; \ -} \ +#define MOO_DEFINE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \ + inline static ElmType * \ + array_type##_ref_elm__ (ElmType *elm) \ + { \ + return (ElmType*) g_object_ref (elm); \ + } \ \ -inline static void \ -array_type##_dummy_free_elm__ (G_GNUC_UNUSED ElmType *elm) \ -{ \ -} \ + inline static void \ + array_type##_unref_elm__ (ElmType *elm) \ + { \ + g_object_unref (elm); \ + } \ \ -MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \ - array_type##_dummy_copy_elm__, \ - array_type##_dummy_free_elm__) + MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \ + array_type##_ref_elm__, \ + array_type##_unref_elm__) #endif /* MOO_ARRAY_H */ diff --git a/moo/mooutils/mooatom.h b/moo/mooutils/mooatom.h index bb18439e..0e602ed7 100644 --- a/moo/mooutils/mooatom.h +++ b/moo/mooutils/mooatom.h @@ -35,6 +35,15 @@ static GdkAtom name ## _atom (void) MOO_DEFINE_ATOM_ (Name) \ } +#define MOO_DECLARE_ATOM_GLOBAL(Name, name) \ +GdkAtom name ## _atom (void) G_GNUC_CONST; + +#define MOO_DEFINE_ATOM_GLOBAL(Name, name) \ +GdkAtom name ## _atom (void) \ +{ \ + MOO_DEFINE_ATOM_ (Name) \ +} + GdkAtom moo_atom_uri_list (void) G_GNUC_CONST; G_END_DECLS diff --git a/moo/mooutils/moofiledialog.c b/moo/mooutils/moofiledialog.c index b6e179d8..c44b3d2a 100644 --- a/moo/mooutils/moofiledialog.c +++ b/moo/mooutils/moofiledialog.c @@ -333,15 +333,23 @@ moo_file_dialog (GtkWidget *parent, { static char *filename; MooFileDialog *dialog; + GFile *start; + GFile *file; - dialog = moo_file_dialog_new (type, parent, FALSE, title, start_dir, start_name); + start = start_dir ? g_file_new_for_path (start_dir) : NULL; + + dialog = moo_file_dialog_new (type, parent, FALSE, title, start, start_name); g_return_val_if_fail (dialog != NULL, NULL); moo_file_dialog_run (dialog); - g_free (filename); - filename = moo_file_dialog_get_filename (dialog); + file = moo_file_dialog_get_file (dialog); + g_free (filename); + filename = file ? g_file_get_path (file) : NULL; + + g_object_unref (file); + g_object_unref (start); g_object_unref (dialog); return filename; } @@ -442,23 +450,20 @@ string_slist_to_strv (GSList *list) return uris; } -static char ** -uri_list_to_filenames (GSList *list) +static MooFileArray * +uri_list_to_files (GSList *list) { - guint len, i; - char **filenames; + MooFileArray *flocs; if (!list) return NULL; - len = g_slist_length (list); - filenames = g_new (char*, len + 1); + flocs = moo_file_array_new (); - for (i = 0; i < len; i++, list = list->next) - filenames[i] = g_filename_from_uri ((const char*) list->data, NULL, NULL); /* XXX check */ + while (list) + moo_file_array_take (flocs, g_file_new_for_uri (list->data)); - filenames[i] = NULL; - return filenames; + return flocs; } @@ -726,12 +731,11 @@ moo_file_dialog_set_extra_widget (MooFileDialog *dialog, } -char * -moo_file_dialog_get_filename (MooFileDialog *dialog) +GFile * +moo_file_dialog_get_file (MooFileDialog *dialog) { g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL); - return dialog->priv->uri ? - g_filename_from_uri (dialog->priv->uri, NULL, NULL) : NULL; + return dialog->priv->uri ? g_file_new_for_uri (dialog->priv->uri) : NULL; } char * @@ -741,11 +745,11 @@ moo_file_dialog_get_uri (MooFileDialog *dialog) return g_strdup (dialog->priv->uri); } -char ** -moo_file_dialog_get_filenames (MooFileDialog *dialog) +MooFileArray * +moo_file_dialog_get_files (MooFileDialog *dialog) { g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL); - return uri_list_to_filenames (dialog->priv->uris); + return uri_list_to_files (dialog->priv->uris); } char ** @@ -808,14 +812,14 @@ moo_file_dialog_new (MooFileDialogType type, GtkWidget *parent, gboolean multiple, const char *title, - const char *start_dir, + GFile *start_loc, const char *start_name) { char *start_dir_uri = NULL; MooFileDialog *dialog; - if (start_dir) - start_dir_uri = g_filename_to_uri (start_dir, NULL, NULL); + if (start_loc) + start_dir_uri = g_file_get_uri (start_loc); dialog = MOO_FILE_DIALOG ( g_object_new (MOO_TYPE_FILE_DIALOG, diff --git a/moo/mooutils/moofiledialog.h b/moo/mooutils/moofiledialog.h index 08e44dcc..a5f8e3e7 100644 --- a/moo/mooutils/moofiledialog.h +++ b/moo/mooutils/moofiledialog.h @@ -17,6 +17,7 @@ #define MOO_FILE_DIALOG_H #include +#include G_BEGIN_DECLS @@ -62,14 +63,14 @@ MooFileDialog *moo_file_dialog_new (MooFileDialogType type, GtkWidget *parent, gboolean multiple, const char *title, - const char *start_dir, + GFile *start_loc, const char *start_name); void moo_file_dialog_set_filter_mgr_id (MooFileDialog *dialog, const char *id); gboolean moo_file_dialog_run (MooFileDialog *dialog); -char *moo_file_dialog_get_filename (MooFileDialog *dialog); -char **moo_file_dialog_get_filenames (MooFileDialog *dialog); +GFile *moo_file_dialog_get_file (MooFileDialog *dialog); +MooFileArray *moo_file_dialog_get_files (MooFileDialog *dialog); char *moo_file_dialog_get_uri (MooFileDialog *dialog); char **moo_file_dialog_get_uris (MooFileDialog *dialog); diff --git a/moo/mooutils/moofileicon.c b/moo/mooutils/moofileicon.c index 82123f87..5e3c64e5 100644 --- a/moo/mooutils/moofileicon.c +++ b/moo/mooutils/moofileicon.c @@ -49,7 +49,7 @@ moo_file_icon_for_file (MooFileIcon *icon, } GdkPixbuf * -moo_get_icon_for_file (const char *path, +moo_get_icon_for_path (const char *path, GtkWidget *widget, GtkIconSize size) { diff --git a/moo/mooutils/moofileicon.h b/moo/mooutils/moofileicon.h index bf37b4c4..efdbe180 100644 --- a/moo/mooutils/moofileicon.h +++ b/moo/mooutils/moofileicon.h @@ -17,6 +17,7 @@ #define MOO_FILE_ICON_H #include +#include G_BEGIN_DECLS @@ -55,7 +56,7 @@ GdkPixbuf *moo_file_icon_get_pixbuf (MooFileIcon *icon, GtkWidget *widget, GtkIconSize size); /* needs gtk lock */ -GdkPixbuf *moo_get_icon_for_file (const char *path, +GdkPixbuf *moo_get_icon_for_path (const char *path, GtkWidget *widget, GtkIconSize size); diff --git a/moo/mooutils/moofileloc.c b/moo/mooutils/moofileloc.c new file mode 100644 index 00000000..e69de29b diff --git a/moo/mooutils/mooutils-file-private.h b/moo/mooutils/moofilewriter-private.h similarity index 94% rename from moo/mooutils/mooutils-file-private.h rename to moo/mooutils/moofilewriter-private.h index d5d9175b..96d12a2f 100644 --- a/moo/mooutils/mooutils-file-private.h +++ b/moo/mooutils/moofilewriter-private.h @@ -1,5 +1,5 @@ /* - * mooutils-file-private.h + * moofilewriter-private.h * * Copyright (C) 2004-2010 by Yevgen Muntyan * @@ -13,10 +13,10 @@ * License along with medit. If not, see . */ -#ifndef MOO_UTILS_FILE_PRIVATE_H -#define MOO_UTILS_FILE_PRIVATE_H +#ifndef MOO_FILE_WRITER_PRIVATE_H +#define MOO_FILE_WRITER_PRIVATE_H -#include "mooutils/mooutils-file.h" +#include "mooutils/moofilewriter.h" G_BEGIN_DECLS @@ -82,4 +82,4 @@ struct MooStringWriterClass { G_END_DECLS -#endif /* MOO_UTILS_FILE_PRIVATE_H */ +#endif /* MOO_FILE_WRITER_PRIVATE_H */ diff --git a/moo/mooutils/moofilewriter.c b/moo/mooutils/moofilewriter.c index c665c3fe..bd8ed5e8 100644 --- a/moo/mooutils/moofilewriter.c +++ b/moo/mooutils/moofilewriter.c @@ -1,5 +1,5 @@ /* - * mooutils-file.c + * moofilewriter.c * * Copyright (C) 2004-2010 by Yevgen Muntyan * @@ -14,7 +14,7 @@ */ #include -#include "mooutils/mooutils-file-private.h" +#include "mooutils/moofilewriter-private.h" #include "mooutils/mootype-macros.h" #include "mooutils/mooutils-fs.h" #include "mooutils/mooutils-misc.h" diff --git a/moo/mooutils/moofilewriter.h b/moo/mooutils/moofilewriter.h index e6233366..34a9f121 100644 --- a/moo/mooutils/moofilewriter.h +++ b/moo/mooutils/moofilewriter.h @@ -13,10 +13,9 @@ * License along with medit. If not, see . */ -#ifndef MOO_UTILS_FILE_H -#define MOO_UTILS_FILE_H +#ifndef MOO_FILE_WRITER_H +#define MOO_FILE_WRITER_H -#include #include G_BEGIN_DECLS @@ -70,4 +69,4 @@ const char *moo_string_writer_get_string (MooFileWriter *writer, G_END_DECLS -#endif /* MOO_UTILS_FILE_H */ +#endif /* MOO_FILE_WRITER_H */ diff --git a/moo/mooutils/moomarkup.h b/moo/mooutils/moomarkup.h index 34a290bd..8e0fd39e 100644 --- a/moo/mooutils/moomarkup.h +++ b/moo/mooutils/moomarkup.h @@ -16,7 +16,7 @@ #ifndef MOO_MARKUP_H #define MOO_MARKUP_H -#include +#include G_BEGIN_DECLS diff --git a/moo/mooutils/mooprefs.c b/moo/mooutils/mooprefs.c index 0470d6ac..d5d3c18b 100644 --- a/moo/mooutils/mooprefs.c +++ b/moo/mooutils/mooprefs.c @@ -981,6 +981,13 @@ moo_prefs_get_filename (const char *key) return val; } +GFile * +moo_prefs_get_file (const char *key) +{ + const char *uri = moo_prefs_get_string (key); + return uri ? g_file_new_for_uri (uri) : NULL; +} + gboolean moo_prefs_get_bool (const char *key) @@ -1056,6 +1063,25 @@ moo_prefs_set_filename (const char *key, g_free (utf8_val); } +void +moo_prefs_set_file (const char *key, + GFile *val) +{ + char *uri; + + g_return_if_fail (key != NULL); + + if (!val) + { + moo_prefs_set_string (key, NULL); + return; + } + + uri = g_file_get_uri (val); + moo_prefs_set_string (key, uri); + g_free (uri); +} + void moo_prefs_set_int (const char *key, diff --git a/moo/mooutils/mooprefs.h b/moo/mooutils/mooprefs.h index 6d1076e7..9749d5c3 100644 --- a/moo/mooutils/mooprefs.h +++ b/moo/mooutils/mooprefs.h @@ -18,6 +18,7 @@ #include #include +#include G_BEGIN_DECLS @@ -73,6 +74,7 @@ char *moo_prefs_make_keyv (const char *first_comp, const char *moo_prefs_get_string (const char *key); const char *moo_prefs_get_filename (const char *key); +GFile *moo_prefs_get_file (const char *key); gboolean moo_prefs_get_bool (const char *key); int moo_prefs_get_int (const char *key); @@ -80,6 +82,8 @@ void moo_prefs_set_string (const char *key, const char *val); void moo_prefs_set_filename (const char *key, const char *val); +void moo_prefs_set_file (const char *key, + GFile *val); void moo_prefs_set_int (const char *key, int val); void moo_prefs_set_bool (const char *key, diff --git a/moo/mooutils/mooutils-file.c b/moo/mooutils/mooutils-file.c new file mode 100644 index 00000000..69501258 --- /dev/null +++ b/moo/mooutils/mooutils-file.c @@ -0,0 +1,28 @@ +#include "config.h" +#include "mooutils-file.h" +#include "mooutils.h" +#include + +MOO_DEFINE_OBJECT_ARRAY (MooFileArray, moo_file_array, GFile) + +char * +moo_file_get_display_name (GFile *file) +{ + moo_return_val_if_fail (G_IS_FILE (file), NULL); + return g_file_get_parse_name (file); +} + +gboolean +moo_file_fnmatch (GFile *file, + const char *glob) +{ + char *filename; + + moo_return_val_if_fail (G_IS_FILE (file), FALSE); + moo_return_val_if_fail (glob != NULL, FALSE); + + filename = g_file_get_path (file); + moo_return_val_if_fail (filename != NULL, FALSE); + + return fnmatch (glob, filename, 0); +} diff --git a/moo/mooutils/mooutils-file.h b/moo/mooutils/mooutils-file.h new file mode 100644 index 00000000..45f5db4e --- /dev/null +++ b/moo/mooutils/mooutils-file.h @@ -0,0 +1,24 @@ +#ifndef MOO_UTILS_FILE_H +#define MOO_UTILS_FILE_H + +#include +#include + +G_BEGIN_DECLS + +MOO_DECLARE_OBJECT_ARRAY (MooFileArray, moo_file_array, GFile) + +inline static void +moo_file_free (GFile *file) +{ + if (file) + g_object_unref (file); +} + +gboolean moo_file_fnmatch (GFile *file, + const char *glob); +char *moo_file_get_display_name (GFile *file); + +G_END_DECLS + +#endif /* MOO_UTILS_FILE_H */ diff --git a/moo/mooutils/mooutils-mem.h b/moo/mooutils/mooutils-mem.h index 72f64511..23a0b80c 100644 --- a/moo/mooutils/mooutils-mem.h +++ b/moo/mooutils/mooutils-mem.h @@ -44,12 +44,13 @@ G_STMT_START { \ gsize n_##name_; \ gsize n_##name_##_allocd__ -#define MOO_IP_ARRAY_INIT(c_,name_,len_) \ +#define MOO_IP_ARRAY_INIT(ElmType,c_,name_,len_) \ G_STMT_START { \ gsize use_len__ = len_; \ if (use_len__ == 0) \ use_len__ = 2; \ - (c_)->name_ = g_malloc0 (use_len__ * sizeof *(c_)->name_); \ + (c_)->name_ = (ElmType*) \ + g_malloc0 (use_len__ * sizeof *(c_)->name_); \ (c_)->n_##name_ = len_; \ (c_)->n_##name_##_allocd__ = use_len__; \ } G_STMT_END @@ -60,14 +61,14 @@ G_STMT_START { \ (c_)->name_ = NULL; \ } G_STMT_END -#define MOO_IP_ARRAY_GROW(c_,name_,howmuch_) \ +#define MOO_IP_ARRAY_GROW(ElmType,c_,name_,howmuch_) \ G_STMT_START { \ if ((c_)->n_##name_ + howmuch_ > (c_)->n_##name_##_allocd__) \ { \ gsize old_size__ = (c_)->n_##name_##_allocd__; \ gsize new_size__ = MAX(old_size__ * 1.2, \ (c_)->n_##name_ + howmuch_); \ - (c_)->name_ = g_realloc ((c_)->name_, \ + (c_)->name_ = (ElmType*) g_realloc ((c_)->name_, \ new_size__ * sizeof *(c_)->name_); \ (c_)->n_##name_##_allocd__ = new_size__; \ } \ @@ -77,5 +78,16 @@ G_STMT_START { \ (c_)->n_##name_ += howmuch_; \ } G_STMT_END +#define MOO_IP_ARRAY_REMOVE_INDEX(c_,name_,idx_) \ +G_STMT_START { \ + gsize idx__ = idx_; \ + g_assert ((c_)->n_##name_ > 0 && idx__ < (c_)->n_##name_); \ + if (idx__ + 1 < (c_)->n_##name_) \ + MOO_ELMMOVE ((c_)->name_ + idx__, \ + (c_)->name_ + idx__ + 1, \ + (c_)->n_##name_ - idx__ - 1); \ + (c_)->n_##name_ -= 1; \ +} G_STMT_END + #endif /* MOO_UTILS_MEM_H */ diff --git a/moo/mooutils/mooutils-messages.h b/moo/mooutils/mooutils-messages.h index cbf2383d..0e80a236 100644 --- a/moo/mooutils/mooutils-messages.h +++ b/moo/mooutils/mooutils-messages.h @@ -153,6 +153,30 @@ do { \ #define moo_return_if_reached() moo_return_val_if_reached(;) + +GQuark moo_error_quark (void) G_GNUC_CONST; + +#define MOO_ERROR (moo_error_quark ()) + +enum { + MOO_ERROR_UNEXPECTED = 1 +}; + +#define moo_return_error_if_fail(cond) \ +do { \ + if (cond) \ + { \ + } \ + else \ + { \ + moo_critical("Condition '%s' failed", #cond); \ + g_set_error (error, MOO_ERROR, MOO_ERROR_UNEXPECTED,\ + "unexpected error"); \ + return FALSE; \ + } \ +} while (0) + + /* * Suppress warnings when GCC is in -pedantic mode and not -std=c99 */ diff --git a/moo/mooutils/mooutils-misc.c b/moo/mooutils/mooutils-misc.c index 16b2657a..9635307b 100644 --- a/moo/mooutils/mooutils-misc.c +++ b/moo/mooutils/mooutils-misc.c @@ -16,7 +16,7 @@ #include "config.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-fs.h" -#include "mooutils/mooutils-file.h" +#include "mooutils/moofilewriter.h" #include "mooutils/mooutils-debug.h" #include "mooutils/mooi18n.h" #include "mooutils/mooatom.h" @@ -24,6 +24,7 @@ #include "mooutils/mooutils-misc.h" #include #include "mooutils/moocompat.h" +#include "mooutils/mootype-macros.h" #include "moologwindow-gxml.h" #include #include @@ -52,6 +53,7 @@ #include #endif +MOO_DEFINE_QUARK (moo-error, moo_error_quark) G_LOCK_DEFINE_STATIC (moo_user_data_dir); static char *moo_app_instance_name; diff --git a/moo/mooutils/mooutils.h b/moo/mooutils/mooutils.h new file mode 100644 index 00000000..22fd9aff --- /dev/null +++ b/moo/mooutils/mooutils.h @@ -0,0 +1,8 @@ +#ifndef MOO_UTILS_H +#define MOO_UTILS_H + +#include +#include +#include + +#endif /* MOO_UTILS_H */ diff --git a/moo/plugins/ctags/ctags-doc.c b/moo/plugins/ctags/ctags-doc.c index 88cf1253..15b36b27 100644 --- a/moo/plugins/ctags/ctags-doc.c +++ b/moo/plugins/ctags/ctags-doc.c @@ -350,6 +350,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin) { MooEdit *doc; char *filename; + GFile *file; plugin->priv->update_idle = 0; @@ -357,7 +358,8 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin) doc = MOO_DOC_PLUGIN (plugin)->doc; - filename = moo_edit_get_filename (doc); + file = moo_edit_get_file (doc); + filename = file ? g_file_get_path (file) : NULL; if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS)) { @@ -368,7 +370,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin) if (filename) { GSList *list = NULL; - MooLang *lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc)); + MooLang *lang = moo_edit_get_lang (doc); MooCtagsLanguage *ctags_lang = _moo_ctags_language_find_for_name (_moo_lang_id (lang)); if (ctags_lang && (list = moo_ctags_parse_file (filename, ctags_lang->opts))) @@ -381,6 +383,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin) } g_free (filename); + moo_file_free (file); return FALSE; } diff --git a/moo/plugins/ctags/ctags-plugin.c b/moo/plugins/ctags/ctags-plugin.c index fc4ccfb6..4f7237d8 100644 --- a/moo/plugins/ctags/ctags-plugin.c +++ b/moo/plugins/ctags/ctags-plugin.c @@ -159,7 +159,7 @@ ctags_plugin_deinit (G_GNUC_UNUSED CtagsPlugin *plugin) MOO_PLUGIN_DEFINE_INFO (ctags, "Ctags", "Shows functions in the open document", "Yevgen Muntyan \n" "Christian Dywan ", - MOO_VERSION, NULL) + MOO_VERSION) MOO_WIN_PLUGIN_DEFINE (Ctags, ctags) MOO_PLUGIN_DEFINE (Ctags, ctags, NULL, NULL, NULL, NULL, NULL, diff --git a/moo/plugins/moofilelist.c b/moo/plugins/moofilelist.c index 0f416c8c..d5fba619 100644 --- a/moo/plugins/moofilelist.c +++ b/moo/plugins/moofilelist.c @@ -2217,15 +2217,23 @@ compare_docs_by_name (MooEdit *doc1, static gboolean do_update (WindowPlugin *plugin) { - GSList *docs; + MooEditArray *docs; + GSList *list; + guint i; plugin->update_idle = 0; - docs = moo_edit_window_list_docs (MOO_WIN_PLUGIN (plugin)->window); - docs = g_slist_sort (docs, (GCompareFunc) compare_docs_by_name); - file_list_update (plugin->list, docs); - g_slist_free (docs); + docs = moo_edit_window_get_docs (MOO_WIN_PLUGIN (plugin)->window); + for (i = 0, list = NULL; i < docs->n_elms; ++i) + list = g_slist_prepend (list, docs->elms[i]); + + list = g_slist_sort (list, (GCompareFunc) compare_docs_by_name); + + file_list_update (plugin->list, list); + + g_slist_free (list); + moo_edit_array_free (docs); return FALSE; } @@ -2405,7 +2413,7 @@ file_list_plugin_deinit (G_GNUC_UNUSED FileListPlugin *plugin) MOO_PLUGIN_DEFINE_INFO (file_list, N_("File List"), N_("List of files"), "Yevgen Muntyan ", - MOO_VERSION, NULL) + MOO_VERSION) MOO_WIN_PLUGIN_DEFINE (FileList, file_list) MOO_PLUGIN_DEFINE (FileList, file_list, NULL, NULL, NULL, NULL, NULL, diff --git a/moo/plugins/moofileselector.c b/moo/plugins/moofileselector.c index fa0c341c..045d2d99 100644 --- a/moo/plugins/moofileselector.c +++ b/moo/plugins/moofileselector.c @@ -19,13 +19,15 @@ #include "moofileselector.h" #include "mooedit/mooplugin-macro.h" +#include "mooedit/mooeditwindow.h" #include "moofileview/moobookmarkmgr.h" #include "moofileview/moofileview-tools.h" #include "mooeditplugins.h" #include "marshals.h" #include "mooutils/moostock.h" +#include "mooutils/mooprefs.h" #include "mooutils/mooutils-fs.h" -#include "mooutils/mooutils-misc.h" +#include "mooutils/mooutils.h" #include "mooutils/mooentry.h" #include "mooutils/moodialogs.h" #include "mooutils/mooactionfactory.h" @@ -64,7 +66,7 @@ enum { }; static GtkTargetEntry targets[] = { - { (char*) "MOO_EDIT_TAB", GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB }, + { (char*) MOO_EDIT_TAB_ATOM_NAME, GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB }, { (char*) "text/uri-list", 0, TARGET_URI_LIST } }; @@ -72,66 +74,65 @@ static GtkTargetEntry targets[] = { G_DEFINE_TYPE (MooFileSelector, _moo_file_selector, MOO_TYPE_FILE_VIEW) -#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ()) -MOO_DEFINE_ATOM (MOO_EDIT_TAB, moo_edit_tab) - enum { PROP_0, PROP_WINDOW }; -static void moo_file_selector_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void moo_file_selector_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static GObject *moo_file_selector_constructor (GType type, - guint n_props, +static void moo_file_selector_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void moo_file_selector_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static GObject *moo_file_selector_constructor (GType type, + guint n_props, GObjectConstructParam *props); -static void moo_file_selector_finalize (GObject *object); +static void moo_file_selector_finalize (GObject *object); -static void moo_file_selector_select_file (MooFileSelector *filesel, - const char *filename); -static gboolean moo_file_selector_chdir (MooFileView *fileview, - const char *dir, - GError **error); -static void moo_file_selector_activate (MooFileView *fileview, - const char *path); -static void moo_file_selector_populate_popup(MooFileView *fileview, - GList *selected, - GtkMenu *menu); +static void moo_file_selector_select_file (MooFileSelector *filesel, + GFile *file); +static void moo_file_selector_select_path (MooFileSelector *filesel, + const char *filename); +static gboolean moo_file_selector_chdir (MooFileView *fileview, + const char *dir, + GError **error); +static void moo_file_selector_activate (MooFileView *fileview, + const char *path); +static void moo_file_selector_populate_popup(MooFileView *fileview, + GList *selected, + GtkMenu *menu); -static void goto_current_doc_dir (MooFileSelector *filesel); +static void goto_current_doc_dir (MooFileSelector *filesel); -static gboolean moo_file_selector_drop (MooFileView *fileview, - const char *path, - GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time); -static gboolean moo_file_selector_drop_data_received (MooFileView *fileview, - const char *path, - GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - GtkSelectionData *data, - guint info, - guint time); +static gboolean moo_file_selector_drop (MooFileView *fileview, + const char *path, + GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + guint time); +static gboolean moo_file_selector_drop_data_received (MooFileView *fileview, + const char *path, + GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + GtkSelectionData *data, + guint info, + guint time); -static void moo_file_selector_drop_doc (MooFileSelector *filesel, - MooEdit *doc, - const char *destdir, - GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time); +static void moo_file_selector_drop_doc (MooFileSelector *filesel, + MooEdit *doc, + const char *destdir, + GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + guint time); static void @@ -151,13 +152,9 @@ _moo_file_selector_class_init (MooFileSelectorClass *klass) fileview_class->drop_data_received = moo_file_selector_drop_data_received; fileview_class->populate_popup = moo_file_selector_populate_popup; - g_object_class_install_property (gobject_class, - PROP_WINDOW, - g_param_spec_object ("window", - "window", - "window", - MOO_TYPE_EDIT_WINDOW, - (GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT))); + g_object_class_install_property (gobject_class, PROP_WINDOW, + g_param_spec_object ("window", "window", "window", + MOO_TYPE_EDIT_WINDOW, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); _moo_signal_new_cb ("goto-current-doc-dir", G_OBJECT_CLASS_TYPE (klass), @@ -234,17 +231,11 @@ static void file_selector_go_home (MooFileView *fileview) { const char *dir; - char *real_dir = NULL; - dir = moo_prefs_get_string (DIR_PREFS); + dir = moo_prefs_get_filename (DIR_PREFS); - if (dir) - real_dir = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL); - - if (!real_dir || !moo_file_view_chdir (fileview, real_dir, NULL)) + if (!dir || !moo_file_view_chdir_path (fileview, dir, NULL)) g_signal_emit_by_name (fileview, "go-home"); - - g_free (real_dir); } @@ -323,19 +314,16 @@ static void goto_current_doc_dir (MooFileSelector *filesel) { MooEdit *doc; - char *filename; + GFile *file, *parent_file; GError *error = NULL; doc = moo_edit_window_get_active_doc (filesel->window); - filename = doc ? moo_edit_get_filename (doc) : NULL; + file = doc ? moo_edit_get_file (doc) : NULL; + parent_file = file ? g_file_get_parent (file) : NULL; - if (filename) - { - char *dirname = g_path_get_dirname (filename); - if (moo_file_view_chdir (MOO_FILE_VIEW (filesel), dirname, &error)) - moo_file_selector_select_file (filesel, filename); - g_free (dirname); - } + if (parent_file) + if (moo_file_view_chdir (MOO_FILE_VIEW (filesel), parent_file, &error)) + moo_file_selector_select_file (filesel, file); if (error) { @@ -343,7 +331,8 @@ goto_current_doc_dir (MooFileSelector *filesel) g_error_free (error); } - g_free (filename); + g_object_unref (parent_file); + g_object_unref (file); } @@ -678,7 +667,7 @@ moo_file_selector_drop (MooFileView *fileview, static gboolean -moo_file_selector_drop_data_received (MooFileView *fileview, +moo_file_selector_drop_data_received (MooFileView *fileview, const char *path, GtkWidget *widget, GdkDragContext *context, @@ -841,7 +830,7 @@ out: static void -moo_file_selector_select_file (MooFileSelector *filesel, +moo_file_selector_select_path (MooFileSelector *filesel, const char *filename) { char *basename; @@ -854,12 +843,21 @@ moo_file_selector_select_file (MooFileSelector *filesel, g_free (basename); } +static void +moo_file_selector_select_file (MooFileSelector *filesel, + GFile *file) +{ + char *filename = g_file_get_path (file); + moo_file_selector_select_path (filesel, filename); + g_free (filename); +} + static gboolean drop_untitled (MooFileSelector *filesel, - MooEdit *doc, - const char *destdir, - GtkWidget *widget, + MooEdit *doc, + const char *destdir, + GtkWidget *widget, G_GNUC_UNUSED GdkDragContext *context, G_GNUC_UNUSED int x, G_GNUC_UNUSED int y, @@ -878,7 +876,7 @@ drop_untitled (MooFileSelector *filesel, result = moo_edit_save_as (doc, name, NULL, NULL); if (result) - moo_file_selector_select_file (filesel, name); + moo_file_selector_select_path (filesel, name); g_free (name); return result; @@ -899,8 +897,8 @@ doc_save_as (MooFileSelector *filesel, if (filename) { - if (moo_edit_save_as (doc, filename, moo_edit_get_encoding (doc), NULL)) - moo_file_selector_select_file (filesel, filename); + if (moo_edit_save_as (doc, filename, NULL, NULL)) + moo_file_selector_select_path (filesel, filename); g_free (filename); } } @@ -919,8 +917,8 @@ doc_save_copy (MooFileSelector *filesel, if (filename) { - if (moo_edit_save_copy (doc, filename, moo_edit_get_encoding (doc), NULL)) - moo_file_selector_select_file (filesel, filename); + if (moo_edit_save_copy (doc, filename, NULL, NULL)) + moo_file_selector_select_path (filesel, filename); g_free (filename); } } @@ -931,11 +929,11 @@ doc_move (MooFileSelector *filesel, gboolean ask_name, const char *destdir) { - char *filename, *old_filename; + GFile *old_file; + char *filename; - old_filename = moo_edit_get_filename (doc); - /* XXX non-local */ - g_return_if_fail (old_filename != NULL); + old_file = moo_edit_get_file (doc); + g_return_if_fail (old_file != NULL); filename = save_as_dialog (GTK_WIDGET (filesel), destdir, moo_edit_get_display_basename (doc), @@ -943,16 +941,16 @@ doc_move (MooFileSelector *filesel, if (filename) { - if (moo_edit_save_as (doc, filename, moo_edit_get_encoding (doc), NULL)) + if (moo_edit_save_as (doc, filename, NULL, NULL)) { - _moo_unlink (old_filename); - moo_file_selector_select_file (filesel, filename); + g_file_delete (old_file, NULL, NULL); + moo_file_selector_select_path (filesel, filename); } g_free (filename); } - g_free (old_filename); + g_object_unref (old_file); } @@ -1122,13 +1120,13 @@ create_drop_doc_menu (MooFileSelector *filesel, static void moo_file_selector_drop_doc (MooFileSelector *filesel, - MooEdit *doc, - const char *destdir, - GtkWidget *widget, - GdkDragContext *context, - int x, - int y, - guint time) + MooEdit *doc, + const char *destdir, + GtkWidget *widget, + GdkDragContext *context, + int x, + int y, + guint time) { GdkModifierType mods; DropDocAction action; @@ -1210,12 +1208,9 @@ static void file_selector_plugin_attach (MooPlugin *mplugin, MooEditWindow *window) { - MooEditor *editor; GtkWidget *filesel; Plugin *plugin = FILE_SELECTOR_PLUGIN (mplugin); - editor = moo_edit_window_get_editor (window); - if (!plugin->bookmark_mgr) plugin->bookmark_mgr = _moo_bookmark_mgr_new (); @@ -1256,7 +1251,7 @@ MOO_PLUGIN_DEFINE_INFO (file_selector, N_("File Selector"), N_("File selector pane for editor window"), "Yevgen Muntyan ", - MOO_VERSION, NULL) + MOO_VERSION) MOO_PLUGIN_DEFINE (FileSelector, file_selector, file_selector_plugin_attach, file_selector_plugin_detach, NULL, NULL, diff --git a/moo/plugins/moofind.c b/moo/plugins/moofind.c index b682131b..7c8e6428 100644 --- a/moo/plugins/moofind.c +++ b/moo/plugins/moofind.c @@ -244,7 +244,6 @@ find_plugin_init (FindPlugin *plugin) MooUiXml *xml = moo_editor_get_ui_xml (editor); g_return_val_if_fail (klass != NULL, FALSE); - g_return_val_if_fail (editor != NULL, FALSE); moo_window_class_new_action (klass, "FindInFiles", NULL, "display-name", _("Find In Files"), @@ -343,8 +342,8 @@ init_skip_list (void) } static void -create_grep_dialog (MooEditWindow *window, - WindowStuff *stuff) +create_grep_dialog (MooEditWindow *window, + WindowStuff *stuff) { GtkWidget *pattern_entry; @@ -388,8 +387,8 @@ create_grep_dialog (MooEditWindow *window, static void -create_find_dialog (MooEditWindow *window, - WindowStuff *stuff) +create_find_dialog (MooEditWindow *window, + WindowStuff *stuff) { GtkWidget *pattern_entry; @@ -443,11 +442,13 @@ init_dir_entry (MooHistoryCombo *hist_combo, if (!gtk_entry_get_text (GTK_ENTRY (entry))[0]) { MooFileEntryCompletion *completion; + GFile *file; char *filename; completion = g_object_get_data (G_OBJECT (entry), "find-plugin-file-completion"); - filename = doc ? moo_edit_get_filename (doc) : NULL; + file = doc ? moo_edit_get_file (doc) : NULL; + filename = file ? g_file_get_path (file) : NULL; if (filename) { @@ -461,6 +462,7 @@ init_dir_entry (MooHistoryCombo *hist_combo, } g_free (filename); + g_object_unref (file); } #if 0 @@ -556,8 +558,8 @@ get_directories (MooHistoryCombo *combo) static void -do_grep (MooEditWindow *window, - WindowStuff *stuff) +do_grep (MooEditWindow *window, + WindowStuff *stuff) { GtkWidget *pane; MooHistoryCombo *pattern_combo, *skip_combo, *glob_combo; @@ -604,8 +606,8 @@ do_grep (MooEditWindow *window, static void -do_find (MooEditWindow *window, - WindowStuff *stuff) +do_find (MooEditWindow *window, + WindowStuff *stuff) { GtkWidget *pane; MooHistoryCombo *pattern_combo, *skip_combo; @@ -1100,8 +1102,7 @@ output_activate (WindowStuff *stuff, return FALSE; editor = moo_edit_window_get_editor (stuff->window); - moo_editor_open_file_line (editor, line_data->filename, - line_data->line, stuff->window); + moo_editor_open_file_line (editor, line_data->filename, line_data->line, stuff->window); return TRUE; } @@ -1110,7 +1111,7 @@ output_activate (WindowStuff *stuff, MOO_PLUGIN_DEFINE_INFO (find, N_("Find"), N_("Finds everything"), "Yevgen Muntyan ", - MOO_VERSION, NULL) + MOO_VERSION) MOO_WIN_PLUGIN_DEFINE (Find, find) MOO_PLUGIN_DEFINE (Find, find, NULL, NULL, NULL, NULL, NULL, diff --git a/moo/plugins/mooluaplugin.cpp b/moo/plugins/mooluaplugin.cpp index 733a1513..ba071510 100644 --- a/moo/plugins/mooluaplugin.cpp +++ b/moo/plugins/mooluaplugin.cpp @@ -109,7 +109,7 @@ load_lua_module (const char *module_file, MOO_PLUGIN_DEFINE_INFO (moo_lua, N_("Lua"), N_("Lua support"), "Yevgen Muntyan <" MOO_EMAIL ">", - MOO_VERSION, NULL) + MOO_VERSION) MOO_PLUGIN_DEFINE (MooLua, moo_lua, NULL, NULL, NULL, NULL, NULL, 0, 0) diff --git a/moo/plugins/moopythonplugin.c b/moo/plugins/moopythonplugin.c index 4c064328..9fef4a77 100644 --- a/moo/plugins/moopythonplugin.c +++ b/moo/plugins/moopythonplugin.c @@ -57,7 +57,7 @@ load_python_module (const char *module_file, MOO_PLUGIN_DEFINE_INFO (moo_python, N_("Python"), N_("Python support"), "Yevgen Muntyan <" MOO_EMAIL ">", - MOO_VERSION, NULL) + MOO_VERSION) MOO_PLUGIN_DEFINE (MooPython, moo_python, NULL, NULL, NULL, NULL, NULL, 0, 0) diff --git a/moo/plugins/usertools/moocommand.c b/moo/plugins/usertools/moocommand.c index e0522e4e..d72cbec3 100644 --- a/moo/plugins/usertools/moocommand.c +++ b/moo/plugins/usertools/moocommand.c @@ -432,7 +432,8 @@ static gboolean save_all (MooEdit *doc) { MooEditWindow *window; - GSList *list, *l; + MooEditArray *docs; + guint i; gboolean result = TRUE; g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE); @@ -440,18 +441,18 @@ save_all (MooEdit *doc) window = moo_edit_get_window (doc); g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE); - list = moo_edit_window_list_docs (window); + docs = moo_edit_window_get_docs (window); - for (l = list; l != NULL; l = l->next) + for (i = 0; i < docs->n_elms; ++i) { - if (!save_one (l->data)) + if (!save_one (docs->elms[i])) { result = FALSE; break; } } - g_slist_free (list); + moo_edit_array_free (docs); return result; } diff --git a/moo/plugins/usertools/mookeyfile.c b/moo/plugins/usertools/mookeyfile.c index 4570e871..d37965cb 100644 --- a/moo/plugins/usertools/mookeyfile.c +++ b/moo/plugins/usertools/mookeyfile.c @@ -17,7 +17,7 @@ #include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-misc.h" #include "mooutils/mootype-macros.h" -#include "mooedit/mooedit-tests.h" +#include "mooedit/mooeditor-tests.h" #include diff --git a/moo/plugins/usertools/moousertools.c b/moo/plugins/usertools/moousertools.c index 2732f38e..cd111a60 100644 --- a/moo/plugins/usertools/moousertools.c +++ b/moo/plugins/usertools/moousertools.c @@ -1399,7 +1399,7 @@ MOO_PLUGIN_DEFINE_INFO (user_tools, N_("User Tools"), N_("Configurable tools"), "Yevgen Muntyan ", - MOO_VERSION, NULL) + MOO_VERSION) MOO_PLUGIN_DEFINE (UserTools, user_tools, NULL, NULL, NULL, NULL,