3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
14 #include "buffer_funcs.h"
15 #include "bufferlist.h"
16 #include "LyXAction.h"
19 #include "tex-strings.h"
21 #include "bufferview_funcs.h"
27 #include "LaTeXFeatures.h"
32 #include "errorlist.h"
35 #include "ParagraphParameters.h"
36 #include "iterators.h"
37 #include "lyxtextclasslist.h"
39 #include "paragraph_funcs.h"
43 #include "frontends/LyXView.h"
45 #include "mathed/formulamacro.h"
46 #include "mathed/formula.h"
48 #include "insets/insetbibitem.h"
49 #include "insets/insetbibtex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insettext.h"
53 #include "frontends/Dialogs.h"
54 #include "frontends/Alert.h"
56 #include "graphics/Previews.h"
58 #include "support/textutils.h"
59 #include "support/filetools.h"
60 #include "support/path.h"
61 #include "support/os.h"
62 #include "support/tostr.h"
63 #include "support/lyxlib.h"
64 #include "support/FileInfo.h"
65 #include "support/lyxmanip.h"
66 #include "support/lyxtime.h"
68 #include <boost/bind.hpp>
69 #include <boost/tuple/tuple.hpp>
81 #include <sys/types.h>
88 using namespace lyx::support;
90 #ifndef CXX_GLOBAL_CSTD
102 using std::make_pair;
110 using lyx::textclass_type;
112 namespace grfx = lyx::graphics;
114 // all these externs should eventually be removed.
115 extern BufferList bufferlist;
119 const int LYX_FORMAT = 224;
123 Buffer::Buffer(string const & file, bool ronly)
124 : niceFile(true), lyx_clean(true), bak_clean(true),
125 unnamed(false), read_only(ronly),
128 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
129 filepath_ = OnlyPath(file);
131 if (read_only || lyxrc.use_tempdir) {
132 tmppath = CreateBufferTmpDir();
137 // set initial author
138 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
144 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
145 // here the buffer should take care that it is
146 // saved properly, before it goes into the void.
150 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
151 Alert::warning(_("Could not remove temporary directory"),
152 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
157 // Remove any previewed LaTeX snippets assocoated with this buffer.
158 grfx::Previews::get().removeLoader(this);
162 string const Buffer::getLatexName(bool no_path) const
164 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
165 return no_path ? OnlyFilename(name) : name;
169 pair<Buffer::LogType, string> const Buffer::getLogName() const
171 string const filename = getLatexName(false);
173 if (filename.empty())
174 return make_pair(Buffer::latexlog, string());
176 string path = OnlyPath(filename);
178 if (lyxrc.use_tempdir || !IsDirWriteable(path))
181 string const fname = AddName(path,
182 OnlyFilename(ChangeExtension(filename,
185 AddName(path, OnlyFilename(
186 ChangeExtension(filename,
187 formats.extension("literate") + ".out")));
189 // If no Latex log or Build log is newer, show Build log
191 FileInfo const f_fi(fname);
192 FileInfo const b_fi(bname);
195 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
196 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
197 return make_pair(Buffer::buildlog, bname);
199 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
200 return make_pair(Buffer::latexlog, fname);
204 void Buffer::setReadonly(bool flag)
206 if (read_only != flag) {
213 AuthorList & Buffer::authors()
215 return params.authorlist;
219 void Buffer::setFileName(string const & newfile)
221 filename_ = MakeAbsPath(newfile);
222 filepath_ = OnlyPath(filename_);
223 setReadonly(IsFileWriteable(filename_) == 0);
228 // We'll remove this later. (Lgb)
231 void unknownClass(string const & unknown)
233 Alert::warning(_("Unknown document class"),
234 bformat(_("Using the default document class, because the "
235 " class %1$s is unknown."), unknown));
240 int Buffer::readHeader(LyXLex & lex)
242 int unknown_tokens = 0;
246 string const token = lex.getString();
251 if (token == "\\end_header")
254 lyxerr[Debug::PARSER] << "Handling header token: `"
255 << token << '\'' << endl;
258 string unknown = params.readToken(lex, token);
259 if (!unknown.empty()) {
260 if (unknown[0] != '\\') {
261 unknownClass(unknown);
264 string const s = bformat(_("Unknown token: "
268 error(ErrorItem(_("Header error"), s,
273 return unknown_tokens;
277 // candidate for move to BufferView
278 // (at least some parts in the beginning of the func)
281 // changed to be public and have one parameter
282 // if par = 0 normal behavior
283 // else insert behavior
284 // Returns false if "\the_end" is not read (Asger)
285 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
287 Paragraph::depth_type depth = 0;
288 bool the_end_read = false;
290 if (paragraphs.empty()) {
292 if (!params.getLyXTextClass().load()) {
293 string theclass = params.getLyXTextClass().name();
294 Alert::error(_("Can't load document class"), bformat(
295 "Using the default document class, because the "
296 " class %1$s could not be loaded.", theclass));
297 params.textclass = 0;
300 // We don't want to adopt the parameters from the
301 // document we insert, so read them into a temporary buffer
302 // and then discard it
304 Buffer tmpbuf("", false);
305 tmpbuf.readHeader(lex);
310 string const token = lex.getString();
315 lyxerr[Debug::PARSER] << "Handling token: `"
316 << token << '\'' << endl;
318 if (token == "\\the_end") {
323 readParagraph(lex, token, paragraphs, pit, depth);
330 int Buffer::readParagraph(LyXLex & lex, string const & token,
331 ParagraphList & pars, ParagraphList::iterator & pit,
332 Paragraph::depth_type & depth)
334 static Change current_change;
337 if (token == "\\layout") {
338 lex.pushToken(token);
341 par.params().depth(depth);
342 if (params.tracking_changes)
344 LyXFont f(LyXFont::ALL_INHERIT, params.language);
348 if (pit != pars.end())
351 pit = pars.insert(pit, par);
353 // FIXME: goddamn InsetTabular makes us pass a Buffer
355 ::readParagraph(*this, *pit, lex);
357 } else if (token == "\\begin_deeper") {
359 } else if (token == "\\end_deeper") {
361 lex.printError("\\end_deeper: " "depth is already null");
372 // needed to insert the selection
373 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
374 LyXFont const & fn,string const & str)
376 LyXLayout_ptr const & layout = par->layout();
380 par->checkInsertChar(font);
381 // insert the string, don't insert doublespace
382 bool space_inserted = true;
383 bool autobreakrows = !par->inInset() ||
384 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
385 for(string::const_iterator cit = str.begin();
386 cit != str.end(); ++cit) {
388 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
389 breakParagraph(params, paragraphs, par, pos,
390 layout->isEnvironment());
393 space_inserted = true;
397 // do not insert consecutive spaces if !free_spacing
398 } else if ((*cit == ' ' || *cit == '\t') &&
399 space_inserted && !par->isFreeSpacing()) {
401 } else if (*cit == '\t') {
402 if (!par->isFreeSpacing()) {
403 // tabs are like spaces here
404 par->insertChar(pos, ' ', font);
406 space_inserted = true;
408 const pos_type nb = 8 - pos % 8;
409 for (pos_type a = 0; a < nb ; ++a) {
410 par->insertChar(pos, ' ', font);
413 space_inserted = true;
415 } else if (!IsPrintable(*cit)) {
416 // Ignore unprintables
419 // just insert the character
420 par->insertChar(pos, *cit, font);
422 space_inserted = (*cit == ' ');
429 bool Buffer::readFile(LyXLex & lex, string const & filename)
431 bool ret = readFile(lex, filename, paragraphs.begin());
433 // After we have read a file, we must ensure that the buffer
434 // language is set and used in the gui.
435 // If you know of a better place to put this, please tell me. (Lgb)
436 updateDocLang(params.language);
442 // FIXME: all the below Alerts should give the filename..
443 bool Buffer::readFile(LyXLex & lex, string const & filename,
444 ParagraphList::iterator pit)
447 Alert::error(_("Document could not be read"),
448 _("The specified document could not be read."));
453 string const token(lex.getString());
456 Alert::error(_("Document could not be read"),
457 _("The specified document could not be read."));
461 // the first token _must_ be...
462 if (token != "\\lyxformat") {
463 Alert::error(_("Document format failure"),
464 _("The specified document is not a LyX document."));
469 string tmp_format = lex.getString();
470 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
471 // if present remove ".," from string.
472 string::size_type dot = tmp_format.find_first_of(".,");
473 //lyxerr << " dot found at " << dot << endl;
474 if (dot != string::npos)
475 tmp_format.erase(dot, 1);
476 file_format = strToInt(tmp_format);
477 //lyxerr << "format: " << file_format << endl;
478 if (file_format == LYX_FORMAT) {
480 } else if (file_format > LYX_FORMAT) {
481 Alert::warning(_("Document format failure"),
482 _("This document was created with a newer version of "
483 "LyX. This is likely to cause problems."));
484 } else if (file_format < LYX_FORMAT) {
486 if (file_format < 200) {
487 Alert::error(_("Document format failure"),
488 _("This LyX document is too old to be read "
489 "by this version of LyX. Try LyX 0.10."));
491 } else if (!filename.empty()) {
493 LibFileSearch("lyx2lyx", "lyx2lyx");
494 if (command.empty()) {
495 Alert::error(_("Conversion script not found"),
496 _("The document is from an earlier version "
497 "of LyX, but the conversion script lyx2lyx "
498 "could not be found."));
502 +tostr(LYX_FORMAT) + ' '
503 + QuoteName(filename);
504 lyxerr[Debug::INFO] << "Running '"
507 cmd_ret const ret = RunCommand(command);
509 Alert::error(_("Conversion script failed"),
510 _("The document is from an earlier version "
511 "of LyX, but the lyx2lyx script failed "
515 istringstream is(STRCONV(ret.second));
517 tmplex.setStream(is);
518 return readFile(tmplex, string(), pit);
520 // This code is reached if lyx2lyx failed (for
521 // some reason) to change the file format of
527 bool the_end = readBody(lex, pit);
528 params.setPaperStuff();
531 Alert::error(_("Document format failure"),
532 _("The document ended unexpectedly, which means "
533 "that it is probably corrupted."));
539 // Should probably be moved to somewhere else: BufferView? LyXView?
540 bool Buffer::save() const
542 // We don't need autosaves in the immediate future. (Asger)
543 resetAutosaveTimers();
547 if (lyxrc.make_backup) {
548 s = fileName() + '~';
549 if (!lyxrc.backupdir_path.empty())
550 s = AddName(lyxrc.backupdir_path,
551 subst(os::slashify_path(s),'/','!'));
553 // Rename is the wrong way of making a backup,
554 // this is the correct way.
555 /* truss cp fil fil2:
556 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
557 stat("LyXVC.lyx", 0xEFFFF688) = 0
558 open("LyXVC.lyx", O_RDONLY) = 3
559 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
560 fstat(4, 0xEFFFF508) = 0
561 fstat(3, 0xEFFFF508) = 0
562 read(3, " # T h i s f i l e w".., 8192) = 5579
563 write(4, " # T h i s f i l e w".., 5579) = 5579
564 read(3, 0xEFFFD4A0, 8192) = 0
567 chmod("LyXVC3.lyx", 0100644) = 0
568 lseek(0, 0, SEEK_CUR) = 46440
572 // Should probably have some more error checking here.
573 // Doing it this way, also makes the inodes stay the same.
574 // This is still not a very good solution, in particular we
575 // might loose the owner of the backup.
576 FileInfo finfo(fileName());
578 mode_t fmode = finfo.getMode();
579 struct utimbuf times = {
580 finfo.getAccessTime(),
581 finfo.getModificationTime() };
583 ifstream ifs(fileName().c_str());
584 ofstream ofs(s.c_str(), ios::out|ios::trunc);
589 ::chmod(s.c_str(), fmode);
591 if (::utime(s.c_str(), ×)) {
592 lyxerr << "utime error." << endl;
595 lyxerr << "LyX was not able to make "
596 "backup copy. Beware." << endl;
601 if (writeFile(fileName())) {
603 removeAutosaveFile(fileName());
605 // Saving failed, so backup is not backup
606 if (lyxrc.make_backup) {
607 rename(s, fileName());
615 bool Buffer::writeFile(string const & fname) const
617 if (read_only && (fname == fileName())) {
621 FileInfo finfo(fname);
622 if (finfo.exist() && !finfo.writable()) {
626 ofstream ofs(fname.c_str());
632 // Use the standard "C" locale for file output.
633 ofs.imbue(std::locale::classic());
636 // The top of the file should not be written by params.
638 // write out a comment in the top of the file
639 ofs << '#' << lyx_docversion
640 << " created this file. For more info see http://www.lyx.org/\n"
641 << "\\lyxformat " << LYX_FORMAT << "\n";
643 // now write out the buffer paramters.
644 params.writeFile(ofs);
646 ofs << "\\end_header\n";
648 Paragraph::depth_type depth = 0;
650 // this will write out all the paragraphs
651 // using recursive descent.
652 ParagraphList::const_iterator pit = paragraphs.begin();
653 ParagraphList::const_iterator pend = paragraphs.end();
654 for (; pit != pend; ++pit)
655 pit->write(this, ofs, params, depth);
657 // Write marker that shows file is complete
658 ofs << "\n\\the_end" << endl;
662 // how to check if close went ok?
663 // Following is an attempt... (BE 20001011)
665 // good() returns false if any error occured, including some
667 // bad() returns true if something bad happened in the buffer,
668 // which should include file system full errors.
675 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
677 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
689 pair<int, string> const addDepth(int depth, int ldepth)
693 d += (ldepth - depth) * 2;
694 return make_pair(d, string(d, ' '));
700 string const Buffer::asciiParagraph(Paragraph const & par,
701 unsigned int linelen,
702 bool noparbreak) const
704 ostringstream buffer;
706 Paragraph::depth_type ltype_depth = 0;
707 bool ref_printed = false;
708 Paragraph::depth_type depth = par.params().depth();
710 // First write the layout
711 string const & tmp = par.layout()->name();
712 if (compare_no_case(tmp, "itemize") == 0) {
714 ltype_depth = depth + 1;
715 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
717 ltype_depth = depth + 1;
718 } else if (contains(ascii_lowercase(tmp), "ection")) {
720 ltype_depth = depth + 1;
721 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
723 ltype_depth = depth + 1;
724 } else if (compare_ascii_no_case(tmp, "description") == 0) {
726 ltype_depth = depth + 1;
727 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
730 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
738 /* maybe some vertical spaces */
740 /* the labelwidthstring used in lists */
744 /* some pagebreaks? */
748 /* what about the alignment */
750 // linelen <= 0 is special and means we don't have paragraph breaks
752 string::size_type currlinelen = 0;
758 buffer << string(depth * 2, ' ');
759 currlinelen += depth * 2;
762 // we should probably change to the paragraph language in the
763 // gettext here (if possible) so that strings are outputted in
764 // the correct language! (20012712 Jug)
768 case 4: // (Sub)Paragraph
769 case 5: // Description
773 buffer << _("Abstract") << "\n\n";
776 string const abst = _("Abstract: ");
778 currlinelen += abst.length();
781 case 7: // Bibliography
784 buffer << _("References") << "\n\n";
787 string const refs = _("References: ");
789 currlinelen += refs.length();
797 string const parlab = par.params().labelString();
798 buffer << parlab << ' ';
799 currlinelen += parlab.length() + 1;
807 pair<int, string> p = addDepth(depth, ltype_depth);
809 currlinelen += p.first;
812 // this is to change the linebreak to do it by word a bit more
813 // intelligent hopefully! (only in the case where we have a
814 // max linelength!) (Jug)
818 for (pos_type i = 0; i < par.size(); ++i) {
819 char c = par.getUChar(params, i);
821 case Paragraph::META_INSET:
823 Inset const * inset = par.getInset(i);
827 currlinelen += word.length();
830 if (inset->ascii(this, buffer, linelen)) {
831 // to be sure it breaks paragraph
832 currlinelen += linelen;
841 currlinelen + word.length() > linelen - 10) {
843 pair<int, string> p = addDepth(depth, ltype_depth);
845 currlinelen = p.first;
848 buffer << word << ' ';
849 currlinelen += word.length() + 1;
856 lyxerr[Debug::INFO] <<
857 "writeAsciiFile: NULL char in structure." << endl;
860 (currlinelen + word.length()) > linelen)
864 pair<int, string> p =
865 addDepth(depth, ltype_depth);
867 currlinelen = p.first;
874 return STRCONV(buffer.str());
878 void Buffer::writeFileAscii(string const & fname, int linelen)
880 ofstream ofs(fname.c_str());
882 string const file = MakeDisplayPath(fname, 50);
883 string text = bformat(_("Could not save the document\n%1$s."), file);
884 Alert::error(_("Could not save document"), text);
887 writeFileAscii(ofs, linelen);
891 void Buffer::writeFileAscii(ostream & os, int linelen)
893 ParagraphList::iterator beg = paragraphs.begin();
894 ParagraphList::iterator end = paragraphs.end();
895 ParagraphList::iterator it = beg;
896 for (; it != end; ++it) {
897 os << asciiParagraph(*it, linelen, it == beg);
904 void Buffer::makeLaTeXFile(string const & fname,
905 string const & original_path,
906 LatexRunParams const & runparams,
907 bool only_body, bool only_preamble)
909 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
911 ofstream ofs(fname.c_str());
913 string const file = MakeDisplayPath(fname, 50);
914 string text = bformat(_("Could not open the specified document\n%1$s."),
916 Alert::error(_("Could not open file"), text);
920 makeLaTeXFile(ofs, original_path,
921 runparams, only_body, only_preamble);
925 lyxerr << "File was not closed properly." << endl;
930 void Buffer::makeLaTeXFile(ostream & os,
931 string const & original_path,
932 LatexRunParams const & runparams_in,
933 bool only_body, bool only_preamble)
935 LatexRunParams runparams = runparams_in;
936 niceFile = runparams.nice; // this will be used by Insetincludes.
938 // validate the buffer.
939 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
940 LaTeXFeatures features(params);
942 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
945 // The starting paragraph of the coming rows is the
946 // first paragraph of the document. (Asger)
947 texrow.start(paragraphs.begin()->id(), 0);
949 if (!only_body && runparams.nice) {
950 os << "%% " << lyx_docversion << " created this file. "
951 "For more info, see http://www.lyx.org/.\n"
952 "%% Do not edit unless you really know what "
957 lyxerr[Debug::INFO] << "lyx header finished" << endl;
958 // There are a few differences between nice LaTeX and usual files:
959 // usual is \batchmode and has a
960 // special input@path to allow the including of figures
961 // with either \input or \includegraphics (what figinsets do).
962 // input@path is set when the actual parameter
963 // original_path is set. This is done for usual tex-file, but not
964 // for nice-latex-file. (Matthias 250696)
966 if (!runparams.nice) {
967 // code for usual, NOT nice-latex-file
968 os << "\\batchmode\n"; // changed
972 if (!original_path.empty()) {
973 string inputpath = os::external_path(original_path);
974 subst(inputpath, "~", "\\string~");
975 os << "\\makeatletter\n"
976 << "\\def\\input@path{{"
977 << inputpath << "/}}\n"
978 << "\\makeatother\n";
984 // Write the preamble
985 runparams.use_babel = params.writeLaTeX(os, features, texrow);
991 os << "\\begin{document}\n";
994 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
996 if (!lyxrc.language_auto_begin) {
997 os << subst(lyxrc.language_command_begin, "$$lang",
998 params.language->babel())
1003 latexParagraphs(this, paragraphs, os, texrow, runparams);
1005 // add this just in case after all the paragraphs
1009 if (!lyxrc.language_auto_end) {
1010 os << subst(lyxrc.language_command_end, "$$lang",
1011 params.language->babel())
1017 os << "\\end{document}\n";
1020 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1022 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1026 // Just to be sure. (Asger)
1029 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1030 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1033 // we want this to be true outside previews (for insetexternal)
1038 bool Buffer::isLatex() const
1040 return params.getLyXTextClass().outputType() == LATEX;
1044 bool Buffer::isLinuxDoc() const
1046 return params.getLyXTextClass().outputType() == LINUXDOC;
1050 bool Buffer::isLiterate() const
1052 return params.getLyXTextClass().outputType() == LITERATE;
1056 bool Buffer::isDocBook() const
1058 return params.getLyXTextClass().outputType() == DOCBOOK;
1062 bool Buffer::isSGML() const
1064 LyXTextClass const & tclass = params.getLyXTextClass();
1066 return tclass.outputType() == LINUXDOC ||
1067 tclass.outputType() == DOCBOOK;
1071 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1073 ofstream ofs(fname.c_str());
1076 string const file = MakeDisplayPath(fname, 50);
1077 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1079 Alert::error(_("Could not save document"), text);
1083 niceFile = nice; // this will be used by included files.
1085 LaTeXFeatures features(params);
1091 LyXTextClass const & tclass = params.getLyXTextClass();
1093 string top_element = tclass.latexname();
1096 ofs << "<!doctype linuxdoc system";
1098 string preamble = params.preamble;
1099 string const name = nice ? ChangeExtension(filename_, ".sgml")
1101 preamble += features.getIncludedFiles(name);
1102 preamble += features.getLyXSGMLEntities();
1104 if (!preamble.empty()) {
1105 ofs << " [ " << preamble << " ]";
1109 if (params.options.empty())
1110 sgml::openTag(ofs, 0, false, top_element);
1112 string top = top_element;
1114 top += params.options;
1115 sgml::openTag(ofs, 0, false, top);
1119 ofs << "<!-- " << lyx_docversion
1120 << " created this file. For more info see http://www.lyx.org/"
1123 Paragraph::depth_type depth = 0; // paragraph depth
1125 vector<string> environment_stack(5);
1127 ParagraphList::iterator pit = paragraphs.begin();
1128 ParagraphList::iterator pend = paragraphs.end();
1129 for (; pit != pend; ++pit) {
1130 LyXLayout_ptr const & style = pit->layout();
1131 // treat <toc> as a special case for compatibility with old code
1132 if (pit->isInset(0)) {
1133 Inset * inset = pit->getInset(0);
1134 Inset::Code lyx_code = inset->lyxCode();
1135 if (lyx_code == Inset::TOC_CODE) {
1136 string const temp = "toc";
1137 sgml::openTag(ofs, depth, false, temp);
1142 // environment tag closing
1143 for (; depth > pit->params().depth(); --depth) {
1144 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1145 environment_stack[depth].erase();
1148 // write opening SGML tags
1149 switch (style->latextype) {
1150 case LATEX_PARAGRAPH:
1151 if (depth == pit->params().depth()
1152 && !environment_stack[depth].empty()) {
1153 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1154 environment_stack[depth].erase();
1160 sgml::openTag(ofs, depth, false, style->latexname());
1165 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1167 if (!environment_stack[depth].empty()) {
1168 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1172 environment_stack[depth].erase();
1173 sgml::openTag(ofs, depth, false, style->latexname());
1176 case LATEX_ENVIRONMENT:
1177 case LATEX_ITEM_ENVIRONMENT:
1178 case LATEX_BIB_ENVIRONMENT:
1180 string const & latexname = style->latexname();
1182 if (depth == pit->params().depth()
1183 && environment_stack[depth] != latexname) {
1184 sgml::closeTag(ofs, depth, false,
1185 environment_stack[depth]);
1186 environment_stack[depth].erase();
1188 if (depth < pit->params().depth()) {
1189 depth = pit->params().depth();
1190 environment_stack[depth].erase();
1192 if (environment_stack[depth] != latexname) {
1194 sgml::openTag(ofs, depth, false, "p");
1196 sgml::openTag(ofs, depth, false, latexname);
1198 if (environment_stack.size() == depth + 1)
1199 environment_stack.push_back("!-- --");
1200 environment_stack[depth] = latexname;
1203 if (style->latexparam() == "CDATA")
1206 if (style->latextype == LATEX_ENVIRONMENT) break;
1208 if (style->labeltype == LABEL_MANUAL)
1213 sgml::openTag(ofs, depth + 1, false, item_name);
1218 sgml::openTag(ofs, depth, false, style->latexname());
1222 simpleLinuxDocOnePar(ofs, pit, depth);
1225 // write closing SGML tags
1226 switch (style->latextype) {
1229 case LATEX_ENVIRONMENT:
1230 case LATEX_ITEM_ENVIRONMENT:
1231 case LATEX_BIB_ENVIRONMENT:
1232 if (style->latexparam() == "CDATA")
1236 sgml::closeTag(ofs, depth, false, style->latexname());
1242 for (int i = depth; i >= 0; --i)
1243 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1247 sgml::closeTag(ofs, 0, false, top_element);
1251 // How to check for successful close
1253 // we want this to be true outside previews (for insetexternal)
1258 // checks, if newcol chars should be put into this line
1259 // writes newline, if necessary.
1262 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1263 string::size_type newcol)
1266 if (colcount > lyxrc.ascii_linelen) {
1268 colcount = newcol; // assume write after this call
1283 string tag_name(PAR_TAG const & pt) {
1285 case NONE: return "!-- --";
1286 case TT: return "tt";
1287 case SF: return "sf";
1288 case BF: return "bf";
1289 case IT: return "it";
1290 case SL: return "sl";
1291 case EM: return "em";
1298 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1300 p1 = static_cast<PAR_TAG>(p1 | p2);
1305 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1307 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1313 // Handle internal paragraph parsing -- layout already processed.
1314 void Buffer::simpleLinuxDocOnePar(ostream & os,
1315 ParagraphList::iterator par,
1316 Paragraph::depth_type /*depth*/) const
1318 LyXLayout_ptr const & style = par->layout();
1320 string::size_type char_line_count = 5; // Heuristic choice ;-)
1322 // gets paragraph main font
1325 if (style->labeltype == LABEL_MANUAL) {
1326 font_old = style->labelfont;
1329 font_old = style->font;
1333 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1334 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1335 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1338 stack<PAR_TAG> tag_state;
1339 // parsing main loop
1340 for (pos_type i = 0; i < par->size(); ++i) {
1342 PAR_TAG tag_close = NONE;
1343 list < PAR_TAG > tag_open;
1345 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1347 if (font_old.family() != font.family()) {
1348 switch (family_type) {
1349 case LyXFont::SANS_FAMILY:
1352 case LyXFont::TYPEWRITER_FAMILY:
1359 family_type = font.family();
1361 switch (family_type) {
1362 case LyXFont::SANS_FAMILY:
1363 tag_open.push_back(SF);
1365 case LyXFont::TYPEWRITER_FAMILY:
1366 tag_open.push_back(TT);
1373 if (font_old.series() != font.series()) {
1374 switch (series_type) {
1375 case LyXFont::BOLD_SERIES:
1382 series_type = font.series();
1384 switch (series_type) {
1385 case LyXFont::BOLD_SERIES:
1386 tag_open.push_back(BF);
1394 if (font_old.shape() != font.shape()) {
1395 switch (shape_type) {
1396 case LyXFont::ITALIC_SHAPE:
1399 case LyXFont::SLANTED_SHAPE:
1406 shape_type = font.shape();
1408 switch (shape_type) {
1409 case LyXFont::ITALIC_SHAPE:
1410 tag_open.push_back(IT);
1412 case LyXFont::SLANTED_SHAPE:
1413 tag_open.push_back(SL);
1420 if (font_old.emph() != font.emph()) {
1421 if (font.emph() == LyXFont::ON) {
1422 tag_open.push_back(EM);
1431 list < PAR_TAG > temp;
1432 while (!tag_state.empty() && tag_close) {
1433 PAR_TAG k = tag_state.top();
1435 os << "</" << tag_name(k) << '>';
1442 for(list< PAR_TAG >::const_iterator j = temp.begin();
1443 j != temp.end(); ++j) {
1445 os << '<' << tag_name(*j) << '>';
1448 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1449 j != tag_open.end(); ++j) {
1451 os << '<' << tag_name(*j) << '>';
1454 char c = par->getChar(i);
1456 if (c == Paragraph::META_INSET) {
1457 Inset * inset = par->getInset(i);
1458 inset->linuxdoc(this, os);
1463 if (style->latexparam() == "CDATA") {
1464 // "TeX"-Mode on == > SGML-Mode on.
1471 boost::tie(ws, str) = sgml::escapeChar(c);
1472 if (ws && !par->isFreeSpacing()) {
1473 // in freespacing mode, spaces are
1474 // non-breaking characters
1475 if (desc_on) {// if char is ' ' then...
1478 sgmlLineBreak(os, char_line_count, 6);
1482 sgmlLineBreak(os, char_line_count, 1);
1487 char_line_count += str.length();
1493 while (!tag_state.empty()) {
1494 os << "</" << tag_name(tag_state.top()) << '>';
1498 // resets description flag correctly
1500 // <tag> not closed...
1501 sgmlLineBreak(os, char_line_count, 6);
1507 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1509 ofstream ofs(fname.c_str());
1511 string const file = MakeDisplayPath(fname, 50);
1512 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1514 Alert::error(_("Could not save document"), text);
1518 niceFile = nice; // this will be used by Insetincludes.
1520 LaTeXFeatures features(params);
1525 LyXTextClass const & tclass = params.getLyXTextClass();
1526 string top_element = tclass.latexname();
1529 ofs << "<!DOCTYPE " << top_element
1530 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1532 string preamble = params.preamble;
1533 string const name = nice ? ChangeExtension(filename_, ".sgml")
1535 preamble += features.getIncludedFiles(name);
1536 preamble += features.getLyXSGMLEntities();
1538 if (!preamble.empty()) {
1539 ofs << "\n [ " << preamble << " ]";
1544 string top = top_element;
1546 top += params.language->code();
1549 if (!params.options.empty()) {
1551 top += params.options;
1553 sgml::openTag(ofs, 0, false, top);
1555 ofs << "<!-- DocBook file was created by " << lyx_docversion
1556 << "\n See http://www.lyx.org/ for more information -->\n";
1558 vector<string> environment_stack(10);
1559 vector<string> environment_inner(10);
1560 vector<string> command_stack(10);
1562 bool command_flag = false;
1563 Paragraph::depth_type command_depth = 0;
1564 Paragraph::depth_type command_base = 0;
1565 Paragraph::depth_type cmd_depth = 0;
1566 Paragraph::depth_type depth = 0; // paragraph depth
1569 string command_name;
1571 ParagraphList::iterator par = paragraphs.begin();
1572 ParagraphList::iterator pend = paragraphs.end();
1574 for (; par != pend; ++par) {
1578 int desc_on = 0; // description mode
1580 LyXLayout_ptr const & style = par->layout();
1582 // environment tag closing
1583 for (; depth > par->params().depth(); --depth) {
1584 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1585 item_name = "listitem";
1586 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1587 if (environment_inner[depth] == "varlistentry")
1588 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1590 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1591 environment_stack[depth].erase();
1592 environment_inner[depth].erase();
1595 if (depth == par->params().depth()
1596 && environment_stack[depth] != style->latexname()
1597 && !environment_stack[depth].empty()) {
1598 if (environment_inner[depth] != "!-- --") {
1599 item_name= "listitem";
1600 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1601 if (environment_inner[depth] == "varlistentry")
1602 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1605 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1607 environment_stack[depth].erase();
1608 environment_inner[depth].erase();
1611 // Write opening SGML tags.
1612 switch (style->latextype) {
1613 case LATEX_PARAGRAPH:
1614 sgml::openTag(ofs, depth + command_depth,
1615 false, style->latexname());
1620 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1622 command_name = style->latexname();
1624 sgmlparam = style->latexparam();
1625 c_params = split(sgmlparam, c_depth,'|');
1627 cmd_depth = atoi(c_depth);
1630 if (cmd_depth < command_base) {
1631 for (Paragraph::depth_type j = command_depth;
1632 j >= command_base; --j) {
1633 sgml::closeTag(ofs, j, false, command_stack[j]);
1636 command_depth = command_base = cmd_depth;
1637 } else if (cmd_depth <= command_depth) {
1638 for (int j = command_depth;
1639 j >= int(cmd_depth); --j) {
1640 sgml::closeTag(ofs, j, false, command_stack[j]);
1643 command_depth = cmd_depth;
1645 command_depth = cmd_depth;
1647 command_depth = command_base = cmd_depth;
1648 command_flag = true;
1650 if (command_stack.size() == command_depth + 1)
1651 command_stack.push_back(string());
1652 command_stack[command_depth] = command_name;
1654 // treat label as a special case for
1655 // more WYSIWYM handling.
1656 // This is a hack while paragraphs can't have
1657 // attributes, like id in this case.
1658 if (par->isInset(0)) {
1659 Inset * inset = par->getInset(0);
1660 Inset::Code lyx_code = inset->lyxCode();
1661 if (lyx_code == Inset::LABEL_CODE) {
1662 command_name += " id=\"";
1663 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1664 command_name += '"';
1669 sgml::openTag(ofs, depth + command_depth, false, command_name);
1671 item_name = c_params.empty() ? "title" : c_params;
1672 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1675 case LATEX_ENVIRONMENT:
1676 case LATEX_ITEM_ENVIRONMENT:
1677 if (depth < par->params().depth()) {
1678 depth = par->params().depth();
1679 environment_stack[depth].erase();
1682 if (environment_stack[depth] != style->latexname()) {
1683 if (environment_stack.size() == depth + 1) {
1684 environment_stack.push_back("!-- --");
1685 environment_inner.push_back("!-- --");
1687 environment_stack[depth] = style->latexname();
1688 environment_inner[depth] = "!-- --";
1689 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1691 if (environment_inner[depth] != "!-- --") {
1692 item_name= "listitem";
1693 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1694 if (environment_inner[depth] == "varlistentry")
1695 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1699 if (style->latextype == LATEX_ENVIRONMENT) {
1700 if (!style->latexparam().empty()) {
1701 if (style->latexparam() == "CDATA")
1704 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1709 desc_on = (style->labeltype == LABEL_MANUAL);
1711 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1712 sgml::openTag(ofs, depth + 1 + command_depth,
1713 false, environment_inner[depth]);
1715 item_name = desc_on ? "term" : "para";
1716 sgml::openTag(ofs, depth + 1 + command_depth,
1720 sgml::openTag(ofs, depth + command_depth,
1721 false, style->latexname());
1725 simpleDocBookOnePar(ofs, par, desc_on,
1726 depth + 1 + command_depth);
1729 // write closing SGML tags
1730 switch (style->latextype) {
1732 end_tag = c_params.empty() ? "title" : c_params;
1733 sgml::closeTag(ofs, depth + command_depth,
1736 case LATEX_ENVIRONMENT:
1737 if (!style->latexparam().empty()) {
1738 if (style->latexparam() == "CDATA")
1741 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1744 case LATEX_ITEM_ENVIRONMENT:
1745 if (desc_on == 1) break;
1747 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1749 case LATEX_PARAGRAPH:
1750 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1753 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1759 for (int d = depth; d >= 0; --d) {
1760 if (!environment_stack[depth].empty()) {
1761 if (environment_inner[depth] != "!-- --") {
1762 item_name = "listitem";
1763 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1764 if (environment_inner[depth] == "varlistentry")
1765 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1768 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1772 for (int j = command_depth; j >= 0 ; --j)
1773 if (!command_stack[j].empty()) {
1774 sgml::closeTag(ofs, j, false, command_stack[j]);
1779 sgml::closeTag(ofs, 0, false, top_element);
1782 // How to check for successful close
1784 // we want this to be true outside previews (for insetexternal)
1789 void Buffer::simpleDocBookOnePar(ostream & os,
1790 ParagraphList::iterator par, int & desc_on,
1791 Paragraph::depth_type depth) const
1793 bool emph_flag = false;
1795 LyXLayout_ptr const & style = par->layout();
1797 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1799 int char_line_count = depth;
1800 //if (!style.free_spacing)
1801 // os << string(depth,' ');
1803 // parsing main loop
1804 for (pos_type i = 0; i < par->size(); ++i) {
1805 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1807 // handle <emphasis> tag
1808 if (font_old.emph() != font.emph()) {
1809 if (font.emph() == LyXFont::ON) {
1810 if (style->latexparam() == "CDATA")
1813 if (style->latexparam() == "CDATA")
1817 if (style->latexparam() == "CDATA")
1819 os << "</emphasis>";
1820 if (style->latexparam() == "CDATA")
1827 if (par->isInset(i)) {
1828 Inset * inset = par->getInset(i);
1829 // don't print the inset in position 0 if desc_on == 3 (label)
1830 if (i || desc_on != 3) {
1831 if (style->latexparam() == "CDATA")
1833 inset->docbook(this, os, false);
1834 if (style->latexparam() == "CDATA")
1838 char c = par->getChar(i);
1841 boost::tie(ws, str) = sgml::escapeChar(c);
1843 if (style->pass_thru) {
1845 } else if (par->isFreeSpacing() || c != ' ') {
1847 } else if (desc_on == 1) {
1849 os << "\n</term><listitem><para>";
1859 if (style->latexparam() == "CDATA")
1861 os << "</emphasis>";
1862 if (style->latexparam() == "CDATA")
1866 // resets description flag correctly
1868 // <term> not closed...
1869 os << "</term>\n<listitem><para> </para>";
1871 if (style->free_spacing)
1876 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1877 // Other flags: -wall -v0 -x
1878 int Buffer::runChktex()
1882 // get LaTeX-Filename
1883 string const name = getLatexName();
1884 string path = filePath();
1886 string const org_path = path;
1887 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1891 Path p(path); // path to LaTeX file
1892 message(_("Running chktex..."));
1894 // Generate the LaTeX file if neccessary
1895 LatexRunParams runparams;
1896 runparams.flavor = LatexRunParams::LATEX;
1897 runparams.nice = false;
1898 makeLaTeXFile(name, org_path, runparams);
1901 Chktex chktex(lyxrc.chktex_command, name, filePath());
1902 int res = chktex.run(terr); // run chktex
1905 Alert::error(_("chktex failure"),
1906 _("Could not run chktex successfully."));
1907 } else if (res > 0) {
1908 // Insert all errors as errors boxes
1909 bufferErrors(*this, terr);
1918 void Buffer::validate(LaTeXFeatures & features) const
1920 LyXTextClass const & tclass = params.getLyXTextClass();
1922 if (params.tracking_changes) {
1923 features.require("dvipost");
1924 features.require("color");
1927 // AMS Style is at document level
1928 if (params.use_amsmath == BufferParams::AMS_ON
1929 || tclass.provides(LyXTextClass::amsmath))
1930 features.require("amsmath");
1932 for_each(paragraphs.begin(), paragraphs.end(),
1933 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1935 // the bullet shapes are buffer level not paragraph level
1936 // so they are tested here
1937 for (int i = 0; i < 4; ++i) {
1938 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1939 int const font = params.user_defined_bullets[i].getFont();
1941 int const c = params
1942 .user_defined_bullets[i]
1949 features.require("latexsym");
1951 } else if (font == 1) {
1952 features.require("amssymb");
1953 } else if ((font >= 2 && font <= 5)) {
1954 features.require("pifont");
1959 if (lyxerr.debugging(Debug::LATEX)) {
1960 features.showStruct();
1965 void Buffer::getLabelList(std::vector<string> & list) const
1967 /// if this is a child document and the parent is already loaded
1968 /// Use the parent's list instead [ale990407]
1969 if (!params.parentname.empty()
1970 && bufferlist.exists(params.parentname)) {
1971 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1973 tmp->getLabelList(list);
1978 for (inset_iterator it = inset_const_iterator_begin();
1979 it != inset_const_iterator_end(); ++it) {
1980 it->getLabelList(list);
1985 // This is also a buffer property (ale)
1986 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1988 /// if this is a child document and the parent is already loaded
1989 /// use the parent's list instead [ale990412]
1990 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1991 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1993 tmp->fillWithBibKeys(keys);
1998 for (inset_iterator it = inset_const_iterator_begin();
1999 it != inset_const_iterator_end(); ++it) {
2000 if (it->lyxCode() == Inset::BIBTEX_CODE)
2001 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2002 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2003 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2004 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2005 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2006 string const key = bib.getContents();
2007 string const opt = bib.getOptions();
2008 string const ref; // = pit->asString(this, false);
2009 string const info = opt + "TheBibliographyRef" + ref;
2010 keys.push_back(pair<string, string>(key, info));
2016 bool Buffer::isDepClean(string const & name) const
2018 DepClean::const_iterator it = dep_clean_.find(name);
2019 if (it == dep_clean_.end())
2025 void Buffer::markDepClean(string const & name)
2027 dep_clean_[name] = true;
2031 bool Buffer::dispatch(string const & command, bool * result)
2033 // Split command string into command and argument
2035 string line = ltrim(command);
2036 string const arg = trim(split(line, cmd, ' '));
2038 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2042 bool Buffer::dispatch(int action, string const & argument, bool * result)
2044 bool dispatched = true;
2048 bool const tmp = Exporter::Export(this, argument, false);
2061 void Buffer::changeLanguage(Language const * from, Language const * to)
2063 lyxerr << "Changing Language!" << endl;
2065 // Take care of l10n/i18n
2068 ParIterator end = par_iterator_end();
2069 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2070 it->changeLanguage(params, from, to);
2074 void Buffer::updateDocLang(Language const * nlang)
2076 messages_.reset(new Messages(nlang->code()));
2080 bool Buffer::isMultiLingual()
2082 ParIterator end = par_iterator_end();
2083 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2084 if (it->isMultiLingual(params))
2091 void Buffer::inset_iterator::setParagraph()
2093 while (pit != pend) {
2094 it = pit->insetlist.begin();
2095 if (it != pit->insetlist.end())
2102 Inset * Buffer::getInsetFromID(int id_arg) const
2104 for (inset_iterator it = inset_const_iterator_begin();
2105 it != inset_const_iterator_end(); ++it)
2107 if (it->id() == id_arg)
2109 Inset * in = it->getInsetFromID(id_arg);
2117 ParIterator Buffer::getParFromID(int id) const
2119 #warning FIXME: const correctness! (Andre)
2120 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2121 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2123 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2125 // John says this is called with id == -1 from undo
2126 lyxerr << "getParFromID(), id: " << id << endl;
2130 for (; it != end; ++it)
2138 bool Buffer::hasParWithID(int id) const
2140 ParConstIterator it = par_iterator_begin();
2141 ParConstIterator end = par_iterator_end();
2144 // John says this is called with id == -1 from undo
2145 lyxerr << "hasParWithID(), id: " << id << endl;
2149 for (; it != end; ++it)
2157 ParIterator Buffer::par_iterator_begin()
2159 return ParIterator(paragraphs.begin(), paragraphs);
2163 ParIterator Buffer::par_iterator_end()
2165 return ParIterator(paragraphs.end(), paragraphs);
2168 ParConstIterator Buffer::par_iterator_begin() const
2170 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2174 ParConstIterator Buffer::par_iterator_end() const
2176 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2180 Language const * Buffer::getLanguage() const
2182 return params.language;
2186 string const Buffer::B_(string const & l10n) const
2188 if (messages_.get()) {
2189 return messages_->get(l10n);
2196 bool Buffer::isClean() const
2202 bool Buffer::isBakClean() const
2208 void Buffer::markClean() const
2214 // if the .lyx file has been saved, we don't need an
2220 void Buffer::markBakClean()
2226 void Buffer::setUnnamed(bool flag)
2232 bool Buffer::isUnnamed()
2238 void Buffer::markDirty()
2246 DepClean::iterator it = dep_clean_.begin();
2247 DepClean::const_iterator const end = dep_clean_.end();
2249 for (; it != end; ++it) {
2255 string const & Buffer::fileName() const
2261 string const & Buffer::filePath() const
2267 bool Buffer::isReadonly() const
2273 void Buffer::setParentName(string const & name)
2275 params.parentname = name;
2279 Buffer::inset_iterator::inset_iterator()
2284 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2291 Buffer::inset_iterator Buffer::inset_iterator_begin()
2293 return inset_iterator(paragraphs.begin(), paragraphs.end());
2297 Buffer::inset_iterator Buffer::inset_iterator_end()
2299 return inset_iterator(paragraphs.end(), paragraphs.end());
2303 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2305 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2306 const_cast<ParagraphList&>(paragraphs).end());
2310 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2312 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2313 const_cast<ParagraphList&>(paragraphs).end());
2317 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2321 if (it == pit->insetlist.end()) {
2330 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2332 inset_iterator tmp = *this;
2338 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2344 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2350 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2356 lyx::pos_type Buffer::inset_iterator::getPos() const
2362 bool operator==(Buffer::inset_iterator const & iter1,
2363 Buffer::inset_iterator const & iter2)
2365 return iter1.pit == iter2.pit
2366 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2370 bool operator!=(Buffer::inset_iterator const & iter1,
2371 Buffer::inset_iterator const & iter2)
2373 return !(iter1 == iter2);