]> git.lyx.org Git - lyx.git/blobdiff - src/factory.cpp
GuiToc::initialiseParams(): Fix list type parsing
[lyx.git] / src / factory.cpp
index 61887ed3484af1dae39c904faed84d1478a1d95a..fd823085ee6e6b194dbc2f95ca3b05585224946e 100644 (file)
 #include "factory.h"
 
 #include "Buffer.h"
-#include "BufferView.h"
 #include "BufferParams.h"
-#include "debug.h"
 #include "FloatList.h"
 #include "FuncRequest.h"
-#include "Color.h"
 #include "Lexer.h"
 #include "LyX.h"
+#include "TextClass.h"
 
 #include "insets/InsetBibitem.h"
 #include "insets/InsetBibtex.h"
@@ -47,7 +45,7 @@
 #include "insets/InsetBox.h"
 #include "insets/InsetBranch.h"
 #include "insets/InsetOptArg.h"
-#include "insets/InsetPagebreak.h"
+#include "insets/InsetNewpage.h"
 #include "insets/InsetRef.h"
 #include "insets/InsetSpace.h"
 #include "insets/InsetTabular.h"
 
 #include "frontends/alert.h"
 
+#include "support/debug.h"
 #include "support/lstrings.h"
 #include "support/ExceptionMessage.h"
 
 #include <boost/assert.hpp>
-#include <boost/current_function.hpp>
 
 #include <sstream>
 
-using std::auto_ptr;
-using std::endl;
-using std::string;
-
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
 namespace Alert = frontend::Alert;
 
-using support::compare_ascii_no_case;
-
 
