3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
14 #include "bufferlist.h"
15 #include "LyXAction.h"
18 #include "tex-strings.h"
20 #include "bufferview_funcs.h"
26 #include "LaTeXFeatures.h"
31 #include "errorlist.h"
34 #include "BufferView.h"
35 #include "ParagraphParameters.h"
36 #include "iterators.h"
37 #include "lyxtextclasslist.h"
39 #include "paragraph_funcs.h"
43 #include "frontends/LyXView.h"
45 #include "mathed/formulamacro.h"
46 #include "mathed/formula.h"
48 #include "insets/inseterror.h"
49 #include "insets/insetbibitem.h"
50 #include "insets/insetbibtex.h"
51 #include "insets/insetinclude.h"
52 #include "insets/insettext.h"
54 #include "frontends/Dialogs.h"
55 #include "frontends/Alert.h"
57 #include "graphics/Previews.h"
59 #include "support/textutils.h"
60 #include "support/filetools.h"
61 #include "support/path.h"
62 #include "support/os.h"
63 #include "support/tostr.h"
64 #include "support/lyxlib.h"
65 #include "support/FileInfo.h"
66 #include "support/lyxmanip.h"
67 #include "support/lyxtime.h"
69 #include <boost/bind.hpp>
70 #include <boost/tuple/tuple.hpp>
82 #include <sys/types.h>
89 #ifndef CXX_GLOBAL_CSTD
101 using std::make_pair;
109 using lyx::textclass_type;
111 // all these externs should eventually be removed.
112 extern BufferList bufferlist;
116 const int LYX_FORMAT = 223;
120 Buffer::Buffer(string const & file, bool ronly)
121 : niceFile(true), lyx_clean(true), bak_clean(true),
122 unnamed(false), read_only(ronly),
123 filename_(file), users(0)
125 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
126 filepath_ = OnlyPath(file);
128 if (read_only || lyxrc.use_tempdir) {
129 tmppath = CreateBufferTmpDir();
134 // set initial author
135 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
141 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
142 // here the buffer should take care that it is
143 // saved properly, before it goes into the void.
145 // make sure that views using this buffer
150 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
151 Alert::warning(_("Could not remove temporary directory"),
152 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
157 // Remove any previewed LaTeX snippets assocoated with this buffer.
158 grfx::Previews::get().removeLoader(this);
162 string const Buffer::getLatexName(bool no_path) const
164 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
165 return no_path ? OnlyFilename(name) : name;
169 pair<Buffer::LogType, string> const Buffer::getLogName() const
171 string const filename = getLatexName(false);
173 if (filename.empty())
174 return make_pair(Buffer::latexlog, string());
176 string path = OnlyPath(filename);
178 if (lyxrc.use_tempdir || !IsDirWriteable(path))
181 string const fname = AddName(path,
182 OnlyFilename(ChangeExtension(filename,
185 AddName(path, OnlyFilename(
186 ChangeExtension(filename,
187 formats.extension("literate") + ".out")));
189 // If no Latex log or Build log is newer, show Build log
191 FileInfo const f_fi(fname);
192 FileInfo const b_fi(bname);
195 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
196 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
197 return make_pair(Buffer::buildlog, bname);
199 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
200 return make_pair(Buffer::latexlog, fname);
204 void Buffer::setReadonly(bool flag)
206 if (read_only != flag) {
209 users->owner()->getDialogs().updateBufferDependent(false);
214 AuthorList & Buffer::authors()
216 return params.authorlist;
220 /// Update window titles of all users
221 // Should work on a list
222 void Buffer::updateTitles() const
225 users->owner()->updateWindowTitle();
229 /// Reset autosave timer of all users
230 // Should work on a list
231 void Buffer::resetAutosaveTimers() const
234 users->owner()->resetAutosaveTimer();
238 void Buffer::setFileName(string const & newfile)
240 filename_ = MakeAbsPath(newfile);
241 filepath_ = OnlyPath(filename_);
242 setReadonly(IsFileWriteable(filename_) == 0);
247 // We'll remove this later. (Lgb)
250 void unknownClass(string const & unknown)
252 Alert::warning(_("Unknown document class"),
253 bformat(_("Using the default document class, because the "
254 " class %1$s is unknown."), unknown));
259 int Buffer::readHeader(LyXLex & lex)
261 int unknown_tokens = 0;
265 string const token = lex.getString();
270 if (token == "\\end_header")
273 lyxerr[Debug::PARSER] << "Handling header token: `"
274 << token << '\'' << endl;
276 string unknown = params.readToken(lex, token);
277 if (!unknown.empty()) {
278 if (unknown[0] != '\\') {
279 unknownClass(unknown);
285 return unknown_tokens;
289 // candidate for move to BufferView
290 // (at least some parts in the beginning of the func)
293 // changed to be public and have one parameter
294 // if par = 0 normal behavior
295 // else insert behavior
296 // Returns false if "\the_end" is not read (Asger)
297 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
299 int unknown_tokens = 0;
301 Paragraph::depth_type depth = 0;
302 bool the_end_read = false;
304 if (paragraphs.empty()) {
305 unknown_tokens += readHeader(lex);
307 if (!params.getLyXTextClass().load()) {
308 string theclass = params.getLyXTextClass().name();
309 Alert::error(_("Can't load document class"), bformat(
310 "Using the default document class, because the "
311 " class %1$s could not be loaded.", theclass));
312 params.textclass = 0;
315 // We are inserting into an existing document
316 users->text->breakParagraph(paragraphs);
318 // We don't want to adopt the parameters from the
319 // document we insert, so read them into a temporary buffer
320 // and then discard it
322 Buffer tmpbuf("", false);
323 tmpbuf.readHeader(lex);
328 string const token = lex.getString();
333 lyxerr[Debug::PARSER] << "Handling token: `"
334 << token << '\'' << endl;
336 if (token == "\\the_end") {
341 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
345 if (unknown_tokens > 0) {
347 if (unknown_tokens == 1) {
348 s = bformat(_("Encountered one unknown token when reading "
349 "the document %1$s."), fileName());
351 s = bformat(_("Encountered %1$s unknown tokens when reading "
352 "the document %2$s."), tostr(unknown_tokens), fileName());
354 Alert::warning(_("Document format failure"), s);
361 int Buffer::readParagraph(LyXLex & lex, string const & token,
362 ParagraphList & pars, ParagraphList::iterator & pit,
363 Paragraph::depth_type & depth)
365 static Change current_change;
368 if (token == "\\layout") {
369 lex.pushToken(token);
372 par.params().depth(depth);
373 if (params.tracking_changes)
375 LyXFont f(LyXFont::ALL_INHERIT, params.language);
378 // FIXME: goddamn InsetTabular makes us pass a Buffer
380 unknown += ::readParagraph(*this, par, lex);
383 if (pit != pars.end())
385 pit = pars.insert(pit, par);
386 } else if (token == "\\begin_deeper") {
388 } else if (token == "\\end_deeper") {
390 lex.printError("\\end_deeper: " "depth is already null");
401 // needed to insert the selection
402 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
403 LyXFont const & fn,string const & str)
405 LyXLayout_ptr const & layout = par->layout();
409 par->checkInsertChar(font);
410 // insert the string, don't insert doublespace
411 bool space_inserted = true;
412 bool autobreakrows = !par->inInset() ||
413 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
414 for(string::const_iterator cit = str.begin();
415 cit != str.end(); ++cit) {
417 if (autobreakrows && (!par->empty() || layout->keepempty)) {
418 breakParagraph(params, paragraphs, par, pos,
419 layout->isEnvironment());
422 space_inserted = true;
426 // do not insert consecutive spaces if !free_spacing
427 } else if ((*cit == ' ' || *cit == '\t') &&
428 space_inserted && !layout->free_spacing &&
429 !par->isFreeSpacing())
432 } else if (*cit == '\t') {
433 if (!layout->free_spacing && !par->isFreeSpacing()) {
434 // tabs are like spaces here
435 par->insertChar(pos, ' ', font);
437 space_inserted = true;
439 const pos_type nb = 8 - pos % 8;
440 for (pos_type a = 0; a < nb ; ++a) {
441 par->insertChar(pos, ' ', font);
444 space_inserted = true;
446 } else if (!IsPrintable(*cit)) {
447 // Ignore unprintables
450 // just insert the character
451 par->insertChar(pos, *cit, font);
453 space_inserted = (*cit == ' ');
460 bool Buffer::readFile(LyXLex & lex, string const & filename)
462 bool ret = readFile(lex, filename, paragraphs.begin());
464 // After we have read a file, we must ensure that the buffer
465 // language is set and used in the gui.
466 // If you know of a better place to put this, please tell me. (Lgb)
467 updateDocLang(params.language);
473 // FIXME: all the below Alerts should give the filename..
474 bool Buffer::readFile(LyXLex & lex, string const & filename,
475 ParagraphList::iterator pit)
478 Alert::error(_("Document could not be read"),
479 _("The specified document could not be read."));
484 string const token(lex.getString());
487 Alert::error(_("Document could not be read"),
488 _("The specified document could not be read."));
492 // the first token _must_ be...
493 if (token != "\\lyxformat") {
494 Alert::error(_("Document format failure"),
495 _("The specified document is not a LyX document."));
500 string tmp_format = lex.getString();
501 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
502 // if present remove ".," from string.
503 string::size_type dot = tmp_format.find_first_of(".,");
504 //lyxerr << " dot found at " << dot << endl;
505 if (dot != string::npos)
506 tmp_format.erase(dot, 1);
507 file_format = strToInt(tmp_format);
508 //lyxerr << "format: " << file_format << endl;
509 if (file_format == LYX_FORMAT) {
511 } else if (file_format > LYX_FORMAT) {
512 Alert::warning(_("Document format failure"),
513 _("This document was created with a newer version of "
514 "LyX. This is likely to cause problems."));
515 } else if (file_format < LYX_FORMAT) {
517 if (file_format < 200) {
518 Alert::error(_("Document format failure"),
519 _("This LyX document is too old to be read "
520 "by this version of LyX. Try LyX 0.10."));
522 } else if (!filename.empty()) {
524 LibFileSearch("lyx2lyx", "lyx2lyx");
525 if (command.empty()) {
526 Alert::error(_("Conversion script not found"),
527 _("The document is from an earlier version "
528 "of LyX, but the conversion script lyx2lyx "
529 "could not be found."));
533 +tostr(LYX_FORMAT) + ' '
534 + QuoteName(filename);
535 lyxerr[Debug::INFO] << "Running '"
538 cmd_ret const ret = RunCommand(command);
540 Alert::error(_("Conversion script failed"),
541 _("The document is from an earlier version "
542 "of LyX, but the lyx2lyx script failed "
546 istringstream is(STRCONV(ret.second));
548 tmplex.setStream(is);
549 return readFile(tmplex, string(), pit);
551 // This code is reached if lyx2lyx failed (for
552 // some reason) to change the file format of
558 bool the_end = readBody(lex, pit);
559 params.setPaperStuff();
562 Alert::error(_("Document format failure"),
563 _("The document ended unexpectedly, which means "
564 "that it is probably corrupted."));
570 // Should probably be moved to somewhere else: BufferView? LyXView?
571 bool Buffer::save() const
573 // We don't need autosaves in the immediate future. (Asger)
574 resetAutosaveTimers();
578 if (lyxrc.make_backup) {
579 s = fileName() + '~';
580 if (!lyxrc.backupdir_path.empty())
581 s = AddName(lyxrc.backupdir_path,
582 subst(os::slashify_path(s),'/','!'));
584 // Rename is the wrong way of making a backup,
585 // this is the correct way.
586 /* truss cp fil fil2:
587 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
588 stat("LyXVC.lyx", 0xEFFFF688) = 0
589 open("LyXVC.lyx", O_RDONLY) = 3
590 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
591 fstat(4, 0xEFFFF508) = 0
592 fstat(3, 0xEFFFF508) = 0
593 read(3, " # T h i s f i l e w".., 8192) = 5579
594 write(4, " # T h i s f i l e w".., 5579) = 5579
595 read(3, 0xEFFFD4A0, 8192) = 0
598 chmod("LyXVC3.lyx", 0100644) = 0
599 lseek(0, 0, SEEK_CUR) = 46440
603 // Should probably have some more error checking here.
604 // Doing it this way, also makes the inodes stay the same.
605 // This is still not a very good solution, in particular we
606 // might loose the owner of the backup.
607 FileInfo finfo(fileName());
609 mode_t fmode = finfo.getMode();
610 struct utimbuf times = {
611 finfo.getAccessTime(),
612 finfo.getModificationTime() };
614 ifstream ifs(fileName().c_str());
615 ofstream ofs(s.c_str(), ios::out|ios::trunc);
620 ::chmod(s.c_str(), fmode);
622 if (::utime(s.c_str(), ×)) {
623 lyxerr << "utime error." << endl;
626 lyxerr << "LyX was not able to make "
627 "backup copy. Beware." << endl;
632 if (writeFile(fileName())) {
634 removeAutosaveFile(fileName());
636 // Saving failed, so backup is not backup
637 if (lyxrc.make_backup) {
638 lyx::rename(s, fileName());
646 bool Buffer::writeFile(string const & fname) const
648 if (read_only && (fname == fileName())) {
652 FileInfo finfo(fname);
653 if (finfo.exist() && !finfo.writable()) {
657 ofstream ofs(fname.c_str());
663 // Use the standard "C" locale for file output.
664 ofs.imbue(std::locale::classic());
667 // The top of the file should not be written by params.
669 // write out a comment in the top of the file
670 ofs << '#' << lyx_docversion
671 << " created this file. For more info see http://www.lyx.org/\n"
672 << "\\lyxformat " << LYX_FORMAT << "\n";
674 // now write out the buffer paramters.
675 params.writeFile(ofs);
677 ofs << "\\end_header\n";
679 Paragraph::depth_type depth = 0;
681 // this will write out all the paragraphs
682 // using recursive descent.
683 ParagraphList::const_iterator pit = paragraphs.begin();
684 ParagraphList::const_iterator pend = paragraphs.end();
685 for (; pit != pend; ++pit)
686 pit->write(this, ofs, params, depth);
688 // Write marker that shows file is complete
689 ofs << "\n\\the_end" << endl;
693 // how to check if close went ok?
694 // Following is an attempt... (BE 20001011)
696 // good() returns false if any error occured, including some
698 // bad() returns true if something bad happened in the buffer,
699 // which should include file system full errors.
706 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
708 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
720 pair<int, string> const addDepth(int depth, int ldepth)
724 d += (ldepth - depth) * 2;
725 return make_pair(d, string(d, ' '));
731 string const Buffer::asciiParagraph(Paragraph const & par,
732 unsigned int linelen,
733 bool noparbreak) const
735 ostringstream buffer;
736 Paragraph::depth_type depth = 0;
738 Paragraph::depth_type ltype_depth = 0;
739 bool ref_printed = false;
740 // if (!par->previous()) {
742 // begins or ends a deeper area ?
743 if (depth != par->params().depth()) {
744 if (par->params().depth() > depth) {
745 while (par->params().depth() > depth) {
749 while (par->params().depth() < depth) {
755 depth = par.params().depth();
758 // First write the layout
759 string const & tmp = par.layout()->name();
760 if (compare_no_case(tmp, "itemize") == 0) {
762 ltype_depth = depth + 1;
763 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
765 ltype_depth = depth + 1;
766 } else if (contains(ascii_lowercase(tmp), "ection")) {
768 ltype_depth = depth + 1;
769 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
771 ltype_depth = depth + 1;
772 } else if (compare_ascii_no_case(tmp, "description") == 0) {
774 ltype_depth = depth + 1;
775 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
778 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
786 /* maybe some vertical spaces */
788 /* the labelwidthstring used in lists */
792 /* some pagebreaks? */
796 /* what about the alignment */
798 // linelen <= 0 is special and means we don't have paragraph breaks
800 string::size_type currlinelen = 0;
806 buffer << string(depth * 2, ' ');
807 currlinelen += depth * 2;
810 // we should probably change to the paragraph language in the
811 // gettext here (if possible) so that strings are outputted in
812 // the correct language! (20012712 Jug)
816 case 4: // (Sub)Paragraph
817 case 5: // Description
821 buffer << _("Abstract") << "\n\n";
824 string const abst = _("Abstract: ");
826 currlinelen += abst.length();
829 case 7: // Bibliography
832 buffer << _("References") << "\n\n";
835 string const refs = _("References: ");
837 currlinelen += refs.length();
845 string const parlab = par.params().labelString();
846 buffer << parlab << ' ';
847 currlinelen += parlab.length() + 1;
855 pair<int, string> p = addDepth(depth, ltype_depth);
857 currlinelen += p.first;
860 // this is to change the linebreak to do it by word a bit more
861 // intelligent hopefully! (only in the case where we have a
862 // max linelength!) (Jug)
866 for (pos_type i = 0; i < par.size(); ++i) {
867 char c = par.getUChar(params, i);
869 case Paragraph::META_INSET:
871 Inset const * inset = par.getInset(i);
875 currlinelen += word.length();
878 if (inset->ascii(this, buffer, linelen)) {
879 // to be sure it breaks paragraph
880 currlinelen += linelen;
889 currlinelen + word.length() > linelen - 10) {
891 pair<int, string> p = addDepth(depth, ltype_depth);
893 currlinelen = p.first;
896 buffer << word << ' ';
897 currlinelen += word.length() + 1;
904 lyxerr[Debug::INFO] <<
905 "writeAsciiFile: NULL char in structure." << endl;
908 (currlinelen + word.length()) > linelen)
912 pair<int, string> p =
913 addDepth(depth, ltype_depth);
915 currlinelen = p.first;
922 return STRCONV(buffer.str());
926 void Buffer::writeFileAscii(string const & fname, int linelen)
928 ofstream ofs(fname.c_str());
930 string const file = MakeDisplayPath(fname, 50);
931 string text = bformat(_("Could not save the document\n%1$s."), file);
932 Alert::error(_("Could not save document"), text);
935 writeFileAscii(ofs, linelen);
939 void Buffer::writeFileAscii(ostream & os, int linelen)
941 ParagraphList::iterator beg = paragraphs.begin();
942 ParagraphList::iterator end = paragraphs.end();
943 ParagraphList::iterator it = beg;
944 for (; it != end; ++it) {
945 os << asciiParagraph(*it, linelen, it == beg);
952 void Buffer::makeLaTeXFile(string const & fname,
953 string const & original_path,
954 LatexRunParams const & runparams,
955 bool only_body, bool only_preamble)
957 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
959 ofstream ofs(fname.c_str());
961 string const file = MakeDisplayPath(fname, 50);
962 string text = bformat(_("Could not open the specified document\n%1$s."),
964 Alert::error(_("Could not open file"), text);
968 makeLaTeXFile(ofs, original_path,
969 runparams, only_body, only_preamble);
973 lyxerr << "File was not closed properly." << endl;
978 void Buffer::makeLaTeXFile(ostream & os,
979 string const & original_path,
980 LatexRunParams const & runparams_in,
981 bool only_body, bool only_preamble)
983 LatexRunParams runparams = runparams_in;
984 niceFile = runparams.nice; // this will be used by Insetincludes.
986 // validate the buffer.
987 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
988 LaTeXFeatures features(params);
990 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
993 // The starting paragraph of the coming rows is the
994 // first paragraph of the document. (Asger)
995 texrow.start(paragraphs.begin()->id(), 0);
997 if (!only_body && runparams.nice) {
998 os << "%% " << lyx_docversion << " created this file. "
999 "For more info, see http://www.lyx.org/.\n"
1000 "%% Do not edit unless you really know what "
1005 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1006 // There are a few differences between nice LaTeX and usual files:
1007 // usual is \batchmode and has a
1008 // special input@path to allow the including of figures
1009 // with either \input or \includegraphics (what figinsets do).
1010 // input@path is set when the actual parameter
1011 // original_path is set. This is done for usual tex-file, but not
1012 // for nice-latex-file. (Matthias 250696)
1014 if (!runparams.nice) {
1015 // code for usual, NOT nice-latex-file
1016 os << "\\batchmode\n"; // changed
1017 // from \nonstopmode
1020 if (!original_path.empty()) {
1021 string inputpath = os::external_path(original_path);
1022 subst(inputpath, "~", "\\string~");
1023 os << "\\makeatletter\n"
1024 << "\\def\\input@path{{"
1025 << inputpath << "/}}\n"
1026 << "\\makeatother\n";
1032 // Write the preamble
1033 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1039 os << "\\begin{document}\n";
1042 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1044 if (!lyxrc.language_auto_begin) {
1045 os << subst(lyxrc.language_command_begin, "$$lang",
1046 params.language->babel())
1051 latexParagraphs(this, paragraphs, os, texrow, runparams);
1053 // add this just in case after all the paragraphs
1057 if (!lyxrc.language_auto_end) {
1058 os << subst(lyxrc.language_command_end, "$$lang",
1059 params.language->babel())
1065 os << "\\end{document}\n";
1068 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1070 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1074 // Just to be sure. (Asger)
1077 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1078 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1081 // we want this to be true outside previews (for insetexternal)
1086 bool Buffer::isLatex() const
1088 return params.getLyXTextClass().outputType() == LATEX;
1092 bool Buffer::isLinuxDoc() const
1094 return params.getLyXTextClass().outputType() == LINUXDOC;
1098 bool Buffer::isLiterate() const
1100 return params.getLyXTextClass().outputType() == LITERATE;
1104 bool Buffer::isDocBook() const
1106 return params.getLyXTextClass().outputType() == DOCBOOK;
1110 bool Buffer::isSGML() const
1112 LyXTextClass const & tclass = params.getLyXTextClass();
1114 return tclass.outputType() == LINUXDOC ||
1115 tclass.outputType() == DOCBOOK;
1119 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1121 ofstream ofs(fname.c_str());
1124 string const file = MakeDisplayPath(fname, 50);
1125 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1127 Alert::error(_("Could not save document"), text);
1131 niceFile = nice; // this will be used by included files.
1133 LaTeXFeatures features(params);
1139 LyXTextClass const & tclass = params.getLyXTextClass();
1141 string top_element = tclass.latexname();
1144 ofs << "<!doctype linuxdoc system";
1146 string preamble = params.preamble;
1147 const string name = nice ? ChangeExtension(filename_, ".sgml")
1149 preamble += features.getIncludedFiles(name);
1150 preamble += features.getLyXSGMLEntities();
1152 if (!preamble.empty()) {
1153 ofs << " [ " << preamble << " ]";
1157 if (params.options.empty())
1158 sgml::openTag(ofs, 0, false, top_element);
1160 string top = top_element;
1162 top += params.options;
1163 sgml::openTag(ofs, 0, false, top);
1167 ofs << "<!-- " << lyx_docversion
1168 << " created this file. For more info see http://www.lyx.org/"
1171 Paragraph::depth_type depth = 0; // paragraph depth
1173 vector<string> environment_stack(5);
1175 users->resetErrorList();
1177 ParagraphList::iterator pit = paragraphs.begin();
1178 ParagraphList::iterator pend = paragraphs.end();
1179 for (; pit != pend; ++pit) {
1180 LyXLayout_ptr const & style = pit->layout();
1181 // treat <toc> as a special case for compatibility with old code
1182 if (pit->isInset(0)) {
1183 Inset * inset = pit->getInset(0);
1184 Inset::Code lyx_code = inset->lyxCode();
1185 if (lyx_code == Inset::TOC_CODE) {
1186 string const temp = "toc";
1187 sgml::openTag(ofs, depth, false, temp);
1192 // environment tag closing
1193 for (; depth > pit->params().depth(); --depth) {
1194 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1195 environment_stack[depth].erase();
1198 // write opening SGML tags
1199 switch (style->latextype) {
1200 case LATEX_PARAGRAPH:
1201 if (depth == pit->params().depth()
1202 && !environment_stack[depth].empty()) {
1203 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1204 environment_stack[depth].erase();
1210 sgml::openTag(ofs, depth, false, style->latexname());
1216 _("Error: Wrong depth for LatexType Command.\n"));
1218 if (!environment_stack[depth].empty()) {
1219 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1223 environment_stack[depth].erase();
1224 sgml::openTag(ofs, depth, false, style->latexname());
1227 case LATEX_ENVIRONMENT:
1228 case LATEX_ITEM_ENVIRONMENT:
1229 case LATEX_BIB_ENVIRONMENT:
1231 string const & latexname = style->latexname();
1233 if (depth == pit->params().depth()
1234 && environment_stack[depth] != latexname) {
1235 sgml::closeTag(ofs, depth, false,
1236 environment_stack[depth]);
1237 environment_stack[depth].erase();
1239 if (depth < pit->params().depth()) {
1240 depth = pit->params().depth();
1241 environment_stack[depth].erase();
1243 if (environment_stack[depth] != latexname) {
1245 sgml::openTag(ofs, depth, false, "p");
1247 sgml::openTag(ofs, depth, false, latexname);
1249 if (environment_stack.size() == depth + 1)
1250 environment_stack.push_back("!-- --");
1251 environment_stack[depth] = latexname;
1254 if (style->latexparam() == "CDATA")
1257 if (style->latextype == LATEX_ENVIRONMENT) break;
1259 if (style->labeltype == LABEL_MANUAL)
1264 sgml::openTag(ofs, depth + 1, false, item_name);
1269 sgml::openTag(ofs, depth, false, style->latexname());
1273 simpleLinuxDocOnePar(ofs, pit, depth);
1276 // write closing SGML tags
1277 switch (style->latextype) {
1280 case LATEX_ENVIRONMENT:
1281 case LATEX_ITEM_ENVIRONMENT:
1282 case LATEX_BIB_ENVIRONMENT:
1283 if (style->latexparam() == "CDATA")
1287 sgml::closeTag(ofs, depth, false, style->latexname());
1293 for (int i = depth; i >= 0; --i)
1294 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1298 sgml::closeTag(ofs, 0, false, top_element);
1302 // How to check for successful close
1304 // we want this to be true outside previews (for insetexternal)
1307 users->showErrorList(_("LinuxDoc"));
1311 // checks, if newcol chars should be put into this line
1312 // writes newline, if necessary.
1315 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1316 string::size_type newcol)
1319 if (colcount > lyxrc.ascii_linelen) {
1321 colcount = newcol; // assume write after this call
1336 string tag_name(PAR_TAG const & pt) {
1338 case NONE: return "!-- --";
1339 case TT: return "tt";
1340 case SF: return "sf";
1341 case BF: return "bf";
1342 case IT: return "it";
1343 case SL: return "sl";
1344 case EM: return "em";
1351 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1353 p1 = static_cast<PAR_TAG>(p1 | p2);
1358 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1360 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1366 // Handle internal paragraph parsing -- layout already processed.
1367 void Buffer::simpleLinuxDocOnePar(ostream & os,
1368 ParagraphList::iterator par,
1369 Paragraph::depth_type /*depth*/) const
1371 LyXLayout_ptr const & style = par->layout();
1373 string::size_type char_line_count = 5; // Heuristic choice ;-)
1375 // gets paragraph main font
1378 if (style->labeltype == LABEL_MANUAL) {
1379 font_old = style->labelfont;
1382 font_old = style->font;
1386 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1387 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1388 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1391 stack<PAR_TAG> tag_state;
1392 // parsing main loop
1393 for (pos_type i = 0; i < par->size(); ++i) {
1395 PAR_TAG tag_close = NONE;
1396 list < PAR_TAG > tag_open;
1398 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1400 if (font_old.family() != font.family()) {
1401 switch (family_type) {
1402 case LyXFont::SANS_FAMILY:
1405 case LyXFont::TYPEWRITER_FAMILY:
1412 family_type = font.family();
1414 switch (family_type) {
1415 case LyXFont::SANS_FAMILY:
1416 tag_open.push_back(SF);
1418 case LyXFont::TYPEWRITER_FAMILY:
1419 tag_open.push_back(TT);
1426 if (font_old.series() != font.series()) {
1427 switch (series_type) {
1428 case LyXFont::BOLD_SERIES:
1435 series_type = font.series();
1437 switch (series_type) {
1438 case LyXFont::BOLD_SERIES:
1439 tag_open.push_back(BF);
1447 if (font_old.shape() != font.shape()) {
1448 switch (shape_type) {
1449 case LyXFont::ITALIC_SHAPE:
1452 case LyXFont::SLANTED_SHAPE:
1459 shape_type = font.shape();
1461 switch (shape_type) {
1462 case LyXFont::ITALIC_SHAPE:
1463 tag_open.push_back(IT);
1465 case LyXFont::SLANTED_SHAPE:
1466 tag_open.push_back(SL);
1473 if (font_old.emph() != font.emph()) {
1474 if (font.emph() == LyXFont::ON) {
1475 tag_open.push_back(EM);
1484 list < PAR_TAG > temp;
1485 while (!tag_state.empty() && tag_close) {
1486 PAR_TAG k = tag_state.top();
1488 os << "</" << tag_name(k) << '>';
1495 for(list< PAR_TAG >::const_iterator j = temp.begin();
1496 j != temp.end(); ++j) {
1498 os << '<' << tag_name(*j) << '>';
1501 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1502 j != tag_open.end(); ++j) {
1504 os << '<' << tag_name(*j) << '>';
1507 char c = par->getChar(i);
1509 if (c == Paragraph::META_INSET) {
1510 Inset * inset = par->getInset(i);
1511 inset->linuxdoc(this, os);
1516 if (style->latexparam() == "CDATA") {
1517 // "TeX"-Mode on == > SGML-Mode on.
1524 boost::tie(ws, str) = sgml::escapeChar(c);
1525 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1526 // in freespacing mode, spaces are
1527 // non-breaking characters
1528 if (desc_on) {// if char is ' ' then...
1531 sgmlLineBreak(os, char_line_count, 6);
1535 sgmlLineBreak(os, char_line_count, 1);
1540 char_line_count += str.length();
1546 while (!tag_state.empty()) {
1547 os << "</" << tag_name(tag_state.top()) << '>';
1551 // resets description flag correctly
1553 // <tag> not closed...
1554 sgmlLineBreak(os, char_line_count, 6);
1560 // Print an error message.
1561 void Buffer::sgmlError(ParagraphList::iterator pit, int pos,
1562 string const & message) const
1564 users->addError(ErrorItem(message, string(), pit->id(), pos, pos));
1568 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1570 ofstream ofs(fname.c_str());
1572 string const file = MakeDisplayPath(fname, 50);
1573 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1575 Alert::error(_("Could not save document"), text);
1579 niceFile = nice; // this will be used by Insetincludes.
1581 LaTeXFeatures features(params);
1586 LyXTextClass const & tclass = params.getLyXTextClass();
1587 string top_element = tclass.latexname();
1590 ofs << "<!DOCTYPE " << top_element
1591 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1593 string preamble = params.preamble;
1594 const string name = nice ? ChangeExtension(filename_, ".sgml")
1596 preamble += features.getIncludedFiles(name);
1597 preamble += features.getLyXSGMLEntities();
1599 if (!preamble.empty()) {
1600 ofs << "\n [ " << preamble << " ]";
1605 string top = top_element;
1607 top += params.language->code();
1610 if (!params.options.empty()) {
1612 top += params.options;
1614 sgml::openTag(ofs, 0, false, top);
1616 ofs << "<!-- DocBook file was created by " << lyx_docversion
1617 << "\n See http://www.lyx.org/ for more information -->\n";
1619 vector<string> environment_stack(10);
1620 vector<string> environment_inner(10);
1621 vector<string> command_stack(10);
1623 bool command_flag = false;
1624 Paragraph::depth_type command_depth = 0;
1625 Paragraph::depth_type command_base = 0;
1626 Paragraph::depth_type cmd_depth = 0;
1627 Paragraph::depth_type depth = 0; // paragraph depth
1630 string command_name;
1632 users->resetErrorList();
1634 ParagraphList::iterator par = paragraphs.begin();
1635 ParagraphList::iterator pend = paragraphs.end();
1637 for (; par != pend; ++par) {
1641 int desc_on = 0; // description mode
1643 LyXLayout_ptr const & style = par->layout();
1645 // environment tag closing
1646 for (; depth > par->params().depth(); --depth) {
1647 if (environment_inner[depth] != "!-- --") {
1648 item_name = "listitem";
1649 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1650 if (environment_inner[depth] == "varlistentry")
1651 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1653 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1654 environment_stack[depth].erase();
1655 environment_inner[depth].erase();
1658 if (depth == par->params().depth()
1659 && environment_stack[depth] != style->latexname()
1660 && !environment_stack[depth].empty()) {
1661 if (environment_inner[depth] != "!-- --") {
1662 item_name= "listitem";
1663 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1664 if (environment_inner[depth] == "varlistentry")
1665 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1668 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1670 environment_stack[depth].erase();
1671 environment_inner[depth].erase();
1674 // Write opening SGML tags.
1675 switch (style->latextype) {
1676 case LATEX_PARAGRAPH:
1677 sgml::openTag(ofs, depth + command_depth,
1678 false, style->latexname());
1684 _("Error: Wrong depth for LatexType Command.\n"));
1686 command_name = style->latexname();
1688 sgmlparam = style->latexparam();
1689 c_params = split(sgmlparam, c_depth,'|');
1691 cmd_depth = lyx::atoi(c_depth);
1694 if (cmd_depth < command_base) {
1695 for (Paragraph::depth_type j = command_depth;
1696 j >= command_base; --j) {
1697 sgml::closeTag(ofs, j, false, command_stack[j]);
1700 command_depth = command_base = cmd_depth;
1701 } else if (cmd_depth <= command_depth) {
1702 for (int j = command_depth;
1703 j >= int(cmd_depth); --j) {
1704 sgml::closeTag(ofs, j, false, command_stack[j]);
1707 command_depth = cmd_depth;
1709 command_depth = cmd_depth;
1711 command_depth = command_base = cmd_depth;
1712 command_flag = true;
1714 if (command_stack.size() == command_depth + 1)
1715 command_stack.push_back(string());
1716 command_stack[command_depth] = command_name;
1718 // treat label as a special case for
1719 // more WYSIWYM handling.
1720 // This is a hack while paragraphs can't have
1721 // attributes, like id in this case.
1722 if (par->isInset(0)) {
1723 Inset * inset = par->getInset(0);
1724 Inset::Code lyx_code = inset->lyxCode();
1725 if (lyx_code == Inset::LABEL_CODE) {
1726 command_name += " id=\"";
1727 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1728 command_name += '"';
1733 sgml::openTag(ofs, depth + command_depth, false, command_name);
1735 item_name = c_params.empty() ? "title" : c_params;
1736 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1739 case LATEX_ENVIRONMENT:
1740 case LATEX_ITEM_ENVIRONMENT:
1741 if (depth < par->params().depth()) {
1742 depth = par->params().depth();
1743 environment_stack[depth].erase();
1746 if (environment_stack[depth] != style->latexname()) {
1747 if (environment_stack.size() == depth + 1) {
1748 environment_stack.push_back("!-- --");
1749 environment_inner.push_back("!-- --");
1751 environment_stack[depth] = style->latexname();
1752 environment_inner[depth] = "!-- --";
1753 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1755 if (environment_inner[depth] != "!-- --") {
1756 item_name= "listitem";
1757 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1758 if (environment_inner[depth] == "varlistentry")
1759 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1763 if (style->latextype == LATEX_ENVIRONMENT) {
1764 if (!style->latexparam().empty()) {
1765 if (style->latexparam() == "CDATA")
1768 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1773 desc_on = (style->labeltype == LABEL_MANUAL);
1775 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1776 sgml::openTag(ofs, depth + 1 + command_depth,
1777 false, environment_inner[depth]);
1779 item_name = desc_on ? "term" : "para";
1780 sgml::openTag(ofs, depth + 1 + command_depth,
1784 sgml::openTag(ofs, depth + command_depth,
1785 false, style->latexname());
1789 simpleDocBookOnePar(ofs, par, desc_on,
1790 depth + 1 + command_depth);
1793 // write closing SGML tags
1794 switch (style->latextype) {
1796 end_tag = c_params.empty() ? "title" : c_params;
1797 sgml::closeTag(ofs, depth + command_depth,
1800 case LATEX_ENVIRONMENT:
1801 if (!style->latexparam().empty()) {
1802 if (style->latexparam() == "CDATA")
1805 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1808 case LATEX_ITEM_ENVIRONMENT:
1809 if (desc_on == 1) break;
1811 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1813 case LATEX_PARAGRAPH:
1814 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1817 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1823 for (int d = depth; d >= 0; --d) {
1824 if (!environment_stack[depth].empty()) {
1825 if (environment_inner[depth] != "!-- --") {
1826 item_name = "listitem";
1827 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1828 if (environment_inner[depth] == "varlistentry")
1829 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1832 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1836 for (int j = command_depth; j >= 0 ; --j)
1837 if (!command_stack[j].empty()) {
1838 sgml::closeTag(ofs, j, false, command_stack[j]);
1843 sgml::closeTag(ofs, 0, false, top_element);
1846 // How to check for successful close
1848 // we want this to be true outside previews (for insetexternal)
1850 users->showErrorList(_("DocBook"));
1854 void Buffer::simpleDocBookOnePar(ostream & os,
1855 ParagraphList::iterator par, int & desc_on,
1856 Paragraph::depth_type depth) const
1858 bool emph_flag = false;
1860 LyXLayout_ptr const & style = par->layout();
1862 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1864 int char_line_count = depth;
1865 //if (!style.free_spacing)
1866 // os << string(depth,' ');
1868 // parsing main loop
1869 for (pos_type i = 0; i < par->size(); ++i) {
1870 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1872 // handle <emphasis> tag
1873 if (font_old.emph() != font.emph()) {
1874 if (font.emph() == LyXFont::ON) {
1875 if (style->latexparam() == "CDATA")
1878 if (style->latexparam() == "CDATA")
1882 if (style->latexparam() == "CDATA")
1884 os << "</emphasis>";
1885 if (style->latexparam() == "CDATA")
1892 if (par->isInset(i)) {
1893 Inset * inset = par->getInset(i);
1894 // don't print the inset in position 0 if desc_on == 3 (label)
1895 if (i || desc_on != 3) {
1896 if (style->latexparam() == "CDATA")
1898 inset->docbook(this, os, false);
1899 if (style->latexparam() == "CDATA")
1903 char c = par->getChar(i);
1906 boost::tie(ws, str) = sgml::escapeChar(c);
1908 if (style->pass_thru) {
1910 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1912 } else if (desc_on ==1) {
1914 os << "\n</term><listitem><para>";
1924 if (style->latexparam() == "CDATA")
1926 os << "</emphasis>";
1927 if (style->latexparam() == "CDATA")
1931 // resets description flag correctly
1933 // <term> not closed...
1934 os << "</term>\n<listitem><para> </para>";
1936 if (style->free_spacing)
1941 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1942 // Other flags: -wall -v0 -x
1943 int Buffer::runChktex()
1945 if (!users->text) return 0;
1947 users->owner()->busy(true);
1949 // get LaTeX-Filename
1950 string const name = getLatexName();
1951 string path = filePath();
1953 string const org_path = path;
1954 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1958 Path p(path); // path to LaTeX file
1959 users->owner()->message(_("Running chktex..."));
1961 // Generate the LaTeX file if neccessary
1962 LatexRunParams runparams;
1963 runparams.flavor = LatexRunParams::LATEX;
1964 runparams.nice = false;
1965 makeLaTeXFile(name, org_path, runparams);
1968 Chktex chktex(lyxrc.chktex_command, name, filePath());
1969 int res = chktex.run(terr); // run chktex
1972 Alert::error(_("chktex failure"),
1973 _("Could not run chktex successfully."));
1974 } else if (res > 0) {
1975 // Insert all errors as errors boxes
1976 ErrorList el (*this, terr);
1977 users->setErrorList(el);
1978 users->showErrorList(_("ChkTeX"));
1981 users->owner()->busy(false);
1987 void Buffer::validate(LaTeXFeatures & features) const
1989 LyXTextClass const & tclass = params.getLyXTextClass();
1991 if (params.tracking_changes) {
1992 features.require("dvipost");
1993 features.require("color");
1996 // AMS Style is at document level
1997 if (params.use_amsmath == BufferParams::AMS_ON
1998 || tclass.provides(LyXTextClass::amsmath))
1999 features.require("amsmath");
2001 for_each(paragraphs.begin(), paragraphs.end(),
2002 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2004 // the bullet shapes are buffer level not paragraph level
2005 // so they are tested here
2006 for (int i = 0; i < 4; ++i) {
2007 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2008 int const font = params.user_defined_bullets[i].getFont();
2010 int const c = params
2011 .user_defined_bullets[i]
2018 features.require("latexsym");
2020 } else if (font == 1) {
2021 features.require("amssymb");
2022 } else if ((font >= 2 && font <= 5)) {
2023 features.require("pifont");
2028 if (lyxerr.debugging(Debug::LATEX)) {
2029 features.showStruct();
2034 vector<string> const Buffer::getLabelList() const
2036 /// if this is a child document and the parent is already loaded
2037 /// Use the parent's list instead [ale990407]
2038 if (!params.parentname.empty()
2039 && bufferlist.exists(params.parentname)) {
2040 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2042 return tmp->getLabelList();
2045 vector<string> label_list;
2046 for (inset_iterator it = inset_const_iterator_begin();
2047 it != inset_const_iterator_end(); ++it) {
2048 vector<string> const l = it->getLabelList();
2049 label_list.insert(label_list.end(), l.begin(), l.end());
2055 // This is also a buffer property (ale)
2056 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2058 /// if this is a child document and the parent is already loaded
2059 /// use the parent's list instead [ale990412]
2060 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2061 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2063 tmp->fillWithBibKeys(keys);
2068 for (inset_iterator it = inset_const_iterator_begin();
2069 it != inset_const_iterator_end(); ++it) {
2070 if (it->lyxCode() == Inset::BIBTEX_CODE)
2071 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2072 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2073 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2074 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2075 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2076 string const key = bib.getContents();
2077 string const opt = bib.getOptions();
2078 string const ref; // = pit->asString(this, false);
2079 string const info = opt + "TheBibliographyRef" + ref;
2080 keys.push_back(pair<string, string>(key, info));
2086 bool Buffer::isDepClean(string const & name) const
2088 DepClean::const_iterator it = dep_clean_.find(name);
2089 if (it == dep_clean_.end())
2095 void Buffer::markDepClean(string const & name)
2097 dep_clean_[name] = true;
2101 bool Buffer::dispatch(string const & command, bool * result)
2103 // Split command string into command and argument
2105 string line = ltrim(command);
2106 string const arg = trim(split(line, cmd, ' '));
2108 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2112 bool Buffer::dispatch(int action, string const & argument, bool * result)
2114 bool dispatched = true;
2118 bool const tmp = Exporter::Export(this, argument, false);
2131 void Buffer::resizeInsets(BufferView * bv)
2133 /// then remove all LyXText in text-insets
2134 for_each(paragraphs.begin(), paragraphs.end(),
2135 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2139 void Buffer::redraw()
2141 #warning repaint needed here, or do you mean update() ?
2147 void Buffer::changeLanguage(Language const * from, Language const * to)
2149 lyxerr << "Changing Language!" << endl;
2151 // Take care of l10n/i18n
2154 ParIterator end = par_iterator_end();
2155 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2156 (*it)->changeLanguage(params, from, to);
2160 void Buffer::updateDocLang(Language const * nlang)
2162 messages_.reset(new Messages(nlang->code()));
2166 bool Buffer::isMultiLingual()
2168 ParIterator end = par_iterator_end();
2169 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2170 if ((*it)->isMultiLingual(params))
2177 void Buffer::inset_iterator::setParagraph()
2179 while (pit != pend) {
2180 it = pit->insetlist.begin();
2181 if (it != pit->insetlist.end())
2188 Inset * Buffer::getInsetFromID(int id_arg) const
2190 for (inset_iterator it = inset_const_iterator_begin();
2191 it != inset_const_iterator_end(); ++it)
2193 if (it->id() == id_arg)
2195 Inset * in = it->getInsetFromID(id_arg);
2203 ParIterator Buffer::getParFromID(int id) const
2205 #warning FIXME: const correctness! (Andre)
2206 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2207 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2209 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2211 // John says this is called with id == -1 from undo
2212 lyxerr << "getParFromID(), id: " << id << endl;
2216 for (; it != end; ++it)
2217 if ((*it)->id() == id)
2224 bool Buffer::hasParWithID(int id) const
2226 ParIterator it(const_cast<Buffer*>(this)->par_iterator_begin());
2227 ParIterator end(const_cast<Buffer*>(this)->par_iterator_end());
2230 // John says this is called with id == -1 from undo
2231 lyxerr << "hasParWithID(), id: " << id << endl;
2235 for (; it != end; ++it)
2236 if ((*it)->id() == id)
2243 ParIterator Buffer::par_iterator_begin()
2245 return ParIterator(paragraphs.begin(), paragraphs);
2249 ParIterator Buffer::par_iterator_end()
2251 return ParIterator(paragraphs.end(), paragraphs);
2254 ParConstIterator Buffer::par_iterator_begin() const
2256 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2260 ParConstIterator Buffer::par_iterator_end() const
2262 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2267 void Buffer::addUser(BufferView * u)
2273 void Buffer::delUser(BufferView *)
2279 Language const * Buffer::getLanguage() const
2281 return params.language;
2285 string const Buffer::B_(string const & l10n) const
2287 if (messages_.get()) {
2288 return messages_->get(l10n);
2295 bool Buffer::isClean() const
2301 bool Buffer::isBakClean() const
2307 void Buffer::markClean() const
2313 // if the .lyx file has been saved, we don't need an
2319 void Buffer::markBakClean()
2325 void Buffer::setUnnamed(bool flag)
2331 bool Buffer::isUnnamed()
2337 void Buffer::markDirty()
2345 DepClean::iterator it = dep_clean_.begin();
2346 DepClean::const_iterator const end = dep_clean_.end();
2348 for (; it != end; ++it) {
2354 string const & Buffer::fileName() const
2360 string const & Buffer::filePath() const
2366 bool Buffer::isReadonly() const
2372 BufferView * Buffer::getUser() const
2378 void Buffer::setParentName(string const & name)
2380 params.parentname = name;
2384 Buffer::inset_iterator::inset_iterator()
2389 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2396 Buffer::inset_iterator Buffer::inset_iterator_begin()
2398 return inset_iterator(paragraphs.begin(), paragraphs.end());
2402 Buffer::inset_iterator Buffer::inset_iterator_end()
2404 return inset_iterator(paragraphs.end(), paragraphs.end());
2408 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2410 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2411 const_cast<ParagraphList&>(paragraphs).end());
2415 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2417 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2418 const_cast<ParagraphList&>(paragraphs).end());
2422 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2426 if (it == pit->insetlist.end()) {
2435 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2437 inset_iterator tmp = *this;
2443 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2449 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2455 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2461 lyx::pos_type Buffer::inset_iterator::getPos() const
2467 bool operator==(Buffer::inset_iterator const & iter1,
2468 Buffer::inset_iterator const & iter2)
2470 return iter1.pit == iter2.pit
2471 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2475 bool operator!=(Buffer::inset_iterator const & iter1,
2476 Buffer::inset_iterator const & iter2)
2478 return !(iter1 == iter2);