Some refactoring

This commit is contained in:
Yevgen Muntyan 2010-11-23 21:54:39 -08:00
parent 25a93907f5
commit 21bf45b7f7
80 changed files with 1797 additions and 1883 deletions

View File

@ -24,6 +24,7 @@ aclocal.m4
*.orig *.orig
*.bak *.bak
*.tmp *.tmp
*.rej
*.pyc *.pyc
.goutputstream-* .goutputstream-*
po*/dist po*/dist

View File

@ -7,7 +7,6 @@
#define HELP_SECTION_DIALOG_FIND_IN_FILES "index.html" #define HELP_SECTION_DIALOG_FIND_IN_FILES "index.html"
#define HELP_SECTION_DIALOG_REPLACE "index.html" #define HELP_SECTION_DIALOG_REPLACE "index.html"
#define HELP_SECTION_DOCUMENT "Document-object.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_EDITING_OPTIONS "Options-for-editing-text.html"
#define HELP_SECTION_FILE_SELECTOR "index.html" #define HELP_SECTION_FILE_SELECTOR "index.html"
#define HELP_SECTION_LICENSE_GPL "GNU-GPL.html" #define HELP_SECTION_LICENSE_GPL "GNU-GPL.html"

View File

@ -18,7 +18,6 @@
* Application object:: Application object * Application object:: Application object
* Editor object:: Editor object * Editor object:: Editor object
* DocumentWindow object:: DocumentWindow object * DocumentWindow object:: DocumentWindow object
* DocumentView object:: DocumentView object
* Document object:: Document object * Document object:: Document object
@end menu @end menu

View File

@ -65,16 +65,6 @@ abcdefghij
tassert(doc.selected_text() == 'abcdefg\n') tassert(doc.selected_text() == 'abcdefg\n')
end 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_active_window()
test_selection() test_selection()
test_views()
cleanup() cleanup()

View File

@ -1,4 +1,4 @@
#include <mooedit/mooedit-tests.h> #include <mooedit/mooeditor-tests.h>
#include <mooscript/lua/moolua-tests.h> #include <mooscript/lua/moolua-tests.h>
#include <mooutils/mooutils-tests.h> #include <mooutils/mooutils-tests.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>

View File

@ -554,21 +554,21 @@ moo_app_get_editor (MooApp *app)
static gboolean static gboolean
close_editor_window (MooApp *app) close_editor_window (MooApp *app)
{ {
GSList *windows; MooEditWindowArray *windows;
gboolean ret = FALSE; gboolean ret = FALSE;
if (!app->priv->running || app->priv->in_try_quit) if (!app->priv->running || app->priv->in_try_quit)
return FALSE; 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); moo_app_quit (app);
ret = TRUE; ret = TRUE;
} }
g_slist_free (windows); moo_edit_window_array_free (windows);
return ret; return ret;
} }
@ -582,7 +582,7 @@ init_plugins (MooApp *app)
static void static void
moo_app_init_editor (MooApp *app) 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_signal_connect_swapped (app->priv->editor, "close-window",
G_CALLBACK (close_editor_window), app); G_CALLBACK (close_editor_window), app);

View File

@ -4,8 +4,8 @@ moo_sources += \
mooedit/mooeditaction-factory.c \ mooedit/mooeditaction-factory.c \
mooedit/mooeditaction-factory.h \ mooedit/mooeditaction-factory.h \
mooedit/mooeditaction.h \ mooedit/mooeditaction.h \
mooedit/mooedit-bookmarks.c \ mooedit/mooeditbookmark.c \
mooedit/mooedit-bookmarks.h \ mooedit/mooeditbookmark.h \
mooedit/mooedit.c \ mooedit/mooedit.c \
mooedit/mooedit.h \ mooedit/mooedit.h \
mooedit/mooeditconfig.c \ mooedit/mooeditconfig.c \
@ -19,14 +19,19 @@ moo_sources += \
mooedit/mooedit-impl.h \ mooedit/mooedit-impl.h \
mooedit/mooeditor.c \ mooedit/mooeditor.c \
mooedit/mooeditor.h \ mooedit/mooeditor.h \
mooedit/mooeditor-impl.h \
mooedit/mooeditor-private.h \ mooedit/mooeditor-private.h \
mooedit/mooeditor-tests.c \
mooedit/mooeditor-tests.h \
mooedit/mooeditprefs.c \ mooedit/mooeditprefs.c \
mooedit/mooeditprefs.h \ mooedit/mooeditprefs.h \
mooedit/mooeditprefspage.c \ mooedit/mooeditprefspage.c \
mooedit/mooedit-private.h \ mooedit/mooedit-private.h \
mooedit/mooedit-tests.h \ mooedit/mooeditor-tests.h \
mooedit/mooeditwindow.c \ mooedit/mooeditwindow.c \
mooedit/mooeditwindow.h \ mooedit/mooeditwindow.h \
mooedit/moofileenc.c \
mooedit/moofileenc.h \
mooedit/moofold.c \ mooedit/moofold.c \
mooedit/moofold.h \ mooedit/moofold.h \
mooedit/mooindenter.c \ mooedit/mooindenter.c \

View File

@ -19,7 +19,7 @@
#define MOOEDIT_COMPILATION #define MOOEDIT_COMPILATION
#include "mooedit/mooedit-private.h" #include "mooedit/mooedit-private.h"
#include "mooedit/mooeditor-private.h" #include "mooedit/mooeditor-impl.h"
#include "mooedit/mooedit-fileops.h" #include "mooedit/mooedit-fileops.h"
#include "mooedit/mooeditdialogs.h" #include "mooedit/mooeditdialogs.h"
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
@ -261,27 +261,6 @@ static LoadResult load_binary (MooEdit *edit,
GError **error); GError **error);
#endif #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 * static GSList *
get_encodings (void) get_encodings (void)
{ {
@ -395,7 +374,7 @@ moo_edit_load_local (MooEdit *edit,
MooLineEndType saved_le; MooLineEndType saved_le;
moo_return_val_if_fail (MOO_IS_EDIT (edit), FALSE); 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)) if (!check_regular (file, error))
return FALSE; return FALSE;
@ -753,8 +732,8 @@ moo_edit_reload_local (MooEdit *edit,
gboolean result, enable_highlight; gboolean result, enable_highlight;
GFile *file; GFile *file;
file = _moo_edit_get_file (edit); file = moo_edit_get_file (edit);
moo_return_val_if_fail (file != NULL, FALSE); moo_return_val_if_fail (G_IS_FILE (file), FALSE);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit));
@ -1233,29 +1212,15 @@ add_untitled (MooEdit *edit)
} }
const char * static char *
_moo_edit_get_default_encoding (void) moo_file_get_display_basename (GFile *file)
{
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)
{ {
char *name; char *name;
const char *slash; const char *slash;
moo_return_val_if_fail (G_IS_FILE (file), NULL); 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); moo_return_val_if_fail (name != NULL, NULL);
slash = strrchr (name, '/'); 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); edit->priv->norm_filename = _moo_edit_normalize_filename_for_comparison (norm_name_tmp);
free_list = g_slist_prepend (free_list, 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_filename = moo_file_get_display_name (file);
edit->priv->display_basename = _moo_file_get_display_basename (file); edit->priv->display_basename = moo_file_get_display_basename (file);
} }
if (!encoding) if (!encoding)
@ -1351,8 +1316,7 @@ _moo_edit_set_file (MooEdit *edit,
g_signal_emit_by_name (edit, "filename-changed", edit->priv->filename, NULL); g_signal_emit_by_name (edit, "filename-changed", edit->priv->filename, NULL);
moo_edit_status_changed (edit); moo_edit_status_changed (edit);
if (tmp) moo_file_free (tmp);
g_object_unref (tmp);
g_slist_foreach (free_list, (GFunc) g_free, NULL); g_slist_foreach (free_list, (GFunc) g_free, NULL);
g_slist_free (free_list); g_slist_free (free_list);
@ -1365,9 +1329,9 @@ _moo_edit_get_icon (MooEdit *doc,
GtkIconSize size) GtkIconSize size)
{ {
if (doc->priv->filename) 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) 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 else
return moo_get_icon_for_file (NULL, widget, size); return moo_get_icon_for_path (NULL, widget, size);
} }

View File

@ -50,7 +50,7 @@ gboolean _moo_edit_reload_file (MooEdit *edit,
const char *encoding, const char *encoding,
GError **error); GError **error);
gboolean _moo_edit_save_file (MooEdit *edit, gboolean _moo_edit_save_file (MooEdit *edit,
GFile *file, GFile *floc,
const char *encoding, const char *encoding,
MooEditSaveFlags flags, MooEditSaveFlags flags,
GError **error); GError **error);
@ -60,9 +60,6 @@ gboolean _moo_edit_save_file_copy (MooEdit *edit,
MooEditSaveFlags flags, MooEditSaveFlags flags,
GError **error); GError **error);
char *_moo_file_get_display_name (GFile *file);
char *_moo_file_get_display_basename (GFile *file);
G_END_DECLS G_END_DECLS

View File

@ -20,18 +20,10 @@
#include "mooedit/mooeditor.h" #include "mooedit/mooeditor.h"
#include "mooedit/mootextview.h" #include "mooedit/mootextview.h"
#include "mooutils/mdhistorymgr.h" #include "mooutils/mdhistorymgr.h"
#include "mooutils/moolist.h"
#include <gio/gio.h> #include <gio/gio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
struct MooEditFileInfo {
GFile *file;
char *encoding;
};
MOO_DEFINE_SLIST(MooEditList, moo_edit_list, MooEdit)
extern MooEditList *_moo_edit_instances; extern MooEditList *_moo_edit_instances;
void _moo_edit_add_class_actions (MooEdit *edit); void _moo_edit_add_class_actions (MooEdit *edit);
@ -92,8 +84,6 @@ void _moo_edit_apply_prefs (MooEdit *edit);
/* File operations /* File operations
*/ */
GFile *_moo_edit_get_file (MooEdit *edit);
void _moo_edit_set_file (MooEdit *edit, void _moo_edit_set_file (MooEdit *edit,
GFile *file, GFile *file,
const char *encoding); const char *encoding);

View File

@ -0,0 +1,3 @@
#define MOOEDIT_COMPILATION
#include "mooedit-priv.h"

View File

