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"
36 #include "converter.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/insetbib.h"
59 #include "insets/insetcite.h"
60 #include "insets/insetexternal.h"
61 #include "insets/insetindex.h"
62 #include "insets/insetinclude.h"
63 #include "insets/insettoc.h"
64 #include "insets/insetparent.h"
65 #include "insets/insetspecialchar.h"
66 #include "insets/insettext.h"
67 #include "insets/insetert.h"
68 #include "insets/insetgraphics.h"
69 #include "insets/insetfoot.h"
70 #include "insets/insetmarginal.h"
71 #include "insets/insetoptarg.h"
72 #include "insets/insetminipage.h"
73 #include "insets/insetfloat.h"
74 #include "insets/insetwrap.h"
75 #include "insets/insettabular.h"
77 #include "insets/insettheorem.h"
78 #include "insets/insetlist.h"
80 #include "insets/insetcaption.h"
81 #include "insets/insetfloatlist.h"
83 #include "frontends/Dialogs.h"
84 #include "frontends/Alert.h"
86 #include "graphics/Previews.h"
88 #include "support/textutils.h"
89 #include "support/filetools.h"
90 #include "support/path.h"
91 #include "support/os.h"
92 #include "support/lyxlib.h"
93 #include "support/FileInfo.h"
94 #include "support/lyxmanip.h"
95 #include "support/lyxtime.h"
97 #include <boost/bind.hpp>
98 #include <boost/tuple/tuple.hpp>
99 #include "BoostFormat.h"
111 #include <sys/types.h>
118 #ifndef CXX_GLOBAL_CSTD
130 using std::make_pair;
138 using lyx::textclass_type;
140 // all these externs should eventually be removed.
141 extern BufferList bufferlist;
145 const int LYX_FORMAT = 222;
149 Buffer::Buffer(string const & file, bool ronly)
150 : niceFile(true), lyx_clean(true), bak_clean(true),
151 unnamed(false), read_only(ronly),
152 filename_(file), users(0)
154 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
155 filepath_ = OnlyPath(file);
157 if (read_only || lyxrc.use_tempdir) {
158 tmppath = CreateBufferTmpDir();
163 // set initial author
164 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
170 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
171 // here the buffer should take care that it is
172 // saved properly, before it goes into the void.
174 // make sure that views using this buffer
179 if (!tmppath.empty()) {
180 DestroyBufferTmpDir(tmppath);
185 // Remove any previewed LaTeX snippets assocoated with this buffer.
186 grfx::Previews::get().removeLoader(this);
190 string const Buffer::getLatexName(bool no_path) const
192 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
194 return OnlyFilename(name);
200 pair<Buffer::LogType, string> const Buffer::getLogName() const
202 string const filename = getLatexName(false);
204 if (filename.empty())
205 return make_pair(Buffer::latexlog, string());
207 string path = OnlyPath(filename);
209 if (lyxrc.use_tempdir || !IsDirWriteable(path))
212 string const fname = AddName(path,
213 OnlyFilename(ChangeExtension(filename,
216 AddName(path, OnlyFilename(
217 ChangeExtension(filename,
218 formats.extension("literate") + ".out")));
220 // If no Latex log or Build log is newer, show Build log
222 FileInfo const f_fi(fname);
223 FileInfo const b_fi(bname);
226 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
227 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
228 return make_pair(Buffer::buildlog, bname);
230 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
231 return make_pair(Buffer::latexlog, fname);
235 void Buffer::setReadonly(bool flag)
237 if (read_only != flag) {
240 users->owner()->getDialogs().updateBufferDependent(false);
245 AuthorList & Buffer::authors()
251 /// Update window titles of all users
252 // Should work on a list
253 void Buffer::updateTitles() const
256 users->owner()->updateWindowTitle();
260 /// Reset autosave timer of all users
261 // Should work on a list
262 void Buffer::resetAutosaveTimers() const
265 users->owner()->resetAutosaveTimer();
269 void Buffer::setFileName(string const & newfile)
271 filename_ = MakeAbsPath(newfile);
272 filepath_ = OnlyPath(filename_);
273 setReadonly(IsFileWriteable(filename_) == 0);
278 // We'll remove this later. (Lgb)
281 string last_inset_read;
284 #warning And _why_ is this here? (Lgb)
288 vector<int> author_ids;
293 // candidate for move to BufferView
294 // (at least some parts in the beginning of the func)
297 // changed to be public and have one parameter
298 // if par = 0 normal behavior
299 // else insert behavior
300 // Returns false if "\the_end" is not read (Asger)
301 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
308 Paragraph::depth_type depth = 0;
309 bool the_end_read = false;
311 Paragraph * first_par = 0;
312 LyXFont font(LyXFont::ALL_INHERIT, params.language);
316 par->layout(params.getLyXTextClass().defaultLayout());
318 // We are inserting into an existing document
319 users->text->breakParagraph(users);
320 first_par = users->text->ownerParagraph();
323 // We don't want to adopt the parameters from the
324 // document we insert, so we skip until the text begins:
327 string const pretoken = lex.getString();
328 if (pretoken == "\\layout") {
329 lex.pushToken(pretoken);
337 string const token = lex.getString();
339 if (token.empty()) continue;
341 lyxerr[Debug::PARSER] << "Handling token: `"
342 << token << '\'' << endl;
345 parseSingleLyXformat2Token(lex, par, first_par,
353 paragraphs.set(first_par);
355 if (unknown_layouts > 0) {
356 string s = _("Couldn't set the layout for ");
357 if (unknown_layouts == 1) {
358 s += _("one paragraph");
360 s += tostr(unknown_layouts);
361 s += _(" paragraphs");
364 Alert::alert(_("Textclass Loading Error!"), s,
365 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
367 Alert::alert(_("Textclass Loading Error!"), s,
368 _("When reading ") + fileName());
372 if (unknown_tokens > 0) {
373 string s = _("Encountered ");
374 if (unknown_tokens == 1) {
375 s += _("one unknown token");
377 s += tostr(unknown_tokens);
378 s += _(" unknown tokens");
381 Alert::alert(_("Textclass Loading Error!"), s,
382 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
384 Alert::alert(_("Textclass Loading Error!"), s,
385 _("When reading ") + fileName());
394 // This stuff is, in the traditional LyX terminology, Super UGLY
395 // but this code is too b0rken to admit of a better solution yet
396 Change current_change;
401 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
402 Paragraph *& first_par,
403 string const & token, int & pos,
404 Paragraph::depth_type & depth,
408 bool the_end_read = false;
410 // The order of the tags tested may seem unnatural, but this
411 // has been done in order to reduce the number of string
412 // comparisons needed to recognize a given token. This leads
413 // on large documents like UserGuide to a reduction of a
415 if (token[0] != '\\') {
416 for (string::const_iterator cit = token.begin();
417 cit != token.end(); ++cit) {
418 par->insertChar(pos, (*cit), font, current_change);
421 } else if (token == "\\layout") {
422 // reset the font as we start a new layout and if the font is
423 // not ALL_INHERIT,document_language then it will be set to the
424 // right values after this tag (Jug 20020420)
425 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
428 string layoutname = lex.getString();
430 LyXTextClass const & tclass = params.getLyXTextClass();
432 if (layoutname.empty()) {
433 layoutname = tclass.defaultLayoutName();
435 bool hasLayout = tclass.hasLayout(layoutname);
437 lyxerr << "Layout '" << layoutname << "' does not"
438 << " exist in textclass '" << tclass.name()
440 lyxerr << "Trying to use default layout instead."
442 layoutname = tclass.defaultLayoutName();
446 // The is the compability reading of layout caption.
447 // It can be removed in LyX version 1.3.0. (Lgb)
448 if (compare_ascii_no_case(layoutname, "caption") == 0) {
449 // We expect that the par we are now working on is
450 // really inside a InsetText inside a InsetFloat.
451 // We also know that captions can only be
452 // one paragraph. (Lgb)
454 // We should now read until the next "\layout"
456 // This is probably not good enough, what if the
457 // caption is the last par in the document (Lgb)
458 istream & ist = lex.getStream();
464 if (prefixIs(line, "\\layout")) {
468 if (prefixIs(line, "\\begin_inset"))
470 if (prefixIs(line, "\\end_inset")) {
481 // Now we should have the whole layout in ss
482 // we should now be able to give this to the
484 ss << "\\end_inset\n";
486 // This seems like a bug in stringstream.
487 // We really should be able to use ss
489 istringstream is(ss.str());
491 tmplex.setStream(is);
492 Inset * inset = new InsetCaption;
493 inset->Read(this, tmplex);
494 par->InsertInset(pos, inset, font);
501 par = new Paragraph(par);
502 par->layout(params.getLyXTextClass().defaultLayout());
503 if (params.tracking_changes)
507 par->layout(params.getLyXTextClass()[layoutname]);
508 // Test whether the layout is obsolete.
509 LyXLayout_ptr const & layout = par->layout();
510 if (!layout->obsoleted_by().empty())
511 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
512 par->params().depth(depth);
517 } else if (token == "\\end_inset") {
518 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
519 << "Last inset read was: " << last_inset_read
521 // Simply ignore this. The insets do not have
523 // But insets should read it, it is a part of
524 // the inset isn't it? Lgb.
525 } else if (token == "\\begin_inset") {
526 readInset(lex, par, pos, font);
527 } else if (token == "\\family") {
529 font.setLyXFamily(lex.getString());
530 } else if (token == "\\series") {
532 font.setLyXSeries(lex.getString());
533 } else if (token == "\\shape") {
535 font.setLyXShape(lex.getString());
536 } else if (token == "\\size") {
538 font.setLyXSize(lex.getString());
539 } else if (token == "\\lang") {
541 string const tok = lex.getString();
542 Language const * lang = languages.getLanguage(tok);
544 font.setLanguage(lang);
546 font.setLanguage(params.language);
547 lex.printError("Unknown language `$$Token'");
549 } else if (token == "\\numeric") {
551 font.setNumber(font.setLyXMisc(lex.getString()));
552 } else if (token == "\\emph") {
554 font.setEmph(font.setLyXMisc(lex.getString()));
555 } else if (token == "\\bar") {
557 string const tok = lex.getString();
558 // This is dirty, but gone with LyX3. (Asger)
560 font.setUnderbar(LyXFont::ON);
561 else if (tok == "no")
562 font.setUnderbar(LyXFont::OFF);
563 else if (tok == "default")
564 font.setUnderbar(LyXFont::INHERIT);
566 lex.printError("Unknown bar font flag "
568 } else if (token == "\\noun") {
570 font.setNoun(font.setLyXMisc(lex.getString()));
571 } else if (token == "\\color") {
573 font.setLyXColor(lex.getString());
574 } else if (token == "\\SpecialChar") {
575 LyXLayout_ptr const & layout = par->layout();
577 // Insets don't make sense in a free-spacing context! ---Kayvan
578 if (layout->free_spacing || par->isFreeSpacing()) {
581 string const next_token = lex.getString();
582 if (next_token == "\\-") {
583 par->insertChar(pos, '-', font, current_change);
584 } else if (next_token == "~") {
585 par->insertChar(pos, ' ', font, current_change);
587 lex.printError("Token `$$Token' "
589 "paragraph layout!");
594 Inset * inset = new InsetSpecialChar;
595 inset->read(this, lex);
596 par->insertInset(pos, inset, font, current_change);
599 } else if (token == "\\i") {
600 Inset * inset = new InsetLatexAccent;
601 inset->read(this, lex);
602 par->insertInset(pos, inset, font, current_change);
604 } else if (token == "\\backslash") {
605 par->insertChar(pos, '\\', font, current_change);
607 } else if (token == "\\begin_deeper") {
609 } else if (token == "\\end_deeper") {
611 lex.printError("\\end_deeper: "
612 "depth is already null");
616 } else if (token == "\\begin_preamble") {
617 params.readPreamble(lex);
618 } else if (token == "\\textclass") {
620 pair<bool, textclass_type> pp =
621 textclasslist.NumberOfClass(lex.getString());
623 params.textclass = pp.second;
626 Alert::alert(_("Textclass error"),
627 boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
628 _("-- substituting default."));
631 _("Textclass error"),
632 _("The document uses an unknown textclass ")
634 _("-- substituting default."));
636 params.textclass = 0;
638 if (!params.getLyXTextClass().load()) {
639 // if the textclass wasn't loaded properly
640 // we need to either substitute another
641 // or stop loading the file.
642 // I can substitute but I don't see how I can
643 // stop loading... ideas?? ARRae980418
645 Alert::alert(_("Textclass Loading Error!"),
646 boost::io::str(boost::format(_("Can't load textclass %1$s")) %
647 params.getLyXTextClass().name()),
648 _("-- substituting default."));
650 Alert::alert(_("Textclass Loading Error!"),
651 _("Can't load textclass ")
652 + params.getLyXTextClass().name(),
653 _("-- substituting default."));
655 params.textclass = 0;
657 } else if (token == "\\options") {
659 params.options = lex.getString();
660 } else if (token == "\\language") {
661 params.readLanguage(lex);
662 } else if (token == "\\fontencoding") {
664 } else if (token == "\\inputencoding") {
666 params.inputenc = lex.getString();
667 } else if (token == "\\graphics") {
668 params.readGraphicsDriver(lex);
669 } else if (token == "\\fontscheme") {
671 params.fonts = lex.getString();
672 } else if (token == "\\noindent") {
673 par->params().noindent(true);
674 } else if (token == "\\leftindent") {
676 LyXLength value(lex.getString());
677 par->params().leftIndent(value);
678 } else if (token == "\\fill_top") {
679 par->params().spaceTop(VSpace(VSpace::VFILL));
680 } else if (token == "\\fill_bottom") {
681 par->params().spaceBottom(VSpace(VSpace::VFILL));
682 } else if (token == "\\line_top") {
683 par->params().lineTop(true);
684 } else if (token == "\\line_bottom") {
685 par->params().lineBottom(true);
686 } else if (token == "\\pagebreak_top") {
687 par->params().pagebreakTop(true);
688 } else if (token == "\\pagebreak_bottom") {
689 par->params().pagebreakBottom(true);
690 } else if (token == "\\start_of_appendix") {
691 par->params().startOfAppendix(true);
692 } else if (token == "\\paragraph_separation") {
693 int tmpret = lex.findToken(string_paragraph_separation);
696 params.paragraph_separation =
697 static_cast<BufferParams::PARSEP>(tmpret);
698 } else if (token == "\\defskip") {
700 params.defskip = VSpace(lex.getString());
701 } else if (token == "\\quotes_language") {
702 int tmpret = lex.findToken(string_quotes_language);
705 InsetQuotes::quote_language tmpl =
706 InsetQuotes::EnglishQ;
709 tmpl = InsetQuotes::EnglishQ;
712 tmpl = InsetQuotes::SwedishQ;
715 tmpl = InsetQuotes::GermanQ;
718 tmpl = InsetQuotes::PolishQ;
721 tmpl = InsetQuotes::FrenchQ;
724 tmpl = InsetQuotes::DanishQ;
727 params.quotes_language = tmpl;
728 } else if (token == "\\quotes_times") {
730 switch (lex.getInteger()) {
732 params.quotes_times = InsetQuotes::SingleQ;
735 params.quotes_times = InsetQuotes::DoubleQ;
738 } else if (token == "\\papersize") {
739 int tmpret = lex.findToken(string_papersize);
743 params.papersize2 = tmpret;
744 } else if (token == "\\paperpackage") {
745 int tmpret = lex.findToken(string_paperpackages);
748 params.paperpackage = BufferParams::PACKAGE_NONE;
750 params.paperpackage = tmpret;
751 } else if (token == "\\use_geometry") {
753 params.use_geometry = lex.getInteger();
754 } else if (token == "\\use_amsmath") {
756 params.use_amsmath = lex.getInteger();
757 } else if (token == "\\use_natbib") {
759 params.use_natbib = lex.getInteger();
760 } else if (token == "\\use_numerical_citations") {
762 params.use_numerical_citations = lex.getInteger();
763 } else if (token == "\\tracking_changes") {
765 params.tracking_changes = lex.getInteger();
766 // mark the first paragraph
767 if (params.tracking_changes)
769 } else if (token == "\\author") {
771 istringstream ss(lex.getString());
774 int aid(authorlist.record(a));
775 lyxerr << "aid is " << aid << endl;
776 lyxerr << "listed aid is " << author_ids.size() << endl;
777 author_ids.push_back(authorlist.record(a));
778 } else if (token == "\\paperorientation") {
779 int tmpret = lex.findToken(string_orientation);
783 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
784 } else if (token == "\\paperwidth") {
786 params.paperwidth = lex.getString();
787 } else if (token == "\\paperheight") {
789 params.paperheight = lex.getString();
790 } else if (token == "\\leftmargin") {
792 params.leftmargin = lex.getString();
793 } else if (token == "\\topmargin") {
795 params.topmargin = lex.getString();
796 } else if (token == "\\rightmargin") {
798 params.rightmargin = lex.getString();
799 } else if (token == "\\bottommargin") {
801 params.bottommargin = lex.getString();
802 } else if (token == "\\headheight") {
804 params.headheight = lex.getString();
805 } else if (token == "\\headsep") {
807 params.headsep = lex.getString();
808 } else if (token == "\\footskip") {
810 params.footskip = lex.getString();
811 } else if (token == "\\paperfontsize") {
813 params.fontsize = rtrim(lex.getString());
814 } else if (token == "\\papercolumns") {
816 params.columns = lex.getInteger();
817 } else if (token == "\\papersides") {
819 switch (lex.getInteger()) {
821 case 1: params.sides = LyXTextClass::OneSide; break;
822 case 2: params.sides = LyXTextClass::TwoSides; break;
824 } else if (token == "\\paperpagestyle") {
826 params.pagestyle = rtrim(lex.getString());
827 } else if (token == "\\bullet") {
829 int const index = lex.getInteger();
831 int temp_int = lex.getInteger();
832 params.user_defined_bullets[index].setFont(temp_int);
833 params.temp_bullets[index].setFont(temp_int);
835 temp_int = lex.getInteger();
836 params.user_defined_bullets[index].setCharacter(temp_int);
837 params.temp_bullets[index].setCharacter(temp_int);
839 temp_int = lex.getInteger();
840 params.user_defined_bullets[index].setSize(temp_int);
841 params.temp_bullets[index].setSize(temp_int);
843 string const temp_str = lex.getString();
844 if (temp_str != "\\end_bullet") {
845 // this element isn't really necessary for
846 // parsing but is easier for humans
847 // to understand bullets. Put it back and
848 // set a debug message?
849 lex.printError("\\end_bullet expected, got" + temp_str);
850 //how can I put it back?
852 } else if (token == "\\bulletLaTeX") {
853 // The bullet class should be able to read this.
855 int const index = lex.getInteger();
857 string temp_str = lex.getString();
859 while (temp_str != "\\end_bullet") {
860 // this loop structure is needed when user
861 // enters an empty string since the first
862 // thing returned will be the \\end_bullet
864 // if the LaTeX entry has spaces. Each element
865 // therefore needs to be read in turn
868 temp_str = lex.getString();
871 params.user_defined_bullets[index].setText(sum_str);
872 params.temp_bullets[index].setText(sum_str);
873 } else if (token == "\\secnumdepth") {
875 params.secnumdepth = lex.getInteger();
876 } else if (token == "\\tocdepth") {
878 params.tocdepth = lex.getInteger();
879 } else if (token == "\\spacing") {
881 string const tmp = rtrim(lex.getString());
882 Spacing::Space tmp_space = Spacing::Default;
884 if (tmp == "single") {
885 tmp_space = Spacing::Single;
886 } else if (tmp == "onehalf") {
887 tmp_space = Spacing::Onehalf;
888 } else if (tmp == "double") {
889 tmp_space = Spacing::Double;
890 } else if (tmp == "other") {
892 tmp_space = Spacing::Other;
893 tmp_val = lex.getFloat();
895 lex.printError("Unknown spacing token: '$$Token'");
897 // Small hack so that files written with klyx will be
900 par->params().spacing(Spacing(tmp_space, tmp_val));
902 params.spacing.set(tmp_space, tmp_val);
904 } else if (token == "\\paragraph_spacing") {
906 string const tmp = rtrim(lex.getString());
907 if (tmp == "single") {
908 par->params().spacing(Spacing(Spacing::Single));
909 } else if (tmp == "onehalf") {
910 par->params().spacing(Spacing(Spacing::Onehalf));
911 } else if (tmp == "double") {
912 par->params().spacing(Spacing(Spacing::Double));
913 } else if (tmp == "other") {
915 par->params().spacing(Spacing(Spacing::Other,
918 lex.printError("Unknown spacing token: '$$Token'");
920 } else if (token == "\\float_placement") {
922 params.float_placement = lex.getString();
923 } else if (token == "\\align") {
924 int tmpret = lex.findToken(string_align);
927 int const tmpret2 = int(pow(2.0, tmpret));
928 par->params().align(LyXAlignment(tmpret2));
929 } else if (token == "\\added_space_top") {
931 VSpace value = VSpace(lex.getString());
932 // only add the length when value > 0 or
934 if ((value.length().len().value() != 0) ||
936 (value.kind() != VSpace::LENGTH))
937 par->params().spaceTop(value);
938 } else if (token == "\\added_space_bottom") {
940 VSpace value = VSpace(lex.getString());
941 // only add the length when value > 0 or
943 if ((value.length().len().value() != 0) ||
945 (value.kind() != VSpace::LENGTH))
946 par->params().spaceBottom(value);
947 } else if (token == "\\labelwidthstring") {
949 par->params().labelWidthString(lex.getString());
950 // do not delete this token, it is still needed!
951 } else if (token == "\\newline") {
952 par->insertChar(pos, Paragraph::META_NEWLINE, font, current_change);
954 } else if (token == "\\LyXTable") {
955 Inset * inset = new InsetTabular(*this);
956 inset->read(this, lex);
957 par->insertInset(pos, inset, font, current_change);
959 } else if (token == "\\bibitem") { // ale970302
960 InsetCommandParams p("bibitem", "dummy");
961 InsetBibKey * inset = new InsetBibKey(p);
962 inset->read(this, lex);
963 par->insertInset(pos, inset, font, current_change);
965 } else if (token == "\\hfill") {
966 par->insertChar(pos, Paragraph::META_HFILL, font, current_change);
968 } else if (token == "\\change_unchanged") {
969 // Hack ! Needed for empty paragraphs :/
972 current_change = Change(Change::UNCHANGED);
973 } else if (token == "\\change_inserted") {
975 istringstream istr(lex.getString());
980 current_change = Change(Change::INSERTED, author_ids[aid], ct);
981 } else if (token == "\\change_deleted") {
983 istringstream istr(lex.getString());
988 current_change = Change(Change::DELETED, author_ids[aid], ct);
989 } else if (token == "\\the_end") {
992 // This should be insurance for the future: (Asger)
996 boost::format fmt(_("Unknown token: %1$s %2$s\n"));
997 fmt % token % lex.text();
998 string const s = fmt.str();
1000 string const s = _("Unknown token: ") + token
1001 + ' ' + lex.text() + '\n';
1003 // we can do this here this way because we're actually reading
1004 // the buffer and don't care about LyXText right now.
1005 InsetError * new_inset = new InsetError(s);
1006 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1011 return the_end_read;
1015 // needed to insert the selection
1016 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
1017 LyXFont const & fn,string const & str) const
1019 LyXLayout_ptr const & layout = par->layout();
1023 par->checkInsertChar(font);
1024 // insert the string, don't insert doublespace
1025 bool space_inserted = true;
1026 bool autobreakrows = !par->inInset() ||
1027 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
1028 for(string::const_iterator cit = str.begin();
1029 cit != str.end(); ++cit) {
1031 if (autobreakrows && (!par->empty() || layout->keepempty)) {
1032 breakParagraph(params, par, pos,
1033 layout->isEnvironment());
1036 space_inserted = true;
1040 // do not insert consecutive spaces if !free_spacing
1041 } else if ((*cit == ' ' || *cit == '\t') &&
1042 space_inserted && !layout->free_spacing &&
1043 !par->isFreeSpacing())
1046 } else if (*cit == '\t') {
1047 if (!layout->free_spacing && !par->isFreeSpacing()) {
1048 // tabs are like spaces here
1049 par->insertChar(pos, ' ', font, current_change);
1051 space_inserted = true;
1053 const pos_type nb = 8 - pos % 8;
1054 for (pos_type a = 0; a < nb ; ++a) {
1055 par->insertChar(pos, ' ', font, current_change);
1058 space_inserted = true;
1060 } else if (!IsPrintable(*cit)) {
1061 // Ignore unprintables
1064 // just insert the character
1065 par->insertChar(pos, *cit, font);
1067 space_inserted = (*cit == ' ');
1074 void Buffer::readInset(LyXLex & lex, Paragraph *& par,
1075 int & pos, LyXFont & font)
1077 // consistency check
1078 if (lex.getString() != "\\begin_inset") {
1079 lyxerr << "Buffer::readInset: Consistency check failed."
1086 string const tmptok = lex.getString();
1087 last_inset_read = tmptok;
1089 // test the different insets
1090 if (tmptok == "LatexCommand") {
1091 InsetCommandParams inscmd;
1094 string const cmdName = inscmd.getCmdName();
1096 // This strange command allows LyX to recognize "natbib" style
1097 // citations: citet, citep, Citet etc.
1098 if (compare_ascii_no_case(cmdName.substr(0,4), "cite") == 0) {
1099 inset = new InsetCitation(inscmd);
1100 } else if (cmdName == "bibitem") {
1101 lex.printError("Wrong place for bibitem");
1102 inset = new InsetBibKey(inscmd);
1103 } else if (cmdName == "BibTeX") {
1104 inset = new InsetBibtex(inscmd);
1105 } else if (cmdName == "index") {
1106 inset = new InsetIndex(inscmd);
1107 } else if (cmdName == "include") {
1108 inset = new InsetInclude(inscmd, *this);
1109 } else if (cmdName == "label") {
1110 inset = new InsetLabel(inscmd);
1111 } else if (cmdName == "url"
1112 || cmdName == "htmlurl") {
1113 inset = new InsetUrl(inscmd);
1114 } else if (cmdName == "ref"
1115 || cmdName == "pageref"
1116 || cmdName == "vref"
1117 || cmdName == "vpageref"
1118 || cmdName == "prettyref") {
1119 if (!inscmd.getOptions().empty()
1120 || !inscmd.getContents().empty()) {
1121 inset = new InsetRef(inscmd, *this);
1123 } else if (cmdName == "tableofcontents") {
1124 inset = new InsetTOC(inscmd);
1125 } else if (cmdName == "listofalgorithms") {
1126 inset = new InsetFloatList("algorithm");
1127 } else if (cmdName == "listoffigures") {
1128 inset = new InsetFloatList("figure");
1129 } else if (cmdName == "listoftables") {
1130 inset = new InsetFloatList("table");
1131 } else if (cmdName == "printindex") {
1132 inset = new InsetPrintIndex(inscmd);
1133 } else if (cmdName == "lyxparent") {
1134 inset = new InsetParent(inscmd, *this);
1137 bool alreadyread = false;
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 == "Figure") { // Backward compatibility
1147 // inset = new InsetFig(100, 100, *this);
1148 inset = new InsetGraphics;
1149 } else if (tmptok == "Graphics") {
1150 inset = new InsetGraphics;
1151 } else if (tmptok == "Info") {// backwards compatibility
1152 inset = new InsetNote(this,
1153 lex.getLongString("\\end_inset"),
1156 } else if (tmptok == "Note") {
1157 inset = new InsetNote(params);
1158 } else if (tmptok == "Include") {
1159 InsetCommandParams p("Include");
1160 inset = new InsetInclude(p, *this);
1161 } else if (tmptok == "ERT") {
1162 inset = new InsetERT(params);
1163 } else if (tmptok == "Tabular") {
1164 inset = new InsetTabular(*this);
1165 } else if (tmptok == "Text") {
1166 inset = new InsetText(params);
1167 } else if (tmptok == "Foot") {
1168 inset = new InsetFoot(params);
1169 } else if (tmptok == "Marginal") {
1170 inset = new InsetMarginal(params);
1171 } else if (tmptok == "OptArg") {
1172 inset = new InsetOptArg(params);
1173 } else if (tmptok == "Minipage") {
1174 inset = new InsetMinipage(params);
1175 } else if (tmptok == "Float") {
1177 string tmptok = lex.getString();
1178 inset = new InsetFloat(params, tmptok);
1179 } else if (tmptok == "Wrap") {
1181 string tmptok = lex.getString();
1182 inset = new InsetWrap(params, tmptok);
1184 } else if (tmptok == "List") {
1185 inset = new InsetList;
1186 } else if (tmptok == "Theorem") {
1187 inset = new InsetList;
1189 } else if (tmptok == "Caption") {
1190 inset = new InsetCaption(params);
1191 } else if (tmptok == "FloatList") {
1192 inset = new InsetFloatList;
1195 if (inset && !alreadyread) inset->read(this, lex);
1199 par->insertInset(pos, inset, font, current_change);
1205 bool Buffer::readFile(LyXLex & lex, string const & filename, Paragraph * par)
1209 string const token(lex.getString());
1210 if (token == "\\lyxformat") { // the first token _must_ be...
1212 string tmp_format = lex.getString();
1213 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
1214 // if present remove ".," from string.
1215 string::size_type dot = tmp_format.find_first_of(".,");
1216 //lyxerr << " dot found at " << dot << endl;
1217 if (dot != string::npos)
1218 tmp_format.erase(dot, 1);
1219 file_format = strToInt(tmp_format);
1220 //lyxerr << "format: " << file_format << endl;
1221 if (file_format == LYX_FORMAT) {
1223 } else if (file_format > LYX_FORMAT) {
1225 Alert::alert(_("Warning!"),
1226 _("The file was created with a newer version of "
1227 "LyX. This is likely to cause problems."));
1229 } else if (file_format < LYX_FORMAT) {
1231 if (file_format < 200) {
1232 Alert::alert(_("ERROR!"),
1233 _("Old LyX file format found. "
1234 "Use LyX 0.10.x to read this!"));
1236 } else if (!filename.empty()) {
1238 LibFileSearch("lyx2lyx", "lyx2lyx");
1239 if (command.empty()) {
1240 Alert::alert(_("ERROR!"),
1241 _("Can't find conversion script."));
1245 +tostr(LYX_FORMAT) + ' '
1246 + QuoteName(filename);
1247 lyxerr[Debug::INFO] << "Running '"
1250 cmd_ret const ret = RunCommand(command);
1252 Alert::alert(_("ERROR!"),
1253 _("An error occured while "
1254 "running the conversion script."));
1257 istringstream is(STRCONV(ret.second));
1258 LyXLex tmplex(0, 0);
1259 tmplex.setStream(is);
1260 return readFile(tmplex, string(), par);
1262 // This code is reached if lyx2lyx failed (for
1263 // some reason) to change the file format of
1269 bool the_end = readLyXformat2(lex, par);
1270 params.setPaperStuff();
1273 Alert::alert(_("Warning!"),
1274 _("Reading of document is not complete"),
1275 _("Maybe the document is truncated"));
1278 } else { // "\\lyxformat" not found
1279 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1282 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1287 // Should probably be moved to somewhere else: BufferView? LyXView?
1288 bool Buffer::save() const
1290 // We don't need autosaves in the immediate future. (Asger)
1291 resetAutosaveTimers();
1295 if (lyxrc.make_backup) {
1296 s = fileName() + '~';
1297 if (!lyxrc.backupdir_path.empty())
1298 s = AddName(lyxrc.backupdir_path,
1299 subst(os::slashify_path(s),'/','!'));
1301 // Rename is the wrong way of making a backup,
1302 // this is the correct way.
1303 /* truss cp fil fil2:
1304 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1305 stat("LyXVC.lyx", 0xEFFFF688) = 0
1306 open("LyXVC.lyx", O_RDONLY) = 3
1307 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1308 fstat(4, 0xEFFFF508) = 0
1309 fstat(3, 0xEFFFF508) = 0
1310 read(3, " # T h i s f i l e w".., 8192) = 5579
1311 write(4, " # T h i s f i l e w".., 5579) = 5579
1312 read(3, 0xEFFFD4A0, 8192) = 0
1315 chmod("LyXVC3.lyx", 0100644) = 0
1316 lseek(0, 0, SEEK_CUR) = 46440
1320 // Should probably have some more error checking here.
1321 // Doing it this way, also makes the inodes stay the same.
1322 // This is still not a very good solution, in particular we
1323 // might loose the owner of the backup.
1324 FileInfo finfo(fileName());
1325 if (finfo.exist()) {
1326 mode_t fmode = finfo.getMode();
1327 struct utimbuf times = {
1328 finfo.getAccessTime(),
1329 finfo.getModificationTime() };
1331 ifstream ifs(fileName().c_str());
1332 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1337 ::chmod(s.c_str(), fmode);
1339 if (::utime(s.c_str(), ×)) {
1340 lyxerr << "utime error." << endl;
1343 lyxerr << "LyX was not able to make "
1344 "backup copy. Beware." << endl;
1349 if (writeFile(fileName())) {
1351 removeAutosaveFile(fileName());
1353 // Saving failed, so backup is not backup
1354 if (lyxrc.make_backup) {
1355 lyx::rename(s, fileName());
1363 bool Buffer::writeFile(string const & fname) const
1365 if (read_only && (fname == fileName())) {
1369 FileInfo finfo(fname);
1370 if (finfo.exist() && !finfo.writable()) {
1374 ofstream ofs(fname.c_str());
1380 // Use the standard "C" locale for file output.
1381 ofs.imbue(std::locale::classic());
1384 // The top of the file should not be written by params.
1386 // write out a comment in the top of the file
1387 ofs << '#' << lyx_docversion
1388 << " created this file. For more info see http://www.lyx.org/\n"
1389 << "\\lyxformat " << LYX_FORMAT << "\n";
1391 // now write out the buffer paramters.
1392 params.writeFile(ofs);
1394 // if we're tracking, list all possible authors
1395 if (params.tracking_changes) {
1396 AuthorList::Authors::const_iterator it = authorlist.begin();
1397 AuthorList::Authors::const_iterator end = authorlist.end();
1398 for (; it != end; ++it) {
1399 ofs << "\\author " << it->second << "\n";
1403 Paragraph::depth_type depth = 0;
1405 // this will write out all the paragraphs
1406 // using recursive descent.
1407 ParagraphList::iterator pit = paragraphs.begin();
1408 ParagraphList::iterator pend = paragraphs.end();
1409 for (; pit != pend; ++pit)
1410 pit->write(this, ofs, params, depth);
1412 // Write marker that shows file is complete
1413 ofs << "\n\\the_end" << endl;
1417 // how to check if close went ok?
1418 // Following is an attempt... (BE 20001011)
1420 // good() returns false if any error occured, including some
1421 // formatting error.
1422 // bad() returns true if something bad happened in the buffer,
1423 // which should include file system full errors.
1430 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1432 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1444 pair<int, string> const addDepth(int depth, int ldepth)
1448 d += (ldepth - depth) * 2;
1449 return make_pair(d, string(d, ' '));
1455 string const Buffer::asciiParagraph(Paragraph const & par,
1456 unsigned int linelen,
1457 bool noparbreak) const
1459 ostringstream buffer;
1460 Paragraph::depth_type depth = 0;
1462 Paragraph::depth_type ltype_depth = 0;
1463 bool ref_printed = false;
1464 // if (!par->previous()) {
1466 // begins or ends a deeper area ?
1467 if (depth != par->params().depth()) {
1468 if (par->params().depth() > depth) {
1469 while (par->params().depth() > depth) {
1473 while (par->params().depth() < depth) {
1479 depth = par.params().depth();
1482 // First write the layout
1483 string const & tmp = par.layout()->name();
1484 if (compare_no_case(tmp, "itemize") == 0) {
1486 ltype_depth = depth + 1;
1487 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1489 ltype_depth = depth + 1;
1490 } else if (contains(ascii_lowercase(tmp), "ection")) {
1492 ltype_depth = depth + 1;
1493 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1495 ltype_depth = depth + 1;
1496 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1498 ltype_depth = depth + 1;
1499 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1502 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1510 /* maybe some vertical spaces */
1512 /* the labelwidthstring used in lists */
1516 /* some pagebreaks? */
1520 /* what about the alignment */
1522 // lyxerr << "Should this ever happen?" << endl;
1525 // linelen <= 0 is special and means we don't have paragraph breaks
1527 string::size_type currlinelen = 0;
1533 buffer << string(depth * 2, ' ');
1534 currlinelen += depth * 2;
1537 // we should probably change to the paragraph language in the
1538 // gettext here (if possible) so that strings are outputted in
1539 // the correct language! (20012712 Jug)
1543 case 4: // (Sub)Paragraph
1544 case 5: // Description
1548 buffer << _("Abstract") << "\n\n";
1551 string const abst = _("Abstract: ");
1553 currlinelen += abst.length();
1556 case 7: // Bibliography
1559 buffer << _("References") << "\n\n";
1562 string const refs = _("References: ");
1564 currlinelen += refs.length();
1572 string const parlab = par.params().labelString();
1573 buffer << parlab << ' ';
1574 currlinelen += parlab.length() + 1;
1582 pair<int, string> p = addDepth(depth, ltype_depth);
1584 currlinelen += p.first;
1587 // this is to change the linebreak to do it by word a bit more
1588 // intelligent hopefully! (only in the case where we have a
1589 // max linelength!) (Jug)
1593 for (pos_type i = 0; i < par.size(); ++i) {
1594 char c = par.getUChar(params, i);
1596 case Paragraph::META_INSET:
1598 Inset const * inset = par.getInset(i);
1602 currlinelen += word.length();
1605 if (inset->ascii(this, buffer, linelen)) {
1606 // to be sure it breaks paragraph
1607 currlinelen += linelen;
1613 case Paragraph::META_NEWLINE:
1615 buffer << word << "\n";
1618 pair<int, string> p = addDepth(depth,
1621 currlinelen = p.first;
1625 case Paragraph::META_HFILL:
1626 buffer << word << "\t";
1627 currlinelen += word.length() + 1;
1634 currlinelen + word.length() > linelen - 10) {
1636 pair<int, string> p =
1637 addDepth(depth, ltype_depth);
1639 currlinelen = p.first;
1642 buffer << word << ' ';
1643 currlinelen += word.length() + 1;
1650 lyxerr[Debug::INFO] <<
1651 "writeAsciiFile: NULL char in structure." << endl;
1653 if ((linelen > 0) &&
1654 (currlinelen + word.length()) > linelen)
1658 pair<int, string> p =
1659 addDepth(depth, ltype_depth);
1661 currlinelen = p.first;
1668 return STRCONV(buffer.str());
1672 void Buffer::writeFileAscii(string const & fname, int linelen)
1674 ofstream ofs(fname.c_str());
1676 Alert::err_alert(_("Error: Cannot write file:"), fname);
1679 writeFileAscii(ofs, linelen);
1683 void Buffer::writeFileAscii(ostream & os, int linelen)
1685 ParagraphList::iterator beg = paragraphs.begin();
1686 ParagraphList::iterator end = paragraphs.end();
1687 ParagraphList::iterator it = beg;
1688 for (; it != end; ++it) {
1689 os << asciiParagraph(*it, linelen, it == beg);
1696 void Buffer::makeLaTeXFile(string const & fname,
1697 string const & original_path,
1698 bool nice, bool only_body, bool only_preamble)
1700 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1702 ofstream ofs(fname.c_str());
1704 Alert::err_alert(_("Error: Cannot open file: "), fname);
1708 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1712 lyxerr << "File was not closed properly." << endl;
1717 void Buffer::makeLaTeXFile(ostream & os,
1718 string const & original_path,
1719 bool nice, bool only_body, bool only_preamble)
1721 niceFile = nice; // this will be used by Insetincludes.
1723 // validate the buffer.
1724 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1725 LaTeXFeatures features(params);
1727 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1730 // The starting paragraph of the coming rows is the
1731 // first paragraph of the document. (Asger)
1732 texrow.start(&*(paragraphs.begin()), 0);
1734 if (!only_body && nice) {
1735 os << "%% " << lyx_docversion << " created this file. "
1736 "For more info, see http://www.lyx.org/.\n"
1737 "%% Do not edit unless you really know what "
1742 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1743 // There are a few differences between nice LaTeX and usual files:
1744 // usual is \batchmode and has a
1745 // special input@path to allow the including of figures
1746 // with either \input or \includegraphics (what figinsets do).
1747 // input@path is set when the actual parameter
1748 // original_path is set. This is done for usual tex-file, but not
1749 // for nice-latex-file. (Matthias 250696)
1752 // code for usual, NOT nice-latex-file
1753 os << "\\batchmode\n"; // changed
1754 // from \nonstopmode
1757 if (!original_path.empty()) {
1758 string inputpath = os::external_path(original_path);
1759 subst(inputpath, "~", "\\string~");
1760 os << "\\makeatletter\n"
1761 << "\\def\\input@path{{"
1762 << inputpath << "/}}\n"
1763 << "\\makeatother\n";
1769 // Write the preamble
1770 params.writeLaTeX(os, features, texrow);
1776 os << "\\begin{document}\n";
1779 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1781 if (!lyxrc.language_auto_begin) {
1782 os << subst(lyxrc.language_command_begin, "$$lang",
1783 params.language->babel())
1788 latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
1790 // add this just in case after all the paragraphs
1794 if (!lyxrc.language_auto_end) {
1795 os << subst(lyxrc.language_command_end, "$$lang",
1796 params.language->babel())
1802 os << "\\end{document}\n";
1805 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1807 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1811 // Just to be sure. (Asger)
1814 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1815 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1818 // we want this to be true outside previews (for insetexternal)
1824 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
1826 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
1827 Paragraph * endpar, TexRow & texrow,
1828 bool moving_arg) const
1830 bool was_title = false;
1831 bool already_title = false;
1832 LyXTextClass const & tclass = params.getLyXTextClass();
1835 while (par != endpar) {
1836 Inset * in = par->inInset();
1837 // well we have to check if we are in an inset with unlimited
1838 // length (all in one row) if that is true then we don't allow
1839 // any special options in the paragraph and also we don't allow
1840 // any environment other then "Standard" to be valid!
1841 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1842 LyXLayout_ptr const & layout = par->layout();
1844 if (layout->intitle) {
1845 if (already_title) {
1846 lyxerr <<"Error in latexParagraphs: You"
1847 " should not mix title layouts"
1848 " with normal ones." << endl;
1849 } else if (!was_title) {
1851 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1853 << tclass.titlename()
1858 } else if (was_title && !already_title) {
1859 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1860 ofs << "\\end{" << tclass.titlename()
1864 ofs << "\\" << tclass.titlename()
1868 already_title = true;
1872 if (layout->isEnvironment() ||
1873 !par->params().leftIndent().zero())
1875 par = par->TeXEnvironment(this, params, ofs, texrow);
1877 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
1880 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
1883 // It might be that we only have a title in this document
1884 if (was_title && !already_title) {
1885 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1886 ofs << "\\end{" << tclass.titlename()
1890 ofs << "\\" << tclass.titlename()
1898 bool Buffer::isLatex() const
1900 return params.getLyXTextClass().outputType() == LATEX;
1904 bool Buffer::isLinuxDoc() const
1906 return params.getLyXTextClass().outputType() == LINUXDOC;
1910 bool Buffer::isLiterate() const
1912 return params.getLyXTextClass().outputType() == LITERATE;
1916 bool Buffer::isDocBook() const
1918 return params.getLyXTextClass().outputType() == DOCBOOK;
1922 bool Buffer::isSGML() const
1924 LyXTextClass const & tclass = params.getLyXTextClass();
1926 return tclass.outputType() == LINUXDOC ||
1927 tclass.outputType() == DOCBOOK;
1931 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1933 ofstream ofs(fname.c_str());
1936 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1940 niceFile = nice; // this will be used by included files.
1942 LaTeXFeatures features(params);
1948 LyXTextClass const & tclass = params.getLyXTextClass();
1950 string top_element = tclass.latexname();
1953 ofs << "<!doctype linuxdoc system";
1955 string preamble = params.preamble;
1956 const string name = nice ? ChangeExtension(filename_, ".sgml")
1958 preamble += features.getIncludedFiles(name);
1959 preamble += features.getLyXSGMLEntities();
1961 if (!preamble.empty()) {
1962 ofs << " [ " << preamble << " ]";
1966 if (params.options.empty())
1967 sgml::openTag(ofs, 0, false, top_element);
1969 string top = top_element;
1971 top += params.options;
1972 sgml::openTag(ofs, 0, false, top);
1976 ofs << "<!-- " << lyx_docversion
1977 << " created this file. For more info see http://www.lyx.org/"
1980 Paragraph::depth_type depth = 0; // paragraph depth
1981 Paragraph * par = &*(paragraphs.begin());
1983 vector<string> environment_stack(5);
1986 LyXLayout_ptr const & style = par->layout();
1987 // treat <toc> as a special case for compatibility with old code
1988 if (par->isInset(0)) {
1989 Inset * inset = par->getInset(0);
1990 Inset::Code lyx_code = inset->lyxCode();
1991 if (lyx_code == Inset::TOC_CODE) {
1992 string const temp = "toc";
1993 sgml::openTag(ofs, depth, false, temp);
2000 // environment tag closing
2001 for (; depth > par->params().depth(); --depth) {
2002 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2003 environment_stack[depth].erase();
2006 // write opening SGML tags
2007 switch (style->latextype) {
2008 case LATEX_PARAGRAPH:
2009 if (depth == par->params().depth()
2010 && !environment_stack[depth].empty()) {
2011 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2012 environment_stack[depth].erase();
2018 sgml::openTag(ofs, depth, false, style->latexname());
2024 _("Error: Wrong depth for LatexType Command.\n"));
2026 if (!environment_stack[depth].empty()) {
2027 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2031 environment_stack[depth].erase();
2032 sgml::openTag(ofs, depth, false, style->latexname());
2035 case LATEX_ENVIRONMENT:
2036 case LATEX_ITEM_ENVIRONMENT:
2037 case LATEX_BIB_ENVIRONMENT:
2039 string const & latexname = style->latexname();
2041 if (depth == par->params().depth()
2042 && environment_stack[depth] != latexname) {
2043 sgml::closeTag(ofs, depth, false,
2044 environment_stack[depth]);
2045 environment_stack[depth].erase();
2047 if (depth < par->params().depth()) {
2048 depth = par->params().depth();
2049 environment_stack[depth].erase();
2051 if (environment_stack[depth] != latexname) {
2053 sgml::openTag(ofs, depth, false, "p");
2055 sgml::openTag(ofs, depth, false, latexname);
2057 if (environment_stack.size() == depth + 1)
2058 environment_stack.push_back("!-- --");
2059 environment_stack[depth] = latexname;
2062 if (style->latexparam() == "CDATA")
2065 if (style->latextype == LATEX_ENVIRONMENT) break;
2067 if (style->labeltype == LABEL_MANUAL)
2072 sgml::openTag(ofs, depth + 1, false, item_name);
2077 sgml::openTag(ofs, depth, false, style->latexname());
2081 simpleLinuxDocOnePar(ofs, par, depth);
2086 // write closing SGML tags
2087 switch (style->latextype) {
2090 case LATEX_ENVIRONMENT:
2091 case LATEX_ITEM_ENVIRONMENT:
2092 case LATEX_BIB_ENVIRONMENT:
2093 if (style->latexparam() == "CDATA")
2097 sgml::closeTag(ofs, depth, false, style->latexname());
2103 for (int i = depth; i >= 0; --i)
2104 sgml::closeTag(ofs, depth, false, environment_stack[i]);
2108 sgml::closeTag(ofs, 0, false, top_element);
2112 // How to check for successful close
2114 // we want this to be true outside previews (for insetexternal)
2119 // checks, if newcol chars should be put into this line
2120 // writes newline, if necessary.
2123 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2124 string::size_type newcol)
2127 if (colcount > lyxrc.ascii_linelen) {
2129 colcount = newcol; // assume write after this call
2144 string tag_name(PAR_TAG const & pt) {
2146 case NONE: return "!-- --";
2147 case TT: return "tt";
2148 case SF: return "sf";
2149 case BF: return "bf";
2150 case IT: return "it";
2151 case SL: return "sl";
2152 case EM: return "em";
2159 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2161 p1 = static_cast<PAR_TAG>(p1 | p2);
2166 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2168 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2174 // Handle internal paragraph parsing -- layout already processed.
2175 void Buffer::simpleLinuxDocOnePar(ostream & os,
2177 Paragraph::depth_type /*depth*/)
2179 LyXLayout_ptr const & style = par->layout();
2181 string::size_type char_line_count = 5; // Heuristic choice ;-)
2183 // gets paragraph main font
2186 if (style->labeltype == LABEL_MANUAL) {
2187 font_old = style->labelfont;
2190 font_old = style->font;
2194 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2195 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2196 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2199 stack<PAR_TAG> tag_state;
2200 // parsing main loop
2201 for (pos_type i = 0; i < par->size(); ++i) {
2203 PAR_TAG tag_close = NONE;
2204 list < PAR_TAG > tag_open;
2206 LyXFont const font = par->getFont(params, i);
2208 if (font_old.family() != font.family()) {
2209 switch (family_type) {
2210 case LyXFont::SANS_FAMILY:
2213 case LyXFont::TYPEWRITER_FAMILY:
2220 family_type = font.family();
2222 switch (family_type) {
2223 case LyXFont::SANS_FAMILY:
2224 tag_open.push_back(SF);
2226 case LyXFont::TYPEWRITER_FAMILY:
2227 tag_open.push_back(TT);
2234 if (font_old.series() != font.series()) {
2235 switch (series_type) {
2236 case LyXFont::BOLD_SERIES:
2243 series_type = font.series();
2245 switch (series_type) {
2246 case LyXFont::BOLD_SERIES:
2247 tag_open.push_back(BF);
2255 if (font_old.shape() != font.shape()) {
2256 switch (shape_type) {
2257 case LyXFont::ITALIC_SHAPE:
2260 case LyXFont::SLANTED_SHAPE:
2267 shape_type = font.shape();
2269 switch (shape_type) {
2270 case LyXFont::ITALIC_SHAPE:
2271 tag_open.push_back(IT);
2273 case LyXFont::SLANTED_SHAPE:
2274 tag_open.push_back(SL);
2281 if (font_old.emph() != font.emph()) {
2282 if (font.emph() == LyXFont::ON) {
2283 tag_open.push_back(EM);
2292 list < PAR_TAG > temp;
2293 while (!tag_state.empty() && tag_close) {
2294 PAR_TAG k = tag_state.top();
2296 os << "</" << tag_name(k) << '>';
2303 for(list< PAR_TAG >::const_iterator j = temp.begin();
2304 j != temp.end(); ++j) {
2306 os << '<' << tag_name(*j) << '>';
2309 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2310 j != tag_open.end(); ++j) {
2312 os << '<' << tag_name(*j) << '>';
2315 char c = par->getChar(i);
2317 if (c == Paragraph::META_INSET) {
2318 Inset * inset = par->getInset(i);
2319 inset->linuxdoc(this, os);
2324 if (style->latexparam() == "CDATA") {
2325 // "TeX"-Mode on == > SGML-Mode on.
2332 boost::tie(ws, str) = sgml::escapeChar(c);
2333 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
2334 // in freespacing mode, spaces are
2335 // non-breaking characters
2336 if (desc_on) {// if char is ' ' then...
2339 sgmlLineBreak(os, char_line_count, 6);
2343 sgmlLineBreak(os, char_line_count, 1);
2348 char_line_count += str.length();
2354 while (!tag_state.empty()) {
2355 os << "</" << tag_name(tag_state.top()) << '>';
2359 // resets description flag correctly
2361 // <tag> not closed...
2362 sgmlLineBreak(os, char_line_count, 6);
2368 // Print an error message.
2369 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
2370 string const & /*message*/) const
2372 #ifdef WITH_WARNINGS
2373 #warning This is wrong we cannot insert an inset like this!!!
2374 // I guess this was Jose' so I explain you more or less why this
2375 // is wrong. This way you insert something in the paragraph and
2376 // don't tell it to LyXText (row rebreaking and undo handling!!!)
2377 // I deactivate this code, have a look at BufferView::insertErrors
2378 // how you should do this correctly! (Jug 20020315)
2381 // insert an error marker in text
2382 InsetError * new_inset = new InsetError(message);
2383 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
2389 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2391 ofstream ofs(fname.c_str());
2393 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2397 Paragraph * par = &*(paragraphs.begin());
2399 niceFile = nice; // this will be used by Insetincludes.
2401 LaTeXFeatures features(params);
2406 LyXTextClass const & tclass = params.getLyXTextClass();
2407 string top_element = tclass.latexname();
2410 ofs << "<!DOCTYPE " << top_element
2411 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
2413 string preamble = params.preamble;
2414 const string name = nice ? ChangeExtension(filename_, ".sgml")
2416 preamble += features.getIncludedFiles(name);
2417 preamble += features.getLyXSGMLEntities();
2419 if (!preamble.empty()) {
2420 ofs << "\n [ " << preamble << " ]";
2425 string top = top_element;
2427 top += params.language->code();
2430 if (!params.options.empty()) {
2432 top += params.options;
2434 sgml::openTag(ofs, 0, false, top);
2436 ofs << "<!-- DocBook file was created by " << lyx_docversion
2437 << "\n See http://www.lyx.org/ for more information -->\n";
2439 vector<string> environment_stack(10);
2440 vector<string> environment_inner(10);
2441 vector<string> command_stack(10);
2443 bool command_flag = false;
2444 Paragraph::depth_type command_depth = 0;
2445 Paragraph::depth_type command_base = 0;
2446 Paragraph::depth_type cmd_depth = 0;
2447 Paragraph::depth_type depth = 0; // paragraph depth
2450 string command_name;
2456 int desc_on = 0; // description mode
2458 LyXLayout_ptr const & style = par->layout();
2460 // environment tag closing
2461 for (; depth > par->params().depth(); --depth) {
2462 if (environment_inner[depth] != "!-- --") {
2463 item_name = "listitem";
2464 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2465 if (environment_inner[depth] == "varlistentry")
2466 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
2468 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2469 environment_stack[depth].erase();
2470 environment_inner[depth].erase();
2473 if (depth == par->params().depth()
2474 && environment_stack[depth] != style->latexname()
2475 && !environment_stack[depth].empty()) {
2476 if (environment_inner[depth] != "!-- --") {
2477 item_name= "listitem";
2478 sgml::closeTag(ofs, command_depth+depth, false, item_name);
2479 if (environment_inner[depth] == "varlistentry")
2480 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2483 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2485 environment_stack[depth].erase();
2486 environment_inner[depth].erase();
2489 // Write opening SGML tags.
2490 switch (style->latextype) {
2491 case LATEX_PARAGRAPH:
2492 sgml::openTag(ofs, depth + command_depth,
2493 false, style->latexname());
2499 _("Error: Wrong depth for LatexType Command.\n"));
2501 command_name = style->latexname();
2503 sgmlparam = style->latexparam();
2504 c_params = split(sgmlparam, c_depth,'|');
2506 cmd_depth = lyx::atoi(c_depth);
2509 if (cmd_depth < command_base) {
2510 for (Paragraph::depth_type j = command_depth;
2511 j >= command_base; --j) {
2512 sgml::closeTag(ofs, j, false, command_stack[j]);
2515 command_depth = command_base = cmd_depth;
2516 } else if (cmd_depth <= command_depth) {
2517 for (int j = command_depth;
2518 j >= int(cmd_depth); --j) {
2519 sgml::closeTag(ofs, j, false, command_stack[j]);
2522 command_depth = cmd_depth;
2524 command_depth = cmd_depth;
2526 command_depth = command_base = cmd_depth;
2527 command_flag = true;
2529 if (command_stack.size() == command_depth + 1)
2530 command_stack.push_back(string());
2531 command_stack[command_depth] = command_name;
2533 // treat label as a special case for
2534 // more WYSIWYM handling.
2535 // This is a hack while paragraphs can't have
2536 // attributes, like id in this case.
2537 if (par->isInset(0)) {
2538 Inset * inset = par->getInset(0);
2539 Inset::Code lyx_code = inset->lyxCode();
2540 if (lyx_code == Inset::LABEL_CODE) {
2541 command_name += " id=\"";
2542 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2543 command_name += '"';
2548 sgml::openTag(ofs, depth + command_depth, false, command_name);
2550 item_name = c_params.empty() ? "title" : c_params;
2551 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
2554 case LATEX_ENVIRONMENT:
2555 case LATEX_ITEM_ENVIRONMENT:
2556 if (depth < par->params().depth()) {
2557 depth = par->params().depth();
2558 environment_stack[depth].erase();
2561 if (environment_stack[depth] != style->latexname()) {
2562 if (environment_stack.size() == depth + 1) {
2563 environment_stack.push_back("!-- --");
2564 environment_inner.push_back("!-- --");
2566 environment_stack[depth] = style->latexname();
2567 environment_inner[depth] = "!-- --";
2568 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
2570 if (environment_inner[depth] != "!-- --") {
2571 item_name= "listitem";
2572 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2573 if (environment_inner[depth] == "varlistentry")
2574 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2578 if (style->latextype == LATEX_ENVIRONMENT) {
2579 if (!style->latexparam().empty()) {
2580 if (style->latexparam() == "CDATA")
2583 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
2588 desc_on = (style->labeltype == LABEL_MANUAL);
2590 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
2591 sgml::openTag(ofs, depth + 1 + command_depth,
2592 false, environment_inner[depth]);
2594 item_name = desc_on ? "term" : "para";
2595 sgml::openTag(ofs, depth + 1 + command_depth,
2599 sgml::openTag(ofs, depth + command_depth,
2600 false, style->latexname());
2604 simpleDocBookOnePar(ofs, par, desc_on,
2605 depth + 1 + command_depth);
2609 // write closing SGML tags
2610 switch (style->latextype) {
2612 end_tag = c_params.empty() ? "title" : c_params;
2613 sgml::closeTag(ofs, depth + command_depth,
2616 case LATEX_ENVIRONMENT:
2617 if (!style->latexparam().empty()) {
2618 if (style->latexparam() == "CDATA")
2621 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
2624 case LATEX_ITEM_ENVIRONMENT:
2625 if (desc_on == 1) break;
2627 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
2629 case LATEX_PARAGRAPH:
2630 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2633 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2639 for (int d = depth; d >= 0; --d) {
2640 if (!environment_stack[depth].empty()) {
2641 if (environment_inner[depth] != "!-- --") {
2642 item_name = "listitem";
2643 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2644 if (environment_inner[depth] == "varlistentry")
2645 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2648 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2652 for (int j = command_depth; j >= 0 ; --j)
2653 if (!command_stack[j].empty()) {
2654 sgml::closeTag(ofs, j, false, command_stack[j]);
2659 sgml::closeTag(ofs, 0, false, top_element);
2662 // How to check for successful close
2664 // we want this to be true outside previews (for insetexternal)
2669 void Buffer::simpleDocBookOnePar(ostream & os,
2670 Paragraph * par, int & desc_on,
2671 Paragraph::depth_type depth) const
2673 bool emph_flag = false;
2675 LyXLayout_ptr const & style = par->layout();
2677 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
2679 int char_line_count = depth;
2680 //if (!style.free_spacing)
2681 // os << string(depth,' ');
2683 // parsing main loop
2684 for (pos_type i = 0; i < par->size(); ++i) {
2685 LyXFont font = par->getFont(params, i);
2687 // handle <emphasis> tag
2688 if (font_old.emph() != font.emph()) {
2689 if (font.emph() == LyXFont::ON) {
2690 if (style->latexparam() == "CDATA")
2693 if (style->latexparam() == "CDATA")
2697 if (style->latexparam() == "CDATA")
2699 os << "</emphasis>";
2700 if (style->latexparam() == "CDATA")
2707 if (par->isInset(i)) {
2708 Inset * inset = par->getInset(i);
2709 // don't print the inset in position 0 if desc_on == 3 (label)
2710 if (i || desc_on != 3) {
2711 if (style->latexparam() == "CDATA")
2713 inset->docbook(this, os, false);
2714 if (style->latexparam() == "CDATA")
2718 char c = par->getChar(i);
2721 boost::tie(ws, str) = sgml::escapeChar(c);
2723 if (style->pass_thru) {
2725 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
2727 } else if (desc_on ==1) {
2729 os << "\n</term><listitem><para>";
2739 if (style->latexparam() == "CDATA")
2741 os << "</emphasis>";
2742 if (style->latexparam() == "CDATA")
2746 // resets description flag correctly
2748 // <term> not closed...
2749 os << "</term>\n<listitem><para> </para>";
2751 if (style->free_spacing)
2756 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2757 // Other flags: -wall -v0 -x
2758 int Buffer::runChktex()
2760 if (!users->text) return 0;
2762 users->owner()->busy(true);
2764 // get LaTeX-Filename
2765 string const name = getLatexName();
2766 string path = filePath();
2768 string const org_path = path;
2769 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2773 Path p(path); // path to LaTeX file
2774 users->owner()->message(_("Running chktex..."));
2776 // Remove all error insets
2777 bool const removedErrorInsets = users->removeAutoInsets();
2779 // Generate the LaTeX file if neccessary
2780 makeLaTeXFile(name, org_path, false);
2783 Chktex chktex(lyxrc.chktex_command, name, filePath());
2784 int res = chktex.run(terr); // run chktex
2787 Alert::alert(_("chktex did not work!"),
2788 _("Could not run with file:"), name);
2789 } else if (res > 0) {
2790 // Insert all errors as errors boxes
2791 users->insertErrors(terr);
2794 // if we removed error insets before we ran chktex or if we inserted
2795 // error insets after we ran chktex, this must be run:
2796 if (removedErrorInsets || res) {
2797 #warning repaint needed here, or do you mean update() ?
2801 users->owner()->busy(false);
2807 void Buffer::validate(LaTeXFeatures & features) const
2809 LyXTextClass const & tclass = params.getLyXTextClass();
2811 if (params.tracking_changes) {
2812 features.require("dvipost");
2813 features.require("color");
2816 // AMS Style is at document level
2817 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
2818 features.require("amsmath");
2820 for_each(paragraphs.begin(), paragraphs.end(),
2821 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2823 // the bullet shapes are buffer level not paragraph level
2824 // so they are tested here
2825 for (int i = 0; i < 4; ++i) {
2826 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2827 int const font = params.user_defined_bullets[i].getFont();
2829 int const c = params
2830 .user_defined_bullets[i]
2837 features.require("latexsym");
2839 } else if (font == 1) {
2840 features.require("amssymb");
2841 } else if ((font >= 2 && font <= 5)) {
2842 features.require("pifont");
2847 if (lyxerr.debugging(Debug::LATEX)) {
2848 features.showStruct();
2853 vector<string> const Buffer::getLabelList() const
2855 /// if this is a child document and the parent is already loaded
2856 /// Use the parent's list instead [ale990407]
2857 if (!params.parentname.empty()
2858 && bufferlist.exists(params.parentname)) {
2859 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2861 return tmp->getLabelList();
2864 vector<string> label_list;
2865 for (inset_iterator it = inset_const_iterator_begin();
2866 it != inset_const_iterator_end(); ++it) {
2867 vector<string> const l = it->getLabelList();
2868 label_list.insert(label_list.end(), l.begin(), l.end());
2874 // This is also a buffer property (ale)
2875 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2877 /// if this is a child document and the parent is already loaded
2878 /// use the parent's list instead [ale990412]
2879 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2880 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2882 tmp->fillWithBibKeys(keys);
2887 for (inset_iterator it = inset_const_iterator_begin();
2888 it != inset_const_iterator_end(); ++it) {
2889 if (it->lyxCode() == Inset::BIBTEX_CODE)
2890 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2891 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2892 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2893 else if (it->lyxCode() == Inset::BIBKEY_CODE) {
2894 InsetBibKey & bib = static_cast<InsetBibKey &>(*it);
2895 string const key = bib.getContents();
2896 string const opt = bib.getOptions();
2897 string const ref; // = pit->asString(this, false);
2898 string const info = opt + "TheBibliographyRef" + ref;
2899 keys.push_back(pair<string, string>(key, info));
2905 bool Buffer::isDepClean(string const & name) const
2907 DepClean::const_iterator it = dep_clean_.find(name);
2908 if (it == dep_clean_.end())
2914 void Buffer::markDepClean(string const & name)
2916 dep_clean_[name] = true;
2920 bool Buffer::dispatch(string const & command, bool * result)
2922 // Split command string into command and argument
2924 string line = ltrim(command);
2925 string const arg = trim(split(line, cmd, ' '));
2927 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2931 bool Buffer::dispatch(int action, string const & argument, bool * result)
2933 bool dispatched = true;
2937 bool const tmp = Exporter::Export(this, argument, false);
2950 void Buffer::resizeInsets(BufferView * bv)
2952 /// then remove all LyXText in text-insets
2953 for_each(paragraphs.begin(), paragraphs.end(),
2954 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2958 void Buffer::redraw()
2960 #warning repaint needed here, or do you mean update() ?
2966 void Buffer::changeLanguage(Language const * from, Language const * to)
2969 ParIterator end = par_iterator_end();
2970 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2971 (*it)->changeLanguage(params, from, to);
2975 bool Buffer::isMultiLingual()
2977 ParIterator end = par_iterator_end();
2978 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2979 if ((*it)->isMultiLingual(params))
2986 void Buffer::inset_iterator::setParagraph()
2988 while (pit != pend) {
2989 it = pit->insetlist.begin();
2990 if (it != pit->insetlist.end())
2997 Inset * Buffer::getInsetFromID(int id_arg) const
2999 for (inset_iterator it = inset_const_iterator_begin();
3000 it != inset_const_iterator_end(); ++it)
3002 if (it->id() == id_arg)
3004 Inset * in = it->getInsetFromID(id_arg);
3012 Paragraph * Buffer::getParFromID(int id) const
3017 // why should we allow < 0 ??
3018 //lyx::Assert(id >= 0);
3020 ParConstIterator it(par_iterator_begin());
3021 ParConstIterator end(par_iterator_end());
3023 for (; it != end; ++it) {
3024 // go on then, show me how to remove
3026 if ((*it)->id() == id) {
3027 return const_cast<Paragraph*>(*it);
3035 ParIterator Buffer::par_iterator_begin()
3037 return ParIterator(&*(paragraphs.begin()));
3041 ParIterator Buffer::par_iterator_end()
3043 return ParIterator();
3046 ParConstIterator Buffer::par_iterator_begin() const
3048 return ParConstIterator(&*(paragraphs.begin()));
3052 ParConstIterator Buffer::par_iterator_end() const
3054 return ParConstIterator();
3059 void Buffer::addUser(BufferView * u)
3065 void Buffer::delUser(BufferView *)
3071 Language const * Buffer::getLanguage() const
3073 return params.language;
3077 bool Buffer::isClean() const
3083 bool Buffer::isBakClean() const
3089 void Buffer::markClean() const
3095 // if the .lyx file has been saved, we don't need an
3101 void Buffer::markBakClean()
3107 void Buffer::setUnnamed(bool flag)
3113 bool Buffer::isUnnamed()
3119 void Buffer::markDirty()
3127 DepClean::iterator it = dep_clean_.begin();
3128 DepClean::const_iterator const end = dep_clean_.end();
3130 for (; it != end; ++it) {
3136 string const & Buffer::fileName() const
3142 string const & Buffer::filePath() const
3148 bool Buffer::isReadonly() const
3154 BufferView * Buffer::getUser() const
3160 void Buffer::setParentName(string const & name)
3162 params.parentname = name;
3166 Buffer::inset_iterator::inset_iterator()
3171 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
3178 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
3182 if (it == pit->insetlist.end()) {
3191 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
3193 inset_iterator tmp = *this;
3199 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
3201 return *it.getInset();
3205 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
3207 return it.getInset();
3211 Paragraph * Buffer::inset_iterator::getPar()
3217 lyx::pos_type Buffer::inset_iterator::getPos() const
3223 bool operator==(Buffer::inset_iterator const & iter1,
3224 Buffer::inset_iterator const & iter2)
3226 return iter1.pit == iter2.pit
3227 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
3231 bool operator!=(Buffer::inset_iterator const & iter1,
3232 Buffer::inset_iterator const & iter2)
3234 return !(iter1 == iter2);