-Inset * createInset(BufferView * bv, FuncRequest const & cmd)
+Inset * createInset(Buffer & buf, FuncRequest const & cmd)
 {
-       BufferParams const & params = bv->buffer().params();
+       BufferParams const & params = buf.params();
 
        try {
 
@@ -94,6 +88,9 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                case LFUN_LINE_INSERT:
                        return new InsetLine;
 
+               case LFUN_NEWPAGE_INSERT:
+                       return new InsetNewpage;
+
                case LFUN_PAGEBREAK_INSERT:
                        return new InsetPagebreak;
 
@@ -105,9 +102,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
 
                case LFUN_FLEX_INSERT: {
                        string s = cmd.getArg(0);
-                       TextClass tclass = params.getTextClass();
-                       InsetLayout il = tclass.insetlayout(from_utf8(s));
-                       return new InsetFlex(params, il);
+                       return new InsetFlex(params, params.getTextClassPtr(), s);
                }
 
                case LFUN_NOTE_INSERT: {
@@ -147,7 +142,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        return new InsetOptArg(params);
 
                case LFUN_BIBITEM_INSERT:
-                       return new InsetBibitem(InsetCommandParams("bibitem"));
+                       return new InsetBibitem(InsetCommandParams(BIBITEM_CODE));
 
                case LFUN_FLOAT_INSERT: {
                        // check if the float type exists
@@ -155,7 +150,6 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        if (params.getTextClass().floats().typeExist(argument))
                                return new InsetFloat(params, argument);
                        lyxerr << "Non-existent float type: " << argument << endl;
-                       return 0;
                }
 
                case LFUN_FLOAT_WIDE_INSERT: {
@@ -182,42 +176,40 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        return new InsetIndex(params);
 
                case LFUN_NOMENCL_INSERT: {
-                       InsetCommandParams icp("nomenclature");
-                       icp["symbol"] = cmd.argument().empty() ?
-                               bv->cursor().innerText()->getStringToIndex(bv->cursor()) :
-                               cmd.argument();
+                       InsetCommandParams icp(NOMENCL_CODE);
+                       icp["symbol"] = cmd.argument();
                        return new InsetNomencl(icp);
                }
 
                case LFUN_TABULAR_INSERT: {
                        if (cmd.argument().empty())
                                return 0;
-                       std::istringstream ss(to_utf8(cmd.argument()));
+                       istringstream ss(to_utf8(cmd.argument()));
                        int r = 0, c = 0;
                        ss >> r >> c;
                        if (r <= 0)
                                r = 2;
                        if (c <= 0)
                                c = 2;
-                       return new InsetTabular(bv->buffer(), r, c);
+                       return new InsetTabular(buf, r, c);
                }
 
                case LFUN_CAPTION_INSERT: {
                        auto_ptr<InsetCaption> inset(new InsetCaption(params));
                        inset->setAutoBreakRows(true);
                        inset->setDrawFrame(true);
-                       inset->setFrameColor(Color::captionframe);
+                       inset->setFrameColor(Color_captionframe);
                        return inset.release();
                }
 
                case LFUN_INDEX_PRINT:
-                       return new InsetPrintIndex(InsetCommandParams("index_print"));
+                       return new InsetPrintIndex(InsetCommandParams(INDEX_PRINT_CODE));
 
                case LFUN_NOMENCL_PRINT:
-                       return new InsetPrintNomencl(InsetCommandParams("nomencl_print"));
+                       return new InsetPrintNomencl(InsetCommandParams(NOMENCL_PRINT_CODE));
 
                case LFUN_TOC_INSERT:
-                       return new InsetTOC(InsetCommandParams("toc"));
+                       return new InsetTOC(InsetCommandParams(TOC_CODE));
 
                case LFUN_ENVIRONMENT_INSERT:
                        return new InsetEnvironment(params, cmd.argument());
@@ -237,103 +229,102 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                lyxerr << "No such inset '" << name << "'.";
                                return 0;
                        
-                               case BIBITEM_CODE: {
-                                       InsetCommandParams icp(name);
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetBibitem(icp);
-                               }
-               
-                               case BIBTEX_CODE: {
-                                       InsetCommandParams icp(name);
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetBibtex(icp);
-                               }
-
-                               case CITE_CODE: {
-                                       InsetCommandParams icp("citation");
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetCitation(icp);
-                               }
-               
-                               case ERT_CODE: {
-                                       InsetCollapsable::CollapseStatus st;
-                                       InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
-                                       return new InsetERT(params, st);
-                               }
-
-                               case LISTINGS_CODE: {
-                                       InsetListingsParams par;
-                                       InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
-                                       return new InsetListings(params, par);
-                               }
-
-                               case EXTERNAL_CODE: {
-                                       Buffer const & buffer = bv->buffer();
-                                       InsetExternalParams iep;
-                                       InsetExternalMailer::string2params(to_utf8(cmd.argument()), buffer, iep);
-                                       auto_ptr<InsetExternal> inset(new InsetExternal);
-                                       inset->setParams(iep, buffer);
-                                       return inset.release();
-                               }
-
-                               case GRAPHICS_CODE: {
-                                       Buffer const & buffer = bv->buffer();
-                                       InsetGraphicsParams igp;
-                                       InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buffer, igp);
-                                       auto_ptr<InsetGraphics> inset(new InsetGraphics);
-                                       inset->setParams(igp);
-                                       return inset.release();
-                               }
-
-                               case HYPERLINK_CODE: {
-                                       InsetCommandParams icp(name);
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetHyperlink(icp);
-                               }
-
-                               case INCLUDE_CODE: {
-                                       InsetCommandParams iip(name);
-                                       InsetIncludeMailer::string2params(to_utf8(cmd.argument()), iip);
-                                       return new InsetInclude(iip);
-                               }
-
+                       case BIBITEM_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetBibitem(icp);
+                       }
+                       
+                       case BIBTEX_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetBibtex(icp);
+                       }
+                       
+                       case CITE_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetCitation(icp);
+                       }
+                       
+                       case ERT_CODE: {
+                               InsetCollapsable::CollapseStatus st;
+                               InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
+                               return new InsetERT(params, st);
+                       }
+                               
+                       case LISTINGS_CODE: {
+                               InsetListingsParams par;
+                               InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
+                               return new InsetListings(params, par);
+                       }
+                       
+                       case EXTERNAL_CODE: {
+                               InsetExternalParams iep;
+                               InsetExternalMailer::string2params(to_utf8(cmd.argument()), buf, iep);
+                               auto_ptr<InsetExternal> inset(new InsetExternal);
+                               inset->setParams(iep, buf);
+                               return inset.release();
+                       }
+                       
+                       case GRAPHICS_CODE: {
+                               InsetGraphicsParams igp;
+                               InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buf, igp);
+                               auto_ptr<InsetGraphics> inset(new InsetGraphics);
+                               inset->setParams(igp);
+                               return inset.release();
+                       }
+                       
+                       case HYPERLINK_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetHyperlink(icp);
+                       }
+                       
+                       case INCLUDE_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetInclude(icp);
+                       }
+                       
                        case INDEX_CODE:
                                return new InsetIndex(params);
