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 updateDocLang(params.language);
509 // FIXME: all the below Alerts should give the filename..
510 bool Buffer::readFile(LyXLex & lex, string const & filename,
511 ParagraphList::iterator pit)
514 Alert::error(_("Document could not be read"),
515 _("The specified document could not be read."));
520 string const token(lex.getString());
523 Alert::error(_("Document could not be read"),
524 _("The specified document could not be read."));
528 // the first token _must_ be...
529 if (token != "\\lyxformat") {
530 Alert::error(_("Document format failure"),
531 _("The specified document is not a LyX document."));
536 string tmp_format = lex.getString();
537 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
538 // if present remove ".," from string.
539 string::size_type dot = tmp_format.find_first_of(".,");
540 //lyxerr << " dot found at " << dot << endl;
541 if (dot != string::npos)
542 tmp_format.erase(dot, 1);
543 file_format = strToInt(tmp_format);
544 //lyxerr << "format: " << file_format << endl;
545 if (file_format == LYX_FORMAT) {
547 } else if (file_format > LYX_FORMAT) {
548 Alert::warning(_("Document format failure"),
549 _("This document was created with a newer version of "
550 "LyX. This is likely to cause problems."));
551 } else if (file_format < LYX_FORMAT) {
553 if (file_format < 200) {
554 Alert::error(_("Document format failure"),
555 _("This LyX document is too old to be read "
556 "by this version of LyX. Try LyX 0.10."));
558 } else if (!filename.empty()) {
560 LibFileSearch("lyx2lyx", "lyx2lyx");
561 if (command.empty()) {
562 Alert::error(_("Conversion script not found"),
563 _("The document is from an earlier version "
564 "of LyX, but the conversion script lyx2lyx "
565 "could not be found."));
569 +tostr(LYX_FORMAT) + ' '
570 + QuoteName(filename);
571 lyxerr[Debug::INFO] << "Running '"
574 cmd_ret const ret = RunCommand(command);
576 Alert::error(_("Conversion script failed"),
577 _("The document is from an earlier version "
578 "of LyX, but the lyx2lyx script failed "
582 istringstream is(STRCONV(ret.second));
584 tmplex.setStream(is);
585 return readFile(tmplex, string(), pit);
587 // This code is reached if lyx2lyx failed (for
588 // some reason) to change the file format of
594 bool the_end = readBody(lex, pit);
595 params.setPaperStuff();
598 Alert::error(_("Document format failure"),
599 _("The document ended unexpectedly, which means "
600 "that it is probably corrupted."));
606 // Should probably be moved to somewhere else: BufferView? LyXView?
607 bool Buffer::save() const
609 // We don't need autosaves in the immediate future. (Asger)
610 resetAutosaveTimers();
614 if (lyxrc.make_backup) {
615 s = fileName() + '~';
616 if (!lyxrc.backupdir_path.empty())
617 s = AddName(lyxrc.backupdir_path,
618 subst(os::slashify_path(s),'/','!'));
620 // Rename is the wrong way of making a backup,
621 // this is the correct way.
622 /* truss cp fil fil2:
623 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
624 stat("LyXVC.lyx", 0xEFFFF688) = 0
625 open("LyXVC.lyx", O_RDONLY) = 3
626 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
627 fstat(4, 0xEFFFF508) = 0
628 fstat(3, 0xEFFFF508) = 0
629 read(3, " # T h i s f i l e w".., 8192) = 5579
630 write(4, " # T h i s f i l e w".., 5579) = 5579
631 read(3, 0xEFFFD4A0, 8192) = 0
634 chmod("LyXVC3.lyx", 0100644) = 0
635 lseek(0, 0, SEEK_CUR) = 46440
639 // Should probably have some more error checking here.
640 // Doing it this way, also makes the inodes stay the same.
641 // This is still not a very good solution, in particular we
642 // might loose the owner of the backup.
643 FileInfo finfo(fileName());
645 mode_t fmode = finfo.getMode();
646 struct utimbuf times = {
647 finfo.getAccessTime(),
648 finfo.getModificationTime() };
650 ifstream ifs(fileName().c_str());
651 ofstream ofs(s.c_str(), ios::out|ios::trunc);
656 ::chmod(s.c_str(), fmode);
658 if (::utime(s.c_str(), ×)) {
659 lyxerr << "utime error." << endl;
662 lyxerr << "LyX was not able to make "
663 "backup copy. Beware." << endl;
668 if (writeFile(fileName())) {
670 removeAutosaveFile(fileName());
672 // Saving failed, so backup is not backup
673 if (lyxrc.make_backup) {
674 lyx::rename(s, fileName());
682 bool Buffer::writeFile(string const & fname) const
684 if (read_only && (fname == fileName())) {
688 FileInfo finfo(fname);
689 if (finfo.exist() && !finfo.writable()) {
693 ofstream ofs(fname.c_str());
699 // Use the standard "C" locale for file output.
700 ofs.imbue(std::locale::classic());
703 // The top of the file should not be written by params.
705 // write out a comment in the top of the file
706 ofs << '#' << lyx_docversion
707 << " created this file. For more info see http://www.lyx.org/\n"
708 << "\\lyxformat " << LYX_FORMAT << "\n";
710 // now write out the buffer paramters.
711 params.writeFile(ofs);
713 ofs << "\\end_header\n";
715 Paragraph::depth_type depth = 0;
717 // this will write out all the paragraphs
718 // using recursive descent.
719 ParagraphList::iterator pit = paragraphs.begin();
720 ParagraphList::iterator pend = paragraphs.end();
721 for (; pit != pend; ++pit)
722 pit->write(this, ofs, params, depth);
724 // Write marker that shows file is complete
725 ofs << "\n\\the_end" << endl;
729 // how to check if close went ok?
730 // Following is an attempt... (BE 20001011)
732 // good() returns false if any error occured, including some
734 // bad() returns true if something bad happened in the buffer,
735 // which should include file system full errors.
742 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
744 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
756 pair<int, string> const addDepth(int depth, int ldepth)
760 d += (ldepth - depth) * 2;
761 return make_pair(d, string(d, ' '));
767 string const Buffer::asciiParagraph(Paragraph const & par,
768 unsigned int linelen,
769 bool noparbreak) const
771 ostringstream buffer;
772 Paragraph::depth_type depth = 0;
774 Paragraph::depth_type ltype_depth = 0;
775 bool ref_printed = false;
776 // if (!par->previous()) {
778 // begins or ends a deeper area ?
779 if (depth != par->params().depth()) {
780 if (par->params().depth() > depth) {
781 while (par->params().depth() > depth) {
785 while (par->params().depth() < depth) {
791 depth = par.params().depth();
794 // First write the layout
795 string const & tmp = par.layout()->name();
796 if (compare_no_case(tmp, "itemize") == 0) {
798 ltype_depth = depth + 1;
799 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
801 ltype_depth = depth + 1;
802 } else if (contains(ascii_lowercase(tmp), "ection")) {
804 ltype_depth = depth + 1;
805 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
807 ltype_depth = depth + 1;
808 } else if (compare_ascii_no_case(tmp, "description") == 0) {
810 ltype_depth = depth + 1;
811 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
814 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
822 /* maybe some vertical spaces */
824 /* the labelwidthstring used in lists */
828 /* some pagebreaks? */
832 /* what about the alignment */
834 // linelen <= 0 is special and means we don't have paragraph breaks
836 string::size_type currlinelen = 0;
842 buffer << string(depth * 2, ' ');
843 currlinelen += depth * 2;
846 // we should probably change to the paragraph language in the
847 // gettext here (if possible) so that strings are outputted in
848 // the correct language! (20012712 Jug)
852 case 4: // (Sub)Paragraph
853 case 5: // Description
857 buffer << _("Abstract") << "\n\n";
860 string const abst = _("Abstract: ");
862 currlinelen += abst.length();
865 case 7: // Bibliography
868 buffer << _("References") << "\n\n";
871 string const refs = _("References: ");
873 currlinelen += refs.length();
881 string const parlab = par.params().labelString();
882 buffer << parlab << ' ';
883 currlinelen += parlab.length() + 1;
891 pair<int, string> p = addDepth(depth, ltype_depth);
893 currlinelen += p.first;
896 // this is to change the linebreak to do it by word a bit more
897 // intelligent hopefully! (only in the case where we have a
898 // max linelength!) (Jug)
902 for (pos_type i = 0; i < par.size(); ++i) {
903 char c = par.getUChar(params, i);
905 case Paragraph::META_INSET:
907 Inset const * inset = par.getInset(i);
911 currlinelen += word.length();
914 if (inset->ascii(this, buffer, linelen)) {
915 // to be sure it breaks paragraph
916 currlinelen += linelen;
925 currlinelen + word.length() > linelen - 10) {
927 pair<int, string> p = addDepth(depth, ltype_depth);
929 currlinelen = p.first;
932 buffer << word << ' ';
933 currlinelen += word.length() + 1;
940 lyxerr[Debug::INFO] <<
941 "writeAsciiFile: NULL char in structure." << endl;
944 (currlinelen + word.length()) > linelen)
948 pair<int, string> p =
949 addDepth(depth, ltype_depth);
951 currlinelen = p.first;
958 return STRCONV(buffer.str());
962 void Buffer::writeFileAscii(string const & fname, int linelen)
964 ofstream ofs(fname.c_str());
966 string const file = MakeDisplayPath(fname, 50);
968 boost::format fmt(_("Could not save the document\n%1$s."));
970 string text = fmt.str();
972 string text = _("Could not save the document\n");
975 Alert::error(_("Could not save document"), text);
978 writeFileAscii(ofs, linelen);
982 void Buffer::writeFileAscii(ostream & os, int linelen)
984 ParagraphList::iterator beg = paragraphs.begin();
985 ParagraphList::iterator end = paragraphs.end();
986 ParagraphList::iterator it = beg;
987 for (; it != end; ++it) {
988 os << asciiParagraph(*it, linelen, it == beg);
995 void Buffer::makeLaTeXFile(string const & fname,
996 string const & original_path,
997 bool nice, bool only_body, bool only_preamble)
999 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1001 ofstream ofs(fname.c_str());
1003 string const file = MakeDisplayPath(fname, 50);
1004 #if USE_BOOST_FORMAT
1005 boost::format fmt(_("Could not open the specified document\n%1$s."));
1007 string text = fmt.str();
1009 string text = _("Could not open the specified document\n");
1012 Alert::error(_("Could not open file"), text);
1016 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1020 lyxerr << "File was not closed properly." << endl;
1025 void Buffer::makeLaTeXFile(ostream & os,
1026 string const & original_path,
1027 bool nice, bool only_body, bool only_preamble)
1029 niceFile = nice; // this will be used by Insetincludes.
1031 // validate the buffer.
1032 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1033 LaTeXFeatures features(params);
1035 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1038 // The starting paragraph of the coming rows is the
1039 // first paragraph of the document. (Asger)
1040 texrow.start(&*(paragraphs.begin()), 0);
1042 if (!only_body && nice) {
1043 os << "%% " << lyx_docversion << " created this file. "
1044 "For more info, see http://www.lyx.org/.\n"
1045 "%% Do not edit unless you really know what "
1050 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1051 // There are a few differences between nice LaTeX and usual files:
1052 // usual is \batchmode and has a
1053 // special input@path to allow the including of figures
1054 // with either \input or \includegraphics (what figinsets do).
1055 // input@path is set when the actual parameter
1056 // original_path is set. This is done for usual tex-file, but not
1057 // for nice-latex-file. (Matthias 250696)
1060 // code for usual, NOT nice-latex-file
1061 os << "\\batchmode\n"; // changed
1062 // from \nonstopmode
1065 if (!original_path.empty()) {
1066 string inputpath = os::external_path(original_path);
1067 subst(inputpath, "~", "\\string~");
1068 os << "\\makeatletter\n"
1069 << "\\def\\input@path{{"
1070 << inputpath << "/}}\n"
1071 << "\\makeatother\n";
1077 // Write the preamble
1078 params.writeLaTeX(os, features, texrow);
1084 os << "\\begin{document}\n";
1087 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1089 if (!lyxrc.language_auto_begin) {
1090 os << subst(lyxrc.language_command_begin, "$$lang",
1091 params.language->babel())
1096 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1098 // add this just in case after all the paragraphs
1102 if (!lyxrc.language_auto_end) {
1103 os << subst(lyxrc.language_command_end, "$$lang",
1104 params.language->babel())
1110 os << "\\end{document}\n";
1113 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1115 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1119 // Just to be sure. (Asger)
1122 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1123 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1126 // we want this to be true outside previews (for insetexternal)
1131 bool Buffer::isLatex() const
1133 return params.getLyXTextClass().outputType() == LATEX;
1137 bool Buffer::isLinuxDoc() const
1139 return params.getLyXTextClass().outputType() == LINUXDOC;
1143 bool Buffer::isLiterate() const
1145 return params.getLyXTextClass().outputType() == LITERATE;
1149 bool Buffer::isDocBook() const
1151 return params.getLyXTextClass().outputType() == DOCBOOK;
1155 bool Buffer::isSGML() const
1157 LyXTextClass const & tclass = params.getLyXTextClass();
1159 return tclass.outputType() == LINUXDOC ||
1160 tclass.outputType() == DOCBOOK;
1164 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1166 ofstream ofs(fname.c_str());
1169 string const file = MakeDisplayPath(fname, 50);
1170 #if USE_BOOST_FORMAT
1171 boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
1173 string text = fmt.str();
1175 string text = _("Could not save the specified document\n");
1176 text += file + _(".\n");
1178 Alert::error(_("Could not save document"), text);
1182 niceFile = nice; // this will be used by included files.
1184 LaTeXFeatures features(params);
1190 LyXTextClass const & tclass = params.getLyXTextClass();
1192 string top_element = tclass.latexname();
1195 ofs << "<!doctype linuxdoc system";
1197 string preamble = params.preamble;
1198 const string name = nice ? ChangeExtension(filename_, ".sgml")
1200 preamble += features.getIncludedFiles(name);
1201 preamble += features.getLyXSGMLEntities();
1203 if (!preamble.empty()) {
1204 ofs << " [ " << preamble << " ]";
1208 if (params.options.empty())
1209 sgml::openTag(ofs, 0, false, top_element);
1211 string top = top_element;
1213 top += params.options;
1214 sgml::openTag(ofs, 0, false, top);
1218 ofs << "<!-- " << lyx_docversion
1219 << " created this file. For more info see http://www.lyx.org/"
1222 Paragraph::depth_type depth = 0; // paragraph depth
1224 vector<string> environment_stack(5);
1226 ParagraphList::iterator pit = paragraphs.begin();
1227 ParagraphList::iterator pend = paragraphs.end();
1228 for (; pit != pend; ++pit) {
1229 LyXLayout_ptr const & style = pit->layout();
1230 // treat <toc> as a special case for compatibility with old code
1231 if (pit->isInset(0)) {
1232 Inset * inset = pit->getInset(0);
1233 Inset::Code lyx_code = inset->lyxCode();
1234 if (lyx_code == Inset::TOC_CODE) {
1235 string const temp = "toc";
1236 sgml::openTag(ofs, depth, false, temp);
1241 // environment tag closing
1242 for (; depth > pit->params().depth(); --depth) {
1243 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1244 environment_stack[depth].erase();
1247 // write opening SGML tags
1248 switch (style->latextype) {
1249 case LATEX_PARAGRAPH:
1250 if (depth == pit->params().depth()
1251 && !environment_stack[depth].empty()) {
1252 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1253 environment_stack[depth].erase();
1259 sgml::openTag(ofs, depth, false, style->latexname());
1265 _("Error: Wrong depth for LatexType Command.\n"));
1267 if (!environment_stack[depth].empty()) {
1268 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1272 environment_stack[depth].erase();
1273 sgml::openTag(ofs, depth, false, style->latexname());
1276 case LATEX_ENVIRONMENT:
1277 case LATEX_ITEM_ENVIRONMENT:
1278 case LATEX_BIB_ENVIRONMENT:
1280 string const & latexname = style->latexname();
1282 if (depth == pit->params().depth()
1283 && environment_stack[depth] != latexname) {
1284 sgml::closeTag(ofs, depth, false,
1285 environment_stack[depth]);
1286 environment_stack[depth].erase();
1288 if (depth < pit->params().depth()) {
1289 depth = pit->params().depth();
1290 environment_stack[depth].erase();
1292 if (environment_stack[depth] != latexname) {
1294 sgml::openTag(ofs, depth, false, "p");
1296 sgml::openTag(ofs, depth, false, latexname);
1298 if (environment_stack.size() == depth + 1)
1299 environment_stack.push_back("!-- --");
1300 environment_stack[depth] = latexname;
1303 if (style->latexparam() == "CDATA")
1306 if (style->latextype == LATEX_ENVIRONMENT) break;
1308 if (style->labeltype == LABEL_MANUAL)
1313 sgml::openTag(ofs, depth + 1, false, item_name);
1318 sgml::openTag(ofs, depth, false, style->latexname());
1322 simpleLinuxDocOnePar(ofs, pit, depth);
1325 // write closing SGML tags
1326 switch (style->latextype) {
1329 case LATEX_ENVIRONMENT:
1330 case LATEX_ITEM_ENVIRONMENT:
1331 case LATEX_BIB_ENVIRONMENT:
1332 if (style->latexparam() == "CDATA")
1336 sgml::closeTag(ofs, depth, false, style->latexname());
1342 for (int i = depth; i >= 0; --i)
1343 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1347 sgml::closeTag(ofs, 0, false, top_element);
1351 // How to check for successful close
1353 // we want this to be true outside previews (for insetexternal)
1358 // checks, if newcol chars should be put into this line
1359 // writes newline, if necessary.
1362 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1363 string::size_type newcol)
1366 if (colcount > lyxrc.ascii_linelen) {
1368 colcount = newcol; // assume write after this call
1383 string tag_name(PAR_TAG const & pt) {
1385 case NONE: return "!-- --";
1386 case TT: return "tt";
1387 case SF: return "sf";
1388 case BF: return "bf";
1389 case IT: return "it";
1390 case SL: return "sl";
1391 case EM: return "em";
1398 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1400 p1 = static_cast<PAR_TAG>(p1 | p2);
1405 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1407 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1413 // Handle internal paragraph parsing -- layout already processed.
1414 void Buffer::simpleLinuxDocOnePar(ostream & os,
1415 ParagraphList::iterator par,
1416 Paragraph::depth_type /*depth*/) const
1418 LyXLayout_ptr const & style = par->layout();
1420 string::size_type char_line_count = 5; // Heuristic choice ;-)
1422 // gets paragraph main font
1425 if (style->labeltype == LABEL_MANUAL) {
1426 font_old = style->labelfont;
1429 font_old = style->font;
1433 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1434 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1435 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1438 stack<PAR_TAG> tag_state;
1439 // parsing main loop
1440 for (pos_type i = 0; i < par->size(); ++i) {
1442 PAR_TAG tag_close = NONE;
1443 list < PAR_TAG > tag_open;
1445 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1447 if (font_old.family() != font.family()) {
1448 switch (family_type) {
1449 case LyXFont::SANS_FAMILY:
1452 case LyXFont::TYPEWRITER_FAMILY:
1459 family_type = font.family();
1461 switch (family_type) {
1462 case LyXFont::SANS_FAMILY:
1463 tag_open.push_back(SF);
1465 case LyXFont::TYPEWRITER_FAMILY:
1466 tag_open.push_back(TT);
1473 if (font_old.series() != font.series()) {
1474 switch (series_type) {
1475 case LyXFont::BOLD_SERIES:
1482 series_type = font.series();
1484 switch (series_type) {
1485 case LyXFont::BOLD_SERIES:
1486 tag_open.push_back(BF);
1494 if (font_old.shape() != font.shape()) {
1495 switch (shape_type) {
1496 case LyXFont::ITALIC_SHAPE:
1499 case LyXFont::SLANTED_SHAPE:
1506 shape_type = font.shape();
1508 switch (shape_type) {
1509 case LyXFont::ITALIC_SHAPE:
1510 tag_open.push_back(IT);
1512 case LyXFont::SLANTED_SHAPE:
1513 tag_open.push_back(SL);
1520 if (font_old.emph() != font.emph()) {
1521 if (font.emph() == LyXFont::ON) {
1522 tag_open.push_back(EM);
1531 list < PAR_TAG > temp;
1532 while (!tag_state.empty() && tag_close) {
1533 PAR_TAG k = tag_state.top();
1535 os << "</" << tag_name(k) << '>';
1542 for(list< PAR_TAG >::const_iterator j = temp.begin();
1543 j != temp.end(); ++j) {
1545 os << '<' << tag_name(*j) << '>';
1548 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1549 j != tag_open.end(); ++j) {
1551 os << '<' << tag_name(*j) << '>';
1554 char c = par->getChar(i);
1556 if (c == Paragraph::META_INSET) {
1557 Inset * inset = par->getInset(i);
1558 inset->linuxdoc(this, os);
1563 if (style->latexparam() == "CDATA") {
1564 // "TeX"-Mode on == > SGML-Mode on.
1571 boost::tie(ws, str) = sgml::escapeChar(c);
1572 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1573 // in freespacing mode, spaces are
1574 // non-breaking characters
1575 if (desc_on) {// if char is ' ' then...
1578 sgmlLineBreak(os, char_line_count, 6);
1582 sgmlLineBreak(os, char_line_count, 1);
1587 char_line_count += str.length();
1593 while (!tag_state.empty()) {
1594 os << "</" << tag_name(tag_state.top()) << '>';
1598 // resets description flag correctly
1600 // <tag> not closed...
1601 sgmlLineBreak(os, char_line_count, 6);
1607 // Print an error message.
1608 void Buffer::sgmlError(ParagraphList::iterator /*par*/, int /*pos*/,
1609 string const & /*message*/) const
1611 #ifdef WITH_WARNINGS
1612 #warning This is wrong we cannot insert an inset like this!!!
1613 // I guess this was Jose' so I explain you more or less why this
1614 // is wrong. This way you insert something in the paragraph and
1615 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1616 // I deactivate this code, have a look at BufferView::insertErrors
1617 // how you should do this correctly! (Jug 20020315)
1620 // insert an error marker in text
1621 InsetError * new_inset = new InsetError(message);
1622 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1628 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1630 ofstream ofs(fname.c_str());
1632 string const file = MakeDisplayPath(fname, 50);
1633 #if USE_BOOST_FORMAT
1634 boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
1636 string text = fmt.str();
1638 string text = _("Could not save the specified document\n");
1639 text += file + _(".\n");
1641 Alert::error(_("Could not save document"), text);
1645 niceFile = nice; // this will be used by Insetincludes.
1647 LaTeXFeatures features(params);
1652 LyXTextClass const & tclass = params.getLyXTextClass();
1653 string top_element = tclass.latexname();
1656 ofs << "<!DOCTYPE " << top_element
1657 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1659 string preamble = params.preamble;
1660 const string name = nice ? ChangeExtension(filename_, ".sgml")
1662 preamble += features.getIncludedFiles(name);
1663 preamble += features.getLyXSGMLEntities();
1665 if (!preamble.empty()) {
1666 ofs << "\n [ " << preamble << " ]";
1671 string top = top_element;
1673 top += params.language->code();
1676 if (!params.options.empty()) {
1678 top += params.options;
1680 sgml::openTag(ofs, 0, false, top);
1682 ofs << "<!-- DocBook file was created by " << lyx_docversion
1683 << "\n See http://www.lyx.org/ for more information -->\n";
1685 vector<string> environment_stack(10);
1686 vector<string> environment_inner(10);
1687 vector<string> command_stack(10);
1689 bool command_flag = false;
1690 Paragraph::depth_type command_depth = 0;
1691 Paragraph::depth_type command_base = 0;
1692 Paragraph::depth_type cmd_depth = 0;
1693 Paragraph::depth_type depth = 0; // paragraph depth
1696 string command_name;
1698 ParagraphList::iterator par = paragraphs.begin();
1699 ParagraphList::iterator pend = paragraphs.end();
1701 for (; par != pend; ++par) {
1705 int desc_on = 0; // description mode
1707 LyXLayout_ptr const & style = par->layout();
1709 // environment tag closing
1710 for (; depth > par->params().depth(); --depth) {
1711 if (environment_inner[depth] != "!-- --") {
1712 item_name = "listitem";
1713 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1714 if (environment_inner[depth] == "varlistentry")
1715 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1717 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1718 environment_stack[depth].erase();
1719 environment_inner[depth].erase();
1722 if (depth == par->params().depth()
1723 && environment_stack[depth] != style->latexname()
1724 && !environment_stack[depth].empty()) {
1725 if (environment_inner[depth] != "!-- --") {
1726 item_name= "listitem";
1727 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1728 if (environment_inner[depth] == "varlistentry")
1729 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1732 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1734 environment_stack[depth].erase();
1735 environment_inner[depth].erase();
1738 // Write opening SGML tags.
1739 switch (style->latextype) {
1740 case LATEX_PARAGRAPH:
1741 sgml::openTag(ofs, depth + command_depth,
1742 false, style->latexname());
1748 _("Error: Wrong depth for LatexType Command.\n"));
1750 command_name = style->latexname();
1752 sgmlparam = style->latexparam();
1753 c_params = split(sgmlparam, c_depth,'|');
1755 cmd_depth = lyx::atoi(c_depth);
1758 if (cmd_depth < command_base) {
1759 for (Paragraph::depth_type j = command_depth;
1760 j >= command_base; --j) {
1761 sgml::closeTag(ofs, j, false, command_stack[j]);
1764 command_depth = command_base = cmd_depth;
1765 } else if (cmd_depth <= command_depth) {
1766 for (int j = command_depth;
1767 j >= int(cmd_depth); --j) {
1768 sgml::closeTag(ofs, j, false, command_stack[j]);
1771 command_depth = cmd_depth;
1773 command_depth = cmd_depth;
1775 command_depth = command_base = cmd_depth;
1776 command_flag = true;
1778 if (command_stack.size() == command_depth + 1)
1779 command_stack.push_back(string());
1780 command_stack[command_depth] = command_name;
1782 // treat label as a special case for
1783 // more WYSIWYM handling.
1784 // This is a hack while paragraphs can't have
1785 // attributes, like id in this case.
1786 if (par->isInset(0)) {
1787 Inset * inset = par->getInset(0);
1788 Inset::Code lyx_code = inset->lyxCode();
1789 if (lyx_code == Inset::LABEL_CODE) {
1790 command_name += " id=\"";
1791 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1792 command_name += '"';
1797 sgml::openTag(ofs, depth + command_depth, false, command_name);
1799 item_name = c_params.empty() ? "title" : c_params;
1800 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1803 case LATEX_ENVIRONMENT:
1804 case LATEX_ITEM_ENVIRONMENT:
1805 if (depth < par->params().depth()) {
1806 depth = par->params().depth();
1807 environment_stack[depth].erase();
1810 if (environment_stack[depth] != style->latexname()) {
1811 if (environment_stack.size() == depth + 1) {
1812 environment_stack.push_back("!-- --");
1813 environment_inner.push_back("!-- --");
1815 environment_stack[depth] = style->latexname();
1816 environment_inner[depth] = "!-- --";
1817 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1819 if (environment_inner[depth] != "!-- --") {
1820 item_name= "listitem";
1821 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1822 if (environment_inner[depth] == "varlistentry")
1823 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1827 if (style->latextype == LATEX_ENVIRONMENT) {
1828 if (!style->latexparam().empty()) {
1829 if (style->latexparam() == "CDATA")
1832 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1837 desc_on = (style->labeltype == LABEL_MANUAL);
1839 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1840 sgml::openTag(ofs, depth + 1 + command_depth,
1841 false, environment_inner[depth]);
1843 item_name = desc_on ? "term" : "para";
1844 sgml::openTag(ofs, depth + 1 + command_depth,
1848 sgml::openTag(ofs, depth + command_depth,
1849 false, style->latexname());
1853 simpleDocBookOnePar(ofs, par, desc_on,
1854 depth + 1 + command_depth);
1857 // write closing SGML tags
1858 switch (style->latextype) {
1860 end_tag = c_params.empty() ? "title" : c_params;
1861 sgml::closeTag(ofs, depth + command_depth,
1864 case LATEX_ENVIRONMENT:
1865 if (!style->latexparam().empty()) {
1866 if (style->latexparam() == "CDATA")
1869 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1872 case LATEX_ITEM_ENVIRONMENT:
1873 if (desc_on == 1) break;
1875 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1877 case LATEX_PARAGRAPH:
1878 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1881 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1887 for (int d = depth; d >= 0; --d) {
1888 if (!environment_stack[depth].empty()) {
1889 if (environment_inner[depth] != "!-- --") {
1890 item_name = "listitem";
1891 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1892 if (environment_inner[depth] == "varlistentry")
1893 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1896 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1900 for (int j = command_depth; j >= 0 ; --j)
1901 if (!command_stack[j].empty()) {
1902 sgml::closeTag(ofs, j, false, command_stack[j]);
1907 sgml::closeTag(ofs, 0, false, top_element);
1910 // How to check for successful close
1912 // we want this to be true outside previews (for insetexternal)
1917 void Buffer::simpleDocBookOnePar(ostream & os,
1918 ParagraphList::iterator par, int & desc_on,
1919 Paragraph::depth_type depth) const
1921 bool emph_flag = false;
1923 LyXLayout_ptr const & style = par->layout();
1925 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1927 int char_line_count = depth;
1928 //if (!style.free_spacing)
1929 // os << string(depth,' ');
1931 // parsing main loop
1932 for (pos_type i = 0; i < par->size(); ++i) {
1933 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1935 // handle <emphasis> tag
1936 if (font_old.emph() != font.emph()) {
1937 if (font.emph() == LyXFont::ON) {
1938 if (style->latexparam() == "CDATA")
1941 if (style->latexparam() == "CDATA")
1945 if (style->latexparam() == "CDATA")
1947 os << "</emphasis>";
1948 if (style->latexparam() == "CDATA")
1955 if (par->isInset(i)) {
1956 Inset * inset = par->getInset(i);
1957 // don't print the inset in position 0 if desc_on == 3 (label)
1958 if (i || desc_on != 3) {
1959 if (style->latexparam() == "CDATA")
1961 inset->docbook(this, os, false);
1962 if (style->latexparam() == "CDATA")
1966 char c = par->getChar(i);
1969 boost::tie(ws, str) = sgml::escapeChar(c);
1971 if (style->pass_thru) {
1973 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1975 } else if (desc_on ==1) {
1977 os << "\n</term><listitem><para>";
1987 if (style->latexparam() == "CDATA")
1989 os << "</emphasis>";
1990 if (style->latexparam() == "CDATA")
1994 // resets description flag correctly
1996 // <term> not closed...
1997 os << "</term>\n<listitem><para> </para>";
1999 if (style->free_spacing)
2004 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2005 // Other flags: -wall -v0 -x
2006 int Buffer::runChktex()
2008 if (!users->text) return 0;
2010 users->owner()->busy(true);
2012 // get LaTeX-Filename
2013 string const name = getLatexName();
2014 string path = filePath();
2016 string const org_path = path;
2017 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2021 Path p(path); // path to LaTeX file
2022 users->owner()->message(_("Running chktex..."));
2024 // Remove all error insets
2025 bool const removedErrorInsets = users->removeAutoInsets();
2027 // Generate the LaTeX file if neccessary
2028 makeLaTeXFile(name, org_path, false);
2031 Chktex chktex(lyxrc.chktex_command, name, filePath());
2032 int res = chktex.run(terr); // run chktex
2035 Alert::error(_("chktex failure"),
2036 _("Could not run chktex successfully."));
2037 } else if (res > 0) {
2038 // Insert all errors as errors boxes
2039 users->insertErrors(terr);
2042 // if we removed error insets before we ran chktex or if we inserted
2043 // error insets after we ran chktex, this must be run:
2044 if (removedErrorInsets || res) {
2045 #warning repaint needed here, or do you mean update() ?
2049 users->owner()->busy(false);
2055 void Buffer::validate(LaTeXFeatures & features) const
2057 LyXTextClass const & tclass = params.getLyXTextClass();
2059 if (params.tracking_changes) {
2060 features.require("dvipost");
2061 features.require("color");
2064 // AMS Style is at document level
2065 if (params.use_amsmath == BufferParams::AMS_ON
2066 || tclass.provides(LyXTextClass::amsmath))
2067 features.require("amsmath");
2069 for_each(paragraphs.begin(), paragraphs.end(),
2070 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2072 // the bullet shapes are buffer level not paragraph level
2073 // so they are tested here
2074 for (int i = 0; i < 4; ++i) {
2075 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2076 int const font = params.user_defined_bullets[i].getFont();
2078 int const c = params
2079 .user_defined_bullets[i]
2086 features.require("latexsym");
2088 } else if (font == 1) {
2089 features.require("amssymb");
2090 } else if ((font >= 2 && font <= 5)) {
2091 features.require("pifont");
2096 if (lyxerr.debugging(Debug::LATEX)) {
2097 features.showStruct();
2102 vector<string> const Buffer::getLabelList() const
2104 /// if this is a child document and the parent is already loaded
2105 /// Use the parent's list instead [ale990407]
2106 if (!params.parentname.empty()
2107 && bufferlist.exists(params.parentname)) {
2108 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2110 return tmp->getLabelList();
2113 vector<string> label_list;
2114 for (inset_iterator it = inset_const_iterator_begin();
2115 it != inset_const_iterator_end(); ++it) {
2116 vector<string> const l = it->getLabelList();
2117 label_list.insert(label_list.end(), l.begin(), l.end());
2123 // This is also a buffer property (ale)
2124 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2126 /// if this is a child document and the parent is already loaded
2127 /// use the parent's list instead [ale990412]
2128 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2129 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2131 tmp->fillWithBibKeys(keys);
2136 for (inset_iterator it = inset_const_iterator_begin();
2137 it != inset_const_iterator_end(); ++it) {
2138 if (it->lyxCode() == Inset::BIBTEX_CODE)
2139 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2140 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2141 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2142 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2143 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2144 string const key = bib.getContents();
2145 string const opt = bib.getOptions();
2146 string const ref; // = pit->asString(this, false);
2147 string const info = opt + "TheBibliographyRef" + ref;
2148 keys.push_back(pair<string, string>(key, info));
2154 bool Buffer::isDepClean(string const & name) const
2156 DepClean::const_iterator it = dep_clean_.find(name);
2157 if (it == dep_clean_.end())
2163 void Buffer::markDepClean(string const & name)
2165 dep_clean_[name] = true;
2169 bool Buffer::dispatch(string const & command, bool * result)
2171 // Split command string into command and argument
2173 string line = ltrim(command);
2174 string const arg = trim(split(line, cmd, ' '));
2176 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2180 bool Buffer::dispatch(int action, string const & argument, bool * result)
2182 bool dispatched = true;
2186 bool const tmp = Exporter::Export(this, argument, false);
2199 void Buffer::resizeInsets(BufferView * bv)
2201 /// then remove all LyXText in text-insets
2202 for_each(paragraphs.begin(), paragraphs.end(),
2203 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2207 void Buffer::redraw()
2209 #warning repaint needed here, or do you mean update() ?
2215 void Buffer::changeLanguage(Language const * from, Language const * to)
2217 lyxerr << "Changing Language!" << endl;
2219 // Take care of l10n/i18n
2222 ParIterator end = par_iterator_end();
2223 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2224 (*it)->changeLanguage(params, from, to);
2228 void Buffer::updateDocLang(Language const * nlang)
2230 messages_.reset(new Messages(nlang->code()));
2234 bool Buffer::isMultiLingual()
2236 ParIterator end = par_iterator_end();
2237 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2238 if ((*it)->isMultiLingual(params))
2245 void Buffer::inset_iterator::setParagraph()
2247 while (pit != pend) {
2248 it = pit->insetlist.begin();
2249 if (it != pit->insetlist.end())
2256 Inset * Buffer::getInsetFromID(int id_arg) const
2258 for (inset_iterator it = inset_const_iterator_begin();
2259 it != inset_const_iterator_end(); ++it)
2261 if (it->id() == id_arg)
2263 Inset * in = it->getInsetFromID(id_arg);
2271 ParagraphList::iterator Buffer::getParFromID(int id) const
2273 #warning FIXME: const correctness! (Andre)
2274 ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
2275 ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
2277 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2279 // John says this is called with id == -1 from undo
2280 lyxerr << "getParFromID(), id: " << id << endl;
2284 for (; it != end; ++it) {
2285 // go on then, show me how to remove
2287 if ((*it)->id() == id) {
2296 ParIterator Buffer::par_iterator_begin()
2298 return ParIterator(&*(paragraphs.begin()));
2302 ParIterator Buffer::par_iterator_end()
2304 return ParIterator();
2307 ParConstIterator Buffer::par_iterator_begin() const
2309 return ParConstIterator(&*(paragraphs.begin()));
2313 ParConstIterator Buffer::par_iterator_end() const
2315 return ParConstIterator();
2320 void Buffer::addUser(BufferView * u)
2326 void Buffer::delUser(BufferView *)
2332 Language const * Buffer::getLanguage() const
2334 return params.language;
2338 string const Buffer::B_(string const & l10n) const
2340 if (messages_.get()) {
2341 return messages_->get(l10n);
2348 bool Buffer::isClean() const
2354 bool Buffer::isBakClean() const
2360 void Buffer::markClean() const
2366 // if the .lyx file has been saved, we don't need an
2372 void Buffer::markBakClean()
2378 void Buffer::setUnnamed(bool flag)
2384 bool Buffer::isUnnamed()
2390 void Buffer::markDirty()
2398 DepClean::iterator it = dep_clean_.begin();
2399 DepClean::const_iterator const end = dep_clean_.end();
2401 for (; it != end; ++it) {
2407 string const & Buffer::fileName() const
2413 string const & Buffer::filePath() const
2419 bool Buffer::isReadonly() const
2425 BufferView * Buffer::getUser() const
2431 void Buffer::setParentName(string const & name)
2433 params.parentname = name;
2437 Buffer::inset_iterator::inset_iterator()
2442 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2449 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2453 if (it == pit->insetlist.end()) {
2462 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2464 inset_iterator tmp = *this;
2470 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2472 return *it.getInset();
2476 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2478 return it.getInset();
2482 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2488 lyx::pos_type Buffer::inset_iterator::getPos() const
2494 bool operator==(Buffer::inset_iterator const & iter1,
2495 Buffer::inset_iterator const & iter2)
2497 return iter1.pit == iter2.pit
2498 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2502 bool operator!=(Buffer::inset_iterator const & iter1,
2503 Buffer::inset_iterator const & iter2)
2505 return !(iter1 == iter2);