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 "bufferlist.h"
15 #include "LyXAction.h"
18 #include "tex-strings.h"
20 #include "bufferview_funcs.h"
26 #include "LaTeXFeatures.h"
31 #include "errorlist.h"
34 #include "BufferView.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/inseterror.h"
49 #include "insets/insetbibitem.h"
50 #include "insets/insetbibtex.h"
51 #include "insets/insetinclude.h"
52 #include "insets/insettext.h"
54 #include "frontends/Dialogs.h"
55 #include "frontends/Alert.h"
57 #include "graphics/Previews.h"
59 #include "support/textutils.h"
60 #include "support/filetools.h"
61 #include "support/path.h"
62 #include "support/os.h"
63 #include "support/tostr.h"
64 #include "support/lyxlib.h"
65 #include "support/FileInfo.h"
66 #include "support/lyxmanip.h"
67 #include "support/lyxtime.h"
69 #include <boost/bind.hpp>
70 #include <boost/tuple/tuple.hpp>
82 #include <sys/types.h>
89 #ifndef CXX_GLOBAL_CSTD
101 using std::make_pair;
109 using lyx::textclass_type;
111 // all these externs should eventually be removed.
112 extern BufferList bufferlist;
116 const int LYX_FORMAT = 224;
120 Buffer::Buffer(string const & file, bool ronly)
121 : niceFile(true), lyx_clean(true), bak_clean(true),
122 unnamed(false), read_only(ronly),
123 filename_(file), users(0)
125 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
126 filepath_ = OnlyPath(file);
128 if (read_only || lyxrc.use_tempdir) {
129 tmppath = CreateBufferTmpDir();
134 // set initial author
135 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
141 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
142 // here the buffer should take care that it is
143 // saved properly, before it goes into the void.
145 // make sure that views using this buffer
150 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
151 Alert::warning(_("Could not remove temporary directory"),
152 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
157 // Remove any previewed LaTeX snippets assocoated with this buffer.
158 grfx::Previews::get().removeLoader(this);
162 string const Buffer::getLatexName(bool no_path) const
164 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
165 return no_path ? OnlyFilename(name) : name;
169 pair<Buffer::LogType, string> const Buffer::getLogName() const
171 string const filename = getLatexName(false);
173 if (filename.empty())
174 return make_pair(Buffer::latexlog, string());
176 string path = OnlyPath(filename);
178 if (lyxrc.use_tempdir || !IsDirWriteable(path))
181 string const fname = AddName(path,
182 OnlyFilename(ChangeExtension(filename,
185 AddName(path, OnlyFilename(
186 ChangeExtension(filename,
187 formats.extension("literate") + ".out")));
189 // If no Latex log or Build log is newer, show Build log
191 FileInfo const f_fi(fname);
192 FileInfo const b_fi(bname);
195 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
196 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
197 return make_pair(Buffer::buildlog, bname);
199 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
200 return make_pair(Buffer::latexlog, fname);
204 void Buffer::setReadonly(bool flag)
206 if (read_only != flag) {
210 users->owner()->getDialogs().updateBufferDependent(false);
215 AuthorList & Buffer::authors()
217 return params.authorlist;
221 /// Update window titles of all users
222 // Should work on a list
223 void Buffer::updateTitles() const
226 users->owner()->updateWindowTitle();
230 /// Reset autosave timer of all users
231 // Should work on a list
232 void Buffer::resetAutosaveTimers() const
235 users->owner()->resetAutosaveTimer();
239 void Buffer::setFileName(string const & newfile)
241 filename_ = MakeAbsPath(newfile);
242 filepath_ = OnlyPath(filename_);
243 setReadonly(IsFileWriteable(filename_) == 0);
248 // We'll remove this later. (Lgb)
251 void unknownClass(string const & unknown)
253 Alert::warning(_("Unknown document class"),
254 bformat(_("Using the default document class, because the "
255 " class %1$s is unknown."), unknown));
260 int Buffer::readHeader(LyXLex & lex)
262 int unknown_tokens = 0;
266 string const token = lex.getString();
271 if (token == "\\end_header")
274 lyxerr[Debug::PARSER] << "Handling header token: `"
275 << token << '\'' << endl;
277 string unknown = params.readToken(lex, token);
278 if (!unknown.empty()) {
279 if (unknown[0] != '\\') {
280 unknownClass(unknown);
286 return unknown_tokens;
290 // candidate for move to BufferView
291 // (at least some parts in the beginning of the func)
294 // changed to be public and have one parameter
295 // if par = 0 normal behavior
296 // else insert behavior
297 // Returns false if "\the_end" is not read (Asger)
298 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
300 int unknown_tokens = 0;
302 Paragraph::depth_type depth = 0;
303 bool the_end_read = false;
305 if (paragraphs.empty()) {
306 unknown_tokens += readHeader(lex);
308 if (!params.getLyXTextClass().load()) {
309 string theclass = params.getLyXTextClass().name();
310 Alert::error(_("Can't load document class"), bformat(
311 "Using the default document class, because the "
312 " class %1$s could not be loaded.", theclass));
313 params.textclass = 0;
316 // We are inserting into an existing document
317 users->text->breakParagraph(paragraphs);
319 // We don't want to adopt the parameters from the
320 // document we insert, so read them into a temporary buffer
321 // and then discard it
323 Buffer tmpbuf("", false);
324 tmpbuf.readHeader(lex);
329 string const token = lex.getString();
334 lyxerr[Debug::PARSER] << "Handling token: `"
335 << token << '\'' << endl;
337 if (token == "\\the_end") {
342 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
346 if (unknown_tokens > 0) {
348 if (unknown_tokens == 1) {
349 s = bformat(_("Encountered one unknown token when reading "
350 "the document %1$s."), fileName());
352 s = bformat(_("Encountered %1$s unknown tokens when reading "
353 "the document %2$s."), tostr(unknown_tokens), fileName());
355 Alert::warning(_("Document format failure"), s);
362 int Buffer::readParagraph(LyXLex & lex, string const & token,
363 ParagraphList & pars, ParagraphList::iterator & pit,
364 Paragraph::depth_type & depth)
366 static Change current_change;
369 if (token == "\\layout") {
370 lex.pushToken(token);
373 par.params().depth(depth);
374 if (params.tracking_changes)
376 LyXFont f(LyXFont::ALL_INHERIT, params.language);
379 // FIXME: goddamn InsetTabular makes us pass a Buffer
381 unknown += ::readParagraph(*this, par, lex);
384 if (pit != pars.end())
386 pit = pars.insert(pit, par);
387 } else if (token == "\\begin_deeper") {
389 } else if (token == "\\end_deeper") {
391 lex.printError("\\end_deeper: " "depth is already null");
402 // needed to insert the selection
403 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
404 LyXFont const & fn,string const & str)
406 LyXLayout_ptr const & layout = par->layout();
410 par->checkInsertChar(font);
411 // insert the string, don't insert doublespace
412 bool space_inserted = true;
413 bool autobreakrows = !par->inInset() ||
414 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
415 for(string::const_iterator cit = str.begin();
416 cit != str.end(); ++cit) {
418 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
419 breakParagraph(params, paragraphs, par, pos,
420 layout->isEnvironment());
423 space_inserted = true;
427 // do not insert consecutive spaces if !free_spacing
428 } else if ((*cit == ' ' || *cit == '\t') &&
429 space_inserted && !par->isFreeSpacing()) {
431 } else if (*cit == '\t') {
432 if (!par->isFreeSpacing()) {
433 // tabs are like spaces here
434 par->insertChar(pos, ' ', font);
436 space_inserted = true;
438 const pos_type nb = 8 - pos % 8;
439 for (pos_type a = 0; a < nb ; ++a) {
440 par->insertChar(pos, ' ', font);
443 space_inserted = true;
445 } else if (!IsPrintable(*cit)) {
446 // Ignore unprintables
449 // just insert the character
450 par->insertChar(pos, *cit, font);
452 space_inserted = (*cit == ' ');
459 bool Buffer::readFile(LyXLex & lex, string const & filename)
461 bool ret = readFile(lex, filename, paragraphs.begin());
463 // After we have read a file, we must ensure that the buffer
464 // language is set and used in the gui.
465 // If you know of a better place to put this, please tell me. (Lgb)
466 updateDocLang(params.language);
472 // FIXME: all the below Alerts should give the filename..
473 bool Buffer::readFile(LyXLex & lex, string const & filename,
474 ParagraphList::iterator pit)
477 Alert::error(_("Document could not be read"),
478 _("The specified document could not be read."));
483 string const token(lex.getString());
486 Alert::error(_("Document could not be read"),
487 _("The specified document could not be read."));
491 // the first token _must_ be...
492 if (token != "\\lyxformat") {
493 Alert::error(_("Document format failure"),
494 _("The specified document is not a LyX document."));
499 string tmp_format = lex.getString();
500 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
501 // if present remove ".," from string.
502 string::size_type dot = tmp_format.find_first_of(".,");
503 //lyxerr << " dot found at " << dot << endl;
504 if (dot != string::npos)
505 tmp_format.erase(dot, 1);
506 file_format = strToInt(tmp_format);
507 //lyxerr << "format: " << file_format << endl;
508 if (file_format == LYX_FORMAT) {
510 } else if (file_format > LYX_FORMAT) {
511 Alert::warning(_("Document format failure"),
512 _("This document was created with a newer version of "
513 "LyX. This is likely to cause problems."));
514 } else if (file_format < LYX_FORMAT) {
516 if (file_format < 200) {
517 Alert::error(_("Document format failure"),
518 _("This LyX document is too old to be read "
519 "by this version of LyX. Try LyX 0.10."));
521 } else if (!filename.empty()) {
523 LibFileSearch("lyx2lyx", "lyx2lyx");
524 if (command.empty()) {
525 Alert::error(_("Conversion script not found"),
526 _("The document is from an earlier version "
527 "of LyX, but the conversion script lyx2lyx "
528 "could not be found."));
532 +tostr(LYX_FORMAT) + ' '
533 + QuoteName(filename);
534 lyxerr[Debug::INFO] << "Running '"
537 cmd_ret const ret = RunCommand(command);
539 Alert::error(_("Conversion script failed"),
540 _("The document is from an earlier version "
541 "of LyX, but the lyx2lyx script failed "
545 istringstream is(STRCONV(ret.second));
547 tmplex.setStream(is);
548 return readFile(tmplex, string(), pit);
550 // This code is reached if lyx2lyx failed (for
551 // some reason) to change the file format of
557 bool the_end = readBody(lex, pit);
558 params.setPaperStuff();
561 Alert::error(_("Document format failure"),
562 _("The document ended unexpectedly, which means "
563 "that it is probably corrupted."));
569 // Should probably be moved to somewhere else: BufferView? LyXView?
570 bool Buffer::save() const
572 // We don't need autosaves in the immediate future. (Asger)
573 resetAutosaveTimers();
577 if (lyxrc.make_backup) {
578 s = fileName() + '~';
579 if (!lyxrc.backupdir_path.empty())
580 s = AddName(lyxrc.backupdir_path,
581 subst(os::slashify_path(s),'/','!'));
583 // Rename is the wrong way of making a backup,
584 // this is the correct way.
585 /* truss cp fil fil2:
586 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
587 stat("LyXVC.lyx", 0xEFFFF688) = 0
588 open("LyXVC.lyx", O_RDONLY) = 3
589 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
590 fstat(4, 0xEFFFF508) = 0
591 fstat(3, 0xEFFFF508) = 0
592 read(3, " # T h i s f i l e w".., 8192) = 5579
593 write(4, " # T h i s f i l e w".., 5579) = 5579
594 read(3, 0xEFFFD4A0, 8192) = 0
597 chmod("LyXVC3.lyx", 0100644) = 0
598 lseek(0, 0, SEEK_CUR) = 46440
602 // Should probably have some more error checking here.
603 // Doing it this way, also makes the inodes stay the same.
604 // This is still not a very good solution, in particular we
605 // might loose the owner of the backup.
606 FileInfo finfo(fileName());
608 mode_t fmode = finfo.getMode();
609 struct utimbuf times = {
610 finfo.getAccessTime(),
611 finfo.getModificationTime() };
613 ifstream ifs(fileName().c_str());
614 ofstream ofs(s.c_str(), ios::out|ios::trunc);
619 ::chmod(s.c_str(), fmode);
621 if (::utime(s.c_str(), ×)) {
622 lyxerr << "utime error." << endl;
625 lyxerr << "LyX was not able to make "
626 "backup copy. Beware." << endl;
631 if (writeFile(fileName())) {
633 removeAutosaveFile(fileName());
635 // Saving failed, so backup is not backup
636 if (lyxrc.make_backup) {
637 lyx::rename(s, fileName());
645 bool Buffer::writeFile(string const & fname) const
647 if (read_only && (fname == fileName())) {
651 FileInfo finfo(fname);
652 if (finfo.exist() && !finfo.writable()) {
656 ofstream ofs(fname.c_str());
662 // Use the standard "C" locale for file output.
663 ofs.imbue(std::locale::classic());
666 // The top of the file should not be written by params.
668 // write out a comment in the top of the file
669 ofs << '#' << lyx_docversion
670 << " created this file. For more info see http://www.lyx.org/\n"
671 << "\\lyxformat " << LYX_FORMAT << "\n";
673 // now write out the buffer paramters.
674 params.writeFile(ofs);
676 ofs << "\\end_header\n";
678 Paragraph::depth_type depth = 0;
680 // this will write out all the paragraphs
681 // using recursive descent.
682 ParagraphList::const_iterator pit = paragraphs.begin();
683 ParagraphList::const_iterator pend = paragraphs.end();
684 for (; pit != pend; ++pit)
685 pit->write(this, ofs, params, depth);
687 // Write marker that shows file is complete
688 ofs << "\n\\the_end" << endl;
692 // how to check if close went ok?
693 // Following is an attempt... (BE 20001011)
695 // good() returns false if any error occured, including some
697 // bad() returns true if something bad happened in the buffer,
698 // which should include file system full errors.
705 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
707 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
719 pair<int, string> const addDepth(int depth, int ldepth)
723 d += (ldepth - depth) * 2;
724 return make_pair(d, string(d, ' '));
730 string const Buffer::asciiParagraph(Paragraph const & par,
731 unsigned int linelen,
732 bool noparbreak) const
734 ostringstream buffer;
736 Paragraph::depth_type ltype_depth = 0;
737 bool ref_printed = false;
738 Paragraph::depth_type depth = par.params().depth();
740 // First write the layout
741 string const & tmp = par.layout()->name();
742 if (compare_no_case(tmp, "itemize") == 0) {
744 ltype_depth = depth + 1;
745 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
747 ltype_depth = depth + 1;
748 } else if (contains(ascii_lowercase(tmp), "ection")) {
750 ltype_depth = depth + 1;
751 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
753 ltype_depth = depth + 1;
754 } else if (compare_ascii_no_case(tmp, "description") == 0) {
756 ltype_depth = depth + 1;
757 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
760 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
768 /* maybe some vertical spaces */
770 /* the labelwidthstring used in lists */
774 /* some pagebreaks? */
778 /* what about the alignment */
780 // linelen <= 0 is special and means we don't have paragraph breaks
782 string::size_type currlinelen = 0;
788 buffer << string(depth * 2, ' ');
789 currlinelen += depth * 2;
792 // we should probably change to the paragraph language in the
793 // gettext here (if possible) so that strings are outputted in
794 // the correct language! (20012712 Jug)
798 case 4: // (Sub)Paragraph
799 case 5: // Description
803 buffer << _("Abstract") << "\n\n";
806 string const abst = _("Abstract: ");
808 currlinelen += abst.length();
811 case 7: // Bibliography
814 buffer << _("References") << "\n\n";
817 string const refs = _("References: ");
819 currlinelen += refs.length();
827 string const parlab = par.params().labelString();
828 buffer << parlab << ' ';
829 currlinelen += parlab.length() + 1;
837 pair<int, string> p = addDepth(depth, ltype_depth);
839 currlinelen += p.first;
842 // this is to change the linebreak to do it by word a bit more
843 // intelligent hopefully! (only in the case where we have a
844 // max linelength!) (Jug)
848 for (pos_type i = 0; i < par.size(); ++i) {
849 char c = par.getUChar(params, i);
851 case Paragraph::META_INSET:
853 Inset const * inset = par.getInset(i);
857 currlinelen += word.length();
860 if (inset->ascii(this, buffer, linelen)) {
861 // to be sure it breaks paragraph
862 currlinelen += linelen;
871 currlinelen + word.length() > linelen - 10) {
873 pair<int, string> p = addDepth(depth, ltype_depth);
875 currlinelen = p.first;
878 buffer << word << ' ';
879 currlinelen += word.length() + 1;
886 lyxerr[Debug::INFO] <<
887 "writeAsciiFile: NULL char in structure." << endl;
890 (currlinelen + word.length()) > linelen)
894 pair<int, string> p =
895 addDepth(depth, ltype_depth);
897 currlinelen = p.first;
904 return STRCONV(buffer.str());
908 void Buffer::writeFileAscii(string const & fname, int linelen)
910 ofstream ofs(fname.c_str());
912 string const file = MakeDisplayPath(fname, 50);
913 string text = bformat(_("Could not save the document\n%1$s."), file);
914 Alert::error(_("Could not save document"), text);
917 writeFileAscii(ofs, linelen);
921 void Buffer::writeFileAscii(ostream & os, int linelen)
923 ParagraphList::iterator beg = paragraphs.begin();
924 ParagraphList::iterator end = paragraphs.end();
925 ParagraphList::iterator it = beg;
926 for (; it != end; ++it) {
927 os << asciiParagraph(*it, linelen, it == beg);
934 void Buffer::makeLaTeXFile(string const & fname,
935 string const & original_path,
936 LatexRunParams const & runparams,
937 bool only_body, bool only_preamble)
939 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
941 ofstream ofs(fname.c_str());
943 string const file = MakeDisplayPath(fname, 50);
944 string text = bformat(_("Could not open the specified document\n%1$s."),
946 Alert::error(_("Could not open file"), text);
950 makeLaTeXFile(ofs, original_path,
951 runparams, only_body, only_preamble);
955 lyxerr << "File was not closed properly." << endl;
960 void Buffer::makeLaTeXFile(ostream & os,
961 string const & original_path,
962 LatexRunParams const & runparams_in,
963 bool only_body, bool only_preamble)
965 LatexRunParams runparams = runparams_in;
966 niceFile = runparams.nice; // this will be used by Insetincludes.
968 // validate the buffer.
969 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
970 LaTeXFeatures features(params);
972 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
975 // The starting paragraph of the coming rows is the
976 // first paragraph of the document. (Asger)
977 texrow.start(paragraphs.begin()->id(), 0);
979 if (!only_body && runparams.nice) {
980 os << "%% " << lyx_docversion << " created this file. "
981 "For more info, see http://www.lyx.org/.\n"
982 "%% Do not edit unless you really know what "
987 lyxerr[Debug::INFO] << "lyx header finished" << endl;
988 // There are a few differences between nice LaTeX and usual files:
989 // usual is \batchmode and has a
990 // special input@path to allow the including of figures
991 // with either \input or \includegraphics (what figinsets do).
992 // input@path is set when the actual parameter
993 // original_path is set. This is done for usual tex-file, but not
994 // for nice-latex-file. (Matthias 250696)
996 if (!runparams.nice) {
997 // code for usual, NOT nice-latex-file
998 os << "\\batchmode\n"; // changed
1002 if (!original_path.empty()) {
1003 string inputpath = os::external_path(original_path);
1004 subst(inputpath, "~", "\\string~");
1005 os << "\\makeatletter\n"
1006 << "\\def\\input@path{{"
1007 << inputpath << "/}}\n"
1008 << "\\makeatother\n";
1014 // Write the preamble
1015 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1021 os << "\\begin{document}\n";
1024 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1026 if (!lyxrc.language_auto_begin) {
1027 os << subst(lyxrc.language_command_begin, "$$lang",
1028 params.language->babel())
1033 latexParagraphs(this, paragraphs, os, texrow, runparams);
1035 // add this just in case after all the paragraphs
1039 if (!lyxrc.language_auto_end) {
1040 os << subst(lyxrc.language_command_end, "$$lang",
1041 params.language->babel())
1047 os << "\\end{document}\n";
1050 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1052 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1056 // Just to be sure. (Asger)
1059 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1060 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1063 // we want this to be true outside previews (for insetexternal)
1068 bool Buffer::isLatex() const
1070 return params.getLyXTextClass().outputType() == LATEX;
1074 bool Buffer::isLinuxDoc() const
1076 return params.getLyXTextClass().outputType() == LINUXDOC;
1080 bool Buffer::isLiterate() const
1082 return params.getLyXTextClass().outputType() == LITERATE;
1086 bool Buffer::isDocBook() const
1088 return params.getLyXTextClass().outputType() == DOCBOOK;
1092 bool Buffer::isSGML() const
1094 LyXTextClass const & tclass = params.getLyXTextClass();
1096 return tclass.outputType() == LINUXDOC ||
1097 tclass.outputType() == DOCBOOK;
1101 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1103 ofstream ofs(fname.c_str());
1106 string const file = MakeDisplayPath(fname, 50);
1107 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1109 Alert::error(_("Could not save document"), text);
1113 niceFile = nice; // this will be used by included files.
1115 LaTeXFeatures features(params);
1121 LyXTextClass const & tclass = params.getLyXTextClass();
1123 string top_element = tclass.latexname();
1126 ofs << "<!doctype linuxdoc system";
1128 string preamble = params.preamble;
1129 const string name = nice ? ChangeExtension(filename_, ".sgml")
1131 preamble += features.getIncludedFiles(name);
1132 preamble += features.getLyXSGMLEntities();
1134 if (!preamble.empty()) {
1135 ofs << " [ " << preamble << " ]";
1139 if (params.options.empty())
1140 sgml::openTag(ofs, 0, false, top_element);
1142 string top = top_element;
1144 top += params.options;
1145 sgml::openTag(ofs, 0, false, top);
1149 ofs << "<!-- " << lyx_docversion
1150 << " created this file. For more info see http://www.lyx.org/"
1153 Paragraph::depth_type depth = 0; // paragraph depth
1155 vector<string> environment_stack(5);
1157 users->resetErrorList();
1159 ParagraphList::iterator pit = paragraphs.begin();
1160 ParagraphList::iterator pend = paragraphs.end();
1161 for (; pit != pend; ++pit) {
1162 LyXLayout_ptr const & style = pit->layout();
1163 // treat <toc> as a special case for compatibility with old code
1164 if (pit->isInset(0)) {
1165 Inset * inset = pit->getInset(0);
1166 Inset::Code lyx_code = inset->lyxCode();
1167 if (lyx_code == Inset::TOC_CODE) {
1168 string const temp = "toc";
1169 sgml::openTag(ofs, depth, false, temp);
1174 // environment tag closing
1175 for (; depth > pit->params().depth(); --depth) {
1176 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1177 environment_stack[depth].erase();
1180 // write opening SGML tags
1181 switch (style->latextype) {
1182 case LATEX_PARAGRAPH:
1183 if (depth == pit->params().depth()
1184 && !environment_stack[depth].empty()) {
1185 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1186 environment_stack[depth].erase();
1192 sgml::openTag(ofs, depth, false, style->latexname());
1198 _("Error: Wrong depth for LatexType Command.\n"));
1200 if (!environment_stack[depth].empty()) {
1201 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1205 environment_stack[depth].erase();
1206 sgml::openTag(ofs, depth, false, style->latexname());
1209 case LATEX_ENVIRONMENT:
1210 case LATEX_ITEM_ENVIRONMENT:
1211 case LATEX_BIB_ENVIRONMENT:
1213 string const & latexname = style->latexname();
1215 if (depth == pit->params().depth()
1216 && environment_stack[depth] != latexname) {
1217 sgml::closeTag(ofs, depth, false,
1218 environment_stack[depth]);
1219 environment_stack[depth].erase();
1221 if (depth < pit->params().depth()) {
1222 depth = pit->params().depth();
1223 environment_stack[depth].erase();
1225 if (environment_stack[depth] != latexname) {
1227 sgml::openTag(ofs, depth, false, "p");
1229 sgml::openTag(ofs, depth, false, latexname);
1231 if (environment_stack.size() == depth + 1)
1232 environment_stack.push_back("!-- --");
1233 environment_stack[depth] = latexname;
1236 if (style->latexparam() == "CDATA")
1239 if (style->latextype == LATEX_ENVIRONMENT) break;
1241 if (style->labeltype == LABEL_MANUAL)
1246 sgml::openTag(ofs, depth + 1, false, item_name);
1251 sgml::openTag(ofs, depth, false, style->latexname());
1255 simpleLinuxDocOnePar(ofs, pit, depth);
1258 // write closing SGML tags
1259 switch (style->latextype) {
1262 case LATEX_ENVIRONMENT:
1263 case LATEX_ITEM_ENVIRONMENT:
1264 case LATEX_BIB_ENVIRONMENT:
1265 if (style->latexparam() == "CDATA")
1269 sgml::closeTag(ofs, depth, false, style->latexname());
1275 for (int i = depth; i >= 0; --i)
1276 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1280 sgml::closeTag(ofs, 0, false, top_element);
1284 // How to check for successful close
1286 // we want this to be true outside previews (for insetexternal)
1289 users->showErrorList(_("LinuxDoc"));
1293 // checks, if newcol chars should be put into this line
1294 // writes newline, if necessary.
1297 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1298 string::size_type newcol)
1301 if (colcount > lyxrc.ascii_linelen) {
1303 colcount = newcol; // assume write after this call
1318 string tag_name(PAR_TAG const & pt) {
1320 case NONE: return "!-- --";
1321 case TT: return "tt";
1322 case SF: return "sf";
1323 case BF: return "bf";
1324 case IT: return "it";
1325 case SL: return "sl";
1326 case EM: return "em";
1333 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1335 p1 = static_cast<PAR_TAG>(p1 | p2);
1340 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1342 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1348 // Handle internal paragraph parsing -- layout already processed.
1349 void Buffer::simpleLinuxDocOnePar(ostream & os,
1350 ParagraphList::iterator par,
1351 Paragraph::depth_type /*depth*/) const
1353 LyXLayout_ptr const & style = par->layout();
1355 string::size_type char_line_count = 5; // Heuristic choice ;-)
1357 // gets paragraph main font
1360 if (style->labeltype == LABEL_MANUAL) {
1361 font_old = style->labelfont;
1364 font_old = style->font;
1368 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1369 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1370 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1373 stack<PAR_TAG> tag_state;
1374 // parsing main loop
1375 for (pos_type i = 0; i < par->size(); ++i) {
1377 PAR_TAG tag_close = NONE;
1378 list < PAR_TAG > tag_open;
1380 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1382 if (font_old.family() != font.family()) {
1383 switch (family_type) {
1384 case LyXFont::SANS_FAMILY:
1387 case LyXFont::TYPEWRITER_FAMILY:
1394 family_type = font.family();
1396 switch (family_type) {
1397 case LyXFont::SANS_FAMILY:
1398 tag_open.push_back(SF);
1400 case LyXFont::TYPEWRITER_FAMILY:
1401 tag_open.push_back(TT);
1408 if (font_old.series() != font.series()) {
1409 switch (series_type) {
1410 case LyXFont::BOLD_SERIES:
1417 series_type = font.series();
1419 switch (series_type) {
1420 case LyXFont::BOLD_SERIES:
1421 tag_open.push_back(BF);
1429 if (font_old.shape() != font.shape()) {
1430 switch (shape_type) {
1431 case LyXFont::ITALIC_SHAPE:
1434 case LyXFont::SLANTED_SHAPE:
1441 shape_type = font.shape();
1443 switch (shape_type) {
1444 case LyXFont::ITALIC_SHAPE:
1445 tag_open.push_back(IT);
1447 case LyXFont::SLANTED_SHAPE:
1448 tag_open.push_back(SL);
1455 if (font_old.emph() != font.emph()) {
1456 if (font.emph() == LyXFont::ON) {
1457 tag_open.push_back(EM);
1466 list < PAR_TAG > temp;
1467 while (!tag_state.empty() && tag_close) {
1468 PAR_TAG k = tag_state.top();
1470 os << "</" << tag_name(k) << '>';
1477 for(list< PAR_TAG >::const_iterator j = temp.begin();
1478 j != temp.end(); ++j) {
1480 os << '<' << tag_name(*j) << '>';
1483 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1484 j != tag_open.end(); ++j) {
1486 os << '<' << tag_name(*j) << '>';
1489 char c = par->getChar(i);
1491 if (c == Paragraph::META_INSET) {
1492 Inset * inset = par->getInset(i);
1493 inset->linuxdoc(this, os);
1498 if (style->latexparam() == "CDATA") {
1499 // "TeX"-Mode on == > SGML-Mode on.
1506 boost::tie(ws, str) = sgml::escapeChar(c);
1507 if (ws && !par->isFreeSpacing()) {
1508 // in freespacing mode, spaces are
1509 // non-breaking characters
1510 if (desc_on) {// if char is ' ' then...
1513 sgmlLineBreak(os, char_line_count, 6);
1517 sgmlLineBreak(os, char_line_count, 1);
1522 char_line_count += str.length();
1528 while (!tag_state.empty()) {
1529 os << "</" << tag_name(tag_state.top()) << '>';
1533 // resets description flag correctly
1535 // <tag> not closed...
1536 sgmlLineBreak(os, char_line_count, 6);
1542 // Print an error message.
1543 void Buffer::sgmlError(ParagraphList::iterator pit, int pos,
1544 string const & message) const
1546 users->addError(ErrorItem(message, string(), pit->id(), pos, pos));
1550 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1552 ofstream ofs(fname.c_str());
1554 string const file = MakeDisplayPath(fname, 50);
1555 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1557 Alert::error(_("Could not save document"), text);
1561 niceFile = nice; // this will be used by Insetincludes.
1563 LaTeXFeatures features(params);
1568 LyXTextClass const & tclass = params.getLyXTextClass();
1569 string top_element = tclass.latexname();
1572 ofs << "<!DOCTYPE " << top_element
1573 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1575 string preamble = params.preamble;
1576 const string name = nice ? ChangeExtension(filename_, ".sgml")
1578 preamble += features.getIncludedFiles(name);
1579 preamble += features.getLyXSGMLEntities();
1581 if (!preamble.empty()) {
1582 ofs << "\n [ " << preamble << " ]";
1587 string top = top_element;
1589 top += params.language->code();
1592 if (!params.options.empty()) {
1594 top += params.options;
1596 sgml::openTag(ofs, 0, false, top);
1598 ofs << "<!-- DocBook file was created by " << lyx_docversion
1599 << "\n See http://www.lyx.org/ for more information -->\n";
1601 vector<string> environment_stack(10);
1602 vector<string> environment_inner(10);
1603 vector<string> command_stack(10);
1605 bool command_flag = false;
1606 Paragraph::depth_type command_depth = 0;
1607 Paragraph::depth_type command_base = 0;
1608 Paragraph::depth_type cmd_depth = 0;
1609 Paragraph::depth_type depth = 0; // paragraph depth
1612 string command_name;
1614 users->resetErrorList();
1616 ParagraphList::iterator par = paragraphs.begin();
1617 ParagraphList::iterator pend = paragraphs.end();
1619 for (; par != pend; ++par) {
1623 int desc_on = 0; // description mode
1625 LyXLayout_ptr const & style = par->layout();
1627 // environment tag closing
1628 for (; depth > par->params().depth(); --depth) {
1629 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1630 item_name = "listitem";
1631 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1632 if (environment_inner[depth] == "varlistentry")
1633 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1635 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1636 environment_stack[depth].erase();
1637 environment_inner[depth].erase();
1640 if (depth == par->params().depth()
1641 && environment_stack[depth] != style->latexname()
1642 && !environment_stack[depth].empty()) {
1643 if (environment_inner[depth] != "!-- --") {
1644 item_name= "listitem";
1645 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1646 if (environment_inner[depth] == "varlistentry")
1647 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1650 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1652 environment_stack[depth].erase();
1653 environment_inner[depth].erase();
1656 // Write opening SGML tags.
1657 switch (style->latextype) {
1658 case LATEX_PARAGRAPH:
1659 sgml::openTag(ofs, depth + command_depth,
1660 false, style->latexname());
1666 _("Error: Wrong depth for LatexType Command.\n"));
1668 command_name = style->latexname();
1670 sgmlparam = style->latexparam();
1671 c_params = split(sgmlparam, c_depth,'|');
1673 cmd_depth = lyx::atoi(c_depth);
1676 if (cmd_depth < command_base) {
1677 for (Paragraph::depth_type j = command_depth;
1678 j >= command_base; --j) {
1679 sgml::closeTag(ofs, j, false, command_stack[j]);
1682 command_depth = command_base = cmd_depth;
1683 } else if (cmd_depth <= command_depth) {
1684 for (int j = command_depth;
1685 j >= int(cmd_depth); --j) {
1686 sgml::closeTag(ofs, j, false, command_stack[j]);
1689 command_depth = cmd_depth;
1691 command_depth = cmd_depth;
1693 command_depth = command_base = cmd_depth;
1694 command_flag = true;
1696 if (command_stack.size() == command_depth + 1)
1697 command_stack.push_back(string());
1698 command_stack[command_depth] = command_name;
1700 // treat label as a special case for
1701 // more WYSIWYM handling.
1702 // This is a hack while paragraphs can't have
1703 // attributes, like id in this case.
1704 if (par->isInset(0)) {
1705 Inset * inset = par->getInset(0);
1706 Inset::Code lyx_code = inset->lyxCode();
1707 if (lyx_code == Inset::LABEL_CODE) {
1708 command_name += " id=\"";
1709 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1710 command_name += '"';
1715 sgml::openTag(ofs, depth + command_depth, false, command_name);
1717 item_name = c_params.empty() ? "title" : c_params;
1718 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1721 case LATEX_ENVIRONMENT:
1722 case LATEX_ITEM_ENVIRONMENT:
1723 if (depth < par->params().depth()) {
1724 depth = par->params().depth();
1725 environment_stack[depth].erase();
1728 if (environment_stack[depth] != style->latexname()) {
1729 if (environment_stack.size() == depth + 1) {
1730 environment_stack.push_back("!-- --");
1731 environment_inner.push_back("!-- --");
1733 environment_stack[depth] = style->latexname();
1734 environment_inner[depth] = "!-- --";
1735 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1737 if (environment_inner[depth] != "!-- --") {
1738 item_name= "listitem";
1739 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1740 if (environment_inner[depth] == "varlistentry")
1741 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1745 if (style->latextype == LATEX_ENVIRONMENT) {
1746 if (!style->latexparam().empty()) {
1747 if (style->latexparam() == "CDATA")
1750 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1755 desc_on = (style->labeltype == LABEL_MANUAL);
1757 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1758 sgml::openTag(ofs, depth + 1 + command_depth,
1759 false, environment_inner[depth]);
1761 item_name = desc_on ? "term" : "para";
1762 sgml::openTag(ofs, depth + 1 + command_depth,
1766 sgml::openTag(ofs, depth + command_depth,
1767 false, style->latexname());
1771 simpleDocBookOnePar(ofs, par, desc_on,
1772 depth + 1 + command_depth);
1775 // write closing SGML tags
1776 switch (style->latextype) {
1778 end_tag = c_params.empty() ? "title" : c_params;
1779 sgml::closeTag(ofs, depth + command_depth,
1782 case LATEX_ENVIRONMENT:
1783 if (!style->latexparam().empty()) {
1784 if (style->latexparam() == "CDATA")
1787 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1790 case LATEX_ITEM_ENVIRONMENT:
1791 if (desc_on == 1) break;
1793 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1795 case LATEX_PARAGRAPH:
1796 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1799 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1805 for (int d = depth; d >= 0; --d) {
1806 if (!environment_stack[depth].empty()) {
1807 if (environment_inner[depth] != "!-- --") {
1808 item_name = "listitem";
1809 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1810 if (environment_inner[depth] == "varlistentry")
1811 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1814 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1818 for (int j = command_depth; j >= 0 ; --j)
1819 if (!command_stack[j].empty()) {
1820 sgml::closeTag(ofs, j, false, command_stack[j]);
1825 sgml::closeTag(ofs, 0, false, top_element);
1828 // How to check for successful close
1830 // we want this to be true outside previews (for insetexternal)
1832 users->showErrorList(_("DocBook"));
1836 void Buffer::simpleDocBookOnePar(ostream & os,
1837 ParagraphList::iterator par, int & desc_on,
1838 Paragraph::depth_type depth) const
1840 bool emph_flag = false;
1842 LyXLayout_ptr const & style = par->layout();
1844 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1846 int char_line_count = depth;
1847 //if (!style.free_spacing)
1848 // os << string(depth,' ');
1850 // parsing main loop
1851 for (pos_type i = 0; i < par->size(); ++i) {
1852 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1854 // handle <emphasis> tag
1855 if (font_old.emph() != font.emph()) {
1856 if (font.emph() == LyXFont::ON) {
1857 if (style->latexparam() == "CDATA")
1860 if (style->latexparam() == "CDATA")
1864 if (style->latexparam() == "CDATA")
1866 os << "</emphasis>";
1867 if (style->latexparam() == "CDATA")
1874 if (par->isInset(i)) {
1875 Inset * inset = par->getInset(i);
1876 // don't print the inset in position 0 if desc_on == 3 (label)
1877 if (i || desc_on != 3) {
1878 if (style->latexparam() == "CDATA")
1880 inset->docbook(this, os, false);
1881 if (style->latexparam() == "CDATA")
1885 char c = par->getChar(i);
1888 boost::tie(ws, str) = sgml::escapeChar(c);
1890 if (style->pass_thru) {
1892 } else if (par->isFreeSpacing() || c != ' ') {
1894 } else if (desc_on == 1) {
1896 os << "\n</term><listitem><para>";
1906 if (style->latexparam() == "CDATA")
1908 os << "</emphasis>";
1909 if (style->latexparam() == "CDATA")
1913 // resets description flag correctly
1915 // <term> not closed...
1916 os << "</term>\n<listitem><para> </para>";
1918 if (style->free_spacing)
1923 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1924 // Other flags: -wall -v0 -x
1925 int Buffer::runChktex()
1927 if (!users->text) return 0;
1929 users->owner()->busy(true);
1931 // get LaTeX-Filename
1932 string const name = getLatexName();
1933 string path = filePath();
1935 string const org_path = path;
1936 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1940 Path p(path); // path to LaTeX file
1941 users->owner()->message(_("Running chktex..."));
1943 // Generate the LaTeX file if neccessary
1944 LatexRunParams runparams;
1945 runparams.flavor = LatexRunParams::LATEX;
1946 runparams.nice = false;
1947 makeLaTeXFile(name, org_path, runparams);
1950 Chktex chktex(lyxrc.chktex_command, name, filePath());
1951 int res = chktex.run(terr); // run chktex
1954 Alert::error(_("chktex failure"),
1955 _("Could not run chktex successfully."));
1956 } else if (res > 0) {
1957 // Insert all errors as errors boxes
1958 ErrorList el (*this, terr);
1959 users->setErrorList(el);
1960 users->showErrorList(_("ChkTeX"));
1963 users->owner()->busy(false);
1969 void Buffer::validate(LaTeXFeatures & features) const
1971 LyXTextClass const & tclass = params.getLyXTextClass();
1973 if (params.tracking_changes) {
1974 features.require("dvipost");
1975 features.require("color");
1978 // AMS Style is at document level
1979 if (params.use_amsmath == BufferParams::AMS_ON
1980 || tclass.provides(LyXTextClass::amsmath))
1981 features.require("amsmath");
1983 for_each(paragraphs.begin(), paragraphs.end(),
1984 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1986 // the bullet shapes are buffer level not paragraph level
1987 // so they are tested here
1988 for (int i = 0; i < 4; ++i) {
1989 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1990 int const font = params.user_defined_bullets[i].getFont();
1992 int const c = params
1993 .user_defined_bullets[i]
2000 features.require("latexsym");
2002 } else if (font == 1) {
2003 features.require("amssymb");
2004 } else if ((font >= 2 && font <= 5)) {
2005 features.require("pifont");
2010 if (lyxerr.debugging(Debug::LATEX)) {
2011 features.showStruct();
2016 void Buffer::getLabelList(std::vector<string> & list) const
2018 /// if this is a child document and the parent is already loaded
2019 /// Use the parent's list instead [ale990407]
2020 if (!params.parentname.empty()
2021 && bufferlist.exists(params.parentname)) {
2022 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2024 tmp->getLabelList(list);
2029 for (inset_iterator it = inset_const_iterator_begin();
2030 it != inset_const_iterator_end(); ++it) {
2031 it->getLabelList(list);
2036 // This is also a buffer property (ale)
2037 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2039 /// if this is a child document and the parent is already loaded
2040 /// use the parent's list instead [ale990412]
2041 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2042 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2044 tmp->fillWithBibKeys(keys);
2049 for (inset_iterator it = inset_const_iterator_begin();
2050 it != inset_const_iterator_end(); ++it) {
2051 if (it->lyxCode() == Inset::BIBTEX_CODE)
2052 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2053 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2054 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2055 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2056 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2057 string const key = bib.getContents();
2058 string const opt = bib.getOptions();
2059 string const ref; // = pit->asString(this, false);
2060 string const info = opt + "TheBibliographyRef" + ref;
2061 keys.push_back(pair<string, string>(key, info));
2067 bool Buffer::isDepClean(string const & name) const
2069 DepClean::const_iterator it = dep_clean_.find(name);
2070 if (it == dep_clean_.end())
2076 void Buffer::markDepClean(string const & name)
2078 dep_clean_[name] = true;
2082 bool Buffer::dispatch(string const & command, bool * result)
2084 // Split command string into command and argument
2086 string line = ltrim(command);
2087 string const arg = trim(split(line, cmd, ' '));
2089 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2093 bool Buffer::dispatch(int action, string const & argument, bool * result)
2095 bool dispatched = true;
2099 bool const tmp = Exporter::Export(this, argument, false);
2112 void Buffer::resizeInsets(BufferView * bv)
2114 /// then remove all LyXText in text-insets
2115 for_each(paragraphs.begin(), paragraphs.end(),
2116 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2120 void Buffer::redraw()
2122 #warning repaint needed here, or do you mean update() ?
2128 void Buffer::changeLanguage(Language const * from, Language const * to)
2130 lyxerr << "Changing Language!" << endl;
2132 // Take care of l10n/i18n
2135 ParIterator end = par_iterator_end();
2136 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2137 it->changeLanguage(params, from, to);
2141 void Buffer::updateDocLang(Language const * nlang)
2143 messages_.reset(new Messages(nlang->code()));
2147 bool Buffer::isMultiLingual()
2149 ParIterator end = par_iterator_end();
2150 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2151 if (it->isMultiLingual(params))
2158 void Buffer::inset_iterator::setParagraph()
2160 while (pit != pend) {
2161 it = pit->insetlist.begin();
2162 if (it != pit->insetlist.end())
2169 Inset * Buffer::getInsetFromID(int id_arg) const
2171 for (inset_iterator it = inset_const_iterator_begin();
2172 it != inset_const_iterator_end(); ++it)
2174 if (it->id() == id_arg)
2176 Inset * in = it->getInsetFromID(id_arg);
2184 ParIterator Buffer::getParFromID(int id) const
2186 #warning FIXME: const correctness! (Andre)
2187 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2188 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2190 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2192 // John says this is called with id == -1 from undo
2193 lyxerr << "getParFromID(), id: " << id << endl;
2197 for (; it != end; ++it)
2205 bool Buffer::hasParWithID(int id) const
2207 ParConstIterator it = par_iterator_begin();
2208 ParConstIterator end = par_iterator_end();
2211 // John says this is called with id == -1 from undo
2212 lyxerr << "hasParWithID(), id: " << id << endl;
2216 for (; it != end; ++it)
2224 ParIterator Buffer::par_iterator_begin()
2226 return ParIterator(paragraphs.begin(), paragraphs);
2230 ParIterator Buffer::par_iterator_end()
2232 return ParIterator(paragraphs.end(), paragraphs);
2235 ParConstIterator Buffer::par_iterator_begin() const
2237 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2241 ParConstIterator Buffer::par_iterator_end() const
2243 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2248 void Buffer::addUser(BufferView * u)
2254 void Buffer::delUser(BufferView *)
2260 Language const * Buffer::getLanguage() const
2262 return params.language;
2266 string const Buffer::B_(string const & l10n) const
2268 if (messages_.get()) {
2269 return messages_->get(l10n);
2276 bool Buffer::isClean() const
2282 bool Buffer::isBakClean() const
2288 void Buffer::markClean() const
2294 // if the .lyx file has been saved, we don't need an
2300 void Buffer::markBakClean()
2306 void Buffer::setUnnamed(bool flag)
2312 bool Buffer::isUnnamed()
2318 void Buffer::markDirty()
2326 DepClean::iterator it = dep_clean_.begin();
2327 DepClean::const_iterator const end = dep_clean_.end();
2329 for (; it != end; ++it) {
2335 string const & Buffer::fileName() const
2341 string const & Buffer::filePath() const
2347 bool Buffer::isReadonly() const
2353 BufferView * Buffer::getUser() const
2359 void Buffer::setParentName(string const & name)
2361 params.parentname = name;
2365 Buffer::inset_iterator::inset_iterator()
2370 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2377 Buffer::inset_iterator Buffer::inset_iterator_begin()
2379 return inset_iterator(paragraphs.begin(), paragraphs.end());
2383 Buffer::inset_iterator Buffer::inset_iterator_end()
2385 return inset_iterator(paragraphs.end(), paragraphs.end());
2389 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2391 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2392 const_cast<ParagraphList&>(paragraphs).end());
2396 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2398 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2399 const_cast<ParagraphList&>(paragraphs).end());
2403 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2407 if (it == pit->insetlist.end()) {
2416 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2418 inset_iterator tmp = *this;
2424 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2430 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2436 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2442 lyx::pos_type Buffer::inset_iterator::getPos() const
2448 bool operator==(Buffer::inset_iterator const & iter1,
2449 Buffer::inset_iterator const & iter2)
2451 return iter1.pit == iter2.pit
2452 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2456 bool operator!=(Buffer::inset_iterator const & iter1,
2457 Buffer::inset_iterator const & iter2)
2459 return !(iter1 == iter2);