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 // all these externs should eventually be removed.
113 extern BufferList bufferlist;
117 const int LYX_FORMAT = 224;
121 Buffer::Buffer(string const & file, bool ronly)
122 : niceFile(true), lyx_clean(true), bak_clean(true),
123 unnamed(false), read_only(ronly),
126 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
127 filepath_ = OnlyPath(file);
129 if (read_only || lyxrc.use_tempdir) {
130 tmppath = CreateBufferTmpDir();
135 // set initial author
136 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
142 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
143 // here the buffer should take care that it is
144 // saved properly, before it goes into the void.
148 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
149 Alert::warning(_("Could not remove temporary directory"),
150 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
155 // Remove any previewed LaTeX snippets assocoated with this buffer.
156 lyx::graphics::Previews::get().removeLoader(this);
160 string const Buffer::getLatexName(bool no_path) const
162 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
163 return no_path ? OnlyFilename(name) : name;
167 pair<Buffer::LogType, string> const Buffer::getLogName() const
169 string const filename = getLatexName(false);
171 if (filename.empty())
172 return make_pair(Buffer::latexlog, string());
174 string path = OnlyPath(filename);
176 if (lyxrc.use_tempdir || !IsDirWriteable(path))
179 string const fname = AddName(path,
180 OnlyFilename(ChangeExtension(filename,
183 AddName(path, OnlyFilename(
184 ChangeExtension(filename,
185 formats.extension("literate") + ".out")));
187 // If no Latex log or Build log is newer, show Build log
189 FileInfo const f_fi(fname);
190 FileInfo const b_fi(bname);
193 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
194 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
195 return make_pair(Buffer::buildlog, bname);
197 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
198 return make_pair(Buffer::latexlog, fname);
202 void Buffer::setReadonly(bool flag)
204 if (read_only != flag) {
211 AuthorList & Buffer::authors()
213 return params.authorlist;
217 void Buffer::setFileName(string const & newfile)
219 filename_ = MakeAbsPath(newfile);
220 filepath_ = OnlyPath(filename_);
221 setReadonly(IsFileWriteable(filename_) == 0);
226 // We'll remove this later. (Lgb)
229 void unknownClass(string const & unknown)
231 Alert::warning(_("Unknown document class"),
232 bformat(_("Using the default document class, because the "
233 " class %1$s is unknown."), unknown));
238 int Buffer::readHeader(LyXLex & lex)
240 int unknown_tokens = 0;
244 string const token = lex.getString();
249 if (token == "\\end_header")
252 lyxerr[Debug::PARSER] << "Handling header token: `"
253 << token << '\'' << endl;
256 string unknown = params.readToken(lex, token);
257 if (!unknown.empty()) {
258 if (unknown[0] != '\\') {
259 unknownClass(unknown);
262 string const s = bformat(_("Unknown token: "
266 error(ErrorItem(_("Header error"), s,
271 return unknown_tokens;
275 // candidate for move to BufferView
276 // (at least some parts in the beginning of the func)
279 // changed to be public and have one parameter
280 // if par = 0 normal behavior
281 // else insert behavior
282 // Returns false if "\the_end" is not read (Asger)
283 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
285 Paragraph::depth_type depth = 0;
286 bool the_end_read = false;
288 if (paragraphs.empty()) {
290 if (!params.getLyXTextClass().load()) {
291 string theclass = params.getLyXTextClass().name();
292 Alert::error(_("Can't load document class"), bformat(
293 "Using the default document class, because the "
294 " class %1$s could not be loaded.", theclass));
295 params.textclass = 0;
298 // We don't want to adopt the parameters from the
299 // document we insert, so read them into a temporary buffer
300 // and then discard it
302 Buffer tmpbuf("", false);
303 tmpbuf.readHeader(lex);
308 string const token = lex.getString();
313 lyxerr[Debug::PARSER] << "Handling token: `"
314 << token << '\'' << endl;
316 if (token == "\\the_end") {
321 readParagraph(lex, token, paragraphs, pit, depth);
328 int Buffer::readParagraph(LyXLex & lex, string const & token,
329 ParagraphList & pars, ParagraphList::iterator & pit,
330 Paragraph::depth_type & depth)
332 static Change current_change;
335 if (token == "\\layout") {
336 lex.pushToken(token);
339 par.params().depth(depth);
340 if (params.tracking_changes)
342 LyXFont f(LyXFont::ALL_INHERIT, params.language);
346 if (pit != pars.end())
349 pit = pars.insert(pit, par);
351 // FIXME: goddamn InsetTabular makes us pass a Buffer
353 ::readParagraph(*this, *pit, lex);
355 } else if (token == "\\begin_deeper") {
357 } else if (token == "\\end_deeper") {
359 lex.printError("\\end_deeper: " "depth is already null");
370 // needed to insert the selection
371 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
372 LyXFont const & fn,string const & str)
374 LyXLayout_ptr const & layout = par->layout();
378 par->checkInsertChar(font);
379 // insert the string, don't insert doublespace
380 bool space_inserted = true;
381 bool autobreakrows = !par->inInset() ||
382 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
383 for(string::const_iterator cit = str.begin();
384 cit != str.end(); ++cit) {
386 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
387 breakParagraph(params, paragraphs, par, pos,
388 layout->isEnvironment());
391 space_inserted = true;
395 // do not insert consecutive spaces if !free_spacing
396 } else if ((*cit == ' ' || *cit == '\t') &&
397 space_inserted && !par->isFreeSpacing()) {
399 } else if (*cit == '\t') {
400 if (!par->isFreeSpacing()) {
401 // tabs are like spaces here
402 par->insertChar(pos, ' ', font);
404 space_inserted = true;
406 const pos_type nb = 8 - pos % 8;
407 for (pos_type a = 0; a < nb ; ++a) {
408 par->insertChar(pos, ' ', font);
411 space_inserted = true;
413 } else if (!IsPrintable(*cit)) {
414 // Ignore unprintables
417 // just insert the character
418 par->insertChar(pos, *cit, font);
420 space_inserted = (*cit == ' ');
427 bool Buffer::readFile(LyXLex & lex, string const & filename)
429 bool ret = readFile(lex, filename, paragraphs.begin());
431 // After we have read a file, we must ensure that the buffer
432 // language is set and used in the gui.
433 // If you know of a better place to put this, please tell me. (Lgb)
434 updateDocLang(params.language);
440 // FIXME: all the below Alerts should give the filename..
441 bool Buffer::readFile(LyXLex & lex, string const & filename,
442 ParagraphList::iterator pit)
445 Alert::error(_("Document could not be read"),
446 _("The specified document could not be read."));
451 string const token(lex.getString());
454 Alert::error(_("Document could not be read"),
455 _("The specified document could not be read."));
459 // the first token _must_ be...
460 if (token != "\\lyxformat") {
461 Alert::error(_("Document format failure"),
462 _("The specified document is not a LyX document."));
467 string tmp_format = lex.getString();
468 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
469 // if present remove ".," from string.
470 string::size_type dot = tmp_format.find_first_of(".,");
471 //lyxerr << " dot found at " << dot << endl;
472 if (dot != string::npos)
473 tmp_format.erase(dot, 1);
474 file_format = strToInt(tmp_format);
475 //lyxerr << "format: " << file_format << endl;
476 if (file_format == LYX_FORMAT) {
478 } else if (file_format > LYX_FORMAT) {
479 Alert::warning(_("Document format failure"),
480 _("This document was created with a newer version of "
481 "LyX. This is likely to cause problems."));
482 } else if (file_format < LYX_FORMAT) {
484 if (file_format < 200) {
485 Alert::error(_("Document format failure"),
486 _("This LyX document is too old to be read "
487 "by this version of LyX. Try LyX 0.10."));
489 } else if (!filename.empty()) {
491 LibFileSearch("lyx2lyx", "lyx2lyx");
492 if (command.empty()) {
493 Alert::error(_("Conversion script not found"),
494 _("The document is from an earlier version "
495 "of LyX, but the conversion script lyx2lyx "
496 "could not be found."));
500 +tostr(LYX_FORMAT) + ' '
501 + QuoteName(filename);
502 lyxerr[Debug::INFO] << "Running '"
505 cmd_ret const ret = RunCommand(command);
507 Alert::error(_("Conversion script failed"),
508 _("The document is from an earlier version "
509 "of LyX, but the lyx2lyx script failed "
513 istringstream is(STRCONV(ret.second));
515 tmplex.setStream(is);
516 return readFile(tmplex, string(), pit);
518 // This code is reached if lyx2lyx failed (for
519 // some reason) to change the file format of
525 bool the_end = readBody(lex, pit);
526 params.setPaperStuff();
529 Alert::error(_("Document format failure"),
530 _("The document ended unexpectedly, which means "
531 "that it is probably corrupted."));
537 // Should probably be moved to somewhere else: BufferView? LyXView?
538 bool Buffer::save() const
540 // We don't need autosaves in the immediate future. (Asger)
541 resetAutosaveTimers();
545 if (lyxrc.make_backup) {
546 s = fileName() + '~';
547 if (!lyxrc.backupdir_path.empty())
548 s = AddName(lyxrc.backupdir_path,
549 subst(os::slashify_path(s),'/','!'));
551 // Rename is the wrong way of making a backup,
552 // this is the correct way.
553 /* truss cp fil fil2:
554 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
555 stat("LyXVC.lyx", 0xEFFFF688) = 0
556 open("LyXVC.lyx", O_RDONLY) = 3
557 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
558 fstat(4, 0xEFFFF508) = 0
559 fstat(3, 0xEFFFF508) = 0
560 read(3, " # T h i s f i l e w".., 8192) = 5579
561 write(4, " # T h i s f i l e w".., 5579) = 5579
562 read(3, 0xEFFFD4A0, 8192) = 0
565 chmod("LyXVC3.lyx", 0100644) = 0
566 lseek(0, 0, SEEK_CUR) = 46440
570 // Should probably have some more error checking here.
571 // Doing it this way, also makes the inodes stay the same.
572 // This is still not a very good solution, in particular we
573 // might loose the owner of the backup.
574 FileInfo finfo(fileName());
576 mode_t fmode = finfo.getMode();
577 struct utimbuf times = {
578 finfo.getAccessTime(),
579 finfo.getModificationTime() };
581 ifstream ifs(fileName().c_str());
582 ofstream ofs(s.c_str(), ios::out|ios::trunc);
587 ::chmod(s.c_str(), fmode);
589 if (::utime(s.c_str(), ×)) {
590 lyxerr << "utime error." << endl;
593 lyxerr << "LyX was not able to make "
594 "backup copy. Beware." << endl;
599 if (writeFile(fileName())) {
601 removeAutosaveFile(fileName());
603 // Saving failed, so backup is not backup
604 if (lyxrc.make_backup) {
605 rename(s, fileName());
613 bool Buffer::writeFile(string const & fname) const
615 if (read_only && (fname == fileName())) {
619 FileInfo finfo(fname);
620 if (finfo.exist() && !finfo.writable()) {
624 ofstream ofs(fname.c_str());
630 // Use the standard "C" locale for file output.
631 ofs.imbue(std::locale::classic());
634 // The top of the file should not be written by params.
636 // write out a comment in the top of the file
637 ofs << '#' << lyx_docversion
638 << " created this file. For more info see http://www.lyx.org/\n"
639 << "\\lyxformat " << LYX_FORMAT << "\n";
641 // now write out the buffer paramters.
642 params.writeFile(ofs);
644 ofs << "\\end_header\n";
646 Paragraph::depth_type depth = 0;
648 // this will write out all the paragraphs
649 // using recursive descent.
650 ParagraphList::const_iterator pit = paragraphs.begin();
651 ParagraphList::const_iterator pend = paragraphs.end();
652 for (; pit != pend; ++pit)
653 pit->write(this, ofs, params, depth);
655 // Write marker that shows file is complete
656 ofs << "\n\\the_end" << endl;
660 // how to check if close went ok?
661 // Following is an attempt... (BE 20001011)
663 // good() returns false if any error occured, including some
665 // bad() returns true if something bad happened in the buffer,
666 // which should include file system full errors.
673 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
675 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
687 pair<int, string> const addDepth(int depth, int ldepth)
691 d += (ldepth - depth) * 2;
692 return make_pair(d, string(d, ' '));
698 string const Buffer::asciiParagraph(Paragraph const & par,
699 unsigned int linelen,
700 bool noparbreak) const
702 ostringstream buffer;
704 Paragraph::depth_type ltype_depth = 0;
705 bool ref_printed = false;
706 Paragraph::depth_type depth = par.params().depth();
708 // First write the layout
709 string const & tmp = par.layout()->name();
710 if (compare_no_case(tmp, "itemize") == 0) {
712 ltype_depth = depth + 1;
713 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
715 ltype_depth = depth + 1;
716 } else if (contains(ascii_lowercase(tmp), "ection")) {
718 ltype_depth = depth + 1;
719 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
721 ltype_depth = depth + 1;
722 } else if (compare_ascii_no_case(tmp, "description") == 0) {
724 ltype_depth = depth + 1;
725 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
728 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
736 /* maybe some vertical spaces */
738 /* the labelwidthstring used in lists */
742 /* some pagebreaks? */
746 /* what about the alignment */
748 // linelen <= 0 is special and means we don't have paragraph breaks
750 string::size_type currlinelen = 0;
756 buffer << string(depth * 2, ' ');
757 currlinelen += depth * 2;
760 // we should probably change to the paragraph language in the
761 // gettext here (if possible) so that strings are outputted in
762 // the correct language! (20012712 Jug)
766 case 4: // (Sub)Paragraph
767 case 5: // Description
771 buffer << _("Abstract") << "\n\n";
774 string const abst = _("Abstract: ");
776 currlinelen += abst.length();
779 case 7: // Bibliography
782 buffer << _("References") << "\n\n";
785 string const refs = _("References: ");
787 currlinelen += refs.length();
795 string const parlab = par.params().labelString();
796 buffer << parlab << ' ';
797 currlinelen += parlab.length() + 1;
805 pair<int, string> p = addDepth(depth, ltype_depth);
807 currlinelen += p.first;
810 // this is to change the linebreak to do it by word a bit more
811 // intelligent hopefully! (only in the case where we have a
812 // max linelength!) (Jug)
816 for (pos_type i = 0; i < par.size(); ++i) {
817 char c = par.getUChar(params, i);
819 case Paragraph::META_INSET:
821 Inset const * inset = par.getInset(i);
825 currlinelen += word.length();
828 if (inset->ascii(this, buffer, linelen)) {
829 // to be sure it breaks paragraph
830 currlinelen += linelen;
839 currlinelen + word.length() > linelen - 10) {
841 pair<int, string> p = addDepth(depth, ltype_depth);
843 currlinelen = p.first;
846 buffer << word << ' ';
847 currlinelen += word.length() + 1;
854 lyxerr[Debug::INFO] <<
855 "writeAsciiFile: NULL char in structure." << endl;
858 (currlinelen + word.length()) > linelen)
862 pair<int, string> p =
863 addDepth(depth, ltype_depth);
865 currlinelen = p.first;
872 return STRCONV(buffer.str());
876 void Buffer::writeFileAscii(string const & fname, int linelen)
878 ofstream ofs(fname.c_str());
880 string const file = MakeDisplayPath(fname, 50);
881 string text = bformat(_("Could not save the document\n%1$s."), file);
882 Alert::error(_("Could not save document"), text);
885 writeFileAscii(ofs, linelen);
889 void Buffer::writeFileAscii(ostream & os, int linelen)
891 ParagraphList::iterator beg = paragraphs.begin();
892 ParagraphList::iterator end = paragraphs.end();
893 ParagraphList::iterator it = beg;
894 for (; it != end; ++it) {
895 os << asciiParagraph(*it, linelen, it == beg);
902 void Buffer::makeLaTeXFile(string const & fname,
903 string const & original_path,
904 LatexRunParams const & runparams,
905 bool only_body, bool only_preamble)
907 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
909 ofstream ofs(fname.c_str());
911 string const file = MakeDisplayPath(fname, 50);
912 string text = bformat(_("Could not open the specified document\n%1$s."),
914 Alert::error(_("Could not open file"), text);
918 makeLaTeXFile(ofs, original_path,
919 runparams, only_body, only_preamble);
923 lyxerr << "File was not closed properly." << endl;
928 void Buffer::makeLaTeXFile(ostream & os,
929 string const & original_path,
930 LatexRunParams const & runparams_in,
931 bool only_body, bool only_preamble)
933 LatexRunParams runparams = runparams_in;
934 niceFile = runparams.nice; // this will be used by Insetincludes.
936 // validate the buffer.
937 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
938 LaTeXFeatures features(params);
940 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
943 // The starting paragraph of the coming rows is the
944 // first paragraph of the document. (Asger)
945 texrow.start(paragraphs.begin()->id(), 0);
947 if (!only_body && runparams.nice) {
948 os << "%% " << lyx_docversion << " created this file. "
949 "For more info, see http://www.lyx.org/.\n"
950 "%% Do not edit unless you really know what "
955 lyxerr[Debug::INFO] << "lyx header finished" << endl;
956 // There are a few differences between nice LaTeX and usual files:
957 // usual is \batchmode and has a
958 // special input@path to allow the including of figures
959 // with either \input or \includegraphics (what figinsets do).
960 // input@path is set when the actual parameter
961 // original_path is set. This is done for usual tex-file, but not
962 // for nice-latex-file. (Matthias 250696)
964 if (!runparams.nice) {
965 // code for usual, NOT nice-latex-file
966 os << "\\batchmode\n"; // changed
970 if (!original_path.empty()) {
971 string inputpath = os::external_path(original_path);
972 subst(inputpath, "~", "\\string~");
973 os << "\\makeatletter\n"
974 << "\\def\\input@path{{"
975 << inputpath << "/}}\n"
976 << "\\makeatother\n";
982 // Write the preamble
983 runparams.use_babel = params.writeLaTeX(os, features, texrow);
989 os << "\\begin{document}\n";
992 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
994 if (!lyxrc.language_auto_begin) {
995 os << subst(lyxrc.language_command_begin, "$$lang",
996 params.language->babel())
1001 latexParagraphs(this, paragraphs, os, texrow, runparams);
1003 // add this just in case after all the paragraphs
1007 if (!lyxrc.language_auto_end) {
1008 os << subst(lyxrc.language_command_end, "$$lang",
1009 params.language->babel())
1015 os << "\\end{document}\n";
1018 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1020 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1024 // Just to be sure. (Asger)
1027 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1028 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1031 // we want this to be true outside previews (for insetexternal)
1036 bool Buffer::isLatex() const
1038 return params.getLyXTextClass().outputType() == LATEX;
1042 bool Buffer::isLinuxDoc() const
1044 return params.getLyXTextClass().outputType() == LINUXDOC;
1048 bool Buffer::isLiterate() const
1050 return params.getLyXTextClass().outputType() == LITERATE;
1054 bool Buffer::isDocBook() const
1056 return params.getLyXTextClass().outputType() == DOCBOOK;
1060 bool Buffer::isSGML() const
1062 LyXTextClass const & tclass = params.getLyXTextClass();
1064 return tclass.outputType() == LINUXDOC ||
1065 tclass.outputType() == DOCBOOK;
1069 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1071 ofstream ofs(fname.c_str());
1074 string const file = MakeDisplayPath(fname, 50);
1075 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1077 Alert::error(_("Could not save document"), text);
1081 niceFile = nice; // this will be used by included files.
1083 LaTeXFeatures features(params);
1089 LyXTextClass const & tclass = params.getLyXTextClass();
1091 string top_element = tclass.latexname();
1094 ofs << "<!doctype linuxdoc system";
1096 string preamble = params.preamble;
1097 string const name = nice ? ChangeExtension(filename_, ".sgml")
1099 preamble += features.getIncludedFiles(name);
1100 preamble += features.getLyXSGMLEntities();
1102 if (!preamble.empty()) {
1103 ofs << " [ " << preamble << " ]";
1107 if (params.options.empty())
1108 sgml::openTag(ofs, 0, false, top_element);
1110 string top = top_element;
1112 top += params.options;
1113 sgml::openTag(ofs, 0, false, top);
1117 ofs << "<!-- " << lyx_docversion
1118 << " created this file. For more info see http://www.lyx.org/"
1121 Paragraph::depth_type depth = 0; // paragraph depth
1123 vector<string> environment_stack(5);
1125 ParagraphList::iterator pit = paragraphs.begin();
1126 ParagraphList::iterator pend = paragraphs.end();
1127 for (; pit != pend; ++pit) {
1128 LyXLayout_ptr const & style = pit->layout();
1129 // treat <toc> as a special case for compatibility with old code
1130 if (pit->isInset(0)) {
1131 Inset * inset = pit->getInset(0);
1132 Inset::Code lyx_code = inset->lyxCode();
1133 if (lyx_code == Inset::TOC_CODE) {
1134 string const temp = "toc";
1135 sgml::openTag(ofs, depth, false, temp);
1140 // environment tag closing
1141 for (; depth > pit->params().depth(); --depth) {
1142 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1143 environment_stack[depth].erase();
1146 // write opening SGML tags
1147 switch (style->latextype) {
1148 case LATEX_PARAGRAPH:
1149 if (depth == pit->params().depth()
1150 && !environment_stack[depth].empty()) {
1151 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1152 environment_stack[depth].erase();
1158 sgml::openTag(ofs, depth, false, style->latexname());
1163 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1165 if (!environment_stack[depth].empty()) {
1166 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1170 environment_stack[depth].erase();
1171 sgml::openTag(ofs, depth, false, style->latexname());
1174 case LATEX_ENVIRONMENT:
1175 case LATEX_ITEM_ENVIRONMENT:
1176 case LATEX_BIB_ENVIRONMENT:
1178 string const & latexname = style->latexname();
1180 if (depth == pit->params().depth()
1181 && environment_stack[depth] != latexname) {
1182 sgml::closeTag(ofs, depth, false,
1183 environment_stack[depth]);
1184 environment_stack[depth].erase();
1186 if (depth < pit->params().depth()) {
1187 depth = pit->params().depth();
1188 environment_stack[depth].erase();
1190 if (environment_stack[depth] != latexname) {
1192 sgml::openTag(ofs, depth, false, "p");
1194 sgml::openTag(ofs, depth, false, latexname);
1196 if (environment_stack.size() == depth + 1)
1197 environment_stack.push_back("!-- --");
1198 environment_stack[depth] = latexname;
1201 if (style->latexparam() == "CDATA")
1204 if (style->latextype == LATEX_ENVIRONMENT) break;
1206 if (style->labeltype == LABEL_MANUAL)
1211 sgml::openTag(ofs, depth + 1, false, item_name);
1216 sgml::openTag(ofs, depth, false, style->latexname());
1220 simpleLinuxDocOnePar(ofs, pit, depth);
1223 // write closing SGML tags
1224 switch (style->latextype) {
1227 case LATEX_ENVIRONMENT:
1228 case LATEX_ITEM_ENVIRONMENT:
1229 case LATEX_BIB_ENVIRONMENT:
1230 if (style->latexparam() == "CDATA")
1234 sgml::closeTag(ofs, depth, false, style->latexname());
1240 for (int i = depth; i >= 0; --i)
1241 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1245 sgml::closeTag(ofs, 0, false, top_element);
1249 // How to check for successful close
1251 // we want this to be true outside previews (for insetexternal)
1256 // checks, if newcol chars should be put into this line
1257 // writes newline, if necessary.
1260 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1261 string::size_type newcol)
1264 if (colcount > lyxrc.ascii_linelen) {
1266 colcount = newcol; // assume write after this call
1281 string tag_name(PAR_TAG const & pt) {
1283 case NONE: return "!-- --";
1284 case TT: return "tt";
1285 case SF: return "sf";
1286 case BF: return "bf";
1287 case IT: return "it";
1288 case SL: return "sl";
1289 case EM: return "em";
1296 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1298 p1 = static_cast<PAR_TAG>(p1 | p2);
1303 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1305 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1311 // Handle internal paragraph parsing -- layout already processed.
1312 void Buffer::simpleLinuxDocOnePar(ostream & os,
1313 ParagraphList::iterator par,
1314 Paragraph::depth_type /*depth*/) const
1316 LyXLayout_ptr const & style = par->layout();
1318 string::size_type char_line_count = 5; // Heuristic choice ;-)
1320 // gets paragraph main font
1323 if (style->labeltype == LABEL_MANUAL) {
1324 font_old = style->labelfont;
1327 font_old = style->font;
1331 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1332 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1333 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1336 stack<PAR_TAG> tag_state;
1337 // parsing main loop
1338 for (pos_type i = 0; i < par->size(); ++i) {
1340 PAR_TAG tag_close = NONE;
1341 list < PAR_TAG > tag_open;
1343 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1345 if (font_old.family() != font.family()) {
1346 switch (family_type) {
1347 case LyXFont::SANS_FAMILY:
1350 case LyXFont::TYPEWRITER_FAMILY:
1357 family_type = font.family();
1359 switch (family_type) {
1360 case LyXFont::SANS_FAMILY:
1361 tag_open.push_back(SF);
1363 case LyXFont::TYPEWRITER_FAMILY:
1364 tag_open.push_back(TT);
1371 if (font_old.series() != font.series()) {
1372 switch (series_type) {
1373 case LyXFont::BOLD_SERIES:
1380 series_type = font.series();
1382 switch (series_type) {
1383 case LyXFont::BOLD_SERIES:
1384 tag_open.push_back(BF);
1392 if (font_old.shape() != font.shape()) {
1393 switch (shape_type) {
1394 case LyXFont::ITALIC_SHAPE:
1397 case LyXFont::SLANTED_SHAPE:
1404 shape_type = font.shape();
1406 switch (shape_type) {
1407 case LyXFont::ITALIC_SHAPE:
1408 tag_open.push_back(IT);
1410 case LyXFont::SLANTED_SHAPE:
1411 tag_open.push_back(SL);
1418 if (font_old.emph() != font.emph()) {
1419 if (font.emph() == LyXFont::ON) {
1420 tag_open.push_back(EM);
1429 list < PAR_TAG > temp;
1430 while (!tag_state.empty() && tag_close) {
1431 PAR_TAG k = tag_state.top();
1433 os << "</" << tag_name(k) << '>';
1440 for(list< PAR_TAG >::const_iterator j = temp.begin();
1441 j != temp.end(); ++j) {
1443 os << '<' << tag_name(*j) << '>';
1446 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1447 j != tag_open.end(); ++j) {
1449 os << '<' << tag_name(*j) << '>';
1452 char c = par->getChar(i);
1454 if (c == Paragraph::META_INSET) {
1455 Inset * inset = par->getInset(i);
1456 inset->linuxdoc(this, os);
1461 if (style->latexparam() == "CDATA") {
1462 // "TeX"-Mode on == > SGML-Mode on.
1469 boost::tie(ws, str) = sgml::escapeChar(c);
1470 if (ws && !par->isFreeSpacing()) {
1471 // in freespacing mode, spaces are
1472 // non-breaking characters
1473 if (desc_on) {// if char is ' ' then...
1476 sgmlLineBreak(os, char_line_count, 6);
1480 sgmlLineBreak(os, char_line_count, 1);
1485 char_line_count += str.length();
1491 while (!tag_state.empty()) {
1492 os << "</" << tag_name(tag_state.top()) << '>';
1496 // resets description flag correctly
1498 // <tag> not closed...
1499 sgmlLineBreak(os, char_line_count, 6);
1505 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1507 ofstream ofs(fname.c_str());
1509 string const file = MakeDisplayPath(fname, 50);
1510 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1512 Alert::error(_("Could not save document"), text);
1516 niceFile = nice; // this will be used by Insetincludes.
1518 LaTeXFeatures features(params);
1523 LyXTextClass const & tclass = params.getLyXTextClass();
1524 string top_element = tclass.latexname();
1527 ofs << "<!DOCTYPE " << top_element
1528 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1530 string preamble = params.preamble;
1531 string const name = nice ? ChangeExtension(filename_, ".sgml")
1533 preamble += features.getIncludedFiles(name);
1534 preamble += features.getLyXSGMLEntities();
1536 if (!preamble.empty()) {
1537 ofs << "\n [ " << preamble << " ]";
1542 string top = top_element;
1544 top += params.language->code();
1547 if (!params.options.empty()) {
1549 top += params.options;
1551 sgml::openTag(ofs, 0, false, top);
1553 ofs << "<!-- DocBook file was created by " << lyx_docversion
1554 << "\n See http://www.lyx.org/ for more information -->\n";
1556 vector<string> environment_stack(10);
1557 vector<string> environment_inner(10);
1558 vector<string> command_stack(10);
1560 bool command_flag = false;
1561 Paragraph::depth_type command_depth = 0;
1562 Paragraph::depth_type command_base = 0;
1563 Paragraph::depth_type cmd_depth = 0;
1564 Paragraph::depth_type depth = 0; // paragraph depth
1567 string command_name;
1569 ParagraphList::iterator par = paragraphs.begin();
1570 ParagraphList::iterator pend = paragraphs.end();
1572 for (; par != pend; ++par) {
1576 int desc_on = 0; // description mode
1578 LyXLayout_ptr const & style = par->layout();
1580 // environment tag closing
1581 for (; depth > par->params().depth(); --depth) {
1582 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1583 item_name = "listitem";
1584 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1585 if (environment_inner[depth] == "varlistentry")
1586 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1588 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1589 environment_stack[depth].erase();
1590 environment_inner[depth].erase();
1593 if (depth == par->params().depth()
1594 && environment_stack[depth] != style->latexname()
1595 && !environment_stack[depth].empty()) {
1596 if (environment_inner[depth] != "!-- --") {
1597 item_name= "listitem";
1598 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1599 if (environment_inner[depth] == "varlistentry")
1600 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1603 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1605 environment_stack[depth].erase();
1606 environment_inner[depth].erase();
1609 // Write opening SGML tags.
1610 switch (style->latextype) {
1611 case LATEX_PARAGRAPH:
1612 sgml::openTag(ofs, depth + command_depth,
1613 false, style->latexname());
1618 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1620 command_name = style->latexname();
1622 sgmlparam = style->latexparam();
1623 c_params = split(sgmlparam, c_depth,'|');
1625 cmd_depth = atoi(c_depth);
1628 if (cmd_depth < command_base) {
1629 for (Paragraph::depth_type j = command_depth;
1630 j >= command_base; --j) {
1631 sgml::closeTag(ofs, j, false, command_stack[j]);
1634 command_depth = command_base = cmd_depth;
1635 } else if (cmd_depth <= command_depth) {
1636 for (int j = command_depth;
1637 j >= int(cmd_depth); --j) {
1638 sgml::closeTag(ofs, j, false, command_stack[j]);
1641 command_depth = cmd_depth;
1643 command_depth = cmd_depth;
1645 command_depth = command_base = cmd_depth;
1646 command_flag = true;
1648 if (command_stack.size() == command_depth + 1)
1649 command_stack.push_back(string());
1650 command_stack[command_depth] = command_name;
1652 // treat label as a special case for
1653 // more WYSIWYM handling.
1654 // This is a hack while paragraphs can't have
1655 // attributes, like id in this case.
1656 if (par->isInset(0)) {
1657 Inset * inset = par->getInset(0);
1658 Inset::Code lyx_code = inset->lyxCode();
1659 if (lyx_code == Inset::LABEL_CODE) {
1660 command_name += " id=\"";
1661 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1662 command_name += '"';
1667 sgml::openTag(ofs, depth + command_depth, false, command_name);
1669 item_name = c_params.empty() ? "title" : c_params;
1670 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1673 case LATEX_ENVIRONMENT:
1674 case LATEX_ITEM_ENVIRONMENT:
1675 if (depth < par->params().depth()) {
1676 depth = par->params().depth();
1677 environment_stack[depth].erase();
1680 if (environment_stack[depth] != style->latexname()) {
1681 if (environment_stack.size() == depth + 1) {
1682 environment_stack.push_back("!-- --");
1683 environment_inner.push_back("!-- --");
1685 environment_stack[depth] = style->latexname();
1686 environment_inner[depth] = "!-- --";
1687 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1689 if (environment_inner[depth] != "!-- --") {
1690 item_name= "listitem";
1691 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1692 if (environment_inner[depth] == "varlistentry")
1693 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1697 if (style->latextype == LATEX_ENVIRONMENT) {
1698 if (!style->latexparam().empty()) {
1699 if (style->latexparam() == "CDATA")
1702 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1707 desc_on = (style->labeltype == LABEL_MANUAL);
1709 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1710 sgml::openTag(ofs, depth + 1 + command_depth,
1711 false, environment_inner[depth]);
1713 item_name = desc_on ? "term" : "para";
1714 sgml::openTag(ofs, depth + 1 + command_depth,
1718 sgml::openTag(ofs, depth + command_depth,
1719 false, style->latexname());
1723 simpleDocBookOnePar(ofs, par, desc_on,
1724 depth + 1 + command_depth);
1727 // write closing SGML tags
1728 switch (style->latextype) {
1730 end_tag = c_params.empty() ? "title" : c_params;
1731 sgml::closeTag(ofs, depth + command_depth,
1734 case LATEX_ENVIRONMENT:
1735 if (!style->latexparam().empty()) {
1736 if (style->latexparam() == "CDATA")
1739 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1742 case LATEX_ITEM_ENVIRONMENT:
1743 if (desc_on == 1) break;
1745 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1747 case LATEX_PARAGRAPH:
1748 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1751 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1757 for (int d = depth; d >= 0; --d) {
1758 if (!environment_stack[depth].empty()) {
1759 if (environment_inner[depth] != "!-- --") {
1760 item_name = "listitem";
1761 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1762 if (environment_inner[depth] == "varlistentry")
1763 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1766 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1770 for (int j = command_depth; j >= 0 ; --j)
1771 if (!command_stack[j].empty()) {
1772 sgml::closeTag(ofs, j, false, command_stack[j]);
1777 sgml::closeTag(ofs, 0, false, top_element);
1780 // How to check for successful close
1782 // we want this to be true outside previews (for insetexternal)
1787 void Buffer::simpleDocBookOnePar(ostream & os,
1788 ParagraphList::iterator par, int & desc_on,
1789 Paragraph::depth_type depth) const
1791 bool emph_flag = false;
1793 LyXLayout_ptr const & style = par->layout();
1795 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1797 int char_line_count = depth;
1798 //if (!style.free_spacing)
1799 // os << string(depth,' ');
1801 // parsing main loop
1802 for (pos_type i = 0; i < par->size(); ++i) {
1803 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1805 // handle <emphasis> tag
1806 if (font_old.emph() != font.emph()) {
1807 if (font.emph() == LyXFont::ON) {
1808 if (style->latexparam() == "CDATA")
1811 if (style->latexparam() == "CDATA")
1815 if (style->latexparam() == "CDATA")
1817 os << "</emphasis>";
1818 if (style->latexparam() == "CDATA")
1825 if (par->isInset(i)) {
1826 Inset * inset = par->getInset(i);
1827 // don't print the inset in position 0 if desc_on == 3 (label)
1828 if (i || desc_on != 3) {
1829 if (style->latexparam() == "CDATA")
1831 inset->docbook(this, os, false);
1832 if (style->latexparam() == "CDATA")
1836 char c = par->getChar(i);
1839 boost::tie(ws, str) = sgml::escapeChar(c);
1841 if (style->pass_thru) {
1843 } else if (par->isFreeSpacing() || c != ' ') {
1845 } else if (desc_on == 1) {
1847 os << "\n</term><listitem><para>";
1857 if (style->latexparam() == "CDATA")
1859 os << "</emphasis>";
1860 if (style->latexparam() == "CDATA")
1864 // resets description flag correctly
1866 // <term> not closed...
1867 os << "</term>\n<listitem><para> </para>";
1869 if (style->free_spacing)
1874 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1875 // Other flags: -wall -v0 -x
1876 int Buffer::runChktex()
1880 // get LaTeX-Filename
1881 string const name = getLatexName();
1882 string path = filePath();
1884 string const org_path = path;
1885 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1889 Path p(path); // path to LaTeX file
1890 message(_("Running chktex..."));
1892 // Generate the LaTeX file if neccessary
1893 LatexRunParams runparams;
1894 runparams.flavor = LatexRunParams::LATEX;
1895 runparams.nice = false;
1896 makeLaTeXFile(name, org_path, runparams);
1899 Chktex chktex(lyxrc.chktex_command, name, filePath());
1900 int res = chktex.run(terr); // run chktex
1903 Alert::error(_("chktex failure"),
1904 _("Could not run chktex successfully."));
1905 } else if (res > 0) {
1906 // Insert all errors as errors boxes
1907 bufferErrors(*this, terr);
1916 void Buffer::validate(LaTeXFeatures & features) const
1918 LyXTextClass const & tclass = params.getLyXTextClass();
1920 if (params.tracking_changes) {
1921 features.require("dvipost");
1922 features.require("color");
1925 // AMS Style is at document level
1926 if (params.use_amsmath == BufferParams::AMS_ON
1927 || tclass.provides(LyXTextClass::amsmath))
1928 features.require("amsmath");
1930 for_each(paragraphs.begin(), paragraphs.end(),
1931 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1933 // the bullet shapes are buffer level not paragraph level
1934 // so they are tested here
1935 for (int i = 0; i < 4; ++i) {
1936 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1937 int const font = params.user_defined_bullets[i].getFont();
1939 int const c = params
1940 .user_defined_bullets[i]
1947 features.require("latexsym");
1949 } else if (font == 1) {
1950 features.require("amssymb");
1951 } else if ((font >= 2 && font <= 5)) {
1952 features.require("pifont");
1957 if (lyxerr.debugging(Debug::LATEX)) {
1958 features.showStruct();
1963 void Buffer::getLabelList(std::vector<string> & list) const
1965 /// if this is a child document and the parent is already loaded
1966 /// Use the parent's list instead [ale990407]
1967 if (!params.parentname.empty()
1968 && bufferlist.exists(params.parentname)) {
1969 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1971 tmp->getLabelList(list);
1976 for (inset_iterator it = inset_const_iterator_begin();
1977 it != inset_const_iterator_end(); ++it) {
1978 it->getLabelList(list);
1983 // This is also a buffer property (ale)
1984 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1986 /// if this is a child document and the parent is already loaded
1987 /// use the parent's list instead [ale990412]
1988 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1989 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1991 tmp->fillWithBibKeys(keys);
1996 for (inset_iterator it = inset_const_iterator_begin();
1997 it != inset_const_iterator_end(); ++it) {
1998 if (it->lyxCode() == Inset::BIBTEX_CODE)
1999 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2000 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2001 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2002 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2003 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2004 string const key = bib.getContents();
2005 string const opt = bib.getOptions();
2006 string const ref; // = pit->asString(this, false);
2007 string const info = opt + "TheBibliographyRef" + ref;
2008 keys.push_back(pair<string, string>(key, info));
2014 bool Buffer::isDepClean(string const & name) const
2016 DepClean::const_iterator it = dep_clean_.find(name);
2017 if (it == dep_clean_.end())
2023 void Buffer::markDepClean(string const & name)
2025 dep_clean_[name] = true;
2029 bool Buffer::dispatch(string const & command, bool * result)
2031 // Split command string into command and argument
2033 string line = ltrim(command);
2034 string const arg = trim(split(line, cmd, ' '));
2036 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2040 bool Buffer::dispatch(int action, string const & argument, bool * result)
2042 bool dispatched = true;
2046 bool const tmp = Exporter::Export(this, argument, false);
2059 void Buffer::changeLanguage(Language const * from, Language const * to)
2061 lyxerr << "Changing Language!" << endl;
2063 // Take care of l10n/i18n
2066 ParIterator end = par_iterator_end();
2067 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2068 it->changeLanguage(params, from, to);
2072 void Buffer::updateDocLang(Language const * nlang)
2074 messages_.reset(new Messages(nlang->code()));
2078 bool Buffer::isMultiLingual()
2080 ParIterator end = par_iterator_end();
2081 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2082 if (it->isMultiLingual(params))
2089 void Buffer::inset_iterator::setParagraph()
2091 while (pit != pend) {
2092 it = pit->insetlist.begin();
2093 if (it != pit->insetlist.end())
2100 Inset * Buffer::getInsetFromID(int id_arg) const
2102 for (inset_iterator it = inset_const_iterator_begin();
2103 it != inset_const_iterator_end(); ++it)
2105 if (it->id() == id_arg)
2107 Inset * in = it->getInsetFromID(id_arg);
2115 ParIterator Buffer::getParFromID(int id) const
2117 #warning FIXME: const correctness! (Andre)
2118 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2119 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2121 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2123 // John says this is called with id == -1 from undo
2124 lyxerr << "getParFromID(), id: " << id << endl;
2128 for (; it != end; ++it)
2136 bool Buffer::hasParWithID(int id) const
2138 ParConstIterator it = par_iterator_begin();
2139 ParConstIterator end = par_iterator_end();
2142 // John says this is called with id == -1 from undo
2143 lyxerr << "hasParWithID(), id: " << id << endl;
2147 for (; it != end; ++it)
2155 ParIterator Buffer::par_iterator_begin()
2157 return ParIterator(paragraphs.begin(), paragraphs);
2161 ParIterator Buffer::par_iterator_end()
2163 return ParIterator(paragraphs.end(), paragraphs);
2166 ParConstIterator Buffer::par_iterator_begin() const
2168 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2172 ParConstIterator Buffer::par_iterator_end() const
2174 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2178 Language const * Buffer::getLanguage() const
2180 return params.language;
2184 string const Buffer::B_(string const & l10n) const
2186 if (messages_.get()) {
2187 return messages_->get(l10n);
2194 bool Buffer::isClean() const
2200 bool Buffer::isBakClean() const
2206 void Buffer::markClean() const
2212 // if the .lyx file has been saved, we don't need an
2218 void Buffer::markBakClean()
2224 void Buffer::setUnnamed(bool flag)
2230 bool Buffer::isUnnamed()
2236 void Buffer::markDirty()
2244 DepClean::iterator it = dep_clean_.begin();
2245 DepClean::const_iterator const end = dep_clean_.end();
2247 for (; it != end; ++it) {
2253 string const & Buffer::fileName() const
2259 string const & Buffer::filePath() const
2265 bool Buffer::isReadonly() const
2271 void Buffer::setParentName(string const & name)
2273 params.parentname = name;
2277 Buffer::inset_iterator::inset_iterator()
2282 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2289 Buffer::inset_iterator Buffer::inset_iterator_begin()
2291 return inset_iterator(paragraphs.begin(), paragraphs.end());
2295 Buffer::inset_iterator Buffer::inset_iterator_end()
2297 return inset_iterator(paragraphs.end(), paragraphs.end());
2301 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2303 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2304 const_cast<ParagraphList&>(paragraphs).end());
2308 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2310 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2311 const_cast<ParagraphList&>(paragraphs).end());
2315 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2319 if (it == pit->insetlist.end()) {
2328 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2330 inset_iterator tmp = *this;
2336 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2342 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2348 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2354 lyx::pos_type Buffer::inset_iterator::getPos() const
2360 bool operator==(Buffer::inset_iterator const & iter1,
2361 Buffer::inset_iterator const & iter2)
2363 return iter1.pit == iter2.pit
2364 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2368 bool operator!=(Buffer::inset_iterator const & iter1,
2369 Buffer::inset_iterator const & iter2)
2371 return !(iter1 == iter2);