]> git.lyx.org Git - lyx.git/blobdiff - src/insets/ExternalTemplate.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / ExternalTemplate.C
index da8fdf5063f879f9019d771be22a28b16f66e301..bfa1e851b86d53ad6e372446f733ee52e04d0f25 100644 (file)
@@ -1,18 +1,15 @@
-/* This file is part of
- * ======================================================
- * 
- *           LyX, The Document Processor
- *      
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2001 The LyX Team.
+/**
+ * \file ExternalTemplate.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * ====================================================== */
+ * \author Asger Alstrup Nielsen
+ *
+ * Full author contact details are available in file CREDITS
+ */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include <algorithm>
 
@@ -34,6 +31,7 @@ extern string user_lyxdir;
 // We have to have dummy default commands for security reasons!
 
 ExternalTemplate::ExternalTemplate()
+       : inputFormat("*")
 {}
 
 
@@ -52,23 +50,23 @@ ExternalTemplateManager::ExternalTemplateManager()
 
 class dumpTemplate {
 public:
-       dumpTemplate(std::ostream & o) 
+       dumpTemplate(ostream & o)
                : ost(o) {}
        void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
                ExternalTemplate const & et = vt.second;
-               
+
                ost << "Template " << et.lyxName << "\n"
                    << "\tGuiName " << et.guiName << "\n"
                    << "\tHelpText\n"
                    << et.helpText
                    << "\tHelpTextEnd\n"
+                   << "\tInputFormat " << et.inputFormat << "\n"
                    << "\tFileFilter " << et.fileRegExp << "\n"
-                   << "\tViewCommand " << et.viewCommand << "\n"
                    << "\tEditCommand " << et.editCommand << "\n"
                    << "\tAutomaticProduction " << et.automaticProduction << "\n";
                et.dumpFormats(ost);
                ost << "TemplateEnd" << endl;
-               
+
        }
 
 private:
