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/insetbibitem.h"
49 #include "insets/insetbibtex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insettext.h"
53 #include "frontends/Dialogs.h"
54 #include "frontends/Alert.h"
56 #include "graphics/Previews.h"
58 #include "support/textutils.h"
59 #include "support/filetools.h"
60 #include "support/path.h"
61 #include "support/os.h"
62 #include "support/tostr.h"
63 #include "support/lyxlib.h"
64 #include "support/FileInfo.h"
65 #include "support/lyxmanip.h"
66 #include "support/lyxtime.h"
68 #include <boost/bind.hpp>
69 #include <boost/tuple/tuple.hpp>
81 #include <sys/types.h>
88 #ifndef CXX_GLOBAL_CSTD
100 using std::make_pair;
108 using lyx::textclass_type;
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
115 const int LYX_FORMAT = 224;
119 Buffer::Buffer(string const & file, bool ronly)
120 : niceFile(true), lyx_clean(true), bak_clean(true),
121 unnamed(false), read_only(ronly),
122 filename_(file), users(0)
124 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
125 filepath_ = OnlyPath(file);
127 if (read_only || lyxrc.use_tempdir) {
128 tmppath = CreateBufferTmpDir();
133 // set initial author
134 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
140 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
141 // here the buffer should take care that it is
142 // saved properly, before it goes into the void.
144 // make sure that views using this buffer
149 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
150 Alert::warning(_("Could not remove temporary directory"),
151 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
156 // Remove any previewed LaTeX snippets assocoated with this buffer.
157 grfx::Previews::get().removeLoader(this);
161 string const Buffer::getLatexName(bool no_path) const
163 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
164 return no_path ? OnlyFilename(name) : name;
168 pair<Buffer::LogType, string> const Buffer::getLogName() const
170 string const filename = getLatexName(false);
172 if (filename.empty())
173 return make_pair(Buffer::latexlog, string());
175 string path = OnlyPath(filename);
177 if (lyxrc.use_tempdir || !IsDirWriteable(path))
180 string const fname = AddName(path,
181 OnlyFilename(ChangeExtension(filename,
184 AddName(path, OnlyFilename(
185 ChangeExtension(filename,
186 formats.extension("literate") + ".out")));
188 // If no Latex log or Build log is newer, show Build log
190 FileInfo const f_fi(fname);
191 FileInfo const b_fi(bname);
194 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
195 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
196 return make_pair(Buffer::buildlog, bname);
198 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
199 return make_pair(Buffer::latexlog, fname);
203 void Buffer::setReadonly(bool flag)
205 if (read_only != flag) {
209 users->owner()->getDialogs().updateBufferDependent(false);
214 AuthorList & Buffer::authors()
216 return params.authorlist;
220 /// Update window titles of all users
221 // Should work on a list
222 void Buffer::updateTitles() const
225 users->owner()->updateWindowTitle();
229 /// Reset autosave timer of all users
230 // Should work on a list
231 void Buffer::resetAutosaveTimers() const
234 users->owner()->resetAutosaveTimer();
238 void Buffer::setFileName(string const & newfile)
240 filename_ = MakeAbsPath(newfile);
241 filepath_ = OnlyPath(filename_);
242 setReadonly(IsFileWriteable(filename_) == 0);
247 // We'll remove this later. (Lgb)
250 void unknownClass(string const & unknown)
252 Alert::warning(_("Unknown document class"),
253 bformat(_("Using the default document class, because the "
254 " class %1$s is unknown."), unknown));
259 int Buffer::readHeader(LyXLex & lex)
261 int unknown_tokens = 0;
265 string const token = lex.getString();
270 if (token == "\\end_header")
273 lyxerr[Debug::PARSER] << "Handling header token: `"
274 << token << '\'' << endl;
277 string unknown = params.readToken(lex, token);
278 if (!unknown.empty()) {
279 if (unknown[0] != '\\') {
280 unknownClass(unknown);
283 string const s = bformat(_("Unknown token: "
287 parseError(ErrorItem(_("Header error"), s,
292 return unknown_tokens;
296 // candidate for move to BufferView
297 // (at least some parts in the beginning of the func)
300 // changed to be public and have one parameter
301 // if par = 0 normal behavior
302 // else insert behavior
303 // Returns false if "\the_end" is not read (Asger)
304 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
306 Paragraph::depth_type depth = 0;
307 bool the_end_read = false;
309 if (paragraphs.empty()) {
311 if (!params.getLyXTextClass().load()) {
312 string theclass = params.getLyXTextClass().name();
313 Alert::error(_("Can't load document class"), bformat(
314 "Using the default document class, because the "
315 " class %1$s could not be loaded.", theclass));
316 params.textclass = 0;
319 // We are inserting into an existing document
320 users->text->breakParagraph(paragraphs);
322 // We don't want to adopt the parameters from the
323 // document we insert, so read them into a temporary buffer
324 // and then discard it
326 Buffer tmpbuf("", false);
327 tmpbuf.readHeader(lex);
332 string const token = lex.getString();
337 lyxerr[Debug::PARSER] << "Handling token: `"
338 << token << '\'' << endl;
340 if (token == "\\the_end") {
345 readParagraph(lex, token, paragraphs, pit, depth);
352 int Buffer::readParagraph(LyXLex & lex, string const & token,
353 ParagraphList & pars, ParagraphList::iterator & pit,
354 Paragraph::depth_type & depth)
356 static Change current_change;
359 if (token == "\\layout") {
360 lex.pushToken(token);
363 par.params().depth(depth);
364 if (params.tracking_changes)
366 LyXFont f(LyXFont::ALL_INHERIT, params.language);
370 if (pit != pars.end())
373 pit = pars.insert(pit, par);
375 // FIXME: goddamn InsetTabular makes us pass a Buffer
377 ::readParagraph(*this, *pit, lex);
379 } else if (token == "\\begin_deeper") {
381 } else if (token == "\\end_deeper") {
383 lex.printError("\\end_deeper: " "depth is already null");
394 // needed to insert the selection
395 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
396 LyXFont const & fn,string const & str)
398 LyXLayout_ptr const & layout = par->layout();
402 par->checkInsertChar(font);
403 // insert the string, don't insert doublespace
404 bool space_inserted = true;
405 bool autobreakrows = !par->inInset() ||
406 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
407 for(string::const_iterator cit = str.begin();
408 cit != str.end(); ++cit) {
410 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
411 breakParagraph(params, paragraphs, par, pos,
412 layout->isEnvironment());
415 space_inserted = true;
419 // do not insert consecutive spaces if !free_spacing
420 } else if ((*cit == ' ' || *cit == '\t') &&
421 space_inserted && !par->isFreeSpacing()) {
423 } else if (*cit == '\t') {
424 if (!par->isFreeSpacing()) {
425 // tabs are like spaces here
426 par->insertChar(pos, ' ', font);
428 space_inserted = true;
430 const pos_type nb = 8 - pos % 8;
431 for (pos_type a = 0; a < nb ; ++a) {
432 par->insertChar(pos, ' ', font);
435 space_inserted = true;
437 } else if (!IsPrintable(*cit)) {
438 // Ignore unprintables
441 // just insert the character
442 par->insertChar(pos, *cit, font);
444 space_inserted = (*cit == ' ');
451 bool Buffer::readFile(LyXLex & lex, string const & filename)
453 bool ret = readFile(lex, filename, paragraphs.begin());
455 // After we have read a file, we must ensure that the buffer
456 // language is set and used in the gui.
457 // If you know of a better place to put this, please tell me. (Lgb)
458 updateDocLang(params.language);
464 // FIXME: all the below Alerts should give the filename..
465 bool Buffer::readFile(LyXLex & lex, string const & filename,
466 ParagraphList::iterator pit)
469 Alert::error(_("Document could not be read"),
470 _("The specified document could not be read."));
475 string const token(lex.getString());
478 Alert::error(_("Document could not be read"),
479 _("The specified document could not be read."));
483 // the first token _must_ be...
484 if (token != "\\lyxformat") {
485 Alert::error(_("Document format failure"),
486 _("The specified document is not a LyX document."));
491 string tmp_format = lex.getString();
492 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
493 // if present remove ".," from string.
494 string::size_type dot = tmp_format.find_first_of(".,");
495 //lyxerr << " dot found at " << dot << endl;
496 if (dot != string::npos)
497 tmp_format.erase(dot, 1);
498 file_format = strToInt(tmp_format);
499 //lyxerr << "format: " << file_format << endl;
500 if (file_format == LYX_FORMAT) {
502 } else if (file_format > LYX_FORMAT) {
503 Alert::warning(_("Document format failure"),
504 _("This document was created with a newer version of "
505 "LyX. This is likely to cause problems."));
506 } else if (file_format < LYX_FORMAT) {
508 if (file_format < 200) {
509 Alert::error(_("Document format failure"),
510 _("This LyX document is too old to be read "
511 "by this version of LyX. Try LyX 0.10."));
513 } else if (!filename.empty()) {
515 LibFileSearch("lyx2lyx", "lyx2lyx");
516 if (command.empty()) {
517 Alert::error(_("Conversion script not found"),
518 _("The document is from an earlier version "
519 "of LyX, but the conversion script lyx2lyx "
520 "could not be found."));
524 +tostr(LYX_FORMAT) + ' '
525 + QuoteName(filename);
526 lyxerr[Debug::INFO] << "Running '"
529 cmd_ret const ret = RunCommand(command);
531 Alert::error(_("Conversion script failed"),
532 _("The document is from an earlier version "
533 "of LyX, but the lyx2lyx script failed "
537 istringstream is(STRCONV(ret.second));
539 tmplex.setStream(is);
540 return readFile(tmplex, string(), pit);
542 // This code is reached if lyx2lyx failed (for
543 // some reason) to change the file format of
549 bool the_end = readBody(lex, pit);
550 params.setPaperStuff();
553 Alert::error(_("Document format failure"),
554 _("The document ended unexpectedly, which means "
555 "that it is probably corrupted."));
561 // Should probably be moved to somewhere else: BufferView? LyXView?
562 bool Buffer::save() const
564 // We don't need autosaves in the immediate future. (Asger)
565 resetAutosaveTimers();
569 if (lyxrc.make_backup) {
570 s = fileName() + '~';
571 if (!lyxrc.backupdir_path.empty())
572 s = AddName(lyxrc.backupdir_path,
573 subst(os::slashify_path(s),'/','!'));
575 // Rename is the wrong way of making a backup,
576 // this is the correct way.
577 /* truss cp fil fil2:
578 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
579 stat("LyXVC.lyx", 0xEFFFF688) = 0
580 open("LyXVC.lyx", O_RDONLY) = 3
581 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
582 fstat(4, 0xEFFFF508) = 0
583 fstat(3, 0xEFFFF508) = 0
584 read(3, " # T h i s f i l e w".., 8192) = 5579
585 write(4, " # T h i s f i l e w".., 5579) = 5579
586 read(3, 0xEFFFD4A0, 8192) = 0
589 chmod("LyXVC3.lyx", 0100644) = 0
590 lseek(0, 0, SEEK_CUR) = 46440
594 // Should probably have some more error checking here.
595 // Doing it this way, also makes the inodes stay the same.
596 // This is still not a very good solution, in particular we
597 // might loose the owner of the backup.
598 FileInfo finfo(fileName());
600 mode_t fmode = finfo.getMode();
601 struct utimbuf times = {
602 finfo.getAccessTime(),
603 finfo.getModificationTime() };
605 ifstream ifs(fileName().c_str());
606 ofstream ofs(s.c_str(), ios::out|ios::trunc);
611 ::chmod(s.c_str(), fmode);
613 if (::utime(s.c_str(), ×)) {
614 lyxerr << "utime error." << endl;
617 lyxerr << "LyX was not able to make "
618 "backup copy. Beware." << endl;
623 if (writeFile(fileName())) {
625 removeAutosaveFile(fileName());
627 // Saving failed, so backup is not backup
628 if (lyxrc.make_backup) {
629 lyx::rename(s, fileName());
637 bool Buffer::writeFile(string const & fname) const
639 if (read_only && (fname == fileName())) {
643 FileInfo finfo(fname);
644 if (finfo.exist() && !finfo.writable()) {
648 ofstream ofs(fname.c_str());
654 // Use the standard "C" locale for file output.
655 ofs.imbue(std::locale::classic());
658 // The top of the file should not be written by params.
660 // write out a comment in the top of the file
661 ofs << '#' << lyx_docversion
662 << " created this file. For more info see http://www.lyx.org/\n"
663 << "\\lyxformat " << LYX_FORMAT << "\n";
665 // now write out the buffer paramters.
666 params.writeFile(ofs);
668 ofs << "\\end_header\n";
670 Paragraph::depth_type depth = 0;
672 // this will write out all the paragraphs
673 // using recursive descent.
674 ParagraphList::const_iterator pit = paragraphs.begin();
675 ParagraphList::const_iterator pend = paragraphs.end();
676 for (; pit != pend; ++pit)
677 pit->write(this, ofs, params, depth);
679 // Write marker that shows file is complete
680 ofs << "\n\\the_end" << endl;
684 // how to check if close went ok?
685 // Following is an attempt... (BE 20001011)
687 // good() returns false if any error occured, including some
689 // bad() returns true if something bad happened in the buffer,
690 // which should include file system full errors.
697 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
699 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
711 pair<int, string> const addDepth(int depth, int ldepth)
715 d += (ldepth - depth) * 2;
716 return make_pair(d, string(d, ' '));
722 string const Buffer::asciiParagraph(Paragraph const & par,
723 unsigned int linelen,
724 bool noparbreak) const
726 ostringstream buffer;
728 Paragraph::depth_type ltype_depth = 0;
729 bool ref_printed = false;
730 Paragraph::depth_type depth = par.params().depth();
732 // First write the layout
733 string const & tmp = par.layout()->name();
734 if (compare_no_case(tmp, "itemize") == 0) {
736 ltype_depth = depth + 1;
737 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
739 ltype_depth = depth + 1;
740 } else if (contains(ascii_lowercase(tmp), "ection")) {
742 ltype_depth = depth + 1;
743 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
745 ltype_depth = depth + 1;
746 } else if (compare_ascii_no_case(tmp, "description") == 0) {
748 ltype_depth = depth + 1;
749 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
752 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
760 /* maybe some vertical spaces */
762 /* the labelwidthstring used in lists */
766 /* some pagebreaks? */
770 /* what about the alignment */
772 // linelen <= 0 is special and means we don't have paragraph breaks
774 string::size_type currlinelen = 0;
780 buffer << string(depth * 2, ' ');
781 currlinelen += depth * 2;
784 // we should probably change to the paragraph language in the
785 // gettext here (if possible) so that strings are outputted in
786 // the correct language! (20012712 Jug)
790 case 4: // (Sub)Paragraph
791 case 5: // Description
795 buffer << _("Abstract") << "\n\n";
798 string const abst = _("Abstract: ");
800 currlinelen += abst.length();
803 case 7: // Bibliography
806 buffer << _("References") << "\n\n";
809 string const refs = _("References: ");
811 currlinelen += refs.length();
819 string const parlab = par.params().labelString();
820 buffer << parlab << ' ';
821 currlinelen += parlab.length() + 1;
829 pair<int, string> p = addDepth(depth, ltype_depth);
831 currlinelen += p.first;
834 // this is to change the linebreak to do it by word a bit more
835 // intelligent hopefully! (only in the case where we have a
836 // max linelength!) (Jug)
840 for (pos_type i = 0; i < par.size(); ++i) {
841 char c = par.getUChar(params, i);
843 case Paragraph::META_INSET:
845 Inset const * inset = par.getInset(i);
849 currlinelen += word.length();
852 if (inset->ascii(this, buffer, linelen)) {
853 // to be sure it breaks paragraph
854 currlinelen += linelen;
863 currlinelen + word.length() > linelen - 10) {
865 pair<int, string> p = addDepth(depth, ltype_depth);
867 currlinelen = p.first;
870 buffer << word << ' ';
871 currlinelen += word.length() + 1;
878 lyxerr[Debug::INFO] <<
879 "writeAsciiFile: NULL char in structure." << endl;
882 (currlinelen + word.length()) > linelen)
886 pair<int, string> p =
887 addDepth(depth, ltype_depth);
889 currlinelen = p.first;
896 return STRCONV(buffer.str());
900 void Buffer::writeFileAscii(string const & fname, int linelen)
902 ofstream ofs(fname.c_str());
904 string const file = MakeDisplayPath(fname, 50);
905 string text = bformat(_("Could not save the document\n%1$s."), file);
906 Alert::error(_("Could not save document"), text);
909 writeFileAscii(ofs, linelen);
913 void Buffer::writeFileAscii(ostream & os, int linelen)
915 ParagraphList::iterator beg = paragraphs.begin();
916 ParagraphList::iterator end = paragraphs.end();
917 ParagraphList::iterator it = beg;
918 for (; it != end; ++it) {
919 os << asciiParagraph(*it, linelen, it == beg);
926 void Buffer::makeLaTeXFile(string const & fname,
927 string const & original_path,
928 LatexRunParams const & runparams,
929 bool only_body, bool only_preamble)
931 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
933 ofstream ofs(fname.c_str());
935 string const file = MakeDisplayPath(fname, 50);
936 string text = bformat(_("Could not open the specified document\n%1$s."),
938 Alert::error(_("Could not open file"), text);
942 makeLaTeXFile(ofs, original_path,
943 runparams, only_body, only_preamble);
947 lyxerr << "File was not closed properly." << endl;
952 void Buffer::makeLaTeXFile(ostream & os,
953 string const & original_path,
954 LatexRunParams const & runparams_in,
955 bool only_body, bool only_preamble)
957 LatexRunParams runparams = runparams_in;
958 niceFile = runparams.nice; // this will be used by Insetincludes.
960 // validate the buffer.
961 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
962 LaTeXFeatures features(params);
964 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
967 // The starting paragraph of the coming rows is the
968 // first paragraph of the document. (Asger)
969 texrow.start(paragraphs.begin()->id(), 0);
971 if (!only_body && runparams.nice) {
972 os << "%% " << lyx_docversion << " created this file. "
973 "For more info, see http://www.lyx.org/.\n"
974 "%% Do not edit unless you really know what "
979 lyxerr[Debug::INFO] << "lyx header finished" << endl;
980 // There are a few differences between nice LaTeX and usual files:
981 // usual is \batchmode and has a
982 // special input@path to allow the including of figures
983 // with either \input or \includegraphics (what figinsets do).
984 // input@path is set when the actual parameter
985 // original_path is set. This is done for usual tex-file, but not
986 // for nice-latex-file. (Matthias 250696)
988 if (!runparams.nice) {
989 // code for usual, NOT nice-latex-file
990 os << "\\batchmode\n"; // changed
994 if (!original_path.empty()) {
995 string inputpath = os::external_path(original_path);
996 subst(inputpath, "~", "\\string~");
997 os << "\\makeatletter\n"
998 << "\\def\\input@path{{"
999 << inputpath << "/}}\n"
1000 << "\\makeatother\n";
1006 // Write the preamble
1007 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1013 os << "\\begin{document}\n";
1016 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1018 if (!lyxrc.language_auto_begin) {
1019 os << subst(lyxrc.language_command_begin, "$$lang",
1020 params.language->babel())
1025 latexParagraphs(this, paragraphs, os, texrow, runparams);
1027 // add this just in case after all the paragraphs
1031 if (!lyxrc.language_auto_end) {
1032 os << subst(lyxrc.language_command_end, "$$lang",
1033 params.language->babel())
1039 os << "\\end{document}\n";
1042 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1044 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1048 // Just to be sure. (Asger)
1051 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1052 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1055 // we want this to be true outside previews (for insetexternal)
1060 bool Buffer::isLatex() const
1062 return params.getLyXTextClass().outputType() == LATEX;
1066 bool Buffer::isLinuxDoc() const
1068 return params.getLyXTextClass().outputType() == LINUXDOC;
1072 bool Buffer::isLiterate() const
1074 return params.getLyXTextClass().outputType() == LITERATE;
1078 bool Buffer::isDocBook() const
1080 return params.getLyXTextClass().outputType() == DOCBOOK;
1084 bool Buffer::isSGML() const
1086 LyXTextClass const & tclass = params.getLyXTextClass();
1088 return tclass.outputType() == LINUXDOC ||
1089 tclass.outputType() == DOCBOOK;
1093 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1095 ofstream ofs(fname.c_str());
1098 string const file = MakeDisplayPath(fname, 50);
1099 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1101 Alert::error(_("Could not save document"), text);
1105 niceFile = nice; // this will be used by included files.
1107 LaTeXFeatures features(params);
1113 LyXTextClass const & tclass = params.getLyXTextClass();
1115 string top_element = tclass.latexname();
1118 ofs << "<!doctype linuxdoc system";
1120 string preamble = params.preamble;
1121 const string name = nice ? ChangeExtension(filename_, ".sgml")
1123 preamble += features.getIncludedFiles(name);
1124 preamble += features.getLyXSGMLEntities();
1126 if (!preamble.empty()) {
1127 ofs << " [ " << preamble << " ]";
1131 if (params.options.empty())
1132 sgml::openTag(ofs, 0, false, top_element);
1134 string top = top_element;
1136 top += params.options;
1137 sgml::openTag(ofs, 0, false, top);
1141 ofs << "<!-- " << lyx_docversion
1142 << " created this file. For more info see http://www.lyx.org/"
1145 Paragraph::depth_type depth = 0; // paragraph depth
1147 vector<string> environment_stack(5);
1149 users->resetErrorList();
1151 ParagraphList::iterator pit = paragraphs.begin();
1152 ParagraphList::iterator pend = paragraphs.end();
1153 for (; pit != pend; ++pit) {
1154 LyXLayout_ptr const & style = pit->layout();
1155 // treat <toc> as a special case for compatibility with old code
1156 if (pit->isInset(0)) {
1157 Inset * inset = pit->getInset(0);
1158 Inset::Code lyx_code = inset->lyxCode();
1159 if (lyx_code == Inset::TOC_CODE) {
1160 string const temp = "toc";
1161 sgml::openTag(ofs, depth, false, temp);
1166 // environment tag closing
1167 for (; depth > pit->params().depth(); --depth) {
1168 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1169 environment_stack[depth].erase();
1172 // write opening SGML tags
1173 switch (style->latextype) {
1174 case LATEX_PARAGRAPH:
1175 if (depth == pit->params().depth()
1176 && !environment_stack[depth].empty()) {
1177 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1178 environment_stack[depth].erase();
1184 sgml::openTag(ofs, depth, false, style->latexname());
1189 parseError(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1191 if (!environment_stack[depth].empty()) {
1192 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1196 environment_stack[depth].erase();
1197 sgml::openTag(ofs, depth, false, style->latexname());
1200 case LATEX_ENVIRONMENT:
1201 case LATEX_ITEM_ENVIRONMENT:
1202 case LATEX_BIB_ENVIRONMENT:
1204 string const & latexname = style->latexname();
1206 if (depth == pit->params().depth()
1207 && environment_stack[depth] != latexname) {
1208 sgml::closeTag(ofs, depth, false,
1209 environment_stack[depth]);
1210 environment_stack[depth].erase();
1212 if (depth < pit->params().depth()) {
1213 depth = pit->params().depth();
1214 environment_stack[depth].erase();
1216 if (environment_stack[depth] != latexname) {
1218 sgml::openTag(ofs, depth, false, "p");
1220 sgml::openTag(ofs, depth, false, latexname);
1222 if (environment_stack.size() == depth + 1)
1223 environment_stack.push_back("!-- --");
1224 environment_stack[depth] = latexname;
1227 if (style->latexparam() == "CDATA")
1230 if (style->latextype == LATEX_ENVIRONMENT) break;
1232 if (style->labeltype == LABEL_MANUAL)
1237 sgml::openTag(ofs, depth + 1, false, item_name);
1242 sgml::openTag(ofs, depth, false, style->latexname());
1246 simpleLinuxDocOnePar(ofs, pit, depth);
1249 // write closing SGML tags
1250 switch (style->latextype) {
1253 case LATEX_ENVIRONMENT:
1254 case LATEX_ITEM_ENVIRONMENT:
1255 case LATEX_BIB_ENVIRONMENT:
1256 if (style->latexparam() == "CDATA")
1260 sgml::closeTag(ofs, depth, false, style->latexname());
1266 for (int i = depth; i >= 0; --i)
1267 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1271 sgml::closeTag(ofs, 0, false, top_element);
1275 // How to check for successful close
1277 // we want this to be true outside previews (for insetexternal)
1280 users->showErrorList(_("LinuxDoc"));
1284 // checks, if newcol chars should be put into this line
1285 // writes newline, if necessary.
1288 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1289 string::size_type newcol)
1292 if (colcount > lyxrc.ascii_linelen) {
1294 colcount = newcol; // assume write after this call
1309 string tag_name(PAR_TAG const & pt) {
1311 case NONE: return "!-- --";
1312 case TT: return "tt";
1313 case SF: return "sf";
1314 case BF: return "bf";
1315 case IT: return "it";
1316 case SL: return "sl";
1317 case EM: return "em";
1324 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1326 p1 = static_cast<PAR_TAG>(p1 | p2);
1331 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1333 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1339 // Handle internal paragraph parsing -- layout already processed.
1340 void Buffer::simpleLinuxDocOnePar(ostream & os,
1341 ParagraphList::iterator par,
1342 Paragraph::depth_type /*depth*/) const
1344 LyXLayout_ptr const & style = par->layout();
1346 string::size_type char_line_count = 5; // Heuristic choice ;-)
1348 // gets paragraph main font
1351 if (style->labeltype == LABEL_MANUAL) {
1352 font_old = style->labelfont;
1355 font_old = style->font;
1359 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1360 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1361 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1364 stack<PAR_TAG> tag_state;
1365 // parsing main loop
1366 for (pos_type i = 0; i < par->size(); ++i) {
1368 PAR_TAG tag_close = NONE;
1369 list < PAR_TAG > tag_open;
1371 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1373 if (font_old.family() != font.family()) {
1374 switch (family_type) {
1375 case LyXFont::SANS_FAMILY:
1378 case LyXFont::TYPEWRITER_FAMILY:
1385 family_type = font.family();
1387 switch (family_type) {
1388 case LyXFont::SANS_FAMILY:
1389 tag_open.push_back(SF);
1391 case LyXFont::TYPEWRITER_FAMILY:
1392 tag_open.push_back(TT);
1399 if (font_old.series() != font.series()) {
1400 switch (series_type) {
1401 case LyXFont::BOLD_SERIES:
1408 series_type = font.series();
1410 switch (series_type) {
1411 case LyXFont::BOLD_SERIES:
1412 tag_open.push_back(BF);
1420 if (font_old.shape() != font.shape()) {
1421 switch (shape_type) {
1422 case LyXFont::ITALIC_SHAPE:
1425 case LyXFont::SLANTED_SHAPE:
1432 shape_type = font.shape();
1434 switch (shape_type) {
1435 case LyXFont::ITALIC_SHAPE:
1436 tag_open.push_back(IT);
1438 case LyXFont::SLANTED_SHAPE:
1439 tag_open.push_back(SL);
1446 if (font_old.emph() != font.emph()) {
1447 if (font.emph() == LyXFont::ON) {
1448 tag_open.push_back(EM);
1457 list < PAR_TAG > temp;
1458 while (!tag_state.empty() && tag_close) {
1459 PAR_TAG k = tag_state.top();
1461 os << "</" << tag_name(k) << '>';
1468 for(list< PAR_TAG >::const_iterator j = temp.begin();
1469 j != temp.end(); ++j) {
1471 os << '<' << tag_name(*j) << '>';
1474 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1475 j != tag_open.end(); ++j) {
1477 os << '<' << tag_name(*j) << '>';
1480 char c = par->getChar(i);
1482 if (c == Paragraph::META_INSET) {
1483 Inset * inset = par->getInset(i);
1484 inset->linuxdoc(this, os);
1489 if (style->latexparam() == "CDATA") {
1490 // "TeX"-Mode on == > SGML-Mode on.
1497 boost::tie(ws, str) = sgml::escapeChar(c);
1498 if (ws && !par->isFreeSpacing()) {
1499 // in freespacing mode, spaces are
1500 // non-breaking characters
1501 if (desc_on) {// if char is ' ' then...
1504 sgmlLineBreak(os, char_line_count, 6);
1508 sgmlLineBreak(os, char_line_count, 1);
1513 char_line_count += str.length();
1519 while (!tag_state.empty()) {
1520 os << "</" << tag_name(tag_state.top()) << '>';
1524 // resets description flag correctly
1526 // <tag> not closed...
1527 sgmlLineBreak(os, char_line_count, 6);
1533 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1535 ofstream ofs(fname.c_str());
1537 string const file = MakeDisplayPath(fname, 50);
1538 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1540 Alert::error(_("Could not save document"), text);
1544 niceFile = nice; // this will be used by Insetincludes.
1546 LaTeXFeatures features(params);
1551 LyXTextClass const & tclass = params.getLyXTextClass();
1552 string top_element = tclass.latexname();
1555 ofs << "<!DOCTYPE " << top_element
1556 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1558 string preamble = params.preamble;
1559 const string name = nice ? ChangeExtension(filename_, ".sgml")
1561 preamble += features.getIncludedFiles(name);
1562 preamble += features.getLyXSGMLEntities();
1564 if (!preamble.empty()) {
1565 ofs << "\n [ " << preamble << " ]";
1570 string top = top_element;
1572 top += params.language->code();
1575 if (!params.options.empty()) {
1577 top += params.options;
1579 sgml::openTag(ofs, 0, false, top);
1581 ofs << "<!-- DocBook file was created by " << lyx_docversion
1582 << "\n See http://www.lyx.org/ for more information -->\n";
1584 vector<string> environment_stack(10);
1585 vector<string> environment_inner(10);
1586 vector<string> command_stack(10);
1588 bool command_flag = false;
1589 Paragraph::depth_type command_depth = 0;
1590 Paragraph::depth_type command_base = 0;
1591 Paragraph::depth_type cmd_depth = 0;
1592 Paragraph::depth_type depth = 0; // paragraph depth
1595 string command_name;
1597 users->resetErrorList();
1599 ParagraphList::iterator par = paragraphs.begin();
1600 ParagraphList::iterator pend = paragraphs.end();
1602 for (; par != pend; ++par) {
1606 int desc_on = 0; // description mode
1608 LyXLayout_ptr const & style = par->layout();
1610 // environment tag closing
1611 for (; depth > par->params().depth(); --depth) {
1612 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1613 item_name = "listitem";
1614 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1615 if (environment_inner[depth] == "varlistentry")
1616 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1618 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1619 environment_stack[depth].erase();
1620 environment_inner[depth].erase();
1623 if (depth == par->params().depth()
1624 && environment_stack[depth] != style->latexname()
1625 && !environment_stack[depth].empty()) {
1626 if (environment_inner[depth] != "!-- --") {
1627 item_name= "listitem";
1628 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1629 if (environment_inner[depth] == "varlistentry")
1630 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1633 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1635 environment_stack[depth].erase();
1636 environment_inner[depth].erase();
1639 // Write opening SGML tags.
1640 switch (style->latextype) {
1641 case LATEX_PARAGRAPH:
1642 sgml::openTag(ofs, depth + command_depth,
1643 false, style->latexname());
1648 parseError(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1650 command_name = style->latexname();
1652 sgmlparam = style->latexparam();
1653 c_params = split(sgmlparam, c_depth,'|');
1655 cmd_depth = lyx::atoi(c_depth);
1658 if (cmd_depth < command_base) {
1659 for (Paragraph::depth_type j = command_depth;
1660 j >= command_base; --j) {
1661 sgml::closeTag(ofs, j, false, command_stack[j]);
1664 command_depth = command_base = cmd_depth;
1665 } else if (cmd_depth <= command_depth) {
1666 for (int j = command_depth;
1667 j >= int(cmd_depth); --j) {
1668 sgml::closeTag(ofs, j, false, command_stack[j]);
1671 command_depth = cmd_depth;
1673 command_depth = cmd_depth;
1675 command_depth = command_base = cmd_depth;
1676 command_flag = true;
1678 if (command_stack.size() == command_depth + 1)
1679 command_stack.push_back(string());
1680 command_stack[command_depth] = command_name;
1682 // treat label as a special case for
1683 // more WYSIWYM handling.
1684 // This is a hack while paragraphs can't have
1685 // attributes, like id in this case.
1686 if (par->isInset(0)) {
1687 Inset * inset = par->getInset(0);
1688 Inset::Code lyx_code = inset->lyxCode();
1689 if (lyx_code == Inset::LABEL_CODE) {
1690 command_name += " id=\"";
1691 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1692 command_name += '"';
1697 sgml::openTag(ofs, depth + command_depth, false, command_name);
1699 item_name = c_params.empty() ? "title" : c_params;
1700 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1703 case LATEX_ENVIRONMENT:
1704 case LATEX_ITEM_ENVIRONMENT:
1705 if (depth < par->params().depth()) {
1706 depth = par->params().depth();
1707 environment_stack[depth].erase();
1710 if (environment_stack[depth] != style->latexname()) {
1711 if (environment_stack.size() == depth + 1) {
1712 environment_stack.push_back("!-- --");
1713 environment_inner.push_back("!-- --");
1715 environment_stack[depth] = style->latexname();
1716 environment_inner[depth] = "!-- --";
1717 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1719 if (environment_inner[depth] != "!-- --") {
1720 item_name= "listitem";
1721 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1722 if (environment_inner[depth] == "varlistentry")
1723 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1727 if (style->latextype == LATEX_ENVIRONMENT) {
1728 if (!style->latexparam().empty()) {
1729 if (style->latexparam() == "CDATA")
1732 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1737 desc_on = (style->labeltype == LABEL_MANUAL);
1739 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1740 sgml::openTag(ofs, depth + 1 + command_depth,
1741 false, environment_inner[depth]);
1743 item_name = desc_on ? "term" : "para";
1744 sgml::openTag(ofs, depth + 1 + command_depth,
1748 sgml::openTag(ofs, depth + command_depth,
1749 false, style->latexname());
1753 simpleDocBookOnePar(ofs, par, desc_on,
1754 depth + 1 + command_depth);
1757 // write closing SGML tags
1758 switch (style->latextype) {
1760 end_tag = c_params.empty() ? "title" : c_params;
1761 sgml::closeTag(ofs, depth + command_depth,
1764 case LATEX_ENVIRONMENT:
1765 if (!style->latexparam().empty()) {
1766 if (style->latexparam() == "CDATA")
1769 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1772 case LATEX_ITEM_ENVIRONMENT:
1773 if (desc_on == 1) break;
1775 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1777 case LATEX_PARAGRAPH:
1778 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1781 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1787 for (int d = depth; d >= 0; --d) {
1788 if (!environment_stack[depth].empty()) {
1789 if (environment_inner[depth] != "!-- --") {
1790 item_name = "listitem";
1791 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1792 if (environment_inner[depth] == "varlistentry")
1793 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1796 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1800 for (int j = command_depth; j >= 0 ; --j)
1801 if (!command_stack[j].empty()) {
1802 sgml::closeTag(ofs, j, false, command_stack[j]);
1807 sgml::closeTag(ofs, 0, false, top_element);
1810 // How to check for successful close
1812 // we want this to be true outside previews (for insetexternal)
1814 users->showErrorList(_("DocBook"));
1818 void Buffer::simpleDocBookOnePar(ostream & os,
1819 ParagraphList::iterator par, int & desc_on,
1820 Paragraph::depth_type depth) const
1822 bool emph_flag = false;
1824 LyXLayout_ptr const & style = par->layout();
1826 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1828 int char_line_count = depth;
1829 //if (!style.free_spacing)
1830 // os << string(depth,' ');
1832 // parsing main loop
1833 for (pos_type i = 0; i < par->size(); ++i) {
1834 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1836 // handle <emphasis> tag
1837 if (font_old.emph() != font.emph()) {
1838 if (font.emph() == LyXFont::ON) {
1839 if (style->latexparam() == "CDATA")
1842 if (style->latexparam() == "CDATA")
1846 if (style->latexparam() == "CDATA")
1848 os << "</emphasis>";
1849 if (style->latexparam() == "CDATA")
1856 if (par->isInset(i)) {
1857 Inset * inset = par->getInset(i);
1858 // don't print the inset in position 0 if desc_on == 3 (label)
1859 if (i || desc_on != 3) {
1860 if (style->latexparam() == "CDATA")
1862 inset->docbook(this, os, false);
1863 if (style->latexparam() == "CDATA")
1867 char c = par->getChar(i);
1870 boost::tie(ws, str) = sgml::escapeChar(c);
1872 if (style->pass_thru) {
1874 } else if (par->isFreeSpacing() || c != ' ') {
1876 } else if (desc_on == 1) {
1878 os << "\n</term><listitem><para>";
1888 if (style->latexparam() == "CDATA")
1890 os << "</emphasis>";
1891 if (style->latexparam() == "CDATA")
1895 // resets description flag correctly
1897 // <term> not closed...
1898 os << "</term>\n<listitem><para> </para>";
1900 if (style->free_spacing)
1905 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1906 // Other flags: -wall -v0 -x
1907 int Buffer::runChktex()
1909 if (!users->text) return 0;
1911 users->owner()->busy(true);
1913 // get LaTeX-Filename
1914 string const name = getLatexName();
1915 string path = filePath();
1917 string const org_path = path;
1918 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1922 Path p(path); // path to LaTeX file
1923 users->owner()->message(_("Running chktex..."));
1925 // Generate the LaTeX file if neccessary
1926 LatexRunParams runparams;
1927 runparams.flavor = LatexRunParams::LATEX;
1928 runparams.nice = false;
1929 makeLaTeXFile(name, org_path, runparams);
1932 Chktex chktex(lyxrc.chktex_command, name, filePath());
1933 int res = chktex.run(terr); // run chktex
1936 Alert::error(_("chktex failure"),
1937 _("Could not run chktex successfully."));
1938 } else if (res > 0) {
1939 // Insert all errors as errors boxes
1940 ErrorList el (*this, terr);
1941 users->setErrorList(el);
1942 users->showErrorList(_("ChkTeX"));
1945 users->owner()->busy(false);
1951 void Buffer::validate(LaTeXFeatures & features) const
1953 LyXTextClass const & tclass = params.getLyXTextClass();
1955 if (params.tracking_changes) {
1956 features.require("dvipost");
1957 features.require("color");
1960 // AMS Style is at document level
1961 if (params.use_amsmath == BufferParams::AMS_ON
1962 || tclass.provides(LyXTextClass::amsmath))
1963 features.require("amsmath");
1965 for_each(paragraphs.begin(), paragraphs.end(),
1966 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1968 // the bullet shapes are buffer level not paragraph level
1969 // so they are tested here
1970 for (int i = 0; i < 4; ++i) {
1971 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1972 int const font = params.user_defined_bullets[i].getFont();
1974 int const c = params
1975 .user_defined_bullets[i]
1982 features.require("latexsym");
1984 } else if (font == 1) {
1985 features.require("amssymb");
1986 } else if ((font >= 2 && font <= 5)) {
1987 features.require("pifont");
1992 if (lyxerr.debugging(Debug::LATEX)) {
1993 features.showStruct();
1998 void Buffer::getLabelList(std::vector<string> & list) const
2000 /// if this is a child document and the parent is already loaded
2001 /// Use the parent's list instead [ale990407]
2002 if (!params.parentname.empty()
2003 && bufferlist.exists(params.parentname)) {
2004 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2006 tmp->getLabelList(list);
2011 for (inset_iterator it = inset_const_iterator_begin();
2012 it != inset_const_iterator_end(); ++it) {
2013 it->getLabelList(list);
2018 // This is also a buffer property (ale)
2019 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2021 /// if this is a child document and the parent is already loaded
2022 /// use the parent's list instead [ale990412]
2023 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2024 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2026 tmp->fillWithBibKeys(keys);
2031 for (inset_iterator it = inset_const_iterator_begin();
2032 it != inset_const_iterator_end(); ++it) {
2033 if (it->lyxCode() == Inset::BIBTEX_CODE)
2034 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2035 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2036 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2037 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2038 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2039 string const key = bib.getContents();
2040 string const opt = bib.getOptions();
2041 string const ref; // = pit->asString(this, false);
2042 string const info = opt + "TheBibliographyRef" + ref;
2043 keys.push_back(pair<string, string>(key, info));
2049 bool Buffer::isDepClean(string const & name) const
2051 DepClean::const_iterator it = dep_clean_.find(name);
2052 if (it == dep_clean_.end())
2058 void Buffer::markDepClean(string const & name)
2060 dep_clean_[name] = true;
2064 bool Buffer::dispatch(string const & command, bool * result)
2066 // Split command string into command and argument
2068 string line = ltrim(command);
2069 string const arg = trim(split(line, cmd, ' '));
2071 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2075 bool Buffer::dispatch(int action, string const & argument, bool * result)
2077 bool dispatched = true;
2081 bool const tmp = Exporter::Export(this, argument, false);
2094 void Buffer::resizeInsets(BufferView * bv)
2096 /// then remove all LyXText in text-insets
2097 for_each(paragraphs.begin(), paragraphs.end(),
2098 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2102 void Buffer::redraw()
2104 #warning repaint needed here, or do you mean update() ?
2110 void Buffer::changeLanguage(Language const * from, Language const * to)
2112 lyxerr << "Changing Language!" << endl;
2114 // Take care of l10n/i18n
2117 ParIterator end = par_iterator_end();
2118 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2119 it->changeLanguage(params, from, to);
2123 void Buffer::updateDocLang(Language const * nlang)
2125 messages_.reset(new Messages(nlang->code()));
2129 bool Buffer::isMultiLingual()
2131 ParIterator end = par_iterator_end();
2132 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2133 if (it->isMultiLingual(params))
2140 void Buffer::inset_iterator::setParagraph()
2142 while (pit != pend) {
2143 it = pit->insetlist.begin();
2144 if (it != pit->insetlist.end())
2151 Inset * Buffer::getInsetFromID(int id_arg) const
2153 for (inset_iterator it = inset_const_iterator_begin();
2154 it != inset_const_iterator_end(); ++it)
2156 if (it->id() == id_arg)
2158 Inset * in = it->getInsetFromID(id_arg);
2166 ParIterator Buffer::getParFromID(int id) const
2168 #warning FIXME: const correctness! (Andre)
2169 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2170 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2172 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2174 // John says this is called with id == -1 from undo
2175 lyxerr << "getParFromID(), id: " << id << endl;
2179 for (; it != end; ++it)
2187 bool Buffer::hasParWithID(int id) const
2189 ParConstIterator it = par_iterator_begin();
2190 ParConstIterator end = par_iterator_end();
2193 // John says this is called with id == -1 from undo
2194 lyxerr << "hasParWithID(), id: " << id << endl;
2198 for (; it != end; ++it)
2206 ParIterator Buffer::par_iterator_begin()
2208 return ParIterator(paragraphs.begin(), paragraphs);
2212 ParIterator Buffer::par_iterator_end()
2214 return ParIterator(paragraphs.end(), paragraphs);
2217 ParConstIterator Buffer::par_iterator_begin() const
2219 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2223 ParConstIterator Buffer::par_iterator_end() const
2225 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2230 void Buffer::addUser(BufferView * u)
2236 void Buffer::delUser(BufferView *)
2242 Language const * Buffer::getLanguage() const
2244 return params.language;
2248 string const Buffer::B_(string const & l10n) const
2250 if (messages_.get()) {
2251 return messages_->get(l10n);
2258 bool Buffer::isClean() const
2264 bool Buffer::isBakClean() const
2270 void Buffer::markClean() const
2276 // if the .lyx file has been saved, we don't need an
2282 void Buffer::markBakClean()
2288 void Buffer::setUnnamed(bool flag)
2294 bool Buffer::isUnnamed()
2300 void Buffer::markDirty()
2308 DepClean::iterator it = dep_clean_.begin();
2309 DepClean::const_iterator const end = dep_clean_.end();
2311 for (; it != end; ++it) {
2317 string const & Buffer::fileName() const
2323 string const & Buffer::filePath() const
2329 bool Buffer::isReadonly() const
2335 BufferView * Buffer::getUser() const
2341 void Buffer::setParentName(string const & name)
2343 params.parentname = name;
2347 Buffer::inset_iterator::inset_iterator()
2352 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2359 Buffer::inset_iterator Buffer::inset_iterator_begin()
2361 return inset_iterator(paragraphs.begin(), paragraphs.end());
2365 Buffer::inset_iterator Buffer::inset_iterator_end()
2367 return inset_iterator(paragraphs.end(), paragraphs.end());
2371 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2373 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2374 const_cast<ParagraphList&>(paragraphs).end());
2378 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2380 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2381 const_cast<ParagraphList&>(paragraphs).end());
2385 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2389 if (it == pit->insetlist.end()) {
2398 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2400 inset_iterator tmp = *this;
2406 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2412 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2418 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2424 lyx::pos_type Buffer::inset_iterator::getPos() const
2430 bool operator==(Buffer::inset_iterator const & iter1,
2431 Buffer::inset_iterator const & iter2)
2433 return iter1.pit == iter2.pit
2434 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2438 bool operator!=(Buffer::inset_iterator const & iter1,
2439 Buffer::inset_iterator const & iter2)
2441 return !(iter1 == iter2);