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"
23 #include "LaTeXFeatures.h"
29 #include "ParagraphParameters.h"
30 #include "iterators.h"
32 #include "paragraph_funcs.h"
37 #include "insets/insetbibitem.h"
38 #include "insets/insetbibtex.h"
39 #include "insets/insetinclude.h"
40 #include "insets/insettext.h"
42 #include "frontends/Alert.h"
44 #include "graphics/Previews.h"
46 #include "support/LAssert.h"
47 #include "support/textutils.h"
48 #include "support/filetools.h"
49 #include "support/path.h"
50 #include "support/os.h"
51 #include "support/tostr.h"
52 #include "support/lyxlib.h"
53 #include "support/FileInfo.h"
54 #include "support/gzstream.h"
56 #include <boost/bind.hpp>
57 #include <boost/tuple/tuple.hpp>
67 using namespace lyx::support;
69 #ifndef CXX_GLOBAL_CSTD
89 using lyx::textclass_type;
91 // all these externs should eventually be removed.
92 extern BufferList bufferlist;
96 const int LYX_FORMAT = 225;
98 bool openFileWrite(ofstream & ofs, string const & fname)
100 ofs.open(fname.c_str());
102 string const file = MakeDisplayPath(fname, 50);
103 string text = bformat(_("Could not open the specified "
104 "document\n%1$s."), file);
105 Alert::error(_("Could not open file"), text);
114 Buffer::Buffer(string const & file, bool ronly)
115 : niceFile(true), lyx_clean(true), bak_clean(true),
116 unnamed(false), read_only(ronly),
119 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
120 filepath_ = OnlyPath(file);
122 if (read_only || lyxrc.use_tempdir) {
123 tmppath = CreateBufferTmpDir();
128 // set initial author
129 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
135 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
136 // here the buffer should take care that it is
137 // saved properly, before it goes into the void.
141 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
142 Alert::warning(_("Could not remove temporary directory"),
143 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
148 // Remove any previewed LaTeX snippets associated with this buffer.
149 lyx::graphics::Previews::get().removeLoader(*this);
153 string const Buffer::getLatexName(bool no_path) const
155 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
156 return no_path ? OnlyFilename(name) : name;
160 pair<Buffer::LogType, string> const Buffer::getLogName() const
162 string const filename = getLatexName(false);
164 if (filename.empty())
165 return make_pair(Buffer::latexlog, string());
167 string path = OnlyPath(filename);
169 if (lyxrc.use_tempdir || !IsDirWriteable(path))
172 string const fname = AddName(path,
173 OnlyFilename(ChangeExtension(filename,
176 AddName(path, OnlyFilename(
177 ChangeExtension(filename,
178 formats.extension("literate") + ".out")));
180 // If no Latex log or Build log is newer, show Build log
182 FileInfo const f_fi(fname);
183 FileInfo const b_fi(bname);
186 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
187 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
188 return make_pair(Buffer::buildlog, bname);
190 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
191 return make_pair(Buffer::latexlog, fname);
195 void Buffer::setReadonly(bool flag)
197 if (read_only != flag) {
204 AuthorList & Buffer::authors()
206 return params.authorlist;
210 void Buffer::setFileName(string const & newfile)
212 filename_ = MakeAbsPath(newfile);
213 filepath_ = OnlyPath(filename_);
214 setReadonly(IsFileWriteable(filename_) == 0);
219 // We'll remove this later. (Lgb)
222 void unknownClass(string const & unknown)
224 Alert::warning(_("Unknown document class"),
225 bformat(_("Using the default document class, because the "
226 "class %1$s is unknown."), unknown));
231 int Buffer::readHeader(LyXLex & lex)
233 int unknown_tokens = 0;
237 string const token = lex.getString();
242 if (token == "\\end_header")
245 lyxerr[Debug::PARSER] << "Handling header token: `"
246 << token << '\'' << endl;
249 string unknown = params.readToken(lex, token);
250 if (!unknown.empty()) {
251 if (unknown[0] != '\\') {
252 unknownClass(unknown);
255 string const s = bformat(_("Unknown token: "
259 error(ErrorItem(_("Header error"), s,
264 return unknown_tokens;
268 // candidate for move to BufferView
269 // (at least some parts in the beginning of the func)
272 // changed to be public and have one parameter
273 // if par = 0 normal behavior
274 // else insert behavior
275 // Returns false if "\end_document" is not read (Asger)
276 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
278 Paragraph::depth_type depth = 0;
279 bool the_end_read = false;
281 if (paragraphs.empty()) {
283 if (!params.getLyXTextClass().load()) {
284 string theclass = params.getLyXTextClass().name();
285 Alert::error(_("Can't load document class"), bformat(
286 "Using the default document class, because the "
287 " class %1$s could not be loaded.", theclass));
288 params.textclass = 0;
291 // We don't want to adopt the parameters from the
292 // document we insert, so read them into a temporary buffer
293 // and then discard it
295 Buffer tmpbuf("", false);
296 tmpbuf.readHeader(lex);
301 string const token = lex.getString();
306 lyxerr[Debug::PARSER] << "Handling token: `"
307 << token << '\'' << endl;
309 if (token == "\\end_document") {
314 readParagraph(lex, token, paragraphs, pit, depth);
321 int Buffer::readParagraph(LyXLex & lex, string const & token,
322 ParagraphList & pars, ParagraphList::iterator & pit,
323 Paragraph::depth_type & depth)
325 static Change current_change;
328 if (token == "\\begin_layout") {
329 lex.pushToken(token);
332 par.params().depth(depth);
333 if (params.tracking_changes)
335 LyXFont f(LyXFont::ALL_INHERIT, params.language);
339 if (pit != pars.end())
342 pit = pars.insert(pit, par);
344 // FIXME: goddamn InsetTabular makes us pass a Buffer
346 ::readParagraph(*this, *pit, lex);
348 } else if (token == "\\begin_deeper") {
350 } else if (token == "\\end_deeper") {
352 lex.printError("\\end_deeper: " "depth is already null");
363 // needed to insert the selection
364 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
365 LyXFont const & fn,string const & str)
367 LyXLayout_ptr const & layout = par->layout();
371 par->checkInsertChar(font);
372 // insert the string, don't insert doublespace
373 bool space_inserted = true;
374 bool autobreakrows = !par->inInset() ||
375 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
376 for(string::const_iterator cit = str.begin();
377 cit != str.end(); ++cit) {
379 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
380 breakParagraph(params, paragraphs, par, pos,
381 layout->isEnvironment());
384 space_inserted = true;
388 // do not insert consecutive spaces if !free_spacing
389 } else if ((*cit == ' ' || *cit == '\t') &&
390 space_inserted && !par->isFreeSpacing()) {
392 } else if (*cit == '\t') {
393 if (!par->isFreeSpacing()) {
394 // tabs are like spaces here
395 par->insertChar(pos, ' ', font);
397 space_inserted = true;
399 const pos_type nb = 8 - pos % 8;
400 for (pos_type a = 0; a < nb ; ++a) {
401 par->insertChar(pos, ' ', font);
404 space_inserted = true;
406 } else if (!IsPrintable(*cit)) {
407 // Ignore unprintables
410 // just insert the character
411 par->insertChar(pos, *cit, font);
413 space_inserted = (*cit == ' ');
420 bool Buffer::readFile(string const & filename)
422 // Check if the file is compressed.
423 string const format = getExtFromContents(filename);
424 if (format == "gzip" || format == "zip" || format == "compress") {
425 params.compressed = true;
428 bool ret = readFile(filename, paragraphs.begin());
430 // After we have read a file, we must ensure that the buffer
431 // language is set and used in the gui.
432 // If you know of a better place to put this, please tell me. (Lgb)
433 updateDocLang(params.language);
439 bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
442 lex.setFile(filename);
444 return readFile(lex, filename, pit);
448 bool Buffer::readFile(LyXLex & lex, string const & filename,
449 ParagraphList::iterator pit)
451 Assert(!filename.empty());
454 Alert::error(_("Document could not be read"),
455 bformat(_("%1$s could not be read."), filename));
460 string const token(lex.getString());
463 Alert::error(_("Document could not be read"),
464 bformat(_("%1$s could not be read."), filename));
468 // the first token _must_ be...
469 if (token != "\\lyxformat") {
470 lyxerr << "Token: " << token << endl;
472 Alert::error(_("Document format failure"),
473 bformat(_("%1$s is not a LyX document."),
479 string tmp_format = lex.getString();
480 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
481 // if present remove ".," from string.
482 string::size_type dot = tmp_format.find_first_of(".,");
483 //lyxerr << " dot found at " << dot << endl;
484 if (dot != string::npos)
485 tmp_format.erase(dot, 1);
486 int file_format = strToInt(tmp_format);
487 //lyxerr << "format: " << file_format << endl;
489 if (file_format > LYX_FORMAT) {
490 Alert::warning(_("Document format failure"),
491 bformat(_("%1$s was created with a newer"
492 " version of LyX. This is likely to"
495 } else if (file_format < LYX_FORMAT) {
496 string const tmpfile = tempName();
497 string command = LibFileSearch("lyx2lyx", "lyx2lyx");
498 if (command.empty()) {
499 Alert::error(_("Conversion script not found"),
500 bformat(_("%1$s is from an earlier"
501 " version of LyX, but the"
502 " conversion script lyx2lyx"
503 " could not be found."),
509 + " -o " + tmpfile + ' '
510 + QuoteName(filename);
511 lyxerr[Debug::INFO] << "Running '"
514 cmd_ret const ret = RunCommand(command);
515 if (ret.first != 0) {
516 Alert::error(_("Conversion script failed"),
517 bformat(_("%1$s is from an earlier version"
518 " of LyX, but the lyx2lyx script"
519 " failed to convert it."),
523 bool ret = readFile(tmpfile, pit);
524 // Do stuff with tmpfile name and buffer name here.
530 bool the_end = readBody(lex, pit);
531 params.setPaperStuff();
534 Alert::error(_("Document format failure"),
535 bformat(_("%1$s ended unexpectedly, which means"
536 " that it is probably corrupted."),
543 // Should probably be moved to somewhere else: BufferView? LyXView?
544 bool Buffer::save() const
546 // We don't need autosaves in the immediate future. (Asger)
547 resetAutosaveTimers();
551 if (lyxrc.make_backup) {
552 s = fileName() + '~';
553 if (!lyxrc.backupdir_path.empty())
554 s = AddName(lyxrc.backupdir_path,
555 subst(os::slashify_path(s),'/','!'));
557 // Rename is the wrong way of making a backup,
558 // this is the correct way.
559 /* truss cp fil fil2:
560 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
561 stat("LyXVC.lyx", 0xEFFFF688) = 0
562 open("LyXVC.lyx", O_RDONLY) = 3
563 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
564 fstat(4, 0xEFFFF508) = 0
565 fstat(3, 0xEFFFF508) = 0
566 read(3, " # T h i s f i l e w".., 8192) = 5579
567 write(4, " # T h i s f i l e w".., 5579) = 5579
568 read(3, 0xEFFFD4A0, 8192) = 0
571 chmod("LyXVC3.lyx", 0100644) = 0
572 lseek(0, 0, SEEK_CUR) = 46440
576 // Should probably have some more error checking here.
577 // Doing it this way, also makes the inodes stay the same.
578 // This is still not a very good solution, in particular we
579 // might loose the owner of the backup.
580 FileInfo finfo(fileName());
582 mode_t fmode = finfo.getMode();
583 struct utimbuf times = {
584 finfo.getAccessTime(),
585 finfo.getModificationTime() };
587 ifstream ifs(fileName().c_str());
588 ofstream ofs(s.c_str(), ios::out|ios::trunc);
593 ::chmod(s.c_str(), fmode);
595 if (::utime(s.c_str(), ×)) {
596 lyxerr << "utime error." << endl;
599 lyxerr << "LyX was not able to make "
600 "backup copy. Beware." << endl;
605 if (writeFile(fileName())) {
607 removeAutosaveFile(fileName());
609 // Saving failed, so backup is not backup
610 if (lyxrc.make_backup) {
611 rename(s, fileName());
619 bool Buffer::writeFile(string const & fname) const
621 if (read_only && (fname == fileName())) {
625 FileInfo finfo(fname);
626 if (finfo.exist() && !finfo.writable()) {
632 if (params.compressed) {
633 gz::ogzstream ofs(fname.c_str());
638 retval = do_writeFile(ofs);
641 ofstream ofs(fname.c_str());
645 retval = do_writeFile(ofs);
652 bool Buffer::do_writeFile(ostream & ofs) const
656 // Use the standard "C" locale for file output.
657 ofs.imbue(std::locale::classic());
660 // The top of the file should not be written by params.
662 // write out a comment in the top of the file
663 ofs << "#LyX " << lyx_version
664 << " created this file. For more info see http://www.lyx.org/\n"
665 << "\\lyxformat " << LYX_FORMAT << "\n";
667 // now write out the buffer paramters.
668 params.writeFile(ofs);
670 ofs << "\\end_header\n";
672 Paragraph::depth_type depth = 0;
674 // this will write out all the paragraphs
675 // using recursive descent.
676 ParagraphList::const_iterator pit = paragraphs.begin();
677 ParagraphList::const_iterator pend = paragraphs.end();
678 for (; pit != pend; ++pit)
679 pit->write(*this, ofs, params, depth);
681 // Write marker that shows file is complete
682 ofs << "\n\\end_document" << endl;
684 // Shouldn't really be needed....
687 // how to check if close went ok?
688 // Following is an attempt... (BE 20001011)
690 // good() returns false if any error occured, including some
692 // bad() returns true if something bad happened in the buffer,
693 // which should include file system full errors.
700 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
702 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
714 pair<int, string> const addDepth(int depth, int ldepth)
718 d += (ldepth - depth) * 2;
719 return make_pair(d, string(d, ' '));
725 string const Buffer::asciiParagraph(Paragraph const & par,
726 unsigned int linelen,
727 bool noparbreak) const
729 ostringstream buffer;
731 Paragraph::depth_type ltype_depth = 0;
732 bool ref_printed = false;
733 Paragraph::depth_type depth = par.params().depth();
735 // First write the layout
736 string const & tmp = par.layout()->name();
737 if (compare_no_case(tmp, "itemize") == 0) {
739 ltype_depth = depth + 1;
740 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
742 ltype_depth = depth + 1;
743 } else if (contains(ascii_lowercase(tmp), "ection")) {
745 ltype_depth = depth + 1;
746 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
748 ltype_depth = depth + 1;
749 } else if (compare_ascii_no_case(tmp, "description") == 0) {
751 ltype_depth = depth + 1;
752 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
755 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
763 /* maybe some vertical spaces */
765 /* the labelwidthstring used in lists */
769 /* some pagebreaks? */
773 /* what about the alignment */
775 // linelen <= 0 is special and means we don't have paragraph breaks
777 string::size_type currlinelen = 0;
783 buffer << string(depth * 2, ' ');
784 currlinelen += depth * 2;
787 // we should probably change to the paragraph language in the
788 // gettext here (if possible) so that strings are outputted in
789 // the correct language! (20012712 Jug)
793 case 4: // (Sub)Paragraph
794 case 5: // Description
798 buffer << _("Abstract") << "\n\n";
801 string const abst = _("Abstract: ");
803 currlinelen += abst.length();
806 case 7: // Bibliography
809 buffer << _("References") << "\n\n";
812 string const refs = _("References: ");
814 currlinelen += refs.length();
822 string const parlab = par.params().labelString();
823 buffer << parlab << ' ';
824 currlinelen += parlab.length() + 1;
832 pair<int, string> p = addDepth(depth, ltype_depth);
834 currlinelen += p.first;
837 // this is to change the linebreak to do it by word a bit more
838 // intelligent hopefully! (only in the case where we have a
839 // max linelength!) (Jug)
843 for (pos_type i = 0; i < par.size(); ++i) {
844 char c = par.getUChar(params, i);
846 case Paragraph::META_INSET:
848 InsetOld const * inset = par.getInset(i);
852 currlinelen += word.length();
855 if (inset->ascii(*this, buffer, linelen)) {
856 // to be sure it breaks paragraph
857 currlinelen += linelen;
866 currlinelen + word.length() > linelen - 10) {
868 pair<int, string> p = addDepth(depth, ltype_depth);
870 currlinelen = p.first;
873 buffer << word << ' ';
874 currlinelen += word.length() + 1;
881 lyxerr[Debug::INFO] <<
882 "writeAsciiFile: NULL char in structure." << endl;
885 (currlinelen + word.length()) > linelen)
889 pair<int, string> p =
890 addDepth(depth, ltype_depth);
892 currlinelen = p.first;
899 return STRCONV(buffer.str());
903 void Buffer::writeFileAscii(string const & fname, int linelen)
906 if (!::openFileWrite(ofs, fname))
908 writeFileAscii(ofs, linelen);
912 void Buffer::writeFileAscii(ostream & os, int linelen)
914 ParagraphList::iterator beg = paragraphs.begin();
915 ParagraphList::iterator end = paragraphs.end();
916 ParagraphList::iterator it = beg;
917 for (; it != end; ++it) {
918 os << asciiParagraph(*it, linelen, it == beg);
924 void Buffer::makeLaTeXFile(string const & fname,
925 string const & original_path,
926 LatexRunParams const & runparams,
927 bool output_preamble, bool output_body)
929 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
932 if (!::openFileWrite(ofs, fname))
935 makeLaTeXFile(ofs, original_path,
936 runparams, output_preamble, output_body);
940 lyxerr << "File was not closed properly." << endl;
945 void Buffer::makeLaTeXFile(ostream & os,
946 string const & original_path,
947 LatexRunParams const & runparams_in,
948 bool output_preamble, bool output_body)
950 LatexRunParams runparams = runparams_in;
951 niceFile = runparams.nice; // this will be used by Insetincludes.
953 // validate the buffer.
954 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
955 LaTeXFeatures features(params);
957 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
960 // The starting paragraph of the coming rows is the
961 // first paragraph of the document. (Asger)
962 texrow.start(paragraphs.begin()->id(), 0);
964 if (output_preamble && runparams.nice) {
965 os << "%% LyX " << lyx_version << " created this file. "
966 "For more info, see http://www.lyx.org/.\n"
967 "%% Do not edit unless you really know what "
972 lyxerr[Debug::INFO] << "lyx header finished" << endl;
973 // There are a few differences between nice LaTeX and usual files:
974 // usual is \batchmode and has a
975 // special input@path to allow the including of figures
976 // with either \input or \includegraphics (what figinsets do).
977 // input@path is set when the actual parameter
978 // original_path is set. This is done for usual tex-file, but not
979 // for nice-latex-file. (Matthias 250696)
980 if (output_preamble) {
981 if (!runparams.nice) {
982 // code for usual, NOT nice-latex-file
983 os << "\\batchmode\n"; // changed
987 if (!original_path.empty()) {
988 string inputpath = os::external_path(original_path);
989 subst(inputpath, "~", "\\string~");
990 os << "\\makeatletter\n"
991 << "\\def\\input@path{{"
992 << inputpath << "/}}\n"
993 << "\\makeatother\n";
999 // Write the preamble
1000 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1006 os << "\\begin{document}\n";
1008 } // output_preamble
1009 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1011 if (!lyxrc.language_auto_begin) {
1012 os << subst(lyxrc.language_command_begin, "$$lang",
1013 params.language->babel())
1018 latexParagraphs(*this, paragraphs, os, texrow, runparams);
1020 // add this just in case after all the paragraphs
1024 if (!lyxrc.language_auto_end) {
1025 os << subst(lyxrc.language_command_end, "$$lang",
1026 params.language->babel())
1031 if (output_preamble) {
1032 os << "\\end{document}\n";
1035 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1037 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1041 // Just to be sure. (Asger)
1044 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1045 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1048 // we want this to be true outside previews (for insetexternal)
1053 bool Buffer::isLatex() const
1055 return params.getLyXTextClass().outputType() == LATEX;
1059 bool Buffer::isLinuxDoc() const
1061 return params.getLyXTextClass().outputType() == LINUXDOC;
1065 bool Buffer::isLiterate() const
1067 return params.getLyXTextClass().outputType() == LITERATE;
1071 bool Buffer::isDocBook() const
1073 return params.getLyXTextClass().outputType() == DOCBOOK;
1077 bool Buffer::isSGML() const
1079 LyXTextClass const & tclass = params.getLyXTextClass();
1081 return tclass.outputType() == LINUXDOC ||
1082 tclass.outputType() == DOCBOOK;
1086 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1089 if (!::openFileWrite(ofs, fname))
1092 niceFile = nice; // this will be used by included files.
1094 LaTeXFeatures features(params);
1100 LyXTextClass const & tclass = params.getLyXTextClass();
1102 string top_element = tclass.latexname();
1105 ofs << "<!doctype linuxdoc system";
1107 string preamble = params.preamble;
1108 string const name = nice ? ChangeExtension(filename_, ".sgml")
1110 preamble += features.getIncludedFiles(name);
1111 preamble += features.getLyXSGMLEntities();
1113 if (!preamble.empty()) {
1114 ofs << " [ " << preamble << " ]";
1118 if (params.options.empty())
1119 sgml::openTag(ofs, 0, false, top_element);
1121 string top = top_element;
1123 top += params.options;
1124 sgml::openTag(ofs, 0, false, top);
1128 ofs << "<!-- LyX " << lyx_version
1129 << " created this file. For more info see http://www.lyx.org/"
1132 Paragraph::depth_type depth = 0; // paragraph depth
1134 vector<string> environment_stack(5);
1136 ParagraphList::iterator pit = paragraphs.begin();
1137 ParagraphList::iterator pend = paragraphs.end();
1138 for (; pit != pend; ++pit) {
1139 LyXLayout_ptr const & style = pit->layout();
1140 // treat <toc> as a special case for compatibility with old code
1141 if (pit->isInset(0)) {
1142 InsetOld * inset = pit->getInset(0);
1143 InsetOld::Code lyx_code = inset->lyxCode();
1144 if (lyx_code == InsetOld::TOC_CODE) {
1145 string const temp = "toc";
1146 sgml::openTag(ofs, depth, false, temp);
1151 // environment tag closing
1152 for (; depth > pit->params().depth(); --depth) {
1153 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1154 environment_stack[depth].erase();
1157 // write opening SGML tags
1158 switch (style->latextype) {
1159 case LATEX_PARAGRAPH:
1160 if (depth == pit->params().depth()
1161 && !environment_stack[depth].empty()) {
1162 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1163 environment_stack[depth].erase();
1169 sgml::openTag(ofs, depth, false, style->latexname());
1174 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1176 if (!environment_stack[depth].empty()) {
1177 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1181 environment_stack[depth].erase();
1182 sgml::openTag(ofs, depth, false, style->latexname());
1185 case LATEX_ENVIRONMENT:
1186 case LATEX_ITEM_ENVIRONMENT:
1187 case LATEX_BIB_ENVIRONMENT:
1189 string const & latexname = style->latexname();
1191 if (depth == pit->params().depth()
1192 && environment_stack[depth] != latexname) {
1193 sgml::closeTag(ofs, depth, false,
1194 environment_stack[depth]);
1195 environment_stack[depth].erase();
1197 if (depth < pit->params().depth()) {
1198 depth = pit->params().depth();
1199 environment_stack[depth].erase();
1201 if (environment_stack[depth] != latexname) {
1203 sgml::openTag(ofs, depth, false, "p");
1205 sgml::openTag(ofs, depth, false, latexname);
1207 if (environment_stack.size() == depth + 1)
1208 environment_stack.push_back("!-- --");
1209 environment_stack[depth] = latexname;
1212 if (style->latexparam() == "CDATA")
1215 if (style->latextype == LATEX_ENVIRONMENT) break;
1217 if (style->labeltype == LABEL_MANUAL)
1222 sgml::openTag(ofs, depth + 1, false, item_name);
1227 sgml::openTag(ofs, depth, false, style->latexname());
1231 simpleLinuxDocOnePar(ofs, pit, depth);
1234 // write closing SGML tags
1235 switch (style->latextype) {
1238 case LATEX_ENVIRONMENT:
1239 case LATEX_ITEM_ENVIRONMENT:
1240 case LATEX_BIB_ENVIRONMENT:
1241 if (style->latexparam() == "CDATA")
1245 sgml::closeTag(ofs, depth, false, style->latexname());
1251 for (int i = depth; i >= 0; --i)
1252 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1256 sgml::closeTag(ofs, 0, false, top_element);
1260 // How to check for successful close
1262 // we want this to be true outside previews (for insetexternal)
1267 // checks, if newcol chars should be put into this line
1268 // writes newline, if necessary.
1271 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1272 string::size_type newcol)
1275 if (colcount > lyxrc.ascii_linelen) {
1277 colcount = newcol; // assume write after this call
1292 string tag_name(PAR_TAG const & pt) {
1294 case NONE: return "!-- --";
1295 case TT: return "tt";
1296 case SF: return "sf";
1297 case BF: return "bf";
1298 case IT: return "it";
1299 case SL: return "sl";
1300 case EM: return "em";
1307 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1309 p1 = static_cast<PAR_TAG>(p1 | p2);
1314 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1316 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1322 // Handle internal paragraph parsing -- layout already processed.
1323 void Buffer::simpleLinuxDocOnePar(ostream & os,
1324 ParagraphList::iterator par,
1325 Paragraph::depth_type /*depth*/) const
1327 LyXLayout_ptr const & style = par->layout();
1329 string::size_type char_line_count = 5; // Heuristic choice ;-)
1331 // gets paragraph main font
1334 if (style->labeltype == LABEL_MANUAL) {
1335 font_old = style->labelfont;
1338 font_old = style->font;
1342 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1343 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1344 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1347 stack<PAR_TAG> tag_state;
1348 // parsing main loop
1349 for (pos_type i = 0; i < par->size(); ++i) {
1351 PAR_TAG tag_close = NONE;
1352 list < PAR_TAG > tag_open;
1354 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1356 if (font_old.family() != font.family()) {
1357 switch (family_type) {
1358 case LyXFont::SANS_FAMILY:
1361 case LyXFont::TYPEWRITER_FAMILY:
1368 family_type = font.family();
1370 switch (family_type) {
1371 case LyXFont::SANS_FAMILY:
1372 tag_open.push_back(SF);
1374 case LyXFont::TYPEWRITER_FAMILY:
1375 tag_open.push_back(TT);
1382 if (font_old.series() != font.series()) {
1383 switch (series_type) {
1384 case LyXFont::BOLD_SERIES:
1391 series_type = font.series();
1393 switch (series_type) {
1394 case LyXFont::BOLD_SERIES:
1395 tag_open.push_back(BF);
1403 if (font_old.shape() != font.shape()) {
1404 switch (shape_type) {
1405 case LyXFont::ITALIC_SHAPE:
1408 case LyXFont::SLANTED_SHAPE:
1415 shape_type = font.shape();
1417 switch (shape_type) {
1418 case LyXFont::ITALIC_SHAPE:
1419 tag_open.push_back(IT);
1421 case LyXFont::SLANTED_SHAPE:
1422 tag_open.push_back(SL);
1429 if (font_old.emph() != font.emph()) {
1430 if (font.emph() == LyXFont::ON) {
1431 tag_open.push_back(EM);
1440 list < PAR_TAG > temp;
1441 while (!tag_state.empty() && tag_close) {
1442 PAR_TAG k = tag_state.top();
1444 os << "</" << tag_name(k) << '>';
1451 for(list< PAR_TAG >::const_iterator j = temp.begin();
1452 j != temp.end(); ++j) {
1454 os << '<' << tag_name(*j) << '>';
1457 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1458 j != tag_open.end(); ++j) {
1460 os << '<' << tag_name(*j) << '>';
1463 char c = par->getChar(i);
1465 if (c == Paragraph::META_INSET) {
1466 InsetOld * inset = par->getInset(i);
1467 inset->linuxdoc(*this, os);
1472 if (style->latexparam() == "CDATA") {
1473 // "TeX"-Mode on == > SGML-Mode on.
1480 boost::tie(ws, str) = sgml::escapeChar(c);
1481 if (ws && !par->isFreeSpacing()) {
1482 // in freespacing mode, spaces are
1483 // non-breaking characters
1484 if (desc_on) {// if char is ' ' then...
1487 sgmlLineBreak(os, char_line_count, 6);
1491 sgmlLineBreak(os, char_line_count, 1);
1496 char_line_count += str.length();
1502 while (!tag_state.empty()) {
1503 os << "</" << tag_name(tag_state.top()) << '>';
1507 // resets description flag correctly
1509 // <tag> not closed...
1510 sgmlLineBreak(os, char_line_count, 6);
1516 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1519 if (!::openFileWrite(ofs, fname))
1522 niceFile = nice; // this will be used by Insetincludes.
1524 LaTeXFeatures features(params);
1529 LyXTextClass const & tclass = params.getLyXTextClass();
1530 string top_element = tclass.latexname();
1533 ofs << "<!DOCTYPE " << top_element
1534 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1536 string preamble = params.preamble;
1537 string const name = nice ? ChangeExtension(filename_, ".sgml")
1539 preamble += features.getIncludedFiles(name);
1540 preamble += features.getLyXSGMLEntities();
1542 if (!preamble.empty()) {
1543 ofs << "\n [ " << preamble << " ]";
1548 string top = top_element;
1550 top += params.language->code();
1553 if (!params.options.empty()) {
1555 top += params.options;
1557 sgml::openTag(ofs, 0, false, top);
1559 ofs << "<!-- DocBook file was created by LyX " << lyx_version
1560 << "\n See http://www.lyx.org/ for more information -->\n";
1562 vector<string> environment_stack(10);
1563 vector<string> environment_inner(10);
1564 vector<string> command_stack(10);
1566 bool command_flag = false;
1567 Paragraph::depth_type command_depth = 0;
1568 Paragraph::depth_type command_base = 0;
1569 Paragraph::depth_type cmd_depth = 0;
1570 Paragraph::depth_type depth = 0; // paragraph depth
1573 string command_name;
1575 ParagraphList::iterator par = paragraphs.begin();
1576 ParagraphList::iterator pend = paragraphs.end();
1578 for (; par != pend; ++par) {
1582 int desc_on = 0; // description mode
1584 LyXLayout_ptr const & style = par->layout();
1586 // environment tag closing
1587 for (; depth > par->params().depth(); --depth) {
1588 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
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]);
1594 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1595 environment_stack[depth].erase();
1596 environment_inner[depth].erase();
1599 if (depth == par->params().depth()
1600 && environment_stack[depth] != style->latexname()
1601 && !environment_stack[depth].empty()) {
1602 if (environment_inner[depth] != "!-- --") {
1603 item_name= "listitem";
1604 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1605 if (environment_inner[depth] == "varlistentry")
1606 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1609 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1611 environment_stack[depth].erase();
1612 environment_inner[depth].erase();
1615 // Write opening SGML tags.
1616 switch (style->latextype) {
1617 case LATEX_PARAGRAPH:
1618 sgml::openTag(ofs, depth + command_depth,
1619 false, style->latexname());
1624 error(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1626 command_name = style->latexname();
1628 sgmlparam = style->latexparam();
1629 c_params = split(sgmlparam, c_depth,'|');
1631 cmd_depth = atoi(c_depth);
1634 if (cmd_depth < command_base) {
1635 for (Paragraph::depth_type j = command_depth;
1636 j >= command_base; --j) {
1637 sgml::closeTag(ofs, j, false, command_stack[j]);
1640 command_depth = command_base = cmd_depth;
1641 } else if (cmd_depth <= command_depth) {
1642 for (int j = command_depth;
1643 j >= int(cmd_depth); --j) {
1644 sgml::closeTag(ofs, j, false, command_stack[j]);
1647 command_depth = cmd_depth;
1649 command_depth = cmd_depth;
1651 command_depth = command_base = cmd_depth;
1652 command_flag = true;
1654 if (command_stack.size() == command_depth + 1)
1655 command_stack.push_back(string());
1656 command_stack[command_depth] = command_name;
1658 // treat label as a special case for
1659 // more WYSIWYM handling.
1660 // This is a hack while paragraphs can't have
1661 // attributes, like id in this case.
1662 if (par->isInset(0)) {
1663 InsetOld * inset = par->getInset(0);
1664 InsetOld::Code lyx_code = inset->lyxCode();
1665 if (lyx_code == InsetOld::LABEL_CODE) {
1666 command_name += " id=\"";
1667 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1668 command_name += '"';
1673 sgml::openTag(ofs, depth + command_depth, false, command_name);
1675 item_name = c_params.empty() ? "title" : c_params;
1676 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1679 case LATEX_ENVIRONMENT:
1680 case LATEX_ITEM_ENVIRONMENT:
1681 if (depth < par->params().depth()) {
1682 depth = par->params().depth();
1683 environment_stack[depth].erase();
1686 if (environment_stack[depth] != style->latexname()) {
1687 if (environment_stack.size() == depth + 1) {
1688 environment_stack.push_back("!-- --");
1689 environment_inner.push_back("!-- --");
1691 environment_stack[depth] = style->latexname();
1692 environment_inner[depth] = "!-- --";
1693 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1695 if (environment_inner[depth] != "!-- --") {
1696 item_name= "listitem";
1697 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1698 if (environment_inner[depth] == "varlistentry")
1699 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1703 if (style->latextype == LATEX_ENVIRONMENT) {
1704 if (!style->latexparam().empty()) {
1705 if (style->latexparam() == "CDATA")
1708 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1713 desc_on = (style->labeltype == LABEL_MANUAL);
1715 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1716 sgml::openTag(ofs, depth + 1 + command_depth,
1717 false, environment_inner[depth]);
1719 item_name = desc_on ? "term" : "para";
1720 sgml::openTag(ofs, depth + 1 + command_depth,
1724 sgml::openTag(ofs, depth + command_depth,
1725 false, style->latexname());
1729 simpleDocBookOnePar(ofs, par, desc_on,
1730 depth + 1 + command_depth);
1733 // write closing SGML tags
1734 switch (style->latextype) {
1736 end_tag = c_params.empty() ? "title" : c_params;
1737 sgml::closeTag(ofs, depth + command_depth,
1740 case LATEX_ENVIRONMENT:
1741 if (!style->latexparam().empty()) {
1742 if (style->latexparam() == "CDATA")
1745 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1748 case LATEX_ITEM_ENVIRONMENT:
1749 if (desc_on == 1) break;
1751 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1753 case LATEX_PARAGRAPH:
1754 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1757 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1763 for (int d = depth; d >= 0; --d) {
1764 if (!environment_stack[depth].empty()) {
1765 if (environment_inner[depth] != "!-- --") {
1766 item_name = "listitem";
1767 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1768 if (environment_inner[depth] == "varlistentry")
1769 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1772 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1776 for (int j = command_depth; j >= 0 ; --j)
1777 if (!command_stack[j].empty()) {
1778 sgml::closeTag(ofs, j, false, command_stack[j]);
1783 sgml::closeTag(ofs, 0, false, top_element);
1786 // How to check for successful close
1788 // we want this to be true outside previews (for insetexternal)
1793 void Buffer::simpleDocBookOnePar(ostream & os,
1794 ParagraphList::iterator par, int & desc_on,
1795 Paragraph::depth_type depth) const
1797 bool emph_flag = false;
1799 LyXLayout_ptr const & style = par->layout();
1801 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1803 int char_line_count = depth;
1804 //if (!style.free_spacing)
1805 // os << string(depth,' ');
1807 // parsing main loop
1808 for (pos_type i = 0; i < par->size(); ++i) {
1809 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1811 // handle <emphasis> tag
1812 if (font_old.emph() != font.emph()) {
1813 if (font.emph() == LyXFont::ON) {
1814 if (style->latexparam() == "CDATA")
1817 if (style->latexparam() == "CDATA")
1821 if (style->latexparam() == "CDATA")
1823 os << "</emphasis>";
1824 if (style->latexparam() == "CDATA")
1831 if (par->isInset(i)) {
1832 InsetOld * inset = par->getInset(i);
1833 // don't print the inset in position 0 if desc_on == 3 (label)
1834 if (i || desc_on != 3) {
1835 if (style->latexparam() == "CDATA")
1837 inset->docbook(*this, os, false);
1838 if (style->latexparam() == "CDATA")
1842 char c = par->getChar(i);
1845 boost::tie(ws, str) = sgml::escapeChar(c);
1847 if (style->pass_thru) {
1849 } else if (par->isFreeSpacing() || c != ' ') {
1851 } else if (desc_on == 1) {
1853 os << "\n</term><listitem><para>";
1863 if (style->latexparam() == "CDATA")
1865 os << "</emphasis>";
1866 if (style->latexparam() == "CDATA")
1870 // resets description flag correctly
1872 // <term> not closed...
1873 os << "</term>\n<listitem><para> </para>";
1875 if (style->free_spacing)
1880 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1881 // Other flags: -wall -v0 -x
1882 int Buffer::runChktex()
1886 // get LaTeX-Filename
1887 string const name = getLatexName();
1888 string path = filePath();
1890 string const org_path = path;
1891 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1895 Path p(path); // path to LaTeX file
1896 message(_("Running chktex..."));
1898 // Generate the LaTeX file if neccessary
1899 LatexRunParams runparams;
1900 runparams.flavor = LatexRunParams::LATEX;
1901 runparams.nice = false;
1902 makeLaTeXFile(name, org_path, runparams);
1905 Chktex chktex(lyxrc.chktex_command, name, filePath());
1906 int res = chktex.run(terr); // run chktex
1909 Alert::error(_("chktex failure"),
1910 _("Could not run chktex successfully."));
1911 } else if (res > 0) {
1912 // Insert all errors as errors boxes
1913 bufferErrors(*this, terr);
1922 void Buffer::validate(LaTeXFeatures & features) const
1924 LyXTextClass const & tclass = params.getLyXTextClass();
1926 if (params.tracking_changes) {
1927 features.require("dvipost");
1928 features.require("color");
1931 // AMS Style is at document level
1932 if (params.use_amsmath == BufferParams::AMS_ON
1933 || tclass.provides(LyXTextClass::amsmath))
1934 features.require("amsmath");
1936 for_each(paragraphs.begin(), paragraphs.end(),
1937 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1939 // the bullet shapes are buffer level not paragraph level
1940 // so they are tested here
1941 for (int i = 0; i < 4; ++i) {
1942 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1943 int const font = params.user_defined_bullets[i].getFont();
1945 int const c = params
1946 .user_defined_bullets[i]
1953 features.require("latexsym");
1955 } else if (font == 1) {
1956 features.require("amssymb");
1957 } else if ((font >= 2 && font <= 5)) {
1958 features.require("pifont");
1963 if (lyxerr.debugging(Debug::LATEX)) {
1964 features.showStruct();
1969 void Buffer::getLabelList(std::vector<string> & list) const
1971 /// if this is a child document and the parent is already loaded
1972 /// Use the parent's list instead [ale990407]
1973 if (!params.parentname.empty()
1974 && bufferlist.exists(params.parentname)) {
1975 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1977 tmp->getLabelList(list);
1982 for (inset_iterator it = inset_const_iterator_begin();
1983 it != inset_const_iterator_end(); ++it) {
1984 it->getLabelList(list);
1989 // This is also a buffer property (ale)
1990 void Buffer::fillWithBibKeys(std::vector<std::pair<string, string> > & keys) const
1992 /// if this is a child document and the parent is already loaded
1993 /// use the parent's list instead [ale990412]
1994 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
1995 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
1997 tmp->fillWithBibKeys(keys);
2002 for (inset_iterator it = inset_const_iterator_begin();
2003 it != inset_const_iterator_end(); ++it) {
2004 if (it->lyxCode() == InsetOld::BIBTEX_CODE)
2005 static_cast<InsetBibtex &>(*it).fillWithBibKeys(*this, keys);
2006 else if (it->lyxCode() == InsetOld::INCLUDE_CODE)
2007 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2008 else if (it->lyxCode() == InsetOld::BIBITEM_CODE) {
2009 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2010 string const key = bib.getContents();
2011 string const opt = bib.getOptions();
2012 string const ref; // = pit->asString(this, false);
2013 string const info = opt + "TheBibliographyRef" + ref;
2014 keys.push_back(pair<string, string>(key, info));
2020 bool Buffer::isDepClean(string const & name) const
2022 DepClean::const_iterator it = dep_clean_.find(name);
2023 if (it == dep_clean_.end())
2029 void Buffer::markDepClean(string const & name)
2031 dep_clean_[name] = true;
2035 bool Buffer::dispatch(string const & command, bool * result)
2037 // Split command string into command and argument
2039 string line = ltrim(command);
2040 string const arg = trim(split(line, cmd, ' '));
2042 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2046 bool Buffer::dispatch(int action, string const & argument, bool * result)
2048 bool dispatched = true;
2052 bool const tmp = Exporter::Export(this, argument, false);
2065 void Buffer::changeLanguage(Language const * from, Language const * to)
2067 lyxerr << "Changing Language!" << endl;
2069 // Take care of l10n/i18n
2072 ParIterator end = par_iterator_end();
2073 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2074 it->changeLanguage(params, from, to);
2078 void Buffer::updateDocLang(Language const * nlang)
2080 messages_.reset(new Messages(nlang->code()));
2084 bool Buffer::isMultiLingual()
2086 ParIterator end = par_iterator_end();
2087 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2088 if (it->isMultiLingual(params))
2095 void Buffer::inset_iterator::setParagraph()
2097 while (pit != pend) {
2098 it = pit->insetlist.begin();
2099 if (it != pit->insetlist.end())
2106 InsetOld * Buffer::getInsetFromID(int id_arg) const
2108 for (inset_iterator it = inset_const_iterator_begin();
2109 it != inset_const_iterator_end(); ++it)
2111 if (it->id() == id_arg)
2113 InsetOld * in = it->getInsetFromID(id_arg);
2121 ParIterator Buffer::getParFromID(int id) const
2123 #warning FIXME: const correctness! (Andre)
2124 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2125 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2127 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2129 // John says this is called with id == -1 from undo
2130 lyxerr << "getParFromID(), id: " << id << endl;
2134 for (; it != end; ++it)
2142 bool Buffer::hasParWithID(int id) const
2144 ParConstIterator it = par_iterator_begin();
2145 ParConstIterator end = par_iterator_end();
2148 // John says this is called with id == -1 from undo
2149 lyxerr << "hasParWithID(), id: " << id << endl;
2153 for (; it != end; ++it)
2161 ParIterator Buffer::par_iterator_begin()
2163 return ParIterator(paragraphs.begin(), paragraphs);
2167 ParIterator Buffer::par_iterator_end()
2169 return ParIterator(paragraphs.end(), paragraphs);
2173 ParConstIterator Buffer::par_iterator_begin() const
2175 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2179 ParConstIterator Buffer::par_iterator_end() const
2181 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2185 Language const * Buffer::getLanguage() const
2187 return params.language;
2191 string const Buffer::B_(string const & l10n) const
2193 if (messages_.get()) {
2194 return messages_->get(l10n);
2201 bool Buffer::isClean() const
2207 bool Buffer::isBakClean() const
2213 void Buffer::markClean() const
2219 // if the .lyx file has been saved, we don't need an
2225 void Buffer::markBakClean()
2231 void Buffer::setUnnamed(bool flag)
2237 bool Buffer::isUnnamed()
2243 void Buffer::markDirty()
2251 DepClean::iterator it = dep_clean_.begin();
2252 DepClean::const_iterator const end = dep_clean_.end();
2254 for (; it != end; ++it) {
2260 string const & Buffer::fileName() const
2266 string const & Buffer::filePath() const
2272 bool Buffer::isReadonly() const
2278 void Buffer::setParentName(string const & name)
2280 params.parentname = name;
2284 Buffer::inset_iterator::inset_iterator()
2289 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2296 Buffer::inset_iterator Buffer::inset_iterator_begin()
2298 return inset_iterator(paragraphs.begin(), paragraphs.end());
2302 Buffer::inset_iterator Buffer::inset_iterator_end()
2304 return inset_iterator(paragraphs.end(), paragraphs.end());
2308 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2310 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2311 const_cast<ParagraphList&>(paragraphs).end());
2315 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2317 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2318 const_cast<ParagraphList&>(paragraphs).end());
2322 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2326 if (it == pit->insetlist.end()) {
2335 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2337 inset_iterator tmp = *this;
2343 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2349 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2355 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2361 lyx::pos_type Buffer::inset_iterator::getPos() const
2367 bool operator==(Buffer::inset_iterator const & iter1,
2368 Buffer::inset_iterator const & iter2)
2370 return iter1.pit == iter2.pit
2371 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2375 bool operator!=(Buffer::inset_iterator const & iter1,
2376 Buffer::inset_iterator const & iter2)
2378 return !(iter1 == iter2);