3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
14 #include "bufferlist.h"
15 #include "LyXAction.h"
18 #include "tex-strings.h"
20 #include "bufferview_funcs.h"
26 #include "LaTeXFeatures.h"
31 #include "errorlist.h"
34 #include "BufferView.h"
35 #include "ParagraphParameters.h"
36 #include "iterators.h"
37 #include "lyxtextclasslist.h"
39 #include "paragraph_funcs.h"
43 #include "frontends/LyXView.h"
45 #include "mathed/formulamacro.h"
46 #include "mathed/formula.h"
48 #include "insets/insetbibitem.h"
49 #include "insets/insetbibtex.h"
50 #include "insets/insetinclude.h"
51 #include "insets/insettext.h"
53 #include "frontends/Dialogs.h"
54 #include "frontends/Alert.h"
56 #include "graphics/Previews.h"
58 #include "support/textutils.h"
59 #include "support/filetools.h"
60 #include "support/path.h"
61 #include "support/os.h"
62 #include "support/tostr.h"
63 #include "support/lyxlib.h"
64 #include "support/FileInfo.h"
65 #include "support/lyxmanip.h"
66 #include "support/lyxtime.h"
68 #include <boost/bind.hpp>
69 #include <boost/tuple/tuple.hpp>
81 #include <sys/types.h>
88 #ifndef CXX_GLOBAL_CSTD
100 using std::make_pair;
108 using lyx::textclass_type;
110 // all these externs should eventually be removed.
111 extern BufferList bufferlist;
115 const int LYX_FORMAT = 224;
119 Buffer::Buffer(string const & file, bool ronly)
120 : niceFile(true), lyx_clean(true), bak_clean(true),
121 unnamed(false), read_only(ronly),
122 filename_(file), users(0)
124 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
125 filepath_ = OnlyPath(file);
127 if (read_only || lyxrc.use_tempdir) {
128 tmppath = CreateBufferTmpDir();
133 // set initial author
134 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
140 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
141 // here the buffer should take care that it is
142 // saved properly, before it goes into the void.
144 // make sure that views using this buffer
149 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
150 Alert::warning(_("Could not remove temporary directory"),
151 bformat(_("Could not remove the temporary directory %1$s"), tmppath));
156 // Remove any previewed LaTeX snippets assocoated with this buffer.
157 grfx::Previews::get().removeLoader(this);
161 string const Buffer::getLatexName(bool no_path) const
163 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
164 return no_path ? OnlyFilename(name) : name;
168 pair<Buffer::LogType, string> const Buffer::getLogName() const
170 string const filename = getLatexName(false);
172 if (filename.empty())
173 return make_pair(Buffer::latexlog, string());
175 string path = OnlyPath(filename);
177 if (lyxrc.use_tempdir || !IsDirWriteable(path))
180 string const fname = AddName(path,
181 OnlyFilename(ChangeExtension(filename,
184 AddName(path, OnlyFilename(
185 ChangeExtension(filename,
186 formats.extension("literate") + ".out")));
188 // If no Latex log or Build log is newer, show Build log
190 FileInfo const f_fi(fname);
191 FileInfo const b_fi(bname);
194 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
195 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
196 return make_pair(Buffer::buildlog, bname);
198 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
199 return make_pair(Buffer::latexlog, fname);
203 void Buffer::setReadonly(bool flag)
205 if (read_only != flag) {
209 users->owner()->getDialogs().updateBufferDependent(false);
214 AuthorList & Buffer::authors()
216 return params.authorlist;
220 /// Update window titles of all users
221 // Should work on a list
222 void Buffer::updateTitles() const
225 users->owner()->updateWindowTitle();
229 /// Reset autosave timer of all users
230 // Should work on a list
231 void Buffer::resetAutosaveTimers() const
234 users->owner()->resetAutosaveTimer();
238 void Buffer::setFileName(string const & newfile)
240 filename_ = MakeAbsPath(newfile);
241 filepath_ = OnlyPath(filename_);
242 setReadonly(IsFileWriteable(filename_) == 0);
247 // We'll remove this later. (Lgb)
250 void unknownClass(string const & unknown)
252 Alert::warning(_("Unknown document class"),
253 bformat(_("Using the default document class, because the "
254 " class %1$s is unknown."), unknown));
259 int Buffer::readHeader(LyXLex & lex)
261 int unknown_tokens = 0;
265 string const token = lex.getString();
270 if (token == "\\end_header")
273 lyxerr[Debug::PARSER] << "Handling header token: `"
274 << token << '\'' << endl;
276 string unknown = params.readToken(lex, token);
277 if (!unknown.empty()) {
278 if (unknown[0] != '\\') {
279 unknownClass(unknown);
282 string const s = bformat(_("Unknown token: "
286 parseError(ErrorItem(_("Header error"), s,
291 return unknown_tokens;
295 // candidate for move to BufferView
296 // (at least some parts in the beginning of the func)
299 // changed to be public and have one parameter
300 // if par = 0 normal behavior
301 // else insert behavior
302 // Returns false if "\the_end" is not read (Asger)
303 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
305 Paragraph::depth_type depth = 0;
306 bool the_end_read = false;
308 if (paragraphs.empty()) {
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 readParagraph(lex, token, paragraphs, pit, depth);
350 int Buffer::readParagraph(LyXLex & lex, string const & token,
351 ParagraphList & pars, ParagraphList::iterator & pit,
352 Paragraph::depth_type & depth)
354 static Change current_change;
357 if (token == "\\layout") {
358 lex.pushToken(token);
361 par.params().depth(depth);
362 if (params.tracking_changes)
364 LyXFont f(LyXFont::ALL_INHERIT, params.language);
368 if (pit != pars.end())
371 pit = pars.insert(pit, par);
373 // FIXME: goddamn InsetTabular makes us pass a Buffer
375 ::readParagraph(*this, *pit, lex);
377 } else if (token == "\\begin_deeper") {
379 } else if (token == "\\end_deeper") {
381 lex.printError("\\end_deeper: " "depth is already null");
392 // needed to insert the selection
393 void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
394 LyXFont const & fn,string const & str)
396 LyXLayout_ptr const & layout = par->layout();
400 par->checkInsertChar(font);
401 // insert the string, don't insert doublespace
402 bool space_inserted = true;
403 bool autobreakrows = !par->inInset() ||
404 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
405 for(string::const_iterator cit = str.begin();
406 cit != str.end(); ++cit) {
408 if (autobreakrows && (!par->empty() || par->allowEmpty())) {
409 breakParagraph(params, paragraphs, par, pos,
410 layout->isEnvironment());
413 space_inserted = true;
417 // do not insert consecutive spaces if !free_spacing
418 } else if ((*cit == ' ' || *cit == '\t') &&
419 space_inserted && !par->isFreeSpacing()) {
421 } else if (*cit == '\t') {
422 if (!par->isFreeSpacing()) {
423 // tabs are like spaces here
424 par->insertChar(pos, ' ', font);
426 space_inserted = true;
428 const pos_type nb = 8 - pos % 8;
429 for (pos_type a = 0; a < nb ; ++a) {
430 par->insertChar(pos, ' ', font);
433 space_inserted = true;
435 } else if (!IsPrintable(*cit)) {
436 // Ignore unprintables
439 // just insert the character
440 par->insertChar(pos, *cit, font);
442 space_inserted = (*cit == ' ');
449 bool Buffer::readFile(LyXLex & lex, string const & filename)
451 bool ret = readFile(lex, filename, paragraphs.begin());
453 // After we have read a file, we must ensure that the buffer
454 // language is set and used in the gui.
455 // If you know of a better place to put this, please tell me. (Lgb)
456 updateDocLang(params.language);
462 // FIXME: all the below Alerts should give the filename..
463 bool Buffer::readFile(LyXLex & lex, string const & filename,
464 ParagraphList::iterator pit)
467 Alert::error(_("Document could not be read"),
468 _("The specified document could not be read."));
473 string const token(lex.getString());
476 Alert::error(_("Document could not be read"),
477 _("The specified document could not be read."));
481 // the first token _must_ be...
482 if (token != "\\lyxformat") {
483 Alert::error(_("Document format failure"),
484 _("The specified document is not a LyX document."));
489 string tmp_format = lex.getString();
490 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
491 // if present remove ".," from string.
492 string::size_type dot = tmp_format.find_first_of(".,");
493 //lyxerr << " dot found at " << dot << endl;
494 if (dot != string::npos)
495 tmp_format.erase(dot, 1);
496 file_format = strToInt(tmp_format);
497 //lyxerr << "format: " << file_format << endl;
498 if (file_format == LYX_FORMAT) {
500 } else if (file_format > LYX_FORMAT) {
501 Alert::warning(_("Document format failure"),
502 _("This document was created with a newer version of "
503 "LyX. This is likely to cause problems."));
504 } else if (file_format < LYX_FORMAT) {
506 if (file_format < 200) {
507 Alert::error(_("Document format failure"),
508 _("This LyX document is too old to be read "
509 "by this version of LyX. Try LyX 0.10."));
511 } else if (!filename.empty()) {
513 LibFileSearch("lyx2lyx", "lyx2lyx");
514 if (command.empty()) {
515 Alert::error(_("Conversion script not found"),
516 _("The document is from an earlier version "
517 "of LyX, but the conversion script lyx2lyx "
518 "could not be found."));
522 +tostr(LYX_FORMAT) + ' '
523 + QuoteName(filename);
524 lyxerr[Debug::INFO] << "Running '"
527 cmd_ret const ret = RunCommand(command);
529 Alert::error(_("Conversion script failed"),
530 _("The document is from an earlier version "
531 "of LyX, but the lyx2lyx script failed "
535 istringstream is(STRCONV(ret.second));
537 tmplex.setStream(is);
538 return readFile(tmplex, string(), pit);
540 // This code is reached if lyx2lyx failed (for
541 // some reason) to change the file format of
547 bool the_end = readBody(lex, pit);
548 params.setPaperStuff();
551 Alert::error(_("Document format failure"),
552 _("The document ended unexpectedly, which means "
553 "that it is probably corrupted."));
559 // Should probably be moved to somewhere else: BufferView? LyXView?
560 bool Buffer::save() const
562 // We don't need autosaves in the immediate future. (Asger)
563 resetAutosaveTimers();
567 if (lyxrc.make_backup) {
568 s = fileName() + '~';
569 if (!lyxrc.backupdir_path.empty())
570 s = AddName(lyxrc.backupdir_path,
571 subst(os::slashify_path(s),'/','!'));
573 // Rename is the wrong way of making a backup,
574 // this is the correct way.
575 /* truss cp fil fil2:
576 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
577 stat("LyXVC.lyx", 0xEFFFF688) = 0
578 open("LyXVC.lyx", O_RDONLY) = 3
579 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
580 fstat(4, 0xEFFFF508) = 0
581 fstat(3, 0xEFFFF508) = 0
582 read(3, " # T h i s f i l e w".., 8192) = 5579
583 write(4, " # T h i s f i l e w".., 5579) = 5579
584 read(3, 0xEFFFD4A0, 8192) = 0
587 chmod("LyXVC3.lyx", 0100644) = 0
588 lseek(0, 0, SEEK_CUR) = 46440
592 // Should probably have some more error checking here.
593 // Doing it this way, also makes the inodes stay the same.
594 // This is still not a very good solution, in particular we
595 // might loose the owner of the backup.
596 FileInfo finfo(fileName());
598 mode_t fmode = finfo.getMode();
599 struct utimbuf times = {
600 finfo.getAccessTime(),
601 finfo.getModificationTime() };
603 ifstream ifs(fileName().c_str());
604 ofstream ofs(s.c_str(), ios::out|ios::trunc);
609 ::chmod(s.c_str(), fmode);
611 if (::utime(s.c_str(), ×)) {
612 lyxerr << "utime error." << endl;
615 lyxerr << "LyX was not able to make "
616 "backup copy. Beware." << endl;
621 if (writeFile(fileName())) {
623 removeAutosaveFile(fileName());
625 // Saving failed, so backup is not backup
626 if (lyxrc.make_backup) {
627 lyx::rename(s, fileName());
635 bool Buffer::writeFile(string const & fname) const
637 if (read_only && (fname == fileName())) {
641 FileInfo finfo(fname);
642 if (finfo.exist() && !finfo.writable()) {
646 ofstream ofs(fname.c_str());
652 // Use the standard "C" locale for file output.
653 ofs.imbue(std::locale::classic());
656 // The top of the file should not be written by params.
658 // write out a comment in the top of the file
659 ofs << '#' << lyx_docversion
660 << " created this file. For more info see http://www.lyx.org/\n"
661 << "\\lyxformat " << LYX_FORMAT << "\n";
663 // now write out the buffer paramters.
664 params.writeFile(ofs);
666 ofs << "\\end_header\n";
668 Paragraph::depth_type depth = 0;
670 // this will write out all the paragraphs
671 // using recursive descent.
672 ParagraphList::const_iterator pit = paragraphs.begin();
673 ParagraphList::const_iterator pend = paragraphs.end();
674 for (; pit != pend; ++pit)
675 pit->write(this, ofs, params, depth);
677 // Write marker that shows file is complete
678 ofs << "\n\\the_end" << endl;
682 // how to check if close went ok?
683 // Following is an attempt... (BE 20001011)
685 // good() returns false if any error occured, including some
687 // bad() returns true if something bad happened in the buffer,
688 // which should include file system full errors.
695 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
697 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
709 pair<int, string> const addDepth(int depth, int ldepth)
713 d += (ldepth - depth) * 2;
714 return make_pair(d, string(d, ' '));
720 string const Buffer::asciiParagraph(Paragraph const & par,
721 unsigned int linelen,
722 bool noparbreak) const
724 ostringstream buffer;
726 Paragraph::depth_type ltype_depth = 0;
727 bool ref_printed = false;
728 Paragraph::depth_type depth = par.params().depth();
730 // First write the layout
731 string const & tmp = par.layout()->name();
732 if (compare_no_case(tmp, "itemize") == 0) {
734 ltype_depth = depth + 1;
735 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
737 ltype_depth = depth + 1;
738 } else if (contains(ascii_lowercase(tmp), "ection")) {
740 ltype_depth = depth + 1;
741 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
743 ltype_depth = depth + 1;
744 } else if (compare_ascii_no_case(tmp, "description") == 0) {
746 ltype_depth = depth + 1;
747 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
750 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
758 /* maybe some vertical spaces */
760 /* the labelwidthstring used in lists */
764 /* some pagebreaks? */
768 /* what about the alignment */
770 // linelen <= 0 is special and means we don't have paragraph breaks
772 string::size_type currlinelen = 0;
778 buffer << string(depth * 2, ' ');
779 currlinelen += depth * 2;
782 // we should probably change to the paragraph language in the
783 // gettext here (if possible) so that strings are outputted in
784 // the correct language! (20012712 Jug)
788 case 4: // (Sub)Paragraph
789 case 5: // Description
793 buffer << _("Abstract") << "\n\n";
796 string const abst = _("Abstract: ");
798 currlinelen += abst.length();
801 case 7: // Bibliography
804 buffer << _("References") << "\n\n";
807 string const refs = _("References: ");
809 currlinelen += refs.length();
817 string const parlab = par.params().labelString();
818 buffer << parlab << ' ';
819 currlinelen += parlab.length() + 1;
827 pair<int, string> p = addDepth(depth, ltype_depth);
829 currlinelen += p.first;
832 // this is to change the linebreak to do it by word a bit more
833 // intelligent hopefully! (only in the case where we have a
834 // max linelength!) (Jug)
838 for (pos_type i = 0; i < par.size(); ++i) {
839 char c = par.getUChar(params, i);
841 case Paragraph::META_INSET:
843 Inset const * inset = par.getInset(i);
847 currlinelen += word.length();
850 if (inset->ascii(this, buffer, linelen)) {
851 // to be sure it breaks paragraph
852 currlinelen += linelen;
861 currlinelen + word.length() > linelen - 10) {
863 pair<int, string> p = addDepth(depth, ltype_depth);
865 currlinelen = p.first;
868 buffer << word << ' ';
869 currlinelen += word.length() + 1;
876 lyxerr[Debug::INFO] <<
877 "writeAsciiFile: NULL char in structure." << endl;
880 (currlinelen + word.length()) > linelen)
884 pair<int, string> p =
885 addDepth(depth, ltype_depth);
887 currlinelen = p.first;
894 return STRCONV(buffer.str());
898 void Buffer::writeFileAscii(string const & fname, int linelen)
900 ofstream ofs(fname.c_str());
902 string const file = MakeDisplayPath(fname, 50);
903 string text = bformat(_("Could not save the document\n%1$s."), file);
904 Alert::error(_("Could not save document"), text);
907 writeFileAscii(ofs, linelen);
911 void Buffer::writeFileAscii(ostream & os, int linelen)
913 ParagraphList::iterator beg = paragraphs.begin();
914 ParagraphList::iterator end = paragraphs.end();
915 ParagraphList::iterator it = beg;
916 for (; it != end; ++it) {
917 os << asciiParagraph(*it, linelen, it == beg);
924 void Buffer::makeLaTeXFile(string const & fname,
925 string const & original_path,
926 LatexRunParams const & runparams,
927 bool only_body, bool only_preamble)
929 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
931 ofstream ofs(fname.c_str());
933 string const file = MakeDisplayPath(fname, 50);
934 string text = bformat(_("Could not open the specified document\n%1$s."),
936 Alert::error(_("Could not open file"), text);
940 makeLaTeXFile(ofs, original_path,
941 runparams, only_body, only_preamble);
945 lyxerr << "File was not closed properly." << endl;
950 void Buffer::makeLaTeXFile(ostream & os,
951 string const & original_path,
952 LatexRunParams const & runparams_in,
953 bool only_body, bool only_preamble)
955 LatexRunParams runparams = runparams_in;
956 niceFile = runparams.nice; // this will be used by Insetincludes.
958 // validate the buffer.
959 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
960 LaTeXFeatures features(params);
962 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
965 // The starting paragraph of the coming rows is the
966 // first paragraph of the document. (Asger)
967 texrow.start(paragraphs.begin()->id(), 0);
969 if (!only_body && runparams.nice) {
970 os << "%% " << lyx_docversion << " created this file. "
971 "For more info, see http://www.lyx.org/.\n"
972 "%% Do not edit unless you really know what "
977 lyxerr[Debug::INFO] << "lyx header finished" << endl;
978 // There are a few differences between nice LaTeX and usual files:
979 // usual is \batchmode and has a
980 // special input@path to allow the including of figures
981 // with either \input or \includegraphics (what figinsets do).
982 // input@path is set when the actual parameter
983 // original_path is set. This is done for usual tex-file, but not
984 // for nice-latex-file. (Matthias 250696)
986 if (!runparams.nice) {
987 // code for usual, NOT nice-latex-file
988 os << "\\batchmode\n"; // changed
992 if (!original_path.empty()) {
993 string inputpath = os::external_path(original_path);
994 subst(inputpath, "~", "\\string~");
995 os << "\\makeatletter\n"
996 << "\\def\\input@path{{"
997 << inputpath << "/}}\n"
998 << "\\makeatother\n";
1004 // Write the preamble
1005 runparams.use_babel = params.writeLaTeX(os, features, texrow);
1011 os << "\\begin{document}\n";
1014 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1016 if (!lyxrc.language_auto_begin) {
1017 os << subst(lyxrc.language_command_begin, "$$lang",
1018 params.language->babel())
1023 latexParagraphs(this, paragraphs, os, texrow, runparams);
1025 // add this just in case after all the paragraphs
1029 if (!lyxrc.language_auto_end) {
1030 os << subst(lyxrc.language_command_end, "$$lang",
1031 params.language->babel())
1037 os << "\\end{document}\n";
1040 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1042 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1046 // Just to be sure. (Asger)
1049 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1050 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1053 // we want this to be true outside previews (for insetexternal)
1058 bool Buffer::isLatex() const
1060 return params.getLyXTextClass().outputType() == LATEX;
1064 bool Buffer::isLinuxDoc() const
1066 return params.getLyXTextClass().outputType() == LINUXDOC;
1070 bool Buffer::isLiterate() const
1072 return params.getLyXTextClass().outputType() == LITERATE;
1076 bool Buffer::isDocBook() const
1078 return params.getLyXTextClass().outputType() == DOCBOOK;
1082 bool Buffer::isSGML() const
1084 LyXTextClass const & tclass = params.getLyXTextClass();
1086 return tclass.outputType() == LINUXDOC ||
1087 tclass.outputType() == DOCBOOK;
1091 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1093 ofstream ofs(fname.c_str());
1096 string const file = MakeDisplayPath(fname, 50);
1097 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1099 Alert::error(_("Could not save document"), text);
1103 niceFile = nice; // this will be used by included files.
1105 LaTeXFeatures features(params);
1111 LyXTextClass const & tclass = params.getLyXTextClass();
1113 string top_element = tclass.latexname();
1116 ofs << "<!doctype linuxdoc system";
1118 string preamble = params.preamble;
1119 const string name = nice ? ChangeExtension(filename_, ".sgml")
1121 preamble += features.getIncludedFiles(name);
1122 preamble += features.getLyXSGMLEntities();
1124 if (!preamble.empty()) {
1125 ofs << " [ " << preamble << " ]";
1129 if (params.options.empty())
1130 sgml::openTag(ofs, 0, false, top_element);
1132 string top = top_element;
1134 top += params.options;
1135 sgml::openTag(ofs, 0, false, top);
1139 ofs << "<!-- " << lyx_docversion
1140 << " created this file. For more info see http://www.lyx.org/"
1143 Paragraph::depth_type depth = 0; // paragraph depth
1145 vector<string> environment_stack(5);
1147 users->resetErrorList();
1149 ParagraphList::iterator pit = paragraphs.begin();
1150 ParagraphList::iterator pend = paragraphs.end();
1151 for (; pit != pend; ++pit) {
1152 LyXLayout_ptr const & style = pit->layout();
1153 // treat <toc> as a special case for compatibility with old code
1154 if (pit->isInset(0)) {
1155 Inset * inset = pit->getInset(0);
1156 Inset::Code lyx_code = inset->lyxCode();
1157 if (lyx_code == Inset::TOC_CODE) {
1158 string const temp = "toc";
1159 sgml::openTag(ofs, depth, false, temp);
1164 // environment tag closing
1165 for (; depth > pit->params().depth(); --depth) {
1166 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1167 environment_stack[depth].erase();
1170 // write opening SGML tags
1171 switch (style->latextype) {
1172 case LATEX_PARAGRAPH:
1173 if (depth == pit->params().depth()
1174 && !environment_stack[depth].empty()) {
1175 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1176 environment_stack[depth].erase();
1182 sgml::openTag(ofs, depth, false, style->latexname());
1187 parseError(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
1189 if (!environment_stack[depth].empty()) {
1190 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1194 environment_stack[depth].erase();
1195 sgml::openTag(ofs, depth, false, style->latexname());
1198 case LATEX_ENVIRONMENT:
1199 case LATEX_ITEM_ENVIRONMENT:
1200 case LATEX_BIB_ENVIRONMENT:
1202 string const & latexname = style->latexname();
1204 if (depth == pit->params().depth()
1205 && environment_stack[depth] != latexname) {
1206 sgml::closeTag(ofs, depth, false,
1207 environment_stack[depth]);
1208 environment_stack[depth].erase();
1210 if (depth < pit->params().depth()) {
1211 depth = pit->params().depth();
1212 environment_stack[depth].erase();
1214 if (environment_stack[depth] != latexname) {
1216 sgml::openTag(ofs, depth, false, "p");
1218 sgml::openTag(ofs, depth, false, latexname);
1220 if (environment_stack.size() == depth + 1)
1221 environment_stack.push_back("!-- --");
1222 environment_stack[depth] = latexname;
1225 if (style->latexparam() == "CDATA")
1228 if (style->latextype == LATEX_ENVIRONMENT) break;
1230 if (style->labeltype == LABEL_MANUAL)
1235 sgml::openTag(ofs, depth + 1, false, item_name);
1240 sgml::openTag(ofs, depth, false, style->latexname());
1244 simpleLinuxDocOnePar(ofs, pit, depth);
1247 // write closing SGML tags
1248 switch (style->latextype) {
1251 case LATEX_ENVIRONMENT:
1252 case LATEX_ITEM_ENVIRONMENT:
1253 case LATEX_BIB_ENVIRONMENT:
1254 if (style->latexparam() == "CDATA")
1258 sgml::closeTag(ofs, depth, false, style->latexname());
1264 for (int i = depth; i >= 0; --i)
1265 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1269 sgml::closeTag(ofs, 0, false, top_element);
1273 // How to check for successful close
1275 // we want this to be true outside previews (for insetexternal)
1278 users->showErrorList(_("LinuxDoc"));
1282 // checks, if newcol chars should be put into this line
1283 // writes newline, if necessary.
1286 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1287 string::size_type newcol)
1290 if (colcount > lyxrc.ascii_linelen) {
1292 colcount = newcol; // assume write after this call
1307 string tag_name(PAR_TAG const & pt) {
1309 case NONE: return "!-- --";
1310 case TT: return "tt";
1311 case SF: return "sf";
1312 case BF: return "bf";
1313 case IT: return "it";
1314 case SL: return "sl";
1315 case EM: return "em";
1322 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1324 p1 = static_cast<PAR_TAG>(p1 | p2);
1329 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1331 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1337 // Handle internal paragraph parsing -- layout already processed.
1338 void Buffer::simpleLinuxDocOnePar(ostream & os,
1339 ParagraphList::iterator par,
1340 Paragraph::depth_type /*depth*/) const
1342 LyXLayout_ptr const & style = par->layout();
1344 string::size_type char_line_count = 5; // Heuristic choice ;-)
1346 // gets paragraph main font
1349 if (style->labeltype == LABEL_MANUAL) {
1350 font_old = style->labelfont;
1353 font_old = style->font;
1357 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1358 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1359 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1362 stack<PAR_TAG> tag_state;
1363 // parsing main loop
1364 for (pos_type i = 0; i < par->size(); ++i) {
1366 PAR_TAG tag_close = NONE;
1367 list < PAR_TAG > tag_open;
1369 LyXFont const font = par->getFont(params, i, outerFont(par, paragraphs));
1371 if (font_old.family() != font.family()) {
1372 switch (family_type) {
1373 case LyXFont::SANS_FAMILY:
1376 case LyXFont::TYPEWRITER_FAMILY:
1383 family_type = font.family();
1385 switch (family_type) {
1386 case LyXFont::SANS_FAMILY:
1387 tag_open.push_back(SF);
1389 case LyXFont::TYPEWRITER_FAMILY:
1390 tag_open.push_back(TT);
1397 if (font_old.series() != font.series()) {
1398 switch (series_type) {
1399 case LyXFont::BOLD_SERIES:
1406 series_type = font.series();
1408 switch (series_type) {
1409 case LyXFont::BOLD_SERIES:
1410 tag_open.push_back(BF);
1418 if (font_old.shape() != font.shape()) {
1419 switch (shape_type) {
1420 case LyXFont::ITALIC_SHAPE:
1423 case LyXFont::SLANTED_SHAPE:
1430 shape_type = font.shape();
1432 switch (shape_type) {
1433 case LyXFont::ITALIC_SHAPE:
1434 tag_open.push_back(IT);
1436 case LyXFont::SLANTED_SHAPE:
1437 tag_open.push_back(SL);
1444 if (font_old.emph() != font.emph()) {
1445 if (font.emph() == LyXFont::ON) {
1446 tag_open.push_back(EM);
1455 list < PAR_TAG > temp;
1456 while (!tag_state.empty() && tag_close) {
1457 PAR_TAG k = tag_state.top();
1459 os << "</" << tag_name(k) << '>';
1466 for(list< PAR_TAG >::const_iterator j = temp.begin();
1467 j != temp.end(); ++j) {
1469 os << '<' << tag_name(*j) << '>';
1472 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1473 j != tag_open.end(); ++j) {
1475 os << '<' << tag_name(*j) << '>';
1478 char c = par->getChar(i);
1480 if (c == Paragraph::META_INSET) {
1481 Inset * inset = par->getInset(i);
1482 inset->linuxdoc(this, os);
1487 if (style->latexparam() == "CDATA") {
1488 // "TeX"-Mode on == > SGML-Mode on.
1495 boost::tie(ws, str) = sgml::escapeChar(c);
1496 if (ws && !par->isFreeSpacing()) {
1497 // in freespacing mode, spaces are
1498 // non-breaking characters
1499 if (desc_on) {// if char is ' ' then...
1502 sgmlLineBreak(os, char_line_count, 6);
1506 sgmlLineBreak(os, char_line_count, 1);
1511 char_line_count += str.length();
1517 while (!tag_state.empty()) {
1518 os << "</" << tag_name(tag_state.top()) << '>';
1522 // resets description flag correctly
1524 // <tag> not closed...
1525 sgmlLineBreak(os, char_line_count, 6);
1531 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1533 ofstream ofs(fname.c_str());
1535 string const file = MakeDisplayPath(fname, 50);
1536 string text = bformat(_("Could not save the specified document\n%1$s.\n"),
1538 Alert::error(_("Could not save document"), text);
1542 niceFile = nice; // this will be used by Insetincludes.
1544 LaTeXFeatures features(params);
1549 LyXTextClass const & tclass = params.getLyXTextClass();
1550 string top_element = tclass.latexname();
1553 ofs << "<!DOCTYPE " << top_element
1554 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1556 string preamble = params.preamble;
1557 const string name = nice ? ChangeExtension(filename_, ".sgml")
1559 preamble += features.getIncludedFiles(name);
1560 preamble += features.getLyXSGMLEntities();
1562 if (!preamble.empty()) {
1563 ofs << "\n [ " << preamble << " ]";
1568 string top = top_element;
1570 top += params.language->code();
1573 if (!params.options.empty()) {
1575 top += params.options;
1577 sgml::openTag(ofs, 0, false, top);
1579 ofs << "<!-- DocBook file was created by " << lyx_docversion
1580 << "\n See http://www.lyx.org/ for more information -->\n";
1582 vector<string> environment_stack(10);
1583 vector<string> environment_inner(10);
1584 vector<string> command_stack(10);
1586 bool command_flag = false;
1587 Paragraph::depth_type command_depth = 0;
1588 Paragraph::depth_type command_base = 0;
1589 Paragraph::depth_type cmd_depth = 0;
1590 Paragraph::depth_type depth = 0; // paragraph depth
1593 string command_name;
1595 users->resetErrorList();
1597 ParagraphList::iterator par = paragraphs.begin();
1598 ParagraphList::iterator pend = paragraphs.end();
1600 for (; par != pend; ++par) {
1604 int desc_on = 0; // description mode
1606 LyXLayout_ptr const & style = par->layout();
1608 // environment tag closing
1609 for (; depth > par->params().depth(); --depth) {
1610 if (environment_inner[depth] != "!-- --" && !environment_inner[depth].empty()) {
1611 item_name = "listitem";
1612 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1613 if (environment_inner[depth] == "varlistentry")
1614 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1616 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1617 environment_stack[depth].erase();
1618 environment_inner[depth].erase();
1621 if (depth == par->params().depth()
1622 && environment_stack[depth] != style->latexname()
1623 && !environment_stack[depth].empty()) {
1624 if (environment_inner[depth] != "!-- --") {
1625 item_name= "listitem";
1626 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1627 if (environment_inner[depth] == "varlistentry")
1628 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1631 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1633 environment_stack[depth].erase();
1634 environment_inner[depth].erase();
1637 // Write opening SGML tags.
1638 switch (style->latextype) {
1639 case LATEX_PARAGRAPH:
1640 sgml::openTag(ofs, depth + command_depth,
1641 false, style->latexname());
1646 parseError(ErrorItem(_("Error"), _("Wrong depth for LatexType Command."), par->id(), 0, par->size()));
1648 command_name = style->latexname();
1650 sgmlparam = style->latexparam();
1651 c_params = split(sgmlparam, c_depth,'|');
1653 cmd_depth = lyx::atoi(c_depth);
1656 if (cmd_depth < command_base) {
1657 for (Paragraph::depth_type j = command_depth;
1658 j >= command_base; --j) {
1659 sgml::closeTag(ofs, j, false, command_stack[j]);
1662 command_depth = command_base = cmd_depth;
1663 } else if (cmd_depth <= command_depth) {
1664 for (int j = command_depth;
1665 j >= int(cmd_depth); --j) {
1666 sgml::closeTag(ofs, j, false, command_stack[j]);
1669 command_depth = cmd_depth;
1671 command_depth = cmd_depth;
1673 command_depth = command_base = cmd_depth;
1674 command_flag = true;
1676 if (command_stack.size() == command_depth + 1)
1677 command_stack.push_back(string());
1678 command_stack[command_depth] = command_name;
1680 // treat label as a special case for
1681 // more WYSIWYM handling.
1682 // This is a hack while paragraphs can't have
1683 // attributes, like id in this case.
1684 if (par->isInset(0)) {
1685 Inset * inset = par->getInset(0);
1686 Inset::Code lyx_code = inset->lyxCode();
1687 if (lyx_code == Inset::LABEL_CODE) {
1688 command_name += " id=\"";
1689 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1690 command_name += '"';
1695 sgml::openTag(ofs, depth + command_depth, false, command_name);
1697 item_name = c_params.empty() ? "title" : c_params;
1698 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1701 case LATEX_ENVIRONMENT:
1702 case LATEX_ITEM_ENVIRONMENT:
1703 if (depth < par->params().depth()) {
1704 depth = par->params().depth();
1705 environment_stack[depth].erase();
1708 if (environment_stack[depth] != style->latexname()) {
1709 if (environment_stack.size() == depth + 1) {
1710 environment_stack.push_back("!-- --");
1711 environment_inner.push_back("!-- --");
1713 environment_stack[depth] = style->latexname();
1714 environment_inner[depth] = "!-- --";
1715 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1717 if (environment_inner[depth] != "!-- --") {
1718 item_name= "listitem";
1719 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1720 if (environment_inner[depth] == "varlistentry")
1721 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1725 if (style->latextype == LATEX_ENVIRONMENT) {
1726 if (!style->latexparam().empty()) {
1727 if (style->latexparam() == "CDATA")
1730 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1735 desc_on = (style->labeltype == LABEL_MANUAL);
1737 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1738 sgml::openTag(ofs, depth + 1 + command_depth,
1739 false, environment_inner[depth]);
1741 item_name = desc_on ? "term" : "para";
1742 sgml::openTag(ofs, depth + 1 + command_depth,
1746 sgml::openTag(ofs, depth + command_depth,
1747 false, style->latexname());
1751 simpleDocBookOnePar(ofs, par, desc_on,
1752 depth + 1 + command_depth);
1755 // write closing SGML tags
1756 switch (style->latextype) {
1758 end_tag = c_params.empty() ? "title" : c_params;
1759 sgml::closeTag(ofs, depth + command_depth,
1762 case LATEX_ENVIRONMENT:
1763 if (!style->latexparam().empty()) {
1764 if (style->latexparam() == "CDATA")
1767 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1770 case LATEX_ITEM_ENVIRONMENT:
1771 if (desc_on == 1) break;
1773 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1775 case LATEX_PARAGRAPH:
1776 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1779 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1785 for (int d = depth; d >= 0; --d) {
1786 if (!environment_stack[depth].empty()) {
1787 if (environment_inner[depth] != "!-- --") {
1788 item_name = "listitem";
1789 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1790 if (environment_inner[depth] == "varlistentry")
1791 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1794 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1798 for (int j = command_depth; j >= 0 ; --j)
1799 if (!command_stack[j].empty()) {
1800 sgml::closeTag(ofs, j, false, command_stack[j]);
1805 sgml::closeTag(ofs, 0, false, top_element);
1808 // How to check for successful close
1810 // we want this to be true outside previews (for insetexternal)
1812 users->showErrorList(_("DocBook"));
1816 void Buffer::simpleDocBookOnePar(ostream & os,
1817 ParagraphList::iterator par, int & desc_on,
1818 Paragraph::depth_type depth) const
1820 bool emph_flag = false;
1822 LyXLayout_ptr const & style = par->layout();
1824 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1826 int char_line_count = depth;
1827 //if (!style.free_spacing)
1828 // os << string(depth,' ');
1830 // parsing main loop
1831 for (pos_type i = 0; i < par->size(); ++i) {
1832 LyXFont font = par->getFont(params, i, outerFont(par, paragraphs));
1834 // handle <emphasis> tag
1835 if (font_old.emph() != font.emph()) {
1836 if (font.emph() == LyXFont::ON) {
1837 if (style->latexparam() == "CDATA")
1840 if (style->latexparam() == "CDATA")
1844 if (style->latexparam() == "CDATA")
1846 os << "</emphasis>";
1847 if (style->latexparam() == "CDATA")
1854 if (par->isInset(i)) {
1855 Inset * inset = par->getInset(i);
1856 // don't print the inset in position 0 if desc_on == 3 (label)
1857 if (i || desc_on != 3) {
1858 if (style->latexparam() == "CDATA")
1860 inset->docbook(this, os, false);
1861 if (style->latexparam() == "CDATA")
1865 char c = par->getChar(i);
1868 boost::tie(ws, str) = sgml::escapeChar(c);
1870 if (style->pass_thru) {
1872 } else if (par->isFreeSpacing() || c != ' ') {
1874 } else if (desc_on == 1) {
1876 os << "\n</term><listitem><para>";
1886 if (style->latexparam() == "CDATA")
1888 os << "</emphasis>";
1889 if (style->latexparam() == "CDATA")
1893 // resets description flag correctly
1895 // <term> not closed...
1896 os << "</term>\n<listitem><para> </para>";
1898 if (style->free_spacing)
1903 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1904 // Other flags: -wall -v0 -x
1905 int Buffer::runChktex()
1907 if (!users->text) return 0;
1909 users->owner()->busy(true);
1911 // get LaTeX-Filename
1912 string const name = getLatexName();
1913 string path = filePath();
1915 string const org_path = path;
1916 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1920 Path p(path); // path to LaTeX file
1921 users->owner()->message(_("Running chktex..."));
1923 // Generate the LaTeX file if neccessary
1924 LatexRunParams runparams;
1925 runparams.flavor = LatexRunParams::LATEX;
1926 runparams.nice = false;
1927 makeLaTeXFile(name, org_path, runparams);
1930 Chktex chktex(lyxrc.chktex_command, name, filePath());
1931 int res = chktex.run(terr); // run chktex
1934 Alert::error(_("chktex failure"),
1935 _("Could not run chktex successfully."));
1936 } else if (res > 0) {
1937 // Insert all errors as errors boxes
1938 ErrorList el (*this, terr);
1939 users->setErrorList(el);
1940 users->showErrorList(_("ChkTeX"));
1943 users->owner()->busy(false);
1949 void Buffer::validate(LaTeXFeatures & features) const
1951 LyXTextClass const & tclass = params.getLyXTextClass();
1953 if (params.tracking_changes) {
1954 features.require("dvipost");
1955 features.require("color");
1958 // AMS Style is at document level
1959 if (params.use_amsmath == BufferParams::AMS_ON
1960 || tclass.provides(LyXTextClass::amsmath))
1961 features.require("amsmath");
1963 for_each(paragraphs.begin(), paragraphs.end(),
1964 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
1966 // the bullet shapes are buffer level not paragraph level
1967 // so they are tested here
1968 for (int i = 0; i < 4; ++i) {
1969 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
1970 int const font = params.user_defined_bullets[i].getFont();
1972 int const c = params
1973 .user_defined_bullets[i]
1980 features.require("latexsym");
1982 } else if (font == 1) {
1983 features.require("amssymb");
1984 } else if ((font >= 2 && font <= 5)) {
1985 features.require("pifont");
1990 if (lyxerr.debugging(Debug::LATEX)) {
1991 features.showStruct();
1996 void Buffer::getLabelList(std::vector<string> & list) const
1998 /// if this is a child document and the parent is already loaded
1999 /// Use the parent's list instead [ale990407]
2000 if (!params.parentname.empty()
2001 && bufferlist.exists(params.parentname)) {
2002 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2004 tmp->getLabelList(list);
2009 for (inset_iterator it = inset_const_iterator_begin();
2010 it != inset_const_iterator_end(); ++it) {
2011 it->getLabelList(list);
2016 // This is also a buffer property (ale)
2017 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2019 /// if this is a child document and the parent is already loaded
2020 /// use the parent's list instead [ale990412]
2021 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2022 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2024 tmp->fillWithBibKeys(keys);
2029 for (inset_iterator it = inset_const_iterator_begin();
2030 it != inset_const_iterator_end(); ++it) {
2031 if (it->lyxCode() == Inset::BIBTEX_CODE)
2032 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2033 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2034 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2035 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2036 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2037 string const key = bib.getContents();
2038 string const opt = bib.getOptions();
2039 string const ref; // = pit->asString(this, false);
2040 string const info = opt + "TheBibliographyRef" + ref;
2041 keys.push_back(pair<string, string>(key, info));
2047 bool Buffer::isDepClean(string const & name) const
2049 DepClean::const_iterator it = dep_clean_.find(name);
2050 if (it == dep_clean_.end())
2056 void Buffer::markDepClean(string const & name)
2058 dep_clean_[name] = true;
2062 bool Buffer::dispatch(string const & command, bool * result)
2064 // Split command string into command and argument
2066 string line = ltrim(command);
2067 string const arg = trim(split(line, cmd, ' '));
2069 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2073 bool Buffer::dispatch(int action, string const & argument, bool * result)
2075 bool dispatched = true;
2079 bool const tmp = Exporter::Export(this, argument, false);
2092 void Buffer::resizeInsets(BufferView * bv)
2094 /// then remove all LyXText in text-insets
2095 for_each(paragraphs.begin(), paragraphs.end(),
2096 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2100 void Buffer::redraw()
2102 #warning repaint needed here, or do you mean update() ?
2108 void Buffer::changeLanguage(Language const * from, Language const * to)
2110 lyxerr << "Changing Language!" << endl;
2112 // Take care of l10n/i18n
2115 ParIterator end = par_iterator_end();
2116 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2117 it->changeLanguage(params, from, to);
2121 void Buffer::updateDocLang(Language const * nlang)
2123 messages_.reset(new Messages(nlang->code()));
2127 bool Buffer::isMultiLingual()
2129 ParIterator end = par_iterator_end();
2130 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2131 if (it->isMultiLingual(params))
2138 void Buffer::inset_iterator::setParagraph()
2140 while (pit != pend) {
2141 it = pit->insetlist.begin();
2142 if (it != pit->insetlist.end())
2149 Inset * Buffer::getInsetFromID(int id_arg) const
2151 for (inset_iterator it = inset_const_iterator_begin();
2152 it != inset_const_iterator_end(); ++it)
2154 if (it->id() == id_arg)
2156 Inset * in = it->getInsetFromID(id_arg);
2164 ParIterator Buffer::getParFromID(int id) const
2166 #warning FIXME: const correctness! (Andre)
2167 ParIterator it = const_cast<Buffer*>(this)->par_iterator_begin();
2168 ParIterator end = const_cast<Buffer*>(this)->par_iterator_end();
2170 #warning FIXME, perhaps this func should return a ParIterator? (Lgb)
2172 // John says this is called with id == -1 from undo
2173 lyxerr << "getParFromID(), id: " << id << endl;
2177 for (; it != end; ++it)
2185 bool Buffer::hasParWithID(int id) const
2187 ParConstIterator it = par_iterator_begin();
2188 ParConstIterator end = par_iterator_end();
2191 // John says this is called with id == -1 from undo
2192 lyxerr << "hasParWithID(), id: " << id << endl;
2196 for (; it != end; ++it)
2204 ParIterator Buffer::par_iterator_begin()
2206 return ParIterator(paragraphs.begin(), paragraphs);
2210 ParIterator Buffer::par_iterator_end()
2212 return ParIterator(paragraphs.end(), paragraphs);
2215 ParConstIterator Buffer::par_iterator_begin() const
2217 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).begin(), paragraphs);
2221 ParConstIterator Buffer::par_iterator_end() const
2223 return ParConstIterator(const_cast<ParagraphList&>(paragraphs).end(), paragraphs);
2228 void Buffer::addUser(BufferView * u)
2234 void Buffer::delUser(BufferView *)
2240 Language const * Buffer::getLanguage() const
2242 return params.language;
2246 string const Buffer::B_(string const & l10n) const
2248 if (messages_.get()) {
2249 return messages_->get(l10n);
2256 bool Buffer::isClean() const
2262 bool Buffer::isBakClean() const
2268 void Buffer::markClean() const
2274 // if the .lyx file has been saved, we don't need an
2280 void Buffer::markBakClean()
2286 void Buffer::setUnnamed(bool flag)
2292 bool Buffer::isUnnamed()
2298 void Buffer::markDirty()
2306 DepClean::iterator it = dep_clean_.begin();
2307 DepClean::const_iterator const end = dep_clean_.end();
2309 for (; it != end; ++it) {
2315 string const & Buffer::fileName() const
2321 string const & Buffer::filePath() const
2327 bool Buffer::isReadonly() const
2333 BufferView * Buffer::getUser() const
2339 void Buffer::setParentName(string const & name)
2341 params.parentname = name;
2345 Buffer::inset_iterator::inset_iterator()
2350 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2357 Buffer::inset_iterator Buffer::inset_iterator_begin()
2359 return inset_iterator(paragraphs.begin(), paragraphs.end());
2363 Buffer::inset_iterator Buffer::inset_iterator_end()
2365 return inset_iterator(paragraphs.end(), paragraphs.end());
2369 Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
2371 return inset_iterator(const_cast<ParagraphList&>(paragraphs).begin(),
2372 const_cast<ParagraphList&>(paragraphs).end());
2376 Buffer::inset_iterator Buffer::inset_const_iterator_end() const
2378 return inset_iterator(const_cast<ParagraphList&>(paragraphs).end(),
2379 const_cast<ParagraphList&>(paragraphs).end());
2383 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2387 if (it == pit->insetlist.end()) {
2396 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2398 inset_iterator tmp = *this;
2404 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2410 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2416 ParagraphList::iterator Buffer::inset_iterator::getPar() const
2422 lyx::pos_type Buffer::inset_iterator::getPos() const
2428 bool operator==(Buffer::inset_iterator const & iter1,
2429 Buffer::inset_iterator const & iter2)
2431 return iter1.pit == iter2.pit
2432 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2436 bool operator!=(Buffer::inset_iterator const & iter1,
2437 Buffer::inset_iterator const & iter2)
2439 return !(iter1 == iter2);