Author: rgheck
Date: Tue Jan 18 16:09:43 2011
New Revision: 37247
URL: http://www.lyx.org/trac/changeset/37247

Log:
Format conversion for bind files. This completes the coding part of the
rc2rc project. (Was there a bug number for that? I can't find it, if
there was.)

Modified:
   lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp

Modified: lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp        Tue Jan 18 
16:07:26 2011        (r37246)
+++ lyx-devel/trunk/src/frontends/qt4/GuiApplication.cpp        Tue Jan 18 
16:09:43 2011        (r37247)
@@ -2319,10 +2319,12 @@
                ui_toolbars,
                ui_toolbarset,
                ui_include,
+               ui_format,
                ui_last
        };
 
        LexerKeyword uitags[] = {
+               { "format", ui_format },
                { "include", ui_include },
                { "menuset", ui_menuset },
                { "toolbars", ui_toolbars },
@@ -2340,15 +2342,40 @@
                lex.printTable(lyxerr);
 
        bool error = false;
+       // format before introduction of format tag
+       unsigned int format = 0;
        while (lex.isOK()) {
-               switch (lex.lex()) {
+               int const status = lex.lex();
+
+               // we have to do this check here, outside the switch,
+               // because otherwise we would start reading include files,
+               // e.g., if the first tag we hit was an include tag.
+               if (status == ui_format)
+                       if (lex.next()) {
+                               format = lex.getInteger();
+                               continue;
+                       }
+
+               // this will trigger unless the first tag we hit is a format
+               // tag, with the right format.
+               if (format != LFUN_FORMAT)
+                       return FormatMismatch;
+
+               switch (status) {
+               case Lexer::LEX_FEOF:
+                       continue;
+
                case ui_include: {
                        lex.next(true);
                        QString const file = toqstr(lex.getString());
-                       if (!readUIFile(file, true))
+                       bool const success = readUIFile(file, true);
+                       if (!success) {
+                               LYXERR0("Failed to read inlcuded file: " << 
fromqstr(file));
                                return ReadError;
+                       }
                        break;
                }
+
                case ui_menuset:
                        d->menus_.read(lex);
                        break;
@@ -2365,10 +2392,13 @@
                default:
                        if (!rtrim(lex.getString()).empty())
                                lex.printError("LyX::ReadUIFile: "
-                                                                "Unknown menu 
tag: `$$Token'");
+                                              "Unknown menu tag: `$$Token'");
+                       else
+                               LYXERR0("Error with status: " << status);
                        error = true;
                        break;
                }
+
        }
        return (error ? ReadError : ReadOK);
 }
@@ -2428,7 +2458,25 @@
 
        LYXERR(Debug::INIT, "Found " << name << " in " << ui_path);
 
-       readUIFile(ui_path);
+       ReturnValues retval = readUIFile(ui_path);
+
+       if (retval == FormatMismatch) {
+               LYXERR(Debug::FILES, "Converting ui file to format " << 
LFUN_FORMAT);
+               FileName const tempfile = FileName::tempName("convert_ui");
+               bool const success = prefs2prefs(ui_path, tempfile, true);
+               if (!success) {
+                       LYXERR0("Unable to convert " << ui_path.absFileName() <<
+                               " to format " << LFUN_FORMAT << ".");
+               } else {
+                       retval = readUIFile(tempfile);
+                       tempfile.removeFile();
+               }
+       }
+
+       if (retval != ReadOK) {
+               LYXERR0("Unable to read UI file: " << ui_path.absFileName());
+               return false;
+       }
 
        if (include)
                return true;

Reply via email to