]> git.lyx.org Git - lyx.git/blobdiff - src/factory.cpp
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[lyx.git] / src / factory.cpp
index 3d21819847ab7aa5604960be1f234b4f5bdab6e6..cb5c15d36d60e7eab98351841824f548e6ae9d9b 100644 (file)
 #include "Color.h"
 #include "Lexer.h"
 #include "LyX.h"
-#include "Paragraph.h"
 
 #include "insets/InsetBibitem.h"
 #include "insets/InsetBibtex.h"
 #include "insets/InsetCaption.h"
 #include "insets/InsetCitation.h"
-#include "insets/InsetCharStyle.h"
+#include "insets/InsetFlex.h"
 #include "insets/InsetEnvironment.h"
 #include "insets/InsetERT.h"
+#include "insets/InsetListings.h"
 #include "insets/InsetExternal.h"
 #include "insets/InsetFloat.h"
 #include "insets/InsetFloatList.h"
 
 #include <sstream>
 
+using std::auto_ptr;
+using std::endl;
+using std::string;
+
 
 namespace lyx {
 
@@ -75,14 +79,10 @@ namespace Alert = frontend::Alert;
 
 using support::compare_ascii_no_case;
 
-using std::auto_ptr;
-using std::endl;
-using std::string;
-
 
 Inset * createInset(BufferView * bv, FuncRequest const & cmd)
 {
-       BufferParams const & params = bv->buffer()->params();
+       BufferParams const & params = bv->buffer().params();
 
        try {
 
@@ -102,14 +102,11 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                case LFUN_CLEARDOUBLEPAGE_INSERT:
                        return new InsetClearDoublePage;
 
-               case LFUN_CHARSTYLE_INSERT: {
+               case LFUN_FLEX_INSERT: {
                        string s = cmd.getArg(0);
-                       LyXTextClass tclass = params.getLyXTextClass();
-                       CharStyles::iterator found_cs = tclass.charstyle(s);
-                       if (found_cs != tclass.charstyles().end())
-                               return new InsetCharStyle(params, found_cs);
-                       else
-                               return new InsetCharStyle(params, s);
+                       TextClass tclass = params.getTextClass();
+                       InsetLayout il = tclass.insetlayout(from_utf8(s));
+                       return new InsetFlex(params, il);
                }
 
                case LFUN_NOTE_INSERT: {
@@ -136,6 +133,9 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                case LFUN_ERT_INSERT:
                        return new InsetERT(params);
 
+               case LFUN_LISTING_INSERT:
+                       return new InsetListings(params);
+
                case LFUN_FOOTNOTE_INSERT:
                        return new InsetFoot(params);
 
@@ -151,7 +151,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                case LFUN_FLOAT_INSERT: {
                        // check if the float type exists
                        string const argument = to_utf8(cmd.argument());
-                       if (params.getLyXTextClass().floats().typeExist(argument))
+                       if (params.getTextClass().floats().typeExist(argument))
                                return new InsetFloat(params, argument);
                        lyxerr << "Non-existent float type: " << argument << endl;
                        return 0;
@@ -160,7 +160,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                case LFUN_FLOAT_WIDE_INSERT: {
                        // check if the float type exists
                        string const argument = to_utf8(cmd.argument());
-                       if (params.getLyXTextClass().floats().typeExist(argument)) {
+                       if (params.getTextClass().floats().typeExist(argument)) {
                                auto_ptr<InsetFloat> p(new InsetFloat(params, argument));
                                p->wide(true, params);
                                return p.release();
@@ -173,7 +173,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        string const argument = to_utf8(cmd.argument());
                        if (argument == "figure")
                                return new InsetWrap(params, argument);
-                       lyxerr << "Non-existent floatflt type: " << argument << endl;
+                       lyxerr << "Non-existent wrapfig type: " << argument << endl;
                        return 0;
                }
 
@@ -204,7 +204,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                r = 2;
                        if (c <= 0)
                                c = 2;
-                       return new InsetTabular(*bv->buffer(), r, c);
+                       return new InsetTabular(bv->buffer(), r, c);
                }
 
                case LFUN_CAPTION_INSERT: {
@@ -225,7 +225,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                        return new InsetTOC(InsetCommandParams("tableofcontents"));
 
                case LFUN_ENVIRONMENT_INSERT:
-                       return new InsetEnvironment(params, to_utf8(cmd.argument()));
+                       return new InsetEnvironment(params, cmd.argument());
 
 #if 0
                case LFUN_LIST_INSERT:
@@ -261,8 +261,13 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                InsetERTMailer::string2params(to_utf8(cmd.argument()), st);
                                return new InsetERT(params, st);
 
+                       } else if (name == "listings") {
+                               InsetListingsParams par;
+                               InsetListingsMailer::string2params(to_utf8(cmd.argument()), par);
+                               return new InsetListings(params, par);
+
                        } else if (name == "external") {
-                               Buffer const & buffer = *bv->buffer();
+                               Buffer const & buffer = bv->buffer();
                                InsetExternalParams iep;
                                InsetExternalMailer::string2params(to_utf8(cmd.argument()),
                                        buffer, iep);
@@ -271,7 +276,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                return inset.release();
 
                        } else if (name == "graphics") {
-                               Buffer const & buffer = *bv->buffer();
+                               Buffer const & buffer = bv->buffer();
                                InsetGraphicsParams igp;
                                InsetGraphicsMailer::string2params(to_utf8(cmd.argument()),
                                        buffer, igp);
@@ -306,7 +311,7 @@ Inset * createInset(BufferView * bv, FuncRequest const & cmd)
                                InsetCommandParams icp(name);
                                InsetCommandMailer::string2params(name, to_utf8(cmd.argument()),
                                        icp);
-                               return new InsetRef(icp, *bv->buffer());
+                               return new InsetRef(icp, bv->buffer());
 
                        } else if (name == "toc") {
                                InsetCommandParams icp("tableofcontents");
@@ -382,7 +387,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
 
        auto_ptr<Inset> inset;
 
-       LyXTextClass tclass = buf.params().getLyXTextClass();
+       TextClass tclass = buf.params().getTextClass();
 
        lex.next();
        string tmptok = lex.getString();
@@ -402,8 +407,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                // the various \\footcite commands. We should increase the
                // file format number and read these commands here, too.
                // Then we should use is_possible_cite_command() in
-               // src/frontends/controllers/frontend_helpers.cpp to test for valid cite
-               // commands.
+               // InsetCitation to test for valid cite commands.
                if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
                        inset.reset(new InsetCitation(inscmd));
                } else if (cmdName == "bibitem") {
@@ -465,16 +469,11 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                        inset.reset(new InsetNote(buf.params(), tmptok));
                } else if (tmptok == "Box") {
                        inset.reset(new InsetBox(buf.params(), tmptok));
-               } else if (tmptok == "CharStyle") {
+               } else if (tmptok == "Flex") {
                        lex.next();
                        string s = lex.getString();
-                       CharStyles::iterator found_cs = tclass.charstyle(s);
-                       if (found_cs != tclass.charstyles().end())
-                               inset.reset(new InsetCharStyle(buf.params(), found_cs));
-                       else {
-                               // "Undefined" inset
-                               inset.reset(new InsetCharStyle(buf.params(), s));
-                       }
+                       InsetLayout il = tclass.insetlayout(from_utf8(s));
+                       inset.reset(new InsetFlex(buf.params(), il));
                } else if (tmptok == "Branch") {
                        inset.reset(new InsetBranch(buf.params(),
                                                    InsetBranchParams()));
@@ -483,9 +482,11 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
                        inset.reset(new InsetInclude(p));
                } else if (tmptok == "Environment") {
                        lex.next();
-                       inset.reset(new InsetEnvironment(buf.params(), lex.getString()));
+                       inset.reset(new InsetEnvironment(buf.params(), lex.getDocString()));
                } else if (tmptok == "ERT") {
                        inset.reset(new InsetERT(buf.params()));
+               } else if (tmptok == "listings") {
+                       inset.reset(new InsetListings(buf.params()));
                } else if (tmptok == "InsetSpace") {
                        inset.reset(new InsetSpace);
                } else if (tmptok == "Tabular") {
@@ -528,9 +529,7 @@ Inset * readInset(Lexer & lex, Buffer const & buf)
 
                inset->read(buf, lex);
 
-#ifdef WITH_WARNINGS
-#warning hack..
-#endif
+// FIXME: hack..
                if (inset->lyxCode() == Inset::MATHMACRO_CODE) {
                        MathMacroTemplate const * tmpl =
                                static_cast<MathMacroTemplate*>(inset.get());