@ -16,15 +16,14 @@
#define MOOEDIT_COMPILATION #define MOOEDIT_COMPILATION
#include "mooedit/mooeditaction-factory.h" #include "mooedit/mooeditaction-factory.h"
#include "mooedit/mooedit-private.h" #include "mooedit/mooedit-private.h"
#include "mooedit/mooedit-bookmarks.h" #include "mooedit/mooeditbookmark.h"
#include "mooedit/mootextview-private.h" #include "mooedit/mootextview-private.h"
#include "mooedit/mooeditdialogs.h" #include "mooedit/mooeditdialogs.h"
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
#include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditfiltersettings.h"
#include "mooedit/mooeditor-private.h" #include "mooedit/mooeditor-impl.h"
#include "mooedit/moolangmgr.h" #include "mooedit/moolangmgr.h"
#include "mooedit/mooedit-tests.h"
#include "marshals.h" #include "marshals.h"
#include "mooutils/mooutils-fs.h" #include "mooutils/mooutils-fs.h"
#include "mooutils/mooi18n.h" #include "mooutils/mooi18n.h"
@ -36,10 +35,10 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#define KEY_ENCODING "encoding" #define KEY_ENCODING "encoding"
#define KEY_LINE "line" #define KEY_LINE "line"
MOO_DEFINE_OBJECT_ARRAY (MooEditArray, moo_edit_array, MooEdit)
MooEditList *_moo_edit_instances = NULL; MooEditList *_moo_edit_instances = NULL;
@ -118,7 +117,6 @@ enum {
PROP_ENCODING PROP_ENCODING
}; };
MOO_DEFINE_BOXED_TYPE_C (MooEditFileInfo, moo_edit_file_info)
G_DEFINE_TYPE (MooEdit, moo_edit, MOO_TYPE_TEXT_VIEW) G_DEFINE_TYPE (MooEdit, moo_edit, MOO_TYPE_TEXT_VIEW)
@ -328,8 +326,7 @@ moo_edit_finalize (GObject *object)
{ {
MooEdit *edit = MOO_EDIT (object); MooEdit *edit = MOO_EDIT (object);
if (edit->priv->file) moo_file_free (edit->priv->file);
g_object_unref (edit->priv->file);
g_free (edit->priv->filename); g_free (edit->priv->filename);
g_free (edit->priv->norm_filename); g_free (edit->priv->norm_filename);
g_free (edit->priv->display_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 * GFile *
_moo_edit_get_file (MooEdit *edit) moo_edit_get_file (MooEdit *edit)
{ {
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL); g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
return edit->priv->file ? g_file_dup (edit->priv->file) : 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 static void
moo_edit_set_lang (MooEdit *edit, moo_edit_set_lang (MooEdit *edit,
MooLang *lang) MooLang *lang)
@ -1984,264 +1944,3 @@ moo_edit_ui_set_show_line_numbers (MooEdit *doc,
"show-line-numbers", show, "show-line-numbers", show,
(char*) NULL); (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);
}

View File

@ -19,6 +19,7 @@
#include <mooedit/mootextview.h> #include <mooedit/mootextview.h>
#include <mooedit/mooeditconfig.h> #include <mooedit/mooeditconfig.h>
#include <mooedit/mooedit-enums.h> #include <mooedit/mooedit-enums.h>
#include <mooedit/mooedittypes.h>
#include <mooutils/mooprefs.h> #include <mooutils/mooprefs.h>
G_BEGIN_DECLS 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_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) #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 MooEditPrivate MooEditPrivate;
typedef struct MooEditClass MooEditClass; typedef struct MooEditClass MooEditClass;
@ -73,6 +73,10 @@ struct MooEditClass
GType moo_edit_get_type (void) G_GNUC_CONST; GType moo_edit_get_type (void) G_GNUC_CONST;
GType moo_edit_file_info_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_uri (MooEdit *edit);
char *moo_edit_get_filename (MooEdit *edit); char *moo_edit_get_filename (MooEdit *edit);
char *moo_edit_get_norm_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); char *moo_edit_get_utf8_filename (MooEdit *edit);
MooLang *moo_edit_get_lang (MooEdit *edit);
MooEditor *moo_edit_get_editor (MooEdit *doc);
#ifdef __WIN32__ #ifdef __WIN32__
#define MOO_LE_DEFAULT MOO_LE_WIN32 #define MOO_LE_DEFAULT MOO_LE_WIN32
#else #else
@ -125,14 +133,6 @@ gboolean moo_edit_save_copy (MooEdit *edit,
void moo_edit_comment (MooEdit *edit); void moo_edit_comment (MooEdit *edit);
void moo_edit_uncomment (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, void moo_edit_ui_set_line_wrap_mode (MooEdit *edit,
gboolean enabled); gboolean enabled);
void moo_edit_ui_set_show_line_numbers (MooEdit *edit, void moo_edit_ui_set_show_line_numbers (MooEdit *edit,

View File

@ -54,9 +54,6 @@ GType moo_edit_action_get_type (void) G_GNUC_CONST;
MooEdit *moo_edit_action_get_doc (MooEditAction *action); MooEdit *moo_edit_action_get_doc (MooEditAction *action);
/* defined in mooeditwindow.c */
GSList *_moo_edit_parse_langs (const char *string);
G_END_DECLS G_END_DECLS

View File

@ -14,7 +14,7 @@
*/ */
#define MOOEDIT_COMPILATION #define MOOEDIT_COMPILATION
#include "mooedit/mooedit-bookmarks.h" #include "mooedit/mooeditbookmark.h"
#include "mooedit/mooedit-private.h" #include "mooedit/mooedit-private.h"
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
#include "mooutils/moostock.h" #include "mooutils/moostock.h"

View File

@ -1,5 +1,5 @@
/* /*
* mooedit-bookmarks.h * mooeditbookmark.h
* *
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net> * Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
* *
@ -13,8 +13,8 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>. * License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MOO_EDIT_BOOKMARKS_H #ifndef MOO_EDIT_BOOKMARK_H
#define MOO_EDIT_BOOKMARKS_H #define MOO_EDIT_BOOKMARK_H
#include <mooedit/mooedit.h> #include <mooedit/mooedit.h>
#include <mooedit/moolinemark.h> #include <mooedit/moolinemark.h>
@ -74,4 +74,4 @@ char *_moo_edit_bookmark_get_text (MooEditBookmark *bookmark);
G_END_DECLS G_END_DECLS
#endif /* MOO_EDIT_BOOKMARKS_H */ #endif /* MOO_EDIT_BOOKMARK_H */

View File

@ -105,7 +105,7 @@ moo_edit_config_init (MooEditConfig *config)
config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, MOO_TYPE_EDIT_CONFIG, MooEditConfigPrivate); 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) if (global)
{ {
@ -231,7 +231,7 @@ update_prop_from_global (MooEditConfig *config,
if (prop_id == config->priv->n_values) 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_init (GVALUE (config, prop_id),
G_VALUE_TYPE (GVALUE (global, prop_id))); G_VALUE_TYPE (GVALUE (global, prop_id)));
VALUE (config, prop_id)->source = VALUE (global, prop_id)->source; 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); 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_value_init (GVALUE (global, prop_id), G_PARAM_SPEC_VALUE_TYPE (pspec));
g_param_value_set_default (pspec, GVALUE (global, prop_id)); g_param_value_set_default (pspec, GVALUE (global, prop_id));

View File

@ -17,10 +17,12 @@
#include "mooedit/mooeditdialogs.h" #include "mooedit/mooeditdialogs.h"
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/mooedit-fileops.h" #include "mooedit/mooedit-fileops.h"
#include "mooedit/moofileenc.h"
#include "mooutils/moodialogs.h" #include "mooutils/moodialogs.h"
#include "mooutils/moostock.h" #include "mooutils/moostock.h"
#include "mooutils/mooi18n.h" #include "mooutils/mooi18n.h"
#include "mooutils/mooencodings.h" #include "mooutils/mooencodings.h"
#include "mooutils/mooutils.h"
#include "mootextfind-prompt-gxml.h" #include "mootextfind-prompt-gxml.h"
#include "mooeditsavemult-gxml.h" #include "mooeditsavemult-gxml.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
@ -28,37 +30,34 @@
#include <string.h> #include <string.h>
GSList * MooFileEncArray *
_moo_edit_open_dialog (GtkWidget *widget, _moo_edit_open_dialog (GtkWidget *widget,
MooEdit *current_doc) MooEdit *current_doc)
{ {
MooFileDialog *dialog; MooFileDialog *dialog;
const char *start_dir = NULL;
const char *encoding; const char *encoding;
char *new_start; GFile *start = NULL;
char *freeme = NULL; MooFileArray *files = NULL;
char **filenames = NULL, **p; MooFileEncArray *fencs = NULL;
GSList *infos = NULL; guint i;
moo_prefs_create_key (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), MOO_PREFS_STATE, G_TYPE_STRING, NULL); 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))) 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) if (file)
{ start = g_file_get_parent (file);
freeme = g_path_get_dirname (filename);
start_dir = freeme; g_object_unref (file);
g_free (filename);
}
} }
if (!start_dir) if (!start)
start_dir = 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_OPEN, widget, dialog = moo_file_dialog_new (MOO_FILE_DIALOG_OPEN, widget,
TRUE, GTK_STOCK_OPEN, start_dir, TRUE, GTK_STOCK_OPEN, start,
NULL); NULL);
g_object_set (dialog, "enable-encodings", TRUE, NULL); g_object_set (dialog, "enable-encodings", TRUE, NULL);
moo_file_dialog_set_help_id (dialog, "dialog-open"); 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"); moo_file_dialog_set_filter_mgr_id (dialog, "MooEdit");
if (!moo_file_dialog_run (dialog)) if (moo_file_dialog_run (dialog))
goto out; {
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)) files = moo_file_dialog_get_files (dialog);
encoding = NULL; g_return_val_if_fail (files != NULL && files->n_elms != 0, NULL);
filenames = moo_file_dialog_get_filenames (dialog); fencs = moo_file_enc_array_new ();
g_return_val_if_fail (filenames != NULL, NULL); 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) g_object_unref (start);
infos = g_slist_prepend (infos, moo_edit_file_info_new_path (*p, encoding)); start = g_file_get_parent (files->elms[0]);
infos = g_slist_reverse (infos); moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start);
}
new_start = g_path_get_dirname (filenames[0]); g_object_unref (start);
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 (dialog); g_object_unref (dialog);
g_strfreev (filenames); moo_file_array_free (files);
return infos; return fencs;
} }
MooEditFileInfo * MooFileEnc *
_moo_edit_save_as_dialog (MooEdit *edit, _moo_edit_save_as_dialog (MooEdit *doc,
const char *display_basename) const char *display_basename)
{ {
const char *start = NULL;
char *filename = NULL;
char *freeme = NULL;
const char *encoding; const char *encoding;
char *new_start;
MooFileDialog *dialog; 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_create_key (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR),
MOO_PREFS_STATE, G_TYPE_STRING, NULL); MOO_PREFS_STATE, G_TYPE_STRING, NULL);
if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC))) if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
{ {
char *this_filename = moo_edit_get_filename (edit); file = moo_edit_get_file (doc);
if (file)
if (this_filename) start = g_file_get_parent (file);
{ g_object_unref (file);
freeme = g_path_get_dirname (this_filename); file = NULL;
start = freeme;
g_free (this_filename);
}
} }
if (!start) 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), dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE, GTK_WIDGET (doc),
FALSE, GTK_STOCK_SAVE_AS, start, display_basename); FALSE, GTK_STOCK_SAVE_AS,
start, display_basename);
g_object_set (dialog, "enable-encodings", TRUE, NULL); 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_help_id (dialog, "dialog-save");
moo_file_dialog_set_filter_mgr_id (dialog, "MooEdit"); 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)) if (!moo_file_dialog_run (dialog))
{ {
g_object_unref (dialog); g_object_unref (dialog);
g_free (freeme); g_object_unref (start);
return NULL; return NULL;
} }
encoding = moo_file_dialog_get_encoding (dialog); encoding = moo_file_dialog_get_encoding (dialog);
filename = moo_file_dialog_get_filename (dialog); file = moo_file_dialog_get_file (dialog);
g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (file != NULL, NULL);
file_info = moo_edit_file_info_new_path (filename, encoding); fenc = moo_file_enc_new (file, encoding);
new_start = g_path_get_dirname (filename); g_object_unref (start);
moo_prefs_set_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), new_start); start = g_file_get_parent (file);
g_free (new_start); 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_object_unref (dialog);
g_free (freeme); return fenc;
return file_info;
} }
MooSaveChangesDialogResponse 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); g_return_val_if_fail (MOO_IS_EDIT (doc), MOO_SAVE_CHANGES_RESPONSE_CANCEL);
return moo_save_changes_dialog (moo_edit_get_display_basename (edit), return moo_save_changes_dialog (moo_edit_get_display_basename (doc),
GTK_WIDGET (edit)); GTK_WIDGET (doc));
} }
@ -179,13 +175,13 @@ name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *column,
GtkTreeModel *model, GtkTreeModel *model,
GtkTreeIter *iter) GtkTreeIter *iter)
{ {
MooEdit *edit = NULL; MooEdit *doc = NULL;
gtk_tree_model_get (model, iter, COLUMN_EDIT, &edit, -1); gtk_tree_model_get (model, iter, COLUMN_EDIT, &doc, -1);
g_return_if_fail (MOO_IS_EDIT (edit)); g_return_if_fail (MOO_IS_EDIT (doc));
g_object_set (cell, "text", moo_edit_get_display_basename (edit), NULL); g_object_set (cell, "text", moo_edit_get_display_basename (doc), NULL);
g_object_unref (edit); g_object_unref (doc);
} }
@ -244,22 +240,23 @@ save_toggled (GtkCellRendererToggle *cell,
} }
static void static void
files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, GSList *docs) files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, MooEditArray *docs)
{ {
GtkListStore *store; GtkListStore *store;
GtkTreeViewColumn *column; GtkTreeViewColumn *column;
GtkCellRenderer *cell; GtkCellRenderer *cell;
GSList *l; guint i;
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_BOOLEAN, MOO_TYPE_EDIT); 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; GtkTreeIter iter;
gtk_list_store_append (store, &iter); gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter, gtk_list_store_set (store, &iter,
COLUMN_SAVE, TRUE, COLUMN_SAVE, TRUE,
COLUMN_EDIT, l->data, -1); COLUMN_EDIT, docs->elms[i],
-1);
} }
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store)); 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 * static void
files_treeview_get_to_save (GtkTreeView *treeview) files_treeview_get_to_save (GtkTreeView *treeview,
MooEditArray *to_save)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
GSList *list = NULL;
model = gtk_tree_view_get_model (treeview); 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); gtk_tree_model_get_iter_first (model, &iter);
do do
{ {
MooEdit *edit = NULL; MooEdit *doc = NULL;
gboolean save = TRUE; gboolean save = TRUE;
gtk_tree_model_get (model, &iter, gtk_tree_model_get (model, &iter,
COLUMN_SAVE, &save, COLUMN_SAVE, &save,
COLUMN_EDIT, &edit, -1); COLUMN_EDIT, &doc, -1);
g_return_val_if_fail (MOO_IS_EDIT (edit), list); g_return_if_fail (MOO_IS_EDIT (doc));
if (save) 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)); while (gtk_tree_model_iter_next (model, &iter));
return g_slist_reverse (list);
} }
@ -341,27 +336,22 @@ find_widget_for_response (GtkDialog *dialog,
} }
MooSaveChangesDialogResponse MooSaveChangesDialogResponse
_moo_edit_save_multiple_changes_dialog (GSList *docs, _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
GSList **to_save) MooEditArray *to_save)
{ {
GSList *l;
GtkWidget *dialog; GtkWidget *dialog;
char *msg, *question; char *msg, *question;
int response; int response;
MooSaveChangesDialogResponse retval; MooSaveChangesDialogResponse retval;
SaveMultDialogXml *xml; SaveMultDialogXml *xml;
g_return_val_if_fail (docs != 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 (docs->next != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
g_return_val_if_fail (to_save != NULL, 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 (); xml = save_mult_dialog_xml_new ();
dialog = GTK_WIDGET (xml->SaveMultDialog); 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), gtk_dialog_add_buttons (GTK_DIALOG (dialog),
MOO_STOCK_SAVE_NONE, GTK_RESPONSE_NO, MOO_STOCK_SAVE_NONE, GTK_RESPONSE_NO,
@ -383,8 +373,8 @@ _moo_edit_save_multiple_changes_dialog (GSList *docs,
"Save changes before closing?", "Save changes before closing?",
"There are %u documents with unsaved changes. " "There are %u documents with unsaved changes. "
"Save changes before closing?", "Save changes before closing?",
g_slist_length (docs)), docs->n_elms),
g_slist_length (docs)); (guint) docs->n_elms);
msg = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>", msg = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>",
question); question);
gtk_label_set_markup (xml->label, msg); 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; retval = MOO_SAVE_CHANGES_RESPONSE_DONT_SAVE;
break; break;
case GTK_RESPONSE_YES: 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; retval = MOO_SAVE_CHANGES_RESPONSE_SAVE;
break; break;
default: default:
@ -430,7 +420,7 @@ _moo_edit_save_error_dialog (GtkWidget *widget,
{ {
char *filename, *msg = NULL; char *filename, *msg = NULL;
filename = _moo_file_get_display_name (file); filename = moo_file_get_display_name (file);
if (filename) if (filename)
/* Could not save file foo.txt */ /* Could not save file foo.txt */
@ -454,7 +444,7 @@ _moo_edit_save_error_enc_dialog (GtkWidget *widget,
g_return_if_fail (encoding != NULL); g_return_if_fail (encoding != NULL);
filename = _moo_file_get_display_name (file); filename = moo_file_get_display_name (file);
if (filename) if (filename)
/* Error saving file foo.txt */ /* Error saving file foo.txt */
@ -483,7 +473,7 @@ _moo_edit_open_error_dialog (GtkWidget *widget,
char *filename, *msg = NULL; char *filename, *msg = NULL;
char *secondary; char *secondary;
filename = _moo_file_get_display_name (file); filename = moo_file_get_display_name (file);
if (filename) if (filename)
/* Could not open file foo.txt */ /* Could not open file foo.txt */
@ -529,14 +519,15 @@ _moo_edit_reload_error_dialog (MooEdit *doc,
if (!filename) if (!filename)
{ {
g_critical ("%s: oops", G_STRLOC); moo_critical ("oops");
filename = ""; filename = "";
} }
/* Could not reload file foo.txt */ /* Could not reload file foo.txt */
msg = g_strdup_printf (_("Could not reload file\n%s"), filename); msg = g_strdup_printf (_("Could not reload file\n%s"), filename);
/* XXX */ /* 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); g_free (msg);
} }
@ -547,13 +538,13 @@ _moo_edit_reload_error_dialog (MooEdit *doc,
*/ */
static gboolean static gboolean
moo_edit_question_dialog (MooEdit *edit, moo_edit_question_dialog (MooEdit *doc,
const char *text, const char *text,
const char *secondary, const char *secondary,
const char *button) const char *button)
{ {
int res; 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; GtkWidget *dialog;
dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL, dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
@ -580,22 +571,22 @@ moo_edit_question_dialog (MooEdit *edit,
} }
gboolean gboolean
_moo_edit_reload_modified_dialog (MooEdit *edit) _moo_edit_reload_modified_dialog (MooEdit *doc)
{ {
const char *name; const char *name;
char *question; char *question;
gboolean result; gboolean result;
name = moo_edit_get_display_basename (edit); name = moo_edit_get_display_basename (doc);
if (!name) if (!name)
{ {
g_critical ("%s: oops", G_STRLOC); moo_critical ("oops");
name = ""; name = "";
} }
question = g_strdup_printf (_("Discard changes in file '%s'?"), 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"), _("If you reload the document, changes will be discarded"),
_("_Reload")); _("_Reload"));
@ -604,24 +595,24 @@ _moo_edit_reload_modified_dialog (MooEdit *edit)
} }
gboolean gboolean
_moo_edit_overwrite_modified_dialog (MooEdit *edit) _moo_edit_overwrite_modified_dialog (MooEdit *doc)
{ {
const char *name; const char *name;
char *question, *secondary; char *question, *secondary;
gboolean result; gboolean result;
name = moo_edit_get_display_basename (edit); name = moo_edit_get_display_basename (doc);
if (!name) if (!name)
{ {
g_critical ("%s: oops", G_STRLOC); moo_critical ("%s: oops", G_STRLOC);
name = ""; name = "";
} }
question = g_strdup_printf (_("Overwrite modified file '%s'?"), 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, " secondary = g_strdup_printf (_("File '%s' was modified on disk by another process. If you save it, "
"changes on disk will be lost."), name); "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 (question);
g_free (secondary); g_free (secondary);

View File

@ -17,25 +17,25 @@
#define MOO_EDIT_DIALOGS_H #define MOO_EDIT_DIALOGS_H
#include "mooutils/moodialogs.h" #include "mooutils/moodialogs.h"
#include "mooedit/mooedit.h" #include "mooedit/mooedittypes.h"
#include <gio/gio.h> #include <gio/gio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
MooEditFileInfo *_moo_edit_save_as_dialog (MooEdit *edit, MooFileEnc *_moo_edit_save_as_dialog (MooEdit *doc,
const char *display_basename); const char *display_basename);
GSList *_moo_edit_open_dialog (GtkWidget *widget, MooFileEncArray *_moo_edit_open_dialog (GtkWidget *widget,
MooEdit *current_doc); MooEdit *current_doc);
MooSaveChangesDialogResponse MooSaveChangesDialogResponse
_moo_edit_save_changes_dialog (MooEdit *edit); _moo_edit_save_changes_dialog (MooEdit *doc);
MooSaveChangesDialogResponse MooSaveChangesDialogResponse
_moo_edit_save_multiple_changes_dialog (GSList *docs, _moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
GSList **to_save); MooEditArray *to_save);
gboolean _moo_edit_reload_modified_dialog (MooEdit *edit); gboolean _moo_edit_reload_modified_dialog (MooEdit *doc);
gboolean _moo_edit_overwrite_modified_dialog (MooEdit *edit); gboolean _moo_edit_overwrite_modified_dialog (MooEdit *doc);
void _moo_edit_save_error_dialog (GtkWidget *widget, void _moo_edit_save_error_dialog (GtkWidget *widget,
GFile *file, GFile *file,

View File

@ -17,13 +17,14 @@
#include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditfiltersettings.h"
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/mooeditaction.h" #include "mooedit/mooeditaction.h"
#include "mooedit/moolang.h"
#include "mooedit/mooeditconfig.h"
#include "mooedit/mooedit.h"
#include "mooutils/mooprefs.h" #include "mooutils/mooprefs.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-debug.h" #include "mooutils/mooutils-debug.h"
#include <glib/gregex.h> #include <glib/gregex.h>
#include <string.h> #include <string.h>
#include <fnmatch.h>
MOO_DEBUG_INIT(filters, FALSE) MOO_DEBUG_INIT(filters, FALSE)
@ -133,6 +134,32 @@ _moo_edit_filter_new (const char *string)
return _moo_edit_filter_new_full (string, FALSE); 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 * MooEditFilter *
_moo_edit_filter_new_langs (const char *string) _moo_edit_filter_new_langs (const char *string)
{ {
@ -244,37 +271,21 @@ static gboolean
moo_edit_filter_check_globs (GSList *globs, moo_edit_filter_check_globs (GSList *globs,
MooEdit *doc) MooEdit *doc)
{ {
char *name = NULL; GFile *file = moo_edit_get_file (doc);
name = moo_edit_get_filename (doc);
if (name)
{
char *tmp = name;
name = g_path_get_basename (tmp);
g_free (tmp);
}
while (globs) while (globs)
{ {
if (name) if (!strcmp (globs->data, "*") ||
(file && moo_file_fnmatch (file, globs->data)))
{ {
if (fnmatch (globs->data, name, 0) == 0) g_object_unref (file);
{ return TRUE;
g_free (name);
return TRUE;
}
}
else
{
if (!strcmp (globs->data, "*"))
return TRUE;
} }
globs = globs->next; globs = globs->next;
} }
g_free (name); moo_file_free (file);
return FALSE; return FALSE;
} }
@ -282,7 +293,8 @@ static gboolean
moo_edit_filter_check_langs (GSList *langs, moo_edit_filter_check_langs (GSList *langs,
MooEdit *doc) 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) while (lang_id && langs)
{ {

View File

@ -0,0 +1,50 @@
#include "mooedithistoryitem.h"
#include <stdlib.h>
#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;
}

View File

@ -0,0 +1,17 @@
#ifndef MOO_EDIT_HISTORY_ITEM_H
#define MOO_EDIT_HISTORY_ITEM_H
#include <mooutils/mdhistorymgr.h>
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 */

View File

@ -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 */

View File

@ -13,60 +13,42 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>. * License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MOOEDIT_COMPILATION
#error "This file may not be used directly"
#endif
#ifndef MOO_EDITOR_PRIVATE_H #ifndef MOO_EDITOR_PRIVATE_H
#define MOO_EDITOR_PRIVATE_H #define MOO_EDITOR_PRIVATE_H
#include "mooedit/mooeditor.h" #include "mooedit/mooeditor-impl.h"
#include "mooutils/mdhistorymgr.h" #include "mooedit/moolangmgr.h"
#include "mooutils/moofilewatch.h"
G_BEGIN_DECLS 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 *focused_doc;
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);
void _moo_editor_set_focused_doc (MooEditor *editor, GType window_type;
MooEdit *doc); GType doc_type;
void _moo_editor_unset_focused_doc (MooEditor *editor,
MooEdit *doc);
void _moo_editor_move_doc (MooEditor *editor, MooLangMgr *lang_mgr;
MooEdit *doc, char *default_lang;
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);
guint prefs_idle;
};
G_END_DECLS G_END_DECLS

View File

@ -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);
}

View File

@ -1,5 +1,5 @@
/* /*
* mooedit-tests.h * mooeditor-tests.h
* *
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net> * Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
* *
@ -13,8 +13,8 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>. * License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MOO_EDIT_TESTS_H #ifndef MOO_EDITOR_TESTS_H
#define MOO_EDIT_TESTS_H #define MOO_EDITOR_TESTS_H
#include "mooutils/moo-test-macros.h" #include "mooutils/moo-test-macros.h"
@ -25,4 +25,4 @@ void moo_test_editor (void);
G_END_DECLS G_END_DECLS
#endif /* MOO_EDIT_TESTS_H */ #endif /* MOO_EDITOR_TESTS_H */

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
#ifndef MOO_EDITOR_H #ifndef MOO_EDITOR_H
#define MOO_EDITOR_H #define MOO_EDITOR_H
#include <mooedit/mooedittypes.h>
#include <mooedit/mooeditwindow.h> #include <mooedit/mooeditwindow.h>
#include <mooutils/moouixml.h> #include <mooutils/moouixml.h>
@ -29,7 +30,6 @@ G_BEGIN_DECLS
#define MOO_IS_EDITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_EDITOR)) #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)) #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 MooEditorPrivate MooEditorPrivate;
typedef struct MooEditorClass MooEditorClass; 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_instance (void);
MooEditor *moo_editor_create_instance (gboolean embedded); MooEditor *moo_editor_create (gboolean embedded);
/* this creates 'windowless' MooEdit instance */ /* this creates 'windowless' MooEdit instance */
MooEdit *moo_editor_create_doc (MooEditor *editor, MooEdit *moo_editor_create_doc (MooEditor *editor,
const char *filename, const char *filename,
const char *encoding, const char *encoding,
GError **error); GError **error);
MooEditWindow *moo_editor_new_window (MooEditor *editor); MooEditWindow *moo_editor_new_window (MooEditor *editor);
MooEdit *moo_editor_new_doc (MooEditor *editor, MooEdit *moo_editor_new_doc (MooEditor *editor,
MooEditWindow *window); MooEditWindow *window);
gboolean moo_editor_open (MooEditor *editor, gboolean moo_editor_open (MooEditor *editor,
MooEditWindow *window, MooEditWindow *window,
GtkWidget *parent, GtkWidget *parent,
GSList *files); /* list of MooEditFileInfo* */ MooFileEncArray *files);
MooEdit *moo_editor_open_file (MooEditor *editor, MooEdit *moo_editor_open_file (MooEditor *editor,
MooEditWindow *window, MooEditWindow *window,
GtkWidget *parent, GtkWidget *parent,
const char *filename, const char *filename,
const char *encoding); const char *encoding);
MooEdit *moo_editor_open_file_line (MooEditor *editor, MooEdit *moo_editor_open_file_line (MooEditor *editor,
const char *filename, const char *filename,
int line, int line,
MooEditWindow *window); MooEditWindow *window);
MooEdit *moo_editor_new_file (MooEditor *editor, MooEdit *moo_editor_new_file (MooEditor *editor,
MooEditWindow *window, MooEditWindow *window,
GtkWidget *parent, GtkWidget *parent,
const char *filename, const char *filename,
const char *encoding); const char *encoding);
MooEdit *moo_editor_open_uri (MooEditor *editor, MooEdit *moo_editor_open_uri (MooEditor *editor,
MooEditWindow *window, MooEditWindow *window,
GtkWidget *parent, GtkWidget *parent,
const char *uri, const char *uri,
const char *encoding); const char *encoding);
MooEdit *moo_editor_get_doc (MooEditor *editor, MooEdit *moo_editor_get_doc (MooEditor *editor,
const char *filename); const char *filename);
MooEdit *moo_editor_get_doc_for_uri (MooEditor *editor, MooEdit *moo_editor_get_doc_for_uri (MooEditor *editor,
const char *uri); const char *uri);
MooEdit *moo_editor_get_active_doc (MooEditor *editor); MooEdit *moo_editor_get_active_doc (MooEditor *editor);
MooEditWindow *moo_editor_get_active_window (MooEditor *editor); MooEditWindow *moo_editor_get_active_window (MooEditor *editor);
void moo_editor_set_active_window (MooEditor *editor, void moo_editor_set_active_window (MooEditor *editor,
MooEditWindow *window); MooEditWindow *window);
void moo_editor_set_active_doc (MooEditor *editor, void moo_editor_set_active_doc (MooEditor *editor,
MooEdit *doc); MooEdit *doc);
void moo_editor_present (MooEditor *editor, void moo_editor_present (MooEditor *editor,
guint32 stamp); guint32 stamp);
/* lists must be freed, content must not be unrefed */ MooEditWindowArray *moo_editor_get_windows (MooEditor *editor);
GSList *moo_editor_list_windows (MooEditor *editor); MooEditArray *moo_editor_get_docs (MooEditor *editor);
GSList *moo_editor_list_docs (MooEditor *editor);
gboolean moo_editor_close_window (MooEditor *editor, gboolean moo_editor_close_window (MooEditor *editor,
MooEditWindow *window, MooEditWindow *window,
gboolean ask_confirm); gboolean ask_confirm);
gboolean moo_editor_close_doc (MooEditor *editor, gboolean moo_editor_close_doc (MooEditor *editor,
MooEdit *doc, MooEdit *doc,
gboolean ask_confirm); gboolean ask_confirm);
gboolean moo_editor_close_docs (MooEditor *editor, gboolean moo_editor_close_docs (MooEditor *editor,
GSList *list, MooEditArray *docs,
gboolean ask_confirm); gboolean ask_confirm);
gboolean moo_editor_close_all (MooEditor *editor, gboolean moo_editor_close_all (MooEditor *editor,
gboolean ask_confirm, gboolean ask_confirm,
gboolean leave_one); gboolean leave_one);
MooUiXml *moo_editor_get_ui_xml (MooEditor *editor); MooUiXml *moo_editor_get_ui_xml (MooEditor *editor);
void moo_editor_set_ui_xml (MooEditor *editor, void moo_editor_set_ui_xml (MooEditor *editor,
MooUiXml *xml); MooUiXml *xml);
MooUiXml *moo_editor_get_doc_ui_xml (MooEditor *editor); MooUiXml *moo_editor_get_doc_ui_xml (MooEditor *editor);
MooEditor *moo_edit_window_get_editor (MooEditWindow *window); void moo_editor_set_window_type (MooEditor *editor,
MooEditor *moo_edit_get_editor (MooEdit *doc); GType type);
void moo_editor_set_edit_type (MooEditor *editor,
GType type);
void moo_editor_set_window_type (MooEditor *editor, gboolean moo_editor_save_copy (MooEditor *editor,
GType type); MooEdit *doc,
void moo_editor_set_edit_type (MooEditor *editor, const char *filename,
GType type); const char *encoding,
GError **error);
gboolean moo_editor_save_copy (MooEditor *editor, void moo_editor_apply_prefs (MooEditor *editor);
MooEdit *doc, void moo_editor_queue_apply_prefs (MooEditor *editor);
const char *filename,
const char *encoding,
GError **error);
void moo_editor_apply_prefs (MooEditor *editor); void _moo_editor_load_session (MooEditor *editor,
void moo_editor_queue_apply_prefs (MooEditor *editor); MooMarkupNode *xml);
void _moo_editor_save_session (MooEditor *editor,
void _moo_editor_load_session (MooEditor *editor, MooMarkupNode *xml);
MooMarkupNode *xml);
void _moo_editor_save_session (MooEditor *editor,
MooMarkupNode *xml);
enum { enum {

View File

@ -22,6 +22,7 @@
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
#include "mooedit/moolangmgr.h" #include "mooedit/moolangmgr.h"
#include "mooutils/mooencodings.h" #include "mooutils/mooencodings.h"
#include "mooutils/mooi18n.h"
#include <string.h> #include <string.h>
#ifdef __WIN32__ #ifdef __WIN32__
@ -37,6 +38,34 @@ static guint settings[MOO_EDIT_LAST_SETTING];
guint *_moo_edit_settings = settings; 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 void
_moo_edit_init_config (void) _moo_edit_init_config (void)
{ {

View File

@ -85,6 +85,9 @@ const char *moo_edit_setting (const char *setting_name);
#define MOO_EDIT_PREFS_ENCODINGS "encodings" #define MOO_EDIT_PREFS_ENCODINGS "encodings"
#define MOO_EDIT_PREFS_ENCODING_SAVE "encoding_save" #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 G_END_DECLS

View File

@ -15,7 +15,7 @@
#define MOOEDIT_COMPILATION #define MOOEDIT_COMPILATION
#include "mooedit/mooedit-impl.h" #include "mooedit/mooedit-impl.h"
#include "mooedit/mooeditor-private.h" #include "mooedit/mooeditor-impl.h"
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/moolangmgr.h" #include "mooedit/moolangmgr.h"
#include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditfiltersettings.h"

View File

@ -0,0 +1,28 @@
#ifndef MOO_EDIT_TYPES_H
#define MOO_EDIT_TYPES_H
#include <gtk/gtk.h>
#include <mooutils/mooarray.h>
#include <mooutils/moolist.h>
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 */

View File

@ -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 */

View File

@ -19,15 +19,16 @@
#define MOOEDIT_COMPILATION #define MOOEDIT_COMPILATION
#include "mooedit/mooedit-impl.h" #include "mooedit/mooedit-impl.h"
#include "mooedit/mooeditwindow-impl.h"
#include "mooedit/mooedit-accels.h" #include "mooedit/mooedit-accels.h"
#include "mooedit/mooeditor-private.h" #include "mooedit/mooeditor-impl.h"
#include "mooedit/mooeditfiltersettings.h" #include "mooedit/mooeditfiltersettings.h"
#include "mooedit/moolang.h" #include "mooedit/moolang.h"
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/mooplugin.h" #include "mooedit/mooplugin.h"
#include "mooedit/mooeditaction.h" #include "mooedit/mooeditaction.h"
#include "mooedit/mooedit-bookmarks.h" #include "mooedit/mooeditbookmark.h"
#include "mooedit/moolangmgr.h" #include "mooedit/moolangmgr.h"
#include "mooutils/moonotebook.h" #include "mooutils/moonotebook.h"
#include "mooutils/moostock.h" #include "mooutils/moostock.h"
@ -39,7 +40,6 @@
#include "mooutils/mooaction-private.h" #include "mooutils/mooaction-private.h"
#include "mooutils/moofiledialog.h" #include "mooutils/moofiledialog.h"
#include "mooutils/mooencodings.h" #include "mooutils/mooencodings.h"
#include "mooutils/mooatom.h"
#include "mooutils/moocompat.h" #include "mooutils/moocompat.h"
#include "moostatusbar-gxml.h" #include "moostatusbar-gxml.h"
#include <string.h> #include <string.h>
@ -98,16 +98,17 @@ struct MooEditWindowPrivate {
guint history_blocked : 1; guint history_blocked : 1;
}; };
MOO_DEFINE_OBJECT_ARRAY (MooEditWindowArray, moo_edit_window_array, MooEditWindow)
enum { enum {
TARGET_MOO_EDIT_TAB = 1, TARGET_MOO_EDIT_TAB = 1,
TARGET_URI_LIST = 2 TARGET_URI_LIST = 2
}; };
#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ()) MOO_DEFINE_ATOM_GLOBAL (MOO_EDIT_TAB, moo_edit_tab)
MOO_DEFINE_ATOM (MOO_EDIT_TAB, moo_edit_tab)
static GtkTargetEntry dest_targets[] = { 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} {(char*) "text/uri-list", 0, TARGET_URI_LIST}
}; };
@ -1106,15 +1107,15 @@ moo_edit_get_window (MooEdit *edit)
gboolean gboolean
moo_edit_window_close_all (MooEditWindow *window) moo_edit_window_close_all (MooEditWindow *window)
{ {
GSList *docs; MooEditArray *docs;
gboolean result; gboolean result;
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE); 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); result = moo_editor_close_docs (window->priv->editor, docs, TRUE);
g_slist_free (docs); moo_edit_array_free (docs);
return result; return result;
} }
@ -1786,19 +1787,19 @@ static void
close_others_activated (GtkWidget *item, close_others_activated (GtkWidget *item,
MooEditWindow *window) MooEditWindow *window)
{ {
GSList *list; MooEditArray *others;
MooEdit *edit = g_object_get_data (G_OBJECT (item), "moo-edit"); 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_WINDOW (window));
g_return_if_fail (MOO_IS_EDIT (edit)); g_return_if_fail (MOO_IS_EDIT (edit));
list = moo_edit_window_list_docs (window); others = moo_edit_window_get_docs (window);
list = g_slist_remove (list, edit); moo_edit_array_remove (others, edit);
if (list) if (!moo_edit_array_is_empty (others))
moo_editor_close_docs (window->priv->editor, list, TRUE); 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); 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 int
moo_edit_window_num_docs (MooEditWindow *window) 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 static gboolean
check_action_filter (G_GNUC_UNUSED GtkAction *action, check_action_filter (G_GNUC_UNUSED GtkAction *action,
G_GNUC_UNUSED MooEditWindow *window, G_GNUC_UNUSED MooEditWindow *window,
@ -3627,9 +3618,10 @@ populate_window_menu (MooEditWindow *window,
GtkWidget *no_docs_item) GtkWidget *no_docs_item)
{ {
MooEdit *active_doc; MooEdit *active_doc;
GSList *docs; MooEditArray *docs;
GList *children, *l; GList *children, *l;
int pos; int pos;
guint i;
GtkWidget *item; GtkWidget *item;
children = g_list_copy (GTK_MENU_SHELL (menu)->children); children = g_list_copy (GTK_MENU_SHELL (menu)->children);
@ -3646,24 +3638,26 @@ populate_window_menu (MooEditWindow *window,
g_list_free (children); g_list_free (children);
docs = moo_edit_window_get_docs (window);
docs = moo_edit_window_list_docs (window); if (moo_edit_array_is_empty (docs))
{
if (!docs) moo_edit_array_free (docs);
return; return;
}
item = gtk_separator_menu_item_new (); item = gtk_separator_menu_item_new ();
g_object_set_data (G_OBJECT (item), "moo-document-menu-item", GINT_TO_POINTER (TRUE)); g_object_set_data (G_OBJECT (item), "moo-document-menu-item", GINT_TO_POINTER (TRUE));
gtk_widget_show (item); gtk_widget_show (item);
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, ++pos); 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); active_doc = ACTIVE_DOC (window);
while (docs) for (i = 0; i < docs->n_elms; ++i)
{ {
int idx; int idx;
MooEdit *doc = docs->data; MooEdit *doc = docs->elms[i];
idx = get_page_num (window, doc); idx = get_page_num (window, doc);
@ -3684,9 +3678,9 @@ populate_window_menu (MooEditWindow *window,
gtk_action_get_accel_path (action)); gtk_action_get_accel_path (action));
g_free (action_name); g_free (action_name);
} }
docs = g_slist_delete_link (docs, docs);
} }
moo_edit_array_free (docs);
} }
static void static void

View File

@ -16,10 +16,12 @@
#ifndef MOO_EDIT_WINDOW_H #ifndef MOO_EDIT_WINDOW_H
#define MOO_EDIT_WINDOW_H #define MOO_EDIT_WINDOW_H
#include <mooedit/mooedittypes.h>
#include <mooedit/mooedit.h> #include <mooedit/mooedit.h>
#include <mooedit/mooedit-enums.h> #include <mooedit/mooedit-enums.h>
#include <mooutils/moowindow.h> #include <mooutils/moowindow.h>
#include <mooutils/moobigpaned.h> #include <mooutils/moobigpaned.h>
#include <mooutils/mooatom.h>
G_BEGIN_DECLS 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_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)) #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 MooEditWindowPrivate MooEditWindowPrivate;
typedef struct MooEditWindowClass MooEditWindowClass; typedef struct MooEditWindowClass MooEditWindowClass;
@ -54,57 +55,61 @@ struct MooEditWindowClass
void (*close_doc_after) (MooEditWindow *window); 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, typedef gboolean (*MooActionCheckFunc) (GtkAction *action,
MooEditWindow *window, MooEditWindow *window,
MooEdit *doc, MooEdit *doc,
gpointer data); gpointer data);
void moo_edit_window_set_action_check (const char *action_id, void moo_edit_window_set_action_check (const char *action_id,
MooActionCheckType type, MooActionCheckType type,
MooActionCheckFunc func, MooActionCheckFunc func,
gpointer data, gpointer data,
GDestroyNotify notify); GDestroyNotify notify);
void moo_edit_window_set_action_filter (const char *action_id, void moo_edit_window_set_action_filter (const char *action_id,
MooActionCheckType type, MooActionCheckType type,
const char *filter); const char *filter);
MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window); MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window);
void moo_edit_window_set_active_doc (MooEditWindow *window, void moo_edit_window_set_active_doc (MooEditWindow *window,
MooEdit *edit); MooEdit *edit);
MooEditWindow *moo_edit_get_window (MooEdit *edit);
MooEdit *moo_edit_window_get_nth_doc (MooEditWindow *window, MooEditor *moo_edit_window_get_editor (MooEditWindow *window);
guint n);
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 */ /* list must be freed, elements must not be unref'ed */
GSList *moo_edit_window_list_docs (MooEditWindow *window); GSList *moo_edit_window_list_docs (MooEditWindow *window);
int moo_edit_window_num_docs (MooEditWindow *window); int moo_edit_window_num_docs (MooEditWindow *window);
void moo_edit_window_set_title_prefix (MooEditWindow *window, void moo_edit_window_set_title_prefix (MooEditWindow *window,
const char *prefix); const char *prefix);
/* sinks widget */ /* sinks widget */
MooPane *moo_edit_window_add_pane (MooEditWindow *window, MooPane *moo_edit_window_add_pane (MooEditWindow *window,
const char *user_id, const char *user_id,
GtkWidget *widget, GtkWidget *widget,
MooPaneLabel *label, MooPaneLabel *label,
MooPanePosition position); MooPanePosition position);
gboolean moo_edit_window_remove_pane (MooEditWindow *window, gboolean moo_edit_window_remove_pane (MooEditWindow *window,
const char *user_id); const char *user_id);
GtkWidget *moo_edit_window_get_pane (MooEditWindow *window, GtkWidget *moo_edit_window_get_pane (MooEditWindow *window,
const char *user_id); const char *user_id);
typedef void (*MooAbortJobFunc) (gpointer job); typedef void (*MooAbortJobFunc) (gpointer job);
void moo_edit_window_add_stop_client (MooEditWindow *window, void moo_edit_window_add_stop_client (MooEditWindow *window,
gpointer client); gpointer client);
void moo_edit_window_remove_stop_client (MooEditWindow *window, void moo_edit_window_remove_stop_client (MooEditWindow *window,
gpointer client); gpointer client);
void moo_edit_window_abort_jobs (MooEditWindow *window); void moo_edit_window_abort_jobs (MooEditWindow *window);
G_END_DECLS G_END_DECLS