-
-                               case NOMENCL_CODE: {
-                                       InsetCommandParams icp(name);
-                                       InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), icp);
-                                       return new InsetNomencl(icp);
-                               }
-
-                               case LABEL_CODE: {
-                                       InsetCommandParams icp(name);
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetLabel(icp);
-                               }
-
-                               case REF_CODE: {
-                                       InsetCommandParams icp(name);
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetRef(icp, bv->buffer());
-                               }
-
-                               case TOC_CODE: {
-                                       InsetCommandParams icp("toc");
-                                       InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
-                                       return new InsetTOC(icp);
-                               }
-
-                               case VSPACE_CODE: {
-                                       VSpace vspace;
-                                       InsetVSpaceMailer::string2params(to_utf8(cmd.argument()), vspace);
-                                       return new InsetVSpace(vspace);
-                               }
-               
-                               default:
-                                       lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
-                                                       << std::endl;
-                                       return 0;
+                       
+                       case NOMENCL_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, lyx::to_utf8(cmd.argument()), icp);
+                               return new InsetNomencl(icp);
+                       }
+                       
+                       case LABEL_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetLabel(icp);
+                       }
+                       
+                       case REF_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetRef(icp, buf);
+                       }
+                       
+                       case TOC_CODE: {
+                               InsetCommandParams icp(code);
+                               InsetCommandMailer::string2params(name, to_utf8(cmd.argument()), icp);
+                               return new InsetTOC(icp);
+                       }
+                       
+                       case VSPACE_CODE: {
+                               VSpace vspace;
+                               InsetVSpaceMailer::string2params(to_utf8(cmd.argument()), vspace);
+                               return new InsetVSpace(vspace);
+                       }
+                       
+                       default:
+                               lyxerr << "Inset '" << name << "' not permitted with LFUN_INSET_INSERT."
+                                               << endl;
+                               return 0;
+                       
                        }
                        } //end LFUN_INSET_INSERT
 
@@ -341,21 +332,21 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        string const name = to_utf8(cmd.argument());
                        if (name == "normal")
                                return new InsetSpace(InsetSpace::NORMAL);
-                       else if (name == "protected")
+                       if (name == "protected")
                                return new InsetSpace(InsetSpace::PROTECTED);
-                       else if (name == "thin")
+                       if (name == "thin")
                                return new InsetSpace(InsetSpace::THIN);
-                       else if (name == "quad")
+                       if (name == "quad")
                                return new InsetSpace(InsetSpace::QUAD);
-                       else if (name == "qquad")
+                       if (name == "qquad")
                                return new InsetSpace(InsetSpace::QQUAD);
-                       else if (name == "enspace")
+                       if (name == "enspace")
                                return new InsetSpace(InsetSpace::ENSPACE);
-                       else if (name == "enskip")
+                       if (name == "enskip")
                                return new InsetSpace(InsetSpace::ENSKIP);
-                       else if (name == "negthinspace")
+                       if (name == "negthinspace")
                                return new InsetSpace(InsetSpace::NEGTHIN);
