X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=5c07e74c5670af0ccdb2fc37800ec3f9dcd0cd16;hb=b0babedcb7a9f4c737540d8ac7007b12ff5d979b;hp=323c897849dd067a13b64343339191371c393ea5;hpb=9681e21dae96d2152df6387ec2e8626ee5b0bd42;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index 323c897849..5c07e74c56 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -30,7 +30,6 @@
#include "version.h"
#include "LaTeX.h"
#include "Chktex.h"
-#include "frontends/LyXView.h"
#include "debug.h"
#include "LaTeXFeatures.h"
#include "lyxtext.h"
@@ -45,6 +44,9 @@
#include "iterators.h"
#include "lyxtextclasslist.h"
#include "sgml.h"
+#include "paragraph_funcs.h"
+
+#include "frontends/LyXView.h"
#include "mathed/formulamacro.h"
#include "mathed/formula.h"
@@ -70,8 +72,10 @@
#include "insets/insetgraphics.h"
#include "insets/insetfoot.h"
#include "insets/insetmarginal.h"
+#include "insets/insetoptarg.h"
#include "insets/insetminipage.h"
#include "insets/insetfloat.h"
+#include "insets/insetwrap.h"
#include "insets/insettabular.h"
#if 0
#include "insets/insettheorem.h"
@@ -94,6 +98,9 @@
#include "support/lyxmanip.h"
#include "support/lyxalgo.h" // for lyx::count
+#include
+#include
+
#include
#include
#include
";
}
- sgmlOpenTag(ofs, depth, false, style->latexname());
+ sgml::openTag(ofs, depth, false, style->latexname());
break;
case LATEX_COMMAND:
@@ -2839,12 +2298,12 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
" LatexType Command.\n"));
if (!environment_stack[depth].empty()) {
- sgmlCloseTag(ofs, depth, false, environment_stack[depth]);
+ sgml::closeTag(ofs, depth, false, environment_stack[depth]);
ofs << "";
}
environment_stack[depth].erase();
- sgmlOpenTag(ofs, depth, false, style->latexname());
+ sgml::openTag(ofs, depth, false, style->latexname());
break;
case LATEX_ENVIRONMENT:
@@ -2854,7 +2313,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
if (depth == par->params().depth()
&& environment_stack[depth] != latexname) {
- sgmlCloseTag(ofs, depth, false,
+ sgml::closeTag(ofs, depth, false,
environment_stack[depth]);
environment_stack[depth].erase();
}
@@ -2864,9 +2323,9 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
}
if (environment_stack[depth] != latexname) {
if (depth == 0) {
- sgmlOpenTag(ofs, depth, false, "p");
+ sgml::openTag(ofs, depth, false, "p");
}
- sgmlOpenTag(ofs, depth, false, latexname);
+ sgml::openTag(ofs, depth, false, latexname);
if (environment_stack.size() == depth + 1)
environment_stack.push_back("!-- --");
@@ -2883,12 +2342,12 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
else
item_name = "item";
- sgmlOpenTag(ofs, depth + 1, false, item_name);
+ sgml::openTag(ofs, depth + 1, false, item_name);
}
break;
default:
- sgmlOpenTag(ofs, depth, false, style->latexname());
+ sgml::openTag(ofs, depth, false, style->latexname());
break;
}
@@ -2907,18 +2366,18 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
ofs << "]]>";
break;
default:
- sgmlCloseTag(ofs, depth, false, style->latexname());
+ sgml::closeTag(ofs, depth, false, style->latexname());
break;
}
}
// Close open tags
for (int i = depth; i >= 0; --i)
- sgmlCloseTag(ofs, depth, false, environment_stack[i]);
+ sgml::closeTag(ofs, depth, false, environment_stack[i]);
if (!body_only) {
ofs << "\n\n";
- sgmlCloseTag(ofs, 0, false, top_element);
+ sgml::closeTag(ofs, 0, false, top_element);
}
ofs.close();
@@ -3244,7 +2703,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
top += " ";
top += params.options;
}
- sgmlOpenTag(ofs, 0, false, top);
+ sgml::openTag(ofs, 0, false, top);
ofs << "\n";
@@ -3274,11 +2733,11 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
for (; depth > par->params().depth(); --depth) {
if (environment_inner[depth] != "!-- --") {
item_name = "listitem";
- sgmlCloseTag(ofs, command_depth + depth, false, item_name);
+ sgml::closeTag(ofs, command_depth + depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]);
+ sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
}
- sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
environment_stack[depth].erase();
environment_inner[depth].erase();
}
@@ -3288,12 +2747,12 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
&& !environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
- sgmlCloseTag(ofs, command_depth+depth, false, item_name);
+ sgml::closeTag(ofs, command_depth+depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
}
- sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
environment_stack[depth].erase();
environment_inner[depth].erase();
@@ -3302,7 +2761,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
// Write opening SGML tags.
switch (style->latextype) {
case LATEX_PARAGRAPH:
- sgmlOpenTag(ofs, depth + command_depth,
+ sgml::openTag(ofs, depth + command_depth,
false, style->latexname());
break;
@@ -3323,14 +2782,14 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
if (cmd_depth < command_base) {
for (Paragraph::depth_type j = command_depth;
j >= command_base; --j) {
- sgmlCloseTag(ofs, j, false, command_stack[j]);
+ sgml::closeTag(ofs, j, false, command_stack[j]);
ofs << endl;
}
command_depth = command_base = cmd_depth;
} else if (cmd_depth <= command_depth) {
for (int j = command_depth;
j >= int(cmd_depth); --j) {
- sgmlCloseTag(ofs, j, false, command_stack[j]);
+ sgml::closeTag(ofs, j, false, command_stack[j]);
ofs << endl;
}
command_depth = cmd_depth;
@@ -3359,10 +2818,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
}
- sgmlOpenTag(ofs, depth + command_depth, false, command_name);
+ sgml::openTag(ofs, depth + command_depth, false, command_name);
item_name = c_params.empty()?"title":c_params;
- sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name);
+ sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
break;
case LATEX_ENVIRONMENT:
@@ -3379,13 +2838,13 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
environment_stack[depth] = style->latexname();
environment_inner[depth] = "!-- --";
- sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]);
+ sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
} else {
if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
- sgmlCloseTag(ofs, command_depth + depth, false, item_name);
+ sgml::closeTag(ofs, command_depth + depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
}
}
@@ -3394,7 +2853,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
if (style->latexparam() == "CDATA")
ofs << "latexparam());
+ sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
}
break;
}
@@ -3402,15 +2861,15 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
desc_on = (style->labeltype == LABEL_MANUAL);
environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
- sgmlOpenTag(ofs, depth + 1 + command_depth,
+ sgml::openTag(ofs, depth + 1 + command_depth,
false, environment_inner[depth]);
item_name = desc_on ? "term" : "para";
- sgmlOpenTag(ofs, depth + 1 + command_depth,
+ sgml::openTag(ofs, depth + 1 + command_depth,
false, item_name);
break;
default:
- sgmlOpenTag(ofs, depth + command_depth,
+ sgml::openTag(ofs, depth + command_depth,
false, style->latexname());
break;
}
@@ -3424,7 +2883,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
switch (style->latextype) {
case LATEX_COMMAND:
end_tag = c_params.empty() ? "title" : c_params;
- sgmlCloseTag(ofs, depth + command_depth,
+ sgml::closeTag(ofs, depth + command_depth,
false, end_tag);
break;
case LATEX_ENVIRONMENT:
@@ -3432,19 +2891,19 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
if (style->latexparam() == "CDATA")
ofs << "]]>";
else
- sgmlCloseTag(ofs, depth + command_depth, false, style->latexparam());
+ sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
}
break;
case LATEX_ITEM_ENVIRONMENT:
if (desc_on == 1) break;
end_tag= "para";
- sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag);
+ sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
break;
case LATEX_PARAGRAPH:
- sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
+ sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
break;
default:
- sgmlCloseTag(ofs, depth + command_depth, false, style->latexname());
+ sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
break;
}
}
@@ -3454,23 +2913,23 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
if (!environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
item_name = "listitem";
- sgmlCloseTag(ofs, command_depth + depth, false, item_name);
+ sgml::closeTag(ofs, command_depth + depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
}
- sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
}
}
for (int j = command_depth; j >= 0 ; --j)
if (!command_stack[j].empty()) {
- sgmlCloseTag(ofs, j, false, command_stack[j]);
+ sgml::closeTag(ofs, j, false, command_stack[j]);
ofs << endl;
}
ofs << "\n\n";
- sgmlCloseTag(ofs, 0, false, top_element);
+ sgml::closeTag(ofs, 0, false, top_element);
ofs.close();
// How to check for successful close
@@ -3620,25 +3079,14 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const
{
- Paragraph * par = &*(paragraphs.begin());
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
@@ -3670,27 +3118,6 @@ void Buffer::validate(LaTeXFeatures & features) const
}
-// This function should be in Buffer because it's a buffer's property (ale)
-string const Buffer::getIncludeonlyList(char delim)
-{
- string lst;
- for (inset_iterator it = inset_iterator_begin();
- it != inset_iterator_end(); ++it) {
- if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
- InsetInclude * insetinc =
- static_cast(*it);
- if (insetinc->isIncludeOnly()) {
- if (!lst.empty())
- lst += delim;
- lst += insetinc->getRelFileBaseName();
- }
- }
- }
- lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
- return lst;
-}
-
-
vector const Buffer::getLabelList() const
{
/// if this is a child document and the parent is already loaded
@@ -3705,7 +3132,7 @@ vector const Buffer::getLabelList() const
vector label_list;
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it) {
- vector const l = (*it)->getLabelList();
+ vector const l = it->getLabelList();
label_list.insert(label_list.end(), l.begin(), l.end());
}
return label_list;
@@ -3725,33 +3152,34 @@ vector > const Buffer::getBibkeyList() const
}
vector keys;
- Paragraph * par = &*(paragraphs.begin());
- 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();
}
+ if (!keys.empty())
+ return keys;
+
// Might be either using bibtex or a child has bibliography
- if (keys.empty()) {
- 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 tmp =
- static_cast(*it)->getKeys(this);
- keys.insert(keys.end(), tmp.begin(), tmp.end());
- } else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
- vector const tmp =
- static_cast(*it)->getKeys();
- keys.insert(keys.end(), tmp.begin(), tmp.end());
- }
+ 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 tmp =
+ static_cast(*it).getKeys(this);
+ keys.insert(keys.end(), tmp.begin(), tmp.end());
+ } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
+ vector const tmp =
+ static_cast(*it).getKeys();
+ keys.insert(keys.end(), tmp.begin(), tmp.end());
}
}
@@ -3825,10 +3253,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 = &*(paragraphs.begin());
- for (; par; par = par->next()) {
- par->resizeInsetsLyXText(bv);
- }
+ for_each(paragraphs.begin(), paragraphs.end(),
+ boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
}
@@ -3860,27 +3286,14 @@ bool Buffer::isMultiLingual()
}
-Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
- : par(paragraph)
-{
- it = par->insetlist.insetIterator(pos);
- if (it == par->insetlist.end()) {
- par = par->next();
- setParagraph();
- }
-}
-
-
void Buffer::inset_iterator::setParagraph()
{
- while (par) {
- it = par->insetlist.begin();
- if (it != par->insetlist.end())
+ while (pit != pend) {
+ it = pit->insetlist.begin();
+ if (it != pit->insetlist.end())
return;
- par = par->next();
+ ++pit;
}
- //it = 0;
- // We maintain an invariant that whenever par = 0 then it = 0
}
@@ -3889,9 +3302,9 @@ Inset * Buffer::getInsetFromID(int id_arg) const
for (inset_iterator it = inset_const_iterator_begin();
it != inset_const_iterator_end(); ++it)
{
- if ((*it)->id() == id_arg)
- return *it;
- Inset * in = (*it)->getInsetFromID(id_arg);
+ if (it->id() == id_arg)
+ return &(*it);
+ Inset * in = it->getInsetFromID(id_arg);
if (in)
return in;
}
@@ -3901,17 +3314,19 @@ Inset * Buffer::getInsetFromID(int id_arg) const
Paragraph * Buffer::getParFromID(int id) const
{
- if (id < 0) return 0;
- Paragraph * par = &*(paragraphs.begin());
- 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;
}
@@ -3927,3 +3342,192 @@ ParIterator Buffer::par_iterator_end()
{
return ParIterator();
}
+
+ParConstIterator Buffer::par_iterator_begin() const
+{
+ return ParConstIterator(&*(paragraphs.begin()));
+}
+
+
+ParConstIterator Buffer::par_iterator_end() const
+{
+ return ParConstIterator();
+}
+
+
+
+void Buffer::addUser(BufferView * u)
+{
+ users = u;
+}
+
+
+void Buffer::delUser(BufferView *)
+{
+ users = 0;
+}
+
+
+Language const * Buffer::getLanguage() const
+{
+ return params.language;
+}
+
+
+bool Buffer::isClean() const
+{
+ return lyx_clean;
+}
+
+
+bool Buffer::isBakClean() const
+{
+ return bak_clean;
+}
+
+
+void Buffer::markClean() const
+{
+ if (!lyx_clean) {
+ lyx_clean = true;
+ updateTitles();
+ }
+ // if the .lyx file has been saved, we don't need an
+ // autosave
+ bak_clean = true;
+}
+
+
+void Buffer::markBakClean()
+{
+ bak_clean = true;
+}
+
+
+void Buffer::setUnnamed(bool flag)
+{
+ unnamed = flag;
+}
+
+
+bool Buffer::isUnnamed()
+{
+ return unnamed;
+}
+
+
+void Buffer::markDirty()
+{
+ if (lyx_clean) {
+ lyx_clean = false;
+ updateTitles();
+ }
+ bak_clean = false;
+ DEPCLEAN * tmp = dep_clean;
+ while (tmp) {
+ tmp->clean = false;
+ tmp = tmp->next;
+ }
+}
+
+
+string const & Buffer::fileName() const
+{
+ return filename_;
+}
+
+
+string const & Buffer::filePath() const
+{
+ return filepath_;
+}
+
+
+bool Buffer::isReadonly() const
+{
+ return read_only;
+}
+
+
+BufferView * Buffer::getUser() const
+{
+ return users;
+}
+
+
+void Buffer::setParentName(string const & name)
+{
+ params.parentname = name;
+}
+
+
+Buffer::inset_iterator::inset_iterator()
+ : pit(0), pend(0)
+{}
+
+
+Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
+ : pit(p), pend(e)
+{
+ setParagraph();
+}
+
+
+Buffer::inset_iterator & Buffer::inset_iterator::operator++()
+{
+ if (pit != pend) {
+ ++it;
+ if (it == pit->insetlist.end()) {
+ ++pit;
+ setParagraph();
+ }
+ }
+ return *this;
+}
+
+
+Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
+{
+ inset_iterator tmp = *this;
+ ++*this;
+ return tmp;
+}
+
+
+Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
+{
+ return *it.getInset();
+}
+
+
+Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
+{
+ return it.getInset();
+}
+
+
+Paragraph * Buffer::inset_iterator::getPar()
+{
+ return &(*pit);
+}
+
+
+lyx::pos_type Buffer::inset_iterator::getPos() const
+{
+ return it.getPos();
+}
+
+
+bool operator==(Buffer::inset_iterator const & iter1,
+ Buffer::inset_iterator const & iter2)
+{
+ return iter1.pit == iter2.pit
+ && (iter1.pit == iter1.pend || iter1.it == iter2.it);
+}
+
+
+bool operator!=(Buffer::inset_iterator const & iter1,
+ Buffer::inset_iterator const & iter2)
+{
+ return !(iter1 == iter2);
+}