1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * This file is Copyright 1996-2001
12 * ======================================================
18 #include "bufferlist.h"
19 #include "LyXAction.h"
22 #include "tex-strings.h"
24 #include "bufferview_funcs.h"
30 #include "LaTeXFeatures.h"
37 #include "BufferView.h"
38 #include "ParagraphParameters.h"
39 #include "iterators.h"
40 #include "lyxtextclasslist.h"
42 #include "paragraph_funcs.h"
45 #include "frontends/LyXView.h"
47 #include "mathed/formulamacro.h"
48 #include "mathed/formula.h"
50 #include "insets/inset.h"
51 #include "insets/inseterror.h"
52 #include "insets/insetlabel.h"
53 #include "insets/insetref.h"
54 #include "insets/inseturl.h"
55 #include "insets/insetnote.h"
56 #include "insets/insetquotes.h"
57 #include "insets/insetlatexaccent.h"
58 #include "insets/insetbibitem.h"
59 #include "insets/insetbibtex.h"
60 #include "insets/insetcite.h"
61 #include "insets/insetexternal.h"
62 #include "insets/insetindex.h"
63 #include "insets/insetinclude.h"
64 #include "insets/insettoc.h"
65 #include "insets/insetparent.h"
66 #include "insets/insetspecialchar.h"
67 #include "insets/insettext.h"
68 #include "insets/insetert.h"
69 #include "insets/insetgraphics.h"
70 #include "insets/insetfoot.h"
71 #include "insets/insetmarginal.h"
72 #include "insets/insetoptarg.h"
73 #include "insets/insetminipage.h"
74 #include "insets/insetfloat.h"
75 #include "insets/insetwrap.h"
76 #include "insets/insettabular.h"
78 #include "insets/insettheorem.h"
79 #include "insets/insetlist.h"
81 #include "insets/insetcaption.h"
82 #include "insets/insetfloatlist.h"
84 #include "frontends/Dialogs.h"
85 #include "frontends/Alert.h"
87 #include "graphics/Previews.h"
89 #include "support/textutils.h"
90 #include "support/filetools.h"
91 #include "support/path.h"
92 #include "support/os.h"
93 #include "support/lyxlib.h"
94 #include "support/FileInfo.h"
95 #include "support/lyxmanip.h"
96 #include "support/lyxtime.h"
98 #include <boost/bind.hpp>
99 #include <boost/tuple/tuple.hpp>
100 #include "BoostFormat.h"
112 #include <sys/types.h>
119 #ifndef CXX_GLOBAL_CSTD
131 using std::make_pair;
139 using lyx::textclass_type;
141 // all these externs should eventually be removed.
142 extern BufferList bufferlist;
146 const int LYX_FORMAT = 222;
150 Buffer::Buffer(string const & file, bool ronly)
151 : niceFile(true), lyx_clean(true), bak_clean(true),
152 unnamed(false), read_only(ronly),
153 filename_(file), users(0)
155 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
156 filepath_ = OnlyPath(file);
158 if (read_only || lyxrc.use_tempdir) {
159 tmppath = CreateBufferTmpDir();
164 // set initial author
165 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
171 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
172 // here the buffer should take care that it is
173 // saved properly, before it goes into the void.
175 // make sure that views using this buffer
180 if (!tmppath.empty()) {
181 DestroyBufferTmpDir(tmppath);
186 // Remove any previewed LaTeX snippets assocoated with this buffer.
187 grfx::Previews::get().removeLoader(this);
191 string const Buffer::getLatexName(bool no_path) const
193 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
195 return OnlyFilename(name);
201 pair<Buffer::LogType, string> const Buffer::getLogName() const
203 string const filename = getLatexName(false);
205 if (filename.empty())
206 return make_pair(Buffer::latexlog, string());
208 string path = OnlyPath(filename);
210 if (lyxrc.use_tempdir || !IsDirWriteable(path))
213 string const fname = AddName(path,
214 OnlyFilename(ChangeExtension(filename,
217 AddName(path, OnlyFilename(
218 ChangeExtension(filename,
219 formats.extension("literate") + ".out")));
221 // If no Latex log or Build log is newer, show Build log
223 FileInfo const f_fi(fname);
224 FileInfo const b_fi(bname);
227 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
228 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
229 return make_pair(Buffer::buildlog, bname);
231 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
232 return make_pair(Buffer::latexlog, fname);
236 void Buffer::setReadonly(bool flag)
238 if (read_only != flag) {
241 users->owner()->getDialogs().updateBufferDependent(false);
246 AuthorList & Buffer::authors()
252 /// Update window titles of all users
253 // Should work on a list
254 void Buffer::updateTitles() const
257 users->owner()->updateWindowTitle();
261 /// Reset autosave timer of all users
262 // Should work on a list
263 void Buffer::resetAutosaveTimers() const
266 users->owner()->resetAutosaveTimer();
270 void Buffer::setFileName(string const & newfile)
272 filename_ = MakeAbsPath(newfile);
273 filepath_ = OnlyPath(filename_);
274 setReadonly(IsFileWriteable(filename_) == 0);
279 // We'll remove this later. (Lgb)
282 string last_inset_read;
285 #warning And _why_ is this here? (Lgb)
289 vector<int> author_ids;
294 // candidate for move to BufferView
295 // (at least some parts in the beginning of the func)
298 // changed to be public and have one parameter
299 // if par = 0 normal behavior
300 // else insert behavior
301 // Returns false if "\the_end" is not read (Asger)
302 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
309 Paragraph::depth_type depth = 0;
310 bool the_end_read = false;
312 Paragraph * first_par = 0;
313 LyXFont font(LyXFont::ALL_INHERIT, params.language);
317 par->layout(params.getLyXTextClass().defaultLayout());
319 // We are inserting into an existing document
320 users->text->breakParagraph(users);
321 first_par = users->text->ownerParagraph();
324 // We don't want to adopt the parameters from the
325 // document we insert, so we skip until the text begins:
328 string const pretoken = lex.getString();
329 if (pretoken == "\\layout") {
330 lex.pushToken(pretoken);
338 string const token = lex.getString();
340 if (token.empty()) continue;
342 lyxerr[Debug::PARSER] << "Handling token: `"
343 << token << '\'' << endl;
346 parseSingleLyXformat2Token(lex, par, first_par,
354 paragraphs.set(first_par);
356 if (unknown_layouts > 0) {
357 string s = _("Couldn't set the layout for ");
358 if (unknown_layouts == 1) {
359 s += _("one paragraph");
361 s += tostr(unknown_layouts);
362 s += _(" paragraphs");
365 Alert::alert(_("Textclass Loading Error!"), s,
366 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
368 Alert::alert(_("Textclass Loading Error!"), s,
369 _("When reading ") + fileName());
373 if (unknown_tokens > 0) {
374 string s = _("Encountered ");
375 if (unknown_tokens == 1) {
376 s += _("one unknown token");
378 s += tostr(unknown_tokens);
379 s += _(" unknown tokens");
382 Alert::alert(_("Textclass Loading Error!"), s,
383 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
385 Alert::alert(_("Textclass Loading Error!"), s,
386 _("When reading ") + fileName());
395 // This stuff is, in the traditional LyX terminology, Super UGLY
396 // but this code is too b0rken to admit of a better solution yet
397 Change current_change;
402 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
403 Paragraph *& first_par,
404 string const & token, int & pos,
405 Paragraph::depth_type & depth,
409 bool the_end_read = false;
411 // The order of the tags tested may seem unnatural, but this
412 // has been done in order to reduce the number of string
413 // comparisons needed to recognize a given token. This leads
414 // on large documents like UserGuide to a reduction of a
416 if (token[0] != '\\') {
417 for (string::const_iterator cit = token.begin();
418 cit != token.end(); ++cit) {
419 par->insertChar(pos, (*cit), font, current_change);
422 } else if (token == "\\layout") {
423 // reset the font as we start a new layout and if the font is
424 // not ALL_INHERIT,document_language then it will be set to the
425 // right values after this tag (Jug 20020420)
426 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
429 string layoutname = lex.getString();
431 LyXTextClass const & tclass = params.getLyXTextClass();
433 if (layoutname.empty()) {
434 layoutname = tclass.defaultLayoutName();
436 bool hasLayout = tclass.hasLayout(layoutname);
438 lyxerr << "Layout '" << layoutname << "' does not"
439 << " exist in textclass '" << tclass.name()
441 lyxerr << "Trying to use default layout instead."
443 layoutname = tclass.defaultLayoutName();
447 // The is the compability reading of layout caption.
448 // It can be removed in LyX version 1.3.0. (Lgb)
449 if (compare_ascii_no_case(layoutname, "caption") == 0) {
450 // We expect that the par we are now working on is
451 // really inside a InsetText inside a InsetFloat.
452 // We also know that captions can only be
453 // one paragraph. (Lgb)
455 // We should now read until the next "\layout"
457 // This is probably not good enough, what if the
458 // caption is the last par in the document (Lgb)
459 istream & ist = lex.getStream();
465 if (prefixIs(line, "\\layout")) {
469 if (prefixIs(line, "\\begin_inset"))
471 if (prefixIs(line, "\\end_inset")) {
482 // Now we should have the whole layout in ss
483 // we should now be able to give this to the
485 ss << "\\end_inset\n";
487 // This seems like a bug in stringstream.
488 // We really should be able to use ss
490 istringstream is(ss.str());
492 tmplex.setStream(is);
493 Inset * inset = new InsetCaption;
494 inset->Read(this, tmplex);
495 par->InsertInset(pos, inset, font);
502 par = new Paragraph(par);
503 par->layout(params.getLyXTextClass().defaultLayout());
504 if (params.tracking_changes)
508 par->layout(params.getLyXTextClass()[layoutname]);
509 // Test whether the layout is obsolete.
510 LyXLayout_ptr const & layout = par->layout();
511 if (!layout->obsoleted_by().empty())
512 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
513 par->params().depth(depth);
518 } else if (token == "\\end_inset") {
519 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
520 << "Last inset read was: " << last_inset_read
522 // Simply ignore this. The insets do not have
524 // But insets should read it, it is a part of
525 // the inset isn't it? Lgb.
526 } else if (token == "\\begin_inset") {
527 readInset(lex, par, pos, font);
528 } else if (token == "\\family") {
530 font.setLyXFamily(lex.getString());
531 } else if (token == "\\series") {
533 font.setLyXSeries(lex.getString());
534 } else if (token == "\\shape") {
536 font.setLyXShape(lex.getString());
537 } else if (token == "\\size") {
539 font.setLyXSize(lex.getString());
540 } else if (token == "\\lang") {
542 string const tok = lex.getString();
543 Language const * lang = languages.getLanguage(tok);
545 font.setLanguage(lang);
547 font.setLanguage(params.language);
548 lex.printError("Unknown language `$$Token'");
550 } else if (token == "\\numeric") {
552 font.setNumber(font.setLyXMisc(lex.getString()));
553 } else if (token == "\\emph") {
555 font.setEmph(font.setLyXMisc(lex.getString()));
556 } else if (token == "\\bar") {
558 string const tok = lex.getString();
559 // This is dirty, but gone with LyX3. (Asger)
561 font.setUnderbar(LyXFont::ON);
562 else if (tok == "no")
563 font.setUnderbar(LyXFont::OFF);
564 else if (tok == "default")
565 font.setUnderbar(LyXFont::INHERIT);
567 lex.printError("Unknown bar font flag "
569 } else if (token == "\\noun") {
571 font.setNoun(font.setLyXMisc(lex.getString()));
572 } else if (token == "\\color") {
574 font.setLyXColor(lex.getString());
575 } else if (token == "\\SpecialChar") {
576 LyXLayout_ptr const & layout = par->layout();
578 // Insets don't make sense in a free-spacing context! ---Kayvan
579 if (layout->free_spacing || par->isFreeSpacing()) {
582 string const next_token = lex.getString();
583 if (next_token == "\\-") {
584 par->insertChar(pos, '-', font, current_change);
585 } else if (next_token == "~") {
586 par->insertChar(pos, ' ', font, current_change);
588 lex.printError("Token `$$Token' "
590 "paragraph layout!");
595 Inset * inset = new InsetSpecialChar;
596 inset->read(this, lex);
597 par->insertInset(pos, inset, font, current_change);
600 } else if (token == "\\i") {
601 Inset * inset = new InsetLatexAccent;
602 inset->read(this, lex);
603 par->insertInset(pos, inset, font, current_change);
605 } else if (token == "\\backslash") {
606 par->insertChar(pos, '\\', font, current_change);
608 } else if (token == "\\begin_deeper") {
610 } else if (token == "\\end_deeper") {
612 lex.printError("\\end_deeper: "
613 "depth is already null");
617 } else if (token == "\\begin_preamble") {
618 params.readPreamble(lex);
619 } else if (token == "\\textclass") {
621 pair<bool, textclass_type> pp =
622 textclasslist.NumberOfClass(lex.getString());
624 params.textclass = pp.second;
627 Alert::alert(_("Textclass error"),
628 boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
629 _("-- substituting default."));
632 _("Textclass error"),
633 _("The document uses an unknown textclass ")
635 _("-- substituting default."));
637 params.textclass = 0;
639 if (!params.getLyXTextClass().load()) {
640 // if the textclass wasn't loaded properly
641 // we need to either substitute another
642 // or stop loading the file.
643 // I can substitute but I don't see how I can
644 // stop loading... ideas?? ARRae980418
646 Alert::alert(_("Textclass Loading Error!"),
647 boost::io::str(boost::format(_("Can't load textclass %1$s")) %
648 params.getLyXTextClass().name()),
649 _("-- substituting default."));
651 Alert::alert(_("Textclass Loading Error!"),
652 _("Can't load textclass ")
653 + params.getLyXTextClass().name(),
654 _("-- substituting default."));
656 params.textclass = 0;
658 } else if (token == "\\options") {
660 params.options = lex.getString();
661 } else if (token == "\\language") {
662 params.readLanguage(lex);
663 } else if (token == "\\fontencoding") {
665 } else if (token == "\\inputencoding") {
667 params.inputenc = lex.getString();
668 } else if (token == "\\graphics") {
669 params.readGraphicsDriver(lex);
670 } else if (token == "\\fontscheme") {
672 params.fonts = lex.getString();
673 } else if (token == "\\noindent") {
674 par->params().noindent(true);
675 } else if (token == "\\leftindent") {
677 LyXLength value(lex.getString());
678 par->params().leftIndent(value);
679 } else if (token == "\\fill_top") {
680 par->params().spaceTop(VSpace(VSpace::VFILL));
681 } else if (token == "\\fill_bottom") {
682 par->params().spaceBottom(VSpace(VSpace::VFILL));
683 } else if (token == "\\line_top") {
684 par->params().lineTop(true);
685 } else if (token == "\\line_bottom") {
686 par->params().lineBottom(true);
687 } else if (token == "\\pagebreak_top") {
688 par->params().pagebreakTop(true);
689 } else if (token == "\\pagebreak_bottom") {
690 par->params().pagebreakBottom(true);
691 } else if (token == "\\start_of_appendix") {
692 par->params().startOfAppendix(true);
693 } else if (token == "\\paragraph_separation") {
694 int tmpret = lex.findToken(string_paragraph_separation);
697 params.paragraph_separation =
698 static_cast<BufferParams::PARSEP>(tmpret);
699 } else if (token == "\\defskip") {
701 params.defskip = VSpace(lex.getString());
702 } else if (token == "\\quotes_language") {
703 int tmpret = lex.findToken(string_quotes_language);
706 InsetQuotes::quote_language tmpl =
707 InsetQuotes::EnglishQ;
710 tmpl = InsetQuotes::EnglishQ;
713 tmpl = InsetQuotes::SwedishQ;
716 tmpl = InsetQuotes::GermanQ;
719 tmpl = InsetQuotes::PolishQ;
722 tmpl = InsetQuotes::FrenchQ;
725 tmpl = InsetQuotes::DanishQ;
728 params.quotes_language = tmpl;
729 } else if (token == "\\quotes_times") {
731 switch (lex.getInteger()) {
733 params.quotes_times = InsetQuotes::SingleQ;
736 params.quotes_times = InsetQuotes::DoubleQ;
739 } else if (token == "\\papersize") {
740 int tmpret = lex.findToken(string_papersize);
744 params.papersize2 = tmpret;
745 } else if (token == "\\paperpackage") {
746 int tmpret = lex.findToken(string_paperpackages);
749 params.paperpackage = BufferParams::PACKAGE_NONE;
751 params.paperpackage = tmpret;
752 } else if (token == "\\use_geometry") {
754 params.use_geometry = lex.getInteger();
755 } else if (token == "\\use_amsmath") {
757 params.use_amsmath = lex.getInteger();
758 } else if (token == "\\use_natbib") {
760 params.use_natbib = lex.getInteger();
761 } else if (token == "\\use_numerical_citations") {
763 params.use_numerical_citations = lex.getInteger();
764 } else if (token == "\\tracking_changes") {
766 params.tracking_changes = lex.getInteger();
767 // mark the first paragraph
768 if (params.tracking_changes)
770 } else if (token == "\\author") {
772 istringstream ss(lex.getString());
775 int aid(authorlist.record(a));
776 lyxerr << "aid is " << aid << endl;
777 lyxerr << "listed aid is " << author_ids.size() << endl;
778 author_ids.push_back(authorlist.record(a));
779 } else if (token == "\\paperorientation") {
780 int tmpret = lex.findToken(string_orientation);
784 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
785 } else if (token == "\\paperwidth") {
787 params.paperwidth = lex.getString();
788 } else if (token == "\\paperheight") {
790 params.paperheight = lex.getString();
791 } else if (token == "\\leftmargin") {
793 params.leftmargin = lex.getString();
794 } else if (token == "\\topmargin") {
796 params.topmargin = lex.getString();
797 } else if (token == "\\rightmargin") {
799 params.rightmargin = lex.getString();
800 } else if (token == "\\bottommargin") {
802 params.bottommargin = lex.getString();
803 } else if (token == "\\headheight") {
805 params.headheight = lex.getString();
806 } else if (token == "\\headsep") {
808 params.headsep = lex.getString();
809 } else if (token == "\\footskip") {
811 params.footskip = lex.getString();
812 } else if (token == "\\paperfontsize") {
814 params.fontsize = rtrim(lex.getString());
815 } else if (token == "\\papercolumns") {
817 params.columns = lex.getInteger();
818 } else if (token == "\\papersides") {
820 switch (lex.getInteger()) {
822 case 1: params.sides = LyXTextClass::OneSide; break;
823 case 2: params.sides = LyXTextClass::TwoSides; break;
825 } else if (token == "\\paperpagestyle") {
827 params.pagestyle = rtrim(lex.getString());
828 } else if (token == "\\bullet") {
830 int const index = lex.getInteger();
832 int temp_int = lex.getInteger();
833 params.user_defined_bullets[index].setFont(temp_int);
834 params.temp_bullets[index].setFont(temp_int);
836 temp_int = lex.getInteger();
837 params.user_defined_bullets[index].setCharacter(temp_int);
838 params.temp_bullets[index].setCharacter(temp_int);
840 temp_int = lex.getInteger();
841 params.user_defined_bullets[index].setSize(temp_int);
842 params.temp_bullets[index].setSize(temp_int);
844 string const temp_str = lex.getString();
845 if (temp_str != "\\end_bullet") {
846 // this element isn't really necessary for
847 // parsing but is easier for humans
848 // to understand bullets. Put it back and
849 // set a debug message?
850 lex.printError("\\end_bullet expected, got" + temp_str);
851 //how can I put it back?
853 } else if (token == "\\bulletLaTeX") {
854 // The bullet class should be able to read this.
856 int const index = lex.getInteger();
858 string temp_str = lex.getString();
860 while (temp_str != "\\end_bullet") {
861 // this loop structure is needed when user
862 // enters an empty string since the first
863 // thing returned will be the \\end_bullet
865 // if the LaTeX entry has spaces. Each element
866 // therefore needs to be read in turn
869 temp_str = lex.getString();
872 params.user_defined_bullets[index].setText(sum_str);
873 params.temp_bullets[index].setText(sum_str);
874 } else if (token == "\\secnumdepth") {
876 params.secnumdepth = lex.getInteger();
877 } else if (token == "\\tocdepth") {
879 params.tocdepth = lex.getInteger();
880 } else if (token == "\\spacing") {
882 string const tmp = rtrim(lex.getString());
883 Spacing::Space tmp_space = Spacing::Default;
885 if (tmp == "single") {
886 tmp_space = Spacing::Single;
887 } else if (tmp == "onehalf") {
888 tmp_space = Spacing::Onehalf;
889 } else if (tmp == "double") {
890 tmp_space = Spacing::Double;
891 } else if (tmp == "other") {
893 tmp_space = Spacing::Other;
894 tmp_val = lex.getFloat();
896 lex.printError("Unknown spacing token: '$$Token'");
898 // Small hack so that files written with klyx will be
901 par->params().spacing(Spacing(tmp_space, tmp_val));
903 params.spacing.set(tmp_space, tmp_val);
905 } else if (token == "\\paragraph_spacing") {
907 string const tmp = rtrim(lex.getString());
908 if (tmp == "single") {
909 par->params().spacing(Spacing(Spacing::Single));
910 } else if (tmp == "onehalf") {
911 par->params().spacing(Spacing(Spacing::Onehalf));
912 } else if (tmp == "double") {
913 par->params().spacing(Spacing(Spacing::Double));
914 } else if (tmp == "other") {
916 par->params().spacing(Spacing(Spacing::Other,
919 lex.printError("Unknown spacing token: '$$Token'");
921 } else if (token == "\\float_placement") {
923 params.float_placement = lex.getString();
924 } else if (token == "\\align") {
925 int tmpret = lex.findToken(string_align);
928 int const tmpret2 = int(pow(2.0, tmpret));
929 par->params().align(LyXAlignment(tmpret2));
930 } else if (token == "\\added_space_top") {
932 VSpace value = VSpace(lex.getString());
933 // only add the length when value > 0 or
935 if ((value.length().len().value() != 0) ||
937 (value.kind() != VSpace::LENGTH))
938 par->params().spaceTop(value);
939 } else if (token == "\\added_space_bottom") {
941 VSpace value = VSpace(lex.getString());
942 // only add the length when value > 0 or
944 if ((value.length().len().value() != 0) ||
946 (value.kind() != VSpace::LENGTH))
947 par->params().spaceBottom(value);
948 } else if (token == "\\labelwidthstring") {
950 par->params().labelWidthString(lex.getString());
951 // do not delete this token, it is still needed!
952 } else if (token == "\\newline") {
953 par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
955 } else if (token == "\\LyXTable") {
956 Inset * inset = new InsetTabular(*this);
957 inset->read(this, lex);
958 par->insertInset(pos, inset, font, current_change);
960 } else if (token == "\\bibitem") { // ale970302
961 InsetCommandParams p("bibitem", "dummy");
962 InsetBibitem * inset = new InsetBibitem(p);
963 inset->read(this, lex);
964 par->insertInset(pos, inset, font, current_change);
966 } else if (token == "\\hfill") {
967 par->insertChar(pos, Paragraph::META_HFILL, font, current_change);
969 } else if (token == "\\change_unchanged") {
970 // Hack ! Needed for empty paragraphs :/
973 current_change = Change(Change::UNCHANGED);
974 } else if (token == "\\change_inserted") {
976 istringstream istr(lex.getString());
981 current_change = Change(Change::INSERTED, author_ids[aid], ct);
982 } else if (token == "\\change_deleted") {
984 istringstream istr(lex.getString());
989 current_change = Change(Change::DELETED, author_ids[aid], ct);
990 } else if (token == "\\the_end") {
993 // This should be insurance for the future: (Asger)
997 boost::format fmt(_("Unknown token: %1$s %2$s\n"));
998 fmt % token % lex.text();
999 string const s = fmt.str();
1001 string const s = _("Unknown token: ") + token
1002 + ' ' + lex.text() + '\n';
1004 // we can do this here this way because we're actually reading
1005 // the buffer and don't care about LyXText right now.
1006 InsetError * new_inset = new InsetError(s);
1007 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1012 return the_end_read;
1016 // needed to insert the selection
1017 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1018 LyXFont const & fn,string const & str)
1020 LyXLayout_ptr const & layout = par->layout();
1024 par->checkInsertChar(font);
1025 // insert the string, don't insert doublespace
1026 bool space_inserted = true;
1027 bool autobreakrows = !par->inInset() ||
1028 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1029 for(string::const_iterator cit = str.begin();
1030 cit != str.end(); ++cit) {
1032 if (autobreakrows && (!par->empty() || layout->keepempty)) {
1033 breakParagraph(this, par, pos,
1034 layout->isEnvironment());
1037 space_inserted = true;
1041 // do not insert consecutive spaces if !free_spacing
1042 } else if ((*cit == ' ' || *cit == '\t') &&
1043 space_inserted && !layout->free_spacing &&
1044 !par->isFreeSpacing())
1047 } else if (*cit == '\t') {
1048 if (!layout->free_spacing && !par->isFreeSpacing()) {
1049 // tabs are like spaces here
1050 par->insertChar(pos, ' ', font, current_change);
1052 space_inserted = true;
1054 const pos_type nb = 8 - pos % 8;
1055 for (pos_type a = 0; a < nb ; ++a) {
1056 par->insertChar(pos, ' ', font, current_change);
1059 space_inserted = true;
1061 } else if (!IsPrintable(*cit)) {
1062 // Ignore unprintables
1065 // just insert the character
1066 par->insertChar(pos, *cit, font);
1068 space_inserted = (*cit == ' ');
1075 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1076 int & pos, LyXFont & font)
1078 // consistency check
1079 if (lex.getString() != "\\begin_inset") {
1080 lyxerr << "Buffer::readInset: Consistency check failed."
1087 string const tmptok = lex.getString();
1088 last_inset_read = tmptok;
1090 // test the different insets
1091 if (tmptok == "LatexCommand") {
1092 InsetCommandParams inscmd;
1095 string const cmdName = inscmd.getCmdName();
1097 // This strange command allows LyX to recognize "natbib" style
1098 // citations: citet, citep, Citet etc.
1099 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1100 inset = new InsetCitation(inscmd);
1101 } else if (cmdName == "bibitem") {
1102 lex.printError("Wrong place for bibitem");
1103 inset = new InsetBibitem(inscmd);
1104 } else if (cmdName == "BibTeX") {
1105 inset = new InsetBibtex(inscmd);
1106 } else if (cmdName == "index") {
1107 inset = new InsetIndex(inscmd);
1108 } else if (cmdName == "include") {
1109 inset = new InsetInclude(inscmd, *this);
1110 } else if (cmdName == "label") {
1111 inset = new InsetLabel(inscmd);
1112 } else if (cmdName == "url"
1113 || cmdName == "htmlurl") {
1114 inset = new InsetUrl(inscmd);
1115 } else if (cmdName == "ref"
1116 || cmdName == "pageref"
1117 || cmdName == "vref"
1118 || cmdName == "vpageref"
1119 || cmdName == "prettyref") {
1120 if (!inscmd.getOptions().empty()
1121 || !inscmd.getContents().empty()) {
1122 inset = new InsetRef(inscmd, *this);
1124 } else if (cmdName == "tableofcontents") {
1125 inset = new InsetTOC(inscmd);
1126 } else if (cmdName == "listofalgorithms") {
1127 inset = new InsetFloatList("algorithm");
1128 } else if (cmdName == "listoffigures") {
1129 inset = new InsetFloatList("figure");
1130 } else if (cmdName == "listoftables") {
1131 inset = new InsetFloatList("table");
1132 } else if (cmdName == "printindex") {
1133 inset = new InsetPrintIndex(inscmd);
1134 } else if (cmdName == "lyxparent") {
1135 inset = new InsetParent(inscmd, *this);
1138 if (tmptok == "Quotes") {
1139 inset = new InsetQuotes;
1140 } else if (tmptok == "External") {
1141 inset = new InsetExternal;
1142 } else if (tmptok == "FormulaMacro") {
1143 inset = new InsetFormulaMacro;
1144 } else if (tmptok == "Formula") {
1145 inset = new InsetFormula;
1146 } else if (tmptok == "Graphics") {
1147 inset = new InsetGraphics;
1148 } else if (tmptok == "Note") {
1149 inset = new InsetNote(params);
1150 } else if (tmptok == "Include") {
1151 InsetCommandParams p("Include");
1152 inset = new InsetInclude(p, *this);
1153 } else if (tmptok == "ERT") {
1154 inset = new InsetERT(params);
1155 } else if (tmptok == "Tabular") {
1156 inset = new InsetTabular(*this);
1157 } else if (tmptok == "Text") {
1158 inset = new InsetText(params);
1159 } else if (tmptok == "Foot") {
1160 inset = new InsetFoot(params);
1161 } else if (tmptok == "Marginal") {
1162 inset = new InsetMarginal(params);
1163 } else if (tmptok == "OptArg") {
1164 inset = new InsetOptArg(params);
1165 } else if (tmptok == "Minipage") {
1166 inset = new InsetMinipage(params);
1167 } else if (tmptok == "Float") {
1169 string tmptok = lex.getString();
1170 inset = new InsetFloat(params, tmptok);
1171 } else if (tmptok == "Wrap") {
1173 string tmptok = lex.getString();
1174 inset = new InsetWrap(params, tmptok);
1176 } else if (tmptok == "List") {
1177 inset = new InsetList;
1178 } else if (tmptok == "Theorem") {
1179 inset = new InsetList;
1181 } else if (tmptok == "Caption") {
1182 inset = new InsetCaption(params);
1183 } else if (tmptok == "FloatList") {
1184 inset = new InsetFloatList;
1188 inset->read(this, lex);
1192 par->insertInset(pos, inset, font, current_change);
1198 bool Buffer::readFile(LyXLex & lex, string const & filename, Paragraph * par)
1202 string const token(lex.getString());
1203 if (token == "\\lyxformat") { // the first token _must_ be...
1205 string tmp_format = lex.getString();
1206 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
1207 // if present remove ".," from string.
1208 string::size_type dot = tmp_format.find_first_of(".,");
1209 //lyxerr << " dot found at " << dot << endl;
1210 if (dot != string::npos)
1211 tmp_format.erase(dot, 1);
1212 file_format = strToInt(tmp_format);
1213 //lyxerr << "format: " << file_format << endl;
1214 if (file_format == LYX_FORMAT) {
1216 } else if (file_format > LYX_FORMAT) {
1218 Alert::alert(_("Warning!"),
1219 _("The file was created with a newer version of "
1220 "LyX. This is likely to cause problems."));
1222 } else if (file_format < LYX_FORMAT) {
1224 if (file_format < 200) {
1225 Alert::alert(_("ERROR!"),
1226 _("Old LyX file format found. "
1227 "Use LyX 0.10.x to read this!"));
1229 } else if (!filename.empty()) {
1231 LibFileSearch("lyx2lyx", "lyx2lyx");
1232 if (command.empty()) {
1233 Alert::alert(_("ERROR!"),
1234 _("Can't find conversion script."));
1238 +tostr(LYX_FORMAT) + ' '
1239 + QuoteName(filename);
1240 lyxerr[Debug::INFO] << "Running '"
1243 cmd_ret const ret = RunCommand(command);
1245 Alert::alert(_("ERROR!"),
1246 _("An error occured while "
1247 "running the conversion script."));
1250 istringstream is(STRCONV(ret.second));
1251 LyXLex tmplex(0, 0);
1252 tmplex.setStream(is);
1253 return readFile(tmplex, string(), par);
1255 // This code is reached if lyx2lyx failed (for
1256 // some reason) to change the file format of
1262 bool the_end = readLyXformat2(lex, par);
1263 params.setPaperStuff();
1266 Alert::alert(_("Warning!"),
1267 _("Reading of document is not complete"),
1268 _("Maybe the document is truncated"));
1271 } else { // "\\lyxformat" not found
1272 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1275 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1280 // Should probably be moved to somewhere else: BufferView? LyXView?
1281 bool Buffer::save() const
1283 // We don't need autosaves in the immediate future. (Asger)
1284 resetAutosaveTimers();
1288 if (lyxrc.make_backup) {
1289 s = fileName() + '~';
1290 if (!lyxrc.backupdir_path.empty())
1291 s = AddName(lyxrc.backupdir_path,
1292 subst(os::slashify_path(s),'/','!'));
1294 // Rename is the wrong way of making a backup,
1295 // this is the correct way.
1296 /* truss cp fil fil2:
1297 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1298 stat("LyXVC.lyx", 0xEFFFF688) = 0
1299 open("LyXVC.lyx", O_RDONLY) = 3
1300 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1301 fstat(4, 0xEFFFF508) = 0
1302 fstat(3, 0xEFFFF508) = 0
1303 read(3, " # T h i s f i l e w".., 8192) = 5579
1304 write(4, " # T h i s f i l e w".., 5579) = 5579
1305 read(3, 0xEFFFD4A0, 8192) = 0
1308 chmod("LyXVC3.lyx", 0100644) = 0
1309 lseek(0, 0, SEEK_CUR) = 46440
1313 // Should probably have some more error checking here.
1314 // Doing it this way, also makes the inodes stay the same.
1315 // This is still not a very good solution, in particular we
1316 // might loose the owner of the backup.
1317 FileInfo finfo(fileName());
1318 if (finfo.exist()) {
1319 mode_t fmode = finfo.getMode();
1320 struct utimbuf times = {
1321 finfo.getAccessTime(),
1322 finfo.getModificationTime() };
1324 ifstream ifs(fileName().c_str());
1325 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1330 ::chmod(s.c_str(), fmode);
1332 if (::utime(s.c_str(), ×)) {
1333 lyxerr << "utime error." << endl;
1336 lyxerr << "LyX was not able to make "
1337 "backup copy. Beware." << endl;
1342 if (writeFile(fileName())) {
1344 removeAutosaveFile(fileName());
1346 // Saving failed, so backup is not backup
1347 if (lyxrc.make_backup) {
1348 lyx::rename(s, fileName());
1356 bool Buffer::writeFile(string const & fname) const
1358 if (read_only && (fname == fileName())) {
1362 FileInfo finfo(fname);
1363 if (finfo.exist() && !finfo.writable()) {
1367 ofstream ofs(fname.c_str());
1373 // Use the standard "C" locale for file output.
1374 ofs.imbue(std::locale::classic());
1377 // The top of the file should not be written by params.
1379 // write out a comment in the top of the file
1380 ofs << '#' << lyx_docversion
1381 << " created this file. For more info see http://www.lyx.org/\n"
1382 << "\\lyxformat " << LYX_FORMAT << "\n";
1384 // now write out the buffer paramters.
1385 params.writeFile(ofs);
1387 // if we're tracking, list all possible authors
1388 if (params.tracking_changes) {
1389 AuthorList::Authors::const_iterator it = authorlist.begin();
1390 AuthorList::Authors::const_iterator end = authorlist.end();
1391 for (; it != end; ++it) {
1392 ofs << "\\author " << it->second << "\n";
1396 Paragraph::depth_type depth = 0;
1398 // this will write out all the paragraphs
1399 // using recursive descent.
1400 ParagraphList::iterator pit = paragraphs.begin();
1401 ParagraphList::iterator pend = paragraphs.end();
1402 for (; pit != pend; ++pit)
1403 pit->write(this, ofs, params, depth);
1405 // Write marker that shows file is complete
1406 ofs << "\n\\the_end" << endl;
1410 // how to check if close went ok?
1411 // Following is an attempt... (BE 20001011)
1413 // good() returns false if any error occured, including some
1414 // formatting error.
1415 // bad() returns true if something bad happened in the buffer,
1416 // which should include file system full errors.
1423 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1425 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1437 pair<int, string> const addDepth(int depth, int ldepth)
1441 d += (ldepth - depth) * 2;
1442 return make_pair(d, string(d, ' '));
1448 string const Buffer::asciiParagraph(Paragraph const & par,
1449 unsigned int linelen,
1450 bool noparbreak) const
1452 ostringstream buffer;
1453 Paragraph::depth_type depth = 0;
1455 Paragraph::depth_type ltype_depth = 0;
1456 bool ref_printed = false;
1457 // if (!par->previous()) {
1459 // begins or ends a deeper area ?
1460 if (depth != par->params().depth()) {
1461 if (par->params().depth() > depth) {
1462 while (par->params().depth() > depth) {
1466 while (par->params().depth() < depth) {
1472 depth = par.params().depth();
1475 // First write the layout
1476 string const & tmp = par.layout()->name();
1477 if (compare_no_case(tmp, "itemize") == 0) {
1479 ltype_depth = depth + 1;
1480 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1482 ltype_depth = depth + 1;
1483 } else if (contains(ascii_lowercase(tmp), "ection")) {
1485 ltype_depth = depth + 1;
1486 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1488 ltype_depth = depth + 1;
1489 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1491 ltype_depth = depth + 1;
1492 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1495 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1503 /* maybe some vertical spaces */
1505 /* the labelwidthstring used in lists */
1509 /* some pagebreaks? */
1513 /* what about the alignment */
1515 // lyxerr << "Should this ever happen?" << endl;
1518 // linelen <= 0 is special and means we don't have paragraph breaks
1520 string::size_type currlinelen = 0;
1526 buffer << string(depth * 2, ' ');
1527 currlinelen += depth * 2;
1530 // we should probably change to the paragraph language in the
1531 // gettext here (if possible) so that strings are outputted in
1532 // the correct language! (20012712 Jug)
1536 case 4: // (Sub)Paragraph
1537 case 5: // Description
1541 buffer << _("Abstract") << "\n\n";
1544 string const abst = _("Abstract: ");
1546 currlinelen += abst.length();
1549 case 7: // Bibliography
1552 buffer << _("References") << "\n\n";
1555 string const refs = _("References: ");
1557 currlinelen += refs.length();
1565 string const parlab = par.params().labelString();
1566 buffer << parlab << ' ';
1567 currlinelen += parlab.length() + 1;
1575 pair<int, string> p = addDepth(depth, ltype_depth);
1577 currlinelen += p.first;
1580 // this is to change the linebreak to do it by word a bit more
1581 // intelligent hopefully! (only in the case where we have a
1582 // max linelength!) (Jug)
1586 for (pos_type i = 0; i < par.size(); ++i) {
1587 char c = par.getUChar(params, i);
1589 case Paragraph::META_INSET:
1591 Inset const * inset = par.getInset(i);
1595 currlinelen += word.length();
1598 if (inset->ascii(this, buffer, linelen)) {
1599 // to be sure it breaks paragraph
1600 currlinelen += linelen;
1606 case Paragraph::META_NEWLINE:
1608 buffer << word << "\n";
1611 pair<int, string> p = addDepth(depth,
1614 currlinelen = p.first;
1618 case Paragraph::META_HFILL:
1619 buffer << word << "\t";
1620 currlinelen += word.length() + 1;
1627 currlinelen + word.length() > linelen - 10) {
1629 pair<int, string> p =
1630 addDepth(depth, ltype_depth);
1632 currlinelen = p.first;
1635 buffer << word << ' ';
1636 currlinelen += word.length() + 1;
1643 lyxerr[Debug::INFO] <<
1644 "writeAsciiFile: NULL char in structure." << endl;
1646 if ((linelen > 0) &&
1647 (currlinelen + word.length()) > linelen)
1651 pair<int, string> p =
1652 addDepth(depth, ltype_depth);
1654 currlinelen = p.first;
1661 return STRCONV(buffer.str());
1665 void Buffer::writeFileAscii(string const & fname, int linelen)
1667 ofstream ofs(fname.c_str());
1669 Alert::err_alert(_("Error: Cannot write file:"), fname);
1672 writeFileAscii(ofs, linelen);
1676 void Buffer::writeFileAscii(ostream & os, int linelen)
1678 ParagraphList::iterator beg = paragraphs.begin();
1679 ParagraphList::iterator end = paragraphs.end();
1680 ParagraphList::iterator it = beg;
1681 for (; it != end; ++it) {
1682 os << asciiParagraph(*it, linelen, it == beg);
1689 void Buffer::makeLaTeXFile(string const & fname,
1690 string const & original_path,
1691 bool nice, bool only_body, bool only_preamble)
1693 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1695 ofstream ofs(fname.c_str());
1697 Alert::err_alert(_("Error: Cannot open file: "), fname);
1701 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1705 lyxerr << "File was not closed properly." << endl;
1710 void Buffer::makeLaTeXFile(ostream & os,
1711 string const & original_path,
1712 bool nice, bool only_body, bool only_preamble)
1714 niceFile = nice; // this will be used by Insetincludes.
1716 // validate the buffer.
1717 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1718 LaTeXFeatures features(params);
1720 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1723 // The starting paragraph of the coming rows is the
1724 // first paragraph of the document. (Asger)
1725 texrow.start(&*(paragraphs.begin()), 0);
1727 if (!only_body && nice) {
1728 os << "%% " << lyx_docversion << " created this file. "
1729 "For more info, see http://www.lyx.org/.\n"
1730 "%% Do not edit unless you really know what "
1735 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1736 // There are a few differences between nice LaTeX and usual files:
1737 // usual is \batchmode and has a
1738 // special input@path to allow the including of figures
1739 // with either \input or \includegraphics (what figinsets do).
1740 // input@path is set when the actual parameter
1741 // original_path is set. This is done for usual tex-file, but not
1742 // for nice-latex-file. (Matthias 250696)
1745 // code for usual, NOT nice-latex-file
1746 os << "\\batchmode\n"; // changed
1747 // from \nonstopmode
1750 if (!original_path.empty()) {
1751 string inputpath = os::external_path(original_path);
1752 subst(inputpath, "~", "\\string~");
1753 os << "\\makeatletter\n"
1754 << "\\def\\input@path{{"
1755 << inputpath << "/}}\n"
1756 << "\\makeatother\n";
1762 // Write the preamble
1763 params.writeLaTeX(os, features, texrow);
1769 os << "\\begin{document}\n";
1772 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1774 if (!lyxrc.language_auto_begin) {
1775 os << subst(lyxrc.language_command_begin, "$$lang",
1776 params.language->babel())
1781 latexParagraphs(os, paragraphs.begin(), paragraphs.end(), texrow);
1783 // add this just in case after all the paragraphs
1787 if (!lyxrc.language_auto_end) {
1788 os << subst(lyxrc.language_command_end, "$$lang",
1789 params.language->babel())
1795 os << "\\end{document}\n";
1798 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1800 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1804 // Just to be sure. (Asger)
1807 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1808 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1811 // we want this to be true outside previews (for insetexternal)
1817 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
1819 void Buffer::latexParagraphs(ostream & ofs,
1820 ParagraphList::iterator par,
1821 ParagraphList::iterator endpar,
1823 bool moving_arg) const
1825 bool was_title = false;
1826 bool already_title = false;
1827 LyXTextClass const & tclass = params.getLyXTextClass();
1830 while (par != endpar) {
1831 Inset * in = par->inInset();
1832 // well we have to check if we are in an inset with unlimited
1833 // length (all in one row) if that is true then we don't allow
1834 // any special options in the paragraph and also we don't allow
1835 // any environment other then "Standard" to be valid!
1836 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1837 LyXLayout_ptr const & layout = par->layout();
1839 if (layout->intitle) {
1840 if (already_title) {
1841 lyxerr <<"Error in latexParagraphs: You"
1842 " should not mix title layouts"
1843 " with normal ones." << endl;
1844 } else if (!was_title) {
1846 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1848 << tclass.titlename()
1853 } else if (was_title && !already_title) {
1854 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1855 ofs << "\\end{" << tclass.titlename()
1859 ofs << "\\" << tclass.titlename()
1863 already_title = true;
1867 if (layout->isEnvironment() ||
1868 !par->params().leftIndent().zero())
1870 par = TeXEnvironment(this, params, par, ofs, texrow);
1872 par = TeXOnePar(this, params, par, ofs, texrow, moving_arg);
1875 par = TeXOnePar(this, params, par, ofs, texrow, moving_arg);
1878 // It might be that we only have a title in this document
1879 if (was_title && !already_title) {
1880 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1881 ofs << "\\end{" << tclass.titlename()
1885 ofs << "\\" << tclass.titlename()
1893 bool Buffer::isLatex() const
1895 return params.getLyXTextClass().outputType() == LATEX;
1899 bool Buffer::isLinuxDoc() const
1901 return params.getLyXTextClass().outputType() == LINUXDOC;
1905 bool Buffer::isLiterate() const
1907 return params.getLyXTextClass().outputType() == LITERATE;
1911 bool Buffer::isDocBook() const
1913 return params.getLyXTextClass().outputType() == DOCBOOK;
1917 bool Buffer::isSGML() const
1919 LyXTextClass const & tclass = params.getLyXTextClass();
1921 return tclass.outputType() == LINUXDOC ||
1922 tclass.outputType() == DOCBOOK;
1926 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1928 ofstream ofs(fname.c_str());
1931 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1935 niceFile = nice; // this will be used by included files.
1937 LaTeXFeatures features(params);
1943 LyXTextClass const & tclass = params.getLyXTextClass();
1945 string top_element = tclass.latexname();
1948 ofs << "<!doctype linuxdoc system";
1950 string preamble = params.preamble;
1951 const string name = nice ? ChangeExtension(filename_, ".sgml")
1953 preamble += features.getIncludedFiles(name);
1954 preamble += features.getLyXSGMLEntities();
1956 if (!preamble.empty()) {
1957 ofs << " [ " << preamble << " ]";
1961 if (params.options.empty())
1962 sgml::openTag(ofs, 0, false, top_element);
1964 string top = top_element;
1966 top += params.options;
1967 sgml::openTag(ofs, 0, false, top);
1971 ofs << "<!-- " << lyx_docversion
1972 << " created this file. For more info see http://www.lyx.org/"
1975 Paragraph::depth_type depth = 0; // paragraph depth
1976 Paragraph * par = &*(paragraphs.begin());
1978 vector<string> environment_stack(5);
1981 LyXLayout_ptr const & style = par->layout();
1982 // treat <toc> as a special case for compatibility with old code
1983 if (par->isInset(0)) {
1984 Inset * inset = par->getInset(0);
1985 Inset::Code lyx_code = inset->lyxCode();
1986 if (lyx_code == Inset::TOC_CODE) {
1987 string const temp = "toc";
1988 sgml::openTag(ofs, depth, false, temp);
1995 // environment tag closing
1996 for (; depth > par->params().depth(); --depth) {
1997 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1998 environment_stack[depth].erase();
2001 // write opening SGML tags
2002 switch (style->latextype) {
2003 case LATEX_PARAGRAPH:
2004 if (depth == par->params().depth()
2005 && !environment_stack[depth].empty()) {
2006 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2007 environment_stack[depth].erase();
2013 sgml::openTag(ofs, depth, false, style->latexname());
2019 _("Error: Wrong depth for LatexType Command.\n"));
2021 if (!environment_stack[depth].empty()) {
2022 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2026 environment_stack[depth].erase();
2027 sgml::openTag(ofs, depth, false, style->latexname());
2030 case LATEX_ENVIRONMENT:
2031 case LATEX_ITEM_ENVIRONMENT:
2032 case LATEX_BIB_ENVIRONMENT:
2034 string const & latexname = style->latexname();
2036 if (depth == par->params().depth()
2037 && environment_stack[depth] != latexname) {
2038 sgml::closeTag(ofs, depth, false,
2039 environment_stack[depth]);
2040 environment_stack[depth].erase();
2042 if (depth < par->params().depth()) {
2043 depth = par->params().depth();
2044 environment_stack[depth].erase();
2046 if (environment_stack[depth] != latexname) {
2048 sgml::openTag(ofs, depth, false, "p");
2050 sgml::openTag(ofs, depth, false, latexname);
2052 if (environment_stack.size() == depth + 1)
2053 environment_stack.push_back("!-- --");
2054 environment_stack[depth] = latexname;
2057 if (style->latexparam() == "CDATA")
2060 if (style->latextype == LATEX_ENVIRONMENT) break;
2062 if (style->labeltype == LABEL_MANUAL)
2067 sgml::openTag(ofs, depth + 1, false, item_name);
2072 sgml::openTag(ofs, depth, false, style->latexname());
2076 simpleLinuxDocOnePar(ofs, par, depth);
2081 // write closing SGML tags
2082 switch (style->latextype) {
2085 case LATEX_ENVIRONMENT:
2086 case LATEX_ITEM_ENVIRONMENT:
2087 case LATEX_BIB_ENVIRONMENT:
2088 if (style->latexparam() == "CDATA")
2092 sgml::closeTag(ofs, depth, false, style->latexname());
2098 for (int i = depth; i >= 0; --i)
2099 sgml::closeTag(ofs, depth, false, environment_stack[i]);
2103 sgml::closeTag(ofs, 0, false, top_element);
2107 // How to check for successful close
2109 // we want this to be true outside previews (for insetexternal)
2114 // checks, if newcol chars should be put into this line
2115 // writes newline, if necessary.
2118 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2119 string::size_type newcol)
2122 if (colcount > lyxrc.ascii_linelen) {
2124 colcount = newcol; // assume write after this call
2139 string tag_name(PAR_TAG const & pt) {
2141 case NONE: return "!-- --";
2142 case TT: return "tt";
2143 case SF: return "sf";
2144 case BF: return "bf";
2145 case IT: return "it";
2146 case SL: return "sl";
2147 case EM: return "em";
2154 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2156 p1 = static_cast<PAR_TAG>(p1 | p2);
2161 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2163 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2169 // Handle internal paragraph parsing -- layout already processed.
2170 void Buffer::simpleLinuxDocOnePar(ostream & os,
2172 Paragraph::depth_type /*depth*/)
2174 LyXLayout_ptr const & style = par->layout();
2176 string::size_type char_line_count = 5; // Heuristic choice ;-)
2178 // gets paragraph main font
2181 if (style->labeltype == LABEL_MANUAL) {
2182 font_old = style->labelfont;
2185 font_old = style->font;
2189 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2190 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2191 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2194 stack<PAR_TAG> tag_state;
2195 // parsing main loop
2196 for (pos_type i = 0; i < par->size(); ++i) {
2198 PAR_TAG tag_close = NONE;
2199 list < PAR_TAG > tag_open;
2201 LyXFont const font = par->getFont(params, i);
2203 if (font_old.family() != font.family()) {
2204 switch (family_type) {
2205 case LyXFont::SANS_FAMILY:
2208 case LyXFont::TYPEWRITER_FAMILY:
2215 family_type = font.family();
2217 switch (family_type) {
2218 case LyXFont::SANS_FAMILY:
2219 tag_open.push_back(SF);
2221 case LyXFont::TYPEWRITER_FAMILY:
2222 tag_open.push_back(TT);
2229 if (font_old.series() != font.series()) {
2230 switch (series_type) {
2231 case LyXFont::BOLD_SERIES:
2238 series_type = font.series();
2240 switch (series_type) {
2241 case LyXFont::BOLD_SERIES:
2242 tag_open.push_back(BF);
2250 if (font_old.shape() != font.shape()) {
2251 switch (shape_type) {
2252 case LyXFont::ITALIC_SHAPE:
2255 case LyXFont::SLANTED_SHAPE:
2262 shape_type = font.shape();
2264 switch (shape_type) {
2265 case LyXFont::ITALIC_SHAPE:
2266 tag_open.push_back(IT);
2268 case LyXFont::SLANTED_SHAPE:
2269 tag_open.push_back(SL);
2276 if (font_old.emph() != font.emph()) {
2277 if (font.emph() == LyXFont::ON) {
2278 tag_open.push_back(EM);
2287 list < PAR_TAG > temp;
2288 while (!tag_state.empty() && tag_close) {
2289 PAR_TAG k = tag_state.top();
2291 os << "</" << tag_name(k) << '>';
2298 for(list< PAR_TAG >::const_iterator j = temp.begin();
2299 j != temp.end(); ++j) {
2301 os << '<' << tag_name(*j) << '>';
2304 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2305 j != tag_open.end(); ++j) {
2307 os << '<' << tag_name(*j) << '>';
2310 char c = par->getChar(i);
2312 if (c == Paragraph::META_INSET) {
2313 Inset * inset = par->getInset(i);
2314 inset->linuxdoc(this, os);
2319 if (style->latexparam() == "CDATA") {
2320 // "TeX"-Mode on == > SGML-Mode on.
2327 boost::tie(ws, str) = sgml::escapeChar(c);
2328 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
2329 // in freespacing mode, spaces are
2330 // non-breaking characters
2331 if (desc_on) {// if char is ' ' then...
2334 sgmlLineBreak(os, char_line_count, 6);
2338 sgmlLineBreak(os, char_line_count, 1);
2343 char_line_count += str.length();
2349 while (!tag_state.empty()) {
2350 os << "</" << tag_name(tag_state.top()) << '>';
2354 // resets description flag correctly
2356 // <tag> not closed...
2357 sgmlLineBreak(os, char_line_count, 6);
2363 // Print an error message.
2364 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
2365 string const & /*message*/) const
2367 #ifdef WITH_WARNINGS
2368 #warning This is wrong we cannot insert an inset like this!!!
2369 // I guess this was Jose' so I explain you more or less why this
2370 // is wrong. This way you insert something in the paragraph and
2371 // don't tell it to LyXText (row rebreaking and undo handling!!!)
2372 // I deactivate this code, have a look at BufferView::insertErrors
2373 // how you should do this correctly! (Jug 20020315)
2376 // insert an error marker in text
2377 InsetError * new_inset = new InsetError(message);
2378 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
2384 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2386 ofstream ofs(fname.c_str());
2388 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2392 Paragraph * par = &*(paragraphs.begin());
2394 niceFile = nice; // this will be used by Insetincludes.
2396 LaTeXFeatures features(params);
2401 LyXTextClass const & tclass = params.getLyXTextClass();
2402 string top_element = tclass.latexname();
2405 ofs << "<!DOCTYPE " << top_element
2406 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
2408 string preamble = params.preamble;
2409 const string name = nice ? ChangeExtension(filename_, ".sgml")
2411 preamble += features.getIncludedFiles(name);
2412 preamble += features.getLyXSGMLEntities();
2414 if (!preamble.empty()) {
2415 ofs << "\n [ " << preamble << " ]";
2420 string top = top_element;
2422 top += params.language->code();
2425 if (!params.options.empty()) {
2427 top += params.options;
2429 sgml::openTag(ofs, 0, false, top);
2431 ofs << "<!-- DocBook file was created by " << lyx_docversion
2432 << "\n See http://www.lyx.org/ for more information -->\n";
2434 vector<string> environment_stack(10);
2435 vector<string> environment_inner(10);
2436 vector<string> command_stack(10);
2438 bool command_flag = false;
2439 Paragraph::depth_type command_depth = 0;
2440 Paragraph::depth_type command_base = 0;
2441 Paragraph::depth_type cmd_depth = 0;
2442 Paragraph::depth_type depth = 0; // paragraph depth
2445 string command_name;
2451 int desc_on = 0; // description mode
2453 LyXLayout_ptr const & style = par->layout();
2455 // environment tag closing
2456 for (; depth > par->params().depth(); --depth) {
2457 if (environment_inner[depth] != "!-- --") {
2458 item_name = "listitem";
2459 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2460 if (environment_inner[depth] == "varlistentry")
2461 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
2463 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2464 environment_stack[depth].erase();
2465 environment_inner[depth].erase();
2468 if (depth == par->params().depth()
2469 && environment_stack[depth] != style->latexname()
2470 && !environment_stack[depth].empty()) {
2471 if (environment_inner[depth] != "!-- --") {
2472 item_name= "listitem";
2473 sgml::closeTag(ofs, command_depth+depth, false, item_name);
2474 if (environment_inner[depth] == "varlistentry")
2475 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2478 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2480 environment_stack[depth].erase();
2481 environment_inner[depth].erase();
2484 // Write opening SGML tags.
2485 switch (style->latextype) {
2486 case LATEX_PARAGRAPH:
2487 sgml::openTag(ofs, depth + command_depth,
2488 false, style->latexname());
2494 _("Error: Wrong depth for LatexType Command.\n"));
2496 command_name = style->latexname();
2498 sgmlparam = style->latexparam();
2499 c_params = split(sgmlparam, c_depth,'|');
2501 cmd_depth = lyx::atoi(c_depth);
2504 if (cmd_depth < command_base) {
2505 for (Paragraph::depth_type j = command_depth;
2506 j >= command_base; --j) {
2507 sgml::closeTag(ofs, j, false, command_stack[j]);
2510 command_depth = command_base = cmd_depth;
2511 } else if (cmd_depth <= command_depth) {
2512 for (int j = command_depth;
2513 j >= int(cmd_depth); --j) {
2514 sgml::closeTag(ofs, j, false, command_stack[j]);
2517 command_depth = cmd_depth;
2519 command_depth = cmd_depth;
2521 command_depth = command_base = cmd_depth;
2522 command_flag = true;
2524 if (command_stack.size() == command_depth + 1)
2525 command_stack.push_back(string());
2526 command_stack[command_depth] = command_name;
2528 // treat label as a special case for
2529 // more WYSIWYM handling.
2530 // This is a hack while paragraphs can't have
2531 // attributes, like id in this case.
2532 if (par->isInset(0)) {
2533 Inset * inset = par->getInset(0);
2534 Inset::Code lyx_code = inset->lyxCode();
2535 if (lyx_code == Inset::LABEL_CODE) {
2536 command_name += " id=\"";
2537 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2538 command_name += '"';
2543 sgml::openTag(ofs, depth + command_depth, false, command_name);
2545 item_name = c_params.empty() ? "title" : c_params;
2546 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
2549 case LATEX_ENVIRONMENT:
2550 case LATEX_ITEM_ENVIRONMENT:
2551 if (depth < par->params().depth()) {
2552 depth = par->params().depth();
2553 environment_stack[depth].erase();
2556 if (environment_stack[depth] != style->latexname()) {
2557 if (environment_stack.size() == depth + 1) {
2558 environment_stack.push_back("!-- --");
2559 environment_inner.push_back("!-- --");
2561 environment_stack[depth] = style->latexname();
2562 environment_inner[depth] = "!-- --";
2563 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
2565 if (environment_inner[depth] != "!-- --") {
2566 item_name= "listitem";
2567 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2568 if (environment_inner[depth] == "varlistentry")
2569 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2573 if (style->latextype == LATEX_ENVIRONMENT) {
2574 if (!style->latexparam().empty()) {
2575 if (style->latexparam() == "CDATA")
2578 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
2583 desc_on = (style->labeltype == LABEL_MANUAL);
2585 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
2586 sgml::openTag(ofs, depth + 1 + command_depth,
2587 false, environment_inner[depth]);
2589 item_name = desc_on ? "term" : "para";
2590 sgml::openTag(ofs, depth + 1 + command_depth,
2594 sgml::openTag(ofs, depth + command_depth,
2595 false, style->latexname());
2599 simpleDocBookOnePar(ofs, par, desc_on,
2600 depth + 1 + command_depth);
2604 // write closing SGML tags
2605 switch (style->latextype) {
2607 end_tag = c_params.empty() ? "title" : c_params;
2608 sgml::closeTag(ofs, depth + command_depth,
2611 case LATEX_ENVIRONMENT:
2612 if (!style->latexparam().empty()) {
2613 if (style->latexparam() == "CDATA")
2616 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
2619 case LATEX_ITEM_ENVIRONMENT:
2620 if (desc_on == 1) break;
2622 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
2624 case LATEX_PARAGRAPH:
2625 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2628 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2634 for (int d = depth; d >= 0; --d) {
2635 if (!environment_stack[depth].empty()) {
2636 if (environment_inner[depth] != "!-- --") {
2637 item_name = "listitem";
2638 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2639 if (environment_inner[depth] == "varlistentry")
2640 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2643 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2647 for (int j = command_depth; j >= 0 ; --j)
2648 if (!command_stack[j].empty()) {
2649 sgml::closeTag(ofs, j, false, command_stack[j]);
2654 sgml::closeTag(ofs, 0, false, top_element);
2657 // How to check for successful close
2659 // we want this to be true outside previews (for insetexternal)
2664 void Buffer::simpleDocBookOnePar(ostream & os,
2665 Paragraph * par, int & desc_on,
2666 Paragraph::depth_type depth) const
2668 bool emph_flag = false;
2670 LyXLayout_ptr const & style = par->layout();
2672 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
2674 int char_line_count = depth;
2675 //if (!style.free_spacing)
2676 // os << string(depth,' ');
2678 // parsing main loop
2679 for (pos_type i = 0; i < par->size(); ++i) {
2680 LyXFont font = par->getFont(params, i);
2682 // handle <emphasis> tag
2683 if (font_old.emph() != font.emph()) {
2684 if (font.emph() == LyXFont::ON) {
2685 if (style->latexparam() == "CDATA")
2688 if (style->latexparam() == "CDATA")
2692 if (style->latexparam() == "CDATA")
2694 os << "</emphasis>";
2695 if (style->latexparam() == "CDATA")
2702 if (par->isInset(i)) {
2703 Inset * inset = par->getInset(i);
2704 // don't print the inset in position 0 if desc_on == 3 (label)
2705 if (i || desc_on != 3) {
2706 if (style->latexparam() == "CDATA")
2708 inset->docbook(this, os, false);
2709 if (style->latexparam() == "CDATA")
2713 char c = par->getChar(i);
2716 boost::tie(ws, str) = sgml::escapeChar(c);
2718 if (style->pass_thru) {
2720 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
2722 } else if (desc_on ==1) {
2724 os << "\n</term><listitem><para>";
2734 if (style->latexparam() == "CDATA")
2736 os << "</emphasis>";
2737 if (style->latexparam() == "CDATA")
2741 // resets description flag correctly
2743 // <term> not closed...
2744 os << "</term>\n<listitem><para> </para>";
2746 if (style->free_spacing)
2751 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2752 // Other flags: -wall -v0 -x
2753 int Buffer::runChktex()
2755 if (!users->text) return 0;
2757 users->owner()->busy(true);
2759 // get LaTeX-Filename
2760 string const name = getLatexName();
2761 string path = filePath();
2763 string const org_path = path;
2764 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2768 Path p(path); // path to LaTeX file
2769 users->owner()->message(_("Running chktex..."));
2771 // Remove all error insets
2772 bool const removedErrorInsets = users->removeAutoInsets();
2774 // Generate the LaTeX file if neccessary
2775 makeLaTeXFile(name, org_path, false);
2778 Chktex chktex(lyxrc.chktex_command, name, filePath());
2779 int res = chktex.run(terr); // run chktex
2782 Alert::alert(_("chktex did not work!"),
2783 _("Could not run with file:"), name);
2784 } else if (res > 0) {
2785 // Insert all errors as errors boxes
2786 users->insertErrors(terr);
2789 // if we removed error insets before we ran chktex or if we inserted
2790 // error insets after we ran chktex, this must be run:
2791 if (removedErrorInsets || res) {
2792 #warning repaint needed here, or do you mean update() ?
2796 users->owner()->busy(false);
2802 void Buffer::validate(LaTeXFeatures & features) const
2804 LyXTextClass const & tclass = params.getLyXTextClass();
2806 if (params.tracking_changes) {
2807 features.require("dvipost");
2808 features.require("color");
2811 // AMS Style is at document level
2812 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
2813 features.require("amsmath");
2815 for_each(paragraphs.begin(), paragraphs.end(),
2816 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2818 // the bullet shapes are buffer level not paragraph level
2819 // so they are tested here
2820 for (int i = 0; i < 4; ++i) {
2821 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2822 int const font = params.user_defined_bullets[i].getFont();
2824 int const c = params
2825 .user_defined_bullets[i]
2832 features.require("latexsym");
2834 } else if (font == 1) {
2835 features.require("amssymb");
2836 } else if ((font >= 2 && font <= 5)) {
2837 features.require("pifont");
2842 if (lyxerr.debugging(Debug::LATEX)) {
2843 features.showStruct();
2848 vector<string> const Buffer::getLabelList() const
2850 /// if this is a child document and the parent is already loaded
2851 /// Use the parent's list instead [ale990407]
2852 if (!params.parentname.empty()
2853 && bufferlist.exists(params.parentname)) {
2854 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2856 return tmp->getLabelList();
2859 vector<string> label_list;
2860 for (inset_iterator it = inset_const_iterator_begin();
2861 it != inset_const_iterator_end(); ++it) {
2862 vector<string> const l = it->getLabelList();
2863 label_list.insert(label_list.end(), l.begin(), l.end());
2869 // This is also a buffer property (ale)
2870 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2872 /// if this is a child document and the parent is already loaded
2873 /// use the parent's list instead [ale990412]
2874 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2875 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2877 tmp->fillWithBibKeys(keys);
2882 for (inset_iterator it = inset_const_iterator_begin();
2883 it != inset_const_iterator_end(); ++it) {
2884 if (it->lyxCode() == Inset::BIBTEX_CODE)
2885 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2886 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2887 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2888 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2889 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2890 string const key = bib.getContents();
2891 string const opt = bib.getOptions();
2892 string const ref; // = pit->asString(this, false);
2893 string const info = opt + "TheBibliographyRef" + ref;
2894 keys.push_back(pair<string, string>(key, info));
2900 bool Buffer::isDepClean(string const & name) const
2902 DepClean::const_iterator it = dep_clean_.find(name);
2903 if (it == dep_clean_.end())
2909 void Buffer::markDepClean(string const & name)
2911 dep_clean_[name] = true;
2915 bool Buffer::dispatch(string const & command, bool * result)
2917 // Split command string into command and argument
2919 string line = ltrim(command);
2920 string const arg = trim(split(line, cmd, ' '));
2922 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2926 bool Buffer::dispatch(int action, string const & argument, bool * result)
2928 bool dispatched = true;
2932 bool const tmp = Exporter::Export(this, argument, false);
2945 void Buffer::resizeInsets(BufferView * bv)
2947 /// then remove all LyXText in text-insets
2948 for_each(paragraphs.begin(), paragraphs.end(),
2949 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2953 void Buffer::redraw()
2955 #warning repaint needed here, or do you mean update() ?
2961 void Buffer::changeLanguage(Language const * from, Language const * to)
2964 ParIterator end = par_iterator_end();
2965 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2966 (*it)->changeLanguage(params, from, to);
2970 bool Buffer::isMultiLingual()
2972 ParIterator end = par_iterator_end();
2973 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2974 if ((*it)->isMultiLingual(params))
2981 void Buffer::inset_iterator::setParagraph()
2983 while (pit != pend) {
2984 it = pit->insetlist.begin();
2985 if (it != pit->insetlist.end())
2992 Inset * Buffer::getInsetFromID(int id_arg) const
2994 for (inset_iterator it = inset_const_iterator_begin();
2995 it != inset_const_iterator_end(); ++it)
2997 if (it->id() == id_arg)
2999 Inset * in = it->getInsetFromID(id_arg);
3007 Paragraph * Buffer::getParFromID(int id) const
3012 // why should we allow < 0 ??
3013 //lyx::Assert(id >= 0);
3015 ParConstIterator it(par_iterator_begin());
3016 ParConstIterator end(par_iterator_end());
3018 for (; it != end; ++it) {
3019 // go on then, show me how to remove
3021 if ((*it)->id() == id) {
3022 return const_cast<Paragraph*>(*it);
3030 ParIterator Buffer::par_iterator_begin()
3032 return ParIterator(&*(paragraphs.begin()));
3036 ParIterator Buffer::par_iterator_end()
3038 return ParIterator();
3041 ParConstIterator Buffer::par_iterator_begin() const
3043 return ParConstIterator(&*(paragraphs.begin()));
3047 ParConstIterator Buffer::par_iterator_end() const
3049 return ParConstIterator();
3054 void Buffer::addUser(BufferView * u)
3060 void Buffer::delUser(BufferView *)
3066 Language const * Buffer::getLanguage() const
3068 return params.language;
3072 bool Buffer::isClean() const
3078 bool Buffer::isBakClean() const
3084 void Buffer::markClean() const
3090 // if the .lyx file has been saved, we don't need an
3096 void Buffer::markBakClean()
3102 void Buffer::setUnnamed(bool flag)
3108 bool Buffer::isUnnamed()
3114 void Buffer::markDirty()
3122 DepClean::iterator it = dep_clean_.begin();
3123 DepClean::const_iterator const end = dep_clean_.end();
3125 for (; it != end; ++it) {
3131 string const & Buffer::fileName() const
3137 string const & Buffer::filePath() const
3143 bool Buffer::isReadonly() const
3149 BufferView * Buffer::getUser() const
3155 void Buffer::setParentName(string const & name)
3157 params.parentname = name;
3161 Buffer::inset_iterator::inset_iterator()
3166 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
3173 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
3177 if (it == pit->insetlist.end()) {
3186 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
3188 inset_iterator tmp = *this;
3194 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
3196 return *it.getInset();
3200 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
3202 return it.getInset();
3206 Paragraph * Buffer::inset_iterator::getPar()
3212 lyx::pos_type Buffer::inset_iterator::getPos() const
3218 bool operator==(Buffer::inset_iterator const & iter1,
3219 Buffer::inset_iterator const & iter2)
3221 return iter1.pit == iter2.pit
3222 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
3226 bool operator!=(Buffer::inset_iterator const & iter1,
3227 Buffer::inset_iterator const & iter2)
3229 return !(iter1 == iter2);