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;
119 bool openFileWrite(ofstream & ofs, string const & fname)
121 ofs.open(fname.c_str());
123 string const file = MakeDisplayPath(fname, 50);
124 string text = bformat(_("Could not open the specified "
125 "document\n%1$s."), file);
126 Alert::error(_("Could not open file"), text);
135 Buffer::Buffer(string const & file, bool ronly)
136 : niceFile(true), lyx_clean(true), bak_clean(true),
137 unnamed(false), read_only(ronly),
140 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
141 filepath_ = OnlyPath(file);
143 if (read_only || lyxrc.use_tempdir) {
144 tmppath = CreateBufferTmpDir();
149 // set initial author
150 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
156 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
157 // here the buffer should take care that it is
158 // saved properly, before it goes into the void.
162 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
163 Alert::warning(_("Could not remove temporary directory"),
164 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
169 // Remove any previewed LaTeX snippets assocoated with this buffer.
170 lyx::graphics::Previews::get().removeLoader(this);
174 string const Buffer::getLatexName(bool no_path) const
176 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
177 return no_path ? OnlyFilename(name) : name;
181 pair<Buffer::LogType, string> const Buffer::getLogName() const
183 string const filename = getLatexName(false);
185 if (filename.empty())
186 return make_pair(Buffer::latexlog, string());
188 string path = OnlyPath(filename);
190 if (lyxrc.use_tempdir || !IsDirWriteable(path))
193 string const fname = AddName(path,
194 OnlyFilename(ChangeExtension(filename,
197 AddName(path, OnlyFilename(
198 ChangeExtension(filename,
199 formats.extension("literate") + ".out")));
201 // If no Latex log or Build log is newer, show Build log
203 FileInfo const f_fi(fname);
204 FileInfo const b_fi(bname);
207 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
208 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
209 return make_pair(Buffer::buildlog, bname);
211 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
212 return make_pair(Buffer::latexlog, fname);
216 void Buffer::setReadonly(bool flag)
218 if (read_only != flag) {
225 AuthorList & Buffer::authors()
227 return params.authorlist;
231 void Buffer::setFileName(string const & newfile)
233 filename_ = MakeAbsPath(newfile);
234 filepath_ = OnlyPath(filename_);
235 setReadonly(IsFileWriteable(filename_) == 0);
240 // We'll remove this later. (Lgb)
243 void unknownClass(string const & unknown)
245 Alert::warning(_("Unknown document class"),
246 bformat(_("Using the default document class, because the "
247 " class %1$s is unknown."), unknown));
252 int Buffer::readHeader(LyXLex & lex)
254 int unknown_tokens = 0;
258 string const token = lex.getString();
263 if (token == "\\end_header")
266 lyxerr[Debug::PARSER] << "Handling header token: `"
267 << token << '\'' << endl;
270 string unknown = params.readToken(lex, token);
271 if (!unknown.empty()) {
272 if (unknown[0] != '\\') {
273 unknownClass(unknown);
276 string const s = bformat(_("Unknown token: "
280 error(ErrorItem(_("Header error"), s,
285 return unknown_tokens;
289 // candidate for move to BufferView
290 // (at least some parts in the beginning of the func)
293 // changed to be public and have one parameter
294 // if par = 0 normal behavior
295 // else insert behavior
296 // Returns false if "\the_end" is not read (Asger)
297 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
299 Paragraph::depth_type depth = 0;
300 bool the_end_read = false;
302 if (paragraphs.empty()) {
304 if (!params.getLyXTextClass().load()) {
305 string theclass = params.getLyXTextClass().name();
306 Alert::error(_("Can't load document class"), bformat(
307 "Using the default document class, because the "
308 " class %1$s could not be loaded.", theclass));
309 params.textclass = 0;
312 // We don't want to adopt the parameters from the
313 // document we insert, so read them into a temporary buffer
314 // and then discard it
316 Buffer tmpbuf("", false);
317 tmpbuf.readHeader(lex);
322 string const token = lex.getString();
327 lyxerr[Debug::PARSER] << "Handling token: `"
328 << token << '\'' << endl;
330 if (token == "\\the_end") {
335 readParagraph(lex, token, paragraphs, pit, depth);
342 int Buffer::readParagraph(LyXLex & lex, string const & token,
343 ParagraphList & pars, ParagraphList::iterator & pit,
344 Paragraph::depth_type & depth)
346 static Change current_change;
349 if (token == "\\layout") {
350 lex.pushToken(token);
353 par.params().depth(depth);
354 if (params.tracking_changes)
356 LyXFont f(LyXFont::ALL_INHERIT, params.language);
360 if (pit != pars.end())
363 pit = pars.insert(pit, par);
365 // FIXME: goddamn InsetTabular makes us pass a Buffer
367 ::readParagraph(*this, *pit, lex);
369 } else if (token == "\\begin_deeper") {
371 } else if (token == "\\end_deeper") {
373 lex.printError("\\end_deeper: " "depth is already null");
384 // needed to insert the selection
385 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
386 LyXFont const & fn,string const & str)
388 LyXLayout_ptr const & layout = par->layout();
392 par->checkInsertChar(font);
393 // insert the string, don't insert doublespace
394 bool space_inserted = true;
395 bool autobreakrows = !par->inInset() ||
396 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
397 for(string::const_iterator cit = str.begin();
398 cit != str.end(); ++cit) {
400 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
401 breakParagraph(params, paragraphs, par, pos,
402 layout->isEnvironment());
405 space_inserted = true;
409 // do not insert consecutive spaces if !free_spacing
410 } else if ((*cit == ' ' || *cit == '\t') &&
411 space_inserted && !par->isFreeSpacing()) {
413 } else if (*cit == '\t') {
414 if (!par->isFreeSpacing()) {
415 // tabs are like spaces here
416 par->insertChar(pos, ' ', font);
418 space_inserted = true;
420 const pos_type nb = 8 - pos % 8;
421 for (pos_type a = 0; a < nb ; ++a) {
422 par->insertChar(pos, ' ', font);
425 space_inserted = true;
427 } else if (!IsPrintable(*cit)) {
428 // Ignore unprintables
431 // just insert the character
432 par->insertChar(pos, *cit, font);
434 space_inserted = (*cit == ' ');
441 bool Buffer::readFile(LyXLex & lex, string const & filename)
443 bool ret = readFile(lex, filename, paragraphs.begin());
445 // After we have read a file, we must ensure that the buffer
446 // language is set and used in the gui.
447 // If you know of a better place to put this, please tell me. (Lgb)
448 updateDocLang(params.language);
454 // FIXME: all the below Alerts should give the filename..
455 bool Buffer::readFile(LyXLex & lex, string const & filename,
456 ParagraphList::iterator pit)
459 Alert::error(_("Document could not be read"),
460 _("The specified document could not be read."));
465 string const token(lex.getString());
468 Alert::error(_("Document could not be read"),
469 _("The specified document could not be read."));
473 // the first token _must_ be...
474 if (token != "\\lyxformat") {
475 Alert::error(_("Document format failure"),
476 _("The specified document is not a LyX document."));
481 string tmp_format = lex.getString();
482 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
483 // if present remove ".," from string.
484 string::size_type dot = tmp_format.find_first_of(".,");
485 //lyxerr << " dot found at " << dot << endl;
486 if (dot != string::npos)
487 tmp_format.erase(dot, 1);
488 file_format = strToInt(tmp_format);
489 //lyxerr << "format: " << file_format << endl;
490 if (file_format == LYX_FORMAT) {
492 } else if (file_format > LYX_FORMAT) {
493 Alert::warning(_("Document format failure"),
494 _("This document was created with a newer version of "
495 "LyX. This is likely to cause problems."));
496 } else if (file_format < LYX_FORMAT) {
498 if (file_format < 200) {
499 Alert::error(_("Document format failure"),
500 _("This LyX document is too old to be read "
501 "by this version of LyX. Try LyX 0.10."));
503 } else if (!filename.empty()) {
505 LibFileSearch("lyx2lyx", "lyx2lyx");
506 if (command.empty()) {
507 Alert::error(_("Conversion script not found"),
508 _("The document is from an earlier version "
509 "of LyX, but the conversion script lyx2lyx "
510 "could not be found."));
514 +tostr(LYX_FORMAT) + ' '
515 + QuoteName(filename);
516 lyxerr[Debug::INFO] << "Running '"
519 cmd_ret const ret = RunCommand(command);
521 Alert::error(_("Conversion script failed"),
522 _("The document is from an earlier version "
523 "of LyX, but the lyx2lyx script failed "
527 istringstream is(STRCONV(ret.second));
529 tmplex.setStream(is);
530 return readFile(tmplex, string(), pit);
532 // This code is reached if lyx2lyx failed (for
533 // some reason) to change the file format of
539 bool the_end = readBody(lex, pit);
540 params.setPaperStuff();
543 Alert::error(_("Document format failure"),
544 _("The document ended unexpectedly, which means "
545 "that it is probably corrupted."));
551 // Should probably be moved to somewhere else: BufferView? LyXView?
552 bool Buffer::save() const
554 // We don't need autosaves in the immediate future. (Asger)
555 resetAutosaveTimers();
559 if (lyxrc.make_backup) {
560 s = fileName() + '~';
561 if (!lyxrc.backupdir_path.empty())
562 s = AddName(lyxrc.backupdir_path,
563 subst(os::slashify_path(s),'/','!'));
565 // Rename is the wrong way of making a backup,
566 // this is the correct way.
567 /* truss cp fil fil2:
568 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
569 stat("LyXVC.lyx", 0xEFFFF688) = 0
570 open("LyXVC.lyx", O_RDONLY) = 3
571 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
572 fstat(4, 0xEFFFF508) = 0
573 fstat(3, 0xEFFFF508) = 0
574 read(3, " # T h i s f i l e w".., 8192) = 5579
575 write(4, " # T h i s f i l e w".., 5579) = 5579
576 read(3, 0xEFFFD4A0, 8192) = 0
579 chmod("LyXVC3.lyx", 0100644) = 0
580 lseek(0, 0, SEEK_CUR) = 46440
584 // Should probably have some more error checking here.
585 // Doing it this way, also makes the inodes stay the same.
586 // This is still not a very good solution, in particular we
587 // might loose the owner of the backup.
588 FileInfo finfo(fileName());
590 mode_t fmode = finfo.getMode();
591 struct utimbuf times = {
592 finfo.getAccessTime(),
593 finfo.getModificationTime() };
595 ifstream ifs(fileName().c_str());
596 ofstream ofs(s.c_str(), ios::out|ios::trunc);
601 ::chmod(s.c_str(), fmode);
603 if (::utime(s.c_str(), ×)) {
604 lyxerr << "utime error." << endl;
607 lyxerr << "LyX was not able to make "
608 "backup copy. Beware." << endl;
613 if (writeFile(fileName())) {
615 removeAutosaveFile(fileName());
617 // Saving failed, so backup is not backup
618 if (lyxrc.make_backup) {
619 rename(s, fileName());
627 bool Buffer::writeFile(string const & fname) const
629 if (read_only && (fname == fileName())) {
633 FileInfo finfo(fname);
634 if (finfo.exist() && !finfo.writable()) {
638 ofstream ofs(fname.c_str());
643 // Use the standard "C" locale for file output.
644 ofs.imbue(std::locale::classic());
647 // The top of the file should not be written by params.
649 // write out a comment in the top of the file
650 ofs << '#' << lyx_docversion
651 << " created this file. For more info see http://www.lyx.org/\n"
652 << "\\lyxformat " << LYX_FORMAT << "\n";
654 // now write out the buffer paramters.
655 params.writeFile(ofs);
657 ofs << "\\end_header\n";
659 Paragraph::depth_type depth = 0;
661 // this will write out all the paragraphs
662 // using recursive descent.
663 ParagraphList::const_iterator pit = paragraphs.begin();
664 ParagraphList::const_iterator pend = paragraphs.end();
665 for (; pit != pend; ++pit)
666 pit->write(this, ofs, params, depth);
668 // Write marker that shows file is complete
669 ofs << "\n\\the_end" << endl;
673 // how to check if close went ok?
674 // Following is an attempt... (BE 20001011)
676 // good() returns false if any error occured, including some
678 // bad() returns true if something bad happened in the buffer,
679 // which should include file system full errors.
686 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
688 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
700 pair<int, string> const addDepth(int depth, int ldepth)
704 d += (ldepth - depth) * 2;
705 return make_pair(d, string(d, ' '));
711 string const Buffer::asciiParagraph(Paragraph const & par,
712 unsigned int linelen,
713 bool noparbreak) const
715 ostringstream buffer;
717 Paragraph::depth_type ltype_depth = 0;
718 bool ref_printed = false;
719 Paragraph::depth_type depth = par.params().depth();
721 // First write the layout
722 string const & tmp = par.layout()->name();
723 if (compare_no_case(tmp, "itemize") == 0) {
725 ltype_depth = depth + 1;
726 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
728 ltype_depth = depth + 1;
729 } else if (contains(ascii_lowercase(tmp), "ection")) {
731 ltype_depth = depth + 1;
732 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
734 ltype_depth = depth + 1;
735 } else if (compare_ascii_no_case(tmp, "description") == 0) {
737 ltype_depth = depth + 1;
738 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
741 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
749 /* maybe some vertical spaces */
751 /* the labelwidthstring used in lists */
755 /* some pagebreaks? */
759 /* what about the alignment */
761 // linelen <= 0 is special and means we don't have paragraph breaks
763 string::size_type currlinelen = 0;
769 buffer << string(depth * 2, ' ');
770 currlinelen += depth * 2;
773 // we should probably change to the paragraph language in the
774 // gettext here (if possible) so that strings are outputted in
775 // the correct language! (20012712 Jug)
779 case 4: // (Sub)Paragraph
780 case 5: // Description
784 buffer << _("Abstract") << "\n\n";
787 string const abst = _("Abstract: ");
789 currlinelen += abst.length();
792 case 7: // Bibliography
795 buffer << _("References") << "\n\n";
798 string const refs = _("References: ");
800 currlinelen += refs.length();
808 string const parlab = par.params().labelString();
809 buffer << parlab << ' ';
810 currlinelen += parlab.length() + 1;
818 pair<int, string> p = addDepth(depth, ltype_depth);
820 currlinelen += p.first;
823 // this is to change the linebreak to do it by word a bit more
824 // intelligent hopefully! (only in the case where we have a
825 // max linelength!) (Jug)
829 for (pos_type i = 0; i < par.size(); ++i) {
830 char c = par.getUChar(params, i);
832 case Paragraph::META_INSET:
834 InsetOld const * inset = par.getInset(i);
838 currlinelen += word.length();
841 if (inset->ascii(this, buffer, linelen)) {
842 // to be sure it breaks paragraph
843 currlinelen += linelen;
852 currlinelen + word.length() > linelen - 10) {
854 pair<int, string> p = addDepth(depth, ltype_depth);
856 currlinelen = p.first;
859 buffer << word << ' ';
860 currlinelen += word.length() + 1;
867 lyxerr[Debug::INFO] <<
868 "writeAsciiFile: NULL char in structure." << endl;
871 (currlinelen + word.length()) > linelen)
875 pair<int, string> p =
876 addDepth(depth, ltype_depth);
878 currlinelen = p.first;
885 return STRCONV(buffer.str());
889 void Buffer::writeFileAscii(string const & fname, int linelen)
892 if (!::openFileWrite(ofs, fname))
894 writeFileAscii(ofs, linelen);
898 void Buffer::writeFileAscii(ostream & os, int linelen)
900 ParagraphList::iterator beg = paragraphs.begin();
901 ParagraphList::iterator end = paragraphs.end();
902 ParagraphList::iterator it = beg;
903 for (; it != end; ++it) {
904 os << asciiParagraph(*it, linelen, it == beg);
910 void Buffer::makeLaTeXFile(string const & fname,
911 string const & original_path,
912 LatexRunParams const & runparams,
913 bool output_preamble, bool output_body)
915 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
918 if (!::openFileWrite(ofs, fname))
921 makeLaTeXFile(ofs, original_path,
922 runparams, output_preamble, output_body);
926 lyxerr << "File was not closed properly." << endl;
931 void Buffer::makeLaTeXFile(ostream & os,
932 string const & original_path,
933 LatexRunParams const & runparams_in,
934 bool output_preamble, bool output_body)
936 LatexRunParams runparams = runparams_in;
937 niceFile = runparams.nice; // this will be used by Insetincludes.
939 // validate the buffer.
940 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
941 LaTeXFeatures features(params);
943 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
946 // The starting paragraph of the coming rows is the
947 // first paragraph of the document. (Asger)
948 texrow.start(paragraphs.begin()->id(), 0);
950 if (output_preamble && runparams.nice) {
951 os << "%% " << lyx_docversion << " created this file. "
952 "For more info, see http://www.lyx.org/.\n"
953 "%% Do not edit unless you really know what "
958 lyxerr[Debug::INFO] << "lyx header finished" << endl;
959 // There are a few differences between nice LaTeX and usual files:
960 // usual is \batchmode and has a
961 // special input@path to allow the including of figures
962 // with either \input or \includegraphics (what figinsets do).
963 // input@path is set when the actual parameter
964 // original_path is set. This is done for usual tex-file, but not
965 // for nice-latex-file. (Matthias 250696)
966 if (output_preamble) {
967 if (!runparams.nice) {
968 // code for usual, NOT nice-latex-file
969 os << "\\batchmode\n"; // changed
973 if (!original_path.empty()) {
974 string inputpath = os::external_path(original_path);
975 subst(inputpath, "~", "\\string~");
976 os << "\\makeatletter\n"
977 << "\\def\\input@path{{"
978 << inputpath << "/}}\n"
979 << "\\makeatother\n";
985 // Write the preamble
986 runparams.use_babel = params.writeLaTeX(os, features, texrow);
992 os << "\\begin{document}\n";
995 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
997 if (!lyxrc.language_auto_begin) {
998 os << subst(lyxrc.language_command_begin, "$$lang",
999 params.language->babel())
1004 latexParagraphs(this, paragraphs, os, texrow, runparams);
1006 // add this just in case after all the paragraphs
1010 if (!lyxrc.language_auto_end) {
1011 os << subst(lyxrc.language_command_end, "$$lang",
1012 params.language->babel())
1017 if (output_preamble) {
1018 os << "\\end{document}\n";
1021 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1023 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1027 // Just to be sure. (Asger)
1030 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1031 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1034 // we want this to be true outside previews (for insetexternal)
1039 bool Buffer::isLatex() const
1041 return params.getLyXTextClass().outputType() == LATEX;
1045 bool Buffer::isLinuxDoc() const
1047 return params.getLyXTextClass().outputType() == LINUXDOC;
1051 bool Buffer::isLiterate() const
1053 return params.getLyXTextClass().outputType() == LITERATE;
1057 bool Buffer::isDocBook() const
1059 return params.getLyXTextClass().outputType() == DOCBOOK;
1063 bool Buffer::isSGML() const
1065 LyXTextClass const & tclass = params.getLyXTextClass();
1067 return tclass.outputType() == LINUXDOC ||
1068 tclass.outputType() == DOCBOOK;
1072 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1075 if (!::openFileWrite(ofs, fname))
1078 niceFile = nice; // this will be used by included files.
1080 LaTeXFeatures features(params);
1086 LyXTextClass const & tclass = params.getLyXTextClass();
1088 string top_element = tclass.latexname();
1091 ofs << "<!doctype linuxdoc system";
1093 string preamble = params.preamble;
1094 string const name = nice ? ChangeExtension(filename_, ".sgml")
1096 preamble += features.getIncludedFiles(name);
1097 preamble += features.getLyXSGMLEntities();
1099 if (!preamble.empty()) {
1100 ofs << " [ " << preamble << " ]";
1104 if (params.options.empty())
1105 sgml::openTag(ofs, 0, false, top_element);
1107 string top = top_element;
1109 top += params.options;
1110 sgml::openTag(ofs, 0, false, top);
1114 ofs << "<!-- " << lyx_docversion
1115 << " created this file. For more info see http://www.lyx.org/"
1118 Paragraph::depth_type depth = 0; // paragraph depth
1120 vector<string> environment_stack(5);
1122 ParagraphList::iterator pit = paragraphs.begin();
1123 ParagraphList::iterator pend = paragraphs.end();
1124 for (; pit != pend; ++pit) {
1125 LyXLayout_ptr const & style = pit->layout();
1126 // treat <toc> as a special case for compatibility with old code
1127 if (pit->isInset(0)) {
1128 InsetOld * inset = pit->getInset(0);
1129 InsetOld::Code lyx_code = inset->lyxCode();
1130 if (lyx_code == InsetOld::TOC_CODE) {
1131 string const temp = "toc";
1132 sgml::openTag(ofs, depth, false, temp);
1137 // environment tag closing
1138 for (; depth > pit->params().depth(); --depth) {
1139 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1140 environment_stack[depth].erase();
1143 // write opening SGML tags
1144 switch (style->latextype) {
1145 case LATEX_PARAGRAPH:
1146 if (depth == pit->params().depth()
1147 && !environment_stack[depth].empty()) {
1148 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1149 environment_stack[depth].erase();
1155 sgml::openTag(ofs, depth, false, style->latexname());
1160 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1162 if (!environment_stack[depth].empty()) {
1163 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1167 environment_stack[depth].erase();
1168 sgml::openTag(ofs, depth, false, style->latexname());
1171 case LATEX_ENVIRONMENT:
1172 case LATEX_ITEM_ENVIRONMENT:
1173 case LATEX_BIB_ENVIRONMENT:
1175 string const & latexname = style->latexname();
1177 if (depth == pit->params().depth()
1178 && environment_stack[depth] != latexname) {
1179 sgml::closeTag(ofs, depth, false,
1180 environment_stack[depth]);
1181 environment_stack[depth].erase();
1183 if (depth < pit->params().depth()) {
1184 depth = pit->params().depth();
1185 environment_stack[depth].erase();
1187 if (environment_stack[depth] != latexname) {
1189 sgml::openTag(ofs, depth, false, "p");
1191 sgml::openTag(ofs, depth, false, latexname);
1193 if (environment_stack.size() == depth + 1)
1194 environment_stack.push_back("!-- --");
1195 environment_stack[depth] = latexname;
1198 if (style->latexparam() == "CDATA")
1201 if (style->latextype == LATEX_ENVIRONMENT) break;
1203 if (style->labeltype == LABEL_MANUAL)
1208 sgml::openTag(ofs, depth + 1, false, item_name);
1213 sgml::openTag(ofs, depth, false, style->latexname());
1217 simpleLinuxDocOnePar(ofs, pit, depth);
1220 // write closing SGML tags
1221 switch (style->latextype) {
1224 case LATEX_ENVIRONMENT:
1225 case LATEX_ITEM_ENVIRONMENT:
1226 case LATEX_BIB_ENVIRONMENT:
1227 if (style->latexparam() == "CDATA")
1231 sgml::closeTag(ofs, depth, false, style->latexname());
1237 for (int i = depth; i >= 0; --i)
1238 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1242 sgml::closeTag(ofs, 0, false, top_element);
1246 // How to check for successful close
1248 // we want this to be true outside previews (for insetexternal)
1253 // checks, if newcol chars should be put into this line
1254 // writes newline, if necessary.
1257 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1258 string::size_type newcol)
1261 if (colcount > lyxrc.ascii_linelen) {
1263 colcount = newcol; // assume write after this call
1278 string tag_name(PAR_TAG const & pt) {
1280 case NONE: return "!-- --";
1281 case TT: return "tt";
1282 case SF: return "sf";
1283 case BF: return "bf";
1284 case IT: return "it";
1285 case SL: return "sl";
1286 case EM: return "em";
1293 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1295 p1 = static_cast<PAR_TAG>(p1 | p2);
1300 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1302 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1308 // Handle internal paragraph parsing -- layout already processed.
1309 void Buffer::simpleLinuxDocOnePar(ostream & os,
1310 ParagraphList::iterator par,
1311 Paragraph::depth_type /*depth*/) const
1313 LyXLayout_ptr const & style = par->layout();
1315 string::size_type char_line_count = 5; // Heuristic choice ;-)
1317 // gets paragraph main font
1320 if (style->labeltype == LABEL_MANUAL) {
1321 font_old = style->labelfont;
1324 font_old = style->font;
1328 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1329 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1330 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1333 stack<PAR_TAG> tag_state;
1334 // parsing main loop
1335 for (pos_type i = 0; i < par->size(); ++i) {
1337 PAR_TAG tag_close = NONE;
1338 list < PAR_TAG > tag_open;
1340 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1342 if (font_old.family() != font.family()) {
1343 switch (family_type) {
1344 case LyXFont::SANS_FAMILY:
1347 case LyXFont::TYPEWRITER_FAMILY:
1354 family_type = font.family();
1356 switch (family_type) {
1357 case LyXFont::SANS_FAMILY:
1358 tag_open.push_back(SF);
1360 case LyXFont::TYPEWRITER_FAMILY:
1361 tag_open.push_back(TT);
1368 if (font_old.series() != font.series()) {
1369 switch (series_type) {
1370 case LyXFont::BOLD_SERIES:
1377 series_type = font.series();
1379 switch (series_type) {
1380 case LyXFont::BOLD_SERIES:
1381 tag_open.push_back(BF);
1389 if (font_old.shape() != font.shape()) {
1390 switch (shape_type) {
1391 case LyXFont::ITALIC_SHAPE:
1394 case LyXFont::SLANTED_SHAPE:
1401 shape_type = font.shape();
1403 switch (shape_type) {
1404 case LyXFont::ITALIC_SHAPE:
1405 tag_open.push_back(IT);
1407 case LyXFont::SLANTED_SHAPE:
1408 tag_open.push_back(SL);
1415 if (font_old.emph() != font.emph()) {
1416 if (font.emph() == LyXFont::ON) {
1417 tag_open.push_back(EM);
1426 list < PAR_TAG > temp;
1427 while (!tag_state.empty() && tag_close) {
1428 PAR_TAG k = tag_state.top();
1430 os << "</" << tag_name(k) << '>';
1437 for(list< PAR_TAG >::const_iterator j = temp.begin();
1438 j != temp.end(); ++j) {
1440 os << '<' << tag_name(*j) << '>';
1443 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1444 j != tag_open.end(); ++j) {
1446 os << '<' << tag_name(*j) << '>';
1449 char c = par->getChar(i);
1451 if (c == Paragraph::META_INSET) {
1452 InsetOld * inset = par->getInset(i);
1453 inset->linuxdoc(this, os);
1458 if (style->latexparam() == "CDATA") {
1459 // "TeX"-Mode on == > SGML-Mode on.
1466 boost::tie(ws, str) = sgml::escapeChar(c);
1467 if (ws && !par->isFreeSpacing()) {
1468 // in freespacing mode, spaces are
1469 // non-breaking characters
1470 if (desc_on) {// if char is ' ' then...
1473 sgmlLineBreak(os, char_line_count, 6);
1477 sgmlLineBreak(os, char_line_count, 1);
1482 char_line_count += str.length();
1488 while (!tag_state.empty()) {
1489 os << "</" << tag_name(tag_state.top()) << '>';
1493 // resets description flag correctly
1495 // <tag> not closed...
1496 sgmlLineBreak(os, char_line_count, 6);
1502 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1505 if (!::openFileWrite(ofs, fname))
1508 niceFile = nice; // this will be used by Insetincludes.
1510 LaTeXFeatures features(params);
1515 LyXTextClass const & tclass = params.getLyXTextClass();
1516 string top_element = tclass.latexname();
1519 ofs << "<!DOCTYPE " << top_element
1520 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1522 string preamble = params.preamble;
1523 string const name = nice ? ChangeExtension(filename_, ".sgml")
1525 preamble += features.getIncludedFiles(name);
1526 preamble += features.getLyXSGMLEntities();
1528 if (!preamble.empty()) {
1529 ofs << "\n [ " << preamble << " ]";
1534 string top = top_element;
1536 top += params.language->code();
1539 if (!params.options.empty()) {
1541 top += params.options;
1543 sgml::openTag(ofs, 0, false, top);
1545 ofs << "<!-- DocBook file was created by " << lyx_docversion
1546 << "\n See http://www.lyx.org/ for more information -->\n";
1548 vector<string> environment_stack(10);
1549 vector<string> environment_inner(10);
1550 vector<string> command_stack(10);
1552 bool command_flag = false;
1553 Paragraph::depth_type command_depth = 0;
1554 Paragraph::depth_type command_base = 0;
1555 Paragraph::depth_type cmd_depth = 0;
1556 Paragraph::depth_type depth = 0; // paragraph depth
1559 string command_name;
1561 ParagraphList::iterator par = paragraphs.begin();
1562 ParagraphList::iterator pend = paragraphs.end();
1564 for (; par != pend; ++par) {
1568 int desc_on = 0; // description mode
1570 LyXLayout_ptr const & style = par->layout();
1572 // environment tag closing
1573 for (; depth > par->params().depth(); --depth) {
1574 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1575 item_name = "listitem";
1576 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1577 if (environment_inner[depth] == "varlistentry")
1578 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1580 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1581 environment_stack[depth].erase();
1582 environment_inner[depth].erase();
1585 if (depth == par->params().depth()
1586 && environment_stack[depth] != style->latexname()
1587 && !environment_stack[depth].empty()) {
1588 if (environment_inner[depth] != "!-- --") {
1589 item_name= "listitem";
1590 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1591 if (environment_inner[depth] == "varlistentry")
1592 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1595 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1597 environment_stack[depth].erase();
1598 environment_inner[depth].erase();
1601 // Write opening SGML tags.
1602 switch (style->latextype) {
1603 case LATEX_PARAGRAPH:
1604 sgml::openTag(ofs, depth + command_depth,
1605 false, style->latexname());
1610 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1612 command_name = style->latexname();
1614 sgmlparam = style->latexparam();
1615 c_params = split(sgmlparam, c_depth,'|');
1617 cmd_depth = atoi(c_depth);
1620 if (cmd_depth < command_base) {
1621 for (Paragraph::depth_type j = command_depth;
1622 j >= command_base; --j) {
1623 sgml::closeTag(ofs, j, false, command_stack[j]);
1626 command_depth = command_base = cmd_depth;
1627 } else if (cmd_depth <= command_depth) {
1628 for (int j = command_depth;
1629 j >= int(cmd_depth); --j) {
1630 sgml::closeTag(ofs, j, false, command_stack[j]);
1633 command_depth = cmd_depth;
1635 command_depth = cmd_depth;
1637 command_depth = command_base = cmd_depth;
1638 command_flag = true;
1640 if (command_stack.size() == command_depth + 1)
1641 command_stack.push_back(string());
1642 command_stack[command_depth] = command_name;
1644 // treat label as a special case for
1645 // more WYSIWYM handling.
1646 // This is a hack while paragraphs can't have
1647 // attributes, like id in this case.
1648 if (par->isInset(0)) {
1649 InsetOld * inset = par->getInset(0);
1650 InsetOld::Code lyx_code = inset->lyxCode();
1651 if (lyx_code == InsetOld::LABEL_CODE) {
1652 command_name += " id=\"";
1653 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1654 command_name += '"';
1659 sgml::openTag(ofs, depth + command_depth, false, command_name);
1661 item_name = c_params.empty() ? "title" : c_params;
1662 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1665 case LATEX_ENVIRONMENT:
1666 case LATEX_ITEM_ENVIRONMENT:
1667 if (depth < par->params().depth()) {
1668 depth = par->params().depth();
1669 environment_stack[depth].erase();
1672 if (environment_stack[depth] != style->latexname()) {
1673 if (environment_stack.size() == depth + 1) {
1674 environment_stack.push_back("!-- --");
1675 environment_inner.push_back("!-- --");
1677 environment_stack[depth] = style->latexname();
1678 environment_inner[depth] = "!-- --";
1679 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1681 if (environment_inner[depth] != "!-- --") {
1682 item_name= "listitem";
1683 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1684 if (environment_inner[depth] == "varlistentry")
1685 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1689 if (style->latextype == LATEX_ENVIRONMENT) {
1690 if (!style->latexparam().empty()) {
1691 if (style->latexparam() == "CDATA")
1694 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1699 desc_on = (style->labeltype == LABEL_MANUAL);
1701 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1702 sgml::openTag(ofs, depth + 1 + command_depth,
1703 false, environment_inner[depth]);
1705 item_name = desc_on ? "term" : "para";
1706 sgml::openTag(ofs, depth + 1 + command_depth,
1710 sgml::openTag(ofs, depth + command_depth,
1711 false, style->latexname());
1715 simpleDocBookOnePar(ofs, par, desc_on,
1716 depth + 1 + command_depth);
1719 // write closing SGML tags
1720 switch (style->latextype) {
1722 end_tag = c_params.empty() ? "title" : c_params;
1723 sgml::closeTag(ofs, depth + command_depth,
1726 case LATEX_ENVIRONMENT:
1727 if (!style->latexparam().empty()) {
1728 if (style->latexparam() == "CDATA")
1731 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1734 case LATEX_ITEM_ENVIRONMENT:
1735 if (desc_on == 1) break;
1737 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1739 case LATEX_PARAGRAPH:
1740 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1743 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1749 for (int d = depth; d >= 0; --d) {
1750 if (!environment_stack[depth].empty()) {
1751 if (environment_inner[depth] != "!-- --") {
1752 item_name = "listitem";
1753 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1754 if (environment_inner[depth] == "varlistentry")
1755 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1758 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1762 for (int j = command_depth; j >= 0 ; --j)
1763 if (!command_stack[j].empty()) {
1764 sgml::closeTag(ofs, j, false, command_stack[j]);
1769 sgml::closeTag(ofs, 0, false, top_element);
1772 // How to check for successful close
1774 // we want this to be true outside previews (for insetexternal)
1779 void Buffer::simpleDocBookOnePar(ostream & os,
1780 ParagraphList::iterator par, int & desc_on,
1781 Paragraph::depth_type depth) const
1783 bool emph_flag = false;
1785 LyXLayout_ptr const & style = par->layout();
1787 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1789 int char_line_count = depth;
1790 //if (!style.free_spacing)
1791 // os << string(depth,' ');
1793 // parsing main loop
1794 for (pos_type i = 0; i < par->size(); ++i) {
1795 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1797 // handle <emphasis> tag
1798 if (font_old.emph() != font.emph()) {
1799 if (font.emph() == LyXFont::ON) {
1800 if (style->latexparam() == "CDATA")
1803 if (style->latexparam() == "CDATA")
1807 if (style->latexparam() == "CDATA")
1809 os << "</emphasis>";
1810 if (style->latexparam() == "CDATA")
1817 if (par->isInset(i)) {
1818 InsetOld * inset = par->getInset(i);
1819 // don't print the inset in position 0 if desc_on == 3 (label)
1820 if (i || desc_on != 3) {
1821 if (style->latexparam() == "CDATA")
1823 inset->docbook(this, os, false);
1824 if (style->latexparam() == "CDATA")
1828 char c = par->getChar(i);
1831 boost::tie(ws, str) = sgml::escapeChar(c);
1833 if (style->pass_thru) {
1835 } else if (par->isFreeSpacing() || c != ' ') {
1837 } else if (desc_on == 1) {
1839 os << "\n</term><listitem><para>";
1849 if (style->latexparam() == "CDATA")
1851 os << "</emphasis>";
1852 if (style->latexparam() == "CDATA")
1856 // resets description flag correctly
1858 // <term> not closed...
1859 os << "</term>\n<listitem><para> </para>";
1861 if (style->free_spacing)
1866 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1867 // Other flags: -wall -v0 -x
1868 int Buffer::runChktex()
1872 // get LaTeX-Filename
1873 string const name = getLatexName();
1874 string path = filePath();
1876 string const org_path = path;
1877 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1881 Path p(path); // path to LaTeX file
1882 message(_("Running chktex..."));
1884 // Generate the LaTeX file if neccessary
1885 LatexRunParams runparams;
1886 runparams.flavor = LatexRunParams::LATEX;
1887 runparams.nice = false;
1888 makeLaTeXFile(name, org_path, runparams);
1891 Chktex chktex(lyxrc.chktex_command, name, filePath());
1892 int res = chktex.run(terr); // run chktex
1895 Alert::error(_("chktex failure"),
1896 _("Could not run chktex successfully."));
1897 } else if (res > 0) {
1898 // Insert all errors as errors boxes
1899 bufferErrors(*this, terr);
1908 void Buffer::validate(LaTeXFeatures & features) const
1910 LyXTextClass const & tclass = params.getLyXTextClass();
1912 if (params.tracking_changes) {
1913 features.require("dvipost");
1914 features.require("color");
1917 // AMS Style is at document level
1918 if (params.use_amsmath == BufferParams::AMS_ON
1919 || tclass.provides(LyXTextClass::amsmath))
1920 features.require("amsmath");
1922 for_each(paragraphs.begin(), paragraphs.end(),
1923 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1925 // the bullet shapes are buffer level not paragraph level
1926 // so they are tested here
1927 for (int i = 0; i < 4; ++i) {
1928 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1929 int const font = params.user_defined_bullets[i].getFont();
1931 int const c = params
1932 .user_defined_bullets[i]
1939 features.require("latexsym");
1941 } else if (font == 1) {
1942 features.require("amssymb");
1943 } else if ((font >= 2 && font <= 5)) {
1944 features.require("pifont");
1949 if (lyxerr.debugging(Debug::LATEX)) {
1950 features.showStruct();
1955 void Buffer::getLabelList(std::vector<string> & list) const
1957 /// if this is a child document and the parent is already loaded
1958 /// Use the parent's list instead [ale990407]
1959 if (!params.parentname.empty()
1960 && bufferlist.exists(params.parentname)) {
1961 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1963 tmp->getLabelList(list);
1968 for (inset_iterator it = inset_const_iterator_begin();
1969 it != inset_const_iterator_end(); ++it) {
1970 it->getLabelList(list);
1975 // This is also a buffer property (ale)
1976 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1978 /// if this is a child document and the parent is already loaded
1979 /// use the parent's list instead [ale990412]
1980 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1981 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1983 tmp->fillWithBibKeys(keys);
1988 for (inset_iterator it = inset_const_iterator_begin();
1989 it != inset_const_iterator_end(); ++it) {
1990 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
1991 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
1992 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
1993 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
1994 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
1995 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
1996 string const key = bib.getContents();
1997 string const opt = bib.getOptions();
1998 string const ref; // = pit->asString(this, false);
1999 string const info = opt + "TheBibliographyRef" + ref;
2000 keys.push_back(pair<string, string>(key, info));
2006 bool Buffer::isDepClean(string const & name) const
2008 DepClean::const_iterator it = dep_clean_.find(name);
2009 if (it == dep_clean_.end())
2015 void Buffer::markDepClean(string const & name)
2017 dep_clean_[name] = true;
2021 bool Buffer::dispatch(string const & command, bool * result)
2023 // Split command string into command and argument
2025 string line = ltrim(command);
2026 string const arg = trim(split(line, cmd, ' '));
2028 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2032 bool Buffer::dispatch(int action, string const & argument, bool * result)
2034 bool dispatched = true;
2038 bool const tmp = Exporter::Export(this, argument, false);
2051 void Buffer::changeLanguage(Language const * from, Language const * to)
2053 lyxerr << "Changing Language!" << endl;
2055 // Take care of l10n/i18n
2058 ParIterator end = par_iterator_end();
2059 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2060 it->changeLanguage(params, from, to);
2064 void Buffer::updateDocLang(Language const * nlang)
2066 messages_.reset(new Messages(nlang->code()));
2070 bool Buffer::isMultiLingual()
2072 ParIterator end = par_iterator_end();
2073 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2074 if (it->isMultiLingual(params))
2081 void Buffer::inset_iterator::setParagraph()
2083 while (pit != pend) {
2084 it = pit->insetlist.begin();
2085 if (it != pit->insetlist.end())
2092 InsetOld * Buffer::getInsetFromID(int id_arg) const
2094 for (inset_iterator it = inset_const_iterator_begin();
2095 it != inset_const_iterator_end(); ++it)
2097 if (it->id() == id_arg)
2099 InsetOld * in = it->getInsetFromID(id_arg);
2107 ParIterator Buffer::getParFromID(int id) const
2109 #warning FIXME: const correctness! (Andre)
2110 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2111 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2113 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2115 // John says this is called with id == -1 from undo
2116 lyxerr << "getParFromID(), id: " << id << endl;
2120 for (; it != end; ++it)
2128 bool Buffer::hasParWithID(int id) const
2130 ParConstIterator it = par_iterator_begin();
2131 ParConstIterator end = par_iterator_end();
2134 // John says this is called with id == -1 from undo
2135 lyxerr << "hasParWithID(), id: " << id << endl;
2139 for (; it != end; ++it)
2147 ParIterator Buffer::par_iterator_begin()
2149 return ParIterator(paragraphs.begin(), paragraphs);
2153 ParIterator Buffer::par_iterator_end()
2155 return ParIterator(paragraphs.end(), paragraphs);
2158 ParConstIterator Buffer::par_iterator_begin() const
2160 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2164 ParConstIterator Buffer::par_iterator_end() const
2166 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2170 Language const * Buffer::getLanguage() const
2172 return params.language;
2176 string const Buffer::B_(string const & l10n) const
2178 if (messages_.get()) {
2179 return messages_->get(l10n);
2186 bool Buffer::isClean() const
2192 bool Buffer::isBakClean() const
2198 void Buffer::markClean() const
2204 // if the .lyx file has been saved, we don't need an
2210 void Buffer::markBakClean()
2216 void Buffer::setUnnamed(bool flag)
2222 bool Buffer::isUnnamed()
2228 void Buffer::markDirty()
2236 DepClean::iterator it = dep_clean_.begin();
2237 DepClean::const_iterator const end = dep_clean_.end();
2239 for (; it != end; ++it) {
2245 string const & Buffer::fileName() const
2251 string const & Buffer::filePath() const
2257 bool Buffer::isReadonly() const
2263 void Buffer::setParentName(string const & name)
2265 params.parentname = name;
2269 Buffer::inset_iterator::inset_iterator()
2274 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2281 Buffer::inset_iterator Buffer::inset_iterator_begin()
2283 return inset_iterator(paragraphs.begin(), paragraphs.end());
2287 Buffer::inset_iterator Buffer::inset_iterator_end()
2289 return inset_iterator(paragraphs.end(), paragraphs.end());
2293 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2295 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2296 const_cast<ParagraphList&>(paragraphs).end());
2300 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2302 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2303 const_cast<ParagraphList&>(paragraphs).end());
2307 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2311 if (it == pit->insetlist.end()) {
2320 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2322 inset_iterator tmp = *this;
2328 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2334 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2340 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2346 lyx::pos_type Buffer::inset_iterator::getPos() const
2352 bool operator==(Buffer::inset_iterator const & iter1,
2353 Buffer::inset_iterator const & iter2)
2355 return iter1.pit == iter2.pit
2356 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2360 bool operator!=(Buffer::inset_iterator const & iter1,
2361 Buffer::inset_iterator const & iter2)
2363 return !(iter1 == iter2);