#include "buffer_funcs.h"
#include "bufferlist.h"
#include "bufferparams.h"
+#include "counters.h"
#include "Bullet.h"
#include "Chktex.h"
#include "debug.h"
#include "LaTeXFeatures.h"
#include "LyXAction.h"
#include "lyxlex.h"
+#include "lyxtext.h"
#include "lyxrc.h"
#include "lyxvc.h"
#include "messages.h"
+#include "output.h"
+#include "output_docbook.h"
+#include "output_latex.h"
+#include "output_linuxdoc.h"
#include "paragraph.h"
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
+#include "PosIterator.h"
#include "sgml.h"
#include "texrow.h"
#include "undo.h"
namespace {
-const int LYX_FORMAT = 225;
-
-bool openFileWrite(ofstream & ofs, string const & fname)
-{
- ofs.open(fname.c_str());
- if (!ofs) {
- string const file = MakeDisplayPath(fname, 50);
- string text = bformat(_("Could not open the specified "
- "document\n%1$s."), file);
- Alert::error(_("Could not open file"), text);
- return false;
- }
- return true;
-}
+const int LYX_FORMAT = 229;
} // namespace anon
limited_stack<Undo> undostack;
limited_stack<Undo> redostack;
BufferParams params;
- ParagraphList paragraphs;
LyXVC lyxvc;
string temppath;
- bool nicefile;
TexRow texrow;
/// need to regenerate .tex ?
* and by the citation inset.
*/
bool file_fully_loaded;
+
+ /// our Text
+ LyXText text;
};
Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_)
- : nicefile(true),
- lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
- filename(file), filepath(OnlyPath(file)), file_fully_loaded(false)
+ : lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_),
+ filename(file), filepath(OnlyPath(file)), file_fully_loaded(false),
+ text(0, 0)
{
lyxvc.buffer(&parent);
if (readonly_ || lyxrc.use_tempdir)
bformat(_("Could not remove the temporary directory %1$s"), temppath()));
}
- paragraphs().clear();
-
// Remove any previewed LaTeX snippets associated with this buffer.
lyx::graphics::Previews::get().removeLoader(*this);
}
+LyXText & Buffer::text() const
+{
+ return const_cast<LyXText &>(pimpl_->text);
+}
+
+
limited_stack<Undo> & Buffer::undostack()
{
return pimpl_->undostack;
ParagraphList & Buffer::paragraphs()
{
- return pimpl_->paragraphs;
+ return pimpl_->text.paragraphs();
}
ParagraphList const & Buffer::paragraphs() const
{
- return pimpl_->paragraphs;
+ return pimpl_->text.paragraphs();
}
}
-bool & Buffer::niceFile()
-{
- return pimpl_->nicefile;
-}
-
-
-bool Buffer::niceFile() const
-{
- return pimpl_->nicefile;
-}
-
-
TexRow & Buffer::texrow()
{
return pimpl_->texrow;
} // anon
+
int Buffer::readHeader(LyXLex & lex)
{
int unknown_tokens = 0;
// if par = 0 normal behavior
// else insert behavior
// Returns false if "\end_document" is not read (Asger)
-bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
+bool Buffer::readBody(LyXLex & lex)
{
- Paragraph::depth_type depth = 0;
bool the_end_read = false;
if (paragraphs().empty()) {
tmpbuf.readHeader(lex);
}
- while (lex.isOK()) {
- lex.nextToken();
- string const token = lex.getString();
-
- if (token.empty())
- continue;
-
- lyxerr[Debug::PARSER] << "Handling token: `"
- << token << '\'' << endl;
-
- if (token == "\\end_document") {
- the_end_read = true;
- continue;
- }
-
- readParagraph(lex, token, paragraphs(), pit, depth);
- }
+ if (text().read(*this, lex))
+ the_end_read = true;
return the_end_read;
}
-int Buffer::readParagraph(LyXLex & lex, string const & token,
- ParagraphList & pars, ParagraphList::iterator & pit,
- lyx::depth_type & depth)
-{
- static Change current_change;
- int unknown = 0;
-
- if (token == "\\begin_layout") {
- lex.pushToken(token);
-
- Paragraph par;
- par.params().depth(depth);
- if (params().tracking_changes)
- par.trackChanges();
- LyXFont f(LyXFont::ALL_INHERIT, params().language);
- par.setFont(0, f);
-
- // insert after
- if (pit != pars.end())
- ++pit;
-
- pit = pars.insert(pit, par);
-
- // FIXME: goddamn InsetTabular makes us pass a Buffer
- // not BufferParams
- ::readParagraph(*this, *pit, lex);
-
- } else if (token == "\\begin_deeper") {
- ++depth;
- } else if (token == "\\end_deeper") {
- if (!depth) {
- lex.printError("\\end_deeper: " "depth is already null");
- } else {
- --depth;
- }
- } else {
- ++unknown;
- }
- return unknown;
-}
-
-
// needed to insert the selection
void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
- LyXFont const & fn,string const & str)
+ LyXFont const & fn, string const & str)
{
LyXLayout_ptr const & layout = par->layout();
}
- bool the_end = readBody(lex, pit);
+ bool the_end = readBody(lex);
params().setPaperStuff();
if (!the_end) {
<< " created this file. For more info see http://www.lyx.org/\n"
<< "\\lyxformat " << LYX_FORMAT << "\n";
- // now write out the buffer paramters.
+ // now write out the buffer parameters.
params().writeFile(ofs);
ofs << "\\end_header\n";
- Paragraph::depth_type depth = 0;
-
- // this will write out all the paragraphs
- // using recursive descent.
- ParagraphList::const_iterator pit = paragraphs().begin();
- ParagraphList::const_iterator pend = paragraphs().end();
- for (; pit != pend; ++pit)
- pit->write(*this, ofs, params(), depth);
+ // write the text
+ text().write(*this, ofs);
// Write marker that shows file is complete
ofs << "\n\\end_document" << endl;
}
-void Buffer::writeFileAscii(string const & fname, LatexRunParams const & runparams)
-{
- ofstream ofs;
- if (!::openFileWrite(ofs, fname))
- return;
- writeFileAscii(ofs, runparams);
-}
-
-
-void Buffer::writeFileAscii(ostream & os, LatexRunParams const & runparams)
-{
- ParagraphList::iterator beg = paragraphs().begin();
- ParagraphList::iterator end = paragraphs().end();
- ParagraphList::iterator it = beg;
- for (; it != end; ++it) {
- asciiParagraph(*this, *it, os, runparams, it == beg);
- }
- os << "\n";
-}
-
-
void Buffer::makeLaTeXFile(string const & fname,
string const & original_path,
- LatexRunParams const & runparams,
+ OutputParams const & runparams,
bool output_preamble, bool output_body)
{
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
ofstream ofs;
- if (!::openFileWrite(ofs, fname))
+ if (!openFileWrite(ofs, fname))
return;
makeLaTeXFile(ofs, original_path,
void Buffer::makeLaTeXFile(ostream & os,
string const & original_path,
- LatexRunParams const & runparams_in,
+ OutputParams const & runparams_in,
bool output_preamble, bool output_body)
{
- LatexRunParams runparams = runparams_in;
- niceFile() = runparams.nice; // this will be used by Insetincludes.
+ OutputParams runparams = runparams_in;
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
- LaTeXFeatures features(*this, params());
+ LaTeXFeatures features(*this, params(), runparams.nice);
validate(features);
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
lyxerr[Debug::INFO] << "Row count was " << texrow().rows() - 1
<< '.' << endl;
-
- // we want this to be true outside previews (for insetexternal)
- niceFile() = true;
}
void Buffer::makeLinuxDocFile(string const & fname,
- LatexRunParams const & runparams,
+ OutputParams const & runparams,
bool body_only )
{
ofstream ofs;
- if (!::openFileWrite(ofs, fname))
+ if (!openFileWrite(ofs, fname))
return;
- niceFile() = runparams.nice; // this will be used by included files.
-
- LaTeXFeatures features(*this, params());
-
+ LaTeXFeatures features(*this, params(), runparams.nice);
validate(features);
texrow().reset();
string top_element = tclass.latexname();
if (!body_only) {
- ofs << "<!doctype linuxdoc system";
+ ofs << tclass.class_header();
string preamble = params().preamble;
string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
ofs.close();
// How to check for successful close
-
- // we want this to be true outside previews (for insetexternal)
- niceFile() = true;
}
void Buffer::makeDocBookFile(string const & fname,
- LatexRunParams const & runparams,
+ OutputParams const & runparams,
bool only_body)
{
ofstream ofs;
- if (!::openFileWrite(ofs, fname))
+ if (!openFileWrite(ofs, fname))
return;
- niceFile() = runparams.nice; // this will be used by Insetincludes.
-
- LaTeXFeatures features(*this, params());
+ LaTeXFeatures features(*this, params(), runparams.nice);
validate(features);
texrow().reset();
string top_element = tclass.latexname();
if (!only_body) {
- ofs << "<!DOCTYPE " << top_element
- << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
+ ofs << subst(tclass.class_header(), "#", top_element);
string preamble = params().preamble;
string const name = runparams.nice ? ChangeExtension(pimpl_->filename, ".sgml")
}
sgml::openTag(ofs, 0, false, top);
- ofs << "<!-- DocBook file was created by LyX " << lyx_version
+ ofs << "<!-- SGML/XML file was created by LyX " << lyx_version
<< "\n See http://www.lyx.org/ for more information -->\n";
+ params().getLyXTextClass().counters().reset();
docbookParagraphs(*this, paragraphs(), ofs, runparams);
ofs << "\n\n";
ofs.close();
// How to check for successful close
-
- // we want this to be true outside previews (for insetexternal)
- niceFile() = true;
}
message(_("Running chktex..."));
// Generate the LaTeX file if neccessary
- LatexRunParams runparams;
- runparams.flavor = LatexRunParams::LATEX;
+ OutputParams runparams;
+ runparams.flavor = OutputParams::LATEX;
runparams.nice = false;
makeLaTeXFile(name, org_path, runparams);
// This is also a buffer property (ale)
-void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
+void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys)
+ const
{
/// if this is a child document and the parent is already loaded
/// use the parent's list instead [ale990412]
}
-InsetOld * 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);
- InsetOld * in = it->getInsetFromID(id_arg);
- if (in)
- return in;
- }
- return 0;
-}
-
-
ParIterator Buffer::getParFromID(int id) const
{
#warning FIXME: const correctness! (Andre)
}
+PosIterator Buffer::pos_iterator_begin()
+{
+ return PosIterator(¶graphs(), paragraphs().begin(), 0);
+}
+
+
+PosIterator Buffer::pos_iterator_end()
+{
+ return PosIterator(¶graphs(), paragraphs().end(), 0);
+}
+
+
ParIterator Buffer::par_iterator_begin()
{
return ParIterator(paragraphs().begin(), paragraphs());