58
moo/mooedit/moofileenc.c Normal file
View File

@ -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;
}

25
moo/mooedit/moofileenc.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef MOO_FILE_INFO_H
#define MOO_FILE_INFO_H
#include <gio/gio.h>
#include <mooedit/mooedittypes.h>
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 */

View File

@ -21,46 +21,7 @@
/* XXX this doesn't take unicode control chars into account */ /* XXX this doesn't take unicode control chars into account */
static GObject *moo_indenter_constructor (GType type, static void sync_settings (MooIndenter *indenter);
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
};
enum { enum {
SETTING_USE_TABS, SETTING_USE_TABS,
@ -75,18 +36,8 @@ G_DEFINE_TYPE (MooIndenter, moo_indenter, G_TYPE_OBJECT)
static void 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 ( settings[SETTING_USE_TABS] = moo_edit_config_install_setting (
g_param_spec_boolean ("indent-use-tabs", "indent-use-tabs", "indent-use-tabs", g_param_spec_boolean ("indent-use-tabs", "indent-use-tabs", "indent-use-tabs",
TRUE, (GParamFlags) G_PARAM_READWRITE)); TRUE, (GParamFlags) G_PARAM_READWRITE));
@ -95,199 +46,29 @@ moo_indenter_class_init (MooIndenterClass *klass)
settings[SETTING_INDENT_WIDTH] = moo_edit_config_install_setting ( settings[SETTING_INDENT_WIDTH] = moo_edit_config_install_setting (
g_param_spec_uint ("indent-width", "indent-width", "indent-width", g_param_spec_uint ("indent-width", "indent-width", "indent-width",
1, G_MAXUINT, 8, (GParamFlags) G_PARAM_READWRITE)); 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 static void
moo_indenter_init (G_GNUC_UNUSED MooIndenter *indent) moo_indenter_init (MooIndenter *indent)
{ {
} indent->tab_width = 8;
indent->use_tabs = TRUE;
indent->indent = 8;
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);
} }
MooIndenter * MooIndenter *
moo_indenter_new (gpointer doc) moo_indenter_new (MooEdit *doc)
{ {
g_return_val_if_fail (!doc || MOO_IS_EDIT (doc), NULL); MooIndenter *indent;
return MOO_INDENTER (g_object_new (MOO_TYPE_INDENTER, "doc", doc, (const char*) NULL));
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 /* Default implementation
*/ */
char* char *
moo_indenter_make_space (MooIndenter *indenter, moo_indenter_make_space (MooIndenter *indenter,
guint len, guint len,
guint start) guint start)
@ -306,6 +87,8 @@ moo_indenter_make_space (MooIndenter *indenter,
g_return_val_if_fail (MOO_IS_INDENTER (indenter), NULL); g_return_val_if_fail (MOO_IS_INDENTER (indenter), NULL);
sync_settings (indenter);
if (!len) if (!len)
return NULL; return NULL;
@ -389,21 +172,27 @@ compute_line_offset (GtkTextIter *dest,
} }
static void void
character_default (MooIndenter *indenter, moo_indenter_character (MooIndenter *indenter,
const char *inserted_char, const char *inserted_char,
GtkTextIter *where) GtkTextIter *where)
{ {
char *indent_string = NULL; char *indent_string = NULL;
GtkTextBuffer *buffer = gtk_text_iter_get_buffer (where); GtkTextBuffer *buffer = gtk_text_iter_get_buffer (where);
guint offset; guint offset;
GtkTextIter iter; GtkTextIter iter;
g_return_if_fail (MOO_IS_INDENTER (indenter));
g_return_if_fail (inserted_char != NULL); g_return_if_fail (inserted_char != NULL);
if (*inserted_char != '\n') if (*inserted_char != '\n')
return; return;
buffer = gtk_text_iter_get_buffer (where);
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
sync_settings (indenter);
iter = *where; iter = *where;
gtk_text_iter_backward_line (&iter); gtk_text_iter_backward_line (&iter);
compute_line_offset (&iter, indenter->tab_width, &offset); compute_line_offset (&iter, indenter->tab_width, &offset);
@ -564,6 +353,8 @@ moo_indenter_tab (MooIndenter *indenter,
guint indent = indenter->indent; guint indent = indenter->indent;
char *text = NULL; char *text = NULL;
sync_settings (indenter);
gtk_text_buffer_get_iter_at_mark (buffer, &insert, gtk_text_buffer_get_insert (buffer)); gtk_text_buffer_get_iter_at_mark (buffer, &insert, gtk_text_buffer_get_insert (buffer));
start = insert; start = insert;
@ -671,6 +462,8 @@ moo_indenter_shift_lines (MooIndenter *indenter,
guint i; guint i;
GtkTextIter iter; GtkTextIter iter;
sync_settings (indenter);
for (i = first_line; i <= last_line; ++i) for (i = first_line; i <= last_line; ++i)
{ {
gtk_text_buffer_get_iter_at_line (buffer, &iter, i); gtk_text_buffer_get_iter_at_line (buffer, &iter, i);
@ -683,27 +476,10 @@ moo_indenter_shift_lines (MooIndenter *indenter,
static void static void
config_changed_default (MooIndenter *indenter, sync_settings (MooIndenter *indenter)
guint var_id,
GParamSpec *pspec)
{ {
MooEdit *doc = indenter->doc; g_return_if_fail (MOO_IS_EDIT (indenter->doc));
indenter->use_tabs = moo_edit_config_get_bool (indenter->doc->config, "indent-use-tabs");
g_return_if_fail (MOO_IS_EDIT (doc)); 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");
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);
}
} }

View File

@ -16,7 +16,7 @@
#ifndef MOO_INDENTER_H #ifndef MOO_INDENTER_H
#define MOO_INDENTER_H #define MOO_INDENTER_H
#include <gtk/gtktextbuffer.h> #include <mooedit/mooedittypes.h>
G_BEGIN_DECLS 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)) #define MOO_INDENTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_INDENTER, MooIndenterClass))
typedef struct _MooIndenter MooIndenter; typedef struct MooIndenter MooIndenter;
typedef struct _MooIndenterClass MooIndenterClass; typedef struct MooIndenterClass MooIndenterClass;
struct _MooIndenter struct MooIndenter
{ {
GObject parent; GObject parent;
MooEdit *doc;
gpointer doc; /* MooEdit* */
gboolean use_tabs; gboolean use_tabs;
guint tab_width; guint tab_width;
guint indent; guint indent;
}; };
struct _MooIndenterClass struct MooIndenterClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
@ -57,7 +56,7 @@ struct _MooIndenterClass
GType moo_indenter_get_type (void) G_GNUC_CONST; 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, char *moo_indenter_make_space (MooIndenter *indenter,
guint len, guint len,

View File

@ -38,7 +38,6 @@
#define KEY_DESCRIPTION "description" #define KEY_DESCRIPTION "description"
#define KEY_AUTHOR "author" #define KEY_AUTHOR "author"
#define KEY_VERSION "version" #define KEY_VERSION "version"
#define KEY_LANGS "langs"
#define KEY_ENABLED "enabled" #define KEY_ENABLED "enabled"
#define KEY_VISIBLE "visible" #define KEY_VISIBLE "visible"
@ -169,7 +168,6 @@ parse_plugin_info (GKeyFile *key_file,
char *description; char *description;
char *author; char *author;
char *version; char *version;
char *langs;
gboolean enabled = TRUE; gboolean enabled = TRUE;
gboolean visible = 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); 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); 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); 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)) 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); 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, info = moo_plugin_info_new (name ? name : plugin_id,
description ? description : "", description ? description : "",
author ? author : "", author ? author : "",
version ? version : "", version ? version : "");
langs);
params = moo_plugin_params_new (enabled, visible); params = moo_plugin_params_new (enabled, visible);
*info_p = info; *info_p = info;
@ -198,7 +194,6 @@ parse_plugin_info (GKeyFile *key_file,
g_free (description); g_free (description);
g_free (author); g_free (author);
g_free (version); g_free (version);
g_free (langs);
return TRUE; return TRUE;
} }

View File

@ -29,12 +29,11 @@ MOO_MODULE_INIT_FUNC (void)
#define MOO_PLUGIN_DEFINE_INFO(plugin_name__,name__, \ #define MOO_PLUGIN_DEFINE_INFO(plugin_name__,name__, \
description__,author__,version__, \ description__,author__,version__) \
langs__) \
\ \
static const MooPluginInfo plugin_name__##_plugin_info = \ static const MooPluginInfo plugin_name__##_plugin_info = \
{(char*) name__, (char*) description__, \ {(char*) name__, (char*) description__, \
(char*) author__, (char*) version__, (char*) langs__}; (char*) author__, (char*) version__};
#define MOO_PLUGIN_DEFINE_FULL(Name__,name__, \ #define MOO_PLUGIN_DEFINE_FULL(Name__,name__, \

