X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=5c07e74c5670af0ccdb2fc37800ec3f9dcd0cd16;hb=b0babedcb7a9f4c737540d8ac7007b12ff5d979b;hp=331c336463b27a1f5c9c5f04851d2deaad42d4b3;hpb=dbd7a961fc46bb10c85bdd8c7fb6626477ae63d8;p=lyx.git
diff --git a/src/buffer.C b/src/buffer.C
index 331c336463..5c07e74c56 100644
--- a/src/buffer.C
+++ b/src/buffer.C
@@ -1,6 +1,6 @@
/* This file is part of
- * ======================================================
- *
+ * ======================================================
+ *
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
@@ -9,7 +9,7 @@
* This file is Copyright 1996-2001
* Lars Gullik Bjønnes
*
- * ======================================================
+ * ======================================================
*/
#include
@@ -20,7 +20,6 @@
#include "buffer.h"
#include "bufferlist.h"
-#include "lyx_main.h"
#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
@@ -31,7 +30,6 @@
#include "version.h"
#include "LaTeX.h"
#include "Chktex.h"
-#include "LyXView.h"
#include "debug.h"
#include "LaTeXFeatures.h"
#include "lyxtext.h"
@@ -45,6 +43,10 @@
#include "ParagraphParameters.h"
#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"
@@ -57,10 +59,10 @@
#include "insets/insetnote.h"
#include "insets/insetquotes.h"
#include "insets/insetlatexaccent.h"
-#include "insets/insetbib.h"
-#include "insets/insetcite.h"
+#include "insets/insetbib.h"
+#include "insets/insetcite.h"
#include "insets/insetexternal.h"
-#include "insets/insetindex.h"
+#include "insets/insetindex.h"
#include "insets/insetinclude.h"
#include "insets/insettoc.h"
#include "insets/insetparent.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"
@@ -83,6 +87,8 @@
#include "frontends/Dialogs.h"
#include "frontends/Alert.h"
+#include "graphics/Previews.h"
+
#include "support/textutils.h"
#include "support/filetools.h"
#include "support/path.h"
@@ -92,6 +98,9 @@
#include "support/lyxmanip.h"
#include "support/lyxalgo.h" // for lyx::count
+#include
+#include
+
#include
#include
#include
";
+ ofs << "";
}
- sgmlOpenTag(ofs, depth, style.latexname());
+ sgml::openTag(ofs, depth, false, style->latexname());
break;
case LATEX_COMMAND:
@@ -2698,20 +2298,22 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
" LatexType Command.\n"));
if (!environment_stack[depth].empty()) {
- sgmlCloseTag(ofs, depth,
- environment_stack[depth]);
+ sgml::closeTag(ofs, depth, false, environment_stack[depth]);
ofs << "";
}
environment_stack[depth].erase();
- sgmlOpenTag(ofs, depth, style.latexname());
+ sgml::openTag(ofs, depth, false, style->latexname());
break;
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
- if (depth == par->params().depth()
- && environment_stack[depth] != style.latexname()) {
- sgmlCloseTag(ofs, depth,
+ {
+ string const & latexname = style->latexname();
+
+ if (depth == par->params().depth()
+ && environment_stack[depth] != latexname) {
+ sgml::closeTag(ofs, depth, false,
environment_stack[depth]);
environment_stack[depth].erase();
}
@@ -2719,31 +2321,33 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
depth = par->params().depth();
environment_stack[depth].erase();
}
- if (environment_stack[depth] != style.latexname()) {
+ if (environment_stack[depth] != latexname) {
if (depth == 0) {
- sgmlOpenTag(ofs, depth, "p");
+ sgml::openTag(ofs, depth, false, "p");
}
- sgmlOpenTag(ofs, depth, style.latexname());
+ sgml::openTag(ofs, depth, false, latexname);
if (environment_stack.size() == depth + 1)
environment_stack.push_back("!-- --");
- environment_stack[depth] = style.latexname();
+ environment_stack[depth] = latexname;
}
- if (style.latexparam() == "CDATA")
+ if (style->latexparam() == "CDATA")
ofs << "latextype == LATEX_ENVIRONMENT) break;
- if (style.labeltype == LABEL_MANUAL)
+ if (style->labeltype == LABEL_MANUAL)
item_name = "tag";
else
item_name = "item";
- sgmlOpenTag(ofs, depth + 1, item_name);
- break;
+ sgml::openTag(ofs, depth + 1, false, item_name);
+ }
+ break;
+
default:
- sgmlOpenTag(ofs, depth, style.latexname());
+ sgml::openTag(ofs, depth, false, style->latexname());
break;
}
@@ -2753,31 +2357,34 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
ofs << "\n";
// write closing SGML tags
- switch (style.latextype) {
+ switch (style->latextype) {
case LATEX_COMMAND:
break;
case LATEX_ENVIRONMENT:
case LATEX_ITEM_ENVIRONMENT:
- if (style.latexparam() == "CDATA")
+ if (style->latexparam() == "CDATA")
ofs << "]]>";
break;
default:
- sgmlCloseTag(ofs, depth, style.latexname());
+ sgml::closeTag(ofs, depth, false, style->latexname());
break;
}
}
-
+
// Close open tags
- for (int i=depth; i >= 0; --i)
- sgmlCloseTag(ofs, depth, environment_stack[i]);
+ for (int i = depth; i >= 0; --i)
+ sgml::closeTag(ofs, depth, false, environment_stack[i]);
if (!body_only) {
ofs << "\n\n";
- sgmlCloseTag(ofs, 0, top_element);
+ sgml::closeTag(ofs, 0, false, top_element);
}
ofs.close();
// How to check for successful close
+
+ // we want this to be true outside previews (for insetexternal)
+ niceFile = true;
}
@@ -2823,7 +2430,7 @@ string tag_name(PAR_TAG const & pt) {
inline
void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
{
- p1 = static_cast(p1 | p2);
+ p1 = static_cast(p1 | p2);
}
@@ -2833,26 +2440,26 @@ void reset(PAR_TAG & p1, PAR_TAG const & p2)
p1 = static_cast(p1 & ~p2);
}
-} // namespace anon
+} // anon
// Handle internal paragraph parsing -- layout already processed.
void Buffer::simpleLinuxDocOnePar(ostream & os,
- Paragraph * par,
- Paragraph::depth_type /*depth*/)
+ Paragraph * par,
+ Paragraph::depth_type /*depth*/)
{
- LyXLayout const & style =
- textclasslist[params.textclass][par->layout()];
- string::size_type char_line_count = 5; // Heuristic choice ;-)
+ LyXLayout_ptr const & style = par->layout();
+
+ string::size_type char_line_count = 5; // Heuristic choice ;-)
// gets paragraph main font
LyXFont font_old;
bool desc_on;
- if (style.labeltype == LABEL_MANUAL) {
- font_old = style.labelfont;
+ if (style->labeltype == LABEL_MANUAL) {
+ font_old = style->labelfont;
desc_on = true;
} else {
- font_old = style.font;
+ font_old = style->font;
desc_on = false;
}
@@ -2986,16 +2593,16 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
continue;
}
- if (style.latexparam() == "CDATA") {
+ if (style->latexparam() == "CDATA") {
// "TeX"-Mode on == > SGML-Mode on.
if (c != '\0')
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...
@@ -3009,8 +2616,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;
@@ -3031,13 +2638,23 @@ void Buffer::simpleLinuxDocOnePar(ostream & os,
// Print an error message.
-void Buffer::sgmlError(Paragraph * par, int pos,
- string const & message) const
+void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
+ string const & /*message*/) const
{
+#ifdef WITH_WARNINGS
+#warning This is wrong we cannot insert an inset like this!!!
+ // I guess this was Jose' so I explain you more or less why this
+ // is wrong. This way you insert something in the paragraph and
+ // don't tell it to LyXText (row rebreaking and undo handling!!!)
+ // I deactivate this code, have a look at BufferView::insertErrors
+ // how you should do this correctly! (Jug 20020315)
+#endif
+#if 0
// insert an error marker in text
InsetError * new_inset = new InsetError(message);
- par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
- params.language));
+ par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
+ params.language));
+#endif
}
@@ -3049,26 +2666,26 @@ 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.
- LyXTextClass const & tclass =
- textclasslist[params.textclass];
-
- LaTeXFeatures features(params, tclass.size());
+ LaTeXFeatures features(params);
validate(features);
-
+
texrow.reset();
- string top_element = textclasslist[params.textclass].latexname();
+ LyXTextClass const & tclass = params.getLyXTextClass();
+ string top_element = tclass.latexname();
if (!only_body) {
ofs << "\n\n";
}
- string top = top_element;
+ string top = top_element;
top += " lang=\"";
top += params.language->code();
top += "\"";
@@ -3086,7 +2703,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
top += " ";
top += params.options;
}
- sgmlOpenTag(ofs, 0, top);
+ sgml::openTag(ofs, 0, false, top);
ofs << "\n";
@@ -3101,7 +2718,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
Paragraph::depth_type cmd_depth = 0;
Paragraph::depth_type depth = 0; // paragraph depth
- string item_name;
+ string item_name;
string command_name;
while (par) {
@@ -3110,50 +2727,42 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
string c_params;
int desc_on = 0; // description mode
- LyXLayout const & style =
- textclasslist[params.textclass][par->layout()];
+ LyXLayout_ptr const & style = par->layout();
// environment tag closing
for (; depth > par->params().depth(); --depth) {
if (environment_inner[depth] != "!-- --") {
item_name = "listitem";
- sgmlCloseTag(ofs, command_depth + depth,
- item_name);
+ sgml::closeTag(ofs, command_depth + depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs, depth+command_depth,
- environment_inner[depth]);
+ sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
}
- sgmlCloseTag(ofs, depth + command_depth,
- environment_stack[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
environment_stack[depth].erase();
environment_inner[depth].erase();
}
if (depth == par->params().depth()
- && environment_stack[depth] != style.latexname()
+ && environment_stack[depth] != style->latexname()
&& !environment_stack[depth].empty()) {
if (environment_inner[depth] != "!-- --") {
item_name= "listitem";
- sgmlCloseTag(ofs, command_depth+depth,
- item_name);
+ sgml::closeTag(ofs, command_depth+depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs,
- depth + command_depth,
- environment_inner[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
}
-
- sgmlCloseTag(ofs, depth + command_depth,
- environment_stack[depth]);
-
+
+ sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
+
environment_stack[depth].erase();
environment_inner[depth].erase();
- }
+ }
// Write opening SGML tags.
- switch (style.latextype) {
+ switch (style->latextype) {
case LATEX_PARAGRAPH:
- sgmlOpenTag(ofs, depth + command_depth,
- style.latexname());
+ sgml::openTag(ofs, depth + command_depth,
+ false, style->latexname());
break;
case LATEX_COMMAND:
@@ -3161,22 +2770,28 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
sgmlError(par, 0,
_("Error : Wrong depth for "
"LatexType Command.\n"));
-
- command_name = style.latexname();
-
- sgmlparam = style.latexparam();
+
+ command_name = style->latexname();
+
+ sgmlparam = style->latexparam();
c_params = split(sgmlparam, c_depth,'|');
-
+
cmd_depth = lyx::atoi(c_depth);
-
+
if (command_flag) {
if (cmd_depth < command_base) {
- for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
- sgmlCloseTag(ofs, j, command_stack[j]);
+ for (Paragraph::depth_type j = command_depth;
+ j >= command_base; --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, command_stack[j]);
+ for (int j = command_depth;
+ j >= int(cmd_depth); --j) {
+ sgml::closeTag(ofs, j, false, command_stack[j]);
+ ofs << endl;
+ }
command_depth = cmd_depth;
} else
command_depth = cmd_depth;
@@ -3193,7 +2808,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
// This is a hack while paragraphs can't have
// attributes, like id in this case.
if (par->isInset(0)) {
- Inset * inset = par->getInset(0);
+ Inset * inset = par->getInset(0);
Inset::Code lyx_code = inset->lyxCode();
if (lyx_code == Inset::LABEL_CODE) {
command_name += " id=\"";
@@ -3203,12 +2818,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
}
}
- sgmlOpenTag(ofs, depth + command_depth, command_name);
- if (c_params.empty())
- item_name = "title";
- else
- item_name = c_params;
- sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
+ sgml::openTag(ofs, depth + command_depth, false, command_name);
+
+ item_name = c_params.empty()?"title":c_params;
+ sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
break;
case LATEX_ENVIRONMENT:
@@ -3218,97 +2831,79 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
environment_stack[depth].erase();
}
- if (environment_stack[depth] != style.latexname()) {
+ if (environment_stack[depth] != style->latexname()) {
if (environment_stack.size() == depth + 1) {
environment_stack.push_back("!-- --");
environment_inner.push_back("!-- --");
}
- environment_stack[depth] = style.latexname();
+ environment_stack[depth] = style->latexname();
environment_inner[depth] = "!-- --";
- sgmlOpenTag(ofs, depth + command_depth,
- 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,
- item_name);
+ sgml::closeTag(ofs, command_depth + depth, false, item_name);
if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs,
- depth + command_depth,
- environment_inner[depth]);
+ sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
}
}
-
- if (style.latextype == LATEX_ENVIRONMENT) {
- if (!style.latexparam().empty()) {
- if (style.latexparam() == "CDATA")
+
+ if (style->latextype == LATEX_ENVIRONMENT) {
+ if (!style->latexparam().empty()) {
+ if (style->latexparam() == "CDATA")
ofs << "latexparam());
}
break;
}
- desc_on = (style.labeltype == LABEL_MANUAL);
-
- if (desc_on)
- environment_inner[depth]= "varlistentry";
- else
- environment_inner[depth]= "listitem";
+ desc_on = (style->labeltype == LABEL_MANUAL);
- sgmlOpenTag(ofs, depth + 1 + command_depth,
- environment_inner[depth]);
+ environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
+ sgml::openTag(ofs, depth + 1 + command_depth,
+ false, environment_inner[depth]);
- if (desc_on) {
- item_name= "term";
- sgmlOpenTag(ofs, depth + 1 + command_depth,
- item_name);
- } else {
- item_name= "para";
- sgmlOpenTag(ofs, depth + 1 + command_depth,
- item_name);
- }
+ item_name = desc_on ? "term" : "para";
+ sgml::openTag(ofs, depth + 1 + command_depth,
+ false, item_name);
break;
default:
- sgmlOpenTag(ofs, depth + command_depth,
- style.latexname());
+ sgml::openTag(ofs, depth + command_depth,
+ false, style->latexname());
break;
}
- simpleDocBookOnePar(ofs, par, desc_on, depth+1+command_depth);
+ simpleDocBookOnePar(ofs, par, desc_on,
+ depth + 1 + command_depth);
par = par->next();
string end_tag;
// write closing SGML tags
- switch (style.latextype) {
+ switch (style->latextype) {
case LATEX_COMMAND:
- if (c_params.empty())
- end_tag = "title";
- else
- end_tag = c_params;
- sgmlCloseTag(ofs, depth + command_depth, end_tag);
+ end_tag = c_params.empty() ? "title" : c_params;
+ sgml::closeTag(ofs, depth + command_depth,
+ false, end_tag);
break;
case LATEX_ENVIRONMENT:
- if (!style.latexparam().empty()) {
- if (style.latexparam() == "CDATA")
+ if (!style->latexparam().empty()) {
+ if (style->latexparam() == "CDATA")
ofs << "]]>";
else
- sgmlCloseTag(ofs, depth + command_depth,
- 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, end_tag);
+ sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
break;
case LATEX_PARAGRAPH:
- sgmlCloseTag(ofs, depth + command_depth, style.latexname());
+ sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
break;
default:
- sgmlCloseTag(ofs, depth + command_depth, style.latexname());
+ sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
break;
}
}
@@ -3318,27 +2913,29 @@ 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,
- item_name);
- if (environment_inner[depth] == "varlistentry")
- sgmlCloseTag(ofs, depth + command_depth,
- environment_inner[depth]);
+ sgml::closeTag(ofs, command_depth + depth, false, item_name);
+ if (environment_inner[depth] == "varlistentry")
+ sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
}
-
- sgmlCloseTag(ofs, depth + command_depth,
- 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, command_stack[j]);
+ if (!command_stack[j].empty()) {
+ sgml::closeTag(ofs, j, false, command_stack[j]);
+ ofs << endl;
+ }
ofs << "\n\n";
- sgmlCloseTag(ofs, 0, top_element);
+ sgml::closeTag(ofs, 0, false, top_element);
ofs.close();
// How to check for successful close
+
+ // we want this to be true outside previews (for insetexternal)
+ niceFile = true;
}
@@ -3348,10 +2945,9 @@ void Buffer::simpleDocBookOnePar(ostream & os,
{
bool emph_flag = false;
- LyXLayout const & style =
- textclasslist[params.textclass][par->layout()];
+ LyXLayout_ptr const & style = par->layout();
- LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
+ LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
int char_line_count = depth;
//if (!style.free_spacing)
@@ -3364,34 +2960,43 @@ void Buffer::simpleDocBookOnePar(ostream & os,
// handle tag
if (font_old.emph() != font.emph()) {
if (font.emph() == LyXFont::ON) {
+ if (style->latexparam() == "CDATA")
+ os << "]]>";
os << "";
+ if (style->latexparam() == "CDATA")
+ os << "latexparam() == "CDATA")
+ os << "]]>";
os << "";
+ if (style->latexparam() == "CDATA")
+ os << "isInset(i)) {
Inset * inset = par->getInset(i);
// don't print the inset in position 0 if desc_on == 3 (label)
- if ( i || desc_on != 3) {
- if(style.latexparam() == "CDATA")
+ if (i || desc_on != 3) {
+ if (style->latexparam() == "CDATA")
os << "]]>";
- inset->docbook(this, os);
- if(style.latexparam() == "CDATA")
+ inset->docbook(this, os, false);
+ if (style->latexparam() == "CDATA")
os << "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) {
+ if (style->pass_thru) {
os << c;
- } else if (style.free_spacing || par->isFreeSpacing() || c != ' ') {
- os << sgml_string;
+ } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
+ os << str;
} else if (desc_on ==1) {
++char_line_count;
os << "\n";
@@ -3404,19 +3009,23 @@ void Buffer::simpleDocBookOnePar(ostream & os,
}
if (emph_flag) {
+ if (style->latexparam() == "CDATA")
+ os << "]]>";
os << "";
+ if (style->latexparam() == "CDATA")
+ os << " not closed...
- os << "";
+ os << "\n ";
}
- if (style.free_spacing) os << '\n';
+ if (style->free_spacing)
+ os << '\n';
}
-// This should be enabled when the Chktex class is implemented. (Asger)
// chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
// Other flags: -wall -v0 -x
int Buffer::runChktex()
@@ -3431,7 +3040,7 @@ int Buffer::runChktex()
string const org_path = path;
if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
- path = tmppath;
+ path = tmppath;
}
Path p(path); // path to LaTeX file
@@ -3458,7 +3067,8 @@ int Buffer::runChktex()
// if we removed error insets before we ran chktex or if we inserted
// error insets after we ran chktex, this must be run:
if (removedErrorInsets || res) {
- users->redraw();
+#warning repaint needed here, or do you mean update() ?
+ users->repaint();
users->fitCursor();
}
users->owner()->allowInput();
@@ -3469,25 +3079,14 @@ int Buffer::runChktex()
void Buffer::validate(LaTeXFeatures & features) const
{
- Paragraph * par = paragraph;
- LyXTextClass const & tclass = textclasslist[params.textclass];
-
- // 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;
+ LyXTextClass const & tclass = params.getLyXTextClass();
- // Now just follow the list of paragraphs and run
- // validate on each of them.
- par->validate(features);
+ // AMS Style is at document level
+ if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
+ features.require("amsmath");
- // 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
@@ -3512,154 +3111,78 @@ void Buffer::validate(LaTeXFeatures & features) const
}
}
}
-
+
if (lyxerr.debugging(Debug::LATEX)) {
features.showStruct();
}
}
-// 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()
+vector 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 label_list;
- for (inset_iterator it = inset_iterator_begin();
- it != inset_iterator_end(); ++it) {
- vector const l = (*it)->getLabelList();
+ for (inset_iterator it = inset_const_iterator_begin();
+ it != inset_const_iterator_end(); ++it) {
+ vector const l = it->getLabelList();
label_list.insert(label_list.end(), l.begin(), l.end());
}
return label_list;
}
-Buffer::Lists const Buffer::getLists() const
-{
- Lists l;
- Paragraph * par = paragraph;
-
- LyXTextClass const & textclass = textclasslist[params.textclass];
- bool found = textclass.hasLayout("caption");
- string const layout("caption");
-
- while (par) {
- char const labeltype = textclass[par->layout()].labeltype;
-
- if (labeltype >= LABEL_COUNTER_CHAPTER
- && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
- // insert this into the table of contents
- SingleList & item = l["TOC"];
- int depth = max(0,
- labeltype -
- textclass.maxcounter());
- item.push_back(TocItem(par, depth, par->asString(this, true)));
- }
- // For each paragrph, traverse its insets and look for
- // FLOAT_CODE
-
- if (found) {
- Paragraph::inset_iterator it =
- par->inset_iterator_begin();
- Paragraph::inset_iterator end =
- par->inset_iterator_end();
-
- for (; it != end; ++it) {
- if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
- InsetFloat * il =
- static_cast(*it);
-
- string const type = il->type();
-
- // Now find the caption in the float...
- // We now tranverse the paragraphs of
- // the inset...
- Paragraph * tmp = il->inset.paragraph();
- while (tmp) {
- if (tmp->layout() == layout) {
- SingleList & item = l[type];
- string const str =
- tostr(item.size()+1) + ". " + tmp->asString(this, false);
- item.push_back(TocItem(tmp, 0 , str));
- }
- tmp = tmp->next();
- }
- }
- }
- } else {
- lyxerr << "caption not found" << endl;
- }
-
- par = par->next();
- }
- return l;
-}
-
-
// This is also a buffer property (ale)
-vector > const Buffer::getBibkeyList()
+vector > const Buffer::getBibkeyList() const
{
+ typedef pair StringPair;
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990412]
- if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
- Buffer * tmp = bufferlist.getBuffer(params.parentname);
+ if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
+ Buffer const * tmp = bufferlist.getBuffer(params.parentname);
if (tmp)
return tmp->getBibkeyList();
}
- vector > keys;
- Paragraph * par = paragraph;
- while (par) {
- if (par->bibkey)
- keys.push_back(pair(par->bibkey->getContents(),
- par->asString(this, false)));
- par = par->next();
+ vector 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 (!keys.empty())
+ return keys;
+
// Might be either using bibtex or a child has bibliography
- if (keys.empty()) {
- for (inset_iterator it = inset_iterator_begin();
- it != inset_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());
}
}
-
+
return keys;
}
@@ -3697,24 +3220,28 @@ void Buffer::markDepClean(string const & name)
}
-bool Buffer::dispatch(string const & command)
+bool Buffer::dispatch(string const & command, bool * result)
{
// Split command string into command and argument
string cmd;
- string line = frontStrip(command);
- string const arg = strip(frontStrip(split(line, cmd, ' ')));
+ string line = ltrim(command);
+ string const arg = trim(split(line, cmd, ' '));
- return dispatch(lyxaction.LookupFunc(cmd), arg);
+ return dispatch(lyxaction.LookupFunc(cmd), arg, result);
}
-bool Buffer::dispatch(int action, string const & argument)
+bool Buffer::dispatch(int action, string const & argument, bool * result)
{
bool dispatched = true;
+
switch (action) {
- case LFUN_EXPORT:
- Exporter::Export(this, argument, false);
+ case LFUN_EXPORT: {
+ bool const tmp = Exporter::Export(this, argument, false);
+ if (result)
+ *result = tmp;
break;
+ }
default:
dispatched = false;
@@ -3726,17 +3253,16 @@ bool Buffer::dispatch(int action, string const & argument)
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));
}
void Buffer::redraw()
{
- users->redraw();
- users->fitCursor();
+#warning repaint needed here, or do you mean update() ?
+ users->repaint();
+ users->fitCursor();
}
@@ -3760,27 +3286,14 @@ bool Buffer::isMultiLingual()
}
-Buffer::inset_iterator::inset_iterator(Paragraph * paragraph, pos_type pos)
- : par(paragraph)
-{
- it = par->InsetIterator(pos);
- if (it == par->inset_iterator_end()) {
- par = par->next();
- setParagraph();
- }
-}
-
-
void Buffer::inset_iterator::setParagraph()
{
- while (par) {
- it = par->inset_iterator_begin();
- if (it != par->inset_iterator_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
}
@@ -3789,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;
}
@@ -3801,17 +3314,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;
}
@@ -3819,11 +3334,200 @@ Paragraph * Buffer::getParFromID(int id) const
ParIterator Buffer::par_iterator_begin()
{
- return ParIterator(paragraph);
+ return ParIterator(&*(paragraphs.begin()));
}
ParIterator Buffer::par_iterator_end()
{
- return ParIterator();
+ 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);
}