]> git.lyx.org Git - lyx.git/blobdiff - src/buffer.C
remove unused code
[lyx.git] / src / buffer.C
index c5d5110e8e4dcecb33b9967d0ec2abb5836793f1..d45fb87f960450fecc75ddcd2b32b5000a282a75 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "buffer.h"
 #include "bufferlist.h"
-#include "lyx_main.h"
+#include "counters.h"
 #include "LyXAction.h"
 #include "lyxrc.h"
 #include "lyxlex.h"
@@ -45,6 +45,7 @@
 #include "ParagraphParameters.h"
 #include "iterators.h"
 #include "lyxtextclasslist.h"
+#include "sgml.h"
 
 #include "mathed/formulamacro.h"
 #include "mathed/formula.h"
@@ -94,6 +95,9 @@
 #include "support/lyxmanip.h"
 #include "support/lyxalgo.h" // for lyx::count
 
+#include <boost/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+
 #include <fstream>
 #include <iomanip>
 #include <map>
 #include <sys/types.h>
 #include <utime.h>
 
-
 #ifdef HAVE_LOCALE
 #include <locale>
 #endif
@@ -131,6 +134,7 @@ using std::max;
 using std::set;
 using std::stack;
 using std::list;
+using std::for_each;
 
 using lyx::pos_type;
 using lyx::textclass_type;
@@ -138,26 +142,20 @@ using lyx::textclass_type;
 // all these externs should eventually be removed.
 extern BufferList bufferlist;
 
-extern LyXAction lyxaction;
-
 namespace {
 
 const int LYX_FORMAT = 220;
 
 } // namespace anon
 
-extern int tex_code_break_column;
-
-
 Buffer::Buffer(string const & file, bool ronly)
-       : paragraph(0), niceFile(true), lyx_clean(true), bak_clean(true),
+       : niceFile(true), lyx_clean(true), bak_clean(true),
          unnamed(false), dep_clean(0), read_only(ronly),
-         filename_(file), users(0)
+         filename_(file), users(0), ctrs(new Counters)
 {
        lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
 //     filename = file;
        filepath_ = OnlyPath(file);
-//     paragraph = 0;
 //     lyx_clean = true;
 //     bak_clean = true;
 //     dep_clean = 0;
@@ -188,14 +186,7 @@ Buffer::~Buffer()
                DestroyBufferTmpDir(tmppath);
        }
 
-       Paragraph * par = paragraph;
-       Paragraph * tmppar;
-       while (par) {
-               tmppar = par->next();
-               delete par;
-               par = tmppar;
-       }
-       paragraph = 0;
+       paragraphs.clear();
 
        // Remove any previewed LaTeX snippets assocoated with this buffer.
        grfx::Previews::get().removeLoader(this);
@@ -252,7 +243,7 @@ void Buffer::setReadonly(bool flag)
        if (read_only != flag) {
                read_only = flag;
                updateTitles();
-               users->owner()->getDialogs()->updateBufferDependent(false);
+               users->owner()->getDialogs().updateBufferDependent(false);
        }
 }
 
@@ -383,7 +374,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
        if (!first_par)
                first_par = par;
 