View File

@ -191,9 +191,6 @@ moo_plugin_finalize (GObject *object)
{ {
MooPlugin *plugin = MOO_PLUGIN (object); MooPlugin *plugin = MOO_PLUGIN (object);
if (plugin->langs)
g_hash_table_destroy (plugin->langs);
g_free (plugin->id); g_free (plugin->id);
moo_plugin_info_free (plugin->info); moo_plugin_info_free (plugin->info);
moo_plugin_params_free (plugin->params); moo_plugin_params_free (plugin->params);
@ -219,7 +216,8 @@ moo_plugin_register (const char *id,
MooPluginClass *klass; MooPluginClass *klass;
MooPlugin *plugin; MooPlugin *plugin;
char *prefs_key; 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 (id != NULL && id[0] != 0, FALSE);
g_return_val_if_fail (g_utf8_validate (id, -1, NULL), 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) : plugin->params = params ? moo_plugin_params_copy ((MooPluginParams*) params) :
moo_plugin_params_new (TRUE, TRUE); 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))) if (moo_plugin_lookup (moo_plugin_id (plugin)))
{ {
_moo_message ("%s: plugin with id %s already registered", _moo_message ("%s: plugin with id %s already registered",
@ -309,10 +270,10 @@ moo_plugin_register (const char *id,
plugin_store_add (plugin); plugin_store_add (plugin);
windows = moo_editor_list_windows (plugin_store->editor); windows = moo_editor_get_windows (plugin_store->editor);
for (l = windows; l != NULL; l = l->next) for (i = 0; i < windows->n_elms; ++i)
plugin_attach_win (plugin, l->data); plugin_attach_win (plugin, windows->elms[i]);
g_slist_free (windows); moo_edit_window_array_free (windows);
return TRUE; return TRUE;
} }
@ -369,7 +330,8 @@ plugin_attach_win (MooPlugin *plugin,
MooWinPluginClass *wklass; MooWinPluginClass *wklass;
MooWinPlugin *win_plugin; MooWinPlugin *win_plugin;
GType wtype; GType wtype;
GSList *l, *docs; MooEditArray *docs;
guint i;
g_return_if_fail (MOO_IS_EDIT_WINDOW (window)); g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
g_return_if_fail (MOO_IS_PLUGIN (plugin)); g_return_if_fail (MOO_IS_PLUGIN (plugin));
@ -399,10 +361,10 @@ plugin_attach_win (MooPlugin *plugin,
g_object_unref (win_plugin); g_object_unref (win_plugin);
} }
docs = moo_edit_window_list_docs (window); docs = moo_edit_window_get_docs (window);
for (l = docs; l != NULL; l = l->next) for (i = 0; i < docs->n_elms; ++i)
plugin_attach_doc (plugin, window, l->data); plugin_attach_doc (plugin, window, docs->elms[i]);
g_slist_free (docs); moo_edit_array_free (docs);
} }
@ -413,7 +375,8 @@ plugin_detach_win (MooPlugin *plugin,
MooPluginClass *klass; MooPluginClass *klass;
MooWinPluginClass *wklass; MooWinPluginClass *wklass;
MooWinPlugin *win_plugin; 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_EDIT_WINDOW (window));
g_return_if_fail (MOO_IS_PLUGIN (plugin)); g_return_if_fail (MOO_IS_PLUGIN (plugin));
@ -421,10 +384,10 @@ plugin_detach_win (MooPlugin *plugin,
if (!moo_plugin_enabled (plugin)) if (!moo_plugin_enabled (plugin))
return; return;
docs = moo_edit_window_list_docs (window); docs = moo_edit_window_get_docs (window);
for (l = docs; l != NULL; l = l->next) for (i = 0; i < docs->n_elms; ++i)
plugin_detach_doc (plugin, window, l->data); plugin_detach_doc (plugin, window, docs->elms[i]);
g_slist_free (docs); moo_edit_array_free (docs);
win_plugin = window_get_plugin (window, plugin); win_plugin = window_get_plugin (window, plugin);
@ -463,19 +426,6 @@ plugin_attach_doc (MooPlugin *plugin,
if (!moo_plugin_enabled (plugin)) if (!moo_plugin_enabled (plugin))
return; 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); plugin->docs = g_slist_prepend (plugin->docs, doc);
klass = MOO_PLUGIN_GET_CLASS (plugin); klass = MOO_PLUGIN_GET_CLASS (plugin);
@ -738,7 +688,8 @@ moo_plugin_enabled (MooPlugin *plugin)
static gboolean static gboolean
plugin_enable (MooPlugin *plugin) plugin_enable (MooPlugin *plugin)
{ {
GSList *l, *windows; MooEditWindowArray *windows;
guint i;
g_return_val_if_fail (MOO_IS_PLUGIN (plugin), FALSE); g_return_val_if_fail (MOO_IS_PLUGIN (plugin), FALSE);
@ -755,10 +706,10 @@ plugin_enable (MooPlugin *plugin)
return FALSE; return FALSE;
} }
windows = moo_editor_list_windows (plugin_store->editor); windows = moo_editor_get_windows (plugin_store->editor);
for (l = windows; l != NULL; l = l->next) for (i = 0; i < windows->n_elms; ++i)
plugin_attach_win (plugin, l->data); plugin_attach_win (plugin, windows->elms[i]);
g_slist_free (windows); moo_edit_window_array_free (windows);
return TRUE; return TRUE;
} }
@ -767,7 +718,8 @@ plugin_enable (MooPlugin *plugin)
static void static void
plugin_disable (MooPlugin *plugin) plugin_disable (MooPlugin *plugin)
{ {
GSList *l, *windows; MooEditWindowArray *windows;
guint i;
g_return_if_fail (MOO_IS_PLUGIN (plugin)); g_return_if_fail (MOO_IS_PLUGIN (plugin));
@ -776,10 +728,10 @@ plugin_disable (MooPlugin *plugin)
g_assert (plugin->initialized); g_assert (plugin->initialized);
windows = moo_editor_list_windows (plugin_store->editor); windows = moo_editor_get_windows (plugin_store->editor);
for (l = windows; l != NULL; l = l->next) for (i = 0; i < windows->n_elms; ++i)
plugin_detach_win (plugin, l->data); plugin_detach_win (plugin, windows->elms[i]);
g_slist_free (windows); moo_edit_window_array_free (windows);
plugin_deinit (plugin); plugin_deinit (plugin);
plugin->params->enabled = FALSE; 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 void
_moo_doc_attach_plugins (MooEditWindow *window, _moo_doc_attach_plugins (MooEditWindow *window,
MooEdit *doc) MooEdit *doc)
@ -1038,10 +961,6 @@ _moo_doc_attach_plugins (MooEditWindow *window,
plugin_store_init (); 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) for (l = plugin_store->list; l != NULL; l = l->next)
plugin_attach_doc (l->data, window, doc); plugin_attach_doc (l->data, window, doc);
} }
@ -1058,10 +977,6 @@ _moo_doc_detach_plugins (MooEditWindow *window,
plugin_store_init (); 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) for (l = plugin_store->list; l != NULL; l = l->next)
plugin_detach_doc (l->data, window, doc); plugin_detach_doc (l->data, window, doc);
} }
@ -1113,8 +1028,7 @@ MooPluginInfo *
moo_plugin_info_new (const char *name, moo_plugin_info_new (const char *name,
const char *description, const char *description,
const char *author, const char *author,
const char *version, const char *version)
const char *langs)
{ {
MooPluginInfo *info; MooPluginInfo *info;
@ -1125,7 +1039,6 @@ moo_plugin_info_new (const char *name,
info->description = description ? g_strdup (description) : g_strdup (""); info->description = description ? g_strdup (description) : g_strdup ("");
info->author = author ? g_strdup (author) : g_strdup (""); info->author = author ? g_strdup (author) : g_strdup ("");
info->version = version ? g_strdup (version) : g_strdup (""); info->version = version ? g_strdup (version) : g_strdup ("");
info->langs = g_strdup (langs);
return info; return info;
} }
@ -1136,7 +1049,7 @@ moo_plugin_info_copy (MooPluginInfo *info)
{ {
g_return_val_if_fail (info != NULL, NULL); g_return_val_if_fail (info != NULL, NULL);
return moo_plugin_info_new (info->name, info->description, 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->description);
g_free (info->author); g_free (info->author);
g_free (info->version); g_free (info->version);
g_free (info->langs);
g_free (info); g_free (info);
} }
} }

