diff --git a/moo/mooedit/mooedit-fileops.c b/moo/mooedit/mooedit-fileops.c index edec9e60..4cc4d19f 100644 --- a/moo/mooedit/mooedit-fileops.c +++ b/moo/mooedit/mooedit-fileops.c @@ -71,6 +71,7 @@ static void add_status (MooEdit *edit, static gboolean moo_edit_load_local (MooEdit *edit, GFile *file, const char *encoding, + const char *cached_encoding, GError **error); static gboolean moo_edit_reload_local (MooEdit *edit, const char *encoding, @@ -102,9 +103,11 @@ gboolean _moo_edit_load_file (MooEdit *edit, GFile *file, const char *encoding, + const char *cached_encoding, GError **error) { char *encoding_copy; + char *cached_encoding_copy; gboolean result; GError *error_here = NULL; @@ -112,8 +115,9 @@ _moo_edit_load_file (MooEdit *edit, moo_return_val_if_fail (G_IS_FILE (file), FALSE); encoding_copy = g_strdup (normalize_encoding (encoding, FALSE)); + cached_encoding_copy = cached_encoding ? g_strdup (normalize_encoding (cached_encoding, FALSE)) : NULL; - result = moo_edit_load_local (edit, file, encoding_copy, &error_here); + result = moo_edit_load_local (edit, file, encoding_copy, cached_encoding_copy, &error_here); if (error_here) g_propagate_error (error, error_here); @@ -379,6 +383,7 @@ static gboolean moo_edit_load_local (MooEdit *edit, GFile *file, const char *encoding, + const char *cached_encoding, GError **error) { GtkTextIter start; @@ -419,6 +424,8 @@ moo_edit_load_local (MooEdit *edit, GSList *encodings; encodings = get_encodings (); + if (cached_encoding) + encodings = g_slist_prepend (encodings, g_strdup (cached_encoding)); result = ERROR_ENCODING; while (encodings) @@ -761,6 +768,7 @@ moo_edit_reload_local (MooEdit *edit, result = _moo_edit_load_file (edit, file, encoding ? encoding : edit->priv->encoding, + NULL, error); g_object_set (edit, "enable-highlight", enable_highlight, (char*) 0); diff --git a/moo/mooedit/mooedit-fileops.h b/moo/mooedit/mooedit-fileops.h index 2dab6874..e3719134 100644 --- a/moo/mooedit/mooedit-fileops.h +++ b/moo/mooedit/mooedit-fileops.h @@ -44,6 +44,7 @@ GQuark _moo_edit_file_error_quark (void) G_GNUC_CONST; gboolean _moo_edit_load_file (MooEdit *edit, GFile *file, const char *encoding, + const char *cached_encoding, GError **error); gboolean _moo_edit_reload_file (MooEdit *edit, const char *encoding, diff --git a/moo/mooedit/mooeditor.c b/moo/mooedit/mooeditor.c index ab10e456..1563423c 100644 --- a/moo/mooedit/mooeditor.c +++ b/moo/mooedit/mooeditor.c @@ -815,7 +815,7 @@ moo_editor_create_doc (MooEditor *editor, if (filename) file = g_file_new_for_path (filename); - if (file && !_moo_edit_load_file (doc, file, encoding, error)) + if (file && !_moo_edit_load_file (doc, file, encoding, NULL, error)) { g_object_ref_sink (doc); g_object_unref (file); @@ -920,6 +920,7 @@ moo_editor_load_file (MooEditor *editor, MooEdit *doc = NULL; char *uri; gboolean result = TRUE; + const char *recent_encoding = NULL; *docp = NULL; uri = g_file_get_uri (info->file); @@ -951,8 +952,15 @@ moo_editor_load_file (MooEditor *editor, new_doc = TRUE; } + if (!info->encoding) + { + MdHistoryItem *hist_item = md_history_mgr_find_uri (editor->priv->history, uri); + if (hist_item) + recent_encoding = _moo_edit_history_item_get_encoding (hist_item); + } + /* XXX open_single */ - if (!_moo_edit_load_file (doc, info->file, info->encoding, &error)) + if (!_moo_edit_load_file (doc, info->file, info->encoding, recent_encoding, &error)) { if (!silent) { @@ -1281,11 +1289,44 @@ do_close_window (MooEditor *editor, } +static void +update_history_item_for_doc (MooEditor *editor, + MooEdit *doc) +{ + char *uri; + MdHistoryItem *item; + int line; + const char *enc; + + if (is_embedded (editor)) + return; + + if (!(uri = moo_edit_get_uri (doc))) + return; + + item = md_history_item_new (uri, NULL); + + line = moo_text_view_get_cursor_line (MOO_TEXT_VIEW (doc)); + if (line != 0) + _moo_edit_history_item_set_line (item, line); + + enc = moo_edit_get_encoding (doc); + if (enc && !_moo_encodings_equal (enc, MOO_ENCODING_UTF8)) + { + _moo_edit_history_item_set_encoding (item, enc); + g_print ("*** file: %s, encoding: %s ***\n", uri, enc); + } + + md_history_mgr_update_file (editor->priv->history, item); + md_history_item_free (item); + g_free (uri); +} + + static void do_close_doc (MooEditor *editor, MooEdit *doc) { - char *uri; MooEditWindow *window; window = moo_edit_get_window (doc); @@ -1296,26 +1337,7 @@ do_close_doc (MooEditor *editor, editor->priv->windowless = doc_list_remove (editor->priv->windowless, doc); } - if (!is_embedded (editor) && (uri = moo_edit_get_uri (doc))) - { - MdHistoryItem *item; - int line; - const char *enc; - - item = md_history_item_new (uri, NULL); - - line = moo_text_view_get_cursor_line (MOO_TEXT_VIEW (doc)); - if (line != 0) - _moo_edit_history_item_set_line (item, line); - - enc = moo_edit_get_encoding (doc); - if (enc && !_moo_encodings_equal (enc, MOO_ENCODING_UTF8)) - _moo_edit_history_item_set_encoding (item, enc); - - md_history_mgr_update_file (editor->priv->history, item); - md_history_item_free (item); - g_free (uri); - } + update_history_item_for_doc (editor, doc); if (window) _moo_edit_window_remove_doc (window, doc, TRUE); @@ -2180,6 +2202,8 @@ _moo_editor_save_as (MooEditor *editor, file_info = moo_edit_file_info_new_path (filename, encoding); } + update_history_item_for_doc (editor, doc); + result = do_save (editor, doc, file_info->file, file_info->encoding, error); /* fall through */