@@ -77,13 +75,13 @@ private:
 
 class dumpFormat {
 public:
-       dumpFormat(ostream & o) 
+       dumpFormat(ostream & o)
                : ost(o) {}
        void operator()(ExternalTemplate::Formats::value_type const & vt) const{
                ExternalTemplate::FormatTemplate const & ft = vt.second;
                ost << "\tFormat " << vt.first << "\n"
                    << "\t\tProduct " << ft.product << "\n"
-                   << "\t\tUpdateCommand " << ft.updateCommand << "\n"
+                   << "\t\tUpdateFormat " << ft.updateFormat << "\n"
                    << "\t\tUpdateResult " << ft.updateResult << "\n"
                    << "\t\tRequirement " << ft.requirement << "\n"
                    << "\t\tPreamble\n"
@@ -96,13 +94,13 @@ private:
 };
 
 
-void ExternalTemplate::dumpFormats(ostream & os) const 
+void ExternalTemplate::dumpFormats(ostream & os) const
 {
        for_each(formats.begin(), formats.end(), dumpFormat(os));
 }
 
 
-void ExternalTemplateManager::dumpTemplates() const 
+void ExternalTemplateManager::dumpTemplates() const
 {
        for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
 }
@@ -134,8 +132,8 @@ ExternalTemplate const & ExternalTemplateManager::getTemplateByName(string const
        return templates[name];
 }
 
-void ExternalTemplateManager::readTemplates(string const & path) 
+
+void ExternalTemplateManager::readTemplates(string const & path)
 {
        Path p(path);
 
@@ -143,7 +141,7 @@ void ExternalTemplateManager::readTemplates(string const & path)
                TM_TEMPLATE = 1,
                TM_END
        };
-       
+
        keyword_item templatetags[] = {
                { "template", TM_TEMPLATE },
                { "templateend", TM_END }
@@ -162,7 +160,7 @@ void ExternalTemplateManager::readTemplates(string const & path)
                        "No template file" << endl;
                return;
        }
-       
+
        while (lex.isOK()) {
                switch (lex.lex()) {
                case TM_TEMPLATE: {
@@ -173,7 +171,7 @@ void ExternalTemplateManager::readTemplates(string const & path)
                        tmp.readTemplate(lex);
                }
                break;
-               
+
                case TM_END:
                        lex.printError("Warning: End outside Template.");
                break;
@@ -187,8 +185,8 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
        enum TemplateOptionTags {
                TO_GUINAME = 1,
                TO_HELPTEXT,
+               TO_INPUTFORMAT,
                TO_FILTER,
-               TO_VIEWCMD,
                TO_EDITCMD,
                TO_AUTOMATIC,
                TO_FORMAT,
@@ -202,51 +200,51 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
                { "format", TO_FORMAT },
                { "guiname", TO_GUINAME },
                { "helptext", TO_HELPTEXT },
-               { "templateend", TO_END },
-               { "viewcommand", TO_VIEWCMD }
+               { "inputformat", TO_INPUTFORMAT },
+               { "templateend", TO_END }
        };
 
        pushpophelper pph(lex, templateoptiontags, TO_END);
-       
+
        while (lex.isOK()) {
                switch (lex.lex()) {
                case TO_GUINAME:
                        lex.next(true);
                        guiName = lex.getString();
                        break;
-                       
+
                case TO_HELPTEXT:
                        helpText = lex.getLongString("HelpTextEnd");
                        break;
-                       
-               case TO_FILTER:
+
+               case TO_INPUTFORMAT:
                        lex.next(true);
-                       fileRegExp = lex.getString();
+                       inputFormat = lex.getString();
                        break;
-                       
-               case TO_VIEWCMD:
+
+               case TO_FILTER:
                        lex.next(true);
-                       viewCommand = lex.getString();
+                       fileRegExp = lex.getString();
                        break;
-                       
+
                case TO_EDITCMD:
                        lex.next(true);
                        editCommand = lex.getString();
                        break;
-                       
+
                case TO_AUTOMATIC:
                        lex.next();
                        automaticProduction = lex.getBool();
                        break;
-                       
+
                case TO_FORMAT:
                        lex.next(true);
                        formats[lex.getString()].readFormat(lex);
                        break;
-                       
+
                case TO_END:
                        return;
-                       
+
                default:
                        lex.printError("ExternalTemplate::readTemplate: "
                                       "Wrong tag: $$Token");
@@ -257,54 +255,54 @@ void ExternalTemplate::readTemplate(LyXLex & lex)
 }
 
 
-void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex) 
+void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
 {
        enum FormatTags {
                FO_PRODUCT = 1,
-               FO_UPDATECMD,
+               FO_UPDATEFORMAT,
                FO_UPDATERESULT,
                FO_REQUIREMENT,
                FO_PREAMBLE,
                FO_END
        };
-       
+
        keyword_item formattags[] = {
                { "formatend", FO_END },
                { "preamble", FO_PREAMBLE },
                { "product", FO_PRODUCT },
                { "requirement", FO_REQUIREMENT },
-               { "updatecommand", FO_UPDATECMD },
+               { "updateformat", FO_UPDATEFORMAT },
                { "updateresult", FO_UPDATERESULT }
        };
 
        pushpophelper pph(lex, formattags, FO_END);
-       
+
        while (lex.isOK()) {
                switch (lex.lex()) {
                case FO_PRODUCT:
                        lex.next(true);
                        product = lex.getString();
                        break;
-                       
-               case FO_UPDATECMD:
+
+               case FO_UPDATEFORMAT:
                        lex.next(true);
-                       updateCommand = lex.getString();
+                       updateFormat = lex.getString();
                        break;
 
                case FO_UPDATERESULT:
                        lex.next(true);
                        updateResult = lex.getString();
                        break;
-                       
+
                case FO_REQUIREMENT:
                        lex.next(true);
                        requirement = lex.getString();
                        break;
-                       
+
                case FO_PREAMBLE:
                        preamble = lex.getLongString("preambleend");
                        break;
-                       
+
                case FO_END:
                        if (lyxerr.debugging())
                                lex.printError("FormatEnd");
@@ -312,4 +310,3 @@ void ExternalTemplate::FormatTemplate::readFormat(LyXLex & lex)
                }
        }
 }
-