View File

@ -110,7 +110,6 @@ struct _MooPluginInfo
char *description; char *description;
char *author; char *author;
char *version; char *version;
char *langs;
}; };
struct _MooPlugin struct _MooPlugin
@ -123,7 +122,6 @@ struct _MooPlugin
GQuark id_quark; GQuark id_quark;
MooPluginInfo *info; MooPluginInfo *info;
MooPluginParams *params; MooPluginParams *params;
GHashTable *langs;
GSList *docs; GSList *docs;
GType win_plugin_type; GType win_plugin_type;
GType doc_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, MooPluginInfo *moo_plugin_info_new (const char *name,
const char *description, const char *description,
const char *author, const char *author,
const char *version, const char *version);
const char *langs);
MooPluginInfo *moo_plugin_info_copy (MooPluginInfo *info); MooPluginInfo *moo_plugin_info_copy (MooPluginInfo *info);
void moo_plugin_info_free (MooPluginInfo *info); void moo_plugin_info_free (MooPluginInfo *info);
MooPluginParams *moo_plugin_params_new (gboolean enabled, MooPluginParams *moo_plugin_params_new (gboolean enabled,

View File

@ -20,9 +20,10 @@
#include "mooedit/mootextbuffer.h" #include "mooedit/mootextbuffer.h"
#include "mooedit/mootextfind.h" #include "mooedit/mootextfind.h"
#include "mooedit/mootext-private.h" #include "mooedit/mootext-private.h"
#include "mooedit/mooedit-enums.h"
#include "mooedit/mooeditprefs.h" #include "mooedit/mooeditprefs.h"
#include "mooedit/moolangmgr.h" #include "mooedit/moolangmgr.h"
#include "mooedit/mooeditwindow.h"
#include "mooedit/mooedit.h"
#include "marshals.h" #include "marshals.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/mooundo.h" #include "mooutils/mooundo.h"
@ -32,6 +33,7 @@
#include "mooutils/mooatom.h" #include "mooutils/mooatom.h"
#include "mooutils/mootype-macros.h" #include "mooutils/mootype-macros.h"
#include "mooutils/moocompat.h" #include "mooutils/moocompat.h"
#include "mooutils/mooutils-gobject.h"
#include "mooquicksearch-gxml.h" #include "mooquicksearch-gxml.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gregex.h> #include <glib/gregex.h>
@ -2605,14 +2607,10 @@ void
moo_text_view_set_lang_by_id (MooTextView *view, moo_text_view_set_lang_by_id (MooTextView *view,
const char *lang_id) const char *lang_id)
{ {
MooEditor *editor;
MooLangMgr *mgr; MooLangMgr *mgr;
MooLang *lang; MooLang *lang;
MooTextStyleScheme *scheme; MooTextStyleScheme *scheme;
editor = moo_editor_instance ();
g_return_if_fail (editor != NULL);
mgr = moo_lang_mgr_default (); mgr = moo_lang_mgr_default ();
lang = moo_lang_mgr_get_lang (mgr, lang_id); lang = moo_lang_mgr_get_lang (mgr, lang_id);
scheme = moo_lang_mgr_get_active_scheme (mgr); scheme = moo_lang_mgr_get_active_scheme (mgr);
@ -4116,12 +4114,7 @@ static void
quick_search_message (MooTextView *view, quick_search_message (MooTextView *view,
const char *msg) const char *msg)
{ {
GtkWidget *window; moo_text_view_message (view, msg);
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
if (MOO_IS_EDIT_WINDOW (window))
moo_window_message (MOO_WINDOW (window), msg);
} }

View File

@ -1906,15 +1906,34 @@ static void size_data_func (G_GNUC_UNUSED GObject *column_or_iconvie
gboolean gboolean
moo_file_view_chdir (MooFileView *fileview, moo_file_view_chdir (MooFileView *fileview,
const char *dir, GFile *file,
GError **error) 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; 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; return result;
} }
@ -1949,7 +1968,7 @@ moo_file_view_go_up (MooFileView *fileview)
const char *path = _moo_folder_get_path (parent); const char *path = _moo_folder_get_path (parent);
char *name = g_path_get_basename (_moo_folder_get_path (fileview->priv->current_dir)); 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); _moo_file_view_select_name (fileview, name);
g_free (name); g_free (name);
@ -1967,7 +1986,7 @@ moo_file_view_go_home (MooFileView *fileview)
if (fileview->priv->entry_state) if (fileview->priv->entry_state)
stop_path_entry (fileview, TRUE); 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); g_warning ("%s: could not go home", G_STRLOC);
@ -2005,7 +2024,7 @@ file_list_row_activated (MooFileView *fileview,
{ {
GError *error = NULL; 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_warning ("%s: could not go into '%s'",
G_STRLOC, _moo_file_name (file)); G_STRLOC, _moo_file_name (file));
@ -2216,7 +2235,7 @@ moo_file_view_go (MooFileView *fileview,
{ {
fileview->priv->history->block++; 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_warning ("%s: could not go into '%s'",
G_STRLOC, dir); G_STRLOC, dir);
@ -2262,7 +2281,7 @@ moo_file_view_set_property (GObject *object,
switch (prop_id) switch (prop_id)
{ {
case PROP_CURRENT_DIRECTORY: 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; break;
case PROP_HOME_DIRECTORY: case PROP_HOME_DIRECTORY:
@ -3746,7 +3765,7 @@ bookmark_activate (G_GNUC_UNUSED MooBookmarkMgr *mgr,
if (activated != fileview) if (activated != fileview)
return; 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) MooBookmark *bookmark)
{ {
g_return_if_fail (bookmark != NULL && bookmark->path != NULL); 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 (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_warning ("%s: could not chdir to %s",
G_STRLOC, path); G_STRLOC, path);
@ -4593,7 +4612,7 @@ file_view_activate_filename (MooFileView *fileview,
g_return_if_reached (); 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_warning ("%s: could not chdir to %s",
G_STRLOC, dirname); G_STRLOC, dirname);
@ -5127,7 +5146,7 @@ drop_open_timeout_func2 (MooFileView *fileview)
g_warning ("%s: oops", G_STRLOC); 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); _moo_file_view_select_name (fileview, NULL);
if (file) if (file)

View File

@ -17,6 +17,7 @@
#define MOO_FILE_VIEW_H #define MOO_FILE_VIEW_H
#include <mooutils/moouixml.h> #include <mooutils/moouixml.h>
#include <mooutils/mooutils-file.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -34,6 +35,9 @@ typedef struct MooFileViewClass MooFileViewClass;
GType moo_file_view_get_type (void) G_GNUC_CONST; GType moo_file_view_get_type (void) G_GNUC_CONST;
gboolean moo_file_view_chdir (MooFileView *fileview, gboolean moo_file_view_chdir (MooFileView *fileview,
GFile *dir,
GError **error);
gboolean moo_file_view_chdir_path (MooFileView *fileview,
const char *dir, const char *dir,
GError **error); GError **error);

View File

@ -1,6 +1,7 @@
#include "mooscript-classes.h" #include "mooscript-classes.h"
#include "mooscript-classes-util.h" #include "mooscript-classes-util.h"
#include "mooapp/mooapp.h" #include "mooapp/mooapp.h"
#include "mooedit/moofileenc.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/moodialogs.h" #include "mooutils/moodialogs.h"
#include <string.h> #include <string.h>
@ -89,6 +90,18 @@ static VariantArray wrap_gslist(GSList *list)
return array; return array;
} }
template<typename GArrayClass, typename GClass, typename Class>
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) static Index get_index(const Variant &val)
{ {
switch (val.vt()) switch (val.vt())
@ -534,42 +547,24 @@ void Editor::set_active_window(DocumentWindow &window)
moo_editor_set_active_window(moo_editor_instance(), window.gobj()); 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() /// @item Editor.documents()
/// returns list of all open documents /// returns list of all open documents
VariantArray Editor::documents() VariantArray Editor::documents()
{ {
GSList *docs = moo_editor_list_docs(moo_editor_instance()); MooEditArray *docs = moo_editor_get_docs(moo_editor_instance());
return wrap_gslist<MooEdit, Document>(docs); VariantArray ret = wrap_array<MooEditArray, MooEdit, Document>(docs);
} moo_edit_array_free(docs);
return ret;
/// @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<MooEdit, DocumentView>(docs);
} }
/// @item Editor.windows() /// @item Editor.windows()
/// returns list of all document windows /// returns list of all document windows
VariantArray Editor::windows() VariantArray Editor::windows()
{ {
GSList *windows = moo_editor_list_windows(moo_editor_instance()); MooEditWindowArray *windows = moo_editor_get_windows(moo_editor_instance());
return wrap_gslist<MooEditWindow, DocumentWindow>(windows); VariantArray ret = wrap_array<MooEditWindowArray, MooEditWindow, DocumentWindow>(windows);
moo_edit_window_array_free(windows);
return ret;
} }
/// @item Editor.new_document(window=null) /// @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)); 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<String> filenames = get_string_list(val); moo::Vector<String> filenames = get_string_list(val);
if (filenames.empty()) if (filenames.empty())
return NULL; return NULL;
GSList *files = NULL; MooFileEncArray *files = moo_file_enc_array_new();
for (int i = 0, c = filenames.size(); i < c; ++i) for (int i = 0, c = filenames.size(); i < c; ++i)
{ {
MooEditFileInfo *fi = uri ? MooFileEnc *fenc = uri ?
moo_edit_file_info_new_uri(filenames[i], NULL) : moo_file_enc_new_for_uri(filenames[i], NULL) :
moo_edit_file_info_new_path(filenames[i], NULL); moo_file_enc_new_for_path(filenames[i], NULL);
if (!fi) if (!fenc)
goto error; goto error;
files = g_slist_prepend(files, fi); moo_file_enc_array_take(files, fenc);
} }
return g_slist_reverse(files); return files;
error: error:
g_slist_foreach(files, (GFunc) moo_edit_file_info_free, NULL); moo_file_enc_array_free(files);
g_slist_free(files);
Error::raise("error"); Error::raise("error");
} }
static void open_files_or_uris(const VariantArray &file_array, DocumentWindow *window, bool uri) 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); moo_editor_open(moo_editor_instance(), window ? window->gobj() : NULL, NULL, files);
g_slist_foreach(files, (GFunc) moo_edit_file_info_free, NULL); moo_file_enc_array_free(files);
g_slist_free(files);
} }
/// @item Editor.open_files(files, window=null) /// @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) for (int i = 0, c = arr.size(); i < c; ++i)
pvec.append(get_object_arg<Document>(arr[i], "doc").gobj()); pvec.append(get_object_arg<Document>(arr[i], "doc").gobj());
GSList *docs = NULL; MooEditArray *docs = moo_edit_array_new ();
for (int i = 0, c = pvec.size(); i < c; ++i) for (int i = 0, c = pvec.size(); i < c; ++i)
docs = g_slist_prepend (docs, pvec[i]); moo_edit_array_append (docs, pvec[i]);
docs = g_slist_reverse (docs);
bool retval = moo_editor_close_docs (moo_editor_instance(), docs, TRUE); bool retval = moo_editor_close_docs (moo_editor_instance(), docs, TRUE);
g_slist_free (docs); moo_edit_array_free (docs);
return retval; return retval;
} }
@ -788,50 +780,28 @@ Editor *DocumentWindow::editor()
return &Editor::get_instance(); 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() /// @item DocumentWindow.active_document()
/// returns current active document in this window, that is the document /// returns current active document in this window.
/// whose view is the active one.
Document *DocumentWindow::active_document() Document *DocumentWindow::active_document()
{ {
return Document::wrap(moo_edit_window_get_active_doc(gobj())); return Document::wrap(moo_edit_window_get_active_doc(gobj()));
} }
/// @item DocumentWindow.set_active_document(doc) /// @item DocumentWindow.set_active_document(doc)
/// makes active a view of document @param{doc}. It picks arbitrary view /// makes active document @param{doc}.
/// of @param{doc} if there are more than one in this window.
void DocumentWindow::set_active_document(Document &doc) void DocumentWindow::set_active_document(Document &doc)
{ {
moo_edit_window_set_active_doc(gobj(), doc.gobj()); 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<MooEdit, DocumentView>(docs);
}
/// @item DocumentWindow.documents() /// @item DocumentWindow.documents()
/// returns list of all documents in this window. /// returns list of all documents in this window.
VariantArray DocumentWindow::documents() VariantArray DocumentWindow::documents()
{ {
GSList *docs = moo_edit_window_list_docs(gobj()); MooEditArray *docs = moo_edit_window_get_docs(gobj());
return wrap_gslist<MooEdit, Document>(docs); VariantArray ret = wrap_array<MooEditArray, MooEdit, Document>(docs);
moo_edit_array_free(docs);
return ret;
} }
/// @item DocumentWindow.is_active() /// @item DocumentWindow.is_active()
@ -852,84 +822,6 @@ void DocumentWindow::set_active()
/// @end table /// @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 // Document
@ -948,25 +840,6 @@ static GtkTextBuffer *buffer(Document *doc)
return gtk_text_view_get_buffer(GTK_TEXT_VIEW(doc->gobj())); 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() /// @item Document.filename()
/// returns full file path of the document or @null{} if the document /// 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 /// has not been saved yet or if it can't be represented with a local

View File

@ -15,13 +15,8 @@
<method name='set_active_window'> <method name='set_active_window'>
<param name='window' type='DocumentWindow'/> <param name='window' type='DocumentWindow'/>
</method> </method>
<method name='active_view' retval='DocumentView'/>
<method name='set_active_view'>
<param name='view' type='DocumentView'/>
</method>
<method name='documents' retval='list'/> <method name='documents' retval='list'/>
<method name='views' retval='list'/>
<method name='windows' retval='list'/> <method name='windows' retval='list'/>
<method name='get_document_by_path' retval='Document'> <method name='get_document_by_path' retval='Document'>
@ -84,31 +79,14 @@
<class name='DocumentWindow' gobject='MooEditWindow'> <class name='DocumentWindow' gobject='MooEditWindow'>
<method name='editor' retval='Editor'/> <method name='editor' retval='Editor'/>
<method name='active_view' retval='DocumentView'/>
<method name='set_active_view' param-name='view' param-type='DocumentView'/>
<method name='active_document' retval='Document'/> <method name='active_document' retval='Document'/>
<method name='set_active_document' param-name='doc' param-type='Document'/> <method name='set_active_document' param-name='doc' param-type='Document'/>
<method name='views' retval='list'/>
<method name='documents' retval='list'/> <method name='documents' retval='list'/>
<method name='is_active' retval='bool'/> <method name='is_active' retval='bool'/>
<method name='set_active'/> <method name='set_active'/>
</class> </class>
<class name='DocumentView' gobject='MooEdit'>
<method name='document' retval='Document'/>
<method name='window' retval='DocumentWindow'/>
<method name='line_wrap_mode' retval='bool'/>
<method name='set_line_wrap_mode' param-name='enabled' param-type='bool'/>
<method name='overwrite_mode' retval='bool'/>
<method name='set_overwrite_mode' param-name='enabled' param-type='bool'/>
<method name='show_line_numbers' retval='bool'/>
<method name='set_show_line_numbers' param-name='show' param-type='bool'/>
</class>
<class name='Document' gobject='MooEdit'> <class name='Document' gobject='MooEdit'>
<method name='views' retval='list'/>
<method name='active_view' retval='DocumentView'/>
<method name='filename' retval='string'/> <method name='filename' retval='string'/>
<method name='uri' retval='string'/> <method name='uri' retval='string'/>
<method name='basename' retval='string'/> <method name='basename' retval='string'/>

View File

@ -50,6 +50,9 @@ moo_sources += \
mooutils/moofileicon.h \ mooutils/moofileicon.h \
mooutils/moofilewatch.c \ mooutils/moofilewatch.c \
mooutils/moofilewatch.h \ mooutils/moofilewatch.h \
mooutils/moofilewriter.c \
mooutils/moofilewriter.h \
mooutils/moofilewriter-private.h\
mooutils/moofiltermgr.c \ mooutils/moofiltermgr.c \
mooutils/moofiltermgr.h \ mooutils/moofiltermgr.h \
mooutils/moofontsel.c \ mooutils/moofontsel.c \
@ -105,7 +108,6 @@ moo_sources += \
mooutils/mooutils-enums.h \ mooutils/mooutils-enums.h \
mooutils/mooutils-file.c \ mooutils/mooutils-file.c \
mooutils/mooutils-file.h \ mooutils/mooutils-file.h \
mooutils/mooutils-file-private.h\
mooutils/mooutils-fs.c \ mooutils/mooutils-fs.c \
mooutils/mooutils-fs.h \ mooutils/mooutils-fs.h \
mooutils/mooutils-gobject-private.h \ mooutils/mooutils-gobject-private.h \

View File

@ -28,8 +28,6 @@ void _moo_sync_toggle_action (GtkAction *action,
const char *prop, const char *prop,
gboolean invert); gboolean invert);
gpointer _moo_action_get_window (gpointer action);
/* defined in mooactionbase.c */ /* defined in mooactionbase.c */
gboolean _moo_action_get_dead (gpointer action); gboolean _moo_action_get_dead (gpointer action);
gboolean _moo_action_get_has_submenu (gpointer action); gboolean _moo_action_get_has_submenu (gpointer action);

