Hi,

I'm sure I've already proposed this or a similar patch and I'm not being able 
to find the TT, but I stumbled across this again: LyX refuses to open a file if 
lyx2lyx fails the conversion, but often LyX would simply be successful in the 
attempt of reading/parsing the file, with some risk of loosing peculiarities of 
the other (new) format which are not recognized thus discarded during the 
loading process.

A typical instance of this problem happens with a brand new nearly empty 
document is created with trunk/master, when trying to open it back with the 
system-wide (older) LyX.

Please, find my patch/proposal below, where the user is notified and queried, 
with the default action being: do not open.

Any comment welcome, thanks.

    T.

tommaso@tommylap:~/lyx-trunk-ws/lyx$ git show 7b58ce4f
commit 7b58ce4f
Author: Tommaso Cucinotta <tomm...@lyx.org>
Date:   Wed Oct 19 11:18:10 2016 +0200

    Tolerate formats that are not supported by lyx2lyx.

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 8efa53bb..3124ae0d 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -1150,14 +1150,22 @@ Buffer::ReadStatus Buffer::readFile(FileName const & fn)
        if (file_format != LYX_FORMAT) {
                FileName tmpFile;
                ReadStatus ret_clf = convertLyXFormat(fn, tmpFile, file_format);
-               if (ret_clf != ReadSuccess)
-                       return ret_clf;
-               ret_clf = readFile(tmpFile);
                if (ret_clf == ReadSuccess) {
-                       d->file_format = file_format;
-                       d->need_format_backup = true;
+                       ret_clf = readFile(tmpFile);
+                       if (ret_clf == ReadSuccess) {
+                               d->file_format = file_format;
+                               d->need_format_backup = true;
+                               return ret_clf;
+                       }
+               }
+               if (ret_clf != ReadSuccess) {
+                       int const ret = Alert::prompt(_("Document format 
failure"),
+                               _("Fileformat unrecognized by lyx2lyx. Trying to 
load anyway, "
+                                 "but some contents might be lost and LyX might 
crash!\n"
+                                 "Would you like to proceed ?"), 0, 1, _("&No"), 
_("&Yes"));
+                       if (ret == 0)
+                               return ret_clf;
                }
-               return ret_clf;
        }

        // FIXME: InsetInfo needs to know whether the file is under VCS

Reply via email to