-                       else if (name.empty())
+                       if (name.empty())
                                lyxerr << "LyX function 'space' needs an argument." << endl;
                        else
                                lyxerr << "Wrong argument for LyX function 'space'." << endl;
@@ -366,12 +357,12 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        break;
                }
 
-       } catch (support::ExceptionMessage const & message) {
-               if (message.type_ == support::ErrorException) {
+       } catch (ExceptionMessage const & message) {
+               if (message.type_ == ErrorException) {
+                       // This should never happen!
                        Alert::error(message.title_, message.details_);
-                       LyX::cref().emergencyCleanup();
-                       abort();
-               } else if (message.type_ == support::WarningException) {
+                       LyX::cref().exit(1);
+               } else if (message.type_ == WarningException) {
                        Alert::warning(message.title_, message.details_);
                        return 0;
                }
@@ -392,8 +383,6 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
 
        auto_ptr<Inset> inset;
 
-       TextClass tclass = buf.params().getTextClass();
-
        lex.next();
        string tmptok = lex.getString();
 
@@ -417,7 +406,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                //we do not know in advance that we're dealing with a command inset.
                //Worst case, we could put it in each case below. Better, we could
                //pass the lexer to the constructor and let the params be built there.
-               InsetCommandParams inscmd(insetType);
+               InsetCommandParams inscmd(code);
                inscmd.read(lex);
 
                switch (code) {
@@ -433,14 +422,9 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                        case HYPERLINK_CODE:
                                inset.reset(new InsetHyperlink(inscmd));
                                break;
-                       // FIXME Currently non-functional, since InsetInclude
-                       // does not write itself as a CommandInset.
                        case INCLUDE_CODE:
                                inset.reset(new InsetInclude(inscmd));
                                break;
-                       case INDEX_CODE:
-                               inset.reset(new InsetIndex(buf.params()));
-                               break;
                        case INDEX_PRINT_CODE:
                                inset.reset(new InsetPrintIndex(inscmd));
                                break;
@@ -463,7 +447,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                        case NO_CODE:
                        default:
                                lyxerr << "unknown CommandInset '" << insetType
-                                                       << "'" << std::endl;
+                                                       << "'" << endl;
                                while (lex.isOK() && lex.getString() != "\\end_inset")
                                        lex.next();
                                return 0;
@@ -492,15 +476,11 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                } else if (tmptok == "Flex") {
                        lex.next();
                        string s = lex.getString();
-                       InsetLayout il = tclass.insetlayout(from_utf8(s));
-                       inset.reset(new InsetFlex(buf.params(), il));
+                       inset.reset(new InsetFlex(buf.params(), 
+                               buf.params().getTextClassPtr(), s));
                } else if (tmptok == "Branch") {
                        inset.reset(new InsetBranch(buf.params(),
                                                    InsetBranchParams()));
-               } else if (tmptok == "Include") {
-                       //FIXME
-                       InsetCommandParams p("include");
-                       inset.reset(new InsetInclude(p));
                } else if (tmptok == "Environment") {
                        lex.next();
                        inset.reset(new InsetEnvironment(buf.params(), lex.getDocString()));
@@ -544,25 +524,13 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                        inset.reset(new InsetInfo(buf.params()));
                } else {
                        lyxerr << "unknown Inset type '" << tmptok
-                              << "'" << std::endl;
+                              << "'" << endl;
                        while (lex.isOK() && lex.getString() != "\\end_inset")
                                lex.next();
                        return 0;
                }
 
                inset->read(buf, lex);
-
-// FIXME: hack..
-               if (inset->lyxCode() == MATHMACRO_CODE) {
-                       MathMacroTemplate const * tmpl =
-                               static_cast<MathMacroTemplate*>(inset.get());
-                       MacroTable::globalMacros().insert
-                               (tmpl->name(), tmpl->asMacroData());
-                       LYXERR(Debug::DEBUG)
-                               << BOOST_CURRENT_FUNCTION
-                               << ": creating local macro " << to_utf8(tmpl->name())
-                               << endl;
-               }
        }
 
        return inset.release();