View File

@ -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_toggle_action_get_type (void) G_GNUC_CONST;
GType moo_radio_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 G_END_DECLS

View File

@ -3,23 +3,63 @@
#include <mooutils/mooutils-mem.h> #include <mooutils/mooutils-mem.h>
#define MOO_DEFINE_PTR_ARRAY(ArrayType, array_type, ElmType, \ #define MOO_DECLARE_PTR_ARRAY(ArrayType, array_type, ElmType) \
copy_elm, free_elm) \
\ \
typedef struct ArrayType ArrayType; \ typedef struct ArrayType ArrayType; \
\
struct ArrayType { \ struct ArrayType { \
MOO_IP_ARRAY_ELMS (ElmType*, elms); \ 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) \ array_type##_new (void) \
{ \ { \
ArrayType *ar = g_slice_new0 (ArrayType); \ ArrayType *ar = g_slice_new0 (ArrayType); \
MOO_IP_ARRAY_INIT (ar, elms, 0); \ MOO_IP_ARRAY_INIT (ElmType*, ar, elms, 0); \
return ar; \ return ar; \
} \ } \
\ \
inline static void \ void \
array_type##_free (ArrayType *ar) \ array_type##_free (ArrayType *ar) \
{ \ { \
if (ar) \ if (ar) \
@ -32,23 +72,36 @@ array_type##_free (ArrayType *ar) \
} \ } \
} \ } \
\ \
inline static void \ void \
array_type##_append (ArrayType *ar, ElmType *elm) \ array_type##_append (ArrayType *ar, ElmType *elm) \
{ \ { \
g_return_if_fail (ar != NULL && elm != NULL); \ 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); \ 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) \ array_type##_take (ArrayType *ar, ElmType *elm) \
{ \ { \
g_return_if_fail (ar != NULL && elm != NULL); \ 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; \ ar->elms[ar->n_elms - 1] = elm; \
} \ } \
\ \
inline static ArrayType * \ ArrayType * \
array_type##_copy (ArrayType *ar) \ array_type##_copy (ArrayType *ar) \
{ \ { \
ArrayType *copy; \ ArrayType *copy; \
@ -60,7 +113,7 @@ array_type##_copy (ArrayType *ar) \
if (ar->n_elms) \ if (ar->n_elms) \
{ \ { \
guint i; \ 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) \ for (i = 0; i < ar->n_elms; ++i) \
copy->elms[i] = copy_elm (ar->elms[i]); \ copy->elms[i] = copy_elm (ar->elms[i]); \
} \ } \
@ -68,39 +121,76 @@ array_type##_copy (ArrayType *ar) \
return copy; \ return copy; \
} \ } \
\ \
typedef void (*ArrayType##ForeachFunc) (ElmType *elm, \ void array_type##_remove (ArrayType *ar, ElmType *elm) \
gpointer data); \
\
inline static void \
array_type##_foreach (ArrayType *ar, \
ArrayType##ForeachFunc func, \
gpointer data) \
{ \ { \
guint i; \ guint i; \
g_return_if_fail (ar != NULL && func != NULL); \ \
g_return_if_fail (ar != NULL); \
\
for (i = 0; i < ar->n_elms; ++i) \ 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) \ #define MOO_DECLARE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \
MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \ MOO_DECLARE_PTR_ARRAY (ArrayType, array_type, ElmType)
g_object_ref, g_object_unref)
#define MOO_DEFINE_PTR_ARRAY_NO_COPY(ArrayType, array_type, ElmType) \ #define MOO_DEFINE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \
inline static ElmType * \ inline static ElmType * \
array_type##_dummy_copy_elm__ (ElmType *elm) \ array_type##_ref_elm__ (ElmType *elm) \
{ \ { \
return elm; \ return (ElmType*) g_object_ref (elm); \
} \ } \
\ \
inline static void \ inline static void \
array_type##_dummy_free_elm__ (G_GNUC_UNUSED ElmType *elm) \ array_type##_unref_elm__ (ElmType *elm) \
{ \ { \
} \ g_object_unref (elm); \
} \
\ \
MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \ MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \
array_type##_dummy_copy_elm__, \ array_type##_ref_elm__, \
array_type##_dummy_free_elm__) array_type##_unref_elm__)
#endif /* MOO_ARRAY_H */ #endif /* MOO_ARRAY_H */

View File

@ -35,6 +35,15 @@ static GdkAtom name ## _atom (void)
MOO_DEFINE_ATOM_ (Name) \ 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; GdkAtom moo_atom_uri_list (void) G_GNUC_CONST;
G_END_DECLS G_END_DECLS

View File

