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"
33 #include "BufferView.h"
34 #include "ParagraphParameters.h"
35 #include "iterators.h"
36 #include "lyxtextclasslist.h"
38 #include "paragraph_funcs.h"
42 #include "frontends/LyXView.h"
44 #include "mathed/formulamacro.h"
45 #include "mathed/formula.h"
47 #include "insets/inseterror.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/lyxlib.h"
63 #include "support/FileInfo.h"
64 #include "support/lyxmanip.h"
65 #include "support/lyxtime.h"
67 #include <boost/bind.hpp>
68 #include <boost/tuple/tuple.hpp>
69 #include "support/BoostFormat.h"
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 = 223;
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) {
151 boost::format fmt = _("Could not remove the temporary directory %1$s");
153 string msg = fmt.str();
155 string msg = _("Could not remove the temporary directory ") + tmppath;
157 Alert::warning(_("Could not remove temporary directory"), msg);
162 // Remove any previewed LaTeX snippets assocoated with this buffer.
163 grfx::Previews::get().removeLoader(this);
167 string const Buffer::getLatexName(bool no_path) const
169 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
171 return OnlyFilename(name);
177 pair<Buffer::LogType, string> const Buffer::getLogName() const
179 string const filename = getLatexName(false);
181 if (filename.empty())
182 return make_pair(Buffer::latexlog, string());
184 string path = OnlyPath(filename);
186 if (lyxrc.use_tempdir || !IsDirWriteable(path))
189 string const fname = AddName(path,
190 OnlyFilename(ChangeExtension(filename,
193 AddName(path, OnlyFilename(
194 ChangeExtension(filename,
195 formats.extension("literate") + ".out")));
197 // If no Latex log or Build log is newer, show Build log
199 FileInfo const f_fi(fname);
200 FileInfo const b_fi(bname);
203 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
204 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
205 return make_pair(Buffer::buildlog, bname);
207 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
208 return make_pair(Buffer::latexlog, fname);
212 void Buffer::setReadonly(bool flag)
214 if (read_only != flag) {
217 users->owner()->getDialogs().updateBufferDependent(false);
222 AuthorList & Buffer::authors()
224 return params.authorlist;
228 /// Update window titles of all users
229 // Should work on a list
230 void Buffer::updateTitles() const
233 users->owner()->updateWindowTitle();
237 /// Reset autosave timer of all users
238 // Should work on a list
239 void Buffer::resetAutosaveTimers() const
242 users->owner()->resetAutosaveTimer();
246 void Buffer::setFileName(string const & newfile)
248 filename_ = MakeAbsPath(newfile);
249 filepath_ = OnlyPath(filename_);
250 setReadonly(IsFileWriteable(filename_) == 0);
255 // We'll remove this later. (Lgb)
258 void unknownClass(string const & unknown)
262 boost::io::str(boost::format(
263 _("Using the default document class, because the "
264 " class %1$s is unknown.")) % unknown);
266 _("Using the default document class, because the "
267 " class ") + unknown + (" is unknown.");
269 Alert::warning(_("Unknown document class"), msg);
274 int Buffer::readHeader(LyXLex & lex)
276 int unknown_tokens = 0;
280 string const token = lex.getString();
285 if (token == "\\end_header")
288 lyxerr[Debug::PARSER] << "Handling header token: `"
289 << token << '\'' << endl;
291 string unknown = params.readToken(lex, token);
292 if (!unknown.empty()) {
293 if (unknown[0] != '\\') {
294 unknownClass(unknown);
300 return unknown_tokens;
304 // candidate for move to BufferView
305 // (at least some parts in the beginning of the func)
308 // changed to be public and have one parameter
309 // if par = 0 normal behavior
310 // else insert behavior
311 // Returns false if "\the_end" is not read (Asger)
312 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
314 int unknown_tokens = 0;
316 Paragraph::depth_type depth = 0;
317 bool the_end_read = false;
319 if (paragraphs.empty()) {
320 unknown_tokens += readHeader(lex);
322 if (!params.getLyXTextClass().load()) {
323 string theclass = params.getLyXTextClass().name();
326 boost::io::str(boost::format(
327 _("Using the default document class, because the "
328 " class %1$s could not be loaded.")) % theclass);
330 _("Using the default document class, because the "
331 " class ") + theclass + (" could not be loaded.");
333 Alert::error(_("Can't load document class"), msg);
334 params.textclass = 0;
337 // We are inserting into an existing document
338 users->text->breakParagraph(paragraphs);
340 // We don't want to adopt the parameters from the
341 // document we insert, so read them into a temporary buffer
342 // and then discard it
344 Buffer tmpbuf("", false);
345 tmpbuf.readHeader(lex);
350 string const token = lex.getString();
355 lyxerr[Debug::PARSER] << "Handling token: `"
356 << token << '\'' << endl;
358 if (token == "\\the_end") {
363 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
367 if (unknown_tokens > 0) {
370 if (unknown_tokens == 1) {
371 boost::format fmt(_("Encountered one unknown token when reading the document %1$s."));
375 boost::format fmt(_("Encountered %1$s unknown tokens when reading the document %2$s."));
376 fmt % tostr(unknown_tokens);
381 string s = _("Encountered ");
382 if (unknown_tokens == 1) {
383 s += _("one unknown token");
385 s += tostr(unknown_tokens);
386 s += _(" unknown tokens");
388 Alert::warning(_("Document format failure"), s);
397 Buffer::readParagraph(LyXLex & lex, string const & token,
398 ParagraphList & pars, ParagraphList::iterator & pit,
399 Paragraph::depth_type & depth)
401 static Change current_change;
404 if (token == "\\layout") {
405 lex.pushToken(token);
407 Paragraph * par = new Paragraph();
408 par->params().depth(depth);
409 if (params.tracking_changes)
411 LyXFont f(LyXFont::ALL_INHERIT, params.language);
414 // FIXME: goddamn InsetTabular makes us pass a Buffer
416 unknown += ::readParagraph(*this, *par, lex);
419 if (pit != pars.end())
421 pit = pars.insert(pit, par);
422 } else if (token == "\\begin_deeper") {
424 } else if (token == "\\end_deeper") {
426 lex.printError("\\end_deeper: " "depth is already null");
437 // needed to insert the selection
438 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
439 LyXFont const & fn,string const & str)
441 LyXLayout_ptr const & layout = par->layout();
445 par->checkInsertChar(font);
446 // insert the string, don't insert doublespace
447 bool space_inserted = true;
448 bool autobreakrows = !par->inInset() ||
449 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
450 for(string::const_iterator cit = str.begin();
451 cit != str.end(); ++cit) {
453 if (autobreakrows && (!par->empty() || layout->keepempty)) {
454 breakParagraph(params, paragraphs, par, pos,
455 layout->isEnvironment());
458 space_inserted = true;
462 // do not insert consecutive spaces if !free_spacing
463 } else if ((*cit == ' ' || *cit == '\t') &&
464 space_inserted && !layout->free_spacing &&
465 !par->isFreeSpacing())
468 } else if (*cit == '\t') {
469 if (!layout->free_spacing && !par->isFreeSpacing()) {
470 // tabs are like spaces here
471 par->insertChar(pos, ' ', font);
473 space_inserted = true;
475 const pos_type nb = 8 - pos % 8;
476 for (pos_type a = 0; a < nb ; ++a) {
477 par->insertChar(pos, ' ', font);
480 space_inserted = true;
482 } else if (!IsPrintable(*cit)) {
483 // Ignore unprintables
486 // just insert the character
487 par->insertChar(pos, *cit, font);
489 space_inserted = (*cit == ' ');
496 bool Buffer::readFile(LyXLex & lex, string const & filename)
498 bool ret = readFile(lex, filename, paragraphs.begin());
500 // After we have read a file, we must ensure that the buffer
501 // language is set and used in the gui.
502 // If you know of a better place to put this, please tell me. (Lgb)
503 messages_.reset(new Messages(params.language->code(),
504 "/usr/local/share/locale"));
510 // FIXME: all the below Alerts should give the filename..
511 bool Buffer::readFile(LyXLex & lex, string const & filename,
512 ParagraphList::iterator pit)
515 Alert::error(_("Document could not be read"),
516 _("The specified document could not be read."));
521 string const token(lex.getString());
524 Alert::error(_("Document could not be read"),
525 _("The specified document could not be read."));
529 // the first token _must_ be...
530 if (token != "\\lyxformat") {
531 Alert::error(_("Document format failure"),
532 _("The specified document is not a LyX document."));
537 string tmp_format = lex.getString();
538 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
539 // if present remove ".," from string.
540 string::size_type dot = tmp_format.find_first_of(".,");
541 //lyxerr << " dot found at " << dot << endl;
542 if (dot != string::npos)
543 tmp_format.erase(dot, 1);
544 file_format = strToInt(tmp_format);
545 //lyxerr << "format: " << file_format << endl;
546 if (file_format == LYX_FORMAT) {
548 } else if (file_format > LYX_FORMAT) {
549 Alert::warning(_("Document format failure"),
550 _("This document was created with a newer version of "
551 "LyX. This is likely to cause problems."));
552 } else if (file_format < LYX_FORMAT) {
554 if (file_format < 200) {
555 Alert::error(_("Document format failure"),
556 _("This LyX document is too old to be read "
557 "by this version of LyX. Try LyX 0.10."));
559 } else if (!filename.empty()) {
561 LibFileSearch("lyx2lyx", "lyx2lyx");
562 if (command.empty()) {
563 Alert::error(_("Conversion script not found"),
564 _("The document is from an earlier version "
565 "of LyX, but the conversion script lyx2lyx "
566 "could not be found."));
570 +tostr(LYX_FORMAT) + ' '
571 + QuoteName(filename);
572 lyxerr[Debug::INFO] << "Running '"
575 cmd_ret const ret = RunCommand(command);
577 Alert::error(_("Conversion script failed"),
578 _("The document is from an earlier version "
579 "of LyX, but the lyx2lyx script failed "
583 istringstream is(STRCONV(ret.second));
585 tmplex.setStream(is);
586 return readFile(tmplex, string(), pit);
588 // This code is reached if lyx2lyx failed (for
589 // some reason) to change the file format of
595 bool the_end = readBody(lex, pit);
596 params.setPaperStuff();
599 Alert::error(_("Document format failure"),
600 _("The document ended unexpectedly, which means "
601 "that it is probably corrupted."));
607 // Should probably be moved to somewhere else: BufferView? LyXView?
608 bool Buffer::save() const
610 // We don't need autosaves in the immediate future. (Asger)
611 resetAutosaveTimers();
615 if (lyxrc.make_backup) {
616 s = fileName() + '~';
617 if (!lyxrc.backupdir_path.empty())
618 s = AddName(lyxrc.backupdir_path,
619 subst(os::slashify_path(s),'/','!'));
621 // Rename is the wrong way of making a backup,
622 // this is the correct way.
623 /* truss cp fil fil2:
624 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
625 stat("LyXVC.lyx", 0xEFFFF688) = 0
626 open("LyXVC.lyx", O_RDONLY) = 3
627 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
628 fstat(4, 0xEFFFF508) = 0
629 fstat(3, 0xEFFFF508) = 0
630 read(3, " # T h i s f i l e w".., 8192) = 5579
631 write(4, " # T h i s f i l e w".., 5579) = 5579
632 read(3, 0xEFFFD4A0, 8192) = 0
635 chmod("LyXVC3.lyx", 0100644) = 0
636 lseek(0, 0, SEEK_CUR) = 46440
640 // Should probably have some more error checking here.
641 // Doing it this way, also makes the inodes stay the same.
642 // This is still not a very good solution, in particular we
643 // might loose the owner of the backup.
644 FileInfo finfo(fileName());
646 mode_t fmode = finfo.getMode();
647 struct utimbuf times = {
648 finfo.getAccessTime(),
649 finfo.getModificationTime() };
651 ifstream ifs(fileName().c_str());
652 ofstream ofs(s.c_str(), ios::out|ios::trunc);
657 ::chmod(s.c_str(), fmode);
659 if (::utime(s.c_str(), ×)) {
660 lyxerr << "utime error." << endl;
663 lyxerr << "LyX was not able to make "
664 "backup copy. Beware." << endl;
669 if (writeFile(fileName())) {
671 removeAutosaveFile(fileName());
673 // Saving failed, so backup is not backup
674 if (lyxrc.make_backup) {
675 lyx::rename(s, fileName());
683 bool Buffer::writeFile(string const & fname) const
685 if (read_only && (fname == fileName())) {
689 FileInfo finfo(fname);
690 if (finfo.exist() && !finfo.writable()) {
694 ofstream ofs(fname.c_str());
700 // Use the standard "C" locale for file output.
701 ofs.imbue(std::locale::classic());
704 // The top of the file should not be written by params.
706 // write out a comment in the top of the file
707 ofs << '#' << lyx_docversion
708 << " created this file. For more info see http://www.lyx.org/\n"
709 << "\\lyxformat " << LYX_FORMAT << "\n";
711 // now write out the buffer paramters.
712 params.writeFile(ofs);
714 ofs << "\\end_header\n";
716 Paragraph::depth_type depth = 0;
718 // this will write out all the paragraphs
719 // using recursive descent.
720 ParagraphList::iterator pit = paragraphs.begin();
721 ParagraphList::iterator pend = paragraphs.end();
722 for (; pit != pend; ++pit)
723 pit->write(this, ofs, params, depth);
725 // Write marker that shows file is complete
726 ofs << "\n\\the_end" << endl;
730 // how to check if close went ok?
731 // Following is an attempt... (BE 20001011)
733 // good() returns false if any error occured, including some
735 // bad() returns true if something bad happened in the buffer,
736 // which should include file system full errors.
743 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
745 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
757 pair<int, string> const addDepth(int depth, int ldepth)
761 d += (ldepth - depth) * 2;
762 return make_pair(d, string(d, ' '));
768 string const Buffer::asciiParagraph(Paragraph const & par,
769 unsigned int linelen,
770 bool noparbreak) const
772 ostringstream buffer;
773 Paragraph::depth_type depth = 0;
775 Paragraph::depth_type ltype_depth = 0;
776 bool ref_printed = false;
777 // if (!par->previous()) {
779 // begins or ends a deeper area ?
780 if (depth != par->params().depth()) {
781 if (par->params().depth() > depth) {
782 while (par->params().depth() > depth) {
786 while (par->params().depth() < depth) {
792 depth = par.params().depth();
795 // First write the layout
796 string const & tmp = par.layout()->name();
797 if (compare_no_case(tmp, "itemize") == 0) {
799 ltype_depth = depth + 1;
800 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
802 ltype_depth = depth + 1;
803 } else if (contains(ascii_lowercase(tmp), "ection")) {
805 ltype_depth = depth + 1;
806 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
808 ltype_depth = depth + 1;
809 } else if (compare_ascii_no_case(tmp, "description") == 0) {
811 ltype_depth = depth + 1;
812 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
815 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
823 /* maybe some vertical spaces */
825 /* the labelwidthstring used in lists */
829 /* some pagebreaks? */
833 /* what about the alignment */
835 // linelen <= 0 is special and means we don't have paragraph breaks
837 string::size_type currlinelen = 0;
843 buffer << string(depth * 2, ' ');
844 currlinelen += depth * 2;
847 // we should probably change to the paragraph language in the
848 // gettext here (if possible) so that strings are outputted in
849 // the correct language! (20012712 Jug)
853 case 4: // (Sub)Paragraph
854 case 5: // Description
858 buffer << _("Abstract") << "\n\n";
861 string const abst = _("Abstract: ");
863 currlinelen += abst.length();
866 case 7: // Bibliography
869 buffer << _("References") << "\n\n";
872 string const refs = _("References: ");
874 currlinelen += refs.length();
882 string const parlab = par.params().labelString();
883 buffer << parlab << ' ';
884 currlinelen += parlab.length() + 1;
892 pair<int, string> p = addDepth(depth, ltype_depth);
894 currlinelen += p.first;
897 // this is to change the linebreak to do it by word a bit more
898 // intelligent hopefully! (only in the case where we have a
899 // max linelength!) (Jug)
903 for (pos_type i = 0; i < par.size(); ++i) {
904 char c = par.getUChar(params, i);
906 case Paragraph::META_INSET:
908 Inset const * inset = par.getInset(i);
912 currlinelen += word.length();
915 if (inset->ascii(this, buffer, linelen)) {
916 // to be sure it breaks paragraph
917 currlinelen += linelen;
926 currlinelen + word.length() > linelen - 10) {
928 pair<int, string> p = addDepth(depth, ltype_depth);
930 currlinelen = p.first;
933 buffer << word << ' ';
934 currlinelen += word.length() + 1;
941 lyxerr[Debug::INFO] <<
942 "writeAsciiFile: NULL char in structure." << endl;
945 (currlinelen + word.length()) > linelen)
949 pair<int, string> p =
950 addDepth(depth, ltype_depth);
952 currlinelen = p.first;
959 return STRCONV(buffer.str());
963 void Buffer::writeFileAscii(string const & fname, int linelen)
965 ofstream ofs(fname.c_str());
967 string const file = MakeDisplayPath(fname, 50);
969 boost::format fmt(_("Could not save the document\n%1$s."));
971 string text = fmt.str();
973 string text = _("Could not save the document\n");
976 Alert::error(_("Could not save document"), text);
979 writeFileAscii(ofs, linelen);
983 void Buffer::writeFileAscii(ostream & os, int linelen)
985 ParagraphList::iterator beg = paragraphs.begin();
986 ParagraphList::iterator end = paragraphs.end();
987 ParagraphList::iterator it = beg;
988 for (; it != end; ++it) {
989 os << asciiParagraph(*it, linelen, it == beg);
996 void Buffer::makeLaTeXFile(string const & fname,
997 string const & original_path,
998 bool nice, bool only_body, bool only_preamble)
1000 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1002 ofstream ofs(fname.c_str());
1004 string const file = MakeDisplayPath(fname, 50);
1005 #if USE_BOOST_FORMAT
1006 boost::format fmt(_("Could not open the specified document\n%1$s."));
1008 string text = fmt.str();
1010 string text = _("Could not open the specified document\n");
1013 Alert::error(_("Could not open file"), text);
1017 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1021 lyxerr << "File was not closed properly." << endl;
1026 void Buffer::makeLaTeXFile(ostream & os,
1027 string const & original_path,
1028 bool nice, bool only_body, bool only_preamble)
1030 niceFile = nice; // this will be used by Insetincludes.
1032 // validate the buffer.
1033 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1034 LaTeXFeatures features(params);
1036 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1039 // The starting paragraph of the coming rows is the
1040 // first paragraph of the document. (Asger)
1041 texrow.start(&*(paragraphs.begin()), 0);
1043 if (!only_body && nice) {
1044 os << "%% " << lyx_docversion << " created this file. "
1045 "For more info, see http://www.lyx.org/.\n"
1046 "%% Do not edit unless you really know what "
1051 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1052 // There are a few differences between nice LaTeX and usual files:
1053 // usual is \batchmode and has a
1054 // special input@path to allow the including of figures
1055 // with either \input or \includegraphics (what figinsets do).
1056 // input@path is set when the actual parameter
1057 // original_path is set. This is done for usual tex-file, but not
1058 // for nice-latex-file. (Matthias 250696)
1061 // code for usual, NOT nice-latex-file
1062 os << "\\batchmode\n"; // changed
1063 // from \nonstopmode
1066 if (!original_path.empty()) {
1067 string inputpath = os::external_path(original_path);
1068 subst(inputpath, "~", "\\string~");
1069 os << "\\makeatletter\n"
1070 << "\\def\\input@path{{"
1071 << inputpath << "/}}\n"
1072 << "\\makeatother\n";
1078 // Write the preamble
1079 params.writeLaTeX(os, features, texrow);
1085 os << "\\begin{document}\n";
1088 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1090 if (!lyxrc.language_auto_begin) {
1091 os << subst(lyxrc.language_command_begin, "$$lang",
1092 params.language->babel())
1097 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1099 // add this just in case after all the paragraphs
1103 if (!lyxrc.language_auto_end) {
1104 os << subst(lyxrc.language_command_end, "$$lang",
1105 params.language->babel())
1111 os << "\\end{document}\n";
1114 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1116 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1120 // Just to be sure. (Asger)
1123 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1124 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1127 // we want this to be true outside previews (for insetexternal)
1132 bool Buffer::isLatex() const
1134 return params.getLyXTextClass().outputType() == LATEX;
1138 bool Buffer::isLinuxDoc() const
1140 return params.getLyXTextClass().outputType() == LINUXDOC;
1144 bool Buffer::isLiterate() const
1146 return params.getLyXTextClass().outputType() == LITERATE;
1150 bool Buffer::isDocBook() const
1152 return params.getLyXTextClass().outputType() == DOCBOOK;
1156 bool Buffer::isSGML() const
1158 LyXTextClass const & tclass = params.getLyXTextClass();
1160 return tclass.outputType() == LINUXDOC ||
1161 tclass.outputType() == DOCBOOK;
1165 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1167 ofstream ofs(fname.c_str());
1170 string const file = MakeDisplayPath(fname, 50);
1171 #if USE_BOOST_FORMAT
1172 boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
1174 string text = fmt.str();
1176 string text = _("Could not save the specified document\n");
1177 text += file + _(".\n");
1179 Alert::error(_("Could not save document"), text);
1183 niceFile = nice; // this will be used by included files.
1185 LaTeXFeatures features(params);
1191 LyXTextClass const & tclass = params.getLyXTextClass();
1193 string top_element = tclass.latexname();
1196 ofs << "<!doctype linuxdoc system";
1198 string preamble = params.preamble;
1199 const string name = nice ? ChangeExtension(filename_, ".sgml")
1201 preamble += features.getIncludedFiles(name);
1202 preamble += features.getLyXSGMLEntities();
1204 if (!preamble.empty()) {
1205 ofs << " [ " << preamble << " ]";
1209 if (params.options.empty())
1210 sgml::openTag(ofs, 0, false, top_element);
1212 string top = top_element;
1214 top += params.options;
1215 sgml::openTag(ofs, 0, false, top);
1219 ofs << "<!-- " << lyx_docversion
1220 << " created this file. For more info see http://www.lyx.org/"
1223 Paragraph::depth_type depth = 0; // paragraph depth
1225 vector<string> environment_stack(5);
1227 ParagraphList::iterator pit = paragraphs.begin();
1228 ParagraphList::iterator pend = paragraphs.end();
1229 for (; pit != pend; ++pit) {
1230 LyXLayout_ptr const & style = pit->layout();
1231 // treat <toc> as a special case for compatibility with old code
1232 if (pit->isInset(0)) {
1233 Inset * inset = pit->getInset(0);
1234 Inset::Code lyx_code = inset->lyxCode();
1235 if (lyx_code == Inset::TOC_CODE) {
1236 string const temp = "toc";
1237 sgml::openTag(ofs, depth, false, temp);
1242 // environment tag closing
1243 for (; depth > pit->params().depth(); --depth) {
1244 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1245 environment_stack[depth].erase();
1248 // write opening SGML tags
1249 switch (style->latextype) {
1250 case LATEX_PARAGRAPH:
1251 if (depth == pit->params().depth()
1252 && !environment_stack[depth].empty()) {
1253 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1254 environment_stack[depth].erase();
1260 sgml::openTag(ofs, depth, false, style->latexname());
1266 _("Error: Wrong depth for LatexType Command.\n"));
1268 if (!environment_stack[depth].empty()) {
1269 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1273 environment_stack[depth].erase();
1274 sgml::openTag(ofs, depth, false, style->latexname());
1277 case LATEX_ENVIRONMENT:
1278 case LATEX_ITEM_ENVIRONMENT:
1279 case LATEX_BIB_ENVIRONMENT:
1281 string const & latexname = style->latexname();
1283 if (depth == pit->params().depth()
1284 && environment_stack[depth] != latexname) {
1285 sgml::closeTag(ofs, depth, false,
1286 environment_stack[depth]);
1287 environment_stack[depth].erase();
1289 if (depth < pit->params().depth()) {
1290 depth = pit->params().depth();
1291 environment_stack[depth].erase();
1293 if (environment_stack[depth] != latexname) {
1295 sgml::openTag(ofs, depth, false, "p");
1297 sgml::openTag(ofs, depth, false, latexname);
1299 if (environment_stack.size() == depth + 1)
1300 environment_stack.push_back("!-- --");
1301 environment_stack[depth] = latexname;
1304 if (style->latexparam() == "CDATA")
1307 if (style->latextype == LATEX_ENVIRONMENT) break;
1309 if (style->labeltype == LABEL_MANUAL)
1314 sgml::openTag(ofs, depth + 1, false, item_name);
1319 sgml::openTag(ofs, depth, false, style->latexname());
1323 simpleLinuxDocOnePar(ofs, &*pit, depth);
1326 // write closing SGML tags
1327 switch (style->latextype) {
1330 case LATEX_ENVIRONMENT:
1331 case LATEX_ITEM_ENVIRONMENT:
1332 case LATEX_BIB_ENVIRONMENT:
1333 if (style->latexparam() == "CDATA")
1337 sgml::closeTag(ofs, depth, false, style->latexname());
1343 for (int i = depth; i >= 0; --i)
1344 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1348 sgml::closeTag(ofs, 0, false, top_element);
1352 // How to check for successful close
1354 // we want this to be true outside previews (for insetexternal)
1359 // checks, if newcol chars should be put into this line
1360 // writes newline, if necessary.
1363 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1364 string::size_type newcol)
1367 if (colcount > lyxrc.ascii_linelen) {
1369 colcount = newcol; // assume write after this call
1384 string tag_name(PAR_TAG const & pt) {
1386 case NONE: return "!-- --";
1387 case TT: return "tt";
1388 case SF: return "sf";
1389 case BF: return "bf";
1390 case IT: return "it";
1391 case SL: return "sl";
1392 case EM: return "em";
1399 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1401 p1 = static_cast<PAR_TAG>(p1 | p2);
1406 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1408 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1414 // Handle internal paragraph parsing -- layout already processed.
1415 void Buffer::simpleLinuxDocOnePar(ostream & os,
1417 Paragraph::depth_type /*depth*/)
1419 LyXLayout_ptr const & style = par->layout();
1421 string::size_type char_line_count = 5; // Heuristic choice ;-)
1423 // gets paragraph main font
1426 if (style->labeltype == LABEL_MANUAL) {
1427 font_old = style->labelfont;
1430 font_old = style->font;
1434 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1435 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1436 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1439 stack<PAR_TAG> tag_state;
1440 // parsing main loop
1441 for (pos_type i = 0; i < par->size(); ++i) {
1443 PAR_TAG tag_close = NONE;
1444 list < PAR_TAG > tag_open;
1446 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1448 if (font_old.family() != font.family()) {
1449 switch (family_type) {
1450 case LyXFont::SANS_FAMILY:
1453 case LyXFont::TYPEWRITER_FAMILY:
1460 family_type = font.family();
1462 switch (family_type) {
1463 case LyXFont::SANS_FAMILY:
1464 tag_open.push_back(SF);
1466 case LyXFont::TYPEWRITER_FAMILY:
1467 tag_open.push_back(TT);
1474 if (font_old.series() != font.series()) {
1475 switch (series_type) {
1476 case LyXFont::BOLD_SERIES:
1483 series_type = font.series();
1485 switch (series_type) {
1486 case LyXFont::BOLD_SERIES:
1487 tag_open.push_back(BF);
1495 if (font_old.shape() != font.shape()) {
1496 switch (shape_type) {
1497 case LyXFont::ITALIC_SHAPE:
1500 case LyXFont::SLANTED_SHAPE:
1507 shape_type = font.shape();
1509 switch (shape_type) {
1510 case LyXFont::ITALIC_SHAPE:
1511 tag_open.push_back(IT);
1513 case LyXFont::SLANTED_SHAPE:
1514 tag_open.push_back(SL);
1521 if (font_old.emph() != font.emph()) {
1522 if (font.emph() == LyXFont::ON) {
1523 tag_open.push_back(EM);
1532 list < PAR_TAG > temp;
1533 while (!tag_state.empty() && tag_close) {
1534 PAR_TAG k = tag_state.top();
1536 os << "</" << tag_name(k) << '>';
1543 for(list< PAR_TAG >::const_iterator j = temp.begin();
1544 j != temp.end(); ++j) {
1546 os << '<' << tag_name(*j) << '>';
1549 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1550 j != tag_open.end(); ++j) {
1552 os << '<' << tag_name(*j) << '>';
1555 char c = par->getChar(i);
1557 if (c == Paragraph::META_INSET) {
1558 Inset * inset = par->getInset(i);
1559 inset->linuxdoc(this, os);
1564 if (style->latexparam() == "CDATA") {
1565 // "TeX"-Mode on == > SGML-Mode on.
1572 boost::tie(ws, str) = sgml::escapeChar(c);
1573 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1574 // in freespacing mode, spaces are
1575 // non-breaking characters
1576 if (desc_on) {// if char is ' ' then...
1579 sgmlLineBreak(os, char_line_count, 6);
1583 sgmlLineBreak(os, char_line_count, 1);
1588 char_line_count += str.length();
1594 while (!tag_state.empty()) {
1595 os << "</" << tag_name(tag_state.top()) << '>';
1599 // resets description flag correctly
1601 // <tag> not closed...
1602 sgmlLineBreak(os, char_line_count, 6);
1608 // Print an error message.
1609 void Buffer::sgmlError(ParagraphList::iterator /*par*/, int /*pos*/,
1610 string const & /*message*/) const
1612 #ifdef WITH_WARNINGS
1613 #warning This is wrong we cannot insert an inset like this!!!
1614 // I guess this was Jose' so I explain you more or less why this
1615 // is wrong. This way you insert something in the paragraph and
1616 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1617 // I deactivate this code, have a look at BufferView::insertErrors
1618 // how you should do this correctly! (Jug 20020315)
1621 // insert an error marker in text
1622 InsetError * new_inset = new InsetError(message);
1623 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1629 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1631 ofstream ofs(fname.c_str());
1633 string const file = MakeDisplayPath(fname, 50);
1634 #if USE_BOOST_FORMAT
1635 boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
1637 string text = fmt.str();
1639 string text = _("Could not save the specified document\n");
1640 text += file + _(".\n");
1642 Alert::error(_("Could not save document"), text);
1646 niceFile = nice; // this will be used by Insetincludes.
1648 LaTeXFeatures features(params);
1653 LyXTextClass const & tclass = params.getLyXTextClass();
1654 string top_element = tclass.latexname();
1657 ofs << "<!DOCTYPE " << top_element
1658 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1660 string preamble = params.preamble;
1661 const string name = nice ? ChangeExtension(filename_, ".sgml")
1663 preamble += features.getIncludedFiles(name);
1664 preamble += features.getLyXSGMLEntities();
1666 if (!preamble.empty()) {
1667 ofs << "\n [ " << preamble << " ]";
1672 string top = top_element;
1674 top += params.language->code();
1677 if (!params.options.empty()) {
1679 top += params.options;
1681 sgml::openTag(ofs, 0, false, top);
1683 ofs << "<!-- DocBook file was created by " << lyx_docversion
1684 << "\n See http://www.lyx.org/ for more information -->\n";
1686 vector<string> environment_stack(10);
1687 vector<string> environment_inner(10);
1688 vector<string> command_stack(10);
1690 bool command_flag = false;
1691 Paragraph::depth_type command_depth = 0;
1692 Paragraph::depth_type command_base = 0;
1693 Paragraph::depth_type cmd_depth = 0;
1694 Paragraph::depth_type depth = 0; // paragraph depth
1697 string command_name;
1699 ParagraphList::iterator par = paragraphs.begin();
1700 ParagraphList::iterator pend = paragraphs.end();
1702 for (; par != pend; ++par) {
1706 int desc_on = 0; // description mode
1708 LyXLayout_ptr const & style = par->layout();
1710 // environment tag closing
1711 for (; depth > par->params().depth(); --depth) {
1712 if (environment_inner[depth] != "!-- --") {
1713 item_name = "listitem";
1714 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1715 if (environment_inner[depth] == "varlistentry")
1716 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1718 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1719 environment_stack[depth].erase();
1720 environment_inner[depth].erase();
1723 if (depth == par->params().depth()
1724 && environment_stack[depth] != style->latexname()
1725 && !environment_stack[depth].empty()) {
1726 if (environment_inner[depth] != "!-- --") {
1727 item_name= "listitem";
1728 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1729 if (environment_inner[depth] == "varlistentry")
1730 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1733 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1735 environment_stack[depth].erase();
1736 environment_inner[depth].erase();
1739 // Write opening SGML tags.
1740 switch (style->latextype) {
1741 case LATEX_PARAGRAPH:
1742 sgml::openTag(ofs, depth + command_depth,
1743 false, style->latexname());
1749 _("Error: Wrong depth for LatexType Command.\n"));
1751 command_name = style->latexname();
1753 sgmlparam = style->latexparam();
1754 c_params = split(sgmlparam, c_depth,'|');
1756 cmd_depth = lyx::atoi(c_depth);
1759 if (cmd_depth < command_base) {
1760 for (Paragraph::depth_type j = command_depth;
1761 j >= command_base; --j) {
1762 sgml::closeTag(ofs, j, false, command_stack[j]);
1765 command_depth = command_base = cmd_depth;
1766 } else if (cmd_depth <= command_depth) {
1767 for (int j = command_depth;
1768 j >= int(cmd_depth); --j) {
1769 sgml::closeTag(ofs, j, false, command_stack[j]);
1772 command_depth = cmd_depth;
1774 command_depth = cmd_depth;
1776 command_depth = command_base = cmd_depth;
1777 command_flag = true;
1779 if (command_stack.size() == command_depth + 1)
1780 command_stack.push_back(string());
1781 command_stack[command_depth] = command_name;
1783 // treat label as a special case for
1784 // more WYSIWYM handling.
1785 // This is a hack while paragraphs can't have
1786 // attributes, like id in this case.
1787 if (par->isInset(0)) {
1788 Inset * inset = par->getInset(0);
1789 Inset::Code lyx_code = inset->lyxCode();
1790 if (lyx_code == Inset::LABEL_CODE) {
1791 command_name += " id=\"";
1792 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1793 command_name += '"';
1798 sgml::openTag(ofs, depth + command_depth, false, command_name);
1800 item_name = c_params.empty() ? "title" : c_params;
1801 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1804 case LATEX_ENVIRONMENT:
1805 case LATEX_ITEM_ENVIRONMENT:
1806 if (depth < par->params().depth()) {
1807 depth = par->params().depth();
1808 environment_stack[depth].erase();
1811 if (environment_stack[depth] != style->latexname()) {
1812 if (environment_stack.size() == depth + 1) {
1813 environment_stack.push_back("!-- --");
1814 environment_inner.push_back("!-- --");
1816 environment_stack[depth] = style->latexname();
1817 environment_inner[depth] = "!-- --";
1818 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1820 if (environment_inner[depth] != "!-- --") {
1821 item_name= "listitem";
1822 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1823 if (environment_inner[depth] == "varlistentry")
1824 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1828 if (style->latextype == LATEX_ENVIRONMENT) {
1829 if (!style->latexparam().empty()) {
1830 if (style->latexparam() == "CDATA")
1833 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1838 desc_on = (style->labeltype == LABEL_MANUAL);
1840 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1841 sgml::openTag(ofs, depth + 1 + command_depth,
1842 false, environment_inner[depth]);
1844 item_name = desc_on ? "term" : "para";
1845 sgml::openTag(ofs, depth + 1 + command_depth,
1849 sgml::openTag(ofs, depth + command_depth,
1850 false, style->latexname());
1854 simpleDocBookOnePar(ofs, par, desc_on,
1855 depth + 1 + command_depth);
1858 // write closing SGML tags
1859 switch (style->latextype) {
1861 end_tag = c_params.empty() ? "title" : c_params;
1862 sgml::closeTag(ofs, depth + command_depth,
1865 case LATEX_ENVIRONMENT:
1866 if (!style->latexparam().empty()) {
1867 if (style->latexparam() == "CDATA")
1870 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1873 case LATEX_ITEM_ENVIRONMENT:
1874 if (desc_on == 1) break;
1876 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1878 case LATEX_PARAGRAPH:
1879 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1882 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1888 for (int d = depth; d >= 0; --d) {
1889 if (!environment_stack[depth].empty()) {
1890 if (environment_inner[depth] != "!-- --") {
1891 item_name = "listitem";
1892 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1893 if (environment_inner[depth] == "varlistentry")
1894 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1897 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1901 for (int j = command_depth; j >= 0 ; --j)
1902 if (!command_stack[j].empty()) {
1903 sgml::closeTag(ofs, j, false, command_stack[j]);
1908 sgml::closeTag(ofs, 0, false, top_element);
1911 // How to check for successful close
1913 // we want this to be true outside previews (for insetexternal)
1918 void Buffer::simpleDocBookOnePar(ostream & os,
1919 ParagraphList::iterator par, int & desc_on,
1920 Paragraph::depth_type depth) const
1922 bool emph_flag = false;
1924 LyXLayout_ptr const & style = par->layout();
1926 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1928 int char_line_count = depth;
1929 //if (!style.free_spacing)
1930 // os << string(depth,' ');
1932 // parsing main loop
1933 for (pos_type i = 0; i < par->size(); ++i) {
1934 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1936 // handle <emphasis> tag
1937 if (font_old.emph() != font.emph()) {
1938 if (font.emph() == LyXFont::ON) {
1939 if (style->latexparam() == "CDATA")
1942 if (style->latexparam() == "CDATA")
1946 if (style->latexparam() == "CDATA")
1948 os << "</emphasis>";
1949 if (style->latexparam() == "CDATA")
1956 if (par->isInset(i)) {
1957 Inset * inset = par->getInset(i);
1958 // don't print the inset in position 0 if desc_on == 3 (label)
1959 if (i || desc_on != 3) {
1960 if (style->latexparam() == "CDATA")
1962 inset->docbook(this, os, false);
1963 if (style->latexparam() == "CDATA")
1967 char c = par->getChar(i);
1970 boost::tie(ws, str) = sgml::escapeChar(c);
1972 if (style->pass_thru) {
1974 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1976 } else if (desc_on ==1) {
1978 os << "\n</term><listitem><para>";
1988 if (style->latexparam() == "CDATA")
1990 os << "</emphasis>";
1991 if (style->latexparam() == "CDATA")
1995 // resets description flag correctly
1997 // <term> not closed...
1998 os << "</term>\n<listitem><para> </para>";
2000 if (style->free_spacing)
2005 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2006 // Other flags: -wall -v0 -x
2007 int Buffer::runChktex()
2009 if (!users->text) return 0;
2011 users->owner()->busy(true);
2013 // get LaTeX-Filename
2014 string const name = getLatexName();
2015 string path = filePath();
2017 string const org_path = path;
2018 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2022 Path p(path); // path to LaTeX file
2023 users->owner()->message(_("Running chktex..."));
2025 // Remove all error insets
2026 bool const removedErrorInsets = users->removeAutoInsets();
2028 // Generate the LaTeX file if neccessary
2029 makeLaTeXFile(name, org_path, false);
2032 Chktex chktex(lyxrc.chktex_command, name, filePath());
2033 int res = chktex.run(terr); // run chktex
2036 Alert::error(_("chktex failure"),
2037 _("Could not run chktex successfully."));
2038 } else if (res > 0) {
2039 // Insert all errors as errors boxes
2040 users->insertErrors(terr);
2043 // if we removed error insets before we ran chktex or if we inserted
2044 // error insets after we ran chktex, this must be run:
2045 if (removedErrorInsets || res) {
2046 #warning repaint needed here, or do you mean update() ?
2050 users->owner()->busy(false);
2056 void Buffer::validate(LaTeXFeatures & features) const
2058 LyXTextClass const & tclass = params.getLyXTextClass();
2060 if (params.tracking_changes) {
2061 features.require("dvipost");
2062 features.require("color");
2065 // AMS Style is at document level
2066 if (params.use_amsmath == BufferParams::AMS_ON
2067 || tclass.provides(LyXTextClass::amsmath))
2068 features.require("amsmath");
2070 for_each(paragraphs.begin(), paragraphs.end(),
2071 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2073 // the bullet shapes are buffer level not paragraph level
2074 // so they are tested here
2075 for (int i = 0; i < 4; ++i) {
2076 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2077 int const font = params.user_defined_bullets[i].getFont();
2079 int const c = params
2080 .user_defined_bullets[i]
2087 features.require("latexsym");
2089 } else if (font == 1) {
2090 features.require("amssymb");
2091 } else if ((font >= 2 && font <= 5)) {
2092 features.require("pifont");
2097 if (lyxerr.debugging(Debug::LATEX)) {
2098 features.showStruct();
2103 vector<string> const Buffer::getLabelList() const
2105 /// if this is a child document and the parent is already loaded
2106 /// Use the parent's list instead [ale990407]
2107 if (!params.parentname.empty()
2108 && bufferlist.exists(params.parentname)) {
2109 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2111 return tmp->getLabelList();
2114 vector<string> label_list;
2115 for (inset_iterator it = inset_const_iterator_begin();
2116 it != inset_const_iterator_end(); ++it) {
2117 vector<string> const l = it->getLabelList();
2118 label_list.insert(label_list.end(), l.begin(), l.end());
2124 // This is also a buffer property (ale)
2125 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2127 /// if this is a child document and the parent is already loaded
2128 /// use the parent's list instead [ale990412]
2129 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2130 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2132 tmp->fillWithBibKeys(keys);
2137 for (inset_iterator it = inset_const_iterator_begin();
2138 it != inset_const_iterator_end(); ++it) {
2139 if (it->lyxCode() == Inset::BIBTEX_CODE)
2140 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2141 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2142 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2143 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2144 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2145 string const key = bib.getContents();
2146 string const opt = bib.getOptions();
2147 string const ref; // = pit->asString(this, false);
2148 string const info = opt + "TheBibliographyRef" + ref;
2149 keys.push_back(pair<string, string>(key, info));
2155 bool Buffer::isDepClean(string const & name) const
2157 DepClean::const_iterator it = dep_clean_.find(name);
2158 if (it == dep_clean_.end())
2164 void Buffer::markDepClean(string const & name)
2166 dep_clean_[name] = true;
2170 bool Buffer::dispatch(string const & command, bool * result)
2172 // Split command string into command and argument
2174 string line = ltrim(command);
2175 string const arg = trim(split(line, cmd, ' '));
2177 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2181 bool Buffer::dispatch(int action, string const & argument, bool * result)
2183 bool dispatched = true;
2187 bool const tmp = Exporter::Export(this, argument, false);
2200 void Buffer::resizeInsets(BufferView * bv)
2202 /// then remove all LyXText in text-insets
2203 for_each(paragraphs.begin(), paragraphs.end(),
2204 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2208 void Buffer::redraw()
2210 #warning repaint needed here, or do you mean update() ?
2216 void Buffer::changeLanguage(Language const * from, Language const * to)
2218 // Take care of l10n/i18n
2219 messages_.reset(new Messages(to->code(), "/usr/local/share/locale"));
2221 ParIterator end = par_iterator_end();
2222 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2223 (*it)->changeLanguage(params, from, to);
2227 bool Buffer::isMultiLingual()
2229 ParIterator end = par_iterator_end();
2230 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2231 if ((*it)->isMultiLingual(params))
2238 void Buffer::inset_iterator::setParagraph()
2240 while (pit != pend) {
2241 it = pit->insetlist.begin();
2242 if (it != pit->insetlist.end())
2249 Inset * Buffer::getInsetFromID(int id_arg) const
2251 for (inset_iterator it = inset_const_iterator_begin();
2252 it != inset_const_iterator_end(); ++it)
2254 if (it->id() == id_arg)
2256 Inset * in = it->getInsetFromID(id_arg);
2264 Paragraph * Buffer::getParFromID(int id) const
2269 // why should we allow < 0 ??
2270 //lyx::Assert(id >= 0);
2272 ParConstIterator it(par_iterator_begin());
2273 ParConstIterator end(par_iterator_end());
2275 for (; it != end; ++it) {
2276 // go on then, show me how to remove
2278 if ((*it)->id() == id) {
2279 return const_cast<Paragraph*>(*it);
2287 ParIterator Buffer::par_iterator_begin()
2289 return ParIterator(&*(paragraphs.begin()));
2293 ParIterator Buffer::par_iterator_end()
2295 return ParIterator();
2298 ParConstIterator Buffer::par_iterator_begin() const
2300 return ParConstIterator(&*(paragraphs.begin()));
2304 ParConstIterator Buffer::par_iterator_end() const
2306 return ParConstIterator();
2311 void Buffer::addUser(BufferView * u)
2317 void Buffer::delUser(BufferView *)
2323 Language const * Buffer::getLanguage() const
2325 return params.language;
2329 string const Buffer::B_(string const & l10n) const
2331 if (messages_.get()) {
2332 return messages_->get(l10n);
2339 bool Buffer::isClean() const
2345 bool Buffer::isBakClean() const
2351 void Buffer::markClean() const
2357 // if the .lyx file has been saved, we don't need an
2363 void Buffer::markBakClean()
2369 void Buffer::setUnnamed(bool flag)
2375 bool Buffer::isUnnamed()
2381 void Buffer::markDirty()
2389 DepClean::iterator it = dep_clean_.begin();
2390 DepClean::const_iterator const end = dep_clean_.end();
2392 for (; it != end; ++it) {
2398 string const & Buffer::fileName() const
2404 string const & Buffer::filePath() const
2410 bool Buffer::isReadonly() const
2416 BufferView * Buffer::getUser() const
2422 void Buffer::setParentName(string const & name)
2424 params.parentname = name;
2428 Buffer::inset_iterator::inset_iterator()
2433 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2440 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2444 if (it == pit->insetlist.end()) {
2453 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2455 inset_iterator tmp = *this;
2461 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2463 return *it.getInset();
2467 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2469 return it.getInset();
2473 Paragraph * Buffer::inset_iterator::getPar()
2479 lyx::pos_type Buffer::inset_iterator::getPos() const
2485 bool operator==(Buffer::inset_iterator const & iter1,
2486 Buffer::inset_iterator const & iter2)
2488 return iter1.pit == iter2.pit
2489 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2493 bool operator!=(Buffer::inset_iterator const & iter1,
2494 Buffer::inset_iterator const & iter2)
2496 return !(iter1 == iter2);