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;
140 using lyx::textclass_type;
142 // all these externs should eventually be removed.
143 extern BufferList bufferlist;
147 const int LYX_FORMAT = 222;
151 Buffer::Buffer(string const & file, bool ronly)
152 : niceFile(true), lyx_clean(true), bak_clean(true),
153 unnamed(false), read_only(ronly),
154 filename_(file), users(0)
156 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
157 filepath_ = OnlyPath(file);
159 if (read_only || lyxrc.use_tempdir) {
160 tmppath = CreateBufferTmpDir();
165 // set initial author
166 authorlist.record(Author(lyxrc.user_name, lyxrc.user_email));
172 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
173 // here the buffer should take care that it is
174 // saved properly, before it goes into the void.
176 // make sure that views using this buffer
181 if (!tmppath.empty()) {
182 DestroyBufferTmpDir(tmppath);
187 // Remove any previewed LaTeX snippets assocoated with this buffer.
188 grfx::Previews::get().removeLoader(this);
192 string const Buffer::getLatexName(bool no_path) const
194 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
196 return OnlyFilename(name);
202 pair<Buffer::LogType, string> const Buffer::getLogName() const
204 string const filename = getLatexName(false);
206 if (filename.empty())
207 return make_pair(Buffer::latexlog, string());
209 string path = OnlyPath(filename);
211 if (lyxrc.use_tempdir || !IsDirWriteable(path))
214 string const fname = AddName(path,
215 OnlyFilename(ChangeExtension(filename,
218 AddName(path, OnlyFilename(
219 ChangeExtension(filename,
220 formats.extension("literate") + ".out")));
222 // If no Latex log or Build log is newer, show Build log
224 FileInfo const f_fi(fname);
225 FileInfo const b_fi(bname);
228 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
229 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
230 return make_pair(Buffer::buildlog, bname);
232 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
233 return make_pair(Buffer::latexlog, fname);
237 void Buffer::setReadonly(bool flag)
239 if (read_only != flag) {
242 users->owner()->getDialogs().updateBufferDependent(false);
247 AuthorList & Buffer::authors()
253 /// Update window titles of all users
254 // Should work on a list
255 void Buffer::updateTitles() const
258 users->owner()->updateWindowTitle();
262 /// Reset autosave timer of all users
263 // Should work on a list
264 void Buffer::resetAutosaveTimers() const
267 users->owner()->resetAutosaveTimer();
271 void Buffer::setFileName(string const & newfile)
273 filename_ = MakeAbsPath(newfile);
274 filepath_ = OnlyPath(filename_);
275 setReadonly(IsFileWriteable(filename_) == 0);
280 // We'll remove this later. (Lgb)
283 string last_inset_read;
286 #warning And _why_ is this here? (Lgb)
290 vector<int> author_ids;
295 // candidate for move to BufferView
296 // (at least some parts in the beginning of the func)
299 // changed to be public and have one parameter
300 // if par = 0 normal behavior
301 // else insert behavior
302 // Returns false if "\the_end" is not read (Asger)
303 bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
310 Paragraph::depth_type depth = 0;
311 bool the_end_read = false;
313 Paragraph * first_par = 0;
314 LyXFont font(LyXFont::ALL_INHERIT, params.language);
318 par->layout(params.getLyXTextClass().defaultLayout());
320 // We are inserting into an existing document
321 users->text->breakParagraph(users);
322 first_par = users->text->ownerParagraph();
325 // We don't want to adopt the parameters from the
326 // document we insert, so we skip until the text begins:
329 string const pretoken = lex.getString();
330 if (pretoken == "\\layout") {
331 lex.pushToken(pretoken);
339 string const token = lex.getString();
341 if (token.empty()) continue;
343 lyxerr[Debug::PARSER] << "Handling token: `"
344 << token << '\'' << endl;
347 parseSingleLyXformat2Token(lex, par, first_par,
355 paragraphs.set(first_par);
357 if (unknown_layouts > 0) {
358 string s = _("Couldn't set the layout for ");
359 if (unknown_layouts == 1) {
360 s += _("one paragraph");
362 s += tostr(unknown_layouts);
363 s += _(" paragraphs");
366 Alert::alert(_("Textclass Loading Error!"), s,
367 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
369 Alert::alert(_("Textclass Loading Error!"), s,
370 _("When reading ") + fileName());
374 if (unknown_tokens > 0) {
375 string s = _("Encountered ");
376 if (unknown_tokens == 1) {
377 s += _("one unknown token");
379 s += tostr(unknown_tokens);
380 s += _(" unknown tokens");
383 Alert::alert(_("Textclass Loading Error!"), s,
384 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
386 Alert::alert(_("Textclass Loading Error!"), s,
387 _("When reading ") + fileName());
396 // This stuff is, in the traditional LyX terminology, Super UGLY
397 // but this code is too b0rken to admit of a better solution yet
398 Change current_change;
403 Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
404 Paragraph *& first_par,
405 string const & token, int & pos,
406 Paragraph::depth_type & depth,
410 bool the_end_read = false;
412 // The order of the tags tested may seem unnatural, but this
413 // has been done in order to reduce the number of string
414 // comparisons needed to recognize a given token. This leads
415 // on large documents like UserGuide to a reduction of a
417 if (token[0] != '\\') {
418 for (string::const_iterator cit = token.begin();
419 cit != token.end(); ++cit) {
420 par->insertChar(pos, (*cit), font, current_change);
423 } else if (token == "\\layout") {
424 // reset the font as we start a new layout and if the font is
425 // not ALL_INHERIT,document_language then it will be set to the
426 // right values after this tag (Jug 20020420)
427 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
430 string layoutname = lex.getString();
432 LyXTextClass const & tclass = params.getLyXTextClass();
434 if (layoutname.empty()) {
435 layoutname = tclass.defaultLayoutName();
437 bool hasLayout = tclass.hasLayout(layoutname);
439 lyxerr << "Layout '" << layoutname << "' does not"
440 << " exist in textclass '" << tclass.name()
442 lyxerr << "Trying to use default layout instead."
444 layoutname = tclass.defaultLayoutName();
448 // The is the compability reading of layout caption.
449 // It can be removed in LyX version 1.3.0. (Lgb)
450 if (compare_ascii_no_case(layoutname, "caption") == 0) {
451 // We expect that the par we are now working on is
452 // really inside a InsetText inside a InsetFloat.
453 // We also know that captions can only be
454 // one paragraph. (Lgb)
456 // We should now read until the next "\layout"
458 // This is probably not good enough, what if the
459 // caption is the last par in the document (Lgb)
460 istream & ist = lex.getStream();
466 if (prefixIs(line, "\\layout")) {
470 if (prefixIs(line, "\\begin_inset"))
472 if (prefixIs(line, "\\end_inset")) {
483 // Now we should have the whole layout in ss
484 // we should now be able to give this to the
486 ss << "\\end_inset\n";
488 // This seems like a bug in stringstream.
489 // We really should be able to use ss
491 istringstream is(ss.str());
493 tmplex.setStream(is);
494 Inset * inset = new InsetCaption;
495 inset->Read(this, tmplex);
496 par->InsertInset(pos, inset, font);
503 par = new Paragraph(par);
504 par->layout(params.getLyXTextClass().defaultLayout());
505 if (params.tracking_changes)
509 par->layout(params.getLyXTextClass()[layoutname]);
510 // Test whether the layout is obsolete.
511 LyXLayout_ptr const & layout = par->layout();
512 if (!layout->obsoleted_by().empty())
513 par->layout(params.getLyXTextClass()[layout->obsoleted_by()]);
514 par->params().depth(depth);
519 } else if (token == "\\end_inset") {
520 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
521 << "Last inset read was: " << last_inset_read
523 // Simply ignore this. The insets do not have
525 // But insets should read it, it is a part of
526 // the inset isn't it? Lgb.
527 } else if (token == "\\begin_inset") {
528 readInset(lex, par, pos, font);
529 } else if (token == "\\family") {
531 font.setLyXFamily(lex.getString());
532 } else if (token == "\\series") {
534 font.setLyXSeries(lex.getString());
535 } else if (token == "\\shape") {
537 font.setLyXShape(lex.getString());
538 } else if (token == "\\size") {
540 font.setLyXSize(lex.getString());
541 } else if (token == "\\lang") {
543 string const tok = lex.getString();
544 Language const * lang = languages.getLanguage(tok);
546 font.setLanguage(lang);
548 font.setLanguage(params.language);
549 lex.printError("Unknown language `$$Token'");
551 } else if (token == "\\numeric") {
553 font.setNumber(font.setLyXMisc(lex.getString()));
554 } else if (token == "\\emph") {
556 font.setEmph(font.setLyXMisc(lex.getString()));
557 } else if (token == "\\bar") {
559 string const tok = lex.getString();
560 // This is dirty, but gone with LyX3. (Asger)
562 font.setUnderbar(LyXFont::ON);
563 else if (tok == "no")
564 font.setUnderbar(LyXFont::OFF);
565 else if (tok == "default")
566 font.setUnderbar(LyXFont::INHERIT);
568 lex.printError("Unknown bar font flag "
570 } else if (token == "\\noun") {
572 font.setNoun(font.setLyXMisc(lex.getString()));
573 } else if (token == "\\color") {
575 font.setLyXColor(lex.getString());
576 } else if (token == "\\SpecialChar") {
577 LyXLayout_ptr const & layout = par->layout();
579 // Insets don't make sense in a free-spacing context! ---Kayvan
580 if (layout->free_spacing || par->isFreeSpacing()) {
583 string const next_token = lex.getString();
584 if (next_token == "\\-") {
585 par->insertChar(pos, '-', font, current_change);
586 } else if (next_token == "~") {
587 par->insertChar(pos, ' ', font, current_change);
589 lex.printError("Token `$$Token' "
591 "paragraph layout!");
596 Inset * inset = new InsetSpecialChar;
597 inset->read(this, lex);
598 par->insertInset(pos, inset, font, current_change);
601 } else if (token == "\\i") {
602 Inset * inset = new InsetLatexAccent;
603 inset->read(this, lex);
604 par->insertInset(pos, inset, font, current_change);
606 } else if (token == "\\backslash") {
607 par->insertChar(pos, '\\', font, current_change);
609 } else if (token == "\\begin_deeper") {
611 } else if (token == "\\end_deeper") {
613 lex.printError("\\end_deeper: "
614 "depth is already null");
618 } else if (token == "\\begin_preamble") {
619 params.readPreamble(lex);
620 } else if (token == "\\textclass") {
622 pair<bool, textclass_type> pp =
623 textclasslist.NumberOfClass(lex.getString());
625 params.textclass = pp.second;
628 Alert::alert(_("Textclass error"),
629 boost::io::str(boost::format(_("The document uses an unknown textclass \"%1$s\".")) % lex.getString()),
630 _("-- substituting default."));
633 _("Textclass error"),
634 _("The document uses an unknown textclass ")
636 _("-- substituting default."));
638 params.textclass = 0;
640 if (!params.getLyXTextClass().load()) {
641 // if the textclass wasn't loaded properly
642 // we need to either substitute another
643 // or stop loading the file.
644 // I can substitute but I don't see how I can
645 // stop loading... ideas?? ARRae980418
647 Alert::alert(_("Textclass Loading Error!"),
648 boost::io::str(boost::format(_("Can't load textclass %1$s")) %
649 params.getLyXTextClass().name()),
650 _("-- substituting default."));
652 Alert::alert(_("Textclass Loading Error!"),
653 _("Can't load textclass ")
654 + params.getLyXTextClass().name(),
655 _("-- substituting default."));
657 params.textclass = 0;
659 } else if (token == "\\options") {
661 params.options = lex.getString();
662 } else if (token == "\\language") {
663 params.readLanguage(lex);
664 } else if (token == "\\fontencoding") {
666 } else if (token == "\\inputencoding") {
668 params.inputenc = lex.getString();
669 } else if (token == "\\graphics") {
670 params.readGraphicsDriver(lex);
671 } else if (token == "\\fontscheme") {
673 params.fonts = lex.getString();
674 } else if (token == "\\noindent") {
675 par->params().noindent(true);
676 } else if (token == "\\leftindent") {
678 LyXLength value(lex.getString());
679 par->params().leftIndent(value);
680 } else if (token == "\\fill_top") {
681 par->params().spaceTop(VSpace(VSpace::VFILL));
682 } else if (token == "\\fill_bottom") {
683 par->params().spaceBottom(VSpace(VSpace::VFILL));
684 } else if (token == "\\line_top") {
685 par->params().lineTop(true);
686 } else if (token == "\\line_bottom") {
687 par->params().lineBottom(true);
688 } else if (token == "\\pagebreak_top") {
689 par->params().pagebreakTop(true);
690 } else if (token == "\\pagebreak_bottom") {
691 par->params().pagebreakBottom(true);
692 } else if (token == "\\start_of_appendix") {
693 par->params().startOfAppendix(true);
694 } else if (token == "\\paragraph_separation") {
695 int tmpret = lex.findToken(string_paragraph_separation);
698 params.paragraph_separation =
699 static_cast<BufferParams::PARSEP>(tmpret);
700 } else if (token == "\\defskip") {
702 params.defskip = VSpace(lex.getString());
703 } else if (token == "\\quotes_language") {
704 int tmpret = lex.findToken(string_quotes_language);
707 InsetQuotes::quote_language tmpl =
708 InsetQuotes::EnglishQ;
711 tmpl = InsetQuotes::EnglishQ;
714 tmpl = InsetQuotes::SwedishQ;
717 tmpl = InsetQuotes::GermanQ;
720 tmpl = InsetQuotes::PolishQ;
723 tmpl = InsetQuotes::FrenchQ;
726 tmpl = InsetQuotes::DanishQ;
729 params.quotes_language = tmpl;
730 } else if (token == "\\quotes_times") {
732 switch (lex.getInteger()) {
734 params.quotes_times = InsetQuotes::SingleQ;
737 params.quotes_times = InsetQuotes::DoubleQ;
740 } else if (token == "\\papersize") {
741 int tmpret = lex.findToken(string_papersize);
745 params.papersize2 = tmpret;
746 } else if (token == "\\paperpackage") {
747 int tmpret = lex.findToken(string_paperpackages);
750 params.paperpackage = BufferParams::PACKAGE_NONE;
752 params.paperpackage = tmpret;
753 } else if (token == "\\use_geometry") {
755 params.use_geometry = lex.getInteger();
756 } else if (token == "\\use_amsmath") {
758 params.use_amsmath = lex.getInteger();
759 } else if (token == "\\use_natbib") {
761 params.use_natbib = lex.getInteger();
762 } else if (token == "\\use_numerical_citations") {
764 params.use_numerical_citations = lex.getInteger();
765 } else if (token == "\\tracking_changes") {
767 params.tracking_changes = lex.getInteger();
768 // mark the first paragraph
769 if (params.tracking_changes)
771 } else if (token == "\\author") {
773 istringstream ss(lex.getString());
776 int aid(authorlist.record(a));
777 lyxerr << "aid is " << aid << endl;
778 lyxerr << "listed aid is " << author_ids.size() << endl;
779 author_ids.push_back(authorlist.record(a));
780 } else if (token == "\\paperorientation") {
781 int tmpret = lex.findToken(string_orientation);
785 static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
786 } else if (token == "\\paperwidth") {
788 params.paperwidth = lex.getString();
789 } else if (token == "\\paperheight") {
791 params.paperheight = lex.getString();
792 } else if (token == "\\leftmargin") {
794 params.leftmargin = lex.getString();
795 } else if (token == "\\topmargin") {
797 params.topmargin = lex.getString();
798 } else if (token == "\\rightmargin") {
800 params.rightmargin = lex.getString();
801 } else if (token == "\\bottommargin") {
803 params.bottommargin = lex.getString();
804 } else if (token == "\\headheight") {
806 params.headheight = lex.getString();
807 } else if (token == "\\headsep") {
809 params.headsep = lex.getString();
810 } else if (token == "\\footskip") {
812 params.footskip = lex.getString();
813 } else if (token == "\\paperfontsize") {
815 params.fontsize = rtrim(lex.getString());
816 } else if (token == "\\papercolumns") {
818 params.columns = lex.getInteger();
819 } else if (token == "\\papersides") {
821 switch (lex.getInteger()) {
823 case 1: params.sides = LyXTextClass::OneSide; break;
824 case 2: params.sides = LyXTextClass::TwoSides; break;
826 } else if (token == "\\paperpagestyle") {
828 params.pagestyle = rtrim(lex.getString());
829 } else if (token == "\\bullet") {
831 int const index = lex.getInteger();
833 int temp_int = lex.getInteger();
834 params.user_defined_bullets[index].setFont(temp_int);
835 params.temp_bullets[index].setFont(temp_int);
837 temp_int = lex.getInteger();
838 params.user_defined_bullets[index].setCharacter(temp_int);
839 params.temp_bullets[index].setCharacter(temp_int);
841 temp_int = lex.getInteger();
842 params.user_defined_bullets[index].setSize(temp_int);
843 params.temp_bullets[index].setSize(temp_int);
845 string const temp_str = lex.getString();
846 if (temp_str != "\\end_bullet") {
847 // this element isn't really necessary for
848 // parsing but is easier for humans
849 // to understand bullets. Put it back and
850 // set a debug message?
851 lex.printError("\\end_bullet expected, got" + temp_str);
852 //how can I put it back?
854 } else if (token == "\\bulletLaTeX") {
855 // The bullet class should be able to read this.
857 int const index = lex.getInteger();
859 string temp_str = lex.getString();
861 while (temp_str != "\\end_bullet") {
862 // this loop structure is needed when user
863 // enters an empty string since the first
864 // thing returned will be the \\end_bullet
866 // if the LaTeX entry has spaces. Each element
867 // therefore needs to be read in turn
870 temp_str = lex.getString();
873 params.user_defined_bullets[index].setText(sum_str);
874 params.temp_bullets[index].setText(sum_str);
875 } else if (token == "\\secnumdepth") {
877 params.secnumdepth = lex.getInteger();
878 } else if (token == "\\tocdepth") {
880 params.tocdepth = lex.getInteger();
881 } else if (token == "\\spacing") {
883 string const tmp = rtrim(lex.getString());
884 Spacing::Space tmp_space = Spacing::Default;
886 if (tmp == "single") {
887 tmp_space = Spacing::Single;
888 } else if (tmp == "onehalf") {
889 tmp_space = Spacing::Onehalf;
890 } else if (tmp == "double") {
891 tmp_space = Spacing::Double;
892 } else if (tmp == "other") {
894 tmp_space = Spacing::Other;
895 tmp_val = lex.getFloat();
897 lex.printError("Unknown spacing token: '$$Token'");
899 // Small hack so that files written with klyx will be
902 par->params().spacing(Spacing(tmp_space, tmp_val));
904 params.spacing.set(tmp_space, tmp_val);
906 } else if (token == "\\paragraph_spacing") {
908 string const tmp = rtrim(lex.getString());
909 if (tmp == "single") {
910 par->params().spacing(Spacing(Spacing::Single));
911 } else if (tmp == "onehalf") {
912 par->params().spacing(Spacing(Spacing::Onehalf));
913 } else if (tmp == "double") {
914 par->params().spacing(Spacing(Spacing::Double));
915 } else if (tmp == "other") {
917 par->params().spacing(Spacing(Spacing::Other,
920 lex.printError("Unknown spacing token: '$$Token'");
922 } else if (token == "\\float_placement") {
924 params.float_placement = lex.getString();
925 } else if (token == "\\align") {
926 int tmpret = lex.findToken(string_align);
927 if (tmpret == -1) ++tmpret;
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 == "\\hfill") {
961 par->insertChar(pos, Paragraph::META_HFILL, font, current_change);
963 } else if (token == "\\change_unchanged") {
964 // Hack ! Needed for empty paragraphs :/
967 current_change = Change(Change::UNCHANGED);
968 } else if (token == "\\change_inserted") {
970 istringstream istr(lex.getString());
975 current_change = Change(Change::INSERTED, author_ids[aid], ct);
976 } else if (token == "\\change_deleted") {
978 istringstream istr(lex.getString());
983 current_change = Change(Change::DELETED, author_ids[aid], ct);
984 } else if (token == "\\bibitem") { // ale970302
986 InsetCommandParams p("bibitem", "dummy");
987 par->bibkey = new InsetBibKey(p);
989 par->bibkey->read(this, lex);
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) const
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(params, 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 InsetBibKey(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 bool alreadyread = false;
1139 if (tmptok == "Quotes") {
1140 inset = new InsetQuotes;
1141 } else if (tmptok == "External") {
1142 inset = new InsetExternal;
1143 } else if (tmptok == "FormulaMacro") {
1144 inset = new InsetFormulaMacro;
1145 } else if (tmptok == "Formula") {
1146 inset = new InsetFormula;
1147 } else if (tmptok == "Figure") { // Backward compatibility
1148 // inset = new InsetFig(100, 100, *this);
1149 inset = new InsetGraphics;
1150 } else if (tmptok == "Graphics") {
1151 inset = new InsetGraphics;
1152 } else if (tmptok == "Info") {// backwards compatibility
1153 inset = new InsetNote(this,
1154 lex.getLongString("\\end_inset"),
1157 } else if (tmptok == "Note") {
1158 inset = new InsetNote(params);
1159 } else if (tmptok == "Include") {
1160 InsetCommandParams p("Include");
1161 inset = new InsetInclude(p, *this);
1162 } else if (tmptok == "ERT") {
1163 inset = new InsetERT(params);
1164 } else if (tmptok == "Tabular") {
1165 inset = new InsetTabular(*this);
1166 } else if (tmptok == "Text") {
1167 inset = new InsetText(params);
1168 } else if (tmptok == "Foot") {
1169 inset = new InsetFoot(params);
1170 } else if (tmptok == "Marginal") {
1171 inset = new InsetMarginal(params);
1172 } else if (tmptok == "OptArg") {
1173 inset = new InsetOptArg(params);
1174 } else if (tmptok == "Minipage") {
1175 inset = new InsetMinipage(params);
1176 } else if (tmptok == "Float") {
1178 string tmptok = lex.getString();
1179 inset = new InsetFloat(params, tmptok);
1180 } else if (tmptok == "Wrap") {
1182 string tmptok = lex.getString();
1183 inset = new InsetWrap(params, tmptok);
1185 } else if (tmptok == "List") {
1186 inset = new InsetList;
1187 } else if (tmptok == "Theorem") {
1188 inset = new InsetList;
1190 } else if (tmptok == "Caption") {
1191 inset = new InsetCaption(params);
1192 } else if (tmptok == "FloatList") {
1193 inset = new InsetFloatList;
1196 if (inset && !alreadyread) inset->read(this, lex);
1200 par->insertInset(pos, inset, font, current_change);
1206 bool Buffer::readFile(LyXLex & lex, string const & filename, Paragraph * par)
1210 string const token(lex.getString());
1211 if (token == "\\lyxformat") { // the first token _must_ be...
1213 string tmp_format = lex.getString();
1214 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
1215 // if present remove ".," from string.
1216 string::size_type dot = tmp_format.find_first_of(".,");
1217 //lyxerr << " dot found at " << dot << endl;
1218 if (dot != string::npos)
1219 tmp_format.erase(dot, 1);
1220 file_format = strToInt(tmp_format);
1221 //lyxerr << "format: " << file_format << endl;
1222 if (file_format == LYX_FORMAT) {
1224 } else if (file_format > LYX_FORMAT) {
1226 Alert::alert(_("Warning!"),
1227 _("The file was created with a newer version of "
1228 "LyX. This is likely to cause problems."));
1230 } else if (file_format < LYX_FORMAT) {
1232 if (file_format < 200) {
1233 Alert::alert(_("ERROR!"),
1234 _("Old LyX file format found. "
1235 "Use LyX 0.10.x to read this!"));
1237 } else if (!filename.empty()) {
1239 LibFileSearch("lyx2lyx", "lyx2lyx");
1240 if (command.empty()) {
1241 Alert::alert(_("ERROR!"),
1242 _("Can't find conversion script."));
1246 +tostr(LYX_FORMAT) + ' '
1247 + QuoteName(filename);
1248 lyxerr[Debug::INFO] << "Running '"
1251 cmd_ret const ret = RunCommand(command);
1253 Alert::alert(_("ERROR!"),
1254 _("An error occured while "
1255 "running the conversion script."));
1258 istringstream is(STRCONV(ret.second));
1259 LyXLex tmplex(0, 0);
1260 tmplex.setStream(is);
1261 return readFile(tmplex, string(), par);
1263 // This code is reached if lyx2lyx failed (for
1264 // some reason) to change the file format of
1270 bool the_end = readLyXformat2(lex, par);
1271 params.setPaperStuff();
1274 Alert::alert(_("Warning!"),
1275 _("Reading of document is not complete"),
1276 _("Maybe the document is truncated"));
1279 } else { // "\\lyxformat" not found
1280 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
1283 Alert::alert(_("ERROR!"), _("Unable to read file!"));
1288 // Should probably be moved to somewhere else: BufferView? LyXView?
1289 bool Buffer::save() const
1291 // We don't need autosaves in the immediate future. (Asger)
1292 resetAutosaveTimers();
1296 if (lyxrc.make_backup) {
1297 s = fileName() + '~';
1298 if (!lyxrc.backupdir_path.empty())
1299 s = AddName(lyxrc.backupdir_path,
1300 subst(os::slashify_path(s),'/','!'));
1302 // Rename is the wrong way of making a backup,
1303 // this is the correct way.
1304 /* truss cp fil fil2:
1305 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1306 stat("LyXVC.lyx", 0xEFFFF688) = 0
1307 open("LyXVC.lyx", O_RDONLY) = 3
1308 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1309 fstat(4, 0xEFFFF508) = 0
1310 fstat(3, 0xEFFFF508) = 0
1311 read(3, " # T h i s f i l e w".., 8192) = 5579
1312 write(4, " # T h i s f i l e w".., 5579) = 5579
1313 read(3, 0xEFFFD4A0, 8192) = 0
1316 chmod("LyXVC3.lyx", 0100644) = 0
1317 lseek(0, 0, SEEK_CUR) = 46440
1321 // Should probably have some more error checking here.
1322 // Doing it this way, also makes the inodes stay the same.
1323 // This is still not a very good solution, in particular we
1324 // might loose the owner of the backup.
1325 FileInfo finfo(fileName());
1326 if (finfo.exist()) {
1327 mode_t fmode = finfo.getMode();
1328 struct utimbuf times = {
1329 finfo.getAccessTime(),
1330 finfo.getModificationTime() };
1332 ifstream ifs(fileName().c_str());
1333 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1338 ::chmod(s.c_str(), fmode);
1340 if (::utime(s.c_str(), ×)) {
1341 lyxerr << "utime error." << endl;
1344 lyxerr << "LyX was not able to make "
1345 "backup copy. Beware." << endl;
1350 if (writeFile(fileName())) {
1352 removeAutosaveFile(fileName());
1354 // Saving failed, so backup is not backup
1355 if (lyxrc.make_backup) {
1356 lyx::rename(s, fileName());
1364 bool Buffer::writeFile(string const & fname) const
1366 if (read_only && (fname == fileName())) {
1370 FileInfo finfo(fname);
1371 if (finfo.exist() && !finfo.writable()) {
1375 ofstream ofs(fname.c_str());
1381 // Use the standard "C" locale for file output.
1382 ofs.imbue(std::locale::classic());
1385 // The top of the file should not be written by params.
1387 // write out a comment in the top of the file
1388 ofs << '#' << lyx_docversion
1389 << " created this file. For more info see http://www.lyx.org/\n"
1390 << "\\lyxformat " << LYX_FORMAT << "\n";
1392 // now write out the buffer paramters.
1393 params.writeFile(ofs);
1395 // if we're tracking, list all possible authors
1396 if (params.tracking_changes) {
1397 AuthorList::Authors::const_iterator it = authorlist.begin();
1398 AuthorList::Authors::const_iterator end = authorlist.end();
1399 for (; it != end; ++it) {
1400 ofs << "\\author " << it->second << "\n";
1404 Paragraph::depth_type depth = 0;
1406 // this will write out all the paragraphs
1407 // using recursive descent.
1408 ParagraphList::iterator pit = paragraphs.begin();
1409 ParagraphList::iterator pend = paragraphs.end();
1410 for (; pit != pend; ++pit)
1411 pit->write(this, ofs, params, depth);
1413 // Write marker that shows file is complete
1414 ofs << "\n\\the_end" << endl;
1418 // how to check if close went ok?
1419 // Following is an attempt... (BE 20001011)
1421 // good() returns false if any error occured, including some
1422 // formatting error.
1423 // bad() returns true if something bad happened in the buffer,
1424 // which should include file system full errors.
1431 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1433 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1445 pair<int, string> const addDepth(int depth, int ldepth)
1449 d += (ldepth - depth) * 2;
1450 return make_pair(d, string(d, ' '));
1456 string const Buffer::asciiParagraph(Paragraph const & par,
1457 unsigned int linelen,
1458 bool noparbreak) const
1460 ostringstream buffer;
1461 Paragraph::depth_type depth = 0;
1463 Paragraph::depth_type ltype_depth = 0;
1464 bool ref_printed = false;
1465 // if (!par->previous()) {
1467 // begins or ends a deeper area ?
1468 if (depth != par->params().depth()) {
1469 if (par->params().depth() > depth) {
1470 while (par->params().depth() > depth) {
1474 while (par->params().depth() < depth) {
1480 depth = par.params().depth();
1483 // First write the layout
1484 string const & tmp = par.layout()->name();
1485 if (compare_no_case(tmp, "itemize") == 0) {
1487 ltype_depth = depth + 1;
1488 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
1490 ltype_depth = depth + 1;
1491 } else if (contains(ascii_lowercase(tmp), "ection")) {
1493 ltype_depth = depth + 1;
1494 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
1496 ltype_depth = depth + 1;
1497 } else if (compare_ascii_no_case(tmp, "description") == 0) {
1499 ltype_depth = depth + 1;
1500 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
1503 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
1511 /* maybe some vertical spaces */
1513 /* the labelwidthstring used in lists */
1517 /* some pagebreaks? */
1521 /* what about the alignment */
1523 // lyxerr << "Should this ever happen?" << endl;
1526 // linelen <= 0 is special and means we don't have paragraph breaks
1528 string::size_type currlinelen = 0;
1534 buffer << string(depth * 2, ' ');
1535 currlinelen += depth * 2;
1538 // we should probably change to the paragraph language in the
1539 // gettext here (if possible) so that strings are outputted in
1540 // the correct language! (20012712 Jug)
1544 case 4: // (Sub)Paragraph
1545 case 5: // Description
1549 buffer << _("Abstract") << "\n\n";
1552 string const abst = _("Abstract: ");
1554 currlinelen += abst.length();
1557 case 7: // Bibliography
1560 buffer << _("References") << "\n\n";
1563 string const refs = _("References: ");
1565 currlinelen += refs.length();
1573 string const parlab = par.params().labelString();
1574 buffer << parlab << ' ';
1575 currlinelen += parlab.length() + 1;
1583 pair<int, string> p = addDepth(depth, ltype_depth);
1585 currlinelen += p.first;
1588 // this is to change the linebreak to do it by word a bit more
1589 // intelligent hopefully! (only in the case where we have a
1590 // max linelenght!) (Jug)
1594 for (pos_type i = 0; i < par.size(); ++i) {
1595 char c = par.getUChar(params, i);
1597 case Paragraph::META_INSET:
1599 Inset const * inset = par.getInset(i);
1603 currlinelen += word.length();
1606 if (inset->ascii(this, buffer, linelen)) {
1607 // to be sure it breaks paragraph
1608 currlinelen += linelen;
1614 case Paragraph::META_NEWLINE:
1616 buffer << word << "\n";
1619 pair<int, string> p = addDepth(depth,
1622 currlinelen = p.first;
1626 case Paragraph::META_HFILL:
1627 buffer << word << "\t";
1628 currlinelen += word.length() + 1;
1635 currlinelen + word.length() > linelen - 10) {
1637 pair<int, string> p =
1638 addDepth(depth, ltype_depth);
1640 currlinelen = p.first;
1643 buffer << word << ' ';
1644 currlinelen += word.length() + 1;
1651 lyxerr[Debug::INFO] <<
1652 "writeAsciiFile: NULL char in structure." << endl;
1654 if ((linelen > 0) &&
1655 (currlinelen + word.length()) > linelen)
1659 pair<int, string> p =
1660 addDepth(depth, ltype_depth);
1662 currlinelen = p.first;
1669 return STRCONV(buffer.str());
1673 void Buffer::writeFileAscii(string const & fname, int linelen)
1675 ofstream ofs(fname.c_str());
1677 Alert::err_alert(_("Error: Cannot write file:"), fname);
1680 writeFileAscii(ofs, linelen);
1684 void Buffer::writeFileAscii(ostream & os, int linelen)
1686 ParagraphList::iterator beg = paragraphs.begin();
1687 ParagraphList::iterator end = paragraphs.end();
1688 ParagraphList::iterator it = beg;
1689 for (; it != end; ++it) {
1690 os << asciiParagraph(*it, linelen, it == beg);
1699 void Buffer::makeLaTeXFile(string const & fname,
1700 string const & original_path,
1701 bool nice, bool only_body, bool only_preamble)
1703 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1705 ofstream ofs(fname.c_str());
1707 Alert::err_alert(_("Error: Cannot open file: "), fname);
1711 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1715 lyxerr << "File was not closed properly." << endl;
1720 void Buffer::makeLaTeXFile(ostream & os,
1721 string const & original_path,
1722 bool nice, bool only_body, bool only_preamble)
1724 niceFile = nice; // this will be used by Insetincludes.
1726 // validate the buffer.
1727 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1728 LaTeXFeatures features(params);
1730 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1733 // The starting paragraph of the coming rows is the
1734 // first paragraph of the document. (Asger)
1735 texrow.start(&*(paragraphs.begin()), 0);
1737 if (!only_body && nice) {
1738 os << "%% " << lyx_docversion << " created this file. "
1739 "For more info, see http://www.lyx.org/.\n"
1740 "%% Do not edit unless you really know what "
1745 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1746 // There are a few differences between nice LaTeX and usual files:
1747 // usual is \batchmode and has a
1748 // special input@path to allow the including of figures
1749 // with either \input or \includegraphics (what figinsets do).
1750 // input@path is set when the actual parameter
1751 // original_path is set. This is done for usual tex-file, but not
1752 // for nice-latex-file. (Matthias 250696)
1755 // code for usual, NOT nice-latex-file
1756 os << "\\batchmode\n"; // changed
1757 // from \nonstopmode
1760 if (!original_path.empty()) {
1761 string inputpath = os::external_path(original_path);
1762 subst(inputpath, "~", "\\string~");
1763 os << "\\makeatletter\n"
1764 << "\\def\\input@path{{"
1765 << inputpath << "/}}\n"
1766 << "\\makeatother\n";
1772 // Write the preamble
1773 params.writeLaTeX(os, features, texrow);
1779 os << "\\begin{document}\n";
1782 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1784 if (!lyxrc.language_auto_begin) {
1785 os << subst(lyxrc.language_command_begin, "$$lang",
1786 params.language->babel())
1791 latexParagraphs(os, &*(paragraphs.begin()), 0, texrow);
1793 // add this just in case after all the paragraphs
1797 if (!lyxrc.language_auto_end) {
1798 os << subst(lyxrc.language_command_end, "$$lang",
1799 params.language->babel())
1805 os << "\\end{document}\n";
1808 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1810 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1814 // Just to be sure. (Asger)
1817 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1818 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1821 // we want this to be true outside previews (for insetexternal)
1827 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
1829 void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
1830 Paragraph * endpar, TexRow & texrow,
1831 bool moving_arg) const
1833 bool was_title = false;
1834 bool already_title = false;
1835 LyXTextClass const & tclass = params.getLyXTextClass();
1838 while (par != endpar) {
1839 Inset * in = par->inInset();
1840 // well we have to check if we are in an inset with unlimited
1841 // length (all in one row) if that is true then we don't allow
1842 // any special options in the paragraph and also we don't allow
1843 // any environment other then "Standard" to be valid!
1844 if ((in == 0) || !in->forceDefaultParagraphs(in)) {
1845 LyXLayout_ptr const & layout = par->layout();
1847 if (layout->intitle) {
1848 if (already_title) {
1849 lyxerr <<"Error in latexParagraphs: You"
1850 " should not mix title layouts"
1851 " with normal ones." << endl;
1852 } else if (!was_title) {
1854 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1856 << tclass.titlename()
1861 } else if (was_title && !already_title) {
1862 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1863 ofs << "\\end{" << tclass.titlename()
1867 ofs << "\\" << tclass.titlename()
1871 already_title = true;
1875 if (layout->isEnvironment() ||
1876 !par->params().leftIndent().zero())
1878 par = par->TeXEnvironment(this, params, ofs, texrow);
1880 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
1883 par = par->TeXOnePar(this, params, ofs, texrow, moving_arg);
1886 // It might be that we only have a title in this document
1887 if (was_title && !already_title) {
1888 if (tclass.titletype() == TITLE_ENVIRONMENT) {
1889 ofs << "\\end{" << tclass.titlename()
1893 ofs << "\\" << tclass.titlename()
1901 bool Buffer::isLatex() const
1903 return params.getLyXTextClass().outputType() == LATEX;
1907 bool Buffer::isLinuxDoc() const
1909 return params.getLyXTextClass().outputType() == LINUXDOC;
1913 bool Buffer::isLiterate() const
1915 return params.getLyXTextClass().outputType() == LITERATE;
1919 bool Buffer::isDocBook() const
1921 return params.getLyXTextClass().outputType() == DOCBOOK;
1925 bool Buffer::isSGML() const
1927 LyXTextClass const & tclass = params.getLyXTextClass();
1929 return tclass.outputType() == LINUXDOC ||
1930 tclass.outputType() == DOCBOOK;
1934 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1936 ofstream ofs(fname.c_str());
1939 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1943 niceFile = nice; // this will be used by included files.
1945 LaTeXFeatures features(params);
1951 LyXTextClass const & tclass = params.getLyXTextClass();
1953 string top_element = tclass.latexname();
1956 ofs << "<!doctype linuxdoc system";
1958 string preamble = params.preamble;
1959 const string name = nice ? ChangeExtension(filename_, ".sgml")
1961 preamble += features.getIncludedFiles(name);
1962 preamble += features.getLyXSGMLEntities();
1964 if (!preamble.empty()) {
1965 ofs << " [ " << preamble << " ]";
1969 if (params.options.empty())
1970 sgml::openTag(ofs, 0, false, top_element);
1972 string top = top_element;
1974 top += params.options;
1975 sgml::openTag(ofs, 0, false, top);
1979 ofs << "<!-- " << lyx_docversion
1980 << " created this file. For more info see http://www.lyx.org/"
1983 Paragraph::depth_type depth = 0; // paragraph depth
1984 Paragraph * par = &*(paragraphs.begin());
1986 vector<string> environment_stack(5);
1989 LyXLayout_ptr const & style = par->layout();
1990 // treat <toc> as a special case for compatibility with old code
1991 if (par->isInset(0)) {
1992 Inset * inset = par->getInset(0);
1993 Inset::Code lyx_code = inset->lyxCode();
1994 if (lyx_code == Inset::TOC_CODE) {
1995 string const temp = "toc";
1996 sgml::openTag(ofs, depth, false, temp);
2003 // environment tag closing
2004 for (; depth > par->params().depth(); --depth) {
2005 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2006 environment_stack[depth].erase();
2009 // write opening SGML tags
2010 switch (style->latextype) {
2011 case LATEX_PARAGRAPH:
2012 if (depth == par->params().depth()
2013 && !environment_stack[depth].empty()) {
2014 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2015 environment_stack[depth].erase();
2021 sgml::openTag(ofs, depth, false, style->latexname());
2027 _("Error: Wrong depth for LatexType Command.\n"));
2029 if (!environment_stack[depth].empty()) {
2030 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
2034 environment_stack[depth].erase();
2035 sgml::openTag(ofs, depth, false, style->latexname());
2038 case LATEX_ENVIRONMENT:
2039 case LATEX_ITEM_ENVIRONMENT:
2041 string const & latexname = style->latexname();
2043 if (depth == par->params().depth()
2044 && environment_stack[depth] != latexname) {
2045 sgml::closeTag(ofs, depth, false,
2046 environment_stack[depth]);
2047 environment_stack[depth].erase();
2049 if (depth < par->params().depth()) {
2050 depth = par->params().depth();
2051 environment_stack[depth].erase();
2053 if (environment_stack[depth] != latexname) {
2055 sgml::openTag(ofs, depth, false, "p");
2057 sgml::openTag(ofs, depth, false, latexname);
2059 if (environment_stack.size() == depth + 1)
2060 environment_stack.push_back("!-- --");
2061 environment_stack[depth] = latexname;
2064 if (style->latexparam() == "CDATA")
2067 if (style->latextype == LATEX_ENVIRONMENT) break;
2069 if (style->labeltype == LABEL_MANUAL)
2074 sgml::openTag(ofs, depth + 1, false, item_name);
2079 sgml::openTag(ofs, depth, false, style->latexname());
2083 simpleLinuxDocOnePar(ofs, par, depth);
2088 // write closing SGML tags
2089 switch (style->latextype) {
2092 case LATEX_ENVIRONMENT:
2093 case LATEX_ITEM_ENVIRONMENT:
2094 if (style->latexparam() == "CDATA")
2098 sgml::closeTag(ofs, depth, false, style->latexname());
2104 for (int i = depth; i >= 0; --i)
2105 sgml::closeTag(ofs, depth, false, environment_stack[i]);
2109 sgml::closeTag(ofs, 0, false, top_element);
2113 // How to check for successful close
2115 // we want this to be true outside previews (for insetexternal)
2120 // checks, if newcol chars should be put into this line
2121 // writes newline, if necessary.
2124 void sgmlLineBreak(ostream & os, string::size_type & colcount,
2125 string::size_type newcol)
2128 if (colcount > lyxrc.ascii_linelen) {
2130 colcount = newcol; // assume write after this call
2145 string tag_name(PAR_TAG const & pt) {
2147 case NONE: return "!-- --";
2148 case TT: return "tt";
2149 case SF: return "sf";
2150 case BF: return "bf";
2151 case IT: return "it";
2152 case SL: return "sl";
2153 case EM: return "em";
2160 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
2162 p1 = static_cast<PAR_TAG>(p1 | p2);
2167 void reset(PAR_TAG & p1, PAR_TAG const & p2)
2169 p1 = static_cast<PAR_TAG>(p1 & ~p2);
2175 // Handle internal paragraph parsing -- layout already processed.
2176 void Buffer::simpleLinuxDocOnePar(ostream & os,
2178 Paragraph::depth_type /*depth*/)
2180 LyXLayout_ptr const & style = par->layout();
2182 string::size_type char_line_count = 5; // Heuristic choice ;-)
2184 // gets paragraph main font
2187 if (style->labeltype == LABEL_MANUAL) {
2188 font_old = style->labelfont;
2191 font_old = style->font;
2195 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2196 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2197 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2200 stack<PAR_TAG> tag_state;
2201 // parsing main loop
2202 for (pos_type i = 0; i < par->size(); ++i) {
2204 PAR_TAG tag_close = NONE;
2205 list < PAR_TAG > tag_open;
2207 LyXFont const font = par->getFont(params, i);
2209 if (font_old.family() != font.family()) {
2210 switch (family_type) {
2211 case LyXFont::SANS_FAMILY:
2214 case LyXFont::TYPEWRITER_FAMILY:
2221 family_type = font.family();
2223 switch (family_type) {
2224 case LyXFont::SANS_FAMILY:
2225 tag_open.push_back(SF);
2227 case LyXFont::TYPEWRITER_FAMILY:
2228 tag_open.push_back(TT);
2235 if (font_old.series() != font.series()) {
2236 switch (series_type) {
2237 case LyXFont::BOLD_SERIES:
2244 series_type = font.series();
2246 switch (series_type) {
2247 case LyXFont::BOLD_SERIES:
2248 tag_open.push_back(BF);
2256 if (font_old.shape() != font.shape()) {
2257 switch (shape_type) {
2258 case LyXFont::ITALIC_SHAPE:
2261 case LyXFont::SLANTED_SHAPE:
2268 shape_type = font.shape();
2270 switch (shape_type) {
2271 case LyXFont::ITALIC_SHAPE:
2272 tag_open.push_back(IT);
2274 case LyXFont::SLANTED_SHAPE:
2275 tag_open.push_back(SL);
2282 if (font_old.emph() != font.emph()) {
2283 if (font.emph() == LyXFont::ON) {
2284 tag_open.push_back(EM);
2293 list < PAR_TAG > temp;
2294 while (!tag_state.empty() && tag_close) {
2295 PAR_TAG k = tag_state.top();
2297 os << "</" << tag_name(k) << '>';
2304 for(list< PAR_TAG >::const_iterator j = temp.begin();
2305 j != temp.end(); ++j) {
2307 os << '<' << tag_name(*j) << '>';
2310 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
2311 j != tag_open.end(); ++j) {
2313 os << '<' << tag_name(*j) << '>';
2316 char c = par->getChar(i);
2318 if (c == Paragraph::META_INSET) {
2319 Inset * inset = par->getInset(i);
2320 inset->linuxdoc(this, os);
2325 if (style->latexparam() == "CDATA") {
2326 // "TeX"-Mode on == > SGML-Mode on.
2333 boost::tie(ws, str) = sgml::escapeChar(c);
2334 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
2335 // in freespacing mode, spaces are
2336 // non-breaking characters
2337 if (desc_on) {// if char is ' ' then...
2340 sgmlLineBreak(os, char_line_count, 6);
2344 sgmlLineBreak(os, char_line_count, 1);
2349 char_line_count += str.length();
2355 while (!tag_state.empty()) {
2356 os << "</" << tag_name(tag_state.top()) << '>';
2360 // resets description flag correctly
2362 // <tag> not closed...
2363 sgmlLineBreak(os, char_line_count, 6);
2369 // Print an error message.
2370 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
2371 string const & /*message*/) const
2373 #ifdef WITH_WARNINGS
2374 #warning This is wrong we cannot insert an inset like this!!!
2375 // I guess this was Jose' so I explain you more or less why this
2376 // is wrong. This way you insert something in the paragraph and
2377 // don't tell it to LyXText (row rebreaking and undo handling!!!)
2378 // I deactivate this code, have a look at BufferView::insertErrors
2379 // how you should do this correctly! (Jug 20020315)
2382 // insert an error marker in text
2383 InsetError * new_inset = new InsetError(message);
2384 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
2390 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
2392 ofstream ofs(fname.c_str());
2394 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2398 Paragraph * par = &*(paragraphs.begin());
2400 niceFile = nice; // this will be used by Insetincludes.
2402 LaTeXFeatures features(params);
2407 LyXTextClass const & tclass = params.getLyXTextClass();
2408 string top_element = tclass.latexname();
2411 ofs << "<!DOCTYPE " << top_element
2412 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
2414 string preamble = params.preamble;
2415 const string name = nice ? ChangeExtension(filename_, ".sgml")
2417 preamble += features.getIncludedFiles(name);
2418 preamble += features.getLyXSGMLEntities();
2420 if (!preamble.empty()) {
2421 ofs << "\n [ " << preamble << " ]";
2426 string top = top_element;
2428 top += params.language->code();
2431 if (!params.options.empty()) {
2433 top += params.options;
2435 sgml::openTag(ofs, 0, false, top);
2437 ofs << "<!-- DocBook file was created by " << lyx_docversion
2438 << "\n See http://www.lyx.org/ for more information -->\n";
2440 vector<string> environment_stack(10);
2441 vector<string> environment_inner(10);
2442 vector<string> command_stack(10);
2444 bool command_flag = false;
2445 Paragraph::depth_type command_depth = 0;
2446 Paragraph::depth_type command_base = 0;
2447 Paragraph::depth_type cmd_depth = 0;
2448 Paragraph::depth_type depth = 0; // paragraph depth
2451 string command_name;
2457 int desc_on = 0; // description mode
2459 LyXLayout_ptr const & style = par->layout();
2461 // environment tag closing
2462 for (; depth > par->params().depth(); --depth) {
2463 if (environment_inner[depth] != "!-- --") {
2464 item_name = "listitem";
2465 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2466 if (environment_inner[depth] == "varlistentry")
2467 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
2469 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2470 environment_stack[depth].erase();
2471 environment_inner[depth].erase();
2474 if (depth == par->params().depth()
2475 && environment_stack[depth] != style->latexname()
2476 && !environment_stack[depth].empty()) {
2477 if (environment_inner[depth] != "!-- --") {
2478 item_name= "listitem";
2479 sgml::closeTag(ofs, command_depth+depth, false, item_name);
2480 if (environment_inner[depth] == "varlistentry")
2481 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2484 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2486 environment_stack[depth].erase();
2487 environment_inner[depth].erase();
2490 // Write opening SGML tags.
2491 switch (style->latextype) {
2492 case LATEX_PARAGRAPH:
2493 sgml::openTag(ofs, depth + command_depth,
2494 false, style->latexname());
2500 _("Error: Wrong depth for LatexType Command.\n"));
2502 command_name = style->latexname();
2504 sgmlparam = style->latexparam();
2505 c_params = split(sgmlparam, c_depth,'|');
2507 cmd_depth = lyx::atoi(c_depth);
2510 if (cmd_depth < command_base) {
2511 for (Paragraph::depth_type j = command_depth;
2512 j >= command_base; --j) {
2513 sgml::closeTag(ofs, j, false, command_stack[j]);
2516 command_depth = command_base = cmd_depth;
2517 } else if (cmd_depth <= command_depth) {
2518 for (int j = command_depth;
2519 j >= int(cmd_depth); --j) {
2520 sgml::closeTag(ofs, j, false, command_stack[j]);
2523 command_depth = cmd_depth;
2525 command_depth = cmd_depth;
2527 command_depth = command_base = cmd_depth;
2528 command_flag = true;
2530 if (command_stack.size() == command_depth + 1)
2531 command_stack.push_back(string());
2532 command_stack[command_depth] = command_name;
2534 // treat label as a special case for
2535 // more WYSIWYM handling.
2536 // This is a hack while paragraphs can't have
2537 // attributes, like id in this case.
2538 if (par->isInset(0)) {
2539 Inset * inset = par->getInset(0);
2540 Inset::Code lyx_code = inset->lyxCode();
2541 if (lyx_code == Inset::LABEL_CODE) {
2542 command_name += " id=\"";
2543 command_name += (static_cast<InsetCommand *>(inset))->getContents();
2544 command_name += '"';
2549 sgml::openTag(ofs, depth + command_depth, false, command_name);
2551 item_name = c_params.empty() ? "title" : c_params;
2552 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
2555 case LATEX_ENVIRONMENT:
2556 case LATEX_ITEM_ENVIRONMENT:
2557 if (depth < par->params().depth()) {
2558 depth = par->params().depth();
2559 environment_stack[depth].erase();
2562 if (environment_stack[depth] != style->latexname()) {
2563 if (environment_stack.size() == depth + 1) {
2564 environment_stack.push_back("!-- --");
2565 environment_inner.push_back("!-- --");
2567 environment_stack[depth] = style->latexname();
2568 environment_inner[depth] = "!-- --";
2569 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
2571 if (environment_inner[depth] != "!-- --") {
2572 item_name= "listitem";
2573 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2574 if (environment_inner[depth] == "varlistentry")
2575 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2579 if (style->latextype == LATEX_ENVIRONMENT) {
2580 if (!style->latexparam().empty()) {
2581 if (style->latexparam() == "CDATA")
2584 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
2589 desc_on = (style->labeltype == LABEL_MANUAL);
2591 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
2592 sgml::openTag(ofs, depth + 1 + command_depth,
2593 false, environment_inner[depth]);
2595 item_name = desc_on ? "term" : "para";
2596 sgml::openTag(ofs, depth + 1 + command_depth,
2600 sgml::openTag(ofs, depth + command_depth,
2601 false, style->latexname());
2605 simpleDocBookOnePar(ofs, par, desc_on,
2606 depth + 1 + command_depth);
2610 // write closing SGML tags
2611 switch (style->latextype) {
2613 end_tag = c_params.empty() ? "title" : c_params;
2614 sgml::closeTag(ofs, depth + command_depth,
2617 case LATEX_ENVIRONMENT:
2618 if (!style->latexparam().empty()) {
2619 if (style->latexparam() == "CDATA")
2622 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
2625 case LATEX_ITEM_ENVIRONMENT:
2626 if (desc_on == 1) break;
2628 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
2630 case LATEX_PARAGRAPH:
2631 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2634 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
2640 for (int d = depth; d >= 0; --d) {
2641 if (!environment_stack[depth].empty()) {
2642 if (environment_inner[depth] != "!-- --") {
2643 item_name = "listitem";
2644 sgml::closeTag(ofs, command_depth + depth, false, item_name);
2645 if (environment_inner[depth] == "varlistentry")
2646 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
2649 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
2653 for (int j = command_depth; j >= 0 ; --j)
2654 if (!command_stack[j].empty()) {
2655 sgml::closeTag(ofs, j, false, command_stack[j]);
2660 sgml::closeTag(ofs, 0, false, top_element);
2663 // How to check for successful close
2665 // we want this to be true outside previews (for insetexternal)
2670 void Buffer::simpleDocBookOnePar(ostream & os,
2671 Paragraph * par, int & desc_on,
2672 Paragraph::depth_type depth) const
2674 bool emph_flag = false;
2676 LyXLayout_ptr const & style = par->layout();
2678 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
2680 int char_line_count = depth;
2681 //if (!style.free_spacing)
2682 // os << string(depth,' ');
2684 // parsing main loop
2685 for (pos_type i = 0; i < par->size(); ++i) {
2686 LyXFont font = par->getFont(params, i);
2688 // handle <emphasis> tag
2689 if (font_old.emph() != font.emph()) {
2690 if (font.emph() == LyXFont::ON) {
2691 if (style->latexparam() == "CDATA")
2694 if (style->latexparam() == "CDATA")
2698 if (style->latexparam() == "CDATA")
2700 os << "</emphasis>";
2701 if (style->latexparam() == "CDATA")
2708 if (par->isInset(i)) {
2709 Inset * inset = par->getInset(i);
2710 // don't print the inset in position 0 if desc_on == 3 (label)
2711 if (i || desc_on != 3) {
2712 if (style->latexparam() == "CDATA")
2714 inset->docbook(this, os, false);
2715 if (style->latexparam() == "CDATA")
2719 char c = par->getChar(i);
2722 boost::tie(ws, str) = sgml::escapeChar(c);
2724 if (style->pass_thru) {
2726 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
2728 } else if (desc_on ==1) {
2730 os << "\n</term><listitem><para>";
2740 if (style->latexparam() == "CDATA")
2742 os << "</emphasis>";
2743 if (style->latexparam() == "CDATA")
2747 // resets description flag correctly
2749 // <term> not closed...
2750 os << "</term>\n<listitem><para> </para>";
2752 if (style->free_spacing)
2757 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2758 // Other flags: -wall -v0 -x
2759 int Buffer::runChktex()
2761 if (!users->text) return 0;
2763 users->owner()->busy(true);
2765 // get LaTeX-Filename
2766 string const name = getLatexName();
2767 string path = filePath();
2769 string const org_path = path;
2770 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2774 Path p(path); // path to LaTeX file
2775 users->owner()->message(_("Running chktex..."));
2777 // Remove all error insets
2778 bool const removedErrorInsets = users->removeAutoInsets();
2780 // Generate the LaTeX file if neccessary
2781 makeLaTeXFile(name, org_path, false);
2784 Chktex chktex(lyxrc.chktex_command, name, filePath());
2785 int res = chktex.run(terr); // run chktex
2788 Alert::alert(_("chktex did not work!"),
2789 _("Could not run with file:"), name);
2790 } else if (res > 0) {
2791 // Insert all errors as errors boxes
2792 users->insertErrors(terr);
2795 // if we removed error insets before we ran chktex or if we inserted
2796 // error insets after we ran chktex, this must be run:
2797 if (removedErrorInsets || res) {
2798 #warning repaint needed here, or do you mean update() ?
2802 users->owner()->busy(false);
2808 void Buffer::validate(LaTeXFeatures & features) const
2810 LyXTextClass const & tclass = params.getLyXTextClass();
2812 if (params.tracking_changes) {
2813 features.require("dvipost");
2814 features.require("color");
2817 // AMS Style is at document level
2818 if (params.use_amsmath || tclass.provides(LyXTextClass::amsmath))
2819 features.require("amsmath");
2821 for_each(paragraphs.begin(), paragraphs.end(),
2822 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2824 // the bullet shapes are buffer level not paragraph level
2825 // so they are tested here
2826 for (int i = 0; i < 4; ++i) {
2827 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2828 int const font = params.user_defined_bullets[i].getFont();
2830 int const c = params
2831 .user_defined_bullets[i]
2838 features.require("latexsym");
2840 } else if (font == 1) {
2841 features.require("amssymb");
2842 } else if ((font >= 2 && font <= 5)) {
2843 features.require("pifont");
2848 if (lyxerr.debugging(Debug::LATEX)) {
2849 features.showStruct();
2854 vector<string> const Buffer::getLabelList() const
2856 /// if this is a child document and the parent is already loaded
2857 /// Use the parent's list instead [ale990407]
2858 if (!params.parentname.empty()
2859 && bufferlist.exists(params.parentname)) {
2860 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2862 return tmp->getLabelList();
2865 vector<string> label_list;
2866 for (inset_iterator it = inset_const_iterator_begin();
2867 it != inset_const_iterator_end(); ++it) {
2868 vector<string> const l = it->getLabelList();
2869 label_list.insert(label_list.end(), l.begin(), l.end());
2875 // This is also a buffer property (ale)
2876 vector<pair<string, string> > const Buffer::getBibkeyList() const
2878 typedef pair<string, string> StringPair;
2879 /// if this is a child document and the parent is already loaded
2880 /// Use the parent's list instead [ale990412]
2881 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2882 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2884 return tmp->getBibkeyList();
2887 vector<StringPair> keys;
2888 ParagraphList::iterator pit = paragraphs.begin();
2889 ParagraphList::iterator pend = paragraphs.end();
2890 for (; pit != pend; ++pit) {
2892 string const key = pit->bibkey->getContents();
2893 string const opt = pit->bibkey->getOptions();
2894 string const ref = pit->asString(this, false);
2895 string const info = opt + "TheBibliographyRef" + ref;
2897 keys.push_back(StringPair(key, info));
2904 // Might be either using bibtex or a child has bibliography
2905 for (inset_iterator it = inset_const_iterator_begin();
2906 it != inset_const_iterator_end(); ++it) {
2907 // Search for Bibtex or Include inset
2908 if (it->lyxCode() == Inset::BIBTEX_CODE) {
2909 vector<StringPair> tmp =
2910 static_cast<InsetBibtex &>(*it).getKeys(this);
2911 keys.insert(keys.end(), tmp.begin(), tmp.end());
2912 } else if (it->lyxCode() == Inset::INCLUDE_CODE) {
2913 vector<StringPair> const tmp =
2914 static_cast<InsetInclude &>(*it).getKeys();
2915 keys.insert(keys.end(), tmp.begin(), tmp.end());
2923 bool Buffer::isDepClean(string const & name) const
2925 DepClean::const_iterator it = dep_clean_.find(name);
2926 if (it == dep_clean_.end())
2932 void Buffer::markDepClean(string const & name)
2934 dep_clean_[name] = true;
2938 bool Buffer::dispatch(string const & command, bool * result)
2940 // Split command string into command and argument
2942 string line = ltrim(command);
2943 string const arg = trim(split(line, cmd, ' '));
2945 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2949 bool Buffer::dispatch(int action, string const & argument, bool * result)
2951 bool dispatched = true;
2955 bool const tmp = Exporter::Export(this, argument, false);
2968 void Buffer::resizeInsets(BufferView * bv)
2970 /// then remove all LyXText in text-insets
2971 for_each(paragraphs.begin(), paragraphs.end(),
2972 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2976 void Buffer::redraw()
2978 #warning repaint needed here, or do you mean update() ?
2984 void Buffer::changeLanguage(Language const * from, Language const * to)
2987 ParIterator end = par_iterator_end();
2988 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2989 (*it)->changeLanguage(params, from, to);
2993 bool Buffer::isMultiLingual()
2995 ParIterator end = par_iterator_end();
2996 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2997 if ((*it)->isMultiLingual(params))
3004 void Buffer::inset_iterator::setParagraph()
3006 while (pit != pend) {
3007 it = pit->insetlist.begin();
3008 if (it != pit->insetlist.end())
3015 Inset * Buffer::getInsetFromID(int id_arg) const
3017 for (inset_iterator it = inset_const_iterator_begin();
3018 it != inset_const_iterator_end(); ++it)
3020 if (it->id() == id_arg)
3022 Inset * in = it->getInsetFromID(id_arg);
3030 Paragraph * Buffer::getParFromID(int id) const
3035 // why should we allow < 0 ??
3036 //lyx::Assert(id >= 0);
3038 ParConstIterator it(par_iterator_begin());
3039 ParConstIterator end(par_iterator_end());
3041 for (; it != end; ++it) {
3042 // go on then, show me how to remove
3044 if ((*it)->id() == id) {
3045 return const_cast<Paragraph*>(*it);
3053 ParIterator Buffer::par_iterator_begin()
3055 return ParIterator(&*(paragraphs.begin()));
3059 ParIterator Buffer::par_iterator_end()
3061 return ParIterator();
3064 ParConstIterator Buffer::par_iterator_begin() const
3066 return ParConstIterator(&*(paragraphs.begin()));
3070 ParConstIterator Buffer::par_iterator_end() const
3072 return ParConstIterator();
3077 void Buffer::addUser(BufferView * u)
3083 void Buffer::delUser(BufferView *)
3089 Language const * Buffer::getLanguage() const
3091 return params.language;
3095 bool Buffer::isClean() const
3101 bool Buffer::isBakClean() const
3107 void Buffer::markClean() const
3113 // if the .lyx file has been saved, we don't need an
3119 void Buffer::markBakClean()
3125 void Buffer::setUnnamed(bool flag)
3131 bool Buffer::isUnnamed()
3137 void Buffer::markDirty()
3145 DepClean::iterator it = dep_clean_.begin();
3146 DepClean::const_iterator const end = dep_clean_.end();
3148 for (; it != end; ++it) {
3154 string const & Buffer::fileName() const
3160 string const & Buffer::filePath() const
3166 bool Buffer::isReadonly() const
3172 BufferView * Buffer::getUser() const
3178 void Buffer::setParentName(string const & name)
3180 params.parentname = name;
3184 Buffer::inset_iterator::inset_iterator()
3189 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
3196 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
3200 if (it == pit->insetlist.end()) {
3209 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
3211 inset_iterator tmp = *this;
3217 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
3219 return *it.getInset();
3223 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
3225 return it.getInset();
3229 Paragraph * Buffer::inset_iterator::getPar()
3235 lyx::pos_type Buffer::inset_iterator::getPos() const
3241 bool operator==(Buffer::inset_iterator const & iter1,
3242 Buffer::inset_iterator const & iter2)
3244 return iter1.pit == iter2.pit
3245 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
3249 bool operator!=(Buffer::inset_iterator const & iter1,
3250 Buffer::inset_iterator const & iter2)
3252 return !(iter1 == iter2);