@ -333,15 +333,23 @@ moo_file_dialog (GtkWidget *parent,
{ {
static char *filename; static char *filename;
MooFileDialog *dialog; 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); g_return_val_if_fail (dialog != NULL, NULL);
moo_file_dialog_run (dialog); moo_file_dialog_run (dialog);
g_free (filename); file = moo_file_dialog_get_file (dialog);
filename = moo_file_dialog_get_filename (dialog);
g_free (filename);
filename = file ? g_file_get_path (file) : NULL;
g_object_unref (file);
g_object_unref (start);
g_object_unref (dialog); g_object_unref (dialog);
return filename; return filename;
} }
@ -442,23 +450,20 @@ string_slist_to_strv (GSList *list)
return uris; return uris;
} }
static char ** static MooFileArray *
uri_list_to_filenames (GSList *list) uri_list_to_files (GSList *list)
{ {
guint len, i; MooFileArray *flocs;
char **filenames;
if (!list) if (!list)
return NULL; return NULL;
len = g_slist_length (list); flocs = moo_file_array_new ();
filenames = g_new (char*, len + 1);
for (i = 0; i < len; i++, list = list->next) while (list)
filenames[i] = g_filename_from_uri ((const char*) list->data, NULL, NULL); /* XXX check */ moo_file_array_take (flocs, g_file_new_for_uri (list->data));
filenames[i] = NULL; return flocs;
return filenames;
} }
@ -726,12 +731,11 @@ moo_file_dialog_set_extra_widget (MooFileDialog *dialog,
} }
char * GFile *
moo_file_dialog_get_filename (MooFileDialog *dialog) moo_file_dialog_get_file (MooFileDialog *dialog)
{ {
g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL); g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL);
return dialog->priv->uri ? return dialog->priv->uri ? g_file_new_for_uri (dialog->priv->uri) : NULL;
g_filename_from_uri (dialog->priv->uri, NULL, NULL) : NULL;
} }
char * char *
@ -741,11 +745,11 @@ moo_file_dialog_get_uri (MooFileDialog *dialog)
return g_strdup (dialog->priv->uri); return g_strdup (dialog->priv->uri);
} }
char ** MooFileArray *
moo_file_dialog_get_filenames (MooFileDialog *dialog) moo_file_dialog_get_files (MooFileDialog *dialog)
{ {
g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL); 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 ** char **
@ -808,14 +812,14 @@ moo_file_dialog_new (MooFileDialogType type,
GtkWidget *parent, GtkWidget *parent,
gboolean multiple, gboolean multiple,
const char *title, const char *title,
const char *start_dir, GFile *start_loc,
const char *start_name) const char *start_name)
{ {
char *start_dir_uri = NULL; char *start_dir_uri = NULL;
MooFileDialog *dialog; MooFileDialog *dialog;
if (start_dir) if (start_loc)
start_dir_uri = g_filename_to_uri (start_dir, NULL, NULL); start_dir_uri = g_file_get_uri (start_loc);
dialog = MOO_FILE_DIALOG ( dialog = MOO_FILE_DIALOG (
g_object_new (MOO_TYPE_FILE_DIALOG, g_object_new (MOO_TYPE_FILE_DIALOG,

View File

@ -17,6 +17,7 @@
#define MOO_FILE_DIALOG_H #define MOO_FILE_DIALOG_H
#include <gtk/gtkwidget.h> #include <gtk/gtkwidget.h>
#include <mooutils/mooutils-file.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -62,14 +63,14 @@ MooFileDialog *moo_file_dialog_new (MooFileDialogType type,
GtkWidget *parent, GtkWidget *parent,
gboolean multiple, gboolean multiple,
const char *title, const char *title,
const char *start_dir, GFile *start_loc,
const char *start_name); const char *start_name);
void moo_file_dialog_set_filter_mgr_id (MooFileDialog *dialog, void moo_file_dialog_set_filter_mgr_id (MooFileDialog *dialog,
const char *id); const char *id);
gboolean moo_file_dialog_run (MooFileDialog *dialog); gboolean moo_file_dialog_run (MooFileDialog *dialog);
char *moo_file_dialog_get_filename (MooFileDialog *dialog); GFile *moo_file_dialog_get_file (MooFileDialog *dialog);
char **moo_file_dialog_get_filenames (MooFileDialog *dialog); MooFileArray *moo_file_dialog_get_files (MooFileDialog *dialog);
char *moo_file_dialog_get_uri (MooFileDialog *dialog); char *moo_file_dialog_get_uri (MooFileDialog *dialog);
char **moo_file_dialog_get_uris (MooFileDialog *dialog); char **moo_file_dialog_get_uris (MooFileDialog *dialog);

View File

@ -49,7 +49,7 @@ moo_file_icon_for_file (MooFileIcon *icon,
} }
GdkPixbuf * GdkPixbuf *
moo_get_icon_for_file (const char *path, moo_get_icon_for_path (const char *path,
GtkWidget *widget, GtkWidget *widget,
GtkIconSize size) GtkIconSize size)
{ {

View File

@ -17,6 +17,7 @@
#define MOO_FILE_ICON_H #define MOO_FILE_ICON_H
#include <gtk/gtkwidget.h> #include <gtk/gtkwidget.h>
#include <mooutils/mooutils-file.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -55,7 +56,7 @@ GdkPixbuf *moo_file_icon_get_pixbuf (MooFileIcon *icon,
GtkWidget *widget, GtkWidget *widget,
GtkIconSize size); GtkIconSize size);
/* needs gtk lock */ /* needs gtk lock */
GdkPixbuf *moo_get_icon_for_file (const char *path, GdkPixbuf *moo_get_icon_for_path (const char *path,
GtkWidget *widget, GtkWidget *widget,
GtkIconSize size); GtkIconSize size);

View File

View File

@ -1,5 +1,5 @@
/* /*
* mooutils-file-private.h * moofilewriter-private.h
* *
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net> * Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
* *
@ -13,10 +13,10 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>. * License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MOO_UTILS_FILE_PRIVATE_H #ifndef MOO_FILE_WRITER_PRIVATE_H
#define MOO_UTILS_FILE_PRIVATE_H #define MOO_FILE_WRITER_PRIVATE_H
#include "mooutils/mooutils-file.h" #include "mooutils/moofilewriter.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -82,4 +82,4 @@ struct MooStringWriterClass {
G_END_DECLS G_END_DECLS
#endif /* MOO_UTILS_FILE_PRIVATE_H */ #endif /* MOO_FILE_WRITER_PRIVATE_H */

View File

@ -1,5 +1,5 @@
/* /*
* mooutils-file.c * moofilewriter.c
* *
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net> * Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
* *
@ -14,7 +14,7 @@
*/ */
#include <config.h> #include <config.h>
#include "mooutils/mooutils-file-private.h" #include "mooutils/moofilewriter-private.h"
#include "mooutils/mootype-macros.h" #include "mooutils/mootype-macros.h"
#include "mooutils/mooutils-fs.h" #include "mooutils/mooutils-fs.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"

View File

@ -13,10 +13,9 @@
* License along with medit. If not, see <http://www.gnu.org/licenses/>. * License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef MOO_UTILS_FILE_H #ifndef MOO_FILE_WRITER_H
#define MOO_UTILS_FILE_H #define MOO_FILE_WRITER_H
#include <mooutils/moofileloc.h>
#include <gio/gio.h> #include <gio/gio.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -70,4 +69,4 @@ const char *moo_string_writer_get_string (MooFileWriter *writer,
G_END_DECLS G_END_DECLS
#endif /* MOO_UTILS_FILE_H */ #endif /* MOO_FILE_WRITER_H */

View File

@ -16,7 +16,7 @@
#ifndef MOO_MARKUP_H #ifndef MOO_MARKUP_H
#define MOO_MARKUP_H #define MOO_MARKUP_H
#include <mooutils/mooutils-file.h> #include <mooutils/moofilewriter.h>
G_BEGIN_DECLS G_BEGIN_DECLS

View File

@ -981,6 +981,13 @@ moo_prefs_get_filename (const char *key)
return val; 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 gboolean
moo_prefs_get_bool (const char *key) moo_prefs_get_bool (const char *key)
@ -1056,6 +1063,25 @@ moo_prefs_set_filename (const char *key,
g_free (utf8_val); 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 void
moo_prefs_set_int (const char *key, moo_prefs_set_int (const char *key,

View File

@ -18,6 +18,7 @@
#include <glib-object.h> #include <glib-object.h>
#include <mooutils/moomarkup.h> #include <mooutils/moomarkup.h>
#include <mooutils/mooutils-file.h>
G_BEGIN_DECLS 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_string (const char *key);
const char *moo_prefs_get_filename (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); gboolean moo_prefs_get_bool (const char *key);
int moo_prefs_get_int (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); const char *val);
void moo_prefs_set_filename (const char *key, void moo_prefs_set_filename (const char *key,
const char *val); const char *val);
void moo_prefs_set_file (const char *key,
GFile *val);
void moo_prefs_set_int (const char *key, void moo_prefs_set_int (const char *key,
int val); int val);
void moo_prefs_set_bool (const char *key, void moo_prefs_set_bool (const char *key,

View File

@ -0,0 +1,28 @@
#include "config.h"
#include "mooutils-file.h"
#include "mooutils.h"
#include <fnmatch.h>
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);
}

View File

@ -0,0 +1,24 @@
#ifndef MOO_UTILS_FILE_H
#define MOO_UTILS_FILE_H
#include <gio/gio.h>
#include <mooutils/mooarray.h>
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 */

View File

@ -44,12 +44,13 @@ G_STMT_START { \
gsize n_##name_; \ gsize n_##name_; \
gsize n_##name_##_allocd__ gsize n_##name_##_allocd__
#define MOO_IP_ARRAY_INIT(c_,name_,len_) \ #define MOO_IP_ARRAY_INIT(ElmType,c_,name_,len_) \
G_STMT_START { \ G_STMT_START { \
gsize use_len__ = len_; \ gsize use_len__ = len_; \
if (use_len__ == 0) \ if (use_len__ == 0) \
use_len__ = 2; \ 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_ = len_; \
(c_)->n_##name_##_allocd__ = use_len__; \ (c_)->n_##name_##_allocd__ = use_len__; \
} G_STMT_END } G_STMT_END
@ -60,14 +61,14 @@ G_STMT_START { \
(c_)->name_ = NULL; \ (c_)->name_ = NULL; \
} G_STMT_END } G_STMT_END
#define MOO_IP_ARRAY_GROW(c_,name_,howmuch_) \ #define MOO_IP_ARRAY_GROW(ElmType,c_,name_,howmuch_) \
G_STMT_START { \ G_STMT_START { \
if ((c_)->n_##name_ + howmuch_ > (c_)->n_##name_##_allocd__) \ if ((c_)->n_##name_ + howmuch_ > (c_)->n_##name_##_allocd__) \
{ \ { \
gsize old_size__ = (c_)->n_##name_##_allocd__; \ gsize old_size__ = (c_)->n_##name_##_allocd__; \
gsize new_size__ = MAX(old_size__ * 1.2, \ gsize new_size__ = MAX(old_size__ * 1.2, \
(c_)->n_##name_ + howmuch_); \ (c_)->n_##name_ + howmuch_); \
(c_)->name_ = g_realloc ((c_)->name_, \ (c_)->name_ = (ElmType*) g_realloc ((c_)->name_, \
new_size__ * sizeof *(c_)->name_); \ new_size__ * sizeof *(c_)->name_); \
(c_)->n_##name_##_allocd__ = new_size__; \ (c_)->n_##name_##_allocd__ = new_size__; \
} \ } \
@ -77,5 +78,16 @@ G_STMT_START { \
(c_)->n_##name_ += howmuch_; \ (c_)->n_##name_ += howmuch_; \
} G_STMT_END } 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 */ #endif /* MOO_UTILS_MEM_H */

View File

@ -153,6 +153,30 @@ do { \
#define moo_return_if_reached() moo_return_val_if_reached(;) #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 * Suppress warnings when GCC is in -pedantic mode and not -std=c99
*/ */

View File

@ -16,7 +16,7 @@
#include "config.h" #include "config.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/mooutils-fs.h" #include "mooutils/mooutils-fs.h"
#include "mooutils/mooutils-file.h" #include "mooutils/moofilewriter.h"
#include "mooutils/mooutils-debug.h" #include "mooutils/mooutils-debug.h"
#include "mooutils/mooi18n.h" #include "mooutils/mooi18n.h"
#include "mooutils/mooatom.h" #include "mooutils/mooatom.h"
@ -24,6 +24,7 @@
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include <mooutils/mooutils-tests.h> #include <mooutils/mooutils-tests.h>
#include "mooutils/moocompat.h" #include "mooutils/moocompat.h"
#include "mooutils/mootype-macros.h"
#include "moologwindow-gxml.h" #include "moologwindow-gxml.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <glib/gmappedfile.h> #include <glib/gmappedfile.h>
@ -52,6 +53,7 @@
#include <shellapi.h> #include <shellapi.h>
#endif #endif
MOO_DEFINE_QUARK (moo-error, moo_error_quark)
G_LOCK_DEFINE_STATIC (moo_user_data_dir); G_LOCK_DEFINE_STATIC (moo_user_data_dir);
static char *moo_app_instance_name; static char *moo_app_instance_name;

8
moo/mooutils/mooutils.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef MOO_UTILS_H
#define MOO_UTILS_H
#include <mooutils/mooutils-misc.h>
#include <mooutils/mooutils-messages.h>
#include <mooutils/mootype-macros.h>
#endif /* MOO_UTILS_H */

View File

@ -350,6 +350,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
{ {
MooEdit *doc; MooEdit *doc;
char *filename; char *filename;
GFile *file;
plugin->priv->update_idle = 0; plugin->priv->update_idle = 0;
@ -357,7 +358,8 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
doc = MOO_DOC_PLUGIN (plugin)->doc; 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)) if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
{ {
@ -368,7 +370,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
if (filename) if (filename)
{ {
GSList *list = NULL; 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)); 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))) 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); g_free (filename);
moo_file_free (file);
return FALSE; return FALSE;
} }

View File

@ -159,7 +159,7 @@ ctags_plugin_deinit (G_GNUC_UNUSED CtagsPlugin *plugin)
MOO_PLUGIN_DEFINE_INFO (ctags, "Ctags", "Shows functions in the open document", MOO_PLUGIN_DEFINE_INFO (ctags, "Ctags", "Shows functions in the open document",
"Yevgen Muntyan <emuntyan@sourceforge.net>\n" "Yevgen Muntyan <emuntyan@sourceforge.net>\n"
"Christian Dywan <christian@twotoasts.de>", "Christian Dywan <christian@twotoasts.de>",
MOO_VERSION, NULL) MOO_VERSION)
MOO_WIN_PLUGIN_DEFINE (Ctags, ctags) MOO_WIN_PLUGIN_DEFINE (Ctags, ctags)
MOO_PLUGIN_DEFINE (Ctags, ctags, MOO_PLUGIN_DEFINE (Ctags, ctags,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

View File

@ -2217,15 +2217,23 @@ compare_docs_by_name (MooEdit *doc1,
static gboolean static gboolean
do_update (WindowPlugin *plugin) do_update (WindowPlugin *plugin)
{ {
GSList *docs; MooEditArray *docs;
GSList *list;
guint i;
plugin->update_idle = 0; plugin->update_idle = 0;
docs = moo_edit_window_list_docs (MOO_WIN_PLUGIN (plugin)->window); docs = moo_edit_window_get_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);
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; return FALSE;
} }
@ -2405,7 +2413,7 @@ file_list_plugin_deinit (G_GNUC_UNUSED FileListPlugin *plugin)
MOO_PLUGIN_DEFINE_INFO (file_list, MOO_PLUGIN_DEFINE_INFO (file_list,
N_("File List"), N_("List of files"), N_("File List"), N_("List of files"),
"Yevgen Muntyan <emuntyan@sourceforge.net>", "Yevgen Muntyan <emuntyan@sourceforge.net>",
MOO_VERSION, NULL) MOO_VERSION)
MOO_WIN_PLUGIN_DEFINE (FileList, file_list) MOO_WIN_PLUGIN_DEFINE (FileList, file_list)
MOO_PLUGIN_DEFINE (FileList, file_list, MOO_PLUGIN_DEFINE (FileList, file_list,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

View File

@ -19,13 +19,15 @@
#include "moofileselector.h" #include "moofileselector.h"
#include "mooedit/mooplugin-macro.h" #include "mooedit/mooplugin-macro.h"
#include "mooedit/mooeditwindow.h"
#include "moofileview/moobookmarkmgr.h" #include "moofileview/moobookmarkmgr.h"
#include "moofileview/moofileview-tools.h" #include "moofileview/moofileview-tools.h"
#include "mooeditplugins.h" #include "mooeditplugins.h"
#include "marshals.h" #include "marshals.h"
#include "mooutils/moostock.h" #include "mooutils/moostock.h"
#include "mooutils/mooprefs.h"
#include "mooutils/mooutils-fs.h" #include "mooutils/mooutils-fs.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils.h"
#include "mooutils/mooentry.h" #include "mooutils/mooentry.h"
#include "mooutils/moodialogs.h" #include "mooutils/moodialogs.h"
#include "mooutils/mooactionfactory.h" #include "mooutils/mooactionfactory.h"
@ -64,7 +66,7 @@ enum {
}; };
static GtkTargetEntry targets[] = { 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 } { (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) 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 { enum {
PROP_0, PROP_0,
PROP_WINDOW PROP_WINDOW
}; };
static void moo_file_selector_set_property (GObject *object, static void moo_file_selector_set_property (GObject *object,
guint prop_id, guint prop_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void moo_file_selector_get_property (GObject *object, static void moo_file_selector_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static GObject *moo_file_selector_constructor (GType type, static GObject *moo_file_selector_constructor (GType type,
guint n_props, guint n_props,
GObjectConstructParam *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, static void moo_file_selector_select_file (MooFileSelector *filesel,
const char *filename); GFile *file);
static gboolean moo_file_selector_chdir (MooFileView *fileview, static void moo_file_selector_select_path (MooFileSelector *filesel,
const char *dir, const char *filename);
GError **error); static gboolean moo_file_selector_chdir (MooFileView *fileview,
static void moo_file_selector_activate (MooFileView *fileview, const char *dir,
const char *path); GError **error);
static void moo_file_selector_populate_popup(MooFileView *fileview, static void moo_file_selector_activate (MooFileView *fileview,
GList *selected, const char *path);
GtkMenu *menu); 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, static gboolean moo_file_selector_drop (MooFileView *fileview,
const char *path, const char *path,
GtkWidget *widget, GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
int x, int x,
int y, int y,
guint time); guint time);
static gboolean moo_file_selector_drop_data_received (MooFileView *fileview, static gboolean moo_file_selector_drop_data_received (MooFileView *fileview,
const char *path, const char *path,
GtkWidget *widget, GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
int x, int x,
int y, int y,
GtkSelectionData *data, GtkSelectionData *data,
guint info, guint info,
guint time); guint time);
static void moo_file_selector_drop_doc (MooFileSelector *filesel, static void moo_file_selector_drop_doc (MooFileSelector *filesel,
MooEdit *doc, MooEdit *doc,
const char *destdir, const char *destdir,
GtkWidget *widget, GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
int x, int x,
int y, int y,
guint time); guint time);
static void 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->drop_data_received = moo_file_selector_drop_data_received;
fileview_class->populate_popup = moo_file_selector_populate_popup; fileview_class->populate_popup = moo_file_selector_populate_popup;
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class, PROP_WINDOW,
PROP_WINDOW, g_param_spec_object ("window", "window", "window",
g_param_spec_object ("window", MOO_TYPE_EDIT_WINDOW, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
"window",
"window",
MOO_TYPE_EDIT_WINDOW,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
_moo_signal_new_cb ("goto-current-doc-dir", _moo_signal_new_cb ("goto-current-doc-dir",
G_OBJECT_CLASS_TYPE (klass), G_OBJECT_CLASS_TYPE (klass),
@ -234,17 +231,11 @@ static void
file_selector_go_home (MooFileView *fileview) file_selector_go_home (MooFileView *fileview)
{ {
const char *dir; const char *dir;
char *real_dir = NULL;
dir = moo_prefs_get_string (DIR_PREFS); dir = moo_prefs_get_filename (DIR_PREFS);
if (dir) if (!dir || !moo_file_view_chdir_path (fileview, dir, NULL))
real_dir = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL);
if (!real_dir || !moo_file_view_chdir (fileview, real_dir, NULL))
g_signal_emit_by_name (fileview, "go-home"); g_signal_emit_by_name (fileview, "go-home");
g_free (real_dir);
} }
@ -323,19 +314,16 @@ static void
goto_current_doc_dir (MooFileSelector *filesel) goto_current_doc_dir (MooFileSelector *filesel)
{ {
MooEdit *doc; MooEdit *doc;
char *filename; GFile *file, *parent_file;
GError *error = NULL; GError *error = NULL;
doc = moo_edit_window_get_active_doc (filesel->window); 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) if (parent_file)
{ if (moo_file_view_chdir (MOO_FILE_VIEW (filesel), parent_file, &error))
char *dirname = g_path_get_dirname (filename); moo_file_selector_select_file (filesel, file);
if (moo_file_view_chdir (MOO_FILE_VIEW (filesel), dirname, &error))
moo_file_selector_select_file (filesel, filename);
g_free (dirname);
}
if (error) if (error)
{ {
@ -343,7 +331,8 @@ goto_current_doc_dir (MooFileSelector *filesel)
g_error_free (error); 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 static gboolean
moo_file_selector_drop_data_received (MooFileView *fileview, moo_file_selector_drop_data_received (MooFileView *fileview,
const char *path, const char *path,
GtkWidget *widget, GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
@ -841,7 +830,7 @@ out:
static void static void
moo_file_selector_select_file (MooFileSelector *filesel, moo_file_selector_select_path (MooFileSelector *filesel,
const char *filename) const char *filename)
{ {
char *basename; char *basename;
@ -854,12 +843,21 @@ moo_file_selector_select_file (MooFileSelector *filesel,
g_free (basename); 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 static gboolean
drop_untitled (MooFileSelector *filesel, drop_untitled (MooFileSelector *filesel,
MooEdit *doc, MooEdit *doc,
const char *destdir, const char *destdir,
GtkWidget *widget, GtkWidget *widget,
G_GNUC_UNUSED GdkDragContext *context, G_GNUC_UNUSED GdkDragContext *context,
G_GNUC_UNUSED int x, G_GNUC_UNUSED int x,
G_GNUC_UNUSED int y, G_GNUC_UNUSED int y,
@ -878,7 +876,7 @@ drop_untitled (MooFileSelector *filesel,
result = moo_edit_save_as (doc, name, NULL, NULL); result = moo_edit_save_as (doc, name, NULL, NULL);
if (result) if (result)
moo_file_selector_select_file (filesel, name); moo_file_selector_select_path (filesel, name);
g_free (name); g_free (name);
return result; return result;
@ -899,8 +897,8 @@ doc_save_as (MooFileSelector *filesel,
if (filename) 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_file_selector_select_file (filesel, filename); moo_file_selector_select_path (filesel, filename);
g_free (filename); g_free (filename);
} }
} }
@ -919,8 +917,8 @@ doc_save_copy (MooFileSelector *filesel,
if (filename) if (filename)
{ {
if (moo_edit_save_copy (doc, filename, moo_edit_get_encoding (doc), NULL)) if (moo_edit_save_copy (doc, filename, NULL, NULL))
moo_file_selector_select_file (filesel, filename); moo_file_selector_select_path (filesel, filename);
g_free (filename); g_free (filename);
} }
} }
@ -931,11 +929,11 @@ doc_move (MooFileSelector *filesel,
gboolean ask_name, gboolean ask_name,
const char *destdir) const char *destdir)
{ {
char *filename, *old_filename; GFile *old_file;
char *filename;
old_filename = moo_edit_get_filename (doc); old_file = moo_edit_get_file (doc);
/* XXX non-local */ g_return_if_fail (old_file != NULL);
g_return_if_fail (old_filename != NULL);
filename = save_as_dialog (GTK_WIDGET (filesel), destdir, filename = save_as_dialog (GTK_WIDGET (filesel), destdir,
moo_edit_get_display_basename (doc), moo_edit_get_display_basename (doc),
@ -943,16 +941,16 @@ doc_move (MooFileSelector *filesel,
if (filename) 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); g_file_delete (old_file, NULL, NULL);
moo_file_selector_select_file (filesel, filename); moo_file_selector_select_path (filesel, filename);
} }
g_free (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 static void
moo_file_selector_drop_doc (MooFileSelector *filesel, moo_file_selector_drop_doc (MooFileSelector *filesel,
MooEdit *doc, MooEdit *doc,
const char *destdir, const char *destdir,
GtkWidget *widget, GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
int x, int x,
int y, int y,
guint time) guint time)
{ {
GdkModifierType mods; GdkModifierType mods;
DropDocAction action; DropDocAction action;
@ -1210,12 +1208,9 @@ static void
file_selector_plugin_attach (MooPlugin *mplugin, file_selector_plugin_attach (MooPlugin *mplugin,
MooEditWindow *window) MooEditWindow *window)
{ {
MooEditor *editor;
GtkWidget *filesel; GtkWidget *filesel;
Plugin *plugin = FILE_SELECTOR_PLUGIN (mplugin); Plugin *plugin = FILE_SELECTOR_PLUGIN (mplugin);
editor = moo_edit_window_get_editor (window);
if (!plugin->bookmark_mgr) if (!plugin->bookmark_mgr)
plugin->bookmark_mgr = _moo_bookmark_mgr_new (); plugin->bookmark_mgr = _moo_bookmark_mgr_new ();
@ -1256,7 +1251,7 @@ MOO_PLUGIN_DEFINE_INFO (file_selector,
N_("File Selector"), N_("File Selector"),
N_("File selector pane for editor window"), N_("File selector pane for editor window"),
"Yevgen Muntyan <emuntyan@sourceforge.net>", "Yevgen Muntyan <emuntyan@sourceforge.net>",
MOO_VERSION, NULL) MOO_VERSION)
MOO_PLUGIN_DEFINE (FileSelector, file_selector, MOO_PLUGIN_DEFINE (FileSelector, file_selector,
file_selector_plugin_attach, file_selector_plugin_detach, file_selector_plugin_attach, file_selector_plugin_detach,
NULL, NULL, NULL, NULL,

View File

@ -244,7 +244,6 @@ find_plugin_init (FindPlugin *plugin)
MooUiXml *xml = moo_editor_get_ui_xml (editor); MooUiXml *xml = moo_editor_get_ui_xml (editor);
g_return_val_if_fail (klass != NULL, FALSE); g_return_val_if_fail (klass != NULL, FALSE);
g_return_val_if_fail (editor != NULL, FALSE);
moo_window_class_new_action (klass, "FindInFiles", NULL, moo_window_class_new_action (klass, "FindInFiles", NULL,
"display-name", _("Find In Files"), "display-name", _("Find In Files"),
@ -343,8 +342,8 @@ init_skip_list (void)
} }
static void static void
create_grep_dialog (MooEditWindow *window, create_grep_dialog (MooEditWindow *window,
WindowStuff *stuff) WindowStuff *stuff)
{ {
GtkWidget *pattern_entry; GtkWidget *pattern_entry;
@ -388,8 +387,8 @@ create_grep_dialog (MooEditWindow *window,
static void static void
create_find_dialog (MooEditWindow *window, create_find_dialog (MooEditWindow *window,
WindowStuff *stuff) WindowStuff *stuff)
{ {
GtkWidget *pattern_entry; GtkWidget *pattern_entry;
@ -443,11 +442,13 @@ init_dir_entry (MooHistoryCombo *hist_combo,
if (!gtk_entry_get_text (GTK_ENTRY (entry))[0]) if (!gtk_entry_get_text (GTK_ENTRY (entry))[0])
{ {
MooFileEntryCompletion *completion; MooFileEntryCompletion *completion;
GFile *file;
char *filename; char *filename;
completion = g_object_get_data (G_OBJECT (entry), "find-plugin-file-completion"); 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) if (filename)
{ {
@ -461,6 +462,7 @@ init_dir_entry (MooHistoryCombo *hist_combo,
} }
g_free (filename); g_free (filename);
g_object_unref (file);
} }
#if 0 #if 0
@ -556,8 +558,8 @@ get_directories (MooHistoryCombo *combo)
static void static void
do_grep (MooEditWindow *window, do_grep (MooEditWindow *window,
WindowStuff *stuff) WindowStuff *stuff)
{ {
GtkWidget *pane; GtkWidget *pane;
MooHistoryCombo *pattern_combo, *skip_combo, *glob_combo; MooHistoryCombo *pattern_combo, *skip_combo, *glob_combo;
@ -604,8 +606,8 @@ do_grep (MooEditWindow *window,
static void static void
do_find (MooEditWindow *window, do_find (MooEditWindow *window,
WindowStuff *stuff) WindowStuff *stuff)
{ {
GtkWidget *pane; GtkWidget *pane;
MooHistoryCombo *pattern_combo, *skip_combo; MooHistoryCombo *pattern_combo, *skip_combo;
@ -1100,8 +1102,7 @@ output_activate (WindowStuff *stuff,
return FALSE; return FALSE;
editor = moo_edit_window_get_editor (stuff->window); editor = moo_edit_window_get_editor (stuff->window);
moo_editor_open_file_line (editor, line_data->filename, moo_editor_open_file_line (editor, line_data->filename, line_data->line, stuff->window);
line_data->line, stuff->window);
return TRUE; return TRUE;
} }
@ -1110,7 +1111,7 @@ output_activate (WindowStuff *stuff,
MOO_PLUGIN_DEFINE_INFO (find, MOO_PLUGIN_DEFINE_INFO (find,
N_("Find"), N_("Finds everything"), N_("Find"), N_("Finds everything"),
"Yevgen Muntyan <emuntyan@sourceforge.net>", "Yevgen Muntyan <emuntyan@sourceforge.net>",
MOO_VERSION, NULL) MOO_VERSION)
MOO_WIN_PLUGIN_DEFINE (Find, find) MOO_WIN_PLUGIN_DEFINE (Find, find)
MOO_PLUGIN_DEFINE (Find, find, MOO_PLUGIN_DEFINE (Find, find,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,

View File

@ -109,7 +109,7 @@ load_lua_module (const char *module_file,
MOO_PLUGIN_DEFINE_INFO (moo_lua, MOO_PLUGIN_DEFINE_INFO (moo_lua,
N_("Lua"), N_("Lua support"), N_("Lua"), N_("Lua support"),
"Yevgen Muntyan <" MOO_EMAIL ">", "Yevgen Muntyan <" MOO_EMAIL ">",
MOO_VERSION, NULL) MOO_VERSION)
MOO_PLUGIN_DEFINE (MooLua, moo_lua, MOO_PLUGIN_DEFINE (MooLua, moo_lua,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
0, 0) 0, 0)

View File

@ -57,7 +57,7 @@ load_python_module (const char *module_file,
MOO_PLUGIN_DEFINE_INFO (moo_python, MOO_PLUGIN_DEFINE_INFO (moo_python,
N_("Python"), N_("Python support"), N_("Python"), N_("Python support"),
"Yevgen Muntyan <" MOO_EMAIL ">", "Yevgen Muntyan <" MOO_EMAIL ">",
MOO_VERSION, NULL) MOO_VERSION)
MOO_PLUGIN_DEFINE (MooPython, moo_python, MOO_PLUGIN_DEFINE (MooPython, moo_python,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
0, 0) 0, 0)

View File

@ -432,7 +432,8 @@ static gboolean
save_all (MooEdit *doc) save_all (MooEdit *doc)
{ {
MooEditWindow *window; MooEditWindow *window;
GSList *list, *l; MooEditArray *docs;
guint i;
gboolean result = TRUE; gboolean result = TRUE;
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE); g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
@ -440,18 +441,18 @@ save_all (MooEdit *doc)
window = moo_edit_get_window (doc); window = moo_edit_get_window (doc);
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE); 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; result = FALSE;
break; break;
} }
} }
g_slist_free (list); moo_edit_array_free (docs);
return result; return result;
} }

View File

@ -17,7 +17,7 @@
#include "mooutils/mooutils-gobject.h" #include "mooutils/mooutils-gobject.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/mootype-macros.h" #include "mooutils/mootype-macros.h"
#include "mooedit/mooedit-tests.h" #include "mooedit/mooeditor-tests.h"
#include <string.h> #include <string.h>

View File

@ -1399,7 +1399,7 @@ MOO_PLUGIN_DEFINE_INFO (user_tools,
N_("User Tools"), N_("User Tools"),
N_("Configurable tools"), N_("Configurable tools"),
"Yevgen Muntyan <emuntyan@sourceforge.net>", "Yevgen Muntyan <emuntyan@sourceforge.net>",
MOO_VERSION, NULL) MOO_VERSION)
MOO_PLUGIN_DEFINE (UserTools, user_tools, MOO_PLUGIN_DEFINE (UserTools, user_tools,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,