Some refactoring
This commit is contained in:
parent
25a93907f5
commit
21bf45b7f7
@ -24,6 +24,7 @@ aclocal.m4
|
||||
*.orig
|
||||
*.bak
|
||||
*.tmp
|
||||
*.rej
|
||||
*.pyc
|
||||
.goutputstream-*
|
||||
po*/dist
|
||||
|
@ -7,7 +7,6 @@
|
||||
#define HELP_SECTION_DIALOG_FIND_IN_FILES "index.html"
|
||||
#define HELP_SECTION_DIALOG_REPLACE "index.html"
|
||||
#define HELP_SECTION_DOCUMENT "Document-object.html"
|
||||
#define HELP_SECTION_DOCUMENT_VIEW "DocumentView-object.html"
|
||||
#define HELP_SECTION_EDITING_OPTIONS "Options-for-editing-text.html"
|
||||
#define HELP_SECTION_FILE_SELECTOR "index.html"
|
||||
#define HELP_SECTION_LICENSE_GPL "GNU-GPL.html"
|
||||
|
@ -18,7 +18,6 @@
|
||||
* Application object:: Application object
|
||||
* Editor object:: Editor object
|
||||
* DocumentWindow object:: DocumentWindow object
|
||||
* DocumentView object:: DocumentView object
|
||||
* Document object:: Document object
|
||||
@end menu
|
||||
|
||||
|
@ -65,16 +65,6 @@ abcdefghij
|
||||
tassert(doc.selected_text() == 'abcdefg\n')
|
||||
end
|
||||
|
||||
local function test_views()
|
||||
doc = editor.new_document()
|
||||
add_doc_to_cleanup(doc)
|
||||
window = doc.active_view().window()
|
||||
tassert(doc.active_view() ~= nil)
|
||||
tassert(#doc.views() == 1)
|
||||
tassert(doc.views()[1] == doc.active_view())
|
||||
end
|
||||
|
||||
test_active_window()
|
||||
test_selection()
|
||||
test_views()
|
||||
cleanup()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <mooedit/mooedit-tests.h>
|
||||
#include <mooedit/mooeditor-tests.h>
|
||||
#include <mooscript/lua/moolua-tests.h>
|
||||
#include <mooutils/mooutils-tests.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -554,21 +554,21 @@ moo_app_get_editor (MooApp *app)
|
||||
static gboolean
|
||||
close_editor_window (MooApp *app)
|
||||
{
|
||||
GSList *windows;
|
||||
MooEditWindowArray *windows;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if (!app->priv->running || app->priv->in_try_quit)
|
||||
return FALSE;
|
||||
|
||||
windows = moo_editor_list_windows (app->priv->editor);
|
||||
windows = moo_editor_get_windows (app->priv->editor);
|
||||
|
||||
if (windows && !windows->next)
|
||||
if (moo_edit_window_array_get_size (windows) == 1)
|
||||
{
|
||||
moo_app_quit (app);
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
g_slist_free (windows);
|
||||
moo_edit_window_array_free (windows);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -582,7 +582,7 @@ init_plugins (MooApp *app)
|
||||
static void
|
||||
moo_app_init_editor (MooApp *app)
|
||||
{
|
||||
app->priv->editor = moo_editor_create_instance (FALSE);
|
||||
app->priv->editor = moo_editor_create (FALSE);
|
||||
|
||||
g_signal_connect_swapped (app->priv->editor, "close-window",
|
||||
G_CALLBACK (close_editor_window), app);
|
||||
|
@ -4,8 +4,8 @@ moo_sources += \
|
||||
mooedit/mooeditaction-factory.c \
|
||||
mooedit/mooeditaction-factory.h \
|
||||
mooedit/mooeditaction.h \
|
||||
mooedit/mooedit-bookmarks.c \
|
||||
mooedit/mooedit-bookmarks.h \
|
||||
mooedit/mooeditbookmark.c \
|
||||
mooedit/mooeditbookmark.h \
|
||||
mooedit/mooedit.c \
|
||||
mooedit/mooedit.h \
|
||||
mooedit/mooeditconfig.c \
|
||||
@ -19,14 +19,19 @@ moo_sources += \
|
||||
mooedit/mooedit-impl.h \
|
||||
mooedit/mooeditor.c \
|
||||
mooedit/mooeditor.h \
|
||||
mooedit/mooeditor-impl.h \
|
||||
mooedit/mooeditor-private.h \
|
||||
mooedit/mooeditor-tests.c \
|
||||
mooedit/mooeditor-tests.h \
|
||||
mooedit/mooeditprefs.c \
|
||||
mooedit/mooeditprefs.h \
|
||||
mooedit/mooeditprefspage.c \
|
||||
mooedit/mooedit-private.h \
|
||||
mooedit/mooedit-tests.h \
|
||||
mooedit/mooeditor-tests.h \
|
||||
mooedit/mooeditwindow.c \
|
||||
mooedit/mooeditwindow.h \
|
||||
mooedit/moofileenc.c \
|
||||
mooedit/moofileenc.h \
|
||||
mooedit/moofold.c \
|
||||
mooedit/moofold.h \
|
||||
mooedit/mooindenter.c \
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit/mooedit-private.h"
|
||||
#include "mooedit/mooeditor-private.h"
|
||||
#include "mooedit/mooeditor-impl.h"
|
||||
#include "mooedit/mooedit-fileops.h"
|
||||
#include "mooedit/mooeditdialogs.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
@ -261,27 +261,6 @@ static LoadResult load_binary (MooEdit *edit,
|
||||
GError **error);
|
||||
#endif
|
||||
|
||||
const char *
|
||||
_moo_get_default_encodings (void)
|
||||
{
|
||||
/* Translators: if translated, it should be a comma-separated list
|
||||
of encodings to try when opening files. Encodings names should be
|
||||
those understood by iconv, or "LOCALE" which means user's locale
|
||||
charset. For instance, the default value is "UTF-8,LOCALE,ISO_8859-15,ISO_8859-1".
|
||||
You want to add common preferred non-UTF8 encodings used in your locale.
|
||||
Do not remove ISO_8859-15 and ISO_8859-1, instead leave them at the end,
|
||||
these are common source files encodings. */
|
||||
const char *to_translate = N_("encodings_list");
|
||||
const char *encodings;
|
||||
|
||||
encodings = _(to_translate);
|
||||
|
||||
if (!strcmp (encodings, to_translate))
|
||||
encodings = "UTF-8," ENCODING_LOCALE ",ISO_8859-1,ISO_8859-15";
|
||||
|
||||
return encodings;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
get_encodings (void)
|
||||
{
|
||||
@ -395,7 +374,7 @@ moo_edit_load_local (MooEdit *edit,
|
||||
MooLineEndType saved_le;
|
||||
|
||||
moo_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
moo_return_val_if_fail (file != NULL, FALSE);
|
||||
moo_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
if (!check_regular (file, error))
|
||||
return FALSE;
|
||||
@ -753,8 +732,8 @@ moo_edit_reload_local (MooEdit *edit,
|
||||
gboolean result, enable_highlight;
|
||||
GFile *file;
|
||||
|
||||
file = _moo_edit_get_file (edit);
|
||||
moo_return_val_if_fail (file != NULL, FALSE);
|
||||
file = moo_edit_get_file (edit);
|
||||
moo_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit));
|
||||
|
||||
@ -1233,29 +1212,15 @@ add_untitled (MooEdit *edit)
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
_moo_edit_get_default_encoding (void)
|
||||
{
|
||||
return moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_ENCODING_SAVE));
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
_moo_file_get_display_name (GFile *file)
|
||||
{
|
||||
moo_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
return g_file_get_parse_name (file);
|
||||
}
|
||||
|
||||
char *
|
||||
_moo_file_get_display_basename (GFile *file)
|
||||
static char *
|
||||
moo_file_get_display_basename (GFile *file)
|
||||
{
|
||||
char *name;
|
||||
const char *slash;
|
||||
|
||||
moo_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
name = _moo_file_get_display_name (file);
|
||||
name = moo_file_get_display_name (file);
|
||||
moo_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
slash = strrchr (name, '/');
|
||||
@ -1339,8 +1304,8 @@ _moo_edit_set_file (MooEdit *edit,
|
||||
edit->priv->norm_filename = _moo_edit_normalize_filename_for_comparison (norm_name_tmp);
|
||||
free_list = g_slist_prepend (free_list, norm_name_tmp);
|
||||
|
||||
edit->priv->display_filename = _moo_file_get_display_name (file);
|
||||
edit->priv->display_basename = _moo_file_get_display_basename (file);
|
||||
edit->priv->display_filename = moo_file_get_display_name (file);
|
||||
edit->priv->display_basename = moo_file_get_display_basename (file);
|
||||
}
|
||||
|
||||
if (!encoding)
|
||||
@ -1351,8 +1316,7 @@ _moo_edit_set_file (MooEdit *edit,
|
||||
g_signal_emit_by_name (edit, "filename-changed", edit->priv->filename, NULL);
|
||||
moo_edit_status_changed (edit);
|
||||
|
||||
if (tmp)
|
||||
g_object_unref (tmp);
|
||||
moo_file_free (tmp);
|
||||
|
||||
g_slist_foreach (free_list, (GFunc) g_free, NULL);
|
||||
g_slist_free (free_list);
|
||||
@ -1365,9 +1329,9 @@ _moo_edit_get_icon (MooEdit *doc,
|
||||
GtkIconSize size)
|
||||
{
|
||||
if (doc->priv->filename)
|
||||
return moo_get_icon_for_file (doc->priv->filename, widget, size);
|
||||
return moo_get_icon_for_path (doc->priv->filename, widget, size);
|
||||
else if (doc->priv->file)
|
||||
return moo_get_icon_for_file (doc->priv->display_basename, widget, size);
|
||||
return moo_get_icon_for_path (doc->priv->display_basename, widget, size);
|
||||
else
|
||||
return moo_get_icon_for_file (NULL, widget, size);
|
||||
return moo_get_icon_for_path (NULL, widget, size);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ gboolean _moo_edit_reload_file (MooEdit *edit,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
gboolean _moo_edit_save_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
GFile *floc,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
@ -60,9 +60,6 @@ gboolean _moo_edit_save_file_copy (MooEdit *edit,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
|
||||
char *_moo_file_get_display_name (GFile *file);
|
||||
char *_moo_file_get_display_basename (GFile *file);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -20,18 +20,10 @@
|
||||
#include "mooedit/mooeditor.h"
|
||||
#include "mooedit/mootextview.h"
|
||||
#include "mooutils/mdhistorymgr.h"
|
||||
#include "mooutils/moolist.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct MooEditFileInfo {
|
||||
GFile *file;
|
||||
char *encoding;
|
||||
};
|
||||
|
||||
MOO_DEFINE_SLIST(MooEditList, moo_edit_list, MooEdit)
|
||||
|
||||
extern MooEditList *_moo_edit_instances;
|
||||
|
||||
void _moo_edit_add_class_actions (MooEdit *edit);
|
||||
@ -92,8 +84,6 @@ void _moo_edit_apply_prefs (MooEdit *edit);
|
||||
/* File operations
|
||||
*/
|
||||
|
||||
GFile *_moo_edit_get_file (MooEdit *edit);
|
||||
|
||||
void _moo_edit_set_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding);
|
||||
|
3
moo/mooedit/mooedit-misc.c
Normal file
3
moo/mooedit/mooedit-misc.c
Normal file
@ -0,0 +1,3 @@
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit-priv.h"
|
||||
|
@ -16,15 +16,14 @@
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit/mooeditaction-factory.h"
|
||||
#include "mooedit/mooedit-private.h"
|
||||
#include "mooedit/mooedit-bookmarks.h"
|
||||
#include "mooedit/mooeditbookmark.h"
|
||||
#include "mooedit/mootextview-private.h"
|
||||
#include "mooedit/mooeditdialogs.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
#include "mooedit/mooeditor-private.h"
|
||||
#include "mooedit/mooeditor-impl.h"
|
||||
#include "mooedit/moolangmgr.h"
|
||||
#include "mooedit/mooedit-tests.h"
|
||||
#include "marshals.h"
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/mooi18n.h"
|
||||
@ -36,10 +35,10 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define KEY_ENCODING "encoding"
|
||||
#define KEY_LINE "line"
|
||||
|
||||
MOO_DEFINE_OBJECT_ARRAY (MooEditArray, moo_edit_array, MooEdit)
|
||||
|
||||
MooEditList *_moo_edit_instances = NULL;
|
||||
|
||||
@ -118,7 +117,6 @@ enum {
|
||||
PROP_ENCODING
|
||||
};
|
||||
|
||||
MOO_DEFINE_BOXED_TYPE_C (MooEditFileInfo, moo_edit_file_info)
|
||||
G_DEFINE_TYPE (MooEdit, moo_edit, MOO_TYPE_TEXT_VIEW)
|
||||
|
||||
|
||||
@ -328,8 +326,7 @@ moo_edit_finalize (GObject *object)
|
||||
{
|
||||
MooEdit *edit = MOO_EDIT (object);
|
||||
|
||||
if (edit->priv->file)
|
||||
g_object_unref (edit->priv->file);
|
||||
moo_file_free (edit->priv->file);
|
||||
g_free (edit->priv->filename);
|
||||
g_free (edit->priv->norm_filename);
|
||||
g_free (edit->priv->display_filename);
|
||||
@ -633,52 +630,8 @@ moo_edit_focus_out (GtkWidget *widget,
|
||||
}
|
||||
|
||||
|
||||
static MooEditFileInfo *
|
||||
moo_edit_file_info_new (GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
MooEditFileInfo *info = moo_new (MooEditFileInfo);
|
||||
info->file = file;
|
||||
info->encoding = g_strdup (encoding);
|
||||
return info;
|
||||
}
|
||||
|
||||
MooEditFileInfo *
|
||||
moo_edit_file_info_new_path (const char *path,
|
||||
const char *encoding)
|
||||
{
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
return moo_edit_file_info_new (g_file_new_for_path (path), encoding);
|
||||
}
|
||||
|
||||
MooEditFileInfo *
|
||||
moo_edit_file_info_new_uri (const char *uri,
|
||||
const char *encoding)
|
||||
{
|
||||
g_return_val_if_fail (uri != NULL, NULL);
|
||||
return moo_edit_file_info_new (g_file_new_for_uri (uri), encoding);
|
||||
}
|
||||
|
||||
MooEditFileInfo *
|
||||
moo_edit_file_info_copy (MooEditFileInfo *info)
|
||||
{
|
||||
return info ? moo_edit_file_info_new ((GFile*) g_object_ref (info->file), info->encoding) : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
moo_edit_file_info_free (MooEditFileInfo *info)
|
||||
{
|
||||
if (info)
|
||||
{
|
||||
g_free (info->encoding);
|
||||
g_object_unref (info->file);
|
||||
moo_free (MooEditFileInfo, info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GFile *
|
||||
_moo_edit_get_file (MooEdit *edit)
|
||||
moo_edit_get_file (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
return edit->priv->file ? g_file_dup (edit->priv->file) : NULL;
|
||||
@ -1063,6 +1016,13 @@ config_changed (MooEdit *edit,
|
||||
}
|
||||
|
||||
|
||||
MooLang *
|
||||
moo_edit_get_lang (MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
return moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
||||
}
|
||||
|
||||
static void
|
||||
moo_edit_set_lang (MooEdit *edit,
|
||||
MooLang *lang)
|
||||
@ -1984,264 +1944,3 @@ moo_edit_ui_set_show_line_numbers (MooEdit *doc,
|
||||
"show-line-numbers", show,
|
||||
(char*) NULL);
|
||||
}
|
||||
|
||||
|
||||
static struct {
|
||||
char *working_dir;
|
||||
char *encodings_dir;
|
||||
} test_data;
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define LE "\r\n"
|
||||
#else
|
||||
#define LE "\n"
|
||||
#endif
|
||||
|
||||
#define TT1 "blah blah blah"
|
||||
#define TT2 "blah blah blah" LE "blah blah blah"
|
||||
#define TT3 LE LE LE LE
|
||||
#define TT4 "lala\nlala\n"
|
||||
#define TT5 "lala\r\nlala\r\n"
|
||||
#define TT6 "lala\rlala\r"
|
||||
|
||||
static void
|
||||
check_contents (const char *filename,
|
||||
const char *expected)
|
||||
{
|
||||
char *contents;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_file_get_contents (filename, &contents, NULL, &error))
|
||||
{
|
||||
TEST_FAILED_MSG ("could not load file '%s': %s",
|
||||
filename, error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
TEST_ASSERT_STR_EQ (contents, expected);
|
||||
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
static void
|
||||
test_basic (void)
|
||||
{
|
||||
MooEditor *editor;
|
||||
MooEdit *doc, *doc2;
|
||||
GtkTextBuffer *buffer;
|
||||
char *filename;
|
||||
|
||||
editor = moo_editor_instance ();
|
||||
filename = g_build_filename (test_data.working_dir, "test.txt", NULL);
|
||||
doc = moo_editor_new_file (editor, NULL, NULL, filename, NULL);
|
||||
TEST_ASSERT (doc != NULL);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, "");
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (doc));
|
||||
|
||||
gtk_text_buffer_set_text (buffer, TT1, -1);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT1);
|
||||
|
||||
gtk_text_buffer_set_text (buffer, TT2, -1);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT2);
|
||||
|
||||
gtk_text_buffer_set_text (buffer, TT2 LE, -1);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT2 LE);
|
||||
|
||||
gtk_text_buffer_set_text (buffer, TT3, -1);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT3);
|
||||
|
||||
doc2 = moo_editor_open_file (editor, NULL, NULL, filename, NULL);
|
||||
TEST_ASSERT (doc2 == doc);
|
||||
|
||||
TEST_ASSERT (moo_edit_close (doc, TRUE));
|
||||
TEST_ASSERT (moo_editor_get_doc (editor, filename) == NULL);
|
||||
|
||||
g_file_set_contents (filename, TT4, -1, NULL);
|
||||
doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL);
|
||||
TEST_ASSERT (doc != NULL);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT4);
|
||||
TEST_ASSERT (moo_edit_close (doc, TRUE));
|
||||
|
||||
g_file_set_contents (filename, TT5, -1, NULL);
|
||||
doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL);
|
||||
TEST_ASSERT (doc != NULL);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT5);
|
||||
TEST_ASSERT (moo_edit_close (doc, TRUE));
|
||||
|
||||
g_file_set_contents (filename, TT6, -1, NULL);
|
||||
doc = moo_editor_open_file (editor, NULL, NULL, filename, NULL);
|
||||
TEST_ASSERT (doc != NULL);
|
||||
TEST_ASSERT (moo_edit_save (doc, NULL));
|
||||
check_contents (filename, TT6);
|
||||
TEST_ASSERT (moo_edit_close (doc, TRUE));
|
||||
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
#define TEST_ASSERT_SAME_FILE_CONTENT(filename1, filename2) \
|
||||
{ \
|
||||
char *contents1__ = NULL; \
|
||||
char *contents2__ = NULL; \
|
||||
g_file_get_contents (filename1, &contents1__, NULL, NULL); \
|
||||
g_file_get_contents (filename2, &contents2__, NULL, NULL); \
|
||||
if (!contents1__) \
|
||||
moo_test_assert_msg (FALSE, __FILE__, __LINE__, \
|
||||
"could not open file %s", \
|
||||
filename1); \
|
||||
if (!contents2__) \
|
||||
moo_test_assert_msg (FALSE, __FILE__, __LINE__, \
|
||||
"could not open file %s", \
|
||||
filename2); \
|
||||
if (contents1__ && contents2__) \
|
||||
{ \
|
||||
gboolean equal = strcmp (contents1__, contents2__) == 0; \
|
||||
TEST_ASSERT_MSG (equal, "contents of %s and %s differ", \
|
||||
filename1, filename2); \
|
||||
} \
|
||||
g_free (contents2__); \
|
||||
g_free (contents1__); \
|
||||
}
|
||||
|
||||
static void
|
||||
test_encodings_1 (const char *name,
|
||||
const char *working_dir)
|
||||
{
|
||||
char *filename;
|
||||
char *filename2;
|
||||
char *encoding;
|
||||
const char *dot;
|
||||
MooEditor *editor;
|
||||
MooEdit *doc;
|
||||
|
||||
if ((dot = strchr (name, '.')))
|
||||
encoding = g_strndup (name, dot - name);
|
||||
else
|
||||
encoding = g_strdup (name);
|
||||
|
||||
filename = g_build_filename (test_data.encodings_dir, name, (char*)0);
|
||||
filename2 = g_build_filename (working_dir, name, (char*)0);
|
||||
|
||||
editor = moo_editor_instance ();
|
||||
doc = moo_editor_open_file (editor, NULL, NULL, filename, encoding);
|
||||
TEST_ASSERT_MSG (doc != NULL,
|
||||
"file '%s', encoding '%s'",
|
||||
TEST_FMT_STR (filename),
|
||||
TEST_FMT_STR (encoding));
|
||||
|
||||
if (doc)
|
||||
{
|
||||
TEST_ASSERT (moo_edit_save_as (doc, filename2, NULL, NULL));
|
||||
TEST_ASSERT_SAME_FILE_CONTENT (filename2, filename);
|
||||
TEST_ASSERT (moo_edit_close (doc, TRUE));
|
||||
}
|
||||
|
||||
g_free (encoding);
|
||||
g_free (filename2);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
static void
|
||||
test_encodings (void)
|
||||
{
|
||||
GDir *dir;
|
||||
const char *name;
|
||||
char *working_dir;
|
||||
|
||||
dir = g_dir_open (test_data.encodings_dir, 0, NULL);
|
||||
|
||||
if (!dir)
|
||||
{
|
||||
g_critical ("could not open encodings dir");
|
||||
TEST_ASSERT (FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
working_dir = g_build_filename (test_data.working_dir, "encodings", (char*)0);
|
||||
_moo_mkdir_with_parents (working_dir);
|
||||
|
||||
while ((name = g_dir_read_name (dir)))
|
||||
test_encodings_1 (name, working_dir);
|
||||
|
||||
g_free (working_dir);
|
||||
g_dir_close (dir);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
test_suite_init (G_GNUC_UNUSED gpointer data)
|
||||
{
|
||||
test_data.working_dir = g_build_filename (moo_test_get_working_dir (),
|
||||
"editor-work", (char*)0);
|
||||
test_data.encodings_dir = g_build_filename (moo_test_get_data_dir (),
|
||||
"encodings", (char*)0);
|
||||
|
||||
if (_moo_mkdir_with_parents (test_data.working_dir) != 0)
|
||||
{
|
||||
g_critical ("could not create directory '%s'",
|
||||
test_data.working_dir);
|
||||
g_free (test_data.working_dir);
|
||||
test_data.working_dir = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_suite_cleanup (G_GNUC_UNUSED gpointer data)
|
||||
{
|
||||
char *recent_file;
|
||||
MooEditor *editor;
|
||||
GError *error = NULL;
|
||||
|
||||
if (!_moo_remove_dir (test_data.working_dir, TRUE, &error))
|
||||
{
|
||||
g_critical ("could not remove directory '%s': %s",
|
||||
test_data.working_dir, error->message);
|
||||
g_error_free (error);
|
||||
error = NULL;
|
||||
}
|
||||
|
||||
g_free (test_data.working_dir);
|
||||
g_free (test_data.encodings_dir);
|
||||
test_data.working_dir = NULL;
|
||||
test_data.encodings_dir = NULL;
|
||||
|
||||
editor = moo_editor_instance ();
|
||||
// moo_editor_close_all (editor, FALSE, FALSE);
|
||||
recent_file = _md_history_mgr_get_filename (_moo_editor_get_history_mgr (editor));
|
||||
|
||||
if (!g_file_test (recent_file, G_FILE_TEST_EXISTS))
|
||||
g_critical ("recent file %s does not exist", recent_file);
|
||||
|
||||
// cache_dir = moo_get_user_cache_dir ();
|
||||
// if (!_moo_remove_dir (cache_dir, TRUE, &error))
|
||||
// {
|
||||
// g_critical ("could not remove directory '%s': %s",
|
||||
// cache_dir, error->message);
|
||||
// g_error_free (error);
|
||||
// error = NULL;
|
||||
// }
|
||||
|
||||
g_free (recent_file);
|
||||
}
|
||||
|
||||
void
|
||||
moo_test_editor (void)
|
||||
{
|
||||
MooTestSuite *suite = moo_test_suite_new ("Editor",
|
||||
"Editor tests",
|
||||
test_suite_init,
|
||||
test_suite_cleanup,
|
||||
NULL);
|
||||
moo_test_suite_add_test (suite, "basic", "basic editor functionality", (MooTestFunc) test_basic, NULL);
|
||||
moo_test_suite_add_test (suite, "encodings", "character encoding handling", (MooTestFunc) test_encodings, NULL);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <mooedit/mootextview.h>
|
||||
#include <mooedit/mooeditconfig.h>
|
||||
#include <mooedit/mooedit-enums.h>
|
||||
#include <mooedit/mooedittypes.h>
|
||||
#include <mooutils/mooprefs.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@ -37,7 +38,6 @@ G_BEGIN_DECLS
|
||||
#define MOO_EDIT_IS_CLEAN(edit) (moo_edit_get_status (edit) & MOO_EDIT_CLEAN)
|
||||
#define MOO_EDIT_IS_BUSY(edit) (moo_edit_get_state (edit) != MOO_EDIT_STATE_NORMAL)
|
||||
|
||||
typedef struct MooEdit MooEdit;
|
||||
typedef struct MooEditPrivate MooEditPrivate;
|
||||
typedef struct MooEditClass MooEditClass;
|
||||
|
||||
@ -73,6 +73,10 @@ struct MooEditClass
|
||||
GType moo_edit_get_type (void) G_GNUC_CONST;
|
||||
GType moo_edit_file_info_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooEditWindow *moo_edit_get_window (MooEdit *edit);
|
||||
|
||||
GFile *moo_edit_get_file (MooEdit *edit);
|
||||
|
||||
char *moo_edit_get_uri (MooEdit *edit);
|
||||
char *moo_edit_get_filename (MooEdit *edit);
|
||||
char *moo_edit_get_norm_filename (MooEdit *edit);
|
||||
@ -85,6 +89,10 @@ void moo_edit_set_encoding (MooEdit *edit,
|
||||
|
||||
char *moo_edit_get_utf8_filename (MooEdit *edit);
|
||||
|
||||
MooLang *moo_edit_get_lang (MooEdit *edit);
|
||||
|
||||
MooEditor *moo_edit_get_editor (MooEdit *doc);
|
||||
|
||||
#ifdef __WIN32__
|
||||
#define MOO_LE_DEFAULT MOO_LE_WIN32
|
||||
#else
|
||||
@ -125,14 +133,6 @@ gboolean moo_edit_save_copy (MooEdit *edit,
|
||||
void moo_edit_comment (MooEdit *edit);
|
||||
void moo_edit_uncomment (MooEdit *edit);
|
||||
|
||||
typedef struct MooEditFileInfo MooEditFileInfo;
|
||||
MooEditFileInfo *moo_edit_file_info_new_path (const char *path,
|
||||
const char *encoding);
|
||||
MooEditFileInfo *moo_edit_file_info_new_uri (const char *uri,
|
||||
const char *encoding);
|
||||
MooEditFileInfo *moo_edit_file_info_copy (MooEditFileInfo *info);
|
||||
void moo_edit_file_info_free (MooEditFileInfo *info);
|
||||
|
||||
void moo_edit_ui_set_line_wrap_mode (MooEdit *edit,
|
||||
gboolean enabled);
|
||||
void moo_edit_ui_set_show_line_numbers (MooEdit *edit,
|
||||
|
@ -54,9 +54,6 @@ GType moo_edit_action_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooEdit *moo_edit_action_get_doc (MooEditAction *action);
|
||||
|
||||
/* defined in mooeditwindow.c */
|
||||
GSList *_moo_edit_parse_langs (const char *string);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit/mooedit-bookmarks.h"
|
||||
#include "mooedit/mooeditbookmark.h"
|
||||
#include "mooedit/mooedit-private.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooutils/moostock.h"
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* mooedit-bookmarks.h
|
||||
* mooeditbookmark.h
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef MOO_EDIT_BOOKMARKS_H
|
||||
#define MOO_EDIT_BOOKMARKS_H
|
||||
#ifndef MOO_EDIT_BOOKMARK_H
|
||||
#define MOO_EDIT_BOOKMARK_H
|
||||
|
||||
#include <mooedit/mooedit.h>
|
||||
#include <mooedit/moolinemark.h>
|
||||
@ -74,4 +74,4 @@ char *_moo_edit_bookmark_get_text (MooEditBookmark *bookmark);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_BOOKMARKS_H */
|
||||
#endif /* MOO_EDIT_BOOKMARK_H */
|
@ -105,7 +105,7 @@ moo_edit_config_init (MooEditConfig *config)
|
||||
|
||||
config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, MOO_TYPE_EDIT_CONFIG, MooEditConfigPrivate);
|
||||
|
||||
MOO_IP_ARRAY_INIT (config->priv, values, vars->len);
|
||||
MOO_IP_ARRAY_INIT (Value, config->priv, values, vars->len);
|
||||
|
||||
if (global)
|
||||
{
|
||||
@ -231,7 +231,7 @@ update_prop_from_global (MooEditConfig *config,
|
||||
|
||||
if (prop_id == config->priv->n_values)
|
||||
{
|
||||
MOO_IP_ARRAY_GROW (config->priv, values, 1);
|
||||
MOO_IP_ARRAY_GROW (Value, config->priv, values, 1);
|
||||
g_value_init (GVALUE (config, prop_id),
|
||||
G_VALUE_TYPE (GVALUE (global, prop_id)));
|
||||
VALUE (config, prop_id)->source = VALUE (global, prop_id)->source;
|
||||
@ -270,7 +270,7 @@ global_add_prop (GParamSpec *pspec,
|
||||
{
|
||||
g_assert (global->priv->n_values == prop_id);
|
||||
|
||||
MOO_IP_ARRAY_GROW (global->priv, values, 1);
|
||||
MOO_IP_ARRAY_GROW (Value, global->priv, values, 1);
|
||||
|
||||
g_value_init (GVALUE (global, prop_id), G_PARAM_SPEC_VALUE_TYPE (pspec));
|
||||
g_param_value_set_default (pspec, GVALUE (global, prop_id));
|
||||
|
@ -17,10 +17,12 @@
|
||||
#include "mooedit/mooeditdialogs.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/mooedit-fileops.h"
|
||||
#include "mooedit/moofileenc.h"
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/mooi18n.h"
|
||||
#include "mooutils/mooencodings.h"
|
||||
#include "mooutils/mooutils.h"
|
||||
#include "mootextfind-prompt-gxml.h"
|
||||
#include "mooeditsavemult-gxml.h"
|
||||
#include <gtk/gtk.h>
|
||||
@ -28,37 +30,34 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
GSList *
|
||||
MooFileEncArray *
|
||||
_moo_edit_open_dialog (GtkWidget *widget,
|
||||
MooEdit *current_doc)
|
||||
{
|
||||
MooFileDialog *dialog;
|
||||
const char *start_dir = NULL;
|
||||
const char *encoding;
|
||||
char *new_start;
|
||||
char *freeme = NULL;
|
||||
char **filenames = NULL, **p;
|
||||
GSList *infos = NULL;
|
||||
GFile *start = NULL;
|
||||
MooFileArray *files = NULL;
|
||||
MooFileEncArray *fencs = NULL;
|
||||
guint i;
|
||||
|
||||
moo_prefs_create_key (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), MOO_PREFS_STATE, G_TYPE_STRING, NULL);
|
||||
|
||||
if (current_doc && moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
|
||||
{
|
||||
char *filename = moo_edit_get_filename (current_doc);
|
||||
GFile *file = moo_edit_get_file (current_doc);
|
||||
|
||||
if (filename)
|
||||
{
|
||||
freeme = g_path_get_dirname (filename);
|
||||
start_dir = freeme;
|
||||
g_free (filename);
|
||||
}
|
||||
if (file)
|
||||
start = g_file_get_parent (file);
|
||||
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
if (!start_dir)
|
||||
start_dir = moo_prefs_get_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR));
|
||||
if (!start)
|
||||
start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR));
|
||||
|
||||
dialog = moo_file_dialog_new (MOO_FILE_DIALOG_OPEN, widget,
|
||||
TRUE, GTK_STOCK_OPEN, start_dir,
|
||||
TRUE, GTK_STOCK_OPEN, start,
|
||||
NULL);
|
||||
g_object_set (dialog, "enable-encodings", TRUE, NULL);
|
||||
moo_file_dialog_set_help_id (dialog, "dialog-open");
|
||||
@ -66,67 +65,64 @@ _moo_edit_open_dialog (GtkWidget *widget,
|
||||
|
||||
moo_file_dialog_set_filter_mgr_id (dialog, "MooEdit");
|
||||
|
||||
if (!moo_file_dialog_run (dialog))
|
||||
goto out;
|
||||
if (moo_file_dialog_run (dialog))
|
||||
{
|
||||
encoding = moo_file_dialog_get_encoding (dialog);
|
||||
|
||||
encoding = moo_file_dialog_get_encoding (dialog);
|
||||
if (encoding && !strcmp (encoding, MOO_ENCODING_AUTO))
|
||||
encoding = NULL;
|
||||
|
||||
if (encoding && !strcmp (encoding, MOO_ENCODING_AUTO))
|
||||
encoding = NULL;
|
||||
files = moo_file_dialog_get_files (dialog);
|
||||
g_return_val_if_fail (files != NULL && files->n_elms != 0, NULL);
|
||||
|
||||
filenames = moo_file_dialog_get_filenames (dialog);
|
||||
g_return_val_if_fail (filenames != NULL, NULL);
|
||||
fencs = moo_file_enc_array_new ();
|
||||
for (i = 0; i < files->n_elms; ++i)
|
||||
moo_file_enc_array_take (fencs, moo_file_enc_new (files->elms[i], encoding));
|
||||
|
||||
for (p = filenames; *p != NULL; ++p)
|
||||
infos = g_slist_prepend (infos, moo_edit_file_info_new_path (*p, encoding));
|
||||
infos = g_slist_reverse (infos);
|
||||
g_object_unref (start);
|
||||
start = g_file_get_parent (files->elms[0]);
|
||||
moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start);
|
||||
}
|
||||
|
||||
new_start = g_path_get_dirname (filenames[0]);
|
||||
moo_prefs_set_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), new_start);
|
||||
g_free (new_start);
|
||||
|
||||
out:
|
||||
g_free (freeme);
|
||||
g_object_unref (start);
|
||||
g_object_unref (dialog);
|
||||
g_strfreev (filenames);
|
||||
return infos;
|
||||
moo_file_array_free (files);
|
||||
return fencs;
|
||||
}
|
||||
|
||||
|
||||
MooEditFileInfo *
|
||||
_moo_edit_save_as_dialog (MooEdit *edit,
|
||||
MooFileEnc *
|
||||
_moo_edit_save_as_dialog (MooEdit *doc,
|
||||
const char *display_basename)
|
||||
{
|
||||
const char *start = NULL;
|
||||
char *filename = NULL;
|
||||
char *freeme = NULL;
|
||||
const char *encoding;
|
||||
char *new_start;
|
||||
MooFileDialog *dialog;
|
||||
MooEditFileInfo *file_info;
|
||||
MooFileEnc *fenc;
|
||||
GFile *start = NULL;
|
||||
GFile *file = NULL;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
|
||||
moo_prefs_create_key (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR),
|
||||
MOO_PREFS_STATE, G_TYPE_STRING, NULL);
|
||||
|
||||
if (moo_prefs_get_bool (moo_edit_setting (MOO_EDIT_PREFS_DIALOGS_OPEN_FOLLOWS_DOC)))
|
||||
{
|
||||
char *this_filename = moo_edit_get_filename (edit);
|
||||
|
||||
if (this_filename)
|
||||
{
|
||||
freeme = g_path_get_dirname (this_filename);
|
||||
start = freeme;
|
||||
g_free (this_filename);
|
||||
}
|
||||
file = moo_edit_get_file (doc);
|
||||
if (file)
|
||||
start = g_file_get_parent (file);
|
||||
g_object_unref (file);
|
||||
file = NULL;
|
||||
}
|
||||
|
||||
if (!start)
|
||||
start = moo_prefs_get_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR));
|
||||
start = moo_prefs_get_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR));
|
||||
|
||||
dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE, GTK_WIDGET (edit),
|
||||
FALSE, GTK_STOCK_SAVE_AS, start, display_basename);
|
||||
dialog = moo_file_dialog_new (MOO_FILE_DIALOG_SAVE, GTK_WIDGET (doc),
|
||||
FALSE, GTK_STOCK_SAVE_AS,
|
||||
start, display_basename);
|
||||
g_object_set (dialog, "enable-encodings", TRUE, NULL);
|
||||
moo_file_dialog_set_encoding (dialog, moo_edit_get_encoding (edit));
|
||||
moo_file_dialog_set_encoding (dialog, moo_edit_get_encoding (doc));
|
||||
moo_file_dialog_set_help_id (dialog, "dialog-save");
|
||||
|
||||
moo_file_dialog_set_filter_mgr_id (dialog, "MooEdit");
|
||||
@ -134,32 +130,32 @@ _moo_edit_save_as_dialog (MooEdit *edit,
|
||||
if (!moo_file_dialog_run (dialog))
|
||||
{
|
||||
g_object_unref (dialog);
|
||||
g_free (freeme);
|
||||
g_object_unref (start);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
encoding = moo_file_dialog_get_encoding (dialog);
|
||||
filename = moo_file_dialog_get_filename (dialog);
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
file_info = moo_edit_file_info_new_path (filename, encoding);
|
||||
file = moo_file_dialog_get_file (dialog);
|
||||
g_return_val_if_fail (file != NULL, NULL);
|
||||
fenc = moo_file_enc_new (file, encoding);
|
||||
|
||||
new_start = g_path_get_dirname (filename);
|
||||
moo_prefs_set_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), new_start);
|
||||
g_free (new_start);
|
||||
g_object_unref (start);
|
||||
start = g_file_get_parent (file);
|
||||
moo_prefs_set_file (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), start);
|
||||
|
||||
g_free (filename);
|
||||
g_object_unref (start);
|
||||
g_object_unref (file);
|
||||
g_object_unref (dialog);
|
||||
g_free (freeme);
|
||||
return file_info;
|
||||
return fenc;
|
||||
}
|
||||
|
||||
|
||||
MooSaveChangesDialogResponse
|
||||
_moo_edit_save_changes_dialog (MooEdit *edit)
|
||||
_moo_edit_save_changes_dialog (MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
return moo_save_changes_dialog (moo_edit_get_display_basename (edit),
|
||||
GTK_WIDGET (edit));
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
return moo_save_changes_dialog (moo_edit_get_display_basename (doc),
|
||||
GTK_WIDGET (doc));
|
||||
}
|
||||
|
||||
|
||||
@ -179,13 +175,13 @@ name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *column,
|
||||
GtkTreeModel *model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
MooEdit *edit = NULL;
|
||||
MooEdit *doc = NULL;
|
||||
|
||||
gtk_tree_model_get (model, iter, COLUMN_EDIT, &edit, -1);
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
gtk_tree_model_get (model, iter, COLUMN_EDIT, &doc, -1);
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
g_object_set (cell, "text", moo_edit_get_display_basename (edit), NULL);
|
||||
g_object_unref (edit);
|
||||
g_object_set (cell, "text", moo_edit_get_display_basename (doc), NULL);
|
||||
g_object_unref (doc);
|
||||
}
|
||||
|
||||
|
||||
@ -244,22 +240,23 @@ save_toggled (GtkCellRendererToggle *cell,
|
||||
}
|
||||
|
||||
static void
|
||||
files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, GSList *docs)
|
||||
files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, MooEditArray *docs)
|
||||
{
|
||||
GtkListStore *store;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkCellRenderer *cell;
|
||||
GSList *l;
|
||||
guint i;
|
||||
|
||||
store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_BOOLEAN, MOO_TYPE_EDIT);
|
||||
|
||||
for (l = docs; l != NULL; l = l->next)
|
||||
for (i = 0; i < docs->n_elms; ++i)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gtk_list_store_append (store, &iter);
|
||||
gtk_list_store_set (store, &iter,
|
||||
COLUMN_SAVE, TRUE,
|
||||
COLUMN_EDIT, l->data, -1);
|
||||
COLUMN_EDIT, docs->elms[i],
|
||||
-1);
|
||||
}
|
||||
|
||||
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (store));
|
||||
@ -286,36 +283,34 @@ files_treeview_init (GtkTreeView *treeview, GtkWidget *dialog, GSList *docs)
|
||||
}
|
||||
|
||||
|
||||
static GSList *
|
||||
files_treeview_get_to_save (GtkTreeView *treeview)
|
||||
static void
|
||||
files_treeview_get_to_save (GtkTreeView *treeview,
|
||||
MooEditArray *to_save)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model;
|
||||
GSList *list = NULL;
|
||||
|
||||
model = gtk_tree_view_get_model (treeview);
|
||||
g_return_val_if_fail (model != NULL, NULL);
|
||||
g_return_if_fail (model != NULL);
|
||||
|
||||
gtk_tree_model_get_iter_first (model, &iter);
|
||||
|
||||
do
|
||||
{
|
||||
MooEdit *edit = NULL;
|
||||
MooEdit *doc = NULL;
|
||||
gboolean save = TRUE;
|
||||
|
||||
gtk_tree_model_get (model, &iter,
|
||||
COLUMN_SAVE, &save,
|
||||
COLUMN_EDIT, &edit, -1);
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), list);
|
||||
COLUMN_EDIT, &doc, -1);
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
if (save)
|
||||
list = g_slist_prepend (list, edit);
|
||||
moo_edit_array_append (to_save, doc);
|
||||
|
||||
g_object_unref (edit);
|
||||
g_object_unref (doc);
|
||||
}
|
||||
while (gtk_tree_model_iter_next (model, &iter));
|
||||
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
|
||||
@ -341,27 +336,22 @@ find_widget_for_response (GtkDialog *dialog,
|
||||
}
|
||||
|
||||
MooSaveChangesDialogResponse
|
||||
_moo_edit_save_multiple_changes_dialog (GSList *docs,
|
||||
GSList **to_save)
|
||||
_moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
||||
MooEditArray *to_save)
|
||||
{
|
||||
GSList *l;
|
||||
GtkWidget *dialog;
|
||||
char *msg, *question;
|
||||
int response;
|
||||
MooSaveChangesDialogResponse retval;
|
||||
SaveMultDialogXml *xml;
|
||||
|
||||
g_return_val_if_fail (docs != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
g_return_val_if_fail (docs->next != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
g_return_val_if_fail (docs != NULL && docs->n_elms > 1, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
g_return_val_if_fail (to_save != NULL, MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
|
||||
for (l = docs; l != NULL; l = l->next)
|
||||
g_return_val_if_fail (MOO_IS_EDIT (l->data), MOO_SAVE_CHANGES_RESPONSE_CANCEL);
|
||||
|
||||
xml = save_mult_dialog_xml_new ();
|
||||
dialog = GTK_WIDGET (xml->SaveMultDialog);
|
||||
|
||||
moo_window_set_parent (dialog, docs->data);
|
||||
moo_window_set_parent (dialog, GTK_WIDGET (docs->elms[0]));
|
||||
|
||||
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
|
||||
MOO_STOCK_SAVE_NONE, GTK_RESPONSE_NO,
|
||||
@ -383,8 +373,8 @@ _moo_edit_save_multiple_changes_dialog (GSList *docs,
|
||||
"Save changes before closing?",
|
||||
"There are %u documents with unsaved changes. "
|
||||
"Save changes before closing?",
|
||||
g_slist_length (docs)),
|
||||
g_slist_length (docs));
|
||||
docs->n_elms),
|
||||
(guint) docs->n_elms);
|
||||
msg = g_markup_printf_escaped ("<span weight=\"bold\" size=\"larger\">%s</span>",
|
||||
question);
|
||||
gtk_label_set_markup (xml->label, msg);
|
||||
@ -405,7 +395,7 @@ _moo_edit_save_multiple_changes_dialog (GSList *docs,
|
||||
retval = MOO_SAVE_CHANGES_RESPONSE_DONT_SAVE;
|
||||
break;
|
||||
case GTK_RESPONSE_YES:
|
||||
*to_save = files_treeview_get_to_save (xml->treeview);
|
||||
files_treeview_get_to_save (xml->treeview, to_save);
|
||||
retval = MOO_SAVE_CHANGES_RESPONSE_SAVE;
|
||||
break;
|
||||
default:
|
||||
@ -430,7 +420,7 @@ _moo_edit_save_error_dialog (GtkWidget *widget,
|
||||
{
|
||||
char *filename, *msg = NULL;
|
||||
|
||||
filename = _moo_file_get_display_name (file);
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
if (filename)
|
||||
/* Could not save file foo.txt */
|
||||
@ -454,7 +444,7 @@ _moo_edit_save_error_enc_dialog (GtkWidget *widget,
|
||||
|
||||
g_return_if_fail (encoding != NULL);
|
||||
|
||||
filename = _moo_file_get_display_name (file);
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
if (filename)
|
||||
/* Error saving file foo.txt */
|
||||
@ -483,7 +473,7 @@ _moo_edit_open_error_dialog (GtkWidget *widget,
|
||||
char *filename, *msg = NULL;
|
||||
char *secondary;
|
||||
|
||||
filename = _moo_file_get_display_name (file);
|
||||
filename = moo_file_get_display_name (file);
|
||||
|
||||
if (filename)
|
||||
/* Could not open file foo.txt */
|
||||
@ -529,14 +519,15 @@ _moo_edit_reload_error_dialog (MooEdit *doc,
|
||||
|
||||
if (!filename)
|
||||
{
|
||||
g_critical ("%s: oops", G_STRLOC);
|
||||
moo_critical ("oops");
|
||||
filename = "";
|
||||
}
|
||||
|
||||
/* Could not reload file foo.txt */
|
||||
msg = g_strdup_printf (_("Could not reload file\n%s"), filename);
|
||||
/* XXX */
|
||||
moo_error_dialog (GTK_WIDGET (doc), msg, error ? error->message : NULL);
|
||||
moo_error_dialog (GTK_WIDGET (doc),
|
||||
msg, error ? error->message : NULL);
|
||||
|
||||
g_free (msg);
|
||||
}
|
||||
@ -547,13 +538,13 @@ _moo_edit_reload_error_dialog (MooEdit *doc,
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
moo_edit_question_dialog (MooEdit *edit,
|
||||
moo_edit_question_dialog (MooEdit *doc,
|
||||
const char *text,
|
||||
const char *secondary,
|
||||
const char *button)
|
||||
{
|
||||
int res;
|
||||
GtkWindow *parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (edit)));
|
||||
GtkWindow *parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (doc)));
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
|
||||
@ -580,22 +571,22 @@ moo_edit_question_dialog (MooEdit *edit,
|
||||
}
|
||||
|
||||
gboolean
|
||||
_moo_edit_reload_modified_dialog (MooEdit *edit)
|
||||
_moo_edit_reload_modified_dialog (MooEdit *doc)
|
||||
{
|
||||
const char *name;
|
||||
char *question;
|
||||
gboolean result;
|
||||
|
||||
name = moo_edit_get_display_basename (edit);
|
||||
name = moo_edit_get_display_basename (doc);
|
||||
|
||||
if (!name)
|
||||
{
|
||||
g_critical ("%s: oops", G_STRLOC);
|
||||
moo_critical ("oops");
|
||||
name = "";
|
||||
}
|
||||
|
||||
question = g_strdup_printf (_("Discard changes in file '%s'?"), name);
|
||||
result = moo_edit_question_dialog (edit, question,
|
||||
result = moo_edit_question_dialog (doc, question,
|
||||
_("If you reload the document, changes will be discarded"),
|
||||
_("_Reload"));
|
||||
|
||||
@ -604,24 +595,24 @@ _moo_edit_reload_modified_dialog (MooEdit *edit)
|
||||
}
|
||||
|
||||
gboolean
|
||||
_moo_edit_overwrite_modified_dialog (MooEdit *edit)
|
||||
_moo_edit_overwrite_modified_dialog (MooEdit *doc)
|
||||
{
|
||||
const char *name;
|
||||
char *question, *secondary;
|
||||
gboolean result;
|
||||
|
||||
name = moo_edit_get_display_basename (edit);
|
||||
name = moo_edit_get_display_basename (doc);
|
||||
|
||||
if (!name)
|
||||
{
|
||||
g_critical ("%s: oops", G_STRLOC);
|
||||
moo_critical ("%s: oops", G_STRLOC);
|
||||
name = "";
|
||||
}
|
||||
|
||||
question = g_strdup_printf (_("Overwrite modified file '%s'?"), name);
|
||||
secondary = g_strdup_printf (_("File '%s' was modified on disk by another process. If you save it, "
|
||||
"changes on disk will be lost."), name);
|
||||
result = moo_edit_question_dialog (edit, question, secondary, _("Over_write"));
|
||||
result = moo_edit_question_dialog (doc, question, secondary, _("Over_write"));
|
||||
|
||||
g_free (question);
|
||||
g_free (secondary);
|
||||
|
@ -17,25 +17,25 @@
|
||||
#define MOO_EDIT_DIALOGS_H
|
||||
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooedit/mooedit.h"
|
||||
#include "mooedit/mooedittypes.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
MooEditFileInfo *_moo_edit_save_as_dialog (MooEdit *edit,
|
||||
MooFileEnc *_moo_edit_save_as_dialog (MooEdit *doc,
|
||||
const char *display_basename);
|
||||
GSList *_moo_edit_open_dialog (GtkWidget *widget,
|
||||
MooFileEncArray *_moo_edit_open_dialog (GtkWidget *widget,
|
||||
MooEdit *current_doc);
|
||||
|
||||
MooSaveChangesDialogResponse
|
||||
_moo_edit_save_changes_dialog (MooEdit *edit);
|
||||
_moo_edit_save_changes_dialog (MooEdit *doc);
|
||||
MooSaveChangesDialogResponse
|
||||
_moo_edit_save_multiple_changes_dialog (GSList *docs,
|
||||
GSList **to_save);
|
||||
_moo_edit_save_multiple_changes_dialog (MooEditArray *docs,
|
||||
MooEditArray *to_save);
|
||||
|
||||
gboolean _moo_edit_reload_modified_dialog (MooEdit *edit);
|
||||
gboolean _moo_edit_overwrite_modified_dialog (MooEdit *edit);
|
||||
gboolean _moo_edit_reload_modified_dialog (MooEdit *doc);
|
||||
gboolean _moo_edit_overwrite_modified_dialog (MooEdit *doc);
|
||||
|
||||
void _moo_edit_save_error_dialog (GtkWidget *widget,
|
||||
GFile *file,
|
||||
|
@ -17,13 +17,14 @@
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/mooeditaction.h"
|
||||
#include "mooedit/moolang.h"
|
||||
#include "mooedit/mooeditconfig.h"
|
||||
#include "mooedit/mooedit.h"
|
||||
#include "mooutils/mooprefs.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-debug.h"
|
||||
#include <glib/gregex.h>
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
|
||||
MOO_DEBUG_INIT(filters, FALSE)
|
||||
|
||||
@ -133,6 +134,32 @@ _moo_edit_filter_new (const char *string)
|
||||
return _moo_edit_filter_new_full (string, FALSE);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
_moo_edit_parse_langs (const char *string)
|
||||
{
|
||||
char **pieces, **p;
|
||||
GSList *list = NULL;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
pieces = g_strsplit_set (string, " \t\r\n;,", 0);
|
||||
|
||||
if (!pieces)
|
||||
return NULL;
|
||||
|
||||
for (p = pieces; *p != NULL; ++p)
|
||||
{
|
||||
g_strstrip (*p);
|
||||
|
||||
if (**p)
|
||||
list = g_slist_prepend (list, _moo_lang_id_from_name (*p));
|
||||
}
|
||||
|
||||
g_strfreev (pieces);
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
MooEditFilter *
|
||||
_moo_edit_filter_new_langs (const char *string)
|
||||
{
|
||||
@ -244,37 +271,21 @@ static gboolean
|
||||
moo_edit_filter_check_globs (GSList *globs,
|
||||
MooEdit *doc)
|
||||
{
|
||||
char *name = NULL;
|
||||
|
||||
name = moo_edit_get_filename (doc);
|
||||
|
||||
if (name)
|
||||
{
|
||||
char *tmp = name;
|
||||
name = g_path_get_basename (tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
GFile *file = moo_edit_get_file (doc);
|
||||
|
||||
while (globs)
|
||||
{
|
||||
if (name)
|
||||
if (!strcmp (globs->data, "*") ||
|
||||
(file && moo_file_fnmatch (file, globs->data)))
|
||||
{
|
||||
if (fnmatch (globs->data, name, 0) == 0)
|
||||
{
|
||||
g_free (name);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!strcmp (globs->data, "*"))
|
||||
return TRUE;
|
||||
g_object_unref (file);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
globs = globs->next;
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
moo_file_free (file);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -282,7 +293,8 @@ static gboolean
|
||||
moo_edit_filter_check_langs (GSList *langs,
|
||||
MooEdit *doc)
|
||||
{
|
||||
const char *lang_id = moo_edit_config_get_string (doc->config, "lang");
|
||||
MooLang *lang = moo_edit_get_lang (doc);
|
||||
const char *lang_id = _moo_lang_id (lang);
|
||||
|
||||
while (lang_id && langs)
|
||||
{
|
||||
|
50
moo/mooedit/mooedithistoryitem.c
Normal file
50
moo/mooedit/mooedithistoryitem.c
Normal 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;
|
||||
}
|
17
moo/mooedit/mooedithistoryitem.h
Normal file
17
moo/mooedit/mooedithistoryitem.h
Normal 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 */
|
42
moo/mooedit/mooeditor-impl.h
Normal file
42
moo/mooedit/mooeditor-impl.h
Normal 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 */
|
@ -13,60 +13,42 @@
|
||||
* 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
|
||||
#define MOO_EDITOR_PRIVATE_H
|
||||
|
||||
#include "mooedit/mooeditor.h"
|
||||
#include "mooutils/mdhistorymgr.h"
|
||||
#include "mooutils/moofilewatch.h"
|
||||
#include "mooedit/mooeditor-impl.h"
|
||||
#include "mooedit/moolangmgr.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
OPEN_SINGLE = 1 << 0,
|
||||
ALLOW_EMPTY_WINDOW = 1 << 1,
|
||||
SINGLE_WINDOW = 1 << 2,
|
||||
SAVE_BACKUPS = 1 << 3,
|
||||
STRIP_WHITESPACE = 1 << 4,
|
||||
EMBEDDED = 1 << 5
|
||||
} MooEditorOptions;
|
||||
|
||||
MdHistoryMgr *_moo_editor_get_history_mgr (MooEditor *editor);
|
||||
struct MooEditorPrivate {
|
||||
MooEditArray *windowless;
|
||||
MooEditWindowArray *windows;
|
||||
MooUiXml *doc_ui_xml;
|
||||
MooUiXml *ui_xml;
|
||||
MdHistoryMgr *history;
|
||||
MooFileWatch *file_watch;
|
||||
MooEditorOptions opts;
|
||||
|
||||
void _moo_edit_window_insert_doc (MooEditWindow *window,
|
||||
MooEdit *doc,
|
||||
int position);
|
||||
void _moo_edit_window_remove_doc (MooEditWindow *window,
|
||||
MooEdit *doc,
|
||||
gboolean destroy);
|
||||
int _moo_edit_window_get_doc_no (MooEditWindow *window,
|
||||
MooEdit *doc);
|
||||
void _moo_edit_window_update_title (void);
|
||||
void _moo_edit_window_set_use_tabs (void);
|
||||
MooEdit *focused_doc;
|
||||
|
||||
void _moo_editor_set_focused_doc (MooEditor *editor,
|
||||
MooEdit *doc);
|
||||
void _moo_editor_unset_focused_doc (MooEditor *editor,
|
||||
MooEdit *doc);
|
||||
GType window_type;
|
||||
GType doc_type;
|
||||
|
||||
void _moo_editor_move_doc (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
MooEditWindow *dest,
|
||||
gboolean focus);
|
||||
|
||||
MooFileWatch *_moo_editor_get_file_watch (MooEditor *editor);
|
||||
void _moo_editor_reload (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
gboolean _moo_editor_save (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
GError **error);
|
||||
gboolean _moo_editor_save_as (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
void _moo_editor_post_message (MooEditor *editor,
|
||||
GQuark domain,
|
||||
const char *message);
|
||||
MooLangMgr *lang_mgr;
|
||||
char *default_lang;
|
||||
|
||||
guint prefs_idle;
|
||||
};
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
265
moo/mooedit/mooeditor-tests.c
Normal file
265
moo/mooedit/mooeditor-tests.c
Normal 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);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* mooedit-tests.h
|
||||
* mooeditor-tests.h
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef MOO_EDIT_TESTS_H
|
||||
#define MOO_EDIT_TESTS_H
|
||||
#ifndef MOO_EDITOR_TESTS_H
|
||||
#define MOO_EDITOR_TESTS_H
|
||||
|
||||
#include "mooutils/moo-test-macros.h"
|
||||
|
||||
@ -25,4 +25,4 @@ void moo_test_editor (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_EDIT_TESTS_H */
|
||||
#endif /* MOO_EDITOR_TESTS_H */
|
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,7 @@
|
||||
#ifndef MOO_EDITOR_H
|
||||
#define MOO_EDITOR_H
|
||||
|
||||
#include <mooedit/mooedittypes.h>
|
||||
#include <mooedit/mooeditwindow.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_EDITOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_EDITOR, MooEditorClass))
|
||||
|
||||
typedef struct MooEditor MooEditor;
|
||||
typedef struct MooEditorPrivate MooEditorPrivate;
|
||||
typedef struct MooEditorClass MooEditorClass;
|
||||
|
||||
@ -49,104 +49,100 @@ struct MooEditorClass
|
||||
};
|
||||
|
||||
|
||||
GType moo_editor_get_type (void) G_GNUC_CONST;
|
||||
GType moo_editor_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooEditor *moo_editor_instance (void);
|
||||
MooEditor *moo_editor_create_instance (gboolean embedded);
|
||||
MooEditor *moo_editor_instance (void);
|
||||
MooEditor *moo_editor_create (gboolean embedded);
|
||||
|
||||
/* this creates 'windowless' MooEdit instance */
|
||||
MooEdit *moo_editor_create_doc (MooEditor *editor,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
MooEdit *moo_editor_create_doc (MooEditor *editor,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
|
||||
MooEditWindow *moo_editor_new_window (MooEditor *editor);
|
||||
MooEdit *moo_editor_new_doc (MooEditor *editor,
|
||||
MooEditWindow *window);
|
||||
MooEditWindow *moo_editor_new_window (MooEditor *editor);
|
||||
MooEdit *moo_editor_new_doc (MooEditor *editor,
|
||||
MooEditWindow *window);
|
||||
|
||||
gboolean moo_editor_open (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
GSList *files); /* list of MooEditFileInfo* */
|
||||
MooEdit *moo_editor_open_file (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
const char *filename,
|
||||
const char *encoding);
|
||||
MooEdit *moo_editor_open_file_line (MooEditor *editor,
|
||||
const char *filename,
|
||||
int line,
|
||||
MooEditWindow *window);
|
||||
MooEdit *moo_editor_new_file (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
const char *filename,
|
||||
const char *encoding);
|
||||
MooEdit *moo_editor_open_uri (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
const char *uri,
|
||||
const char *encoding);
|
||||
gboolean moo_editor_open (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
MooFileEncArray *files);
|
||||
MooEdit *moo_editor_open_file (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
const char *filename,
|
||||
const char *encoding);
|
||||
MooEdit *moo_editor_open_file_line (MooEditor *editor,
|
||||
const char *filename,
|
||||
int line,
|
||||
MooEditWindow *window);
|
||||
MooEdit *moo_editor_new_file (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
const char *filename,
|
||||
const char *encoding);
|
||||
MooEdit *moo_editor_open_uri (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
GtkWidget *parent,
|
||||
const char *uri,
|
||||
const char *encoding);
|
||||
|
||||
MooEdit *moo_editor_get_doc (MooEditor *editor,
|
||||
const char *filename);
|
||||
MooEdit *moo_editor_get_doc_for_uri (MooEditor *editor,
|
||||
const char *uri);
|
||||
MooEdit *moo_editor_get_doc (MooEditor *editor,
|
||||
const char *filename);
|
||||
MooEdit *moo_editor_get_doc_for_uri (MooEditor *editor,
|
||||
const char *uri);
|
||||
|
||||
MooEdit *moo_editor_get_active_doc (MooEditor *editor);
|
||||
MooEditWindow *moo_editor_get_active_window (MooEditor *editor);
|
||||
MooEdit *moo_editor_get_active_doc (MooEditor *editor);
|
||||
MooEditWindow *moo_editor_get_active_window (MooEditor *editor);
|
||||
|
||||
void moo_editor_set_active_window (MooEditor *editor,
|
||||
MooEditWindow *window);
|
||||
void moo_editor_set_active_doc (MooEditor *editor,
|
||||
MooEdit *doc);
|
||||
void moo_editor_set_active_window (MooEditor *editor,
|
||||
MooEditWindow *window);
|
||||
void moo_editor_set_active_doc (MooEditor *editor,
|
||||
MooEdit *doc);
|
||||
|
||||
void moo_editor_present (MooEditor *editor,
|
||||
guint32 stamp);
|
||||
void moo_editor_present (MooEditor *editor,
|
||||
guint32 stamp);
|
||||
|
||||
/* lists must be freed, content must not be unrefed */
|
||||
GSList *moo_editor_list_windows (MooEditor *editor);
|
||||
GSList *moo_editor_list_docs (MooEditor *editor);
|
||||
MooEditWindowArray *moo_editor_get_windows (MooEditor *editor);
|
||||
MooEditArray *moo_editor_get_docs (MooEditor *editor);
|
||||
|
||||
gboolean moo_editor_close_window (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
gboolean ask_confirm);
|
||||
gboolean moo_editor_close_doc (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
gboolean ask_confirm);
|
||||
gboolean moo_editor_close_docs (MooEditor *editor,
|
||||
GSList *list,
|
||||
gboolean ask_confirm);
|
||||
gboolean moo_editor_close_all (MooEditor *editor,
|
||||
gboolean ask_confirm,
|
||||
gboolean leave_one);
|
||||
gboolean moo_editor_close_window (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
gboolean ask_confirm);
|
||||
gboolean moo_editor_close_doc (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
gboolean ask_confirm);
|
||||
gboolean moo_editor_close_docs (MooEditor *editor,
|
||||
MooEditArray *docs,
|
||||
gboolean ask_confirm);
|
||||
gboolean moo_editor_close_all (MooEditor *editor,
|
||||
gboolean ask_confirm,
|
||||
gboolean leave_one);
|
||||
|
||||
MooUiXml *moo_editor_get_ui_xml (MooEditor *editor);
|
||||
void moo_editor_set_ui_xml (MooEditor *editor,
|
||||
MooUiXml *xml);
|
||||
MooUiXml *moo_editor_get_doc_ui_xml (MooEditor *editor);
|
||||
MooUiXml *moo_editor_get_ui_xml (MooEditor *editor);
|
||||
void moo_editor_set_ui_xml (MooEditor *editor,
|
||||
MooUiXml *xml);
|
||||
MooUiXml *moo_editor_get_doc_ui_xml (MooEditor *editor);
|
||||
|
||||
MooEditor *moo_edit_window_get_editor (MooEditWindow *window);
|
||||
MooEditor *moo_edit_get_editor (MooEdit *doc);
|
||||
void moo_editor_set_window_type (MooEditor *editor,
|
||||
GType type);
|
||||
void moo_editor_set_edit_type (MooEditor *editor,
|
||||
GType type);
|
||||
|
||||
void moo_editor_set_window_type (MooEditor *editor,
|
||||
GType type);
|
||||
void moo_editor_set_edit_type (MooEditor *editor,
|
||||
GType type);
|
||||
gboolean moo_editor_save_copy (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
|
||||
gboolean moo_editor_save_copy (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
void moo_editor_apply_prefs (MooEditor *editor);
|
||||
void moo_editor_queue_apply_prefs (MooEditor *editor);
|
||||
|
||||
void moo_editor_apply_prefs (MooEditor *editor);
|
||||
void moo_editor_queue_apply_prefs (MooEditor *editor);
|
||||
|
||||
void _moo_editor_load_session (MooEditor *editor,
|
||||
MooMarkupNode *xml);
|
||||
void _moo_editor_save_session (MooEditor *editor,
|
||||
MooMarkupNode *xml);
|
||||
void _moo_editor_load_session (MooEditor *editor,
|
||||
MooMarkupNode *xml);
|
||||
void _moo_editor_save_session (MooEditor *editor,
|
||||
MooMarkupNode *xml);
|
||||
|
||||
|
||||
enum {
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooedit/moolangmgr.h"
|
||||
#include "mooutils/mooencodings.h"
|
||||
#include "mooutils/mooi18n.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
@ -37,6 +38,34 @@ static guint settings[MOO_EDIT_LAST_SETTING];
|
||||
guint *_moo_edit_settings = settings;
|
||||
|
||||
|
||||
const char *
|
||||
_moo_get_default_encodings (void)
|
||||
{
|
||||
/* Translators: if translated, it should be a comma-separated list
|
||||
of encodings to try when opening files. Encodings names should be
|
||||
those understood by iconv, or "LOCALE" which means user's locale
|
||||
charset. For instance, the default value is "UTF-8,LOCALE,ISO_8859-15,ISO_8859-1".
|
||||
You want to add common preferred non-UTF8 encodings used in your locale.
|
||||
Do not remove ISO_8859-15 and ISO_8859-1, instead leave them at the end,
|
||||
these are common source files encodings. */
|
||||
const char *to_translate = N_("encodings_list");
|
||||
const char *encodings;
|
||||
|
||||
encodings = _(to_translate);
|
||||
|
||||
if (!strcmp (encodings, to_translate))
|
||||
encodings = "UTF-8," MOO_EDIT_ENCODING_LOCALE ",ISO_8859-1,ISO_8859-15";
|
||||
|
||||
return encodings;
|
||||
}
|
||||
|
||||
const char *
|
||||
_moo_edit_get_default_encoding (void)
|
||||
{
|
||||
return moo_prefs_get_string (moo_edit_setting (MOO_EDIT_PREFS_ENCODING_SAVE));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_moo_edit_init_config (void)
|
||||
{
|
||||
|
@ -85,6 +85,9 @@ const char *moo_edit_setting (const char *setting_name);
|
||||
#define MOO_EDIT_PREFS_ENCODINGS "encodings"
|
||||
#define MOO_EDIT_PREFS_ENCODING_SAVE "encoding_save"
|
||||
|
||||
#define MOO_EDIT_ENCODING_LOCALE "LOCALE"
|
||||
const char *_moo_get_default_encodings (void);
|
||||
const char *_moo_edit_get_default_encoding (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit/mooedit-impl.h"
|
||||
#include "mooedit/mooeditor-private.h"
|
||||
#include "mooedit/mooeditor-impl.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/moolangmgr.h"
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
|
28
moo/mooedit/mooedittypes.h
Normal file
28
moo/mooedit/mooedittypes.h
Normal 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 */
|
21
moo/mooedit/mooeditwindow-impl.h
Normal file
21
moo/mooedit/mooeditwindow-impl.h
Normal 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 */
|
@ -19,15 +19,16 @@
|
||||
|
||||
#define MOOEDIT_COMPILATION
|
||||
#include "mooedit/mooedit-impl.h"
|
||||
#include "mooedit/mooeditwindow-impl.h"
|
||||
#include "mooedit/mooedit-accels.h"
|
||||
#include "mooedit/mooeditor-private.h"
|
||||
#include "mooedit/mooeditor-impl.h"
|
||||
#include "mooedit/mooeditfiltersettings.h"
|
||||
#include "mooedit/moolang.h"
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/mooplugin.h"
|
||||
#include "mooedit/mooeditaction.h"
|
||||
#include "mooedit/mooedit-bookmarks.h"
|
||||
#include "mooedit/mooeditbookmark.h"
|
||||
#include "mooedit/moolangmgr.h"
|
||||
#include "mooutils/moonotebook.h"
|
||||
#include "mooutils/moostock.h"
|
||||
@ -39,7 +40,6 @@
|
||||
#include "mooutils/mooaction-private.h"
|
||||
#include "mooutils/moofiledialog.h"
|
||||
#include "mooutils/mooencodings.h"
|
||||
#include "mooutils/mooatom.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "moostatusbar-gxml.h"
|
||||
#include <string.h>
|
||||
@ -98,16 +98,17 @@ struct MooEditWindowPrivate {
|
||||
guint history_blocked : 1;
|
||||
};
|
||||
|
||||
MOO_DEFINE_OBJECT_ARRAY (MooEditWindowArray, moo_edit_window_array, MooEditWindow)
|
||||
|
||||
enum {
|
||||
TARGET_MOO_EDIT_TAB = 1,
|
||||
TARGET_URI_LIST = 2
|
||||
};
|
||||
|
||||
#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ())
|
||||
MOO_DEFINE_ATOM (MOO_EDIT_TAB, moo_edit_tab)
|
||||
MOO_DEFINE_ATOM_GLOBAL (MOO_EDIT_TAB, moo_edit_tab)
|
||||
|
||||
static GtkTargetEntry dest_targets[] = {
|
||||
{(char*) "MOO_EDIT_TAB", GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB},
|
||||
{(char*) MOO_EDIT_TAB_ATOM_NAME, GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB},
|
||||
{(char*) "text/uri-list", 0, TARGET_URI_LIST}
|
||||
};
|
||||
|
||||
@ -1106,15 +1107,15 @@ moo_edit_get_window (MooEdit *edit)
|
||||
gboolean
|
||||
moo_edit_window_close_all (MooEditWindow *window)
|
||||
{
|
||||
GSList *docs;
|
||||
MooEditArray *docs;
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
|
||||
|
||||
docs = moo_edit_window_list_docs (window);
|
||||
docs = moo_edit_window_get_docs (window);
|
||||
result = moo_editor_close_docs (window->priv->editor, docs, TRUE);
|
||||
|
||||
g_slist_free (docs);
|
||||
moo_edit_array_free (docs);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1786,19 +1787,19 @@ static void
|
||||
close_others_activated (GtkWidget *item,
|
||||
MooEditWindow *window)
|
||||
{
|
||||
GSList *list;
|
||||
MooEditArray *others;
|
||||
MooEdit *edit = g_object_get_data (G_OBJECT (item), "moo-edit");
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
||||
g_return_if_fail (MOO_IS_EDIT (edit));
|
||||
|
||||
list = moo_edit_window_list_docs (window);
|
||||
list = g_slist_remove (list, edit);
|
||||
others = moo_edit_window_get_docs (window);
|
||||
moo_edit_array_remove (others, edit);
|
||||
|
||||
if (list)
|
||||
moo_editor_close_docs (window->priv->editor, list, TRUE);
|
||||
if (!moo_edit_array_is_empty (others))
|
||||
moo_editor_close_docs (window->priv->editor, others, TRUE);
|
||||
|
||||
g_slist_free (list);
|
||||
moo_edit_array_free (others);
|
||||
}
|
||||
|
||||
|
||||
@ -2184,6 +2185,23 @@ moo_edit_window_list_docs (MooEditWindow *window)
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
MooEditArray *
|
||||
moo_edit_window_get_docs (MooEditWindow *window)
|
||||
{
|
||||
MooEditArray *docs;
|
||||
int num, i;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), NULL);
|
||||
|
||||
docs = moo_edit_array_new ();
|
||||
num = moo_notebook_get_n_pages (window->priv->notebook);
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
moo_edit_array_append (docs, get_nth_tab (window, i));
|
||||
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
moo_edit_window_num_docs (MooEditWindow *window)
|
||||
@ -3315,33 +3333,6 @@ moo_edit_window_remove_action_check (const char *action_id,
|
||||
}
|
||||
|
||||
|
||||
GSList *
|
||||
_moo_edit_parse_langs (const char *string)
|
||||
{
|
||||
char **pieces, **p;
|
||||
GSList *list = NULL;
|
||||
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
||||
pieces = g_strsplit_set (string, " \t\r\n;,", 0);
|
||||
|
||||
if (!pieces)
|
||||
return NULL;
|
||||
|
||||
for (p = pieces; *p != NULL; ++p)
|
||||
{
|
||||
g_strstrip (*p);
|
||||
|
||||
if (**p)
|
||||
list = g_slist_prepend (list, _moo_lang_id_from_name (*p));
|
||||
}
|
||||
|
||||
g_strfreev (pieces);
|
||||
return g_slist_reverse (list);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
check_action_filter (G_GNUC_UNUSED GtkAction *action,
|
||||
G_GNUC_UNUSED MooEditWindow *window,
|
||||
@ -3627,9 +3618,10 @@ populate_window_menu (MooEditWindow *window,
|
||||
GtkWidget *no_docs_item)
|
||||
{
|
||||
MooEdit *active_doc;
|
||||
GSList *docs;
|
||||
MooEditArray *docs;
|
||||
GList *children, *l;
|
||||
int pos;
|
||||
guint i;
|
||||
GtkWidget *item;
|
||||
|
||||
children = g_list_copy (GTK_MENU_SHELL (menu)->children);
|
||||
@ -3646,24 +3638,26 @@ populate_window_menu (MooEditWindow *window,
|
||||
|
||||
g_list_free (children);
|
||||
|
||||
docs = moo_edit_window_get_docs (window);
|
||||
|
||||
docs = moo_edit_window_list_docs (window);
|
||||
|
||||
if (!docs)
|
||||
if (moo_edit_array_is_empty (docs))
|
||||
{
|
||||
moo_edit_array_free (docs);
|
||||
return;
|
||||
}
|
||||
|
||||
item = gtk_separator_menu_item_new ();
|
||||
g_object_set_data (G_OBJECT (item), "moo-document-menu-item", GINT_TO_POINTER (TRUE));
|
||||
gtk_widget_show (item);
|
||||
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, ++pos);
|
||||
|
||||
docs = g_slist_sort (docs, (GCompareFunc) compare_docs_for_menu);
|
||||
moo_edit_array_sort (docs, (GCompareFunc) compare_docs_for_menu);
|
||||
active_doc = ACTIVE_DOC (window);
|
||||
|
||||
while (docs)
|
||||
for (i = 0; i < docs->n_elms; ++i)
|
||||
{
|
||||
int idx;
|
||||
MooEdit *doc = docs->data;
|
||||
MooEdit *doc = docs->elms[i];
|
||||
|
||||
idx = get_page_num (window, doc);
|
||||
|
||||
@ -3684,9 +3678,9 @@ populate_window_menu (MooEditWindow *window,
|
||||
gtk_action_get_accel_path (action));
|
||||
g_free (action_name);
|
||||
}
|
||||
|
||||
docs = g_slist_delete_link (docs, docs);
|
||||
}
|
||||
|
||||
moo_edit_array_free (docs);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -16,10 +16,12 @@
|
||||
#ifndef MOO_EDIT_WINDOW_H
|
||||
#define MOO_EDIT_WINDOW_H
|
||||
|
||||
#include <mooedit/mooedittypes.h>
|
||||
#include <mooedit/mooedit.h>
|
||||
#include <mooedit/mooedit-enums.h>
|
||||
#include <mooutils/moowindow.h>
|
||||
#include <mooutils/moobigpaned.h>
|
||||
#include <mooutils/mooatom.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -31,7 +33,6 @@ G_BEGIN_DECLS
|
||||
#define MOO_IS_EDIT_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_EDIT_WINDOW))
|
||||
#define MOO_EDIT_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_EDIT_WINDOW, MooEditWindowClass))
|
||||
|
||||
typedef struct MooEditWindow MooEditWindow;
|
||||
typedef struct MooEditWindowPrivate MooEditWindowPrivate;
|
||||
typedef struct MooEditWindowClass MooEditWindowClass;
|
||||
|
||||
@ -54,57 +55,61 @@ struct MooEditWindowClass
|
||||
void (*close_doc_after) (MooEditWindow *window);
|
||||
};
|
||||
|
||||
#define MOO_EDIT_TAB_ATOM_NAME "MOO_EDIT_TAB"
|
||||
#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ())
|
||||
MOO_DECLARE_ATOM_GLOBAL (MOO_EDIT_TAB, moo_edit_tab)
|
||||
|
||||
GType moo_edit_window_get_type (void) G_GNUC_CONST;
|
||||
GType moo_edit_window_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean moo_edit_window_close_all (MooEditWindow *window);
|
||||
gboolean moo_edit_window_close_all (MooEditWindow *window);
|
||||
|
||||
typedef gboolean (*MooActionCheckFunc) (GtkAction *action,
|
||||
MooEditWindow *window,
|
||||
MooEdit *doc,
|
||||
gpointer data);
|
||||
void moo_edit_window_set_action_check (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
MooActionCheckFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
void moo_edit_window_set_action_filter (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
const char *filter);
|
||||
typedef gboolean (*MooActionCheckFunc) (GtkAction *action,
|
||||
MooEditWindow *window,
|
||||
MooEdit *doc,
|
||||
gpointer data);
|
||||
void moo_edit_window_set_action_check (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
MooActionCheckFunc func,
|
||||
gpointer data,
|
||||
GDestroyNotify notify);
|
||||
void moo_edit_window_set_action_filter (const char *action_id,
|
||||
MooActionCheckType type,
|
||||
const char *filter);
|
||||
|
||||
MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window);
|
||||
void moo_edit_window_set_active_doc (MooEditWindow *window,
|
||||
MooEdit *edit);
|
||||
MooEditWindow *moo_edit_get_window (MooEdit *edit);
|
||||
MooEdit *moo_edit_window_get_active_doc (MooEditWindow *window);
|
||||
void moo_edit_window_set_active_doc (MooEditWindow *window,
|
||||
MooEdit *edit);
|
||||
|
||||
MooEdit *moo_edit_window_get_nth_doc (MooEditWindow *window,
|
||||
guint n);
|
||||
MooEditor *moo_edit_window_get_editor (MooEditWindow *window);
|
||||
|
||||
MooEdit *moo_edit_window_get_nth_doc (MooEditWindow *window,
|
||||
guint n);
|
||||
MooEditArray *moo_edit_window_get_docs (MooEditWindow *window);
|
||||
/* list must be freed, elements must not be unref'ed */
|
||||
GSList *moo_edit_window_list_docs (MooEditWindow *window);
|
||||
int moo_edit_window_num_docs (MooEditWindow *window);
|
||||
GSList *moo_edit_window_list_docs (MooEditWindow *window);
|
||||
int moo_edit_window_num_docs (MooEditWindow *window);
|
||||
|
||||
void moo_edit_window_set_title_prefix (MooEditWindow *window,
|
||||
const char *prefix);
|
||||
void moo_edit_window_set_title_prefix (MooEditWindow *window,
|
||||
const char *prefix);
|
||||
|
||||
/* sinks widget */
|
||||
MooPane *moo_edit_window_add_pane (MooEditWindow *window,
|
||||
const char *user_id,
|
||||
GtkWidget *widget,
|
||||
MooPaneLabel *label,
|
||||
MooPanePosition position);
|
||||
gboolean moo_edit_window_remove_pane (MooEditWindow *window,
|
||||
const char *user_id);
|
||||
GtkWidget *moo_edit_window_get_pane (MooEditWindow *window,
|
||||
const char *user_id);
|
||||
|
||||
MooPane *moo_edit_window_add_pane (MooEditWindow *window,
|
||||
const char *user_id,
|
||||
GtkWidget *widget,
|
||||
MooPaneLabel *label,
|
||||
MooPanePosition position);
|
||||
gboolean moo_edit_window_remove_pane (MooEditWindow *window,
|
||||
const char *user_id);
|
||||
GtkWidget *moo_edit_window_get_pane (MooEditWindow *window,
|
||||
const char *user_id);
|
||||
|
||||
typedef void (*MooAbortJobFunc) (gpointer job);
|
||||
|
||||
void moo_edit_window_add_stop_client (MooEditWindow *window,
|
||||
gpointer client);
|
||||
void moo_edit_window_remove_stop_client (MooEditWindow *window,
|
||||
gpointer client);
|
||||
void moo_edit_window_abort_jobs (MooEditWindow *window);
|
||||
void moo_edit_window_add_stop_client (MooEditWindow *window,
|
||||
gpointer client);
|
||||
void moo_edit_window_remove_stop_client (MooEditWindow *window,
|
||||
gpointer client);
|
||||
void moo_edit_window_abort_jobs (MooEditWindow *window);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
58
moo/mooedit/moofileenc.c
Normal file
58
moo/mooedit/moofileenc.c
Normal 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
25
moo/mooedit/moofileenc.h
Normal 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 */
|
@ -21,46 +21,7 @@
|
||||
|
||||
/* XXX this doesn't take unicode control chars into account */
|
||||
|
||||
static GObject *moo_indenter_constructor (GType type,
|
||||
guint n_construct_properties,
|
||||
GObjectConstructParam *construct_param);
|
||||
static void moo_indenter_finalize (GObject *object);
|
||||
static void moo_indenter_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void moo_indenter_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void character_default (MooIndenter *indenter,
|
||||
const char *inserted_char,
|
||||
GtkTextIter *where);
|
||||
static void config_changed_default (MooIndenter *indenter,
|
||||
guint setting_id,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void config_notify (MooIndenter *indenter,
|
||||
guint var_id,
|
||||
GParamSpec *pspec);
|
||||
|
||||
|
||||
enum {
|
||||
CONFIG_CHANGED,
|
||||
CHARACTER,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL];
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TAB_WIDTH,
|
||||
PROP_USE_TABS,
|
||||
PROP_INDENT,
|
||||
PROP_DOC
|
||||
};
|
||||
static void sync_settings (MooIndenter *indenter);
|
||||
|
||||
enum {
|
||||
SETTING_USE_TABS,
|
||||
@ -75,18 +36,8 @@ G_DEFINE_TYPE (MooIndenter, moo_indenter, G_TYPE_OBJECT)
|
||||
|
||||
|
||||
static void
|
||||
moo_indenter_class_init (MooIndenterClass *klass)
|
||||
moo_indenter_class_init (G_GNUC_UNUSED MooIndenterClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
gobject_class->constructor = moo_indenter_constructor;
|
||||
gobject_class->finalize = moo_indenter_finalize;
|
||||
gobject_class->set_property = moo_indenter_set_property;
|
||||
gobject_class->get_property = moo_indenter_get_property;
|
||||
|
||||
klass->character = character_default;
|
||||
klass->config_changed = config_changed_default;
|
||||
|
||||
settings[SETTING_USE_TABS] = moo_edit_config_install_setting (
|
||||
g_param_spec_boolean ("indent-use-tabs", "indent-use-tabs", "indent-use-tabs",
|
||||
TRUE, (GParamFlags) G_PARAM_READWRITE));
|
||||
@ -95,199 +46,29 @@ moo_indenter_class_init (MooIndenterClass *klass)
|
||||
settings[SETTING_INDENT_WIDTH] = moo_edit_config_install_setting (
|
||||
g_param_spec_uint ("indent-width", "indent-width", "indent-width",
|
||||
1, G_MAXUINT, 8, (GParamFlags) G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_DOC,
|
||||
g_param_spec_object ("doc", "doc", "doc",
|
||||
MOO_TYPE_EDIT,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_TAB_WIDTH,
|
||||
g_param_spec_uint ("tab-width", "tab-width", "tab-width",
|
||||
1, G_MAXUINT, 8,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_USE_TABS,
|
||||
g_param_spec_boolean ("use-tabs", "use-tabs", "use-tabs",
|
||||
TRUE,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_INDENT,
|
||||
g_param_spec_uint ("indent", "indent", "indent",
|
||||
1, G_MAXUINT, 8,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
|
||||
|
||||
signals[CONFIG_CHANGED] =
|
||||
g_signal_new ("config-changed",
|
||||
G_OBJECT_CLASS_TYPE (klass),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (MooIndenterClass, config_changed),
|
||||
NULL, NULL,
|
||||
_moo_marshal_VOID__UINT_POINTER,
|
||||
G_TYPE_NONE, 2,
|
||||
G_TYPE_UINT, G_TYPE_POINTER);
|
||||
|
||||
signals[CHARACTER] =
|
||||
g_signal_new ("character",
|
||||
G_OBJECT_CLASS_TYPE (klass),
|
||||
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (MooIndenterClass, character),
|
||||
NULL, NULL,
|
||||
_moo_marshal_VOID__STRING_BOXED,
|
||||
G_TYPE_NONE, 2,
|
||||
G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
|
||||
GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_indenter_init (G_GNUC_UNUSED MooIndenter *indent)
|
||||
moo_indenter_init (MooIndenter *indent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static GObject*
|
||||
moo_indenter_constructor (GType type,
|
||||
guint n_props,
|
||||
GObjectConstructParam *props)
|
||||
{
|
||||
GObject *object;
|
||||
MooIndenter *indent;
|
||||
|
||||
object = G_OBJECT_CLASS(moo_indenter_parent_class)->constructor (type, n_props, props);
|
||||
indent = MOO_INDENTER (object);
|
||||
|
||||
if (indent->doc)
|
||||
{
|
||||
guint i;
|
||||
GParamSpec *pspec;
|
||||
guint id;
|
||||
|
||||
for (i = 0; i < LAST_SETTING; ++i)
|
||||
config_notify (indent, settings[i], NULL);
|
||||
|
||||
pspec = moo_edit_config_lookup_spec ("tab-width", &id, FALSE);
|
||||
g_return_val_if_fail (pspec != NULL, object);
|
||||
config_notify (indent, id, pspec);
|
||||
|
||||
g_signal_connect_swapped (indent->doc, "config-notify",
|
||||
G_CALLBACK (config_notify),
|
||||
indent);
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moo_indenter_finalize (GObject *object)
|
||||
{
|
||||
MooIndenter *indent = MOO_INDENTER (object);
|
||||
|
||||
if (indent->doc)
|
||||
g_signal_handlers_disconnect_by_func (indent->doc,
|
||||
(gpointer) config_notify,
|
||||
indent);
|
||||
indent->doc = NULL;
|
||||
|
||||
G_OBJECT_CLASS(moo_indenter_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void moo_indenter_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MooIndenter *indenter = MOO_INDENTER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DOC:
|
||||
indenter->doc = g_value_get_object (value);
|
||||
g_object_notify (object, "doc");
|
||||
break;
|
||||
|
||||
case PROP_TAB_WIDTH:
|
||||
indenter->tab_width = g_value_get_uint (value);
|
||||
g_object_notify (object, "tab-width");
|
||||
break;
|
||||
|
||||
case PROP_USE_TABS:
|
||||
indenter->use_tabs = g_value_get_boolean (value);
|
||||
g_object_notify (object, "use-tabs");
|
||||
break;
|
||||
|
||||
case PROP_INDENT:
|
||||
indenter->indent = g_value_get_uint (value);
|
||||
g_object_notify (object, "indent");
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void moo_indenter_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MooIndenter *indenter = MOO_INDENTER (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_DOC:
|
||||
g_value_set_object (value, indenter->doc);
|
||||
break;
|
||||
|
||||
case PROP_TAB_WIDTH:
|
||||
g_value_set_uint (value, indenter->tab_width);
|
||||
break;
|
||||
|
||||
case PROP_USE_TABS:
|
||||
g_value_set_boolean (value, indenter->use_tabs);
|
||||
break;
|
||||
|
||||
case PROP_INDENT:
|
||||
g_value_set_uint (value, indenter->indent);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
config_notify (MooIndenter *indenter,
|
||||
guint var_id,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
if (!pspec)
|
||||
pspec = moo_edit_config_get_spec (var_id);
|
||||
g_return_if_fail (pspec != NULL);
|
||||
g_signal_emit (indenter, signals[CONFIG_CHANGED], 0, var_id, pspec);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_indenter_character (MooIndenter *indenter,
|
||||
const char *inserted_char,
|
||||
GtkTextIter *where)
|
||||
{
|
||||
g_return_if_fail (MOO_IS_INDENTER (indenter));
|
||||
MOO_INDENTER_GET_CLASS(indenter)->character (indenter, inserted_char, where);
|
||||
indent->tab_width = 8;
|
||||
indent->use_tabs = TRUE;
|
||||
indent->indent = 8;
|
||||
}
|
||||
|
||||
|
||||
MooIndenter *
|
||||
moo_indenter_new (gpointer doc)
|
||||
moo_indenter_new (MooEdit *doc)
|
||||
{
|
||||
g_return_val_if_fail (!doc || MOO_IS_EDIT (doc), NULL);
|
||||
return MOO_INDENTER (g_object_new (MOO_TYPE_INDENTER, "doc", doc, (const char*) NULL));
|
||||
MooIndenter *indent;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), NULL);
|
||||
|
||||
indent = g_object_new (MOO_TYPE_INDENTER, NULL);
|
||||
indent->doc = doc;
|
||||
|
||||
return indent;
|
||||
}
|
||||
|
||||
|
||||
@ -295,7 +76,7 @@ moo_indenter_new (gpointer doc)
|
||||
/* Default implementation
|
||||
*/
|
||||
|
||||
char*
|
||||
char *
|
||||
moo_indenter_make_space (MooIndenter *indenter,
|
||||
guint len,
|
||||
guint start)
|
||||
@ -306,6 +87,8 @@ moo_indenter_make_space (MooIndenter *indenter,
|
||||
|
||||
g_return_val_if_fail (MOO_IS_INDENTER (indenter), NULL);
|
||||
|
||||
sync_settings (indenter);
|
||||
|
||||
if (!len)
|
||||
return NULL;
|
||||
|
||||
@ -389,21 +172,27 @@ compute_line_offset (GtkTextIter *dest,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
character_default (MooIndenter *indenter,
|
||||
const char *inserted_char,
|
||||
GtkTextIter *where)
|
||||
void
|
||||
moo_indenter_character (MooIndenter *indenter,
|
||||
const char *inserted_char,
|
||||
GtkTextIter *where)
|
||||
{
|
||||
char *indent_string = NULL;
|
||||
GtkTextBuffer *buffer = gtk_text_iter_get_buffer (where);
|
||||
guint offset;
|
||||
GtkTextIter iter;
|
||||
|
||||
g_return_if_fail (MOO_IS_INDENTER (indenter));
|
||||
g_return_if_fail (inserted_char != NULL);
|
||||
|
||||
if (*inserted_char != '\n')
|
||||
return;
|
||||
|
||||
buffer = gtk_text_iter_get_buffer (where);
|
||||
g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
|
||||
|
||||
sync_settings (indenter);
|
||||
|
||||
iter = *where;
|
||||
gtk_text_iter_backward_line (&iter);
|
||||
compute_line_offset (&iter, indenter->tab_width, &offset);
|
||||
@ -564,6 +353,8 @@ moo_indenter_tab (MooIndenter *indenter,
|
||||
guint indent = indenter->indent;
|
||||
char *text = NULL;
|
||||
|
||||
sync_settings (indenter);
|
||||
|
||||
gtk_text_buffer_get_iter_at_mark (buffer, &insert, gtk_text_buffer_get_insert (buffer));
|
||||
|
||||
start = insert;
|
||||
@ -671,6 +462,8 @@ moo_indenter_shift_lines (MooIndenter *indenter,
|
||||
guint i;
|
||||
GtkTextIter iter;
|
||||
|
||||
sync_settings (indenter);
|
||||
|
||||
for (i = first_line; i <= last_line; ++i)
|
||||
{
|
||||
gtk_text_buffer_get_iter_at_line (buffer, &iter, i);
|
||||
@ -683,27 +476,10 @@ moo_indenter_shift_lines (MooIndenter *indenter,
|
||||
|
||||
|
||||
static void
|
||||
config_changed_default (MooIndenter *indenter,
|
||||
guint var_id,
|
||||
GParamSpec *pspec)
|
||||
sync_settings (MooIndenter *indenter)
|
||||
{
|
||||
MooEdit *doc = indenter->doc;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
if (var_id == settings[SETTING_USE_TABS])
|
||||
{
|
||||
gboolean use_tabs = moo_edit_config_get_bool (doc->config, "indent-use-tabs");
|
||||
g_object_set (indenter, "use-tabs", use_tabs, NULL);
|
||||
}
|
||||
else if (var_id == settings[SETTING_INDENT_WIDTH])
|
||||
{
|
||||
guint width = moo_edit_config_get_uint (doc->config, "indent-width");
|
||||
g_object_set (indenter, "indent", width, NULL);
|
||||
}
|
||||
else if (!strcmp (pspec->name, "tab-width"))
|
||||
{
|
||||
guint tab_width = moo_edit_config_get_uint (doc->config, "tab-width");
|
||||
g_object_set (indenter, "tab-width", tab_width, NULL);
|
||||
}
|
||||
g_return_if_fail (MOO_IS_EDIT (indenter->doc));
|
||||
indenter->use_tabs = moo_edit_config_get_bool (indenter->doc->config, "indent-use-tabs");
|
||||
indenter->indent = moo_edit_config_get_uint (indenter->doc->config, "indent-width");
|
||||
indenter->tab_width = moo_edit_config_get_uint (indenter->doc->config, "tab-width");
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef MOO_INDENTER_H
|
||||
#define MOO_INDENTER_H
|
||||
|
||||
#include <gtk/gtktextbuffer.h>
|
||||
#include <mooedit/mooedittypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -29,20 +29,19 @@ G_BEGIN_DECLS
|
||||
#define MOO_INDENTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_INDENTER, MooIndenterClass))
|
||||
|
||||
|
||||
typedef struct _MooIndenter MooIndenter;
|
||||
typedef struct _MooIndenterClass MooIndenterClass;
|
||||
typedef struct MooIndenter MooIndenter;
|
||||
typedef struct MooIndenterClass MooIndenterClass;
|
||||
|
||||
struct _MooIndenter
|
||||
struct MooIndenter
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
gpointer doc; /* MooEdit* */
|
||||
MooEdit *doc;
|
||||
gboolean use_tabs;
|
||||
guint tab_width;
|
||||
guint indent;
|
||||
};
|
||||
|
||||
struct _MooIndenterClass
|
||||
struct MooIndenterClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
@ -57,7 +56,7 @@ struct _MooIndenterClass
|
||||
|
||||
GType moo_indenter_get_type (void) G_GNUC_CONST;
|
||||
|
||||
MooIndenter *moo_indenter_new (gpointer doc);
|
||||
MooIndenter *moo_indenter_new (MooEdit *doc);
|
||||
|
||||
char *moo_indenter_make_space (MooIndenter *indenter,
|
||||
guint len,
|
||||
|
@ -38,7 +38,6 @@
|
||||
#define KEY_DESCRIPTION "description"
|
||||
#define KEY_AUTHOR "author"
|
||||
#define KEY_VERSION "version"
|
||||
#define KEY_LANGS "langs"
|
||||
#define KEY_ENABLED "enabled"
|
||||
#define KEY_VISIBLE "visible"
|
||||
|
||||
@ -169,7 +168,6 @@ parse_plugin_info (GKeyFile *key_file,
|
||||
char *description;
|
||||
char *author;
|
||||
char *version;
|
||||
char *langs;
|
||||
gboolean enabled = TRUE;
|
||||
gboolean visible = TRUE;
|
||||
|
||||
@ -177,7 +175,6 @@ parse_plugin_info (GKeyFile *key_file,
|
||||
description = g_key_file_get_locale_string (key_file, GROUP_PLUGIN, KEY_DESCRIPTION, NULL, NULL);
|
||||
author = g_key_file_get_locale_string (key_file, GROUP_PLUGIN, KEY_AUTHOR, NULL, NULL);
|
||||
version = g_key_file_get_locale_string (key_file, GROUP_PLUGIN, KEY_VERSION, NULL, NULL);
|
||||
langs = g_key_file_get_string (key_file, GROUP_PLUGIN, KEY_LANGS, NULL);
|
||||
|
||||
if (g_key_file_has_key (key_file, GROUP_PLUGIN, KEY_ENABLED, NULL))
|
||||
enabled = g_key_file_get_boolean (key_file, GROUP_PLUGIN, KEY_ENABLED, NULL);
|
||||
@ -187,8 +184,7 @@ parse_plugin_info (GKeyFile *key_file,
|
||||
info = moo_plugin_info_new (name ? name : plugin_id,
|
||||
description ? description : "",
|
||||
author ? author : "",
|
||||
version ? version : "",
|
||||
langs);
|
||||
version ? version : "");
|
||||
params = moo_plugin_params_new (enabled, visible);
|
||||
|
||||
*info_p = info;
|
||||
@ -198,7 +194,6 @@ parse_plugin_info (GKeyFile *key_file,
|
||||
g_free (description);
|
||||
g_free (author);
|
||||
g_free (version);
|
||||
g_free (langs);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -29,12 +29,11 @@ MOO_MODULE_INIT_FUNC (void)
|
||||
|
||||
|
||||
#define MOO_PLUGIN_DEFINE_INFO(plugin_name__,name__, \
|
||||
description__,author__,version__, \
|
||||
langs__) \
|
||||
description__,author__,version__) \
|
||||
\
|
||||
static const MooPluginInfo plugin_name__##_plugin_info = \
|
||||
{(char*) name__, (char*) description__, \
|
||||
(char*) author__, (char*) version__, (char*) langs__};
|
||||
(char*) author__, (char*) version__};
|
||||
|
||||
|
||||
#define MOO_PLUGIN_DEFINE_FULL(Name__,name__, \
|
||||
|
@ -191,9 +191,6 @@ moo_plugin_finalize (GObject *object)
|
||||
{
|
||||
MooPlugin *plugin = MOO_PLUGIN (object);
|
||||
|
||||
if (plugin->langs)
|
||||
g_hash_table_destroy (plugin->langs);
|
||||
|
||||
g_free (plugin->id);
|
||||
moo_plugin_info_free (plugin->info);
|
||||
moo_plugin_params_free (plugin->params);
|
||||
@ -219,7 +216,8 @@ moo_plugin_register (const char *id,
|
||||
MooPluginClass *klass;
|
||||
MooPlugin *plugin;
|
||||
char *prefs_key;
|
||||
GSList *l, *windows;
|
||||
MooEditWindowArray *windows;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (id != NULL && id[0] != 0, FALSE);
|
||||
g_return_val_if_fail (g_utf8_validate (id, -1, NULL), FALSE);
|
||||
@ -249,43 +247,6 @@ moo_plugin_register (const char *id,
|
||||
plugin->params = params ? moo_plugin_params_copy ((MooPluginParams*) params) :
|
||||
moo_plugin_params_new (TRUE, TRUE);
|
||||
|
||||
if (info->langs)
|
||||
{
|
||||
char **langs, **p;
|
||||
GHashTable *table;
|
||||
|
||||
/* XXX */
|
||||
langs = g_strsplit_set (info->langs, " \t\r\n", 0);
|
||||
table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
for (p = langs; p && *p; ++p)
|
||||
{
|
||||
char *lang_id;
|
||||
|
||||
if (!**p)
|
||||
continue;
|
||||
|
||||
lang_id = _moo_lang_id_from_name (*p);
|
||||
|
||||
if (!g_hash_table_lookup (table, lang_id))
|
||||
g_hash_table_insert (table, lang_id, lang_id);
|
||||
else
|
||||
g_free (lang_id);
|
||||
}
|
||||
|
||||
if (!g_hash_table_size (table))
|
||||
{
|
||||
g_warning ("%s: invalid langs string '%s'", G_STRLOC, info->langs);
|
||||
g_hash_table_destroy (table);
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin->langs = table;
|
||||
}
|
||||
|
||||
g_strfreev (langs);
|
||||
}
|
||||
|
||||
if (moo_plugin_lookup (moo_plugin_id (plugin)))
|
||||
{
|
||||
_moo_message ("%s: plugin with id %s already registered",
|
||||
@ -309,10 +270,10 @@ moo_plugin_register (const char *id,
|
||||
|
||||
plugin_store_add (plugin);
|
||||
|
||||
windows = moo_editor_list_windows (plugin_store->editor);
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
plugin_attach_win (plugin, l->data);
|
||||
g_slist_free (windows);
|
||||
windows = moo_editor_get_windows (plugin_store->editor);
|
||||
for (i = 0; i < windows->n_elms; ++i)
|
||||
plugin_attach_win (plugin, windows->elms[i]);
|
||||
moo_edit_window_array_free (windows);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -369,7 +330,8 @@ plugin_attach_win (MooPlugin *plugin,
|
||||
MooWinPluginClass *wklass;
|
||||
MooWinPlugin *win_plugin;
|
||||
GType wtype;
|
||||
GSList *l, *docs;
|
||||
MooEditArray *docs;
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
||||
g_return_if_fail (MOO_IS_PLUGIN (plugin));
|
||||
@ -399,10 +361,10 @@ plugin_attach_win (MooPlugin *plugin,
|
||||
g_object_unref (win_plugin);
|
||||
}
|
||||
|
||||
docs = moo_edit_window_list_docs (window);
|
||||
for (l = docs; l != NULL; l = l->next)
|
||||
plugin_attach_doc (plugin, window, l->data);
|
||||
g_slist_free (docs);
|
||||
docs = moo_edit_window_get_docs (window);
|
||||
for (i = 0; i < docs->n_elms; ++i)
|
||||
plugin_attach_doc (plugin, window, docs->elms[i]);
|
||||
moo_edit_array_free (docs);
|
||||
}
|
||||
|
||||
|
||||
@ -413,7 +375,8 @@ plugin_detach_win (MooPlugin *plugin,
|
||||
MooPluginClass *klass;
|
||||
MooWinPluginClass *wklass;
|
||||
MooWinPlugin *win_plugin;
|
||||
GSList *l, *docs;
|
||||
MooEditArray *docs;
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT_WINDOW (window));
|
||||
g_return_if_fail (MOO_IS_PLUGIN (plugin));
|
||||
@ -421,10 +384,10 @@ plugin_detach_win (MooPlugin *plugin,
|
||||
if (!moo_plugin_enabled (plugin))
|
||||
return;
|
||||
|
||||
docs = moo_edit_window_list_docs (window);
|
||||
for (l = docs; l != NULL; l = l->next)
|
||||
plugin_detach_doc (plugin, window, l->data);
|
||||
g_slist_free (docs);
|
||||
docs = moo_edit_window_get_docs (window);
|
||||
for (i = 0; i < docs->n_elms; ++i)
|
||||
plugin_detach_doc (plugin, window, docs->elms[i]);
|
||||
moo_edit_array_free (docs);
|
||||
|
||||
win_plugin = window_get_plugin (window, plugin);
|
||||
|
||||
@ -463,19 +426,6 @@ plugin_attach_doc (MooPlugin *plugin,
|
||||
if (!moo_plugin_enabled (plugin))
|
||||
return;
|
||||
|
||||
/* XXX ! */
|
||||
if (plugin->langs)
|
||||
{
|
||||
MooLang *lang;
|
||||
const char *id;
|
||||
|
||||
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
||||
id = _moo_lang_id (lang);
|
||||
|
||||
if (!g_hash_table_lookup (plugin->langs, id))
|
||||
return;
|
||||
}
|
||||
|
||||
plugin->docs = g_slist_prepend (plugin->docs, doc);
|
||||
|
||||
klass = MOO_PLUGIN_GET_CLASS (plugin);
|
||||
@ -738,7 +688,8 @@ moo_plugin_enabled (MooPlugin *plugin)
|
||||
static gboolean
|
||||
plugin_enable (MooPlugin *plugin)
|
||||
{
|
||||
GSList *l, *windows;
|
||||
MooEditWindowArray *windows;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_PLUGIN (plugin), FALSE);
|
||||
|
||||
@ -755,10 +706,10 @@ plugin_enable (MooPlugin *plugin)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
windows = moo_editor_list_windows (plugin_store->editor);
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
plugin_attach_win (plugin, l->data);
|
||||
g_slist_free (windows);
|
||||
windows = moo_editor_get_windows (plugin_store->editor);
|
||||
for (i = 0; i < windows->n_elms; ++i)
|
||||
plugin_attach_win (plugin, windows->elms[i]);
|
||||
moo_edit_window_array_free (windows);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -767,7 +718,8 @@ plugin_enable (MooPlugin *plugin)
|
||||
static void
|
||||
plugin_disable (MooPlugin *plugin)
|
||||
{
|
||||
GSList *l, *windows;
|
||||
MooEditWindowArray *windows;
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (MOO_IS_PLUGIN (plugin));
|
||||
|
||||
@ -776,10 +728,10 @@ plugin_disable (MooPlugin *plugin)
|
||||
|
||||
g_assert (plugin->initialized);
|
||||
|
||||
windows = moo_editor_list_windows (plugin_store->editor);
|
||||
for (l = windows; l != NULL; l = l->next)
|
||||
plugin_detach_win (plugin, l->data);
|
||||
g_slist_free (windows);
|
||||
windows = moo_editor_get_windows (plugin_store->editor);
|
||||
for (i = 0; i < windows->n_elms; ++i)
|
||||
plugin_detach_win (plugin, windows->elms[i]);
|
||||
moo_edit_window_array_free (windows);
|
||||
|
||||
plugin_deinit (plugin);
|
||||
plugin->params->enabled = FALSE;
|
||||
@ -998,35 +950,6 @@ _moo_window_detach_plugins (MooEditWindow *window)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
doc_lang_changed (MooEdit *doc)
|
||||
{
|
||||
GSList *l;
|
||||
MooLang *lang;
|
||||
const char *id;
|
||||
MooEditWindow *window = NULL;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDIT (doc));
|
||||
|
||||
window = moo_edit_get_window (doc);
|
||||
lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
||||
id = _moo_lang_id (lang);
|
||||
|
||||
for (l = plugin_store->list; l != NULL; l = l->next)
|
||||
{
|
||||
MooPlugin *plugin = l->data;
|
||||
|
||||
if (moo_plugin_enabled (plugin) && plugin->langs)
|
||||
{
|
||||
if (g_hash_table_lookup (plugin->langs, id))
|
||||
plugin_attach_doc (plugin, window, doc);
|
||||
else
|
||||
plugin_detach_doc (plugin, window, doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_moo_doc_attach_plugins (MooEditWindow *window,
|
||||
MooEdit *doc)
|
||||
@ -1038,10 +961,6 @@ _moo_doc_attach_plugins (MooEditWindow *window,
|
||||
|
||||
plugin_store_init ();
|
||||
|
||||
g_signal_connect (doc, "config-notify::lang",
|
||||
G_CALLBACK (doc_lang_changed),
|
||||
plugin_store);
|
||||
|
||||
for (l = plugin_store->list; l != NULL; l = l->next)
|
||||
plugin_attach_doc (l->data, window, doc);
|
||||
}
|
||||
@ -1058,10 +977,6 @@ _moo_doc_detach_plugins (MooEditWindow *window,
|
||||
|
||||
plugin_store_init ();
|
||||
|
||||
g_signal_handlers_disconnect_by_func (doc,
|
||||
(gpointer) doc_lang_changed,
|
||||
plugin_store);
|
||||
|
||||
for (l = plugin_store->list; l != NULL; l = l->next)
|
||||
plugin_detach_doc (l->data, window, doc);
|
||||
}
|
||||
@ -1113,8 +1028,7 @@ MooPluginInfo *
|
||||
moo_plugin_info_new (const char *name,
|
||||
const char *description,
|
||||
const char *author,
|
||||
const char *version,
|
||||
const char *langs)
|
||||
const char *version)
|
||||
{
|
||||
MooPluginInfo *info;
|
||||
|
||||
@ -1125,7 +1039,6 @@ moo_plugin_info_new (const char *name,
|
||||
info->description = description ? g_strdup (description) : g_strdup ("");
|
||||
info->author = author ? g_strdup (author) : g_strdup ("");
|
||||
info->version = version ? g_strdup (version) : g_strdup ("");
|
||||
info->langs = g_strdup (langs);
|
||||
|
||||
return info;
|
||||
}
|
||||
@ -1136,7 +1049,7 @@ moo_plugin_info_copy (MooPluginInfo *info)
|
||||
{
|
||||
g_return_val_if_fail (info != NULL, NULL);
|
||||
return moo_plugin_info_new (info->name, info->description,
|
||||
info->author, info->version, info->langs);
|
||||
info->author, info->version);
|
||||
}
|
||||
|
||||
|
||||
@ -1149,7 +1062,6 @@ moo_plugin_info_free (MooPluginInfo *info)
|
||||
g_free (info->description);
|
||||
g_free (info->author);
|
||||
g_free (info->version);
|
||||
g_free (info->langs);
|
||||
g_free (info);
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,6 @@ struct _MooPluginInfo
|
||||
char *description;
|
||||
char *author;
|
||||
char *version;
|
||||
char *langs;
|
||||
};
|
||||
|
||||
struct _MooPlugin
|
||||
@ -123,7 +122,6 @@ struct _MooPlugin
|
||||
GQuark id_quark;
|
||||
MooPluginInfo *info;
|
||||
MooPluginParams *params;
|
||||
GHashTable *langs;
|
||||
GSList *docs;
|
||||
GType win_plugin_type;
|
||||
GType doc_plugin_type;
|
||||
@ -225,8 +223,7 @@ void moo_plugin_set_win_plugin_type (MooPlugin *plugin,
|
||||
MooPluginInfo *moo_plugin_info_new (const char *name,
|
||||
const char *description,
|
||||
const char *author,
|
||||
const char *version,
|
||||
const char *langs);
|
||||
const char *version);
|
||||
MooPluginInfo *moo_plugin_info_copy (MooPluginInfo *info);
|
||||
void moo_plugin_info_free (MooPluginInfo *info);
|
||||
MooPluginParams *moo_plugin_params_new (gboolean enabled,
|
||||
|
@ -20,9 +20,10 @@
|
||||
#include "mooedit/mootextbuffer.h"
|
||||
#include "mooedit/mootextfind.h"
|
||||
#include "mooedit/mootext-private.h"
|
||||
#include "mooedit/mooedit-enums.h"
|
||||
#include "mooedit/mooeditprefs.h"
|
||||
#include "mooedit/moolangmgr.h"
|
||||
#include "mooedit/mooeditwindow.h"
|
||||
#include "mooedit/mooedit.h"
|
||||
#include "marshals.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooundo.h"
|
||||
@ -32,6 +33,7 @@
|
||||
#include "mooutils/mooatom.h"
|
||||
#include "mooutils/mootype-macros.h"
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/mooutils-gobject.h"
|
||||
#include "mooquicksearch-gxml.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gregex.h>
|
||||
@ -2605,14 +2607,10 @@ void
|
||||
moo_text_view_set_lang_by_id (MooTextView *view,
|
||||
const char *lang_id)
|
||||
{
|
||||
MooEditor *editor;
|
||||
MooLangMgr *mgr;
|
||||
MooLang *lang;
|
||||
MooTextStyleScheme *scheme;
|
||||
|
||||
editor = moo_editor_instance ();
|
||||
g_return_if_fail (editor != NULL);
|
||||
|
||||
mgr = moo_lang_mgr_default ();
|
||||
lang = moo_lang_mgr_get_lang (mgr, lang_id);
|
||||
scheme = moo_lang_mgr_get_active_scheme (mgr);
|
||||
@ -4116,12 +4114,7 @@ static void
|
||||
quick_search_message (MooTextView *view,
|
||||
const char *msg)
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
window = gtk_widget_get_toplevel (GTK_WIDGET (view));
|
||||
|
||||
if (MOO_IS_EDIT_WINDOW (window))
|
||||
moo_window_message (MOO_WINDOW (window), msg);
|
||||
moo_text_view_message (view, msg);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1906,15 +1906,34 @@ static void size_data_func (G_GNUC_UNUSED GObject *column_or_iconvie
|
||||
|
||||
|
||||
gboolean
|
||||
moo_file_view_chdir (MooFileView *fileview,
|
||||
const char *dir,
|
||||
GError **error)
|
||||
moo_file_view_chdir (MooFileView *fileview,
|
||||
GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
gboolean result;
|
||||
char *dir;
|
||||
|
||||
moo_return_error_if_fail (MOO_IS_FILE_VIEW (fileview));
|
||||
|
||||
dir = g_file_get_path (file);
|
||||
moo_return_error_if_fail (dir != NULL);
|
||||
|
||||
result = moo_file_view_chdir_path (fileview, dir, error);
|
||||
|
||||
g_free (dir);
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean
|
||||
moo_file_view_chdir_path (MooFileView *fileview,
|
||||
const char *path,
|
||||
GError **error)
|
||||
{
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_FILE_VIEW (fileview), FALSE);
|
||||
moo_return_error_if_fail (MOO_IS_FILE_VIEW (fileview));
|
||||
|
||||
g_signal_emit (fileview, signals[CHDIR], 0, dir, error, &result);
|
||||
g_signal_emit (fileview, signals[CHDIR], 0, path, error, &result);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1949,7 +1968,7 @@ moo_file_view_go_up (MooFileView *fileview)
|
||||
const char *path = _moo_folder_get_path (parent);
|
||||
char *name = g_path_get_basename (_moo_folder_get_path (fileview->priv->current_dir));
|
||||
|
||||
if (moo_file_view_chdir (fileview, path, NULL))
|
||||
if (moo_file_view_chdir_path (fileview, path, NULL))
|
||||
_moo_file_view_select_name (fileview, name);
|
||||
|
||||
g_free (name);
|
||||
@ -1967,7 +1986,7 @@ moo_file_view_go_home (MooFileView *fileview)
|
||||
if (fileview->priv->entry_state)
|
||||
stop_path_entry (fileview, TRUE);
|
||||
|
||||
if (!moo_file_view_chdir (fileview, moo_file_view_get_home_dir (fileview), &error))
|
||||
if (!moo_file_view_chdir_path (fileview, moo_file_view_get_home_dir (fileview), &error))
|
||||
{
|
||||
g_warning ("%s: could not go home", G_STRLOC);
|
||||
|
||||
@ -2005,7 +2024,7 @@ file_list_row_activated (MooFileView *fileview,
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!moo_file_view_chdir (fileview, _moo_file_name (file), &error))
|
||||
if (!moo_file_view_chdir_path (fileview, _moo_file_name (file), &error))
|
||||
{
|
||||
g_warning ("%s: could not go into '%s'",
|
||||
G_STRLOC, _moo_file_name (file));
|
||||
@ -2216,7 +2235,7 @@ moo_file_view_go (MooFileView *fileview,
|
||||
{
|
||||
fileview->priv->history->block++;
|
||||
|
||||
if (!moo_file_view_chdir (fileview, dir, &error))
|
||||
if (!moo_file_view_chdir_path (fileview, dir, &error))
|
||||
{
|
||||
g_warning ("%s: could not go into '%s'",
|
||||
G_STRLOC, dir);
|
||||
@ -2262,7 +2281,7 @@ moo_file_view_set_property (GObject *object,
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_CURRENT_DIRECTORY:
|
||||
moo_file_view_chdir (fileview, g_value_get_string (value), NULL);
|
||||
moo_file_view_chdir_path (fileview, g_value_get_string (value), NULL);
|
||||
break;
|
||||
|
||||
case PROP_HOME_DIRECTORY:
|
||||
@ -3746,7 +3765,7 @@ bookmark_activate (G_GNUC_UNUSED MooBookmarkMgr *mgr,
|
||||
if (activated != fileview)
|
||||
return;
|
||||
|
||||
moo_file_view_chdir (fileview, bookmark->path, NULL);
|
||||
moo_file_view_chdir_path (fileview, bookmark->path, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -3755,7 +3774,7 @@ bookmark_activated (MooFileView *fileview,
|
||||
MooBookmark *bookmark)
|
||||
{
|
||||
g_return_if_fail (bookmark != NULL && bookmark->path != NULL);
|
||||
moo_file_view_chdir (fileview, bookmark->path, NULL);
|
||||
moo_file_view_chdir_path (fileview, bookmark->path, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -4567,7 +4586,7 @@ file_view_activate_filename (MooFileView *fileview,
|
||||
|
||||
if (g_file_test (path, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
if (!moo_file_view_chdir (fileview, path, &error))
|
||||
if (!moo_file_view_chdir_path (fileview, path, &error))
|
||||
{
|
||||
g_warning ("%s: could not chdir to %s",
|
||||
G_STRLOC, path);
|
||||
@ -4593,7 +4612,7 @@ file_view_activate_filename (MooFileView *fileview,
|
||||
g_return_if_reached ();
|
||||
}
|
||||
|
||||
if (!moo_file_view_chdir (fileview, dirname, &error))
|
||||
if (!moo_file_view_chdir_path (fileview, dirname, &error))
|
||||
{
|
||||
g_warning ("%s: could not chdir to %s",
|
||||
G_STRLOC, dirname);
|
||||
@ -5127,7 +5146,7 @@ drop_open_timeout_func2 (MooFileView *fileview)
|
||||
g_warning ("%s: oops", G_STRLOC);
|
||||
}
|
||||
|
||||
if (goto_dir && moo_file_view_chdir (fileview, goto_dir, NULL))
|
||||
if (goto_dir && moo_file_view_chdir_path (fileview, goto_dir, NULL))
|
||||
_moo_file_view_select_name (fileview, NULL);
|
||||
|
||||
if (file)
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define MOO_FILE_VIEW_H
|
||||
|
||||
#include <mooutils/moouixml.h>
|
||||
#include <mooutils/mooutils-file.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -34,6 +35,9 @@ typedef struct MooFileViewClass MooFileViewClass;
|
||||
GType moo_file_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gboolean moo_file_view_chdir (MooFileView *fileview,
|
||||
GFile *dir,
|
||||
GError **error);
|
||||
gboolean moo_file_view_chdir_path (MooFileView *fileview,
|
||||
const char *dir,
|
||||
GError **error);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "mooscript-classes.h"
|
||||
#include "mooscript-classes-util.h"
|
||||
#include "mooapp/mooapp.h"
|
||||
#include "mooedit/moofileenc.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include <string.h>
|
||||
@ -89,6 +90,18 @@ static VariantArray wrap_gslist(GSList *list)
|
||||
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)
|
||||
{
|
||||
switch (val.vt())
|
||||
@ -534,42 +547,24 @@ void Editor::set_active_window(DocumentWindow &window)
|
||||
moo_editor_set_active_window(moo_editor_instance(), window.gobj());
|
||||
}
|
||||
|
||||
/// @item Editor.active_view()
|
||||
/// returns current active document view
|
||||
DocumentView *Editor::active_view()
|
||||
{
|
||||
return DocumentView::wrap(moo_editor_get_active_doc(moo_editor_instance()));
|
||||
}
|
||||
|
||||
/// @item Editor.set_active_view(view)
|
||||
/// makes @param{view} active
|
||||
void Editor::set_active_view(DocumentView &view)
|
||||
{
|
||||
moo_editor_set_active_doc(moo_editor_instance(), view.gobj());
|
||||
}
|
||||
|
||||
/// @item Editor.documents()
|
||||
/// returns list of all open documents
|
||||
VariantArray Editor::documents()
|
||||
{
|
||||
GSList *docs = moo_editor_list_docs(moo_editor_instance());
|
||||
return wrap_gslist<MooEdit, Document>(docs);
|
||||
}
|
||||
|
||||
/// @item Editor.views()
|
||||
/// returns list of all open document views
|
||||
VariantArray Editor::views()
|
||||
{
|
||||
GSList *docs = moo_editor_list_docs(moo_editor_instance());
|
||||
return wrap_gslist<MooEdit, DocumentView>(docs);
|
||||
MooEditArray *docs = moo_editor_get_docs(moo_editor_instance());
|
||||
VariantArray ret = wrap_array<MooEditArray, MooEdit, Document>(docs);
|
||||
moo_edit_array_free(docs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// @item Editor.windows()
|
||||
/// returns list of all document windows
|
||||
VariantArray Editor::windows()
|
||||
{
|
||||
GSList *windows = moo_editor_list_windows(moo_editor_instance());
|
||||
return wrap_gslist<MooEditWindow, DocumentWindow>(windows);
|
||||
MooEditWindowArray *windows = moo_editor_get_windows(moo_editor_instance());
|
||||
VariantArray ret = wrap_array<MooEditWindowArray, MooEditWindow, DocumentWindow>(windows);
|
||||
moo_edit_window_array_free(windows);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// @item Editor.new_document(window=null)
|
||||
@ -601,39 +596,37 @@ Document *Editor::get_document_by_uri(const String &uri)
|
||||
return Document::wrap(moo_editor_get_doc_for_uri(moo_editor_instance(), uri));
|
||||
}
|
||||
|
||||
static GSList *get_file_info_list(const Variant &val, bool uri)
|
||||
static MooFileEncArray *get_file_info_list(const Variant &val, bool uri)
|
||||
{
|
||||
moo::Vector<String> filenames = get_string_list(val);
|
||||
|
||||
if (filenames.empty())
|
||||
return NULL;
|
||||
|
||||
GSList *files = NULL;
|
||||
MooFileEncArray *files = moo_file_enc_array_new();
|
||||
|
||||
for (int i = 0, c = filenames.size(); i < c; ++i)
|
||||
{
|
||||
MooEditFileInfo *fi = uri ?
|
||||
moo_edit_file_info_new_uri(filenames[i], NULL) :
|
||||
moo_edit_file_info_new_path(filenames[i], NULL);
|
||||
if (!fi)
|
||||
MooFileEnc *fenc = uri ?
|
||||
moo_file_enc_new_for_uri(filenames[i], NULL) :
|
||||
moo_file_enc_new_for_path(filenames[i], NULL);
|
||||
if (!fenc)
|
||||
goto error;
|
||||
files = g_slist_prepend(files, fi);
|
||||
moo_file_enc_array_take(files, fenc);
|
||||
}
|
||||
|
||||
return g_slist_reverse(files);
|
||||
return files;
|
||||
|
||||
error:
|
||||
g_slist_foreach(files, (GFunc) moo_edit_file_info_free, NULL);
|
||||
g_slist_free(files);
|
||||
moo_file_enc_array_free(files);
|
||||
Error::raise("error");
|
||||
}
|
||||
|
||||
static void open_files_or_uris(const VariantArray &file_array, DocumentWindow *window, bool uri)
|
||||
{
|
||||
GSList *files = get_file_info_list(file_array, uri);
|
||||
MooFileEncArray *files = get_file_info_list(file_array, uri);
|
||||
moo_editor_open(moo_editor_instance(), window ? window->gobj() : NULL, NULL, files);
|
||||
g_slist_foreach(files, (GFunc) moo_edit_file_info_free, NULL);
|
||||
g_slist_free(files);
|
||||
moo_file_enc_array_free(files);
|
||||
}
|
||||
|
||||
/// @item Editor.open_files(files, window=null)
|
||||
@ -748,13 +741,12 @@ bool Editor::close_documents(const VariantArray &arr)
|
||||
for (int i = 0, c = arr.size(); i < c; ++i)
|
||||
pvec.append(get_object_arg<Document>(arr[i], "doc").gobj());
|
||||
|
||||
GSList *docs = NULL;
|
||||
MooEditArray *docs = moo_edit_array_new ();
|
||||
for (int i = 0, c = pvec.size(); i < c; ++i)
|
||||
docs = g_slist_prepend (docs, pvec[i]);
|
||||
docs = g_slist_reverse (docs);
|
||||
moo_edit_array_append (docs, pvec[i]);
|
||||
|
||||
bool retval = moo_editor_close_docs (moo_editor_instance(), docs, TRUE);
|
||||
g_slist_free (docs);
|
||||
moo_edit_array_free (docs);
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -788,50 +780,28 @@ Editor *DocumentWindow::editor()
|
||||
return &Editor::get_instance();
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.active_view()
|
||||
/// returns current active document view in this window.
|
||||
DocumentView *DocumentWindow::active_view()
|
||||
{
|
||||
return DocumentView::wrap(moo_edit_window_get_active_doc(gobj()));
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.set_active_view(view)
|
||||
/// makes @param{view} active, i.e. switches to its tab.
|
||||
void DocumentWindow::set_active_view(DocumentView &view)
|
||||
{
|
||||
moo_edit_window_set_active_doc(gobj(), view.gobj());
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.active_document()
|
||||
/// returns current active document in this window, that is the document
|
||||
/// whose view is the active one.
|
||||
/// returns current active document in this window.
|
||||
Document *DocumentWindow::active_document()
|
||||
{
|
||||
return Document::wrap(moo_edit_window_get_active_doc(gobj()));
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.set_active_document(doc)
|
||||
/// makes active a view of document @param{doc}. It picks arbitrary view
|
||||
/// of @param{doc} if there are more than one in this window.
|
||||
/// makes active document @param{doc}.
|
||||
void DocumentWindow::set_active_document(Document &doc)
|
||||
{
|
||||
moo_edit_window_set_active_doc(gobj(), doc.gobj());
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.views()
|
||||
/// returns list of all document views in this window.
|
||||
VariantArray DocumentWindow::views()
|
||||
{
|
||||
GSList *docs = moo_edit_window_list_docs(gobj());
|
||||
return wrap_gslist<MooEdit, DocumentView>(docs);
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.documents()
|
||||
/// returns list of all documents in this window.
|
||||
VariantArray DocumentWindow::documents()
|
||||
{
|
||||
GSList *docs = moo_edit_window_list_docs(gobj());
|
||||
return wrap_gslist<MooEdit, Document>(docs);
|
||||
MooEditArray *docs = moo_edit_window_get_docs(gobj());
|
||||
VariantArray ret = wrap_array<MooEditArray, MooEdit, Document>(docs);
|
||||
moo_edit_array_free(docs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// @item DocumentWindow.is_active()
|
||||
@ -852,84 +822,6 @@ void DocumentWindow::set_active()
|
||||
/// @end table
|
||||
///
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DocumentView
|
||||
//
|
||||
|
||||
///
|
||||
/// @node DocumentView object
|
||||
/// @section DocumentView object
|
||||
/// @helpsection{DOCUMENT_VIEW}
|
||||
/// @table @method
|
||||
///
|
||||
|
||||
/// @item DocumentView.document()
|
||||
/// returns document to which this view belongs.
|
||||
Document *DocumentView::document()
|
||||
{
|
||||
return Document::wrap(gobj());
|
||||
}
|
||||
|
||||
/// @item DocumentView.window()
|
||||
/// returns window which contains this view.
|
||||
DocumentWindow *DocumentView::window()
|
||||
{
|
||||
return DocumentWindow::wrap(moo_edit_get_window(gobj()));
|
||||
}
|
||||
|
||||
/// @item DocumentView.line_wrap_mode()
|
||||
/// returns whether line wrapping is enabled.
|
||||
bool DocumentView::line_wrap_mode()
|
||||
{
|
||||
GtkWrapMode mode;
|
||||
g_object_get(gobj(), "wrap-mode", &mode, (char*) NULL);
|
||||
return mode != GTK_WRAP_NONE;
|
||||
}
|
||||
|
||||
/// @item DocumentView.set_line_wrap_mode(enabled)
|
||||
/// enables or disables line wrapping.
|
||||
void DocumentView::set_line_wrap_mode(bool wrap)
|
||||
{
|
||||
moo_edit_ui_set_line_wrap_mode(gobj(), wrap);
|
||||
}
|
||||
|
||||
/// @item DocumentView.overwrite_mode()
|
||||
/// returns whether overwrite mode is on.
|
||||
bool DocumentView::overwrite_mode()
|
||||
{
|
||||
gboolean overwrite;
|
||||
g_object_get(gobj(), "overwrite", &overwrite, (char*) NULL);
|
||||
return overwrite;
|
||||
}
|
||||
|
||||
/// @item DocumentView.set_overwrite_mode(enabled)
|
||||
/// enables or disables overwrite mode.
|
||||
void DocumentView::set_overwrite_mode(bool overwrite)
|
||||
{
|
||||
g_object_set(gobj(), "overwrite", gboolean(overwrite), (char*) NULL);
|
||||
}
|
||||
|
||||
/// @item DocumentView.show_line_numbers()
|
||||
/// returns whether line numbers are displayed.
|
||||
bool DocumentView::show_line_numbers()
|
||||
{
|
||||
gboolean show;
|
||||
g_object_get(gobj(), "show-line-numbers", &show, (char*) NULL);
|
||||
return show;
|
||||
}
|
||||
|
||||
/// @item DocumentView.set_show_line_numbers(show)
|
||||
/// shows or hides line numbers.
|
||||
void DocumentView::set_show_line_numbers(bool show)
|
||||
{
|
||||
moo_edit_ui_set_show_line_numbers(gobj(), show);
|
||||
}
|
||||
|
||||
///
|
||||
/// @end table
|
||||
///
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Document
|
||||
@ -948,25 +840,6 @@ static GtkTextBuffer *buffer(Document *doc)
|
||||
return gtk_text_view_get_buffer(GTK_TEXT_VIEW(doc->gobj()));
|
||||
}
|
||||
|
||||
/// @item Document.views()
|
||||
/// returns list of views which display this document.
|
||||
VariantArray Document::views()
|
||||
{
|
||||
VariantArray views;
|
||||
views.append(HObject(*DocumentView::wrap(gobj())));
|
||||
return views;
|
||||
}
|
||||
|
||||
/// @item Document.active_view()
|
||||
/// returns active view of this document. If the document has a single
|
||||
/// view, then that is returned; otherwise if the current active view
|
||||
/// belongs to this document, then that view is returned; otherwise
|
||||
/// a random view is picked.
|
||||
DocumentView *Document::active_view()
|
||||
{
|
||||
return DocumentView::wrap(gobj());
|
||||
}
|
||||
|
||||
/// @item Document.filename()
|
||||
/// returns full file path of the document or @null{} if the document
|
||||
/// has not been saved yet or if it can't be represented with a local
|
||||
|
@ -15,13 +15,8 @@
|
||||
<method name='set_active_window'>
|
||||
<param name='window' type='DocumentWindow'/>
|
||||
</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='views' retval='list'/>
|
||||
<method name='windows' retval='list'/>
|
||||
|
||||
<method name='get_document_by_path' retval='Document'>
|
||||
@ -84,31 +79,14 @@
|
||||
|
||||
<class name='DocumentWindow' gobject='MooEditWindow'>
|
||||
<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='set_active_document' param-name='doc' param-type='Document'/>
|
||||
<method name='views' retval='list'/>
|
||||
<method name='documents' retval='list'/>
|
||||
<method name='is_active' retval='bool'/>
|
||||
<method name='set_active'/>
|
||||
</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'>
|
||||
<method name='views' retval='list'/>
|
||||
<method name='active_view' retval='DocumentView'/>
|
||||
|
||||
<method name='filename' retval='string'/>
|
||||
<method name='uri' retval='string'/>
|
||||
<method name='basename' retval='string'/>
|
||||
|
@ -50,6 +50,9 @@ moo_sources += \
|
||||
mooutils/moofileicon.h \
|
||||
mooutils/moofilewatch.c \
|
||||
mooutils/moofilewatch.h \
|
||||
mooutils/moofilewriter.c \
|
||||
mooutils/moofilewriter.h \
|
||||
mooutils/moofilewriter-private.h\
|
||||
mooutils/moofiltermgr.c \
|
||||
mooutils/moofiltermgr.h \
|
||||
mooutils/moofontsel.c \
|
||||
@ -105,7 +108,6 @@ moo_sources += \
|
||||
mooutils/mooutils-enums.h \
|
||||
mooutils/mooutils-file.c \
|
||||
mooutils/mooutils-file.h \
|
||||
mooutils/mooutils-file-private.h\
|
||||
mooutils/mooutils-fs.c \
|
||||
mooutils/mooutils-fs.h \
|
||||
mooutils/mooutils-gobject-private.h \
|
||||
|
@ -28,8 +28,6 @@ void _moo_sync_toggle_action (GtkAction *action,
|
||||
const char *prop,
|
||||
gboolean invert);
|
||||
|
||||
gpointer _moo_action_get_window (gpointer action);
|
||||
|
||||
/* defined in mooactionbase.c */
|
||||
gboolean _moo_action_get_dead (gpointer action);
|
||||
gboolean _moo_action_get_has_submenu (gpointer action);
|
||||
|
@ -86,6 +86,8 @@ GType moo_action_get_type (void) G_GNUC_CONST;
|
||||
GType moo_toggle_action_get_type (void) G_GNUC_CONST;
|
||||
GType moo_radio_action_get_type (void) G_GNUC_CONST;
|
||||
|
||||
gpointer _moo_action_get_window (gpointer action);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -3,23 +3,63 @@
|
||||
|
||||
#include <mooutils/mooutils-mem.h>
|
||||
|
||||
#define MOO_DEFINE_PTR_ARRAY(ArrayType, array_type, ElmType, \
|
||||
copy_elm, free_elm) \
|
||||
#define MOO_DECLARE_PTR_ARRAY(ArrayType, array_type, ElmType) \
|
||||
\
|
||||
typedef struct ArrayType ArrayType; \
|
||||
\
|
||||
struct ArrayType { \
|
||||
MOO_IP_ARRAY_ELMS (ElmType*, elms); \
|
||||
}; \
|
||||
\
|
||||
inline static ArrayType * \
|
||||
ArrayType *array_type##_new (void); \
|
||||
void array_type##_free (ArrayType *ar); \
|
||||
void array_type##_append (ArrayType *ar, ElmType *elm); \
|
||||
void array_type##_take (ArrayType *ar, ElmType *elm); \
|
||||
void array_type##_append_array (ArrayType *ar, ArrayType *ar2); \
|
||||
ArrayType *array_type##_copy (ArrayType *ar); \
|
||||
\
|
||||
typedef void (*ArrayType##Foreach) (ElmType *elm, \
|
||||
gpointer data); \
|
||||
\
|
||||
inline static void \
|
||||
array_type##_foreach (const ArrayType *ar, \
|
||||
ArrayType##Foreach func, \
|
||||
gpointer data) \
|
||||
{ \
|
||||
guint i; \
|
||||
g_return_if_fail (ar != NULL && func != NULL); \
|
||||
for (i = 0; i < ar->n_elms; ++i) \
|
||||
func (ar->elms[i], data); \
|
||||
} \
|
||||
\
|
||||
void array_type##_sort (ArrayType *ar, GCompareFunc func); \
|
||||
int array_type##_find (const ArrayType *ar, ElmType *elm); \
|
||||
void array_type##_remove (ArrayType *ar, ElmType *elm); \
|
||||
guint array_type##_insert_sorted (ArrayType *ar, ElmType *elm, \
|
||||
GCompareFunc func); \
|
||||
\
|
||||
inline static gboolean array_type##_is_empty (ArrayType *ar) \
|
||||
{ \
|
||||
return !ar || !ar->n_elms; \
|
||||
} \
|
||||
\
|
||||
inline static gsize array_type##_get_size (ArrayType *ar) \
|
||||
{ \
|
||||
return ar ? ar->n_elms : 0; \
|
||||
}
|
||||
|
||||
#define MOO_DEFINE_PTR_ARRAY(ArrayType, array_type, ElmType, \
|
||||
copy_elm, free_elm) \
|
||||
\
|
||||
ArrayType * \
|
||||
array_type##_new (void) \
|
||||
{ \
|
||||
ArrayType *ar = g_slice_new0 (ArrayType); \
|
||||
MOO_IP_ARRAY_INIT (ar, elms, 0); \
|
||||
MOO_IP_ARRAY_INIT (ElmType*, ar, elms, 0); \
|
||||
return ar; \
|
||||
} \
|
||||
\
|
||||
inline static void \
|
||||
void \
|
||||
array_type##_free (ArrayType *ar) \
|
||||
{ \
|
||||
if (ar) \
|
||||
@ -32,23 +72,36 @@ array_type##_free (ArrayType *ar) \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
inline static void \
|
||||
void \
|
||||
array_type##_append (ArrayType *ar, ElmType *elm) \
|
||||
{ \
|
||||
g_return_if_fail (ar != NULL && elm != NULL); \
|
||||
MOO_IP_ARRAY_GROW (ar, elms, 1); \
|
||||
MOO_IP_ARRAY_GROW (ElmType*, ar, elms, 1); \
|
||||
ar->elms[ar->n_elms - 1] = copy_elm (elm); \
|
||||
} \
|
||||
\
|
||||
inline static void \
|
||||
void array_type##_append_array (ArrayType *ar, ArrayType *ar2) \
|
||||
{ \
|
||||
guint i, old_size; \
|
||||
g_return_if_fail (ar != NULL && ar2 != NULL); \
|
||||
if (!ar2->n_elms) \
|
||||
return; \
|
||||
old_size = ar->n_elms; \
|
||||
MOO_IP_ARRAY_GROW (ElmType*, ar, elms, ar2->n_elms); \
|
||||
ar->n_elms += ar2->n_elms; \
|
||||
for (i = 0; i < ar2->n_elms; ++i) \
|
||||
ar->elms[old_size + i] = copy_elm (ar2->elms[i]); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
array_type##_take (ArrayType *ar, ElmType *elm) \
|
||||
{ \
|
||||
g_return_if_fail (ar != NULL && elm != NULL); \
|
||||
MOO_IP_ARRAY_GROW (ar, elms, 1); \
|
||||
MOO_IP_ARRAY_GROW (ElmType*, ar, elms, 1); \
|
||||
ar->elms[ar->n_elms - 1] = elm; \
|
||||
} \
|
||||
\
|
||||
inline static ArrayType * \
|
||||
ArrayType * \
|
||||
array_type##_copy (ArrayType *ar) \
|
||||
{ \
|
||||
ArrayType *copy; \
|
||||
@ -60,7 +113,7 @@ array_type##_copy (ArrayType *ar) \
|
||||
if (ar->n_elms) \
|
||||
{ \
|
||||
guint i; \
|
||||
MOO_IP_ARRAY_GROW (copy, elms, ar->n_elms); \
|
||||
MOO_IP_ARRAY_GROW (ElmType*, copy, elms, ar->n_elms); \
|
||||
for (i = 0; i < ar->n_elms; ++i) \
|
||||
copy->elms[i] = copy_elm (ar->elms[i]); \
|
||||
} \
|
||||
@ -68,39 +121,76 @@ array_type##_copy (ArrayType *ar) \
|
||||
return copy; \
|
||||
} \
|
||||
\
|
||||
typedef void (*ArrayType##ForeachFunc) (ElmType *elm, \
|
||||
gpointer data); \
|
||||
\
|
||||
inline static void \
|
||||
array_type##_foreach (ArrayType *ar, \
|
||||
ArrayType##ForeachFunc func, \
|
||||
gpointer data) \
|
||||
void array_type##_remove (ArrayType *ar, ElmType *elm) \
|
||||
{ \
|
||||
guint i; \
|
||||
g_return_if_fail (ar != NULL && func != NULL); \
|
||||
\
|
||||
g_return_if_fail (ar != NULL); \
|
||||
\
|
||||
for (i = 0; i < ar->n_elms; ++i) \
|
||||
func (ar->elms[i], data); \
|
||||
{ \
|
||||
if (ar->elms[i] == elm) \
|
||||
{ \
|
||||
MOO_IP_ARRAY_REMOVE_INDEX (ar, elms, i); \
|
||||
free_elm (elm); \
|
||||
return; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static int \
|
||||
array_type##_gcompare_data_func (gconstpointer a, \
|
||||
gconstpointer b, \
|
||||
gpointer user_data) \
|
||||
{ \
|
||||
GCompareFunc func = (GCompareFunc) user_data; \
|
||||
ElmType **ea = (ElmType **) a; \
|
||||
ElmType **eb = (ElmType **) b; \
|
||||
return func (*ea, *eb); \
|
||||
} \
|
||||
\
|
||||
void \
|
||||
array_type##_sort (ArrayType *ar, GCompareFunc func) \
|
||||
{ \
|
||||
g_return_if_fail (ar != NULL && func != NULL); \
|
||||
\
|
||||
if (ar->n_elms <= 1) \
|
||||
return; \
|
||||
\
|
||||
g_qsort_with_data (ar->elms, ar->n_elms, sizeof (*ar->elms), \
|
||||
array_type##_gcompare_data_func, \
|
||||
func); \
|
||||
} \
|
||||
\
|
||||
int array_type##_find (const ArrayType *ar, ElmType *elm) \
|
||||
{ \
|
||||
guint i; \
|
||||
g_return_val_if_fail (ar != NULL && elm != NULL, -1); \
|
||||
for (i = 0; i < ar->n_elms; ++i) \
|
||||
if (ar->elms[i] == elm) \
|
||||
return i; \
|
||||
return -1; \
|
||||
}
|
||||
|
||||
|
||||
#define MOO_DEFINE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \
|
||||
MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \
|
||||
g_object_ref, g_object_unref)
|
||||
#define MOO_DECLARE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \
|
||||
MOO_DECLARE_PTR_ARRAY (ArrayType, array_type, ElmType)
|
||||
|
||||
#define MOO_DEFINE_PTR_ARRAY_NO_COPY(ArrayType, array_type, ElmType) \
|
||||
inline static ElmType * \
|
||||
array_type##_dummy_copy_elm__ (ElmType *elm) \
|
||||
{ \
|
||||
return elm; \
|
||||
} \
|
||||
#define MOO_DEFINE_OBJECT_ARRAY(ArrayType, array_type, ElmType) \
|
||||
inline static ElmType * \
|
||||
array_type##_ref_elm__ (ElmType *elm) \
|
||||
{ \
|
||||
return (ElmType*) g_object_ref (elm); \
|
||||
} \
|
||||
\
|
||||
inline static void \
|
||||
array_type##_dummy_free_elm__ (G_GNUC_UNUSED ElmType *elm) \
|
||||
{ \
|
||||
} \
|
||||
inline static void \
|
||||
array_type##_unref_elm__ (ElmType *elm) \
|
||||
{ \
|
||||
g_object_unref (elm); \
|
||||
} \
|
||||
\
|
||||
MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \
|
||||
array_type##_dummy_copy_elm__, \
|
||||
array_type##_dummy_free_elm__)
|
||||
MOO_DEFINE_PTR_ARRAY (ArrayType, array_type, ElmType, \
|
||||
array_type##_ref_elm__, \
|
||||
array_type##_unref_elm__)
|
||||
|
||||
#endif /* MOO_ARRAY_H */
|
||||
|
@ -35,6 +35,15 @@ static GdkAtom name ## _atom (void)
|
||||
MOO_DEFINE_ATOM_ (Name) \
|
||||
}
|
||||
|
||||
#define MOO_DECLARE_ATOM_GLOBAL(Name, name) \
|
||||
GdkAtom name ## _atom (void) G_GNUC_CONST;
|
||||
|
||||
#define MOO_DEFINE_ATOM_GLOBAL(Name, name) \
|
||||
GdkAtom name ## _atom (void) \
|
||||
{ \
|
||||
MOO_DEFINE_ATOM_ (Name) \
|
||||
}
|
||||
|
||||
GdkAtom moo_atom_uri_list (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -333,15 +333,23 @@ moo_file_dialog (GtkWidget *parent,
|
||||
{
|
||||
static char *filename;
|
||||
MooFileDialog *dialog;
|
||||
GFile *start;
|
||||
GFile *file;
|
||||
|
||||
dialog = moo_file_dialog_new (type, parent, FALSE, title, start_dir, start_name);
|
||||
start = start_dir ? g_file_new_for_path (start_dir) : NULL;
|
||||
|
||||
dialog = moo_file_dialog_new (type, parent, FALSE, title, start, start_name);
|
||||
g_return_val_if_fail (dialog != NULL, NULL);
|
||||
|
||||
moo_file_dialog_run (dialog);
|
||||
|
||||
g_free (filename);
|
||||
filename = moo_file_dialog_get_filename (dialog);
|
||||
file = moo_file_dialog_get_file (dialog);
|
||||
|
||||
g_free (filename);
|
||||
filename = file ? g_file_get_path (file) : NULL;
|
||||
|
||||
g_object_unref (file);
|
||||
g_object_unref (start);
|
||||
g_object_unref (dialog);
|
||||
return filename;
|
||||
}
|
||||
@ -442,23 +450,20 @@ string_slist_to_strv (GSList *list)
|
||||
return uris;
|
||||
}
|
||||
|
||||
static char **
|
||||
uri_list_to_filenames (GSList *list)
|
||||
static MooFileArray *
|
||||
uri_list_to_files (GSList *list)
|
||||
{
|
||||
guint len, i;
|
||||
char **filenames;
|
||||
MooFileArray *flocs;
|
||||
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
len = g_slist_length (list);
|
||||
filenames = g_new (char*, len + 1);
|
||||
flocs = moo_file_array_new ();
|
||||
|
||||
for (i = 0; i < len; i++, list = list->next)
|
||||
filenames[i] = g_filename_from_uri ((const char*) list->data, NULL, NULL); /* XXX check */
|
||||
while (list)
|
||||
moo_file_array_take (flocs, g_file_new_for_uri (list->data));
|
||||
|
||||
filenames[i] = NULL;
|
||||
return filenames;
|
||||
return flocs;
|
||||
}
|
||||
|
||||
|
||||
@ -726,12 +731,11 @@ moo_file_dialog_set_extra_widget (MooFileDialog *dialog,
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
moo_file_dialog_get_filename (MooFileDialog *dialog)
|
||||
GFile *
|
||||
moo_file_dialog_get_file (MooFileDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL);
|
||||
return dialog->priv->uri ?
|
||||
g_filename_from_uri (dialog->priv->uri, NULL, NULL) : NULL;
|
||||
return dialog->priv->uri ? g_file_new_for_uri (dialog->priv->uri) : NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
@ -741,11 +745,11 @@ moo_file_dialog_get_uri (MooFileDialog *dialog)
|
||||
return g_strdup (dialog->priv->uri);
|
||||
}
|
||||
|
||||
char **
|
||||
moo_file_dialog_get_filenames (MooFileDialog *dialog)
|
||||
MooFileArray *
|
||||
moo_file_dialog_get_files (MooFileDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_FILE_DIALOG (dialog), NULL);
|
||||
return uri_list_to_filenames (dialog->priv->uris);
|
||||
return uri_list_to_files (dialog->priv->uris);
|
||||
}
|
||||
|
||||
char **
|
||||
@ -808,14 +812,14 @@ moo_file_dialog_new (MooFileDialogType type,
|
||||
GtkWidget *parent,
|
||||
gboolean multiple,
|
||||
const char *title,
|
||||
const char *start_dir,
|
||||
GFile *start_loc,
|
||||
const char *start_name)
|
||||
{
|
||||
char *start_dir_uri = NULL;
|
||||
MooFileDialog *dialog;
|
||||
|
||||
if (start_dir)
|
||||
start_dir_uri = g_filename_to_uri (start_dir, NULL, NULL);
|
||||
if (start_loc)
|
||||
start_dir_uri = g_file_get_uri (start_loc);
|
||||
|
||||
dialog = MOO_FILE_DIALOG (
|
||||
g_object_new (MOO_TYPE_FILE_DIALOG,
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define MOO_FILE_DIALOG_H
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <mooutils/mooutils-file.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -62,14 +63,14 @@ MooFileDialog *moo_file_dialog_new (MooFileDialogType type,
|
||||
GtkWidget *parent,
|
||||
gboolean multiple,
|
||||
const char *title,
|
||||
const char *start_dir,
|
||||
GFile *start_loc,
|
||||
const char *start_name);
|
||||
void moo_file_dialog_set_filter_mgr_id (MooFileDialog *dialog,
|
||||
const char *id);
|
||||
|
||||
gboolean moo_file_dialog_run (MooFileDialog *dialog);
|
||||
char *moo_file_dialog_get_filename (MooFileDialog *dialog);
|
||||
char **moo_file_dialog_get_filenames (MooFileDialog *dialog);
|
||||
GFile *moo_file_dialog_get_file (MooFileDialog *dialog);
|
||||
MooFileArray *moo_file_dialog_get_files (MooFileDialog *dialog);
|
||||
char *moo_file_dialog_get_uri (MooFileDialog *dialog);
|
||||
char **moo_file_dialog_get_uris (MooFileDialog *dialog);
|
||||
|
||||
|
@ -49,7 +49,7 @@ moo_file_icon_for_file (MooFileIcon *icon,
|
||||
}
|
||||
|
||||
GdkPixbuf *
|
||||
moo_get_icon_for_file (const char *path,
|
||||
moo_get_icon_for_path (const char *path,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size)
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define MOO_FILE_ICON_H
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <mooutils/mooutils-file.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -55,7 +56,7 @@ GdkPixbuf *moo_file_icon_get_pixbuf (MooFileIcon *icon,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size);
|
||||
/* needs gtk lock */
|
||||
GdkPixbuf *moo_get_icon_for_file (const char *path,
|
||||
GdkPixbuf *moo_get_icon_for_path (const char *path,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size);
|
||||
|
||||
|
0
moo/mooutils/moofileloc.c
Normal file
0
moo/mooutils/moofileloc.c
Normal file
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* mooutils-file-private.h
|
||||
* moofilewriter-private.h
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef MOO_UTILS_FILE_PRIVATE_H
|
||||
#define MOO_UTILS_FILE_PRIVATE_H
|
||||
#ifndef MOO_FILE_WRITER_PRIVATE_H
|
||||
#define MOO_FILE_WRITER_PRIVATE_H
|
||||
|
||||
#include "mooutils/mooutils-file.h"
|
||||
#include "mooutils/moofilewriter.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -82,4 +82,4 @@ struct MooStringWriterClass {
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_UTILS_FILE_PRIVATE_H */
|
||||
#endif /* MOO_FILE_WRITER_PRIVATE_H */
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* mooutils-file.c
|
||||
* moofilewriter.c
|
||||
*
|
||||
* Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@sourceforge.net>
|
||||
*
|
||||
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "mooutils/mooutils-file-private.h"
|
||||
#include "mooutils/moofilewriter-private.h"
|
||||
#include "mooutils/mootype-macros.h"
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
|
@ -13,10 +13,9 @@
|
||||
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MOO_UTILS_FILE_H
|
||||
#define MOO_UTILS_FILE_H
|
||||
#ifndef MOO_FILE_WRITER_H
|
||||
#define MOO_FILE_WRITER_H
|
||||
|
||||
#include <mooutils/moofileloc.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@ -70,4 +69,4 @@ const char *moo_string_writer_get_string (MooFileWriter *writer,
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* MOO_UTILS_FILE_H */
|
||||
#endif /* MOO_FILE_WRITER_H */
|
||||
|
@ -16,7 +16,7 @@
|
||||
#ifndef MOO_MARKUP_H
|
||||
#define MOO_MARKUP_H
|
||||
|
||||
#include <mooutils/mooutils-file.h>
|
||||
#include <mooutils/moofilewriter.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -981,6 +981,13 @@ moo_prefs_get_filename (const char *key)
|
||||
return val;
|
||||
}
|
||||
|
||||
GFile *
|
||||
moo_prefs_get_file (const char *key)
|
||||
{
|
||||
const char *uri = moo_prefs_get_string (key);
|
||||
return uri ? g_file_new_for_uri (uri) : NULL;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
moo_prefs_get_bool (const char *key)
|
||||
@ -1056,6 +1063,25 @@ moo_prefs_set_filename (const char *key,
|
||||
g_free (utf8_val);
|
||||
}
|
||||
|
||||
void
|
||||
moo_prefs_set_file (const char *key,
|
||||
GFile *val)
|
||||
{
|
||||
char *uri;
|
||||
|
||||
g_return_if_fail (key != NULL);
|
||||
|
||||
if (!val)
|
||||
{
|
||||
moo_prefs_set_string (key, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
uri = g_file_get_uri (val);
|
||||
moo_prefs_set_string (key, uri);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_prefs_set_int (const char *key,
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <mooutils/moomarkup.h>
|
||||
#include <mooutils/mooutils-file.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -73,6 +74,7 @@ char *moo_prefs_make_keyv (const char *first_comp,
|
||||
|
||||
const char *moo_prefs_get_string (const char *key);
|
||||
const char *moo_prefs_get_filename (const char *key);
|
||||
GFile *moo_prefs_get_file (const char *key);
|
||||
gboolean moo_prefs_get_bool (const char *key);
|
||||
int moo_prefs_get_int (const char *key);
|
||||
|
||||
@ -80,6 +82,8 @@ void moo_prefs_set_string (const char *key,
|
||||
const char *val);
|
||||
void moo_prefs_set_filename (const char *key,
|
||||
const char *val);
|
||||
void moo_prefs_set_file (const char *key,
|
||||
GFile *val);
|
||||
void moo_prefs_set_int (const char *key,
|
||||
int val);
|
||||
void moo_prefs_set_bool (const char *key,
|
||||
|
28
moo/mooutils/mooutils-file.c
Normal file
28
moo/mooutils/mooutils-file.c
Normal 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);
|
||||
}
|
24
moo/mooutils/mooutils-file.h
Normal file
24
moo/mooutils/mooutils-file.h
Normal 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 */
|
@ -44,12 +44,13 @@ G_STMT_START { \
|
||||
gsize n_##name_; \
|
||||
gsize n_##name_##_allocd__
|
||||
|
||||
#define MOO_IP_ARRAY_INIT(c_,name_,len_) \
|
||||
#define MOO_IP_ARRAY_INIT(ElmType,c_,name_,len_) \
|
||||
G_STMT_START { \
|
||||
gsize use_len__ = len_; \
|
||||
if (use_len__ == 0) \
|
||||
use_len__ = 2; \
|
||||
(c_)->name_ = g_malloc0 (use_len__ * sizeof *(c_)->name_); \
|
||||
(c_)->name_ = (ElmType*) \
|
||||
g_malloc0 (use_len__ * sizeof *(c_)->name_); \
|
||||
(c_)->n_##name_ = len_; \
|
||||
(c_)->n_##name_##_allocd__ = use_len__; \
|
||||
} G_STMT_END
|
||||
@ -60,14 +61,14 @@ G_STMT_START { \
|
||||
(c_)->name_ = NULL; \
|
||||
} G_STMT_END
|
||||
|
||||
#define MOO_IP_ARRAY_GROW(c_,name_,howmuch_) \
|
||||
#define MOO_IP_ARRAY_GROW(ElmType,c_,name_,howmuch_) \
|
||||
G_STMT_START { \
|
||||
if ((c_)->n_##name_ + howmuch_ > (c_)->n_##name_##_allocd__) \
|
||||
{ \
|
||||
gsize old_size__ = (c_)->n_##name_##_allocd__; \
|
||||
gsize new_size__ = MAX(old_size__ * 1.2, \
|
||||
(c_)->n_##name_ + howmuch_); \
|
||||
(c_)->name_ = g_realloc ((c_)->name_, \
|
||||
(c_)->name_ = (ElmType*) g_realloc ((c_)->name_, \
|
||||
new_size__ * sizeof *(c_)->name_); \
|
||||
(c_)->n_##name_##_allocd__ = new_size__; \
|
||||
} \
|
||||
@ -77,5 +78,16 @@ G_STMT_START { \
|
||||
(c_)->n_##name_ += howmuch_; \
|
||||
} G_STMT_END
|
||||
|
||||
#define MOO_IP_ARRAY_REMOVE_INDEX(c_,name_,idx_) \
|
||||
G_STMT_START { \
|
||||
gsize idx__ = idx_; \
|
||||
g_assert ((c_)->n_##name_ > 0 && idx__ < (c_)->n_##name_); \
|
||||
if (idx__ + 1 < (c_)->n_##name_) \
|
||||
MOO_ELMMOVE ((c_)->name_ + idx__, \
|
||||
(c_)->name_ + idx__ + 1, \
|
||||
(c_)->n_##name_ - idx__ - 1); \
|
||||
(c_)->n_##name_ -= 1; \
|
||||
} G_STMT_END
|
||||
|
||||
|
||||
#endif /* MOO_UTILS_MEM_H */
|
||||
|
@ -153,6 +153,30 @@ do { \
|
||||
|
||||
#define moo_return_if_reached() moo_return_val_if_reached(;)
|
||||
|
||||
|
||||
GQuark moo_error_quark (void) G_GNUC_CONST;
|
||||
|
||||
#define MOO_ERROR (moo_error_quark ())
|
||||
|
||||
enum {
|
||||
MOO_ERROR_UNEXPECTED = 1
|
||||
};
|
||||
|
||||
#define moo_return_error_if_fail(cond) \
|
||||
do { \
|
||||
if (cond) \
|
||||
{ \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
moo_critical("Condition '%s' failed", #cond); \
|
||||
g_set_error (error, MOO_ERROR, MOO_ERROR_UNEXPECTED,\
|
||||
"unexpected error"); \
|
||||
return FALSE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/*
|
||||
* Suppress warnings when GCC is in -pedantic mode and not -std=c99
|
||||
*/
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "config.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/mooutils-file.h"
|
||||
#include "mooutils/moofilewriter.h"
|
||||
#include "mooutils/mooutils-debug.h"
|
||||
#include "mooutils/mooi18n.h"
|
||||
#include "mooutils/mooatom.h"
|
||||
@ -24,6 +24,7 @@
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include <mooutils/mooutils-tests.h>
|
||||
#include "mooutils/moocompat.h"
|
||||
#include "mooutils/mootype-macros.h"
|
||||
#include "moologwindow-gxml.h"
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gmappedfile.h>
|
||||
@ -52,6 +53,7 @@
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
|
||||
MOO_DEFINE_QUARK (moo-error, moo_error_quark)
|
||||
|
||||
G_LOCK_DEFINE_STATIC (moo_user_data_dir);
|
||||
static char *moo_app_instance_name;
|
||||
|
8
moo/mooutils/mooutils.h
Normal file
8
moo/mooutils/mooutils.h
Normal 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 */
|
@ -350,6 +350,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
|
||||
{
|
||||
MooEdit *doc;
|
||||
char *filename;
|
||||
GFile *file;
|
||||
|
||||
plugin->priv->update_idle = 0;
|
||||
|
||||
@ -357,7 +358,8 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
|
||||
|
||||
doc = MOO_DOC_PLUGIN (plugin)->doc;
|
||||
|
||||
filename = moo_edit_get_filename (doc);
|
||||
file = moo_edit_get_file (doc);
|
||||
filename = file ? g_file_get_path (file) : NULL;
|
||||
|
||||
if (filename && !g_file_test (filename, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
@ -368,7 +370,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
|
||||
if (filename)
|
||||
{
|
||||
GSList *list = NULL;
|
||||
MooLang *lang = moo_text_view_get_lang (MOO_TEXT_VIEW (doc));
|
||||
MooLang *lang = moo_edit_get_lang (doc);
|
||||
MooCtagsLanguage *ctags_lang = _moo_ctags_language_find_for_name (_moo_lang_id (lang));
|
||||
|
||||
if (ctags_lang && (list = moo_ctags_parse_file (filename, ctags_lang->opts)))
|
||||
@ -381,6 +383,7 @@ moo_ctags_doc_plugin_update (MooCtagsDocPlugin *plugin)
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
moo_file_free (file);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ ctags_plugin_deinit (G_GNUC_UNUSED CtagsPlugin *plugin)
|
||||
MOO_PLUGIN_DEFINE_INFO (ctags, "Ctags", "Shows functions in the open document",
|
||||
"Yevgen Muntyan <emuntyan@sourceforge.net>\n"
|
||||
"Christian Dywan <christian@twotoasts.de>",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
MOO_WIN_PLUGIN_DEFINE (Ctags, ctags)
|
||||
MOO_PLUGIN_DEFINE (Ctags, ctags,
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
|
@ -2217,15 +2217,23 @@ compare_docs_by_name (MooEdit *doc1,
|
||||
static gboolean
|
||||
do_update (WindowPlugin *plugin)
|
||||
{
|
||||
GSList *docs;
|
||||
MooEditArray *docs;
|
||||
GSList *list;
|
||||
guint i;
|
||||
|
||||
plugin->update_idle = 0;
|
||||
|
||||
docs = moo_edit_window_list_docs (MOO_WIN_PLUGIN (plugin)->window);
|
||||
docs = g_slist_sort (docs, (GCompareFunc) compare_docs_by_name);
|
||||
file_list_update (plugin->list, docs);
|
||||
g_slist_free (docs);
|
||||
docs = moo_edit_window_get_docs (MOO_WIN_PLUGIN (plugin)->window);
|
||||
|
||||
for (i = 0, list = NULL; i < docs->n_elms; ++i)
|
||||
list = g_slist_prepend (list, docs->elms[i]);
|
||||
|
||||
list = g_slist_sort (list, (GCompareFunc) compare_docs_by_name);
|
||||
|
||||
file_list_update (plugin->list, list);
|
||||
|
||||
g_slist_free (list);
|
||||
moo_edit_array_free (docs);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -2405,7 +2413,7 @@ file_list_plugin_deinit (G_GNUC_UNUSED FileListPlugin *plugin)
|
||||
MOO_PLUGIN_DEFINE_INFO (file_list,
|
||||
N_("File List"), N_("List of files"),
|
||||
"Yevgen Muntyan <emuntyan@sourceforge.net>",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
MOO_WIN_PLUGIN_DEFINE (FileList, file_list)
|
||||
MOO_PLUGIN_DEFINE (FileList, file_list,
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
|
@ -19,13 +19,15 @@
|
||||
|
||||
#include "moofileselector.h"
|
||||
#include "mooedit/mooplugin-macro.h"
|
||||
#include "mooedit/mooeditwindow.h"
|
||||
#include "moofileview/moobookmarkmgr.h"
|
||||
#include "moofileview/moofileview-tools.h"
|
||||
#include "mooeditplugins.h"
|
||||
#include "marshals.h"
|
||||
#include "mooutils/moostock.h"
|
||||
#include "mooutils/mooprefs.h"
|
||||
#include "mooutils/mooutils-fs.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mooutils.h"
|
||||
#include "mooutils/mooentry.h"
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooutils/mooactionfactory.h"
|
||||
@ -64,7 +66,7 @@ enum {
|
||||
};
|
||||
|
||||
static GtkTargetEntry targets[] = {
|
||||
{ (char*) "MOO_EDIT_TAB", GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB },
|
||||
{ (char*) MOO_EDIT_TAB_ATOM_NAME, GTK_TARGET_SAME_APP, TARGET_MOO_EDIT_TAB },
|
||||
{ (char*) "text/uri-list", 0, TARGET_URI_LIST }
|
||||
};
|
||||
|
||||
@ -72,66 +74,65 @@ static GtkTargetEntry targets[] = {
|
||||
|
||||
G_DEFINE_TYPE (MooFileSelector, _moo_file_selector, MOO_TYPE_FILE_VIEW)
|
||||
|
||||
#define MOO_EDIT_TAB_ATOM (moo_edit_tab_atom ())
|
||||
MOO_DEFINE_ATOM (MOO_EDIT_TAB, moo_edit_tab)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_WINDOW
|
||||
};
|
||||
|
||||
|
||||
static void moo_file_selector_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void moo_file_selector_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static GObject *moo_file_selector_constructor (GType type,
|
||||
guint n_props,
|
||||
static void moo_file_selector_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void moo_file_selector_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static GObject *moo_file_selector_constructor (GType type,
|
||||
guint n_props,
|
||||
GObjectConstructParam *props);
|
||||
static void moo_file_selector_finalize (GObject *object);
|
||||
static void moo_file_selector_finalize (GObject *object);
|
||||
|
||||
static void moo_file_selector_select_file (MooFileSelector *filesel,
|
||||
const char *filename);
|
||||
static gboolean moo_file_selector_chdir (MooFileView *fileview,
|
||||
const char *dir,
|
||||
GError **error);
|
||||
static void moo_file_selector_activate (MooFileView *fileview,
|
||||
const char *path);
|
||||
static void moo_file_selector_populate_popup(MooFileView *fileview,
|
||||
GList *selected,
|
||||
GtkMenu *menu);
|
||||
static void moo_file_selector_select_file (MooFileSelector *filesel,
|
||||
GFile *file);
|
||||
static void moo_file_selector_select_path (MooFileSelector *filesel,
|
||||
const char *filename);
|
||||
static gboolean moo_file_selector_chdir (MooFileView *fileview,
|
||||
const char *dir,
|
||||
GError **error);
|
||||
static void moo_file_selector_activate (MooFileView *fileview,
|
||||
const char *path);
|
||||
static void moo_file_selector_populate_popup(MooFileView *fileview,
|
||||
GList *selected,
|
||||
GtkMenu *menu);
|
||||
|
||||
static void goto_current_doc_dir (MooFileSelector *filesel);
|
||||
static void goto_current_doc_dir (MooFileSelector *filesel);
|
||||
|
||||
static gboolean moo_file_selector_drop (MooFileView *fileview,
|
||||
const char *path,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
guint time);
|
||||
static gboolean moo_file_selector_drop_data_received (MooFileView *fileview,
|
||||
const char *path,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
GtkSelectionData *data,
|
||||
guint info,
|
||||
guint time);
|
||||
static gboolean moo_file_selector_drop (MooFileView *fileview,
|
||||
const char *path,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
guint time);
|
||||
static gboolean moo_file_selector_drop_data_received (MooFileView *fileview,
|
||||
const char *path,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
GtkSelectionData *data,
|
||||
guint info,
|
||||
guint time);
|
||||
|
||||
static void moo_file_selector_drop_doc (MooFileSelector *filesel,
|
||||
MooEdit *doc,
|
||||
const char *destdir,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
guint time);
|
||||
static void moo_file_selector_drop_doc (MooFileSelector *filesel,
|
||||
MooEdit *doc,
|
||||
const char *destdir,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
guint time);
|
||||
|
||||
|
||||
static void
|
||||
@ -151,13 +152,9 @@ _moo_file_selector_class_init (MooFileSelectorClass *klass)
|
||||
fileview_class->drop_data_received = moo_file_selector_drop_data_received;
|
||||
fileview_class->populate_popup = moo_file_selector_populate_popup;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_WINDOW,
|
||||
g_param_spec_object ("window",
|
||||
"window",
|
||||
"window",
|
||||
MOO_TYPE_EDIT_WINDOW,
|
||||
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
|
||||
g_object_class_install_property (gobject_class, PROP_WINDOW,
|
||||
g_param_spec_object ("window", "window", "window",
|
||||
MOO_TYPE_EDIT_WINDOW, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
|
||||
_moo_signal_new_cb ("goto-current-doc-dir",
|
||||
G_OBJECT_CLASS_TYPE (klass),
|
||||
@ -234,17 +231,11 @@ static void
|
||||
file_selector_go_home (MooFileView *fileview)
|
||||
{
|
||||
const char *dir;
|
||||
char *real_dir = NULL;
|
||||
|
||||
dir = moo_prefs_get_string (DIR_PREFS);
|
||||
dir = moo_prefs_get_filename (DIR_PREFS);
|
||||
|
||||
if (dir)
|
||||
real_dir = g_filename_from_utf8 (dir, -1, NULL, NULL, NULL);
|
||||
|
||||
if (!real_dir || !moo_file_view_chdir (fileview, real_dir, NULL))
|
||||
if (!dir || !moo_file_view_chdir_path (fileview, dir, NULL))
|
||||
g_signal_emit_by_name (fileview, "go-home");
|
||||
|
||||
g_free (real_dir);
|
||||
}
|
||||
|
||||
|
||||
@ -323,19 +314,16 @@ static void
|
||||
goto_current_doc_dir (MooFileSelector *filesel)
|
||||
{
|
||||
MooEdit *doc;
|
||||
char *filename;
|
||||
GFile *file, *parent_file;
|
||||
GError *error = NULL;
|
||||
|
||||
doc = moo_edit_window_get_active_doc (filesel->window);
|
||||
filename = doc ? moo_edit_get_filename (doc) : NULL;
|
||||
file = doc ? moo_edit_get_file (doc) : NULL;
|
||||
parent_file = file ? g_file_get_parent (file) : NULL;
|
||||
|
||||
if (filename)
|
||||
{
|
||||
char *dirname = g_path_get_dirname (filename);
|
||||
if (moo_file_view_chdir (MOO_FILE_VIEW (filesel), dirname, &error))
|
||||
moo_file_selector_select_file (filesel, filename);
|
||||
g_free (dirname);
|
||||
}
|
||||
if (parent_file)
|
||||
if (moo_file_view_chdir (MOO_FILE_VIEW (filesel), parent_file, &error))
|
||||
moo_file_selector_select_file (filesel, file);
|
||||
|
||||
if (error)
|
||||
{
|
||||
@ -343,7 +331,8 @@ goto_current_doc_dir (MooFileSelector *filesel)
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
g_object_unref (parent_file);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
|
||||
@ -678,7 +667,7 @@ moo_file_selector_drop (MooFileView *fileview,
|
||||
|
||||
|
||||
static gboolean
|
||||
moo_file_selector_drop_data_received (MooFileView *fileview,
|
||||
moo_file_selector_drop_data_received (MooFileView *fileview,
|
||||
const char *path,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
@ -841,7 +830,7 @@ out:
|
||||
|
||||
|
||||
static void
|
||||
moo_file_selector_select_file (MooFileSelector *filesel,
|
||||
moo_file_selector_select_path (MooFileSelector *filesel,
|
||||
const char *filename)
|
||||
{
|
||||
char *basename;
|
||||
@ -854,12 +843,21 @@ moo_file_selector_select_file (MooFileSelector *filesel,
|
||||
g_free (basename);
|
||||
}
|
||||
|
||||
static void
|
||||
moo_file_selector_select_file (MooFileSelector *filesel,
|
||||
GFile *file)
|
||||
{
|
||||
char *filename = g_file_get_path (file);
|
||||
moo_file_selector_select_path (filesel, filename);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
drop_untitled (MooFileSelector *filesel,
|
||||
MooEdit *doc,
|
||||
const char *destdir,
|
||||
GtkWidget *widget,
|
||||
MooEdit *doc,
|
||||
const char *destdir,
|
||||
GtkWidget *widget,
|
||||
G_GNUC_UNUSED GdkDragContext *context,
|
||||
G_GNUC_UNUSED int x,
|
||||
G_GNUC_UNUSED int y,
|
||||
@ -878,7 +876,7 @@ drop_untitled (MooFileSelector *filesel,
|
||||
result = moo_edit_save_as (doc, name, NULL, NULL);
|
||||
|
||||
if (result)
|
||||
moo_file_selector_select_file (filesel, name);
|
||||
moo_file_selector_select_path (filesel, name);
|
||||
|
||||
g_free (name);
|
||||
return result;
|
||||
@ -899,8 +897,8 @@ doc_save_as (MooFileSelector *filesel,
|
||||
|
||||
if (filename)
|
||||
{
|
||||
if (moo_edit_save_as (doc, filename, moo_edit_get_encoding (doc), NULL))
|
||||
moo_file_selector_select_file (filesel, filename);
|
||||
if (moo_edit_save_as (doc, filename, NULL, NULL))
|
||||
moo_file_selector_select_path (filesel, filename);
|
||||
g_free (filename);
|
||||
}
|
||||
}
|
||||
@ -919,8 +917,8 @@ doc_save_copy (MooFileSelector *filesel,
|
||||
|
||||
if (filename)
|
||||
{
|
||||
if (moo_edit_save_copy (doc, filename, moo_edit_get_encoding (doc), NULL))
|
||||
moo_file_selector_select_file (filesel, filename);
|
||||
if (moo_edit_save_copy (doc, filename, NULL, NULL))
|
||||
moo_file_selector_select_path (filesel, filename);
|
||||
g_free (filename);
|
||||
}
|
||||
}
|
||||
@ -931,11 +929,11 @@ doc_move (MooFileSelector *filesel,
|
||||
gboolean ask_name,
|
||||
const char *destdir)
|
||||
{
|
||||
char *filename, *old_filename;
|
||||
GFile *old_file;
|
||||
char *filename;
|
||||
|
||||
old_filename = moo_edit_get_filename (doc);
|
||||
/* XXX non-local */
|
||||
g_return_if_fail (old_filename != NULL);
|
||||
old_file = moo_edit_get_file (doc);
|
||||
g_return_if_fail (old_file != NULL);
|
||||
|
||||
filename = save_as_dialog (GTK_WIDGET (filesel), destdir,
|
||||
moo_edit_get_display_basename (doc),
|
||||
@ -943,16 +941,16 @@ doc_move (MooFileSelector *filesel,
|
||||
|
||||
if (filename)
|
||||
{
|
||||
if (moo_edit_save_as (doc, filename, moo_edit_get_encoding (doc), NULL))
|
||||
if (moo_edit_save_as (doc, filename, NULL, NULL))
|
||||
{
|
||||
_moo_unlink (old_filename);
|
||||
moo_file_selector_select_file (filesel, filename);
|
||||
g_file_delete (old_file, NULL, NULL);
|
||||
moo_file_selector_select_path (filesel, filename);
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
g_free (old_filename);
|
||||
g_object_unref (old_file);
|
||||
}
|
||||
|
||||
|
||||
@ -1122,13 +1120,13 @@ create_drop_doc_menu (MooFileSelector *filesel,
|
||||
|
||||
static void
|
||||
moo_file_selector_drop_doc (MooFileSelector *filesel,
|
||||
MooEdit *doc,
|
||||
const char *destdir,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
guint time)
|
||||
MooEdit *doc,
|
||||
const char *destdir,
|
||||
GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
int x,
|
||||
int y,
|
||||
guint time)
|
||||
{
|
||||
GdkModifierType mods;
|
||||
DropDocAction action;
|
||||
@ -1210,12 +1208,9 @@ static void
|
||||
file_selector_plugin_attach (MooPlugin *mplugin,
|
||||
MooEditWindow *window)
|
||||
{
|
||||
MooEditor *editor;
|
||||
GtkWidget *filesel;
|
||||
Plugin *plugin = FILE_SELECTOR_PLUGIN (mplugin);
|
||||
|
||||
editor = moo_edit_window_get_editor (window);
|
||||
|
||||
if (!plugin->bookmark_mgr)
|
||||
plugin->bookmark_mgr = _moo_bookmark_mgr_new ();
|
||||
|
||||
@ -1256,7 +1251,7 @@ MOO_PLUGIN_DEFINE_INFO (file_selector,
|
||||
N_("File Selector"),
|
||||
N_("File selector pane for editor window"),
|
||||
"Yevgen Muntyan <emuntyan@sourceforge.net>",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
MOO_PLUGIN_DEFINE (FileSelector, file_selector,
|
||||
file_selector_plugin_attach, file_selector_plugin_detach,
|
||||
NULL, NULL,
|
||||
|
@ -244,7 +244,6 @@ find_plugin_init (FindPlugin *plugin)
|
||||
MooUiXml *xml = moo_editor_get_ui_xml (editor);
|
||||
|
||||
g_return_val_if_fail (klass != NULL, FALSE);
|
||||
g_return_val_if_fail (editor != NULL, FALSE);
|
||||
|
||||
moo_window_class_new_action (klass, "FindInFiles", NULL,
|
||||
"display-name", _("Find In Files"),
|
||||
@ -343,8 +342,8 @@ init_skip_list (void)
|
||||
}
|
||||
|
||||
static void
|
||||
create_grep_dialog (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
create_grep_dialog (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
{
|
||||
GtkWidget *pattern_entry;
|
||||
|
||||
@ -388,8 +387,8 @@ create_grep_dialog (MooEditWindow *window,
|
||||
|
||||
|
||||
static void
|
||||
create_find_dialog (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
create_find_dialog (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
{
|
||||
GtkWidget *pattern_entry;
|
||||
|
||||
@ -443,11 +442,13 @@ init_dir_entry (MooHistoryCombo *hist_combo,
|
||||
if (!gtk_entry_get_text (GTK_ENTRY (entry))[0])
|
||||
{
|
||||
MooFileEntryCompletion *completion;
|
||||
GFile *file;
|
||||
char *filename;
|
||||
|
||||
completion = g_object_get_data (G_OBJECT (entry), "find-plugin-file-completion");
|
||||
|
||||
filename = doc ? moo_edit_get_filename (doc) : NULL;
|
||||
file = doc ? moo_edit_get_file (doc) : NULL;
|
||||
filename = file ? g_file_get_path (file) : NULL;
|
||||
|
||||
if (filename)
|
||||
{
|
||||
@ -461,6 +462,7 @@ init_dir_entry (MooHistoryCombo *hist_combo,
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
g_object_unref (file);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -556,8 +558,8 @@ get_directories (MooHistoryCombo *combo)
|
||||
|
||||
|
||||
static void
|
||||
do_grep (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
do_grep (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
{
|
||||
GtkWidget *pane;
|
||||
MooHistoryCombo *pattern_combo, *skip_combo, *glob_combo;
|
||||
@ -604,8 +606,8 @@ do_grep (MooEditWindow *window,
|
||||
|
||||
|
||||
static void
|
||||
do_find (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
do_find (MooEditWindow *window,
|
||||
WindowStuff *stuff)
|
||||
{
|
||||
GtkWidget *pane;
|
||||
MooHistoryCombo *pattern_combo, *skip_combo;
|
||||
@ -1100,8 +1102,7 @@ output_activate (WindowStuff *stuff,
|
||||
return FALSE;
|
||||
|
||||
editor = moo_edit_window_get_editor (stuff->window);
|
||||
moo_editor_open_file_line (editor, line_data->filename,
|
||||
line_data->line, stuff->window);
|
||||
moo_editor_open_file_line (editor, line_data->filename, line_data->line, stuff->window);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -1110,7 +1111,7 @@ output_activate (WindowStuff *stuff,
|
||||
MOO_PLUGIN_DEFINE_INFO (find,
|
||||
N_("Find"), N_("Finds everything"),
|
||||
"Yevgen Muntyan <emuntyan@sourceforge.net>",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
MOO_WIN_PLUGIN_DEFINE (Find, find)
|
||||
MOO_PLUGIN_DEFINE (Find, find,
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
|
@ -109,7 +109,7 @@ load_lua_module (const char *module_file,
|
||||
MOO_PLUGIN_DEFINE_INFO (moo_lua,
|
||||
N_("Lua"), N_("Lua support"),
|
||||
"Yevgen Muntyan <" MOO_EMAIL ">",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
MOO_PLUGIN_DEFINE (MooLua, moo_lua,
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
0, 0)
|
||||
|
@ -57,7 +57,7 @@ load_python_module (const char *module_file,
|
||||
MOO_PLUGIN_DEFINE_INFO (moo_python,
|
||||
N_("Python"), N_("Python support"),
|
||||
"Yevgen Muntyan <" MOO_EMAIL ">",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
MOO_PLUGIN_DEFINE (MooPython, moo_python,
|
||||
NULL, NULL, NULL, NULL, NULL,
|
||||
0, 0)
|
||||
|
@ -432,7 +432,8 @@ static gboolean
|
||||
save_all (MooEdit *doc)
|
||||
{
|
||||
MooEditWindow *window;
|
||||
GSList *list, *l;
|
||||
MooEditArray *docs;
|
||||
guint i;
|
||||
gboolean result = TRUE;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (doc), FALSE);
|
||||
@ -440,18 +441,18 @@ save_all (MooEdit *doc)
|
||||
window = moo_edit_get_window (doc);
|
||||
g_return_val_if_fail (MOO_IS_EDIT_WINDOW (window), FALSE);
|
||||
|
||||
list = moo_edit_window_list_docs (window);
|
||||
docs = moo_edit_window_get_docs (window);
|
||||
|
||||
for (l = list; l != NULL; l = l->next)
|
||||
for (i = 0; i < docs->n_elms; ++i)
|
||||
{
|
||||
if (!save_one (l->data))
|
||||
if (!save_one (docs->elms[i]))
|
||||
{
|
||||
result = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_slist_free (list);
|
||||
moo_edit_array_free (docs);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "mooutils/mooutils-gobject.h"
|
||||
#include "mooutils/mooutils-misc.h"
|
||||
#include "mooutils/mootype-macros.h"
|
||||
#include "mooedit/mooedit-tests.h"
|
||||
#include "mooedit/mooeditor-tests.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
@ -1399,7 +1399,7 @@ MOO_PLUGIN_DEFINE_INFO (user_tools,
|
||||
N_("User Tools"),
|
||||
N_("Configurable tools"),
|
||||
"Yevgen Muntyan <emuntyan@sourceforge.net>",
|
||||
MOO_VERSION, NULL)
|
||||
MOO_VERSION)
|
||||
|
||||
MOO_PLUGIN_DEFINE (UserTools, user_tools,
|
||||
NULL, NULL, NULL, NULL,
|
||||
|
Loading…
x
Reference in New Issue
Block a user