-       paragraph = first_par;
+       paragraphs.set(first_par);
 
        if (unknown_layouts > 0) {
                string s = _("Couldn't set the layout for ");
@@ -1503,7 +1494,7 @@ void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
        for(string::const_iterator cit = str.begin();
            cit != str.end(); ++cit) {
                if (*cit == '\n') {
-                       if (autobreakrows && (par->size() || layout->keepempty)) {
+                       if (autobreakrows && (!par->empty() || layout->keepempty)) {
                                par->breakParagraph(params, pos,
                                                    layout->isEnvironment());
                                par = par->next();
@@ -1852,7 +1843,7 @@ bool Buffer::writeFile(string const & fname) const
 
        // this will write out all the paragraphs
        // using recursive descent.
-       paragraph->writeFile(this, ofs, params, depth);
+       paragraphs.begin()->writeFile(this, ofs, params, depth);
 
        // Write marker that shows file is complete
        ofs << "\n\\the_end" << endl;
@@ -2127,10 +2118,11 @@ void Buffer::writeFileAscii(string const & fname, int linelen)
 
 void Buffer::writeFileAscii(ostream & ofs, int linelen)
 {
-       Paragraph * par = paragraph;
-       while (par) {
-               ofs << asciiParagraph(par, linelen, par->previous() == 0);
-               par = par->next();
+       ParagraphList::iterator beg = paragraphs.begin();
+       ParagraphList::iterator end = paragraphs.end();
+       ParagraphList::iterator it = beg;
+       for (; it != end; ++it) {
+               ofs << asciiParagraph(&*it, linelen, it == beg);
        }
        ofs << "\n";
 }
@@ -2166,8 +2158,6 @@ void Buffer::makeLaTeXFile(ostream & os,
 {
        niceFile = nice; // this will be used by Insetincludes.
 
-       tex_code_break_column = lyxrc.ascii_linelen;
-
        // validate the buffer.
        lyxerr[Debug::LATEX] << "  Validating buffer..." << endl;
        LaTeXFeatures features(params);
@@ -2177,7 +2167,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        texrow.reset();
        // The starting paragraph of the coming rows is the
        // first paragraph of the document. (Asger)
-       texrow.start(paragraph, 0);
+       texrow.start(&*(paragraphs.begin()), 0);
 
        if (!only_body && nice) {
                os << "%% " << lyx_docversion << " created this file.  "
@@ -2192,9 +2182,7 @@ void Buffer::makeLaTeXFile(ostream & os,
        // usual is \batchmode and has a
        // special input@path to allow the including of figures
        // with either \input or \includegraphics (what figinsets do).
-       // batchmode is not set if there is a tex_code_break_column.
-       // In this case somebody is interested in the generated LaTeX,
-       // so this is OK. input@path is set when the actual parameter
+       // input@path is set when the actual parameter
        // original_path is set. This is done for usual tex-file, but not
        // for nice-latex-file. (Matthias 250696)
        if (!only_body) {
@@ -2606,7 +2594,7 @@ void Buffer::makeLaTeXFile(ostream & os,
                texrow.newline();
        }
 
-       latexParagraphs(os, paragraph, 0, texrow);
+       latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
 
        // add this just in case after all the paragraphs
        os << endl;
@@ -2632,12 +2620,6 @@ void Buffer::makeLaTeXFile(ostream & os,
        // Just to be sure. (Asger)
        texrow.newline();
 
-       // tex_code_break_column's value is used to decide
-       // if we are in batchmode or not (within mathed_write()
-       // in math_write.C) so we must set it to a non-zero
-       // value when we leave otherwise we save incorrect .lyx files.
-       tex_code_break_column = lyxrc.ascii_linelen;
-
        lyxerr[Debug::INFO] << "Finished making latex file." << endl;
        lyxerr[Debug::INFO] << "Row count was " << texrow.rows()-1 << "." << endl;
 
@@ -2814,7 +2796,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
            << " -->\n";
 
        Paragraph::depth_type depth = 0; // paragraph depth
-       Paragraph * par = paragraph;
+       Paragraph * par = &*(paragraphs.begin());
        string item_name;
        vector<string> environment_stack(5);
 
@@ -3162,10 +3144,10 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
                                os << c;
                        ++char_line_count;
                } else {
-                       string sgml_string;
-                       if (par->sgmlConvertChar(c, sgml_string)
-                           && !style->free_spacing && !par->isFreeSpacing())
-                       {
+                       bool ws;
+                       string str;
+                       boost::tie(ws, str) = sgml::escapeChar(c);
+                       if (ws && !style->free_spacing && !par->isFreeSpacing()) {
                                // in freespacing mode, spaces are
                                // non-breaking characters
                                if (desc_on) {// if char is ' ' then...
@@ -3179,8 +3161,8 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
                                        os << c;
                                }
                        } else {
-                               os << sgml_string;
-                               char_line_count += sgml_string.length();
+                               os << str;
+                               char_line_count += str.length();
                        }
                }
                font_old = font;
@@ -3229,7 +3211,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
                return;
        }
 
-       Paragraph * par = paragraph;
+       Paragraph * par = &*(paragraphs.begin());
 
        niceFile = nice; // this will be used by Insetincludes.
 
@@ -3552,13 +3534,14 @@ void Buffer::simpleDocBookOnePar(ostream & os,
                        }
                } else {
                        char c = par->getChar(i);
-                       string sgml_string;
-                       par->sgmlConvertChar(c, sgml_string);
+                       bool ws;
+                       string str;
+                       boost::tie(ws, str) = sgml::escapeChar(c);
 
                        if (style->pass_thru) {
                                os << c;
                        } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
-                                       os << sgml_string;
+                                       os << str;
                        } else if (desc_on ==1) {
                                ++char_line_count;
                                os << "\n</term><listitem><para>";
@@ -3641,25 +3624,14 @@ int Buffer::runChktex()
 
 void Buffer::validate(LaTeXFeatures & features) const
 {
-       Paragraph * par = paragraph;
        LyXTextClass const & tclass = params.getLyXTextClass();
 
        // AMS Style is at document level
        if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
                features.require("amsmath");
 
-       while (par) {
-               // We don't use "lyxerr.debug" because of speed. (Asger)
-               if (lyxerr.debugging(Debug::LATEX))
-                       lyxerr << "Paragraph: " <<  par << endl;
-
-               // Now just follow the list of paragraphs and run
-               // validate on each of them.
-               par->validate(features);
-
-               // and then the next paragraph
-               par = par->next();
-       }
+       for_each(paragraphs.begin(), paragraphs.end(),
+                boost::bind(&Paragraph::validate, _1, boost::ref(features)));
 
        // the bullet shapes are buffer level not paragraph level
        // so they are tested here
@@ -3712,20 +3684,20 @@ string const Buffer::getIncludeonlyList(char delim)
 }
 
 
-vector<string> const Buffer::getLabelList()
+vector<string> const Buffer::getLabelList() const
 {
        /// if this is a child document and the parent is already loaded
        /// Use the parent's list instead  [ale990407]
        if (!params.parentname.empty()
            && bufferlist.exists(params.parentname)) {
-               Buffer * tmp = bufferlist.getBuffer(params.parentname);
+               Buffer const * tmp = bufferlist.getBuffer(params.parentname);
                if (tmp)
                        return tmp->getLabelList();
        }
 
        vector<string> label_list;
-       for (inset_iterator it = inset_iterator_begin();
-            it != inset_iterator_end(); ++it) {
+       for (inset_iterator it = inset_const_iterator_begin();
+            it != inset_const_iterator_end(); ++it) {
                vector<string> const l = (*it)->getLabelList();
                label_list.insert(label_list.end(), l.begin(), l.end());
        }
@@ -3746,17 +3718,17 @@ vector<pair<string, string> > const Buffer::getBibkeyList() const
        }
 
        vector<StringPair> keys;
-       Paragraph * par = paragraph;
-       while (par) {
-               if (par->bibkey) {
-                       string const key = par->bibkey->getContents();
-                       string const opt = par->bibkey->getOptions();
-                       string const ref = par->asString(this, false);
+       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));
                }
-               par = par->next();
        }
 
        // Might be either using bibtex or a child has bibliography
@@ -3846,10 +3818,8 @@ bool Buffer::dispatch(int action, string const & argument, bool * result)
 void Buffer::resizeInsets(BufferView * bv)
 {
        /// then remove all LyXText in text-insets
-       Paragraph * par = paragraph;
-       for (; par; par = par->next()) {
-           par->resizeInsetsLyXText(bv);
-       }
+       for_each(paragraphs.begin(), paragraphs.end(),
+                boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
 }
 
 
@@ -3881,11 +3851,17 @@ bool Buffer::isMultiLingual()
 }
 
 
+Counters & Buffer::counters() const
+{
+       return *ctrs.get();
+}
+
+
 Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
        : par(paragraph)
 {
-       it = par->InsetIterator(pos);
-       if (it == par->inset_iterator_end()) {
+       it = par->insetlist.insetIterator(pos);
+       if (it == par->insetlist.end()) {
                par = par->next();
                setParagraph();
        }
@@ -3895,8 +3871,8 @@ Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
 void Buffer::inset_iterator::setParagraph()
 {
        while (par) {
-               it = par->inset_iterator_begin();
-               if (it != par->inset_iterator_end())
+               it = par->insetlist.begin();
+               if (it != par->insetlist.end())
                        return;
                par = par->next();
        }
@@ -3922,17 +3898,19 @@ Inset * Buffer::getInsetFromID(int id_arg) const
 
 Paragraph * Buffer::getParFromID(int id) const
 {
-       if (id < 0) return 0;
-       Paragraph * par = paragraph;
-       while (par) {
-               if (par->id() == id) {
-                       return par;
+       if (id < 0)
+               return 0;
+
+       ParagraphList::iterator it = paragraphs.begin();
+       ParagraphList::iterator end = paragraphs.end();
+       for (; it != end; ++it) {
+               if (it->id() == id) {
+                       return &*it;
                }
-               Paragraph * tmp = par->getParFromID(id);
+               Paragraph * tmp = it->getParFromID(id);
                if (tmp) {
                        return tmp;
                }
-               par = par->next();
        }
        return 0;
 }
@@ -3940,7 +3918,7 @@ Paragraph * Buffer::getParFromID(int id) const
 
 ParIterator Buffer::par_iterator_begin()
 {
-       return ParIterator(paragraph);
+       return ParIterator(&*(paragraphs.begin()));
 }