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/tostr.h"
63 #include "support/lyxlib.h"
64 #include "support/FileInfo.h"
65 #include "support/lyxmanip.h"
66 #include "support/lyxtime.h"
68 #include <boost/bind.hpp>
69 #include <boost/tuple/tuple.hpp>
81 #include <sys/types.h>
88 #ifndef CXX_GLOBAL_CSTD
100 using std::make_pair;
108 using lyx::textclass_type;
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
115 const int LYX_FORMAT = 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) {
150 Alert::warning(_("Could not remove temporary directory"),
151 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
156 // Remove any previewed LaTeX snippets assocoated with this buffer.
157 grfx::Previews::get().removeLoader(this);
161 string const Buffer::getLatexName(bool no_path) const
163 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
165 return OnlyFilename(name);
171 pair<Buffer::LogType, string> const Buffer::getLogName() const
173 string const filename = getLatexName(false);
175 if (filename.empty())
176 return make_pair(Buffer::latexlog, string());
178 string path = OnlyPath(filename);
180 if (lyxrc.use_tempdir || !IsDirWriteable(path))
183 string const fname = AddName(path,
184 OnlyFilename(ChangeExtension(filename,
187 AddName(path, OnlyFilename(
188 ChangeExtension(filename,
189 formats.extension("literate") + ".out")));
191 // If no Latex log or Build log is newer, show Build log
193 FileInfo const f_fi(fname);
194 FileInfo const b_fi(bname);
197 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
198 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
199 return make_pair(Buffer::buildlog, bname);
201 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
202 return make_pair(Buffer::latexlog, fname);
206 void Buffer::setReadonly(bool flag)
208 if (read_only != flag) {
211 users->owner()->getDialogs().updateBufferDependent(false);
216 AuthorList & Buffer::authors()
218 return params.authorlist;
222 /// Update window titles of all users
223 // Should work on a list
224 void Buffer::updateTitles() const
227 users->owner()->updateWindowTitle();
231 /// Reset autosave timer of all users
232 // Should work on a list
233 void Buffer::resetAutosaveTimers() const
236 users->owner()->resetAutosaveTimer();
240 void Buffer::setFileName(string const & newfile)
242 filename_ = MakeAbsPath(newfile);
243 filepath_ = OnlyPath(filename_);
244 setReadonly(IsFileWriteable(filename_) == 0);
249 // We'll remove this later. (Lgb)
252 void unknownClass(string const & unknown)
254 Alert::warning(_("Unknown document class"),
255 bformat(_("Using the default document class, because the "
256 " class %1$s is unknown."), unknown));
261 int Buffer::readHeader(LyXLex & lex)
263 int unknown_tokens = 0;
267 string const token = lex.getString();
272 if (token == "\\end_header")
275 lyxerr[Debug::PARSER] << "Handling header token: `"
276 << token << '\'' << endl;
278 string unknown = params.readToken(lex, token);
279 if (!unknown.empty()) {
280 if (unknown[0] != '\\') {
281 unknownClass(unknown);
287 return unknown_tokens;
291 // candidate for move to BufferView
292 // (at least some parts in the beginning of the func)
295 // changed to be public and have one parameter
296 // if par = 0 normal behavior
297 // else insert behavior
298 // Returns false if "\the_end" is not read (Asger)
299 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
301 int unknown_tokens = 0;
303 Paragraph::depth_type depth = 0;
304 bool the_end_read = false;
306 if (paragraphs.empty()) {
307 unknown_tokens += readHeader(lex);
309 if (!params.getLyXTextClass().load()) {
310 string theclass = params.getLyXTextClass().name();
311 Alert::error(_("Can't load document class"), bformat(
312 "Using the default document class, because the "
313 " class %1$s could not be loaded.", theclass));
314 params.textclass = 0;
317 // We are inserting into an existing document
318 users->text->breakParagraph(paragraphs);
320 // We don't want to adopt the parameters from the
321 // document we insert, so read them into a temporary buffer
322 // and then discard it
324 Buffer tmpbuf("", false);
325 tmpbuf.readHeader(lex);
330 string const token = lex.getString();
335 lyxerr[Debug::PARSER] << "Handling token: `"
336 << token << '\'' << endl;
338 if (token == "\\the_end") {
343 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
347 if (unknown_tokens > 0) {
349 if (unknown_tokens == 1) {
350 s = bformat(_("Encountered one unknown token when reading "
351 "the document %1$s."), fileName());
353 s = bformat(_("Encountered %1$s unknown tokens when reading "
354 "the document %2$s."), tostr(unknown_tokens), fileName());
356 Alert::warning(_("Document format failure"), s);
363 int Buffer::readParagraph(LyXLex & lex, string const & token,
364 ParagraphList & pars, ParagraphList::iterator & pit,
365 Paragraph::depth_type & depth)
367 static Change current_change;
370 if (token == "\\layout") {
371 lex.pushToken(token);
373 Paragraph * par = new Paragraph();
374 par->params().depth(depth);
375 if (params.tracking_changes)
377 LyXFont f(LyXFont::ALL_INHERIT, params.language);
380 // FIXME: goddamn InsetTabular makes us pass a Buffer
382 unknown += ::readParagraph(*this, *par, lex);
385 if (pit != pars.end())
387 pit = pars.insert(pit, par);
388 } else if (token == "\\begin_deeper") {
390 } else if (token == "\\end_deeper") {
392 lex.printError("\\end_deeper: " "depth is already null");
403 // needed to insert the selection
404 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
405 LyXFont const & fn,string const & str)
407 LyXLayout_ptr const & layout = par->layout();
411 par->checkInsertChar(font);
412 // insert the string, don't insert doublespace
413 bool space_inserted = true;
414 bool autobreakrows = !par->inInset() ||
415 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
416 for(string::const_iterator cit = str.begin();
417 cit != str.end(); ++cit) {
419 if (autobreakrows && (!par->empty() || layout->keepempty)) {
420 breakParagraph(params, paragraphs, par, pos,
421 layout->isEnvironment());
424 space_inserted = true;
428 // do not insert consecutive spaces if !free_spacing
429 } else if ((*cit == ' ' || *cit == '\t') &&
430 space_inserted && !layout->free_spacing &&
431 !par->isFreeSpacing())
434 } else if (*cit == '\t') {
435 if (!layout->free_spacing && !par->isFreeSpacing()) {
436 // tabs are like spaces here
437 par->insertChar(pos, ' ', font);
439 space_inserted = true;
441 const pos_type nb = 8 - pos % 8;
442 for (pos_type a = 0; a < nb ; ++a) {
443 par->insertChar(pos, ' ', font);
446 space_inserted = true;
448 } else if (!IsPrintable(*cit)) {
449 // Ignore unprintables
452 // just insert the character
453 par->insertChar(pos, *cit, font);
455 space_inserted = (*cit == ' ');
462 bool Buffer::readFile(LyXLex & lex, string const & filename)
464 bool ret = readFile(lex, filename, paragraphs.begin());
466 // After we have read a file, we must ensure that the buffer
467 // language is set and used in the gui.
468 // If you know of a better place to put this, please tell me. (Lgb)
469 updateDocLang(params.language);
475 // FIXME: all the below Alerts should give the filename..
476 bool Buffer::readFile(LyXLex & lex, string const & filename,
477 ParagraphList::iterator pit)
480 Alert::error(_("Document could not be read"),
481 _("The specified document could not be read."));
486 string const token(lex.getString());
489 Alert::error(_("Document could not be read"),
490 _("The specified document could not be read."));
494 // the first token _must_ be...
495 if (token != "\\lyxformat") {
496 Alert::error(_("Document format failure"),
497 _("The specified document is not a LyX document."));
502 string tmp_format = lex.getString();
503 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
504 // if present remove ".," from string.
505 string::size_type dot = tmp_format.find_first_of(".,");
506 //lyxerr << " dot found at " << dot << endl;
507 if (dot != string::npos)
508 tmp_format.erase(dot, 1);
509 file_format = strToInt(tmp_format);
510 //lyxerr << "format: " << file_format << endl;
511 if (file_format == LYX_FORMAT) {
513 } else if (file_format > LYX_FORMAT) {
514 Alert::warning(_("Document format failure"),
515 _("This document was created with a newer version of "
516 "LyX. This is likely to cause problems."));
517 } else if (file_format < LYX_FORMAT) {
519 if (file_format < 200) {
520 Alert::error(_("Document format failure"),
521 _("This LyX document is too old to be read "
522 "by this version of LyX. Try LyX 0.10."));
524 } else if (!filename.empty()) {
526 LibFileSearch("lyx2lyx", "lyx2lyx");
527 if (command.empty()) {
528 Alert::error(_("Conversion script not found"),
529 _("The document is from an earlier version "
530 "of LyX, but the conversion script lyx2lyx "
531 "could not be found."));
535 +tostr(LYX_FORMAT) + ' '
536 + QuoteName(filename);
537 lyxerr[Debug::INFO] << "Running '"
540 cmd_ret const ret = RunCommand(command);
542 Alert::error(_("Conversion script failed"),
543 _("The document is from an earlier version "
544 "of LyX, but the lyx2lyx script failed "
548 istringstream is(STRCONV(ret.second));
550 tmplex.setStream(is);
551 return readFile(tmplex, string(), pit);
553 // This code is reached if lyx2lyx failed (for
554 // some reason) to change the file format of
560 bool the_end = readBody(lex, pit);
561 params.setPaperStuff();
564 Alert::error(_("Document format failure"),
565 _("The document ended unexpectedly, which means "
566 "that it is probably corrupted."));
572 // Should probably be moved to somewhere else: BufferView? LyXView?
573 bool Buffer::save() const
575 // We don't need autosaves in the immediate future. (Asger)
576 resetAutosaveTimers();
580 if (lyxrc.make_backup) {
581 s = fileName() + '~';
582 if (!lyxrc.backupdir_path.empty())
583 s = AddName(lyxrc.backupdir_path,
584 subst(os::slashify_path(s),'/','!'));
586 // Rename is the wrong way of making a backup,
587 // this is the correct way.
588 /* truss cp fil fil2:
589 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
590 stat("LyXVC.lyx", 0xEFFFF688) = 0
591 open("LyXVC.lyx", O_RDONLY) = 3
592 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
593 fstat(4, 0xEFFFF508) = 0
594 fstat(3, 0xEFFFF508) = 0
595 read(3, " # T h i s f i l e w".., 8192) = 5579
596 write(4, " # T h i s f i l e w".., 5579) = 5579
597 read(3, 0xEFFFD4A0, 8192) = 0
600 chmod("LyXVC3.lyx", 0100644) = 0
601 lseek(0, 0, SEEK_CUR) = 46440
605 // Should probably have some more error checking here.
606 // Doing it this way, also makes the inodes stay the same.
607 // This is still not a very good solution, in particular we
608 // might loose the owner of the backup.
609 FileInfo finfo(fileName());
611 mode_t fmode = finfo.getMode();
612 struct utimbuf times = {
613 finfo.getAccessTime(),
614 finfo.getModificationTime() };
616 ifstream ifs(fileName().c_str());
617 ofstream ofs(s.c_str(), ios::out|ios::trunc);
622 ::chmod(s.c_str(), fmode);
624 if (::utime(s.c_str(), ×)) {
625 lyxerr << "utime error." << endl;
628 lyxerr << "LyX was not able to make "
629 "backup copy. Beware." << endl;
634 if (writeFile(fileName())) {
636 removeAutosaveFile(fileName());
638 // Saving failed, so backup is not backup
639 if (lyxrc.make_backup) {
640 lyx::rename(s, fileName());
648 bool Buffer::writeFile(string const & fname) const
650 if (read_only && (fname == fileName())) {
654 FileInfo finfo(fname);
655 if (finfo.exist() && !finfo.writable()) {
659 ofstream ofs(fname.c_str());
665 // Use the standard "C" locale for file output.
666 ofs.imbue(std::locale::classic());
669 // The top of the file should not be written by params.
671 // write out a comment in the top of the file
672 ofs << '#' << lyx_docversion
673 << " created this file. For more info see http://www.lyx.org/\n"
674 << "\\lyxformat " << LYX_FORMAT << "\n";
676 // now write out the buffer paramters.
677 params.writeFile(ofs);
679 ofs << "\\end_header\n";
681 Paragraph::depth_type depth = 0;
683 // this will write out all the paragraphs
684 // using recursive descent.
685 ParagraphList::iterator pit = paragraphs.begin();
686 ParagraphList::iterator pend = paragraphs.end();
687 for (; pit != pend; ++pit)
688 pit->write(this, ofs, params, depth);
690 // Write marker that shows file is complete
691 ofs << "\n\\the_end" << endl;
695 // how to check if close went ok?
696 // Following is an attempt... (BE 20001011)
698 // good() returns false if any error occured, including some
700 // bad() returns true if something bad happened in the buffer,
701 // which should include file system full errors.
708 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
710 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
722 pair<int, string> const addDepth(int depth, int ldepth)
726 d += (ldepth - depth) * 2;
727 return make_pair(d, string(d, ' '));
733 string const Buffer::asciiParagraph(Paragraph const & par,
734 unsigned int linelen,
735 bool noparbreak) const
737 ostringstream buffer;
738 Paragraph::depth_type depth = 0;
740 Paragraph::depth_type ltype_depth = 0;
741 bool ref_printed = false;
742 // if (!par->previous()) {
744 // begins or ends a deeper area ?
745 if (depth != par->params().depth()) {
746 if (par->params().depth() > depth) {
747 while (par->params().depth() > depth) {
751 while (par->params().depth() < depth) {
757 depth = par.params().depth();
760 // First write the layout
761 string const & tmp = par.layout()->name();
762 if (compare_no_case(tmp, "itemize") == 0) {
764 ltype_depth = depth + 1;
765 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
767 ltype_depth = depth + 1;
768 } else if (contains(ascii_lowercase(tmp), "ection")) {
770 ltype_depth = depth + 1;
771 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
773 ltype_depth = depth + 1;
774 } else if (compare_ascii_no_case(tmp, "description") == 0) {
776 ltype_depth = depth + 1;
777 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
780 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
788 /* maybe some vertical spaces */
790 /* the labelwidthstring used in lists */
794 /* some pagebreaks? */
798 /* what about the alignment */
800 // linelen <= 0 is special and means we don't have paragraph breaks
802 string::size_type currlinelen = 0;
808 buffer << string(depth * 2, ' ');
809 currlinelen += depth * 2;
812 // we should probably change to the paragraph language in the
813 // gettext here (if possible) so that strings are outputted in
814 // the correct language! (20012712 Jug)
818 case 4: // (Sub)Paragraph
819 case 5: // Description
823 buffer << _("Abstract") << "\n\n";
826 string const abst = _("Abstract: ");
828 currlinelen += abst.length();
831 case 7: // Bibliography
834 buffer << _("References") << "\n\n";
837 string const refs = _("References: ");
839 currlinelen += refs.length();
847 string const parlab = par.params().labelString();
848 buffer << parlab << ' ';
849 currlinelen += parlab.length() + 1;
857 pair<int, string> p = addDepth(depth, ltype_depth);
859 currlinelen += p.first;
862 // this is to change the linebreak to do it by word a bit more
863 // intelligent hopefully! (only in the case where we have a
864 // max linelength!) (Jug)
868 for (pos_type i = 0; i < par.size(); ++i) {
869 char c = par.getUChar(params, i);
871 case Paragraph::META_INSET:
873 Inset const * inset = par.getInset(i);
877 currlinelen += word.length();
880 if (inset->ascii(this, buffer, linelen)) {
881 // to be sure it breaks paragraph
882 currlinelen += linelen;
891 currlinelen + word.length() > linelen - 10) {
893 pair<int, string> p = addDepth(depth, ltype_depth);
895 currlinelen = p.first;
898 buffer << word << ' ';
899 currlinelen += word.length() + 1;
906 lyxerr[Debug::INFO] <<
907 "writeAsciiFile: NULL char in structure." << endl;
910 (currlinelen + word.length()) > linelen)
914 pair<int, string> p =
915 addDepth(depth, ltype_depth);
917 currlinelen = p.first;
924 return STRCONV(buffer.str());
928 void Buffer::writeFileAscii(string const & fname, int linelen)
930 ofstream ofs(fname.c_str());
932 string const file = MakeDisplayPath(fname, 50);
933 string text = bformat(_("Could not save the document\n%1$s."), file);
934 Alert::error(_("Could not save document"), text);
937 writeFileAscii(ofs, linelen);
941 void Buffer::writeFileAscii(ostream & os, int linelen)
943 ParagraphList::iterator beg = paragraphs.begin();
944 ParagraphList::iterator end = paragraphs.end();
945 ParagraphList::iterator it = beg;
946 for (; it != end; ++it) {
947 os << asciiParagraph(*it, linelen, it == beg);
954 void Buffer::makeLaTeXFile(string const & fname,
955 string const & original_path,
956 bool nice, bool only_body, bool only_preamble)
958 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
960 ofstream ofs(fname.c_str());
962 string const file = MakeDisplayPath(fname, 50);
963 string text = bformat(_("Could not open the specified document\n%1$s."),
965 Alert::error(_("Could not open file"), text);
969 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
973 lyxerr << "File was not closed properly." << endl;
978 void Buffer::makeLaTeXFile(ostream & os,
979 string const & original_path,
980 bool nice, bool only_body, bool only_preamble)
982 niceFile = nice; // this will be used by Insetincludes.
984 // validate the buffer.
985 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
986 LaTeXFeatures features(params);
988 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
991 // The starting paragraph of the coming rows is the
992 // first paragraph of the document. (Asger)
993 texrow.start(paragraphs.begin()->id(), 0);
995 if (!only_body && nice) {
996 os << "%% " << lyx_docversion << " created this file. "
997 "For more info, see http://www.lyx.org/.\n"
998 "%% Do not edit unless you really know what "
1003 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1004 // There are a few differences between nice LaTeX and usual files:
1005 // usual is \batchmode and has a
1006 // special input@path to allow the including of figures
1007 // with either \input or \includegraphics (what figinsets do).
1008 // input@path is set when the actual parameter
1009 // original_path is set. This is done for usual tex-file, but not
1010 // for nice-latex-file. (Matthias 250696)
1013 // code for usual, NOT nice-latex-file
1014 os << "\\batchmode\n"; // changed
1015 // from \nonstopmode
1018 if (!original_path.empty()) {
1019 string inputpath = os::external_path(original_path);
1020 subst(inputpath, "~", "\\string~");
1021 os << "\\makeatletter\n"
1022 << "\\def\\input@path{{"
1023 << inputpath << "/}}\n"
1024 << "\\makeatother\n";
1030 // Write the preamble
1031 params.writeLaTeX(os, features, texrow);
1037 os << "\\begin{document}\n";
1040 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1042 if (!lyxrc.language_auto_begin) {
1043 os << subst(lyxrc.language_command_begin, "$$lang",
1044 params.language->babel())
1049 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1051 // add this just in case after all the paragraphs
1055 if (!lyxrc.language_auto_end) {
1056 os << subst(lyxrc.language_command_end, "$$lang",
1057 params.language->babel())
1063 os << "\\end{document}\n";
1066 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1068 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1072 // Just to be sure. (Asger)
1075 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1076 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1079 // we want this to be true outside previews (for insetexternal)
1084 bool Buffer::isLatex() const
1086 return params.getLyXTextClass().outputType() == LATEX;
1090 bool Buffer::isLinuxDoc() const
1092 return params.getLyXTextClass().outputType() == LINUXDOC;
1096 bool Buffer::isLiterate() const
1098 return params.getLyXTextClass().outputType() == LITERATE;
1102 bool Buffer::isDocBook() const
1104 return params.getLyXTextClass().outputType() == DOCBOOK;
1108 bool Buffer::isSGML() const
1110 LyXTextClass const & tclass = params.getLyXTextClass();
1112 return tclass.outputType() == LINUXDOC ||
1113 tclass.outputType() == DOCBOOK;
1117 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1119 ofstream ofs(fname.c_str());
1122 string const file = MakeDisplayPath(fname, 50);
1123 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1125 Alert::error(_("Could not save document"), text);
1129 niceFile = nice; // this will be used by included files.
1131 LaTeXFeatures features(params);
1137 LyXTextClass const & tclass = params.getLyXTextClass();
1139 string top_element = tclass.latexname();
1142 ofs << "<!doctype linuxdoc system";
1144 string preamble = params.preamble;
1145 const string name = nice ? ChangeExtension(filename_, ".sgml")
1147 preamble += features.getIncludedFiles(name);
1148 preamble += features.getLyXSGMLEntities();
1150 if (!preamble.empty()) {
1151 ofs << " [ " << preamble << " ]";
1155 if (params.options.empty())
1156 sgml::openTag(ofs, 0, false, top_element);
1158 string top = top_element;
1160 top += params.options;
1161 sgml::openTag(ofs, 0, false, top);
1165 ofs << "<!-- " << lyx_docversion
1166 << " created this file. For more info see http://www.lyx.org/"
1169 Paragraph::depth_type depth = 0; // paragraph depth
1171 vector<string> environment_stack(5);
1173 ParagraphList::iterator pit = paragraphs.begin();
1174 ParagraphList::iterator pend = paragraphs.end();
1175 for (; pit != pend; ++pit) {
1176 LyXLayout_ptr const & style = pit->layout();
1177 // treat <toc> as a special case for compatibility with old code
1178 if (pit->isInset(0)) {
1179 Inset * inset = pit->getInset(0);
1180 Inset::Code lyx_code = inset->lyxCode();
1181 if (lyx_code == Inset::TOC_CODE) {
1182 string const temp = "toc";
1183 sgml::openTag(ofs, depth, false, temp);
1188 // environment tag closing
1189 for (; depth > pit->params().depth(); --depth) {
1190 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1191 environment_stack[depth].erase();
1194 // write opening SGML tags
1195 switch (style->latextype) {
1196 case LATEX_PARAGRAPH:
1197 if (depth == pit->params().depth()
1198 && !environment_stack[depth].empty()) {
1199 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1200 environment_stack[depth].erase();
1206 sgml::openTag(ofs, depth, false, style->latexname());
1212 _("Error: Wrong depth for LatexType Command.\n"));
1214 if (!environment_stack[depth].empty()) {
1215 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1219 environment_stack[depth].erase();
1220 sgml::openTag(ofs, depth, false, style->latexname());
1223 case LATEX_ENVIRONMENT:
1224 case LATEX_ITEM_ENVIRONMENT:
1225 case LATEX_BIB_ENVIRONMENT:
1227 string const & latexname = style->latexname();
1229 if (depth == pit->params().depth()
1230 && environment_stack[depth] != latexname) {
1231 sgml::closeTag(ofs, depth, false,
1232 environment_stack[depth]);
1233 environment_stack[depth].erase();
1235 if (depth < pit->params().depth()) {
1236 depth = pit->params().depth();
1237 environment_stack[depth].erase();
1239 if (environment_stack[depth] != latexname) {
1241 sgml::openTag(ofs, depth, false, "p");
1243 sgml::openTag(ofs, depth, false, latexname);
1245 if (environment_stack.size() == depth + 1)
1246 environment_stack.push_back("!-- --");
1247 environment_stack[depth] = latexname;
1250 if (style->latexparam() == "CDATA")
1253 if (style->latextype == LATEX_ENVIRONMENT) break;
1255 if (style->labeltype == LABEL_MANUAL)
1260 sgml::openTag(ofs, depth + 1, false, item_name);
1265 sgml::openTag(ofs, depth, false, style->latexname());
1269 simpleLinuxDocOnePar(ofs, pit, depth);
1272 // write closing SGML tags
1273 switch (style->latextype) {
1276 case LATEX_ENVIRONMENT:
1277 case LATEX_ITEM_ENVIRONMENT:
1278 case LATEX_BIB_ENVIRONMENT:
1279 if (style->latexparam() == "CDATA")
1283 sgml::closeTag(ofs, depth, false, style->latexname());
1289 for (int i = depth; i >= 0; --i)
1290 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1294 sgml::closeTag(ofs, 0, false, top_element);
1298 // How to check for successful close
1300 // we want this to be true outside previews (for insetexternal)
1305 // checks, if newcol chars should be put into this line
1306 // writes newline, if necessary.
1309 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1310 string::size_type newcol)
1313 if (colcount > lyxrc.ascii_linelen) {
1315 colcount = newcol; // assume write after this call
1330 string tag_name(PAR_TAG const & pt) {
1332 case NONE: return "!-- --";
1333 case TT: return "tt";
1334 case SF: return "sf";
1335 case BF: return "bf";
1336 case IT: return "it";
1337 case SL: return "sl";
1338 case EM: return "em";
1345 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1347 p1 = static_cast<PAR_TAG>(p1 | p2);
1352 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1354 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1360 // Handle internal paragraph parsing -- layout already processed.
1361 void Buffer::simpleLinuxDocOnePar(ostream & os,
1362 ParagraphList::iterator par,
1363 Paragraph::depth_type /*depth*/) const
1365 LyXLayout_ptr const & style = par->layout();
1367 string::size_type char_line_count = 5; // Heuristic choice ;-)
1369 // gets paragraph main font
1372 if (style->labeltype == LABEL_MANUAL) {
1373 font_old = style->labelfont;
1376 font_old = style->font;
1380 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1381 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1382 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1385 stack<PAR_TAG> tag_state;
1386 // parsing main loop
1387 for (pos_type i = 0; i < par->size(); ++i) {
1389 PAR_TAG tag_close = NONE;
1390 list < PAR_TAG > tag_open;
1392 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1394 if (font_old.family() != font.family()) {
1395 switch (family_type) {
1396 case LyXFont::SANS_FAMILY:
1399 case LyXFont::TYPEWRITER_FAMILY:
1406 family_type = font.family();
1408 switch (family_type) {
1409 case LyXFont::SANS_FAMILY:
1410 tag_open.push_back(SF);
1412 case LyXFont::TYPEWRITER_FAMILY:
1413 tag_open.push_back(TT);
1420 if (font_old.series() != font.series()) {
1421 switch (series_type) {
1422 case LyXFont::BOLD_SERIES:
1429 series_type = font.series();
1431 switch (series_type) {
1432 case LyXFont::BOLD_SERIES:
1433 tag_open.push_back(BF);
1441 if (font_old.shape() != font.shape()) {
1442 switch (shape_type) {
1443 case LyXFont::ITALIC_SHAPE:
1446 case LyXFont::SLANTED_SHAPE:
1453 shape_type = font.shape();
1455 switch (shape_type) {
1456 case LyXFont::ITALIC_SHAPE:
1457 tag_open.push_back(IT);
1459 case LyXFont::SLANTED_SHAPE:
1460 tag_open.push_back(SL);
1467 if (font_old.emph() != font.emph()) {
1468 if (font.emph() == LyXFont::ON) {
1469 tag_open.push_back(EM);
1478 list < PAR_TAG > temp;
1479 while (!tag_state.empty() && tag_close) {
1480 PAR_TAG k = tag_state.top();
1482 os << "</" << tag_name(k) << '>';
1489 for(list< PAR_TAG >::const_iterator j = temp.begin();
1490 j != temp.end(); ++j) {
1492 os << '<' << tag_name(*j) << '>';
1495 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1496 j != tag_open.end(); ++j) {
1498 os << '<' << tag_name(*j) << '>';
1501 char c = par->getChar(i);
1503 if (c == Paragraph::META_INSET) {
1504 Inset * inset = par->getInset(i);
1505 inset->linuxdoc(this, os);
1510 if (style->latexparam() == "CDATA") {
1511 // "TeX"-Mode on == > SGML-Mode on.
1518 boost::tie(ws, str) = sgml::escapeChar(c);
1519 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1520 // in freespacing mode, spaces are
1521 // non-breaking characters
1522 if (desc_on) {// if char is ' ' then...
1525 sgmlLineBreak(os, char_line_count, 6);
1529 sgmlLineBreak(os, char_line_count, 1);
1534 char_line_count += str.length();
1540 while (!tag_state.empty()) {
1541 os << "</" << tag_name(tag_state.top()) << '>';
1545 // resets description flag correctly
1547 // <tag> not closed...
1548 sgmlLineBreak(os, char_line_count, 6);
1554 // Print an error message.
1555 void Buffer::sgmlError(ParagraphList::iterator /*par*/, int /*pos*/,
1556 string const & /*message*/) const
1558 #ifdef WITH_WARNINGS
1559 #warning This is wrong we cannot insert an inset like this!!!
1560 // I guess this was Jose' so I explain you more or less why this
1561 // is wrong. This way you insert something in the paragraph and
1562 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1563 // I deactivate this code, have a look at BufferView::insertErrors
1564 // how you should do this correctly! (Jug 20020315)
1567 // insert an error marker in text
1568 InsetError * new_inset = new InsetError(message);
1569 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1575 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1577 ofstream ofs(fname.c_str());
1579 string const file = MakeDisplayPath(fname, 50);
1580 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1582 Alert::error(_("Could not save document"), text);
1586 niceFile = nice; // this will be used by Insetincludes.
1588 LaTeXFeatures features(params);
1593 LyXTextClass const & tclass = params.getLyXTextClass();
1594 string top_element = tclass.latexname();
1597 ofs << "<!DOCTYPE " << top_element
1598 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1600 string preamble = params.preamble;
1601 const string name = nice ? ChangeExtension(filename_, ".sgml")
1603 preamble += features.getIncludedFiles(name);
1604 preamble += features.getLyXSGMLEntities();
1606 if (!preamble.empty()) {
1607 ofs << "\n [ " << preamble << " ]";
1612 string top = top_element;
1614 top += params.language->code();
1617 if (!params.options.empty()) {
1619 top += params.options;
1621 sgml::openTag(ofs, 0, false, top);
1623 ofs << "<!-- DocBook file was created by " << lyx_docversion
1624 << "\n See http://www.lyx.org/ for more information -->\n";
1626 vector<string> environment_stack(10);
1627 vector<string> environment_inner(10);
1628 vector<string> command_stack(10);
1630 bool command_flag = false;
1631 Paragraph::depth_type command_depth = 0;
1632 Paragraph::depth_type command_base = 0;
1633 Paragraph::depth_type cmd_depth = 0;
1634 Paragraph::depth_type depth = 0; // paragraph depth
1637 string command_name;
1639 ParagraphList::iterator par = paragraphs.begin();
1640 ParagraphList::iterator pend = paragraphs.end();
1642 for (; par != pend; ++par) {
1646 int desc_on = 0; // description mode
1648 LyXLayout_ptr const & style = par->layout();
1650 // environment tag closing
1651 for (; depth > par->params().depth(); --depth) {
1652 if (environment_inner[depth] != "!-- --") {
1653 item_name = "listitem";
1654 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1655 if (environment_inner[depth] == "varlistentry")
1656 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1658 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1659 environment_stack[depth].erase();
1660 environment_inner[depth].erase();
1663 if (depth == par->params().depth()
1664 && environment_stack[depth] != style->latexname()
1665 && !environment_stack[depth].empty()) {
1666 if (environment_inner[depth] != "!-- --") {
1667 item_name= "listitem";
1668 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1669 if (environment_inner[depth] == "varlistentry")
1670 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1673 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1675 environment_stack[depth].erase();
1676 environment_inner[depth].erase();
1679 // Write opening SGML tags.
1680 switch (style->latextype) {
1681 case LATEX_PARAGRAPH:
1682 sgml::openTag(ofs, depth + command_depth,
1683 false, style->latexname());
1689 _("Error: Wrong depth for LatexType Command.\n"));
1691 command_name = style->latexname();
1693 sgmlparam = style->latexparam();
1694 c_params = split(sgmlparam, c_depth,'|');
1696 cmd_depth = lyx::atoi(c_depth);
1699 if (cmd_depth < command_base) {
1700 for (Paragraph::depth_type j = command_depth;
1701 j >= command_base; --j) {
1702 sgml::closeTag(ofs, j, false, command_stack[j]);
1705 command_depth = command_base = cmd_depth;
1706 } else if (cmd_depth <= command_depth) {
1707 for (int j = command_depth;
1708 j >= int(cmd_depth); --j) {
1709 sgml::closeTag(ofs, j, false, command_stack[j]);
1712 command_depth = cmd_depth;
1714 command_depth = cmd_depth;
1716 command_depth = command_base = cmd_depth;
1717 command_flag = true;
1719 if (command_stack.size() == command_depth + 1)
1720 command_stack.push_back(string());
1721 command_stack[command_depth] = command_name;
1723 // treat label as a special case for
1724 // more WYSIWYM handling.
1725 // This is a hack while paragraphs can't have
1726 // attributes, like id in this case.
1727 if (par->isInset(0)) {
1728 Inset * inset = par->getInset(0);
1729 Inset::Code lyx_code = inset->lyxCode();
1730 if (lyx_code == Inset::LABEL_CODE) {
1731 command_name += " id=\"";
1732 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1733 command_name += '"';
1738 sgml::openTag(ofs, depth + command_depth, false, command_name);
1740 item_name = c_params.empty() ? "title" : c_params;
1741 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1744 case LATEX_ENVIRONMENT:
1745 case LATEX_ITEM_ENVIRONMENT:
1746 if (depth < par->params().depth()) {
1747 depth = par->params().depth();
1748 environment_stack[depth].erase();
1751 if (environment_stack[depth] != style->latexname()) {
1752 if (environment_stack.size() == depth + 1) {
1753 environment_stack.push_back("!-- --");
1754 environment_inner.push_back("!-- --");
1756 environment_stack[depth] = style->latexname();
1757 environment_inner[depth] = "!-- --";
1758 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1760 if (environment_inner[depth] != "!-- --") {
1761 item_name= "listitem";
1762 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1763 if (environment_inner[depth] == "varlistentry")
1764 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1768 if (style->latextype == LATEX_ENVIRONMENT) {
1769 if (!style->latexparam().empty()) {
1770 if (style->latexparam() == "CDATA")
1773 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1778 desc_on = (style->labeltype == LABEL_MANUAL);
1780 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1781 sgml::openTag(ofs, depth + 1 + command_depth,
1782 false, environment_inner[depth]);
1784 item_name = desc_on ? "term" : "para";
1785 sgml::openTag(ofs, depth + 1 + command_depth,
1789 sgml::openTag(ofs, depth + command_depth,
1790 false, style->latexname());
1794 simpleDocBookOnePar(ofs, par, desc_on,
1795 depth + 1 + command_depth);
1798 // write closing SGML tags
1799 switch (style->latextype) {
1801 end_tag = c_params.empty() ? "title" : c_params;
1802 sgml::closeTag(ofs, depth + command_depth,
1805 case LATEX_ENVIRONMENT:
1806 if (!style->latexparam().empty()) {
1807 if (style->latexparam() == "CDATA")
1810 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1813 case LATEX_ITEM_ENVIRONMENT:
1814 if (desc_on == 1) break;
1816 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1818 case LATEX_PARAGRAPH:
1819 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1822 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1828 for (int d = depth; d >= 0; --d) {
1829 if (!environment_stack[depth].empty()) {
1830 if (environment_inner[depth] != "!-- --") {
1831 item_name = "listitem";
1832 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1833 if (environment_inner[depth] == "varlistentry")
1834 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1837 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1841 for (int j = command_depth; j >= 0 ; --j)
1842 if (!command_stack[j].empty()) {
1843 sgml::closeTag(ofs, j, false, command_stack[j]);
1848 sgml::closeTag(ofs, 0, false, top_element);
1851 // How to check for successful close
1853 // we want this to be true outside previews (for insetexternal)
1858 void Buffer::simpleDocBookOnePar(ostream & os,
1859 ParagraphList::iterator par, int & desc_on,
1860 Paragraph::depth_type depth) const
1862 bool emph_flag = false;
1864 LyXLayout_ptr const & style = par->layout();
1866 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1868 int char_line_count = depth;
1869 //if (!style.free_spacing)
1870 // os << string(depth,' ');
1872 // parsing main loop
1873 for (pos_type i = 0; i < par->size(); ++i) {
1874 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1876 // handle <emphasis> tag
1877 if (font_old.emph() != font.emph()) {
1878 if (font.emph() == LyXFont::ON) {
1879 if (style->latexparam() == "CDATA")
1882 if (style->latexparam() == "CDATA")
1886 if (style->latexparam() == "CDATA")
1888 os << "</emphasis>";
1889 if (style->latexparam() == "CDATA")
1896 if (par->isInset(i)) {
1897 Inset * inset = par->getInset(i);
1898 // don't print the inset in position 0 if desc_on == 3 (label)
1899 if (i || desc_on != 3) {
1900 if (style->latexparam() == "CDATA")
1902 inset->docbook(this, os, false);
1903 if (style->latexparam() == "CDATA")
1907 char c = par->getChar(i);
1910 boost::tie(ws, str) = sgml::escapeChar(c);
1912 if (style->pass_thru) {
1914 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1916 } else if (desc_on ==1) {
1918 os << "\n</term><listitem><para>";
1928 if (style->latexparam() == "CDATA")
1930 os << "</emphasis>";
1931 if (style->latexparam() == "CDATA")
1935 // resets description flag correctly
1937 // <term> not closed...
1938 os << "</term>\n<listitem><para> </para>";
1940 if (style->free_spacing)
1945 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1946 // Other flags: -wall -v0 -x
1947 int Buffer::runChktex()
1949 if (!users->text) return 0;
1951 users->owner()->busy(true);
1953 // get LaTeX-Filename
1954 string const name = getLatexName();
1955 string path = filePath();
1957 string const org_path = path;
1958 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1962 Path p(path); // path to LaTeX file
1963 users->owner()->message(_("Running chktex..."));
1965 // Remove all error insets
1966 bool const removedErrorInsets = users->removeAutoInsets();
1968 // Generate the LaTeX file if neccessary
1969 makeLaTeXFile(name, org_path, false);
1972 Chktex chktex(lyxrc.chktex_command, name, filePath());
1973 int res = chktex.run(terr); // run chktex
1976 Alert::error(_("chktex failure"),
1977 _("Could not run chktex successfully."));
1978 } else if (res > 0) {
1979 // Insert all errors as errors boxes
1980 users->showErrorList();
1983 // if we removed error insets before we ran chktex or if we inserted
1984 // error insets after we ran chktex, this must be run:
1985 if (removedErrorInsets || res) {
1986 #warning repaint needed here, or do you mean update() ?
1990 users->owner()->busy(false);
1996 void Buffer::validate(LaTeXFeatures & features) const
1998 LyXTextClass const & tclass = params.getLyXTextClass();
2000 if (params.tracking_changes) {
2001 features.require("dvipost");
2002 features.require("color");
2005 // AMS Style is at document level
2006 if (params.use_amsmath == BufferParams::AMS_ON
2007 || tclass.provides(LyXTextClass::amsmath))
2008 features.require("amsmath");
2010 for_each(paragraphs.begin(), paragraphs.end(),
2011 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2013 // the bullet shapes are buffer level not paragraph level
2014 // so they are tested here
2015 for (int i = 0; i < 4; ++i) {
2016 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2017 int const font = params.user_defined_bullets[i].getFont();
2019 int const c = params
2020 .user_defined_bullets[i]
2027 features.require("latexsym");
2029 } else if (font == 1) {
2030 features.require("amssymb");
2031 } else if ((font >= 2 && font <= 5)) {
2032 features.require("pifont");
2037 if (lyxerr.debugging(Debug::LATEX)) {
2038 features.showStruct();
2043 vector<string> const Buffer::getLabelList() const
2045 /// if this is a child document and the parent is already loaded
2046 /// Use the parent's list instead [ale990407]
2047 if (!params.parentname.empty()
2048 && bufferlist.exists(params.parentname)) {
2049 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2051 return tmp->getLabelList();
2054 vector<string> label_list;
2055 for (inset_iterator it = inset_const_iterator_begin();
2056 it != inset_const_iterator_end(); ++it) {
2057 vector<string> const l = it->getLabelList();
2058 label_list.insert(label_list.end(), l.begin(), l.end());
2064 // This is also a buffer property (ale)
2065 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2067 /// if this is a child document and the parent is already loaded
2068 /// use the parent's list instead [ale990412]
2069 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2070 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2072 tmp->fillWithBibKeys(keys);
2077 for (inset_iterator it = inset_const_iterator_begin();
2078 it != inset_const_iterator_end(); ++it) {
2079 if (it->lyxCode() == Inset::BIBTEX_CODE)
2080 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2081 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2082 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2083 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2084 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2085 string const key = bib.getContents();
2086 string const opt = bib.getOptions();
2087 string const ref; // = pit->asString(this, false);
2088 string const info = opt + "TheBibliographyRef" + ref;
2089 keys.push_back(pair<string, string>(key, info));
2095 bool Buffer::isDepClean(string const & name) const
2097 DepClean::const_iterator it = dep_clean_.find(name);
2098 if (it == dep_clean_.end())
2104 void Buffer::markDepClean(string const & name)
2106 dep_clean_[name] = true;
2110 bool Buffer::dispatch(string const & command, bool * result)
2112 // Split command string into command and argument
2114 string line = ltrim(command);
2115 string const arg = trim(split(line, cmd, ' '));
2117 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2121 bool Buffer::dispatch(int action, string const & argument, bool * result)
2123 bool dispatched = true;
2127 bool const tmp = Exporter::Export(this, argument, false);
2140 void Buffer::resizeInsets(BufferView * bv)
2142 /// then remove all LyXText in text-insets
2143 for_each(paragraphs.begin(), paragraphs.end(),
2144 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2148 void Buffer::redraw()
2150 #warning repaint needed here, or do you mean update() ?
2156 void Buffer::changeLanguage(Language const * from, Language const * to)
2158 lyxerr << "Changing Language!" << endl;
2160 // Take care of l10n/i18n
2163 ParIterator end = par_iterator_end();
2164 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2165 (*it)->changeLanguage(params, from, to);
2169 void Buffer::updateDocLang(Language const * nlang)
2171 messages_.reset(new Messages(nlang->code()));
2175 bool Buffer::isMultiLingual()
2177 ParIterator end = par_iterator_end();
2178 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2179 if ((*it)->isMultiLingual(params))
2186 void Buffer::inset_iterator::setParagraph()
2188 while (pit != pend) {
2189 it = pit->insetlist.begin();
2190 if (it != pit->insetlist.end())
2197 Inset * Buffer::getInsetFromID(int id_arg) const
2199 for (inset_iterator it = inset_const_iterator_begin();
2200 it != inset_const_iterator_end(); ++it)
2202 if (it->id() == id_arg)
2204 Inset * in = it->getInsetFromID(id_arg);
2212 ParagraphList::iterator Buffer::getParFromID(int id) const
2214 #warning FIXME: const correctness! (Andre)
2215 ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
2216 ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
2218 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2220 // John says this is called with id == -1 from undo
2221 lyxerr << "getParFromID(), id: " << id << endl;
2225 for (; it != end; ++it) {
2226 // go on then, show me how to remove
2228 if ((*it)->id() == id) {
2237 bool Buffer::hasParWithID(int id) const
2239 ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
2240 ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
2243 // John says this is called with id == -1 from undo
2244 lyxerr << "hasParWithID(), id: " << id << endl;
2248 for (; it != end; ++it)
2249 if ((*it)->id() == id)
2256 ParIterator Buffer::par_iterator_begin()
2258 return ParIterator(&*(paragraphs.begin()));
2262 ParIterator Buffer::par_iterator_end()
2264 return ParIterator();
2267 ParConstIterator Buffer::par_iterator_begin() const
2269 return ParConstIterator(&*(paragraphs.begin()));
2273 ParConstIterator Buffer::par_iterator_end() const
2275 return ParConstIterator();
2280 void Buffer::addUser(BufferView * u)
2286 void Buffer::delUser(BufferView *)
2292 Language const * Buffer::getLanguage() const
2294 return params.language;
2298 string const Buffer::B_(string const & l10n) const
2300 if (messages_.get()) {
2301 return messages_->get(l10n);
2308 bool Buffer::isClean() const
2314 bool Buffer::isBakClean() const
2320 void Buffer::markClean() const
2326 // if the .lyx file has been saved, we don't need an
2332 void Buffer::markBakClean()
2338 void Buffer::setUnnamed(bool flag)
2344 bool Buffer::isUnnamed()
2350 void Buffer::markDirty()
2358 DepClean::iterator it = dep_clean_.begin();
2359 DepClean::const_iterator const end = dep_clean_.end();
2361 for (; it != end; ++it) {
2367 string const & Buffer::fileName() const
2373 string const & Buffer::filePath() const
2379 bool Buffer::isReadonly() const
2385 BufferView * Buffer::getUser() const
2391 void Buffer::setParentName(string const & name)
2393 params.parentname = name;
2397 Buffer::inset_iterator::inset_iterator()
2402 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2409 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2413 if (it == pit->insetlist.end()) {
2422 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2424 inset_iterator tmp = *this;
2430 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2432 return *it.getInset();
2436 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2438 return it.getInset();
2442 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2448 lyx::pos_type Buffer::inset_iterator::getPos() const
2454 bool operator==(Buffer::inset_iterator const & iter1,
2455 Buffer::inset_iterator const & iter2)
2457 return iter1.pit == iter2.pit
2458 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2462 bool operator!=(Buffer::inset_iterator const & iter1,
2463 Buffer::inset_iterator const & iter2)
2465 return !(iter1 == iter2);