]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
Minimal fix needed to give Qt a label dialog again.
[lyx.git] / src / buffer.C
index 207b6c60aa2dd5dd8a3426fbf6710df2f666ebe8..d091ac51e867a2cec56a97b67b30cc5bf48342df 100644 (file)
@@ -33,7 +33,7 @@
 #include "language.h"
 #include "exporter.h"
 #include "Lsstream.h"
-#include "converter.h"
+#include "format.h"
 #include "BufferView.h"
 #include "ParagraphParameters.h"
 #include "iterators.h"
@@ -55,7 +55,8 @@
 #include "insets/insetnote.h"
 #include "insets/insetquotes.h"
 #include "insets/insetlatexaccent.h"
-#include "insets/insetbib.h"
+#include "insets/insetbibitem.h"
+#include "insets/insetbibtex.h"
 #include "insets/insetcite.h"
 #include "insets/insetexternal.h"
 #include "insets/insetindex.h"
@@ -130,8 +131,6 @@ using std::pair;
 using std::make_pair;
 using std::vector;
 using std::map;
-using std::max;
-using std::set;
 using std::stack;
 using std::list;
 using std::for_each;
@@ -163,7 +162,7 @@ Buffer::Buffer(string const & file, bool ronly)
        }
 
        // set initial author
-       authorlist.record(Author(lyxrc.user_name, lyxrc.user_email)); 
+       authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
 }
 
 
@@ -397,7 +396,7 @@ namespace {
        // but this code is too b0rken to admit of a better solution yet
        Change current_change;
 };
+
 
 bool
 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
@@ -773,7 +772,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                istringstream ss(lex.getString());
                Author a;
                ss >> a;
-               int aid(authorlist.record(a)); 
+               int aid(authorlist.record(a));
                lyxerr << "aid is " << aid << endl;
                lyxerr << "listed aid is " << author_ids.size() << endl;
                author_ids.push_back(authorlist.record(a));
@@ -924,7 +923,8 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                params.float_placement = lex.getString();
        } else if (token == "\\align") {
                int tmpret = lex.findToken(string_align);
-               if (tmpret == -1) ++tmpret;
+               if (tmpret == -1)
+                       ++tmpret;
                int const tmpret2 = int(pow(2.0, tmpret));
                par->params().align(LyXAlignment(tmpret2));
        } else if (token == "\\added_space_top") {
@@ -957,6 +957,12 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                inset->read(this, lex);
                par->insertInset(pos, inset, font, current_change);
                ++pos;
+       } else if (token == "\\bibitem") {  // ale970302
+               InsetCommandParams p("bibitem", "dummy");
+               InsetBibitem * inset = new InsetBibitem(p);
+               inset->read(this, lex);
+               par->insertInset(pos, inset, font, current_change);
+               ++pos;
        } else if (token == "\\hfill") {
                par->insertChar(pos, Paragraph::META_HFILL, font, current_change);
                ++pos;
@@ -981,12 +987,6 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
                istr >> aid;
                istr >> ct;
                current_change = Change(Change::DELETED, author_ids[aid], ct);
-       } else if (token == "\\bibitem") {  // ale970302
-               if (!par->bibkey) {
-                       InsetCommandParams p("bibitem", "dummy");
-                       par->bibkey = new InsetBibKey(p);
-               }
-               par->bibkey->read(this, lex);
        } else if (token == "\\the_end") {
                the_end_read = true;
        } else {
@@ -1015,7 +1015,7 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
 
 // needed to insert the selection
 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
-                                LyXFont const & fn,string const & str) const
+                                LyXFont const & fn,string const & str)
 {
        LyXLayout_ptr const & layout = par->layout();
 
@@ -1030,7 +1030,7 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
                        if (autobreakrows && (!par->empty() || layout->keepempty)) {
-                               breakParagraph(params, par, pos,
+                               breakParagraph(this, par, pos,
                                               layout->isEnvironment());
                                par = par->next();
                                pos = 0;
@@ -1100,7 +1100,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                        inset = new InsetCitation(inscmd);
                } else if (cmdName == "bibitem") {
                        lex.printError("Wrong place for bibitem");
-                       inset = new InsetBibKey(inscmd);
+                       inset = new InsetBibitem(inscmd);
                } else if (cmdName == "BibTeX") {
                        inset = new InsetBibtex(inscmd);
                } else if (cmdName == "index") {
@@ -1135,7 +1135,6 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                        inset = new InsetParent(inscmd, *this);
                }
        } else {
-               bool alreadyread = false;
                if (tmptok == "Quotes") {
                        inset = new InsetQuotes;
                } else if (tmptok == "External") {
@@ -1144,16 +1143,8 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                        inset = new InsetFormulaMacro;
                } else if (tmptok == "Formula") {
                        inset = new InsetFormula;
-               } else if (tmptok == "Figure") { // Backward compatibility
-//                     inset = new InsetFig(100, 100, *this);
-                       inset = new InsetGraphics;
                } else if (tmptok == "Graphics") {
                        inset = new InsetGraphics;
-               } else if (tmptok == "Info") {// backwards compatibility
-                       inset = new InsetNote(this,
-                                             lex.getLongString("\\end_inset"),
-                                             true);
-                       alreadyread = true;
                } else if (tmptok == "Note") {
                        inset = new InsetNote(params);
                } else if (tmptok == "Include") {
@@ -1193,7 +1184,8 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
                        inset = new InsetFloatList;
                }
 
-               if (inset && !alreadyread) inset->read(this, lex);
+               if (inset)
+                       inset->read(this, lex);
        }
 
        if (inset) {
@@ -1400,7 +1392,7 @@ bool Buffer::writeFile(string const & fname) const
                        ofs << "\\author " << it->second << "\n";
                }
        }
+
        Paragraph::depth_type depth = 0;
 
        // this will write out all the paragraphs
@@ -1587,7 +1579,7 @@ string const Buffer::asciiParagraph(Paragraph const & par,
 
        // this is to change the linebreak to do it by word a bit more
        // intelligent hopefully! (only in the case where we have a
-       // max linelenght!) (Jug)
+       // max linelength!) (Jug)
 
        string word;
 
@@ -1786,7 +1778,7 @@ void Buffer::makeLaTeXFile(ostream & os,
                texrow.newline();
        }
 
-       latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
+       latexParagraphs(os, paragraphs.begin(), paragraphs.end(), texrow);
 
        // add this just in case after all the paragraphs
        os << endl;
@@ -1824,8 +1816,10 @@ void Buffer::makeLaTeXFile(ostream & os,
 //
 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
 //
-void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
-                            Paragraph * endpar, TexRow & texrow,
+void Buffer::latexParagraphs(ostream & ofs,
+                            ParagraphList::iterator par,
+                            ParagraphList::iterator endpar,
+                            TexRow & texrow,
                             bool moving_arg) const
 {
        bool was_title = false;
@@ -1873,12 +1867,12 @@ void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
                        if (layout->isEnvironment() ||
                                !par->params().leftIndent().zero())
                        {
-                               par = par->TeXEnvironment(this, params, ofs, texrow);
+                               par = TeXEnvironment(this, params, par, ofs, texrow);
                        } else {
-                               par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
+                               par = TeXOnePar(this, params, par, ofs, texrow, moving_arg);
                        }
                } else {
-                       par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
+                       par = TeXOnePar(this, params, par, ofs, texrow, moving_arg);
                }
        }
        // It might be that we only have a title in this document
@@ -2035,6 +2029,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
 
                case LATEX_ENVIRONMENT:
                case LATEX_ITEM_ENVIRONMENT:
+               case LATEX_BIB_ENVIRONMENT:
                {
                        string const & latexname = style->latexname();
 
@@ -2089,6 +2084,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
                        break;
                case LATEX_ENVIRONMENT:
                case LATEX_ITEM_ENVIRONMENT:
+               case LATEX_BIB_ENVIRONMENT:
                        if (style->latexparam() == "CDATA")
                                ofs << "]]>";
                        break;
@@ -2811,7 +2807,7 @@ void Buffer::validate(LaTeXFeatures & features) const
                features.require("dvipost");
                features.require("color");
        }
+
        // AMS Style is at document level
        if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
                features.require("amsmath");
@@ -2871,50 +2867,33 @@ vector<string> const Buffer::getLabelList() const
 
 
 // This is also a buffer property (ale)
-vector<pair<string, string> > const Buffer::getBibkeyList() const
+void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
 {
-       typedef pair<string, string> StringPair;
        /// if this is a child document and the parent is already loaded
-       /// Use the parent's list instead  [ale990412]
+       /// use the parent's list instead  [ale990412]
        if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
                Buffer const * tmp = bufferlist.getBuffer(params.parentname);
-               if (tmp)
-                       return tmp->getBibkeyList();
-       }
-
-       vector<StringPair> keys;
-       ParagraphList::iterator pit = paragraphs.begin();
-       ParagraphList::iterator pend = paragraphs.end();
-       for (; pit != pend; ++pit) {
-               if (pit->bibkey) {
-                       string const key = pit->bibkey->getContents();
-                       string const opt = pit->bibkey->getOptions();
-                       string const ref = pit->asString(this, false);
-                       string const info = opt + "TheBibliographyRef" + ref;
-
-                       keys.push_back(StringPair(key, info));
+               if (tmp) {
+                       tmp->fillWithBibKeys(keys);
+                       return;
                }
        }
 
-       if (!keys.empty())
-               return keys;
-
-       // Might be either using bibtex or a child has bibliography
        for (inset_iterator it = inset_const_iterator_begin();
                it != inset_const_iterator_end(); ++it) {
-               // Search for Bibtex or Include inset
-               if (it->lyxCode() == Inset::BIBTEX_CODE) {
-                       vector<StringPair> tmp =
-                               static_cast<InsetBibtex &>(*it).getKeys(this);
-                       keys.insert(keys.end(), tmp.begin(), tmp.end());
-               } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
-                       vector<StringPair> const tmp =
-                               static_cast<InsetInclude &>(*it).getKeys();
-                       keys.insert(keys.end(), tmp.begin(), tmp.end());
+               if (it->lyxCode() == Inset::BIBTEX_CODE)
+                       static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
+               else if (it->lyxCode() == Inset::INCLUDE_CODE)
+                       static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
+               else if (it->lyxCode() == Inset::BIBITEM_CODE) {
+                       InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
+                       string const key = bib.getContents();
+                       string const opt = bib.getOptions();
+                       string const ref; // = pit->asString(this, false);
+                       string const info = opt + "TheBibliographyRef" + ref;
+                       keys.push_back(pair<string, string>(key, info));
                }
        }
-
-       return keys;
 }
 
 
@@ -3029,7 +3008,7 @@ Paragraph * Buffer::getParFromID(int id) const
 {
        if (id < 0)
                return 0;
+
        // why should we allow < 0 ??
        //lyx::Assert(id >= 0);