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/LAssert.h"
59 #include "support/textutils.h"
60 #include "support/filetools.h"
61 #include "support/path.h"
62 #include "support/os.h"
63 #include "support/tostr.h"
64 #include "support/lyxlib.h"
65 #include "support/FileInfo.h"
66 #include "support/lyxmanip.h"
67 #include "support/lyxtime.h"
68 #include "support/gzstream.h"
70 #include <boost/bind.hpp>
71 #include <boost/tuple/tuple.hpp>
83 #include <sys/types.h>
90 using namespace lyx::support;
92 #ifndef CXX_GLOBAL_CSTD
104 using std::make_pair;
112 using lyx::textclass_type;
114 // all these externs should eventually be removed.
115 extern BufferList bufferlist;
119 const int LYX_FORMAT = 225;
121 bool openFileWrite(ofstream & ofs, string const & fname)
123 ofs.open(fname.c_str());
125 string const file = MakeDisplayPath(fname, 50);
126 string text = bformat(_("Could not open the specified "
127 "document\n%1$s."), file);
128 Alert::error(_("Could not open file"), text);
137 Buffer::Buffer(string const & file, bool ronly)
138 : niceFile(true), lyx_clean(true), bak_clean(true),
139 unnamed(false), read_only(ronly),
142 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
143 filepath_ = OnlyPath(file);
145 if (read_only || lyxrc.use_tempdir) {
146 tmppath = CreateBufferTmpDir();
151 // set initial author
152 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
158 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
159 // here the buffer should take care that it is
160 // saved properly, before it goes into the void.
164 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
165 Alert::warning(_("Could not remove temporary directory"),
166 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
171 // Remove any previewed LaTeX snippets assocoated with this buffer.
172 lyx::graphics::Previews::get().removeLoader(this);
176 string const Buffer::getLatexName(bool no_path) const
178 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
179 return no_path ? OnlyFilename(name) : name;
183 pair<Buffer::LogType, string> const Buffer::getLogName() const
185 string const filename = getLatexName(false);
187 if (filename.empty())
188 return make_pair(Buffer::latexlog, string());
190 string path = OnlyPath(filename);
192 if (lyxrc.use_tempdir || !IsDirWriteable(path))
195 string const fname = AddName(path,
196 OnlyFilename(ChangeExtension(filename,
199 AddName(path, OnlyFilename(
200 ChangeExtension(filename,
201 formats.extension("literate") + ".out")));
203 // If no Latex log or Build log is newer, show Build log
205 FileInfo const f_fi(fname);
206 FileInfo const b_fi(bname);
209 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
210 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
211 return make_pair(Buffer::buildlog, bname);
213 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
214 return make_pair(Buffer::latexlog, fname);
218 void Buffer::setReadonly(bool flag)
220 if (read_only != flag) {
227 AuthorList & Buffer::authors()
229 return params.authorlist;
233 void Buffer::setFileName(string const & newfile)
235 filename_ = MakeAbsPath(newfile);
236 filepath_ = OnlyPath(filename_);
237 setReadonly(IsFileWriteable(filename_) == 0);
242 // We'll remove this later. (Lgb)
245 void unknownClass(string const & unknown)
247 Alert::warning(_("Unknown document class"),
248 bformat(_("Using the default document class, because the "
249 " class %1$s is unknown."), unknown));
254 int Buffer::readHeader(LyXLex & lex)
256 int unknown_tokens = 0;
260 string const token = lex.getString();
265 if (token == "\\end_header")
268 lyxerr[Debug::PARSER] << "Handling header token: `"
269 << token << '\'' << endl;
272 string unknown = params.readToken(lex, token);
273 if (!unknown.empty()) {
274 if (unknown[0] != '\\') {
275 unknownClass(unknown);
278 string const s = bformat(_("Unknown token: "
282 error(ErrorItem(_("Header error"), s,
287 return unknown_tokens;
291 // candidate for move to BufferView
292 // (at least some parts in the beginning of the func)
295 // changed to be public and have one parameter
296 // if par = 0 normal behavior
297 // else insert behavior
298 // Returns false if "\end_document" is not read (Asger)
299 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
301 Paragraph::depth_type depth = 0;
302 bool the_end_read = false;
304 if (paragraphs.empty()) {
306 if (!params.getLyXTextClass().load()) {
307 string theclass = params.getLyXTextClass().name();
308 Alert::error(_("Can't load document class"), bformat(
309 "Using the default document class, because the "
310 " class %1$s could not be loaded.", theclass));
311 params.textclass = 0;
314 // We don't want to adopt the parameters from the
315 // document we insert, so read them into a temporary buffer
316 // and then discard it
318 Buffer tmpbuf("", false);
319 tmpbuf.readHeader(lex);
324 string const token = lex.getString();
329 lyxerr[Debug::PARSER] << "Handling token: `"
330 << token << '\'' << endl;
332 if (token == "\\end_document") {
337 readParagraph(lex, token, paragraphs, pit, depth);
344 int Buffer::readParagraph(LyXLex & lex, string const & token,
345 ParagraphList & pars, ParagraphList::iterator & pit,
346 Paragraph::depth_type & depth)
348 static Change current_change;
351 if (token == "\\begin_layout") {
352 lex.pushToken(token);
355 par.params().depth(depth);
356 if (params.tracking_changes)
358 LyXFont f(LyXFont::ALL_INHERIT, params.language);
362 if (pit != pars.end())
365 pit = pars.insert(pit, par);
367 // FIXME: goddamn InsetTabular makes us pass a Buffer
369 ::readParagraph(*this, *pit, lex);
371 } else if (token == "\\begin_deeper") {
373 } else if (token == "\\end_deeper") {
375 lex.printError("\\end_deeper: " "depth is already null");
386 // needed to insert the selection
387 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
388 LyXFont const & fn,string const & str)
390 LyXLayout_ptr const & layout = par->layout();
394 par->checkInsertChar(font);
395 // insert the string, don't insert doublespace
396 bool space_inserted = true;
397 bool autobreakrows = !par->inInset() ||
398 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
399 for(string::const_iterator cit = str.begin();
400 cit != str.end(); ++cit) {
402 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
403 breakParagraph(params, paragraphs, par, pos,
404 layout->isEnvironment());
407 space_inserted = true;
411 // do not insert consecutive spaces if !free_spacing
412 } else if ((*cit == ' ' || *cit == '\t') &&
413 space_inserted && !par->isFreeSpacing()) {
415 } else if (*cit == '\t') {
416 if (!par->isFreeSpacing()) {
417 // tabs are like spaces here
418 par->insertChar(pos, ' ', font);
420 space_inserted = true;
422 const pos_type nb = 8 - pos % 8;
423 for (pos_type a = 0; a < nb ; ++a) {
424 par->insertChar(pos, ' ', font);
427 space_inserted = true;
429 } else if (!IsPrintable(*cit)) {
430 // Ignore unprintables
433 // just insert the character
434 par->insertChar(pos, *cit, font);
436 space_inserted = (*cit == ' ');
443 bool Buffer::readFile(string const & filename)
445 // Check if the file is compressed.
446 string const format = getExtFromContents(filename);
447 if (format == "gzip" || format == "zip" || format == "compress") {
448 params.compressed = true;
452 lex.setFile(filename);
454 bool ret = readFile(lex, filename, paragraphs.begin());
456 // After we have read a file, we must ensure that the buffer
457 // language is set and used in the gui.
458 // If you know of a better place to put this, please tell me. (Lgb)
459 updateDocLang(params.language);
465 // FIXME: all the below Alerts should give the filename..
466 bool Buffer::readFile(LyXLex & lex, string const & filename,
467 ParagraphList::iterator pit)
470 Alert::error(_("Document could not be read"),
471 _("The specified document could not be read."));
476 string const token(lex.getString());
479 Alert::error(_("Document could not be read"),
480 _("The specified document could not be read."));
484 // the first token _must_ be...
485 if (token != "\\lyxformat") {
486 Alert::error(_("Document format failure"),
487 _("The specified document is not a LyX document."));
492 string tmp_format = lex.getString();
493 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
494 // if present remove ".," from string.
495 string::size_type dot = tmp_format.find_first_of(".,");
496 //lyxerr << " dot found at " << dot << endl;
497 if (dot != string::npos)
498 tmp_format.erase(dot, 1);
499 file_format = strToInt(tmp_format);
500 //lyxerr << "format: " << file_format << endl;
501 if (file_format == LYX_FORMAT) {
503 } else if (file_format > LYX_FORMAT) {
504 Alert::warning(_("Document format failure"),
505 _("This document was created with a newer version of "
506 "LyX. This is likely to cause problems."));
507 } else if (file_format < LYX_FORMAT) {
509 if (file_format < 200) {
510 Alert::error(_("Document format failure"),
511 _("This LyX document is too old to be read "
512 "by this version of LyX. Try LyX 0.10."));
514 } else if (!filename.empty()) {
516 LibFileSearch("lyx2lyx", "lyx2lyx");
517 if (command.empty()) {
518 Alert::error(_("Conversion script not found"),
519 _("The document is from an earlier version "
520 "of LyX, but the conversion script lyx2lyx "
521 "could not be found."));
525 +tostr(LYX_FORMAT) + ' '
526 + QuoteName(filename);
527 lyxerr[Debug::INFO] << "Running '"
530 cmd_ret const ret = RunCommand(command);
532 Alert::error(_("Conversion script failed"),
533 _("The document is from an earlier version "
534 "of LyX, but the lyx2lyx script failed "
538 istringstream is(STRCONV(ret.second));
540 tmplex.setStream(is);
541 return readFile(tmplex, string(), pit);
543 // This code is reached if lyx2lyx failed (for
544 // some reason) to change the file format of
550 bool the_end = readBody(lex, pit);
551 params.setPaperStuff();
554 Alert::error(_("Document format failure"),
555 _("The document ended unexpectedly, which means "
556 "that it is probably corrupted."));
562 // Should probably be moved to somewhere else: BufferView? LyXView?
563 bool Buffer::save() const
565 // We don't need autosaves in the immediate future. (Asger)
566 resetAutosaveTimers();
570 if (lyxrc.make_backup) {
571 s = fileName() + '~';
572 if (!lyxrc.backupdir_path.empty())
573 s = AddName(lyxrc.backupdir_path,
574 subst(os::slashify_path(s),'/','!'));
576 // Rename is the wrong way of making a backup,
577 // this is the correct way.
578 /* truss cp fil fil2:
579 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
580 stat("LyXVC.lyx", 0xEFFFF688) = 0
581 open("LyXVC.lyx", O_RDONLY) = 3
582 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
583 fstat(4, 0xEFFFF508) = 0
584 fstat(3, 0xEFFFF508) = 0
585 read(3, " # T h i s f i l e w".., 8192) = 5579
586 write(4, " # T h i s f i l e w".., 5579) = 5579
587 read(3, 0xEFFFD4A0, 8192) = 0
590 chmod("LyXVC3.lyx", 0100644) = 0
591 lseek(0, 0, SEEK_CUR) = 46440
595 // Should probably have some more error checking here.
596 // Doing it this way, also makes the inodes stay the same.
597 // This is still not a very good solution, in particular we
598 // might loose the owner of the backup.
599 FileInfo finfo(fileName());
601 mode_t fmode = finfo.getMode();
602 struct utimbuf times = {
603 finfo.getAccessTime(),
604 finfo.getModificationTime() };
606 ifstream ifs(fileName().c_str());
607 ofstream ofs(s.c_str(), ios::out|ios::trunc);
612 ::chmod(s.c_str(), fmode);
614 if (::utime(s.c_str(), ×)) {
615 lyxerr << "utime error." << endl;
618 lyxerr << "LyX was not able to make "
619 "backup copy. Beware." << endl;
624 if (writeFile(fileName())) {
626 removeAutosaveFile(fileName());
628 // Saving failed, so backup is not backup
629 if (lyxrc.make_backup) {
630 rename(s, fileName());
638 bool Buffer::writeFile(string const & fname) const
640 if (read_only && (fname == fileName())) {
644 FileInfo finfo(fname);
645 if (finfo.exist() && !finfo.writable()) {
651 if (params.compressed) {
652 gz::ogzstream ofs(fname.c_str());
657 retval = do_writeFile(ofs);
660 ofstream ofs(fname.c_str());
664 retval = do_writeFile(ofs);
671 bool Buffer::do_writeFile(ostream & ofs) const
675 // Use the standard "C" locale for file output.
676 ofs.imbue(std::locale::classic());
679 // The top of the file should not be written by params.
681 // write out a comment in the top of the file
682 ofs << "#LyX " << lyx_version
683 << " created this file. For more info see http://www.lyx.org/\n"
684 << "\\lyxformat " << LYX_FORMAT << "\n";
686 // now write out the buffer paramters.
687 params.writeFile(ofs);
689 ofs << "\\end_header\n";
691 Paragraph::depth_type depth = 0;
693 // this will write out all the paragraphs
694 // using recursive descent.
695 ParagraphList::const_iterator pit = paragraphs.begin();
696 ParagraphList::const_iterator pend = paragraphs.end();
697 for (; pit != pend; ++pit)
698 pit->write(this, ofs, params, depth);
700 // Write marker that shows file is complete
701 ofs << "\n\\end_document" << endl;
703 // Shouldn't really be needed....
706 // how to check if close went ok?
707 // Following is an attempt... (BE 20001011)
709 // good() returns false if any error occured, including some
711 // bad() returns true if something bad happened in the buffer,
712 // which should include file system full errors.
719 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
721 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
733 pair<int, string> const addDepth(int depth, int ldepth)
737 d += (ldepth - depth) * 2;
738 return make_pair(d, string(d, ' '));
744 string const Buffer::asciiParagraph(Paragraph const & par,
745 unsigned int linelen,
746 bool noparbreak) const
748 ostringstream buffer;
750 Paragraph::depth_type ltype_depth = 0;
751 bool ref_printed = false;
752 Paragraph::depth_type depth = par.params().depth();
754 // First write the layout
755 string const & tmp = par.layout()->name();
756 if (compare_no_case(tmp, "itemize") == 0) {
758 ltype_depth = depth + 1;
759 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
761 ltype_depth = depth + 1;
762 } else if (contains(ascii_lowercase(tmp), "ection")) {
764 ltype_depth = depth + 1;
765 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
767 ltype_depth = depth + 1;
768 } else if (compare_ascii_no_case(tmp, "description") == 0) {
770 ltype_depth = depth + 1;
771 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
774 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
782 /* maybe some vertical spaces */
784 /* the labelwidthstring used in lists */
788 /* some pagebreaks? */
792 /* what about the alignment */
794 // linelen <= 0 is special and means we don't have paragraph breaks
796 string::size_type currlinelen = 0;
802 buffer << string(depth * 2, ' ');
803 currlinelen += depth * 2;
806 // we should probably change to the paragraph language in the
807 // gettext here (if possible) so that strings are outputted in
808 // the correct language! (20012712 Jug)
812 case 4: // (Sub)Paragraph
813 case 5: // Description
817 buffer << _("Abstract") << "\n\n";
820 string const abst = _("Abstract: ");
822 currlinelen += abst.length();
825 case 7: // Bibliography
828 buffer << _("References") << "\n\n";
831 string const refs = _("References: ");
833 currlinelen += refs.length();
841 string const parlab = par.params().labelString();
842 buffer << parlab << ' ';
843 currlinelen += parlab.length() + 1;
851 pair<int, string> p = addDepth(depth, ltype_depth);
853 currlinelen += p.first;
856 // this is to change the linebreak to do it by word a bit more
857 // intelligent hopefully! (only in the case where we have a
858 // max linelength!) (Jug)
862 for (pos_type i = 0; i < par.size(); ++i) {
863 char c = par.getUChar(params, i);
865 case Paragraph::META_INSET:
867 InsetOld const * inset = par.getInset(i);
871 currlinelen += word.length();
874 if (inset->ascii(this, buffer, linelen)) {
875 // to be sure it breaks paragraph
876 currlinelen += linelen;
885 currlinelen + word.length() > linelen - 10) {
887 pair<int, string> p = addDepth(depth, ltype_depth);
889 currlinelen = p.first;
892 buffer << word << ' ';
893 currlinelen += word.length() + 1;
900 lyxerr[Debug::INFO] <<
901 "writeAsciiFile: NULL char in structure." << endl;
904 (currlinelen + word.length()) > linelen)
908 pair<int, string> p =
909 addDepth(depth, ltype_depth);
911 currlinelen = p.first;
918 return STRCONV(buffer.str());
922 void Buffer::writeFileAscii(string const & fname, int linelen)
925 if (!::openFileWrite(ofs, fname))
927 writeFileAscii(ofs, linelen);
931 void Buffer::writeFileAscii(ostream & os, int linelen)
933 ParagraphList::iterator beg = paragraphs.begin();
934 ParagraphList::iterator end = paragraphs.end();
935 ParagraphList::iterator it = beg;
936 for (; it != end; ++it) {
937 os << asciiParagraph(*it, linelen, it == beg);
943 void Buffer::makeLaTeXFile(string const & fname,
944 string const & original_path,
945 LatexRunParams const & runparams,
946 bool output_preamble, bool output_body)
948 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
951 if (!::openFileWrite(ofs, fname))
954 makeLaTeXFile(ofs, original_path,
955 runparams, output_preamble, output_body);
959 lyxerr << "File was not closed properly." << endl;
964 void Buffer::makeLaTeXFile(ostream & os,
965 string const & original_path,
966 LatexRunParams const & runparams_in,
967 bool output_preamble, bool output_body)
969 LatexRunParams runparams = runparams_in;
970 niceFile = runparams.nice; // this will be used by Insetincludes.
972 // validate the buffer.
973 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
974 LaTeXFeatures features(params);
976 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
979 // The starting paragraph of the coming rows is the
980 // first paragraph of the document. (Asger)
981 texrow.start(paragraphs.begin()->id(), 0);
983 if (output_preamble && runparams.nice) {
984 os << "%% LyX " << lyx_version << " created this file. "
985 "For more info, see http://www.lyx.org/.\n"
986 "%% Do not edit unless you really know what "
991 lyxerr[Debug::INFO] << "lyx header finished" << endl;
992 // There are a few differences between nice LaTeX and usual files:
993 // usual is \batchmode and has a
994 // special input@path to allow the including of figures
995 // with either \input or \includegraphics (what figinsets do).
996 // input@path is set when the actual parameter
997 // original_path is set. This is done for usual tex-file, but not
998 // for nice-latex-file. (Matthias 250696)
999 if (output_preamble) {
1000 if (!runparams.nice) {
1001 // code for usual, NOT nice-latex-file
1002 os << "\\batchmode\n"; // changed
1003 // from \nonstopmode
1006 if (!original_path.empty()) {
1007 string inputpath = os::external_path(original_path);
1008 subst(inputpath, "~", "\\string~");
1009 os << "\\makeatletter\n"
1010 << "\\def\\input@path{{"
1011 << inputpath << "/}}\n"
1012 << "\\makeatother\n";
1018 // Write the preamble
1019 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1025 os << "\\begin{document}\n";
1027 } // output_preamble
1028 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1030 if (!lyxrc.language_auto_begin) {
1031 os << subst(lyxrc.language_command_begin, "$$lang",
1032 params.language->babel())
1037 latexParagraphs(this, paragraphs, os, texrow, runparams);
1039 // add this just in case after all the paragraphs
1043 if (!lyxrc.language_auto_end) {
1044 os << subst(lyxrc.language_command_end, "$$lang",
1045 params.language->babel())
1050 if (output_preamble) {
1051 os << "\\end{document}\n";
1054 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1056 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1060 // Just to be sure. (Asger)
1063 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1064 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1067 // we want this to be true outside previews (for insetexternal)
1072 bool Buffer::isLatex() const
1074 return params.getLyXTextClass().outputType() == LATEX;
1078 bool Buffer::isLinuxDoc() const
1080 return params.getLyXTextClass().outputType() == LINUXDOC;
1084 bool Buffer::isLiterate() const
1086 return params.getLyXTextClass().outputType() == LITERATE;
1090 bool Buffer::isDocBook() const
1092 return params.getLyXTextClass().outputType() == DOCBOOK;
1096 bool Buffer::isSGML() const
1098 LyXTextClass const & tclass = params.getLyXTextClass();
1100 return tclass.outputType() == LINUXDOC ||
1101 tclass.outputType() == DOCBOOK;
1105 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1108 if (!::openFileWrite(ofs, fname))
1111 niceFile = nice; // this will be used by included files.
1113 LaTeXFeatures features(params);
1119 LyXTextClass const & tclass = params.getLyXTextClass();
1121 string top_element = tclass.latexname();
1124 ofs << "<!doctype linuxdoc system";
1126 string preamble = params.preamble;
1127 string const name = nice ? ChangeExtension(filename_, ".sgml")
1129 preamble += features.getIncludedFiles(name);
1130 preamble += features.getLyXSGMLEntities();
1132 if (!preamble.empty()) {
1133 ofs << " [ " << preamble << " ]";
1137 if (params.options.empty())
1138 sgml::openTag(ofs, 0, false, top_element);
1140 string top = top_element;
1142 top += params.options;
1143 sgml::openTag(ofs, 0, false, top);
1147 ofs << "<!-- LyX " << lyx_version
1148 << " created this file. For more info see http://www.lyx.org/"
1151 Paragraph::depth_type depth = 0; // paragraph depth
1153 vector<string> environment_stack(5);
1155 ParagraphList::iterator pit = paragraphs.begin();
1156 ParagraphList::iterator pend = paragraphs.end();
1157 for (; pit != pend; ++pit) {
1158 LyXLayout_ptr const & style = pit->layout();
1159 // treat <toc> as a special case for compatibility with old code
1160 if (pit->isInset(0)) {
1161 InsetOld * inset = pit->getInset(0);
1162 InsetOld::Code lyx_code = inset->lyxCode();
1163 if (lyx_code == InsetOld::TOC_CODE) {
1164 string const temp = "toc";
1165 sgml::openTag(ofs, depth, false, temp);
1170 // environment tag closing
1171 for (; depth > pit->params().depth(); --depth) {
1172 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1173 environment_stack[depth].erase();
1176 // write opening SGML tags
1177 switch (style->latextype) {
1178 case LATEX_PARAGRAPH:
1179 if (depth == pit->params().depth()
1180 && !environment_stack[depth].empty()) {
1181 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1182 environment_stack[depth].erase();
1188 sgml::openTag(ofs, depth, false, style->latexname());
1193 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1195 if (!environment_stack[depth].empty()) {
1196 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1200 environment_stack[depth].erase();
1201 sgml::openTag(ofs, depth, false, style->latexname());
1204 case LATEX_ENVIRONMENT:
1205 case LATEX_ITEM_ENVIRONMENT:
1206 case LATEX_BIB_ENVIRONMENT:
1208 string const & latexname = style->latexname();
1210 if (depth == pit->params().depth()
1211 && environment_stack[depth] != latexname) {
1212 sgml::closeTag(ofs, depth, false,
1213 environment_stack[depth]);
1214 environment_stack[depth].erase();
1216 if (depth < pit->params().depth()) {
1217 depth = pit->params().depth();
1218 environment_stack[depth].erase();
1220 if (environment_stack[depth] != latexname) {
1222 sgml::openTag(ofs, depth, false, "p");
1224 sgml::openTag(ofs, depth, false, latexname);
1226 if (environment_stack.size() == depth + 1)
1227 environment_stack.push_back("!-- --");
1228 environment_stack[depth] = latexname;
1231 if (style->latexparam() == "CDATA")
1234 if (style->latextype == LATEX_ENVIRONMENT) break;
1236 if (style->labeltype == LABEL_MANUAL)
1241 sgml::openTag(ofs, depth + 1, false, item_name);
1246 sgml::openTag(ofs, depth, false, style->latexname());
1250 simpleLinuxDocOnePar(ofs, pit, depth);
1253 // write closing SGML tags
1254 switch (style->latextype) {
1257 case LATEX_ENVIRONMENT:
1258 case LATEX_ITEM_ENVIRONMENT:
1259 case LATEX_BIB_ENVIRONMENT:
1260 if (style->latexparam() == "CDATA")
1264 sgml::closeTag(ofs, depth, false, style->latexname());
1270 for (int i = depth; i >= 0; --i)
1271 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1275 sgml::closeTag(ofs, 0, false, top_element);
1279 // How to check for successful close
1281 // we want this to be true outside previews (for insetexternal)
1286 // checks, if newcol chars should be put into this line
1287 // writes newline, if necessary.
1290 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1291 string::size_type newcol)
1294 if (colcount > lyxrc.ascii_linelen) {
1296 colcount = newcol; // assume write after this call
1311 string tag_name(PAR_TAG const & pt) {
1313 case NONE: return "!-- --";
1314 case TT: return "tt";
1315 case SF: return "sf";
1316 case BF: return "bf";
1317 case IT: return "it";
1318 case SL: return "sl";
1319 case EM: return "em";
1326 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1328 p1 = static_cast<PAR_TAG>(p1 | p2);
1333 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1335 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1341 // Handle internal paragraph parsing -- layout already processed.
1342 void Buffer::simpleLinuxDocOnePar(ostream & os,
1343 ParagraphList::iterator par,
1344 Paragraph::depth_type /*depth*/) const
1346 LyXLayout_ptr const & style = par->layout();
1348 string::size_type char_line_count = 5; // Heuristic choice ;-)
1350 // gets paragraph main font
1353 if (style->labeltype == LABEL_MANUAL) {
1354 font_old = style->labelfont;
1357 font_old = style->font;
1361 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1362 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1363 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1366 stack<PAR_TAG> tag_state;
1367 // parsing main loop
1368 for (pos_type i = 0; i < par->size(); ++i) {
1370 PAR_TAG tag_close = NONE;
1371 list < PAR_TAG > tag_open;
1373 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1375 if (font_old.family() != font.family()) {
1376 switch (family_type) {
1377 case LyXFont::SANS_FAMILY:
1380 case LyXFont::TYPEWRITER_FAMILY:
1387 family_type = font.family();
1389 switch (family_type) {
1390 case LyXFont::SANS_FAMILY:
1391 tag_open.push_back(SF);
1393 case LyXFont::TYPEWRITER_FAMILY:
1394 tag_open.push_back(TT);
1401 if (font_old.series() != font.series()) {
1402 switch (series_type) {
1403 case LyXFont::BOLD_SERIES:
1410 series_type = font.series();
1412 switch (series_type) {
1413 case LyXFont::BOLD_SERIES:
1414 tag_open.push_back(BF);
1422 if (font_old.shape() != font.shape()) {
1423 switch (shape_type) {
1424 case LyXFont::ITALIC_SHAPE:
1427 case LyXFont::SLANTED_SHAPE:
1434 shape_type = font.shape();
1436 switch (shape_type) {
1437 case LyXFont::ITALIC_SHAPE:
1438 tag_open.push_back(IT);
1440 case LyXFont::SLANTED_SHAPE:
1441 tag_open.push_back(SL);
1448 if (font_old.emph() != font.emph()) {
1449 if (font.emph() == LyXFont::ON) {
1450 tag_open.push_back(EM);
1459 list < PAR_TAG > temp;
1460 while (!tag_state.empty() && tag_close) {
1461 PAR_TAG k = tag_state.top();
1463 os << "</" << tag_name(k) << '>';
1470 for(list< PAR_TAG >::const_iterator j = temp.begin();
1471 j != temp.end(); ++j) {
1473 os << '<' << tag_name(*j) << '>';
1476 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1477 j != tag_open.end(); ++j) {
1479 os << '<' << tag_name(*j) << '>';
1482 char c = par->getChar(i);
1484 if (c == Paragraph::META_INSET) {
1485 InsetOld * inset = par->getInset(i);
1486 inset->linuxdoc(this, os);
1491 if (style->latexparam() == "CDATA") {
1492 // "TeX"-Mode on == > SGML-Mode on.
1499 boost::tie(ws, str) = sgml::escapeChar(c);
1500 if (ws && !par->isFreeSpacing()) {
1501 // in freespacing mode, spaces are
1502 // non-breaking characters
1503 if (desc_on) {// if char is ' ' then...
1506 sgmlLineBreak(os, char_line_count, 6);
1510 sgmlLineBreak(os, char_line_count, 1);
1515 char_line_count += str.length();
1521 while (!tag_state.empty()) {
1522 os << "</" << tag_name(tag_state.top()) << '>';
1526 // resets description flag correctly
1528 // <tag> not closed...
1529 sgmlLineBreak(os, char_line_count, 6);
1535 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1538 if (!::openFileWrite(ofs, fname))
1541 niceFile = nice; // this will be used by Insetincludes.
1543 LaTeXFeatures features(params);
1548 LyXTextClass const & tclass = params.getLyXTextClass();
1549 string top_element = tclass.latexname();
1552 ofs << "<!DOCTYPE " << top_element
1553 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1555 string preamble = params.preamble;
1556 string const name = nice ? ChangeExtension(filename_, ".sgml")
1558 preamble += features.getIncludedFiles(name);
1559 preamble += features.getLyXSGMLEntities();
1561 if (!preamble.empty()) {
1562 ofs << "\n [ " << preamble << " ]";
1567 string top = top_element;
1569 top += params.language->code();
1572 if (!params.options.empty()) {
1574 top += params.options;
1576 sgml::openTag(ofs, 0, false, top);
1578 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1579 << "\n See http://www.lyx.org/ for more information -->\n";
1581 vector<string> environment_stack(10);
1582 vector<string> environment_inner(10);
1583 vector<string> command_stack(10);
1585 bool command_flag = false;
1586 Paragraph::depth_type command_depth = 0;
1587 Paragraph::depth_type command_base = 0;
1588 Paragraph::depth_type cmd_depth = 0;
1589 Paragraph::depth_type depth = 0; // paragraph depth
1592 string command_name;
1594 ParagraphList::iterator par = paragraphs.begin();
1595 ParagraphList::iterator pend = paragraphs.end();
1597 for (; par != pend; ++par) {
1601 int desc_on = 0; // description mode
1603 LyXLayout_ptr const & style = par->layout();
1605 // environment tag closing
1606 for (; depth > par->params().depth(); --depth) {
1607 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1608 item_name = "listitem";
1609 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1610 if (environment_inner[depth] == "varlistentry")
1611 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1613 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1614 environment_stack[depth].erase();
1615 environment_inner[depth].erase();
1618 if (depth == par->params().depth()
1619 && environment_stack[depth] != style->latexname()
1620 && !environment_stack[depth].empty()) {
1621 if (environment_inner[depth] != "!-- --") {
1622 item_name= "listitem";
1623 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1624 if (environment_inner[depth] == "varlistentry")
1625 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1628 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1630 environment_stack[depth].erase();
1631 environment_inner[depth].erase();
1634 // Write opening SGML tags.
1635 switch (style->latextype) {
1636 case LATEX_PARAGRAPH:
1637 sgml::openTag(ofs, depth + command_depth,
1638 false, style->latexname());
1643 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1645 command_name = style->latexname();
1647 sgmlparam = style->latexparam();
1648 c_params = split(sgmlparam, c_depth,'|');
1650 cmd_depth = atoi(c_depth);
1653 if (cmd_depth < command_base) {
1654 for (Paragraph::depth_type j = command_depth;
1655 j >= command_base; --j) {
1656 sgml::closeTag(ofs, j, false, command_stack[j]);
1659 command_depth = command_base = cmd_depth;
1660 } else if (cmd_depth <= command_depth) {
1661 for (int j = command_depth;
1662 j >= int(cmd_depth); --j) {
1663 sgml::closeTag(ofs, j, false, command_stack[j]);
1666 command_depth = cmd_depth;
1668 command_depth = cmd_depth;
1670 command_depth = command_base = cmd_depth;
1671 command_flag = true;
1673 if (command_stack.size() == command_depth + 1)
1674 command_stack.push_back(string());
1675 command_stack[command_depth] = command_name;
1677 // treat label as a special case for
1678 // more WYSIWYM handling.
1679 // This is a hack while paragraphs can't have
1680 // attributes, like id in this case.
1681 if (par->isInset(0)) {
1682 InsetOld * inset = par->getInset(0);
1683 InsetOld::Code lyx_code = inset->lyxCode();
1684 if (lyx_code == InsetOld::LABEL_CODE) {
1685 command_name += " id=\"";
1686 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1687 command_name += '"';
1692 sgml::openTag(ofs, depth + command_depth, false, command_name);
1694 item_name = c_params.empty() ? "title" : c_params;
1695 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1698 case LATEX_ENVIRONMENT:
1699 case LATEX_ITEM_ENVIRONMENT:
1700 if (depth < par->params().depth()) {
1701 depth = par->params().depth();
1702 environment_stack[depth].erase();
1705 if (environment_stack[depth] != style->latexname()) {
1706 if (environment_stack.size() == depth + 1) {
1707 environment_stack.push_back("!-- --");
1708 environment_inner.push_back("!-- --");
1710 environment_stack[depth] = style->latexname();
1711 environment_inner[depth] = "!-- --";
1712 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1714 if (environment_inner[depth] != "!-- --") {
1715 item_name= "listitem";
1716 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1717 if (environment_inner[depth] == "varlistentry")
1718 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1722 if (style->latextype == LATEX_ENVIRONMENT) {
1723 if (!style->latexparam().empty()) {
1724 if (style->latexparam() == "CDATA")
1727 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1732 desc_on = (style->labeltype == LABEL_MANUAL);
1734 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1735 sgml::openTag(ofs, depth + 1 + command_depth,
1736 false, environment_inner[depth]);
1738 item_name = desc_on ? "term" : "para";
1739 sgml::openTag(ofs, depth + 1 + command_depth,
1743 sgml::openTag(ofs, depth + command_depth,
1744 false, style->latexname());
1748 simpleDocBookOnePar(ofs, par, desc_on,
1749 depth + 1 + command_depth);
1752 // write closing SGML tags
1753 switch (style->latextype) {
1755 end_tag = c_params.empty() ? "title" : c_params;
1756 sgml::closeTag(ofs, depth + command_depth,
1759 case LATEX_ENVIRONMENT:
1760 if (!style->latexparam().empty()) {
1761 if (style->latexparam() == "CDATA")
1764 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1767 case LATEX_ITEM_ENVIRONMENT:
1768 if (desc_on == 1) break;
1770 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1772 case LATEX_PARAGRAPH:
1773 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1776 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1782 for (int d = depth; d >= 0; --d) {
1783 if (!environment_stack[depth].empty()) {
1784 if (environment_inner[depth] != "!-- --") {
1785 item_name = "listitem";
1786 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1787 if (environment_inner[depth] == "varlistentry")
1788 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1791 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1795 for (int j = command_depth; j >= 0 ; --j)
1796 if (!command_stack[j].empty()) {
1797 sgml::closeTag(ofs, j, false, command_stack[j]);
1802 sgml::closeTag(ofs, 0, false, top_element);
1805 // How to check for successful close
1807 // we want this to be true outside previews (for insetexternal)
1812 void Buffer::simpleDocBookOnePar(ostream & os,
1813 ParagraphList::iterator par, int & desc_on,
1814 Paragraph::depth_type depth) const
1816 bool emph_flag = false;
1818 LyXLayout_ptr const & style = par->layout();
1820 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1822 int char_line_count = depth;
1823 //if (!style.free_spacing)
1824 // os << string(depth,' ');
1826 // parsing main loop
1827 for (pos_type i = 0; i < par->size(); ++i) {
1828 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1830 // handle <emphasis> tag
1831 if (font_old.emph() != font.emph()) {
1832 if (font.emph() == LyXFont::ON) {
1833 if (style->latexparam() == "CDATA")
1836 if (style->latexparam() == "CDATA")
1840 if (style->latexparam() == "CDATA")
1842 os << "</emphasis>";
1843 if (style->latexparam() == "CDATA")
1850 if (par->isInset(i)) {
1851 InsetOld * inset = par->getInset(i);
1852 // don't print the inset in position 0 if desc_on == 3 (label)
1853 if (i || desc_on != 3) {
1854 if (style->latexparam() == "CDATA")
1856 inset->docbook(this, os, false);
1857 if (style->latexparam() == "CDATA")
1861 char c = par->getChar(i);
1864 boost::tie(ws, str) = sgml::escapeChar(c);
1866 if (style->pass_thru) {
1868 } else if (par->isFreeSpacing() || c != ' ') {
1870 } else if (desc_on == 1) {
1872 os << "\n</term><listitem><para>";
1882 if (style->latexparam() == "CDATA")
1884 os << "</emphasis>";
1885 if (style->latexparam() == "CDATA")
1889 // resets description flag correctly
1891 // <term> not closed...
1892 os << "</term>\n<listitem><para> </para>";
1894 if (style->free_spacing)
1899 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1900 // Other flags: -wall -v0 -x
1901 int Buffer::runChktex()
1905 // get LaTeX-Filename
1906 string const name = getLatexName();
1907 string path = filePath();
1909 string const org_path = path;
1910 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1914 Path p(path); // path to LaTeX file
1915 message(_("Running chktex..."));
1917 // Generate the LaTeX file if neccessary
1918 LatexRunParams runparams;
1919 runparams.flavor = LatexRunParams::LATEX;
1920 runparams.nice = false;
1921 makeLaTeXFile(name, org_path, runparams);
1924 Chktex chktex(lyxrc.chktex_command, name, filePath());
1925 int res = chktex.run(terr); // run chktex
1928 Alert::error(_("chktex failure"),
1929 _("Could not run chktex successfully."));
1930 } else if (res > 0) {
1931 // Insert all errors as errors boxes
1932 bufferErrors(*this, terr);
1941 void Buffer::validate(LaTeXFeatures & features) const
1943 LyXTextClass const & tclass = params.getLyXTextClass();
1945 if (params.tracking_changes) {
1946 features.require("dvipost");
1947 features.require("color");
1950 // AMS Style is at document level
1951 if (params.use_amsmath == BufferParams::AMS_ON
1952 || tclass.provides(LyXTextClass::amsmath))
1953 features.require("amsmath");
1955 for_each(paragraphs.begin(), paragraphs.end(),
1956 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1958 // the bullet shapes are buffer level not paragraph level
1959 // so they are tested here
1960 for (int i = 0; i < 4; ++i) {
1961 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1962 int const font = params.user_defined_bullets[i].getFont();
1964 int const c = params
1965 .user_defined_bullets[i]
1972 features.require("latexsym");
1974 } else if (font == 1) {
1975 features.require("amssymb");
1976 } else if ((font >= 2 && font <= 5)) {
1977 features.require("pifont");
1982 if (lyxerr.debugging(Debug::LATEX)) {
1983 features.showStruct();
1988 void Buffer::getLabelList(std::vector<string> & list) const
1990 /// if this is a child document and the parent is already loaded
1991 /// Use the parent's list instead [ale990407]
1992 if (!params.parentname.empty()
1993 && bufferlist.exists(params.parentname)) {
1994 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1996 tmp->getLabelList(list);
2001 for (inset_iterator it = inset_const_iterator_begin();
2002 it != inset_const_iterator_end(); ++it) {
2003 it->getLabelList(list);
2008 // This is also a buffer property (ale)
2009 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
2011 /// if this is a child document and the parent is already loaded
2012 /// use the parent's list instead [ale990412]
2013 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2014 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2016 tmp->fillWithBibKeys(keys);
2021 for (inset_iterator it = inset_const_iterator_begin();
2022 it != inset_const_iterator_end(); ++it) {
2023 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2024 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2025 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2026 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2027 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2028 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2029 string const key = bib.getContents();
2030 string const opt = bib.getOptions();
2031 string const ref; // = pit->asString(this, false);
2032 string const info = opt + "TheBibliographyRef" + ref;
2033 keys.push_back(pair<string, string>(key, info));
2039 bool Buffer::isDepClean(string const & name) const
2041 DepClean::const_iterator it = dep_clean_.find(name);
2042 if (it == dep_clean_.end())
2048 void Buffer::markDepClean(string const & name)
2050 dep_clean_[name] = true;
2054 bool Buffer::dispatch(string const & command, bool * result)
2056 // Split command string into command and argument
2058 string line = ltrim(command);
2059 string const arg = trim(split(line, cmd, ' '));
2061 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2065 bool Buffer::dispatch(int action, string const & argument, bool * result)
2067 bool dispatched = true;
2071 bool const tmp = Exporter::Export(this, argument, false);
2084 void Buffer::changeLanguage(Language const * from, Language const * to)
2086 lyxerr << "Changing Language!" << endl;
2088 // Take care of l10n/i18n
2091 ParIterator end = par_iterator_end();
2092 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2093 it->changeLanguage(params, from, to);
2097 void Buffer::updateDocLang(Language const * nlang)
2099 messages_.reset(new Messages(nlang->code()));
2103 bool Buffer::isMultiLingual()
2105 ParIterator end = par_iterator_end();
2106 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2107 if (it->isMultiLingual(params))
2114 void Buffer::inset_iterator::setParagraph()
2116 while (pit != pend) {
2117 it = pit->insetlist.begin();
2118 if (it != pit->insetlist.end())
2125 InsetOld * Buffer::getInsetFromID(int id_arg) const
2127 for (inset_iterator it = inset_const_iterator_begin();
2128 it != inset_const_iterator_end(); ++it)
2130 if (it->id() == id_arg)
2132 InsetOld * in = it->getInsetFromID(id_arg);
2140 ParIterator Buffer::getParFromID(int id) const
2142 #warning FIXME: const correctness! (Andre)
2143 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2144 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2146 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2148 // John says this is called with id == -1 from undo
2149 lyxerr << "getParFromID(), id: " << id << endl;
2153 for (; it != end; ++it)
2161 bool Buffer::hasParWithID(int id) const
2163 ParConstIterator it = par_iterator_begin();
2164 ParConstIterator end = par_iterator_end();
2167 // John says this is called with id == -1 from undo
2168 lyxerr << "hasParWithID(), id: " << id << endl;
2172 for (; it != end; ++it)
2180 ParIterator Buffer::par_iterator_begin()
2182 return ParIterator(paragraphs.begin(), paragraphs);
2186 ParIterator Buffer::par_iterator_end()
2188 return ParIterator(paragraphs.end(), paragraphs);
2191 ParConstIterator Buffer::par_iterator_begin() const
2193 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2197 ParConstIterator Buffer::par_iterator_end() const
2199 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2203 Language const * Buffer::getLanguage() const
2205 return params.language;
2209 string const Buffer::B_(string const & l10n) const
2211 if (messages_.get()) {
2212 return messages_->get(l10n);
2219 bool Buffer::isClean() const
2225 bool Buffer::isBakClean() const
2231 void Buffer::markClean() const
2237 // if the .lyx file has been saved, we don't need an
2243 void Buffer::markBakClean()
2249 void Buffer::setUnnamed(bool flag)
2255 bool Buffer::isUnnamed()
2261 void Buffer::markDirty()
2269 DepClean::iterator it = dep_clean_.begin();
2270 DepClean::const_iterator const end = dep_clean_.end();
2272 for (; it != end; ++it) {
2278 string const & Buffer::fileName() const
2284 string const & Buffer::filePath() const
2290 bool Buffer::isReadonly() const
2296 void Buffer::setParentName(string const & name)
2298 params.parentname = name;
2302 Buffer::inset_iterator::inset_iterator()
2307 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2314 Buffer::inset_iterator Buffer::inset_iterator_begin()
2316 return inset_iterator(paragraphs.begin(), paragraphs.end());
2320 Buffer::inset_iterator Buffer::inset_iterator_end()
2322 return inset_iterator(paragraphs.end(), paragraphs.end());
2326 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2328 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2329 const_cast<ParagraphList&>(paragraphs).end());
2333 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2335 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2336 const_cast<ParagraphList&>(paragraphs).end());
2340 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2344 if (it == pit->insetlist.end()) {
2353 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2355 inset_iterator tmp = *this;
2361 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2367 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2373 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2379 lyx::pos_type Buffer::inset_iterator::getPos() const
2385 bool operator==(Buffer::inset_iterator const & iter1,
2386 Buffer::inset_iterator const & iter2)
2388 return iter1.pit == iter2.pit
2389 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2393 bool operator!=(Buffer::inset_iterator const & iter1,
2394 Buffer::inset_iterator const & iter2)
2396 return !(iter1 == iter2);