More gio
parent
ad43a4e698
commit
b7b1de49f5
|
@ -10,8 +10,9 @@ files = subprocess.Popen(['hg', 'log', '-r', 'tip', '--template', '{files}'],
|
|||
status = 0
|
||||
|
||||
for name in files:
|
||||
if not os.path.exists(name) or name.endswith('.icns') or name.endswith('.png'):
|
||||
continue
|
||||
if not os.path.exists(name) or name.startswith('medit/data') or \
|
||||
name.endswith('.icns') or name.endswith('.png'):
|
||||
continue
|
||||
f = open(name, 'rb')
|
||||
if '\r' in f.read():
|
||||
print >> sys.stderr, "%s contains \\r character" % (name,)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
char *filename;
|
||||
char *filename2;
|
||||
char *encoding;
|
||||
const char *dot;
|
||||
MooEditor *editor;
|
||||
MooEdit *doc;
|
|
@ -0,0 +1 @@
|
|||
中国铁路第六次大提速启动。广深线今起每天都将有85趟列车从广州东站开往深圳,十分钟一列如公交车般摆渡广深,早班车提前到早上5时56分始发,晚班车延至凌晨1时。
|
|
@ -0,0 +1,3 @@
|
|||
"Бодун" -- пятый студийный альбом российской группы АукцЫон.
|
||||
В песнях альбома впервые в истории группы дважды встречается ненормативная лексика.
|
||||
По этой причине одна из композиций альбома первоначально не была пропущена советской цензурой.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,6 @@
|
|||
char *filename;
|
||||
char *filename2;
|
||||
char *encoding;
|
||||
const char *dot;
|
||||
MooEditor *editor;
|
||||
MooEdit *doc;
|
|
@ -0,0 +1,4 @@
|
|||
ğĪĤĞģĦħĢįᦍഊഎഌആഔകഛങ
|
||||
ؓثحپټڃڅڄ
|
||||
ԸԺՀԿԾԽԿՀՁ
|
||||
ঊকএগখঔওউ
|
|
@ -0,0 +1 @@
|
|||
中国铁路第六次大提速启动。广深线今起每天都将有85趟列车从广州东站开往深圳,十分钟一列如公交车般摆渡广深,早班车提前到早上5时56分始发,晚班车延至凌晨1时。
|
|
@ -0,0 +1,10 @@
|
|||
Бодун (альбом)
|
||||
[править]
|
||||
Материал из Википедии — свободной энциклопедии
|
||||
|
||||
«Бодун» — пятый студийный альбом российской группы АукцЫон.
|
||||
|
||||
[править] Интересные факты
|
||||
|
||||
В песнях альбома впервые в истории группы дважды встречается ненормативная лексика.
|
||||
По этой причине одна из композиций альбома первоначально не была пропущена советской цензурой.
|
|
@ -0,0 +1,10 @@
|
|||
Бодун (альбом)
|
||||
[править]
|
||||
Материал из Википедии — свободной энциклопедии
|
||||
|
||||
«Бодун» — пятый студийный альбом российской группы АукцЫон.
|
||||
|
||||
[править] Интересные факты
|
||||
|
||||
В песнях альбома впервые в истории группы дважды встречается ненормативная лексика.
|
||||
По этой причине одна из композиций альбома первоначально не была пропущена советской цензурой.
|
|
@ -75,6 +75,7 @@ unit_tests_main (int argc, char *argv[])
|
|||
|
||||
add_tests ();
|
||||
moo_test_run_tests (argv[1], data_dir, opts);
|
||||
|
||||
moo_test_cleanup ();
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
|
|
@ -66,23 +66,22 @@ static void add_status (MooEdit *edit,
|
|||
MooEditStatus s);
|
||||
|
||||
static gboolean moo_edit_load_local (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
static gboolean moo_edit_reload_local (MooEdit *edit,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
static gboolean moo_edit_save_local (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
static gboolean moo_edit_save_copy_local (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
static char *_moo_edit_filename_to_utf8 (const char *filename);
|
||||
static void _moo_edit_start_file_watch (MooEdit *edit);
|
||||
|
||||
|
||||
|
@ -97,27 +96,25 @@ normalize_encoding (const char *encoding,
|
|||
|
||||
|
||||
gboolean
|
||||
_moo_edit_load_file (MooEdit *edit,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError **error)
|
||||
_moo_edit_load_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error)
|
||||
{
|
||||
char *filename_copy, *encoding_copy;
|
||||
char *encoding_copy;
|
||||
gboolean result;
|
||||
GError *error_here = NULL;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (filename != NULL, FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
filename_copy = g_strdup (filename);
|
||||
encoding_copy = g_strdup (normalize_encoding (encoding, FALSE));
|
||||
|
||||
result = moo_edit_load_local (edit, filename_copy, encoding_copy, &error_here);
|
||||
result = moo_edit_load_local (edit, file, encoding_copy, &error_here);
|
||||
|
||||
if (error_here)
|
||||
g_propagate_error (error, error_here);
|
||||
|
||||
g_free (filename_copy);
|
||||
g_free (encoding_copy);
|
||||
return result;
|
||||
}
|
||||
|
@ -144,27 +141,25 @@ _moo_edit_reload_file (MooEdit *edit,
|
|||
|
||||
gboolean
|
||||
_moo_edit_save_file (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
GError *error_here = NULL;
|
||||
char *filename_copy, *encoding_copy;
|
||||
char *encoding_copy;
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (filename != NULL, FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
filename_copy = g_strdup (filename);
|
||||
encoding_copy = g_strdup (normalize_encoding (encoding, TRUE));
|
||||
|
||||
result = moo_edit_save_local (edit, filename_copy, encoding_copy, flags, &error_here);
|
||||
result = moo_edit_save_local (edit, file, encoding_copy, flags, &error_here);
|
||||
|
||||
if (error_here)
|
||||
g_propagate_error (error, error_here);
|
||||
|
||||
g_free (filename_copy);
|
||||
g_free (encoding_copy);
|
||||
return result;
|
||||
}
|
||||
|
@ -172,23 +167,21 @@ _moo_edit_save_file (MooEdit *edit,
|
|||
|
||||
gboolean
|
||||
_moo_edit_save_file_copy (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
char *filename_copy, *encoding_copy;
|
||||
char *encoding_copy;
|
||||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (filename != NULL, FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
filename_copy = g_strdup (filename);
|
||||
encoding_copy = g_strdup (normalize_encoding (encoding, TRUE));
|
||||
|
||||
result = moo_edit_save_copy_local (edit, filename_copy, encoding_copy, flags, error);
|
||||
result = moo_edit_save_copy_local (edit, file, encoding_copy, flags, error);
|
||||
|
||||
g_free (filename_copy);
|
||||
g_free (encoding_copy);
|
||||
return result;
|
||||
}
|
||||
|
@ -216,15 +209,14 @@ typedef enum {
|
|||
ERROR_ENCODING
|
||||
} LoadResult;
|
||||
|
||||
static LoadResult do_load (MooEdit *edit,
|
||||
const char *file,
|
||||
const char *encoding,
|
||||
struct stat *statbuf,
|
||||
GError **error);
|
||||
static LoadResult do_load (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
#ifdef LOAD_BINARY
|
||||
static LoadResult load_binary (MooEdit *edit,
|
||||
const char *file,
|
||||
GError **error);
|
||||
static LoadResult load_binary (MooEdit *edit,
|
||||
const char *file,
|
||||
GError **error);
|
||||
#endif
|
||||
|
||||
const char *
|
||||
|
@ -293,18 +285,17 @@ get_encodings (void)
|
|||
|
||||
|
||||
static LoadResult
|
||||
try_load (MooEdit *edit,
|
||||
const char *file,
|
||||
const char *encoding,
|
||||
struct stat *statbuf,
|
||||
GError **error)
|
||||
try_load (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error)
|
||||
{
|
||||
GtkTextBuffer *buffer;
|
||||
gboolean enable_highlight;
|
||||
LoadResult result;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (file && file[0], FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
g_return_val_if_fail (encoding && encoding[0], FALSE);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit));
|
||||
|
@ -312,16 +303,43 @@ try_load (MooEdit *edit,
|
|||
|
||||
g_object_get (edit, "enable-highlight", &enable_highlight, NULL);
|
||||
g_object_set (edit, "enable-highlight", FALSE, NULL);
|
||||
result = do_load (edit, file, encoding, statbuf, error);
|
||||
result = do_load (edit, file, encoding, error);
|
||||
g_object_set (edit, "enable-highlight", enable_highlight, NULL);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
check_regular (GFile *file,
|
||||
GError **error)
|
||||
{
|
||||
GFileInfo *info;
|
||||
GFileType type;
|
||||
gboolean retval = TRUE;
|
||||
|
||||
if (!g_file_is_native (file))
|
||||
return TRUE;
|
||||
|
||||
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, NULL, NULL);
|
||||
g_return_val_if_fail (info != NULL, TRUE);
|
||||
|
||||
type = g_file_info_get_file_type (info);
|
||||
if (type != G_FILE_TYPE_REGULAR && type != G_FILE_TYPE_UNKNOWN)
|
||||
{
|
||||
g_set_error (error, MOO_EDIT_FILE_ERROR,
|
||||
MOO_EDIT_FILE_ERROR_FAILED,
|
||||
"%s", D_("Not a regular file", "glib20"));
|
||||
retval = FALSE;
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
moo_edit_load_local (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error)
|
||||
{
|
||||
|
@ -330,11 +348,13 @@ moo_edit_load_local (MooEdit *edit,
|
|||
MooTextView *view;
|
||||
gboolean undo;
|
||||
LoadResult result = ERROR_FILE;
|
||||
struct stat statbuf;
|
||||
char *freeme = NULL;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (file && file[0], FALSE);
|
||||
g_return_val_if_fail (file != NULL, FALSE);
|
||||
|
||||
if (!check_regular (file, error))
|
||||
return FALSE;
|
||||
|
||||
if (moo_edit_is_empty (edit))
|
||||
undo = FALSE;
|
||||
|
@ -368,7 +388,7 @@ moo_edit_load_local (MooEdit *edit,
|
|||
encodings = g_slist_delete_link (encodings, encodings);
|
||||
|
||||
g_clear_error (error);
|
||||
result = try_load (edit, file, enc, &statbuf, error);
|
||||
result = try_load (edit, file, enc, error);
|
||||
|
||||
if (result != ERROR_ENCODING)
|
||||
{
|
||||
|
@ -384,7 +404,7 @@ moo_edit_load_local (MooEdit *edit,
|
|||
}
|
||||
else
|
||||
{
|
||||
result = try_load (edit, file, encoding, &statbuf, error);
|
||||
result = try_load (edit, file, encoding, error);
|
||||
}
|
||||
|
||||
#ifdef LOAD_BINARY
|
||||
|
@ -410,9 +430,7 @@ moo_edit_load_local (MooEdit *edit,
|
|||
gtk_text_buffer_place_cursor (buffer, &start);
|
||||
edit->priv->status = 0;
|
||||
moo_edit_set_modified (edit, FALSE);
|
||||
_moo_edit_set_filename (edit, file, encoding);
|
||||
edit->priv->mode = statbuf.st_mode;
|
||||
edit->priv->mode_set = TRUE;
|
||||
_moo_edit_set_file (edit, file, encoding);
|
||||
_moo_edit_start_file_watch (edit);
|
||||
}
|
||||
else
|
||||
|
@ -433,11 +451,10 @@ moo_edit_load_local (MooEdit *edit,
|
|||
|
||||
|
||||
static LoadResult
|
||||
do_load (MooEdit *edit,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
struct stat *statbuf,
|
||||
GError **error)
|
||||
do_load (MooEdit *edit,
|
||||
GFile *gfile,
|
||||
const char *encoding,
|
||||
GError **error)
|
||||
{
|
||||
GIOChannel *file = NULL;
|
||||
GIOStatus status;
|
||||
|
@ -446,35 +463,21 @@ do_load (MooEdit *edit,
|
|||
GString *text = NULL;
|
||||
char *line = NULL;
|
||||
LoadResult result = ERROR_FILE;
|
||||
char *path;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, ERROR_FILE);
|
||||
g_return_val_if_fail (G_IS_FILE (gfile), ERROR_FILE);
|
||||
g_return_val_if_fail (encoding != NULL, ERROR_FILE);
|
||||
|
||||
if (g_stat (filename, statbuf) == 0)
|
||||
if (!(path = g_file_get_path (gfile)))
|
||||
{
|
||||
if (
|
||||
#ifdef S_ISBLK
|
||||
S_ISBLK (statbuf->st_mode) ||
|
||||
#endif
|
||||
#ifdef S_ISCHR
|
||||
S_ISCHR (statbuf->st_mode) ||
|
||||
#endif
|
||||
#ifdef S_ISFIFO
|
||||
S_ISFIFO (statbuf->st_mode) ||
|
||||
#endif
|
||||
#ifdef S_ISSOCK
|
||||
S_ISSOCK (statbuf->st_mode) ||
|
||||
#endif
|
||||
0)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR,
|
||||
G_FILE_ERROR_FAILED,
|
||||
"Not a regular file.");
|
||||
return ERROR_FILE;
|
||||
}
|
||||
g_set_error (error, MOO_EDIT_FILE_ERROR,
|
||||
MOO_EDIT_FILE_ERROR_NOT_IMPLEMENTED,
|
||||
"Loading remote files is not implemented");
|
||||
return ERROR_FILE;
|
||||
}
|
||||
|
||||
file = g_io_channel_new_file (filename, "r", error);
|
||||
file = g_io_channel_new_file (path, "r", error);
|
||||
g_free (path);
|
||||
|
||||
if (!file)
|
||||
return ERROR_FILE;
|
||||
|
@ -690,8 +693,10 @@ moo_edit_reload_local (MooEdit *edit,
|
|||
GtkTextIter start, end;
|
||||
GtkTextBuffer *buffer;
|
||||
gboolean result, enable_highlight;
|
||||
GFile *file;
|
||||
|
||||
g_return_val_if_fail (edit->priv->filename != NULL, FALSE);
|
||||
file = _moo_edit_get_file (edit);
|
||||
g_return_val_if_fail (file != NULL, FALSE);
|
||||
|
||||
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (edit));
|
||||
|
||||
|
@ -703,7 +708,7 @@ moo_edit_reload_local (MooEdit *edit,
|
|||
g_object_get (edit, "enable-highlight", &enable_highlight, NULL);
|
||||
g_object_set (edit, "enable-highlight", FALSE, NULL);
|
||||
|
||||
result = _moo_edit_load_file (edit, edit->priv->filename,
|
||||
result = _moo_edit_load_file (edit, file,
|
||||
encoding ? encoding : edit->priv->encoding,
|
||||
error);
|
||||
|
||||
|
@ -719,6 +724,7 @@ moo_edit_reload_local (MooEdit *edit,
|
|||
g_clear_error (error);
|
||||
}
|
||||
|
||||
g_object_unref (file);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -736,7 +742,7 @@ moo_edit_reload_local (MooEdit *edit,
|
|||
#endif
|
||||
|
||||
static gboolean do_write (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
|
@ -744,7 +750,7 @@ static gboolean do_write (MooEdit *edit,
|
|||
|
||||
static gboolean
|
||||
do_save_local (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error,
|
||||
|
@ -752,7 +758,7 @@ do_save_local (MooEdit *edit,
|
|||
{
|
||||
*retval = TRUE;
|
||||
|
||||
if (!do_write (edit, filename, encoding, flags, error))
|
||||
if (!do_write (edit, file, encoding, flags, error))
|
||||
{
|
||||
if ((*error)->domain != G_CONVERT_ERROR ||
|
||||
_moo_encodings_equal (encoding, MOO_ENCODING_UTF8))
|
||||
|
@ -763,7 +769,7 @@ do_save_local (MooEdit *edit,
|
|||
|
||||
g_clear_error (error);
|
||||
|
||||
if (!do_write (edit, filename, MOO_ENCODING_UTF8, flags, error))
|
||||
if (!do_write (edit, file, MOO_ENCODING_UTF8, flags, error))
|
||||
{
|
||||
*retval = FALSE;
|
||||
return FALSE;
|
||||
|
@ -779,7 +785,7 @@ do_save_local (MooEdit *edit,
|
|||
|
||||
static gboolean
|
||||
moo_edit_save_local (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error)
|
||||
|
@ -787,13 +793,13 @@ moo_edit_save_local (MooEdit *edit,
|
|||
gboolean result;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (filename && filename[0], FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
if (do_save_local (edit, filename, encoding, flags, error, &result))
|
||||
if (do_save_local (edit, file, encoding, flags, error, &result))
|
||||
{
|
||||
edit->priv->status = 0;
|
||||
_moo_edit_set_filename (edit, filename,
|
||||
result ? encoding : MOO_ENCODING_UTF8);
|
||||
_moo_edit_set_file (edit, file,
|
||||
result ? encoding : MOO_ENCODING_UTF8);
|
||||
moo_edit_set_modified (edit, FALSE);
|
||||
_moo_edit_start_file_watch (edit);
|
||||
}
|
||||
|
@ -804,15 +810,15 @@ moo_edit_save_local (MooEdit *edit,
|
|||
|
||||
static gboolean
|
||||
moo_edit_save_copy_local (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
gboolean result;
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), FALSE);
|
||||
g_return_val_if_fail (filename && filename[0], FALSE);
|
||||
do_save_local (edit, filename, encoding, flags, error, &result);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
do_save_local (edit, file, encoding, flags, error, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -861,7 +867,7 @@ convert_with_iconv (GIConv converter,
|
|||
|
||||
static gboolean
|
||||
do_write (MooEdit *edit,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error)
|
||||
|
@ -877,7 +883,7 @@ do_write (MooEdit *edit,
|
|||
gsize le_len = 1;
|
||||
gboolean success = FALSE;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, FALSE);
|
||||
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
||||
|
||||
if (encoding && (!g_ascii_strcasecmp (encoding, "UTF-8") || !g_ascii_strcasecmp (encoding, "UTF8")))
|
||||
encoding = NULL;
|
||||
|
@ -906,12 +912,15 @@ do_write (MooEdit *edit,
|
|||
{
|
||||
case MOO_EDIT_LINE_END_UNIX:
|
||||
le = "\n";
|
||||
le_len = 1;
|
||||
break;
|
||||
case MOO_EDIT_LINE_END_WIN32:
|
||||
le = "\r\n";
|
||||
le_len = 2;
|
||||
break;
|
||||
case MOO_EDIT_LINE_END_MAC:
|
||||
le = "\r";
|
||||
le_len = 1;
|
||||
break;
|
||||
case MOO_EDIT_LINE_END_MIX:
|
||||
case MOO_EDIT_LINE_END_NONE:
|
||||
|
@ -926,7 +935,7 @@ do_write (MooEdit *edit,
|
|||
}
|
||||
|
||||
writer_flags = (flags & MOO_EDIT_SAVE_BACKUP) ? MOO_FILE_WRITER_SAVE_BACKUP : 0;
|
||||
if (!(writer = moo_file_writer_new (filename, writer_flags, error)))
|
||||
if (!(writer = moo_file_writer_new_for_file (file, writer_flags, error)))
|
||||
goto out;
|
||||
|
||||
gtk_text_buffer_get_start_iter (buffer, &line_start);
|
||||
|
@ -948,7 +957,7 @@ do_write (MooEdit *edit,
|
|||
{
|
||||
char *tmp;
|
||||
|
||||
if (!convert_with_iconv (converter, line, len, &tmp, &len, error))
|
||||
if (!(success = convert_with_iconv (converter, line, len, &tmp, &len, error)))
|
||||
{
|
||||
/* XXX */
|
||||
moo_file_writer_close (writer, NULL);
|
||||
|
@ -1122,8 +1131,8 @@ focus_in_cb (MooEdit *edit)
|
|||
|
||||
|
||||
static void
|
||||
check_file_status (MooEdit *edit,
|
||||
gboolean in_focus_only)
|
||||
check_file_status (MooEdit *edit,
|
||||
gboolean in_focus_only)
|
||||
{
|
||||
if (in_focus_only && !GTK_WIDGET_HAS_FOCUS (edit))
|
||||
return;
|
||||
|
@ -1220,14 +1229,64 @@ _moo_edit_get_default_encoding (void)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
_moo_edit_set_filename (MooEdit *edit,
|
||||
const char *file,
|
||||
const char *encoding)
|
||||
char *
|
||||
_moo_file_get_display_name (GFile *file)
|
||||
{
|
||||
char *tmp1, *tmp3, *tmp4;
|
||||
char *name;
|
||||
char *filename;
|
||||
|
||||
tmp1 = edit->priv->filename;
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
if ((filename = g_file_get_path (file)))
|
||||
{
|
||||
name = g_filename_display_name (filename);
|
||||
g_free (filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
name = g_file_get_uri (file);
|
||||
}
|
||||
|
||||
if (!name)
|
||||
{
|
||||
g_critical ("%s: oops", G_STRFUNC);
|
||||
name = g_strdup ("<UNKNOWN>");
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_basename (const char *filename)
|
||||
{
|
||||
const char *slash;
|
||||
slash = strrchr (filename, '/');
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
{
|
||||
const char *backslash = strrchr (filename, '\\');
|
||||
if (backslash && (!slash || backslash > slash))
|
||||
slash = backslash;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (slash)
|
||||
return g_strdup (slash + 1);
|
||||
else
|
||||
return g_strdup (filename);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_moo_edit_set_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
GFile *tmp;
|
||||
char *tmp2, *tmp3, *tmp4;
|
||||
|
||||
tmp = edit->priv->file;
|
||||
tmp2 = edit->priv->filename;
|
||||
tmp3 = edit->priv->display_filename;
|
||||
tmp4 = edit->priv->display_basename;
|
||||
|
||||
|
@ -1238,6 +1297,7 @@ _moo_edit_set_filename (MooEdit *edit,
|
|||
{
|
||||
int n = add_untitled (edit);
|
||||
|
||||
edit->priv->file = NULL;
|
||||
edit->priv->filename = NULL;
|
||||
|
||||
if (n == 1)
|
||||
|
@ -1249,17 +1309,11 @@ _moo_edit_set_filename (MooEdit *edit,
|
|||
}
|
||||
else
|
||||
{
|
||||
char *basename;
|
||||
|
||||
remove_untitled (NULL, edit);
|
||||
|
||||
edit->priv->filename = g_strdup (file);
|
||||
edit->priv->display_filename = _moo_edit_filename_to_utf8 (file);
|
||||
|
||||
basename = g_path_get_basename (file);
|
||||
edit->priv->display_basename = _moo_edit_filename_to_utf8 (basename);
|
||||
|
||||
g_free (basename);
|
||||
edit->priv->file = g_file_dup (file);
|
||||
edit->priv->filename = g_file_get_path (file);
|
||||
edit->priv->display_filename = _moo_file_get_display_name (file);
|
||||
edit->priv->display_basename = get_basename (edit->priv->display_filename);
|
||||
}
|
||||
|
||||
if (!encoding)
|
||||
|
@ -1270,44 +1324,23 @@ _moo_edit_set_filename (MooEdit *edit,
|
|||
g_signal_emit_by_name (edit, "filename-changed", edit->priv->filename, NULL);
|
||||
moo_edit_status_changed (edit);
|
||||
|
||||
g_free (tmp1);
|
||||
if (tmp)
|
||||
g_object_unref (tmp);
|
||||
g_free (tmp2);
|
||||
g_free (tmp3);
|
||||
g_free (tmp4);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
_moo_edit_filename_to_utf8 (const char *filename)
|
||||
{
|
||||
GError *err = NULL;
|
||||
char *utf_filename;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
|
||||
utf_filename = g_filename_to_utf8 (filename, -1, NULL, NULL, &err);
|
||||
|
||||
if (!utf_filename)
|
||||
{
|
||||
g_critical ("%s: could not convert filename to UTF8", G_STRLOC);
|
||||
|
||||
if (err)
|
||||
{
|
||||
g_critical ("%s: %s", G_STRLOC, err->message);
|
||||
g_error_free (err);
|
||||
err = NULL;
|
||||
}
|
||||
|
||||
utf_filename = g_strdup ("<Unknown>");
|
||||
}
|
||||
|
||||
return utf_filename;
|
||||
}
|
||||
|
||||
|
||||
GdkPixbuf *
|
||||
_moo_edit_get_icon (MooEdit *doc,
|
||||
GtkWidget *widget,
|
||||
GtkIconSize size)
|
||||
{
|
||||
return moo_get_icon_for_file (doc->priv->filename, widget, size);
|
||||
if (doc->priv->filename)
|
||||
return moo_get_icon_for_file (doc->priv->filename, widget, size);
|
||||
else if (doc->priv->file)
|
||||
return moo_get_icon_for_file (doc->priv->display_basename, widget, size);
|
||||
else
|
||||
return moo_get_icon_for_file (NULL, widget, size);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#define MOO_EDIT_FILE_OPS_H
|
||||
|
||||
#include "mooedit/mooedit.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -32,28 +33,34 @@ typedef enum {
|
|||
} MooEditSaveFlags;
|
||||
|
||||
#define MOO_EDIT_FILE_ERROR (_moo_edit_file_error_quark ())
|
||||
#define MOO_EDIT_FILE_ERROR_ENCODING 0
|
||||
enum {
|
||||
MOO_EDIT_FILE_ERROR_ENCODING,
|
||||
MOO_EDIT_FILE_ERROR_FAILED,
|
||||
MOO_EDIT_FILE_ERROR_NOT_IMPLEMENTED
|
||||
};
|
||||
|
||||
GQuark _moo_edit_file_error_quark (void) G_GNUC_CONST;
|
||||
|
||||
gboolean _moo_edit_load_file (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
gboolean _moo_edit_reload_file (MooEdit *edit,
|
||||
const char *encoding,
|
||||
GError **error);
|
||||
gboolean _moo_edit_save_file (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
gboolean _moo_edit_save_file_copy (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
MooEditSaveFlags flags,
|
||||
GError **error);
|
||||
|
||||
char *_moo_file_get_display_name (GFile *file);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -24,17 +24,10 @@
|
|||
#include "mooedit/mooeditor.h"
|
||||
#include "mooedit/mootextview.h"
|
||||
#include "mooutils/mdhistorymgr.h"
|
||||
#include <sys/types.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#if defined(__WIN32__) && !defined(__GNUC__)
|
||||
typedef unsigned short mode_t;
|
||||
#define S_IRUSR S_IREAD
|
||||
#define S_IWUSR S_IWRITE
|
||||
#endif
|
||||
|
||||
|
||||
#define PROGRESS_TIMEOUT 100
|
||||
#define PROGRESS_WIDTH 300
|
||||
#define PROGRESS_HEIGHT 100
|
||||
|
@ -99,8 +92,10 @@ void _moo_edit_apply_prefs (MooEdit *edit);
|
|||
/* File operations
|
||||
*/
|
||||
|
||||
void _moo_edit_set_filename (MooEdit *edit,
|
||||
const char *file,
|
||||
GFile *_moo_edit_get_file (MooEdit *edit);
|
||||
|
||||
void _moo_edit_set_file (MooEdit *edit,
|
||||
GFile *file,
|
||||
const char *encoding);
|
||||
void _moo_edit_set_encoding (MooEdit *edit,
|
||||
const char *encoding);
|
||||
|
@ -125,10 +120,10 @@ GdkPixbuf *_moo_edit_get_icon (MooEdit *edit,
|
|||
GtkWidget *widget,
|
||||
GtkIconSize size);
|
||||
|
||||
#define MOO_EDIT_IS_UNTITLED(edit) (!(edit)->priv->filename)
|
||||
#define MOO_EDIT_IS_UNTITLED(edit) (!(edit)->priv->file)
|
||||
|
||||
struct MooEditFileInfo {
|
||||
char *filename;
|
||||
GFile *file;
|
||||
char *encoding;
|
||||
};
|
||||
|
||||
|
@ -149,6 +144,7 @@ struct MooEditPrivate {
|
|||
/***********************************************************************/
|
||||
/* Document
|
||||
*/
|
||||
GFile *file;
|
||||
char *filename;
|
||||
char *display_filename;
|
||||
char *display_basename;
|
||||
|
@ -162,9 +158,6 @@ struct MooEditPrivate {
|
|||
gboolean modified_on_disk;
|
||||
gboolean deleted_from_disk;
|
||||
|
||||
mode_t mode;
|
||||
guint mode_set : 1;
|
||||
|
||||
/***********************************************************************/
|
||||
/* Progress dialog and stuff
|
||||
*/
|
||||
|
|
|
@ -298,7 +298,7 @@ moo_edit_constructor (GType type,
|
|||
G_CALLBACK (modified_changed_cb),
|
||||
edit);
|
||||
|
||||
_moo_edit_set_filename (edit, NULL, NULL);
|
||||
_moo_edit_set_file (edit, NULL, NULL);
|
||||
|
||||
buffer = get_buffer (edit);
|
||||
g_signal_connect_swapped (buffer, "line-mark-moved",
|
||||
|
@ -317,6 +317,8 @@ moo_edit_finalize (GObject *object)
|
|||
{
|
||||
MooEdit *edit = MOO_EDIT (object);
|
||||
|
||||
if (edit->priv->file)
|
||||
g_object_unref (edit->priv->file);
|
||||
g_free (edit->priv->filename);
|
||||
g_free (edit->priv->display_filename);
|
||||
g_free (edit->priv->display_basename);
|
||||
|
@ -608,20 +610,36 @@ moo_edit_focus_out (GtkWidget *widget,
|
|||
}
|
||||
|
||||
|
||||
MooEditFileInfo *
|
||||
moo_edit_file_info_new (const char *filename,
|
||||
static MooEditFileInfo *
|
||||
moo_edit_file_info_new (GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
MooEditFileInfo *info = g_new0 (MooEditFileInfo, 1);
|
||||
info->filename = g_strdup (filename);
|
||||
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 (info->filename, info->encoding) : NULL;
|
||||
return info ? moo_edit_file_info_new (g_object_ref (info->file), info->encoding) : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -630,12 +648,19 @@ moo_edit_file_info_free (MooEditFileInfo *info)
|
|||
if (info)
|
||||
{
|
||||
g_free (info->encoding);
|
||||
g_free (info->filename);
|
||||
g_free (info);
|
||||
g_object_unref (info->file);
|
||||
moo_free (MooEditFileInfo, info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GFile *
|
||||
_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;
|
||||
}
|
||||
|
||||
char *
|
||||
moo_edit_get_filename (MooEdit *edit)
|
||||
{
|
||||
|
@ -661,11 +686,7 @@ char *
|
|||
moo_edit_get_uri (MooEdit *edit)
|
||||
{
|
||||
g_return_val_if_fail (MOO_IS_EDIT (edit), NULL);
|
||||
|
||||
if (edit->priv->filename)
|
||||
return g_filename_to_uri (edit->priv->filename, NULL, NULL);
|
||||
else
|
||||
return NULL;
|
||||
return edit->priv->file ? g_file_get_uri (edit->priv->file) : NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
|
@ -1880,6 +1901,7 @@ _moo_edit_set_state (MooEdit *edit,
|
|||
|
||||
static struct {
|
||||
char *working_dir;
|
||||
char *encodings_dir;
|
||||
} test_data;
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
@ -1978,6 +2000,91 @@ test_basic (void)
|
|||
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, NULL);
|
||||
filename2 = g_build_filename (working_dir, name, NULL);
|
||||
|
||||
editor = moo_editor_instance ();
|
||||
doc = moo_editor_open_file (editor, NULL, NULL, filename, encoding);
|
||||
TEST_ASSERT (doc != NULL);
|
||||
|
||||
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", NULL);
|
||||
_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)
|
||||
{
|
||||
|
@ -1990,6 +2097,8 @@ test_suite_init (G_GNUC_UNUSED gpointer data)
|
|||
|
||||
test_data.working_dir = g_build_filename (moo_test_get_working_dir (),
|
||||
"editor-work", NULL);
|
||||
test_data.encodings_dir = g_build_filename (moo_test_get_data_dir (),
|
||||
"encodings", NULL);
|
||||
|
||||
if (_moo_mkdir_with_parents (test_data.working_dir) != 0)
|
||||
{
|
||||
|
@ -2012,16 +2121,18 @@ test_suite_cleanup (G_GNUC_UNUSED gpointer data)
|
|||
char *cache_dir;
|
||||
MooEditor *editor;
|
||||
|
||||
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;
|
||||
}
|
||||
// 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);
|
||||
|
@ -2052,6 +2163,7 @@ moo_test_editor (void)
|
|||
test_suite_cleanup,
|
||||
NULL);
|
||||
moo_test_suite_add_test (suite, "basic", (MooTestFunc) test_basic, NULL);
|
||||
moo_test_suite_add_test (suite, "encodings", (MooTestFunc) test_encodings, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -126,7 +126,9 @@ void moo_edit_comment (MooEdit *edit);
|
|||
void moo_edit_uncomment (MooEdit *edit);
|
||||
|
||||
typedef struct MooEditFileInfo MooEditFileInfo;
|
||||
MooEditFileInfo *moo_edit_file_info_new (const char *filename,
|
||||
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);
|
||||
|
|
|
@ -80,7 +80,7 @@ _moo_edit_open_dialog (GtkWidget *widget,
|
|||
g_return_val_if_fail (filenames != NULL, NULL);
|
||||
|
||||
for (p = filenames; *p != NULL; ++p)
|
||||
infos = g_slist_prepend (infos, moo_edit_file_info_new (*p, encoding));
|
||||
infos = g_slist_prepend (infos, moo_edit_file_info_new_path (*p, encoding));
|
||||
infos = g_slist_reverse (infos);
|
||||
|
||||
new_start = g_path_get_dirname (filenames[0]);
|
||||
|
@ -143,7 +143,7 @@ _moo_edit_save_as_dialog (MooEdit *edit,
|
|||
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 (filename, encoding);
|
||||
file_info = moo_edit_file_info_new_path (filename, encoding);
|
||||
|
||||
new_start = g_path_get_dirname (filename);
|
||||
moo_prefs_set_filename (moo_edit_setting (MOO_EDIT_PREFS_LAST_DIR), new_start);
|
||||
|
@ -399,50 +399,41 @@ _moo_edit_save_multiple_changes_dialog (GSList *docs,
|
|||
*/
|
||||
|
||||
void
|
||||
_moo_edit_save_error_dialog (GtkWidget *widget,
|
||||
const char *filename,
|
||||
GError *error)
|
||||
_moo_edit_save_error_dialog (GtkWidget *widget,
|
||||
GFile *file,
|
||||
GError *error)
|
||||
{
|
||||
char *filename_utf8, *msg = NULL;
|
||||
char *filename, *msg = NULL;
|
||||
|
||||
g_return_if_fail (filename != NULL);
|
||||
filename = _moo_file_get_display_name (file);
|
||||
|
||||
filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
||||
|
||||
if (!filename_utf8)
|
||||
g_critical ("%s: could not convert filename '%s' to utf8", G_STRLOC, filename);
|
||||
|
||||
if (filename_utf8)
|
||||
if (filename)
|
||||
/* Could not save file foo.txt */
|
||||
msg = g_strdup_printf (_("Could not save file\n%s"), filename_utf8);
|
||||
msg = g_strdup_printf (_("Could not save file\n%s"), filename);
|
||||
else
|
||||
msg = g_strdup (_("Could not save file"));
|
||||
|
||||
moo_error_dialog (widget, msg, error ? error->message : NULL);
|
||||
|
||||
g_free (msg);
|
||||
g_free (filename_utf8);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
void
|
||||
_moo_edit_save_error_enc_dialog (GtkWidget *widget,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding)
|
||||
{
|
||||
char *filename_utf8, *msg = NULL;
|
||||
char *filename, *msg = NULL;
|
||||
char *secondary;
|
||||
|
||||
g_return_if_fail (filename != NULL);
|
||||
g_return_if_fail (encoding != NULL);
|
||||
|
||||
filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
||||
filename = _moo_file_get_display_name (file);
|
||||
|
||||
if (!filename_utf8)
|
||||
g_critical ("%s: could not convert filename '%s' to utf8", G_STRLOC, filename);
|
||||
|
||||
if (filename_utf8)
|
||||
if (filename)
|
||||
/* Error saving file foo.txt */
|
||||
msg = g_strdup_printf (_("Error saving file\n%s"), filename_utf8);
|
||||
msg = g_strdup_printf (_("Error saving file\n%s"), filename);
|
||||
else
|
||||
msg = g_strdup (_("Error saving file"));
|
||||
|
||||
|
@ -454,29 +445,24 @@ _moo_edit_save_error_enc_dialog (GtkWidget *widget,
|
|||
|
||||
g_free (msg);
|
||||
g_free (secondary);
|
||||
g_free (filename_utf8);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
_moo_edit_open_error_dialog (GtkWidget *widget,
|
||||
const char *filename,
|
||||
const char *encoding,
|
||||
GError *error)
|
||||
_moo_edit_open_error_dialog (GtkWidget *widget,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError *error)
|
||||
{
|
||||
char *filename_utf8, *msg = NULL;
|
||||
char *filename, *msg = NULL;
|
||||
char *secondary;
|
||||
|
||||
g_return_if_fail (filename != NULL);
|
||||
filename = _moo_file_get_display_name (file);
|
||||
|
||||
filename_utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
||||
|
||||
if (!filename_utf8)
|
||||
g_critical ("%s: could not convert filename '%s' to utf8", G_STRLOC, filename);
|
||||
|
||||
if (filename_utf8)
|
||||
if (filename)
|
||||
/* Could not open file foo.txt */
|
||||
msg = g_strdup_printf (_("Could not open file\n%s"), filename_utf8);
|
||||
msg = g_strdup_printf (_("Could not open file\n%s"), filename);
|
||||
else
|
||||
msg = g_strdup (_("Could not open file"));
|
||||
|
||||
|
@ -501,7 +487,7 @@ _moo_edit_open_error_dialog (GtkWidget *widget,
|
|||
|
||||
g_free (msg);
|
||||
g_free (secondary);
|
||||
g_free (filename_utf8);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "mooutils/moodialogs.h"
|
||||
#include "mooedit/mooedit.h"
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -37,13 +38,13 @@ gboolean _moo_edit_reload_modified_dialog (MooEdit *edit);
|
|||
gboolean _moo_edit_overwrite_modified_dialog (MooEdit *edit);
|
||||
|
||||
void _moo_edit_save_error_dialog (GtkWidget *widget,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
GError *error);
|
||||
void _moo_edit_save_error_enc_dialog (GtkWidget *widget,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding);
|
||||
void _moo_edit_open_error_dialog (GtkWidget *widget,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError *error);
|
||||
void _moo_edit_reload_error_dialog (MooEdit *doc,
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#define RECENT_ACTION_ID "OpenRecent"
|
||||
#define RECENT_DIALOG_ACTION_ID "OpenRecentDialog"
|
||||
|
||||
#define CURRENT_SESSION_VERSION "2.0"
|
||||
|
||||
static gpointer editor_instance = NULL;
|
||||
|
||||
MOO_DEFINE_SLIST (DocList, doc_list, MooEdit)
|
||||
|
@ -640,12 +642,20 @@ _moo_editor_get_history_mgr (MooEditor *editor)
|
|||
}
|
||||
|
||||
static void
|
||||
add_recent_file (MooEditor *editor,
|
||||
const char *filename)
|
||||
add_recent_uri (MooEditor *editor,
|
||||
const char *uri)
|
||||
{
|
||||
if (!is_embedded (editor))
|
||||
md_history_mgr_add_uri (editor->priv->history, uri);
|
||||
}
|
||||
|
||||
static void
|
||||
add_recent_file (MooEditor *editor,
|
||||
GFile *file)
|
||||
{
|
||||
if (!is_embedded (editor))
|
||||
{
|
||||
char *uri = g_filename_to_uri (filename, NULL, NULL);
|
||||
char *uri = g_file_get_uri (file);
|
||||
if (uri)
|
||||
md_history_mgr_add_uri (editor->priv->history, uri);
|
||||
g_free (uri);
|
||||
|
@ -816,14 +826,19 @@ moo_editor_create_doc (MooEditor *editor,
|
|||
GError **error)
|
||||
{
|
||||
MooEdit *doc;
|
||||
GFile *file = NULL;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
||||
|
||||
doc = g_object_new (get_doc_type (editor), "editor", editor, NULL);
|
||||
|
||||
if (filename && !_moo_edit_load_file (doc, filename, encoding, error))
|
||||
if (filename)
|
||||
file = g_file_new_for_path (filename);
|
||||
|
||||
if (file && !_moo_edit_load_file (doc, file, encoding, error))
|
||||
{
|
||||
MOO_OBJECT_REF_SINK (doc);
|
||||
g_object_unref (file);
|
||||
g_object_unref (doc);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -831,6 +846,9 @@ moo_editor_create_doc (MooEditor *editor,
|
|||
moo_editor_add_doc (editor, NULL, doc);
|
||||
_moo_doc_attach_plugins (NULL, doc);
|
||||
|
||||
if (file)
|
||||
g_object_unref (file);
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -920,18 +938,19 @@ moo_editor_load_file (MooEditor *editor,
|
|||
GError *error = NULL;
|
||||
gboolean new_doc = FALSE;
|
||||
MooEdit *doc = NULL;
|
||||
char *filename;
|
||||
char *uri;
|
||||
gboolean result = TRUE;
|
||||
|
||||
*docp = NULL;
|
||||
filename = _moo_normalize_file_path (info->filename);
|
||||
uri = g_file_get_uri (info->file);
|
||||
g_return_val_if_fail (uri != NULL, FALSE);
|
||||
|
||||
if ((doc = moo_editor_get_doc (editor, filename)))
|
||||
if ((doc = moo_editor_get_doc_for_uri (editor, uri)))
|
||||
{
|
||||
*docp = doc;
|
||||
if (add_history)
|
||||
add_recent_file (editor, filename);
|
||||
g_free (filename);
|
||||
add_recent_uri (editor, uri);
|
||||
g_free (uri);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -953,7 +972,7 @@ moo_editor_load_file (MooEditor *editor,
|
|||
}
|
||||
|
||||
/* XXX open_single */
|
||||
if (!_moo_edit_load_file (doc, filename, info->encoding, &error))
|
||||
if (!_moo_edit_load_file (doc, info->file, info->encoding, &error))
|
||||
{
|
||||
if (!silent)
|
||||
{
|
||||
|
@ -961,7 +980,7 @@ moo_editor_load_file (MooEditor *editor,
|
|||
window = moo_editor_get_active_window (editor);
|
||||
if (!parent && window)
|
||||
parent = GTK_WIDGET (window);
|
||||
_moo_edit_open_error_dialog (parent, filename, info->encoding, error);
|
||||
_moo_edit_open_error_dialog (parent, info->file, info->encoding, error);
|
||||
}
|
||||
g_error_free (error);
|
||||
result = FALSE;
|
||||
|
@ -969,15 +988,12 @@ moo_editor_load_file (MooEditor *editor,
|
|||
else
|
||||
{
|
||||
MdHistoryItem *hist_item;
|
||||
char *uri;
|
||||
|
||||
if (line < 0)
|
||||
{
|
||||
uri = g_filename_to_uri (filename, NULL, NULL);
|
||||
hist_item = md_history_mgr_find_uri (editor->priv->history, uri);
|
||||
if (hist_item)
|
||||
line = _moo_edit_history_item_get_line (hist_item);
|
||||
g_free (uri);
|
||||
}
|
||||
|
||||
if (line >= 0)
|
||||
|
@ -995,13 +1011,13 @@ moo_editor_load_file (MooEditor *editor,
|
|||
}
|
||||
|
||||
if (add_history)
|
||||
add_recent_file (editor, filename);
|
||||
add_recent_uri (editor, uri);
|
||||
}
|
||||
|
||||
if (result)
|
||||
*docp = doc;
|
||||
|
||||
g_free (filename);
|
||||
g_free (uri);
|
||||
g_object_unref (doc);
|
||||
return result;
|
||||
}
|
||||
|
@ -1526,6 +1542,7 @@ moo_editor_close_all (MooEditor *editor,
|
|||
}
|
||||
|
||||
|
||||
/* Remove after March 2009 */
|
||||
static char *
|
||||
filename_from_utf8 (const char *encoded)
|
||||
{
|
||||
|
@ -1550,47 +1567,47 @@ filename_from_utf8 (const char *encoded)
|
|||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
filename_to_utf8 (const char *filename)
|
||||
{
|
||||
char *encoded, *ret;
|
||||
|
||||
if (g_utf8_validate (filename, -1, NULL))
|
||||
return g_strdup (filename);
|
||||
|
||||
encoded = g_base64_encode ((const guchar *) filename, strlen (filename) + 1);
|
||||
ret = g_strdup_printf ("base64%s", encoded);
|
||||
g_free (encoded);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static MooEdit *
|
||||
load_doc_session (MooEditor *editor,
|
||||
MooEditWindow *window,
|
||||
MooMarkupNode *elm)
|
||||
MooMarkupNode *elm,
|
||||
gboolean file_is_uri)
|
||||
{
|
||||
char *filename;
|
||||
const char *utf8_filename;
|
||||
const char *uri;
|
||||
const char *encoding;
|
||||
char *freeme = NULL;
|
||||
MooEdit *doc = NULL;
|
||||
MooEditFileInfo *info;
|
||||
|
||||
utf8_filename = moo_markup_get_content (elm);
|
||||
if (file_is_uri)
|
||||
{
|
||||
uri = moo_markup_get_content (elm);
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *filename_utf8 = moo_markup_get_content (elm);
|
||||
char *filename = filename_from_utf8 (filename_utf8);
|
||||
if (filename)
|
||||
{
|
||||
freeme = g_filename_to_uri (filename, NULL, NULL);
|
||||
uri = freeme;
|
||||
}
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
if (!utf8_filename || !utf8_filename[0])
|
||||
if (!uri || !uri[0])
|
||||
{
|
||||
g_free (freeme);
|
||||
return moo_editor_new_doc (editor, window);
|
||||
|
||||
filename = filename_from_utf8 (utf8_filename);
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
}
|
||||
|
||||
encoding = moo_markup_get_prop (elm, "encoding");
|
||||
info = moo_edit_file_info_new (filename, encoding);
|
||||
info = moo_edit_file_info_new_uri (uri, encoding);
|
||||
|
||||
moo_editor_load_file (editor, window, GTK_WIDGET (window), info, TRUE, FALSE, -1, &doc);
|
||||
|
||||
moo_edit_file_info_free (info);
|
||||
g_free (filename);
|
||||
|
||||
g_free (freeme);
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
@ -1598,39 +1615,33 @@ static MooMarkupNode *
|
|||
save_doc_session (MooEdit *doc,
|
||||
MooMarkupNode *elm)
|
||||
{
|
||||
char *filename;
|
||||
char *uri;
|
||||
const char *encoding;
|
||||
MooMarkupNode *node;
|
||||
|
||||
filename = moo_edit_get_filename (doc);
|
||||
uri = moo_edit_get_uri (doc);
|
||||
encoding = moo_edit_get_encoding (doc);
|
||||
|
||||
if (filename)
|
||||
if (uri)
|
||||
{
|
||||
char *utf8_filename;
|
||||
|
||||
utf8_filename = filename_to_utf8 (filename);
|
||||
g_return_val_if_fail (utf8_filename != NULL, NULL);
|
||||
|
||||
node = moo_markup_create_text_element (elm, "document", utf8_filename);
|
||||
node = moo_markup_create_text_element (elm, "document", uri);
|
||||
|
||||
if (encoding && encoding[0])
|
||||
moo_markup_set_prop (node, "encoding", encoding);
|
||||
|
||||
g_free (utf8_filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = moo_markup_create_element (elm, "document");
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
g_free (uri);
|
||||
return node;
|
||||
}
|
||||
|
||||
static MooEditWindow *
|
||||
load_window_session (MooEditor *editor,
|
||||
MooMarkupNode *elm)
|
||||
MooMarkupNode *elm,
|
||||
gboolean file_is_uri)
|
||||
{
|
||||
MooEditWindow *window;
|
||||
MooEdit *active_doc = NULL;
|
||||
|
@ -1644,7 +1655,7 @@ load_window_session (MooEditor *editor,
|
|||
{
|
||||
MooEdit *doc;
|
||||
|
||||
doc = load_doc_session (editor, window, node);
|
||||
doc = load_doc_session (editor, window, node, file_is_uri);
|
||||
|
||||
if (doc && moo_markup_get_bool_prop (node, "active", FALSE))
|
||||
active_doc = doc;
|
||||
|
@ -1691,12 +1702,22 @@ _moo_editor_load_session (MooEditor *editor,
|
|||
MooMarkupNode *xml)
|
||||
{
|
||||
MooMarkupNode *editor_node;
|
||||
gboolean old_format = FALSE;
|
||||
|
||||
g_return_if_fail (MOO_IS_EDITOR (editor));
|
||||
g_return_if_fail (MOO_MARKUP_IS_ELEMENT (xml));
|
||||
|
||||
editor_node = moo_markup_get_element (xml, "editor");
|
||||
|
||||
if (editor_node)
|
||||
{
|
||||
const char *version = moo_markup_get_prop (editor_node, "version");
|
||||
if (!version)
|
||||
old_format = TRUE;
|
||||
else if (strcmp (version, CURRENT_SESSION_VERSION) != 0)
|
||||
editor_node = NULL;
|
||||
}
|
||||
|
||||
if (editor_node)
|
||||
{
|
||||
MooEditWindow *active_window = NULL;
|
||||
|
@ -1709,7 +1730,7 @@ _moo_editor_load_session (MooEditor *editor,
|
|||
if (!MOO_MARKUP_IS_ELEMENT (node))
|
||||
continue;
|
||||
|
||||
window = load_window_session (editor, node);
|
||||
window = load_window_session (editor, node, !old_format);
|
||||
|
||||
if (window && moo_markup_get_bool_prop (node, "active", FALSE))
|
||||
active_window = window;
|
||||
|
@ -1735,6 +1756,7 @@ _moo_editor_save_session (MooEditor *editor,
|
|||
windows = moo_editor_list_windows (editor);
|
||||
|
||||
node = moo_markup_create_element (xml, "editor");
|
||||
moo_markup_set_prop (node, "version", CURRENT_SESSION_VERSION);
|
||||
|
||||
while (windows)
|
||||
{
|
||||
|
@ -1804,7 +1826,7 @@ moo_editor_open_file (MooEditor *editor,
|
|||
MooEditFileInfo *info;
|
||||
GSList *list;
|
||||
|
||||
info = moo_edit_file_info_new (filename, encoding);
|
||||
info = moo_edit_file_info_new_path (filename, encoding);
|
||||
list = g_slist_prepend (NULL, info);
|
||||
|
||||
result = moo_editor_open (editor, window, parent, list);
|
||||
|
@ -1850,7 +1872,7 @@ moo_editor_open_file_line (MooEditor *editor,
|
|||
if (!g_file_test (filename, G_FILE_TEST_EXISTS))
|
||||
goto out;
|
||||
|
||||
info = moo_edit_file_info_new (filename, NULL);
|
||||
info = moo_edit_file_info_new_path (filename, NULL);
|
||||
moo_editor_load_file (editor, window, NULL, info,
|
||||
is_embedded (editor),
|
||||
TRUE, line, &doc);
|
||||
|
@ -1877,6 +1899,7 @@ moo_editor_new_file (MooEditor *editor,
|
|||
{
|
||||
MooEdit *doc = NULL;
|
||||
char *freeme = NULL;
|
||||
GFile *file;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
||||
g_return_val_if_fail (!window || MOO_IS_EDIT_WINDOW (window), NULL);
|
||||
|
@ -1907,10 +1930,12 @@ moo_editor_new_file (MooEditor *editor,
|
|||
doc = moo_editor_new_doc (editor, window);
|
||||
|
||||
doc->priv->status = MOO_EDIT_NEW;
|
||||
_moo_edit_set_filename (doc, filename, encoding);
|
||||
file = g_file_new_for_path (filename);
|
||||
_moo_edit_set_file (doc, file, encoding);
|
||||
moo_editor_set_active_doc (editor, doc);
|
||||
gtk_widget_grab_focus (GTK_WIDGET (doc));
|
||||
|
||||
g_object_unref (file);
|
||||
g_free (freeme);
|
||||
return doc;
|
||||
}
|
||||
|
@ -2006,7 +2031,7 @@ moo_editor_get_save_flags (MooEditor *editor)
|
|||
static gboolean
|
||||
do_save (MooEditor *editor,
|
||||
MooEdit *doc,
|
||||
const char *filename,
|
||||
GFile *file,
|
||||
const char *encoding,
|
||||
GError **error)
|
||||
{
|
||||
|
@ -2023,7 +2048,7 @@ do_save (MooEditor *editor,
|
|||
_moo_edit_ensure_newline (doc);
|
||||
|
||||
g_signal_emit_by_name (doc, "save-before");
|
||||
result = _moo_edit_save_file (doc, filename, encoding,
|
||||
result = _moo_edit_save_file (doc, file, encoding,
|
||||
moo_editor_get_save_flags (editor),
|
||||
error);
|
||||
g_signal_emit_by_name (doc, "save-after");
|
||||
|
@ -2038,7 +2063,7 @@ _moo_editor_save (MooEditor *editor,
|
|||
GError **error)
|
||||
{
|
||||
GError *error_here = NULL;
|
||||
char *filename;
|
||||
GFile *file;
|
||||
char *encoding;
|
||||
gboolean result = FALSE;
|
||||
|
||||
|
@ -2050,7 +2075,7 @@ _moo_editor_save (MooEditor *editor,
|
|||
if (moo_edit_is_untitled (doc))
|
||||
return _moo_editor_save_as (editor, doc, NULL, NULL, error);
|
||||
|
||||
filename = moo_edit_get_filename (doc);
|
||||
file = _moo_edit_get_file (doc);
|
||||
encoding = g_strdup (moo_edit_get_encoding (doc));
|
||||
|
||||
if (!is_embedded (editor) &&
|
||||
|
@ -2058,16 +2083,16 @@ _moo_editor_save (MooEditor *editor,
|
|||
!_moo_edit_overwrite_modified_dialog (doc))
|
||||
goto out;
|
||||
|
||||
if (!do_save (editor, doc, filename, encoding, &error_here))
|
||||
if (!do_save (editor, doc, file, encoding, &error_here))
|
||||
{
|
||||
if (!is_embedded (editor))
|
||||
{
|
||||
gboolean saved_utf8 = error_here->domain == MOO_EDIT_FILE_ERROR &&
|
||||
error_here->code == MOO_EDIT_FILE_ERROR_ENCODING;
|
||||
if (saved_utf8)
|
||||
_moo_edit_save_error_enc_dialog (GTK_WIDGET (doc), filename, encoding);
|
||||
_moo_edit_save_error_enc_dialog (GTK_WIDGET (doc), file, encoding);
|
||||
else
|
||||
_moo_edit_save_error_dialog (GTK_WIDGET (doc), filename, error_here);
|
||||
_moo_edit_save_error_dialog (GTK_WIDGET (doc), file, error_here);
|
||||
g_error_free (error_here);
|
||||
}
|
||||
else
|
||||
|
@ -2079,12 +2104,13 @@ _moo_editor_save (MooEditor *editor,
|
|||
goto out;
|
||||
}
|
||||
|
||||
add_recent_file (editor, filename);
|
||||
add_recent_file (editor, file);
|
||||
result = TRUE;
|
||||
|
||||
/* fall through */
|
||||
out:
|
||||
g_free (filename);
|
||||
if (file)
|
||||
g_object_unref (file);
|
||||
g_free (encoding);
|
||||
return result;
|
||||
}
|
||||
|
@ -2115,10 +2141,12 @@ _moo_editor_save_as (MooEditor *editor,
|
|||
}
|
||||
else
|
||||
{
|
||||
file_info = moo_edit_file_info_new (filename, encoding);
|
||||
if (!encoding)
|
||||
encoding = doc->priv->encoding;
|
||||
file_info = moo_edit_file_info_new_path (filename, encoding);
|
||||
}
|
||||
|
||||
if (!do_save (editor, doc, file_info->filename, file_info->encoding, &error_here))
|
||||
if (!do_save (editor, doc, file_info->file, file_info->encoding, &error_here))
|
||||
{
|
||||
if (!is_embedded (editor))
|
||||
{
|
||||
|
@ -2126,11 +2154,11 @@ _moo_editor_save_as (MooEditor *editor,
|
|||
error_here->code == MOO_EDIT_FILE_ERROR_ENCODING;
|
||||
if (saved_utf8)
|
||||
_moo_edit_save_error_enc_dialog (GTK_WIDGET (doc),
|
||||
file_info->filename,
|
||||
file_info->file,
|
||||
file_info->encoding);
|
||||
else
|
||||
_moo_edit_save_error_dialog (GTK_WIDGET (doc),
|
||||
file_info->filename,
|
||||
file_info->file,
|
||||
error_here);
|
||||
g_error_free (error_here);
|
||||
}
|
||||
|
@ -2143,7 +2171,7 @@ _moo_editor_save_as (MooEditor *editor,
|
|||
goto out;
|
||||
}
|
||||
|
||||
add_recent_file (editor, file_info->filename);
|
||||
add_recent_file (editor, file_info->file);
|
||||
result = TRUE;
|
||||
|
||||
/* fall through */
|
||||
|
@ -2160,11 +2188,19 @@ moo_editor_save_copy (MooEditor *editor,
|
|||
const char *encoding,
|
||||
GError **error)
|
||||
{
|
||||
GFile *file;
|
||||
gboolean retval;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDITOR (editor), FALSE);
|
||||
g_return_val_if_fail (filename != NULL, FALSE);
|
||||
return _moo_edit_save_file_copy (doc, filename, encoding,
|
||||
moo_editor_get_save_flags (editor),
|
||||
error);
|
||||
|
||||
file = g_file_new_for_path (filename);
|
||||
retval = _moo_edit_save_file_copy (doc, file, encoding,
|
||||
moo_editor_get_save_flags (editor),
|
||||
error);
|
||||
|
||||
g_object_unref (file);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2218,6 +2254,50 @@ out:
|
|||
return doc;
|
||||
}
|
||||
|
||||
static MooEdit *
|
||||
doc_list_find_uri (DocList *list,
|
||||
const char *uri)
|
||||
{
|
||||
while (list)
|
||||
{
|
||||
char *tmp = moo_edit_get_uri (list->data);
|
||||
/* XXX */
|
||||
if (tmp && strcmp (tmp, uri) == 0)
|
||||
{
|
||||
g_free (tmp);
|
||||
return list->data;
|
||||
}
|
||||
g_free (tmp);
|
||||
list = list->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
MooEdit *
|
||||
moo_editor_get_doc_for_uri (MooEditor *editor,
|
||||
const char *uri)
|
||||
{
|
||||
MooEdit *doc;
|
||||
WindowList *l;
|
||||
|
||||
g_return_val_if_fail (MOO_IS_EDITOR (editor), NULL);
|
||||
g_return_val_if_fail (uri != NULL, NULL);
|
||||
|
||||
if ((doc = doc_list_find_uri (editor->priv->windowless, uri)))
|
||||
return doc;
|
||||
|
||||
for (l = editor->priv->windows; l != NULL; l = l->next)
|
||||
{
|
||||
DocList *docs = window_list_docs (l->data);
|
||||
doc = doc_list_find_uri (docs, uri);
|
||||
doc_list_free (docs);
|
||||
if (doc)
|
||||
return doc;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
moo_editor_set_window_type (MooEditor *editor,
|
||||
|
|
|
@ -90,6 +90,8 @@ MooEdit *moo_editor_open_uri (MooEditor *editor,
|
|||
|
||||
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);
|
||||
|
|
|
@ -236,23 +236,25 @@ struct MooLocalFileWriter {
|
|||
MOO_DEFINE_TYPE_STATIC (MooLocalFileWriter, moo_local_file_writer, MOO_TYPE_FILE_WRITER)
|
||||
|
||||
static MooFileWriter *
|
||||
moo_local_file_writer_new (const char *filename,
|
||||
moo_local_file_writer_new (GFile *file,
|
||||
MooFileWriterFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
MooLocalFileWriter *writer = NULL;
|
||||
GFile *file = NULL;
|
||||
GFileOutputStream *stream = NULL;
|
||||
GFile *file_copy = NULL;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
|
||||
if (flags & MOO_FILE_WRITER_CONFIG_MODE)
|
||||
{
|
||||
char *dirname;
|
||||
char *filename;
|
||||
|
||||
dirname = g_path_get_dirname (filename);
|
||||
filename = g_file_get_path (file);
|
||||
dirname = filename ? g_path_get_dirname (filename) : NULL;
|
||||
|
||||
if (_moo_mkdir_with_parents (dirname) != 0)
|
||||
if (dirname && _moo_mkdir_with_parents (dirname) != 0)
|
||||
{
|
||||
int err = errno;
|
||||
char *display_name = g_filename_display_name (dirname);
|
||||
|
@ -266,10 +268,11 @@ moo_local_file_writer_new (const char *filename,
|
|||
}
|
||||
|
||||
g_free (dirname);
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
file = g_file_new_for_path (filename);
|
||||
stream = g_file_replace (file, NULL,
|
||||
file_copy = g_file_dup (file);
|
||||
stream = g_file_replace (file_copy, NULL,
|
||||
(flags & MOO_FILE_WRITER_SAVE_BACKUP) != 0,
|
||||
G_FILE_CREATE_NONE,
|
||||
NULL, error);
|
||||
|
@ -278,15 +281,15 @@ moo_local_file_writer_new (const char *filename,
|
|||
goto error;
|
||||
|
||||
writer = g_object_new (MOO_TYPE_LOCAL_FILE_WRITER, NULL);
|
||||
writer->file = file;
|
||||
writer->file = file_copy;
|
||||
writer->stream = G_OUTPUT_STREAM (stream);
|
||||
writer->flags = flags;
|
||||
|
||||
return MOO_FILE_WRITER (writer);
|
||||
|
||||
error:
|
||||
if (file)
|
||||
g_object_unref (file);
|
||||
if (file_copy)
|
||||
g_object_unref (file_copy);
|
||||
if (stream)
|
||||
g_object_unref (stream);
|
||||
return NULL;
|
||||
|
@ -297,9 +300,27 @@ moo_file_writer_new (const char *filename,
|
|||
MooFileWriterFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
GFile *file;
|
||||
MooFileWriter *writer;
|
||||
|
||||
g_return_val_if_fail (filename != NULL, NULL);
|
||||
g_return_val_if_fail (!error || !*error, NULL);
|
||||
return moo_local_file_writer_new (filename, flags, error);
|
||||
|
||||
file = g_file_new_for_path (filename);
|
||||
writer = moo_local_file_writer_new (file, flags, error);
|
||||
|
||||
g_object_unref (file);
|
||||
return writer;
|
||||
}
|
||||
|
||||
MooFileWriter *
|
||||
moo_file_writer_new_for_file (GFile *file,
|
||||
MooFileWriterFlags flags,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
||||
g_return_val_if_fail (!error || !*error, NULL);
|
||||
return moo_local_file_writer_new (file, flags, error);
|
||||
}
|
||||
|
||||
MooFileWriter *
|
||||
|
@ -370,7 +391,9 @@ moo_local_file_writer_close (MooFileWriter *fwriter,
|
|||
|
||||
if (!writer->error)
|
||||
{
|
||||
g_output_stream_close (writer->stream, NULL, &writer->error);
|
||||
g_output_stream_flush (writer->stream, NULL, &writer->error);
|
||||
g_output_stream_close (writer->stream, NULL,
|
||||
writer->error ? NULL : &writer->error);
|
||||
g_object_unref (writer->stream);
|
||||
g_object_unref (writer->file);
|
||||
writer->stream = NULL;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#ifndef MOO_UTILS_FILE_H
|
||||
#define MOO_UTILS_FILE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -45,6 +45,9 @@ typedef enum /*< flags >*/
|
|||
MooFileWriter *moo_file_writer_new (const char *filename,
|
||||
MooFileWriterFlags flags,
|
||||
GError **error);
|
||||
MooFileWriter *moo_file_writer_new_for_file (GFile *file,
|
||||
MooFileWriterFlags flags,
|
||||
GError **error);
|
||||
MooFileWriter *moo_config_writer_new (const char *filename,
|
||||
gboolean save_backup,
|
||||
GError **error);
|
||||
|
|
Loading…
Reference in New Issue