]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_main.C
Alfredo's second patch
[lyx.git] / src / lyx_main.C
index ba262926874ee876fd9b6cd5697b4c37d47378b7..d365a0d2803ababe5f342db13f9c976b1fb92df2 100644 (file)
@@ -673,14 +673,29 @@ void LyX::readUIFile(string const & name)
        enum Uitags {
                ui_menuset = 1,
                ui_toolbar,
+               ui_include,
                ui_last
        };
 
        struct keyword_item uitags[ui_last - 1] = {
+               { "include", ui_include },
                { "menuset", ui_menuset },
                { "toolbar", ui_toolbar }
        };
 
+       // Ensure that a file is read only once (prevents include loops)
+       static std::list<string> uifiles;
+       std::list<string>::const_iterator it  = uifiles.begin();
+       std::list<string>::const_iterator end = uifiles.end();
+       it = std::find(it, end, name);
+       if (it != end) {
+               lyxerr[Debug::INIT] << "UI file '" << name
+                                   << "' has been read already. "
+                                   << "Is this an include loop?"
+                                   << endl;
+               return;
+       }
+
        lyxerr[Debug::INIT] << "About to read " << name << "..." << endl;
 
        string const ui_path = LibFileSearch("ui", name, "ui");
@@ -690,6 +705,7 @@ void LyX::readUIFile(string const & name)
                showFileError(name);
                return;
        }
+       uifiles.push_back(name);
 
        lyxerr[Debug::INIT] << "Found " << name
                            << " in " << ui_path << endl;
@@ -705,6 +721,12 @@ void LyX::readUIFile(string const & name)
 
        while (lex.isOK()) {
                switch (lex.lex()) {
+               case ui_include: {
+                       lex.next(true);
+                       string const file = lex.getString();
+                       readUIFile(file);
+                       break;
+               }
                case ui_menuset:
                        menubackend.read(lex);
                        break;