1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * This file is Copyright 1996-2001
12 * ======================================================
18 #include "bufferlist.h"
19 #include "LyXAction.h"
22 #include "tex-strings.h"
24 #include "bufferview_funcs.h"
30 #include "LaTeXFeatures.h"
37 #include "BufferView.h"
38 #include "ParagraphParameters.h"
39 #include "iterators.h"
40 #include "lyxtextclasslist.h"
42 #include "paragraph_funcs.h"
45 #include "frontends/LyXView.h"
47 #include "mathed/formulamacro.h"
48 #include "mathed/formula.h"
50 #include "insets/inseterror.h"
51 #include "insets/insetbibitem.h"
52 #include "insets/insetbibtex.h"
53 #include "insets/insetinclude.h"
54 #include "insets/insettext.h"
56 #include "frontends/Dialogs.h"
57 #include "frontends/Alert.h"
59 #include "graphics/Previews.h"
61 #include "support/textutils.h"
62 #include "support/filetools.h"
63 #include "support/path.h"
64 #include "support/os.h"
65 #include "support/lyxlib.h"
66 #include "support/FileInfo.h"
67 #include "support/lyxmanip.h"
68 #include "support/lyxtime.h"
70 #include <boost/bind.hpp>
71 #include <boost/tuple/tuple.hpp>
72 #include "BoostFormat.h"
84 #include <sys/types.h>
91 #ifndef CXX_GLOBAL_CSTD
103 using std::make_pair;
111 using lyx::textclass_type;
113 // all these externs should eventually be removed.
114 extern BufferList bufferlist;
118 const int LYX_FORMAT = 223;
122 Buffer::Buffer(string const & file, bool ronly)
123 : niceFile(true), lyx_clean(true), bak_clean(true),
124 unnamed(false), read_only(ronly),
125 filename_(file), users(0)
127 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
128 filepath_ = OnlyPath(file);
130 if (read_only || lyxrc.use_tempdir) {
131 tmppath = CreateBufferTmpDir();
136 // set initial author
137 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
143 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
144 // here the buffer should take care that it is
145 // saved properly, before it goes into the void.
147 // make sure that views using this buffer
152 if (!tmppath.empty()) {
153 DestroyBufferTmpDir(tmppath);
158 // Remove any previewed LaTeX snippets assocoated with this buffer.
159 grfx::Previews::get().removeLoader(this);
163 string const Buffer::getLatexName(bool no_path) const
165 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
167 return OnlyFilename(name);
173 pair<Buffer::LogType, string> const Buffer::getLogName() const
175 string const filename = getLatexName(false);
177 if (filename.empty())
178 return make_pair(Buffer::latexlog, string());
180 string path = OnlyPath(filename);
182 if (lyxrc.use_tempdir || !IsDirWriteable(path))
185 string const fname = AddName(path,
186 OnlyFilename(ChangeExtension(filename,
189 AddName(path, OnlyFilename(
190 ChangeExtension(filename,
191 formats.extension("literate") + ".out")));
193 // If no Latex log or Build log is newer, show Build log
195 FileInfo const f_fi(fname);
196 FileInfo const b_fi(bname);
199 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
200 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
201 return make_pair(Buffer::buildlog, bname);
203 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
204 return make_pair(Buffer::latexlog, fname);
208 void Buffer::setReadonly(bool flag)
210 if (read_only != flag) {
213 users->owner()->getDialogs().updateBufferDependent(false);
218 AuthorList & Buffer::authors()
220 return params.authorlist;
224 /// Update window titles of all users
225 // Should work on a list
226 void Buffer::updateTitles() const
229 users->owner()->updateWindowTitle();
233 /// Reset autosave timer of all users
234 // Should work on a list
235 void Buffer::resetAutosaveTimers() const
238 users->owner()->resetAutosaveTimer();
242 void Buffer::setFileName(string const & newfile)
244 filename_ = MakeAbsPath(newfile);
245 filepath_ = OnlyPath(filename_);
246 setReadonly(IsFileWriteable(filename_) == 0);
251 // We'll remove this later. (Lgb)
255 #warning this is never set to != 0 !!! - remove ?
259 void unknownClass(string const & unknown)
263 boost::io::str(boost::format(
264 _("The document uses an unknown textclass \"%1$s\".")) % unknown)
265 + _("-- substituting default.");
267 _("The document uses an unknown textclass ")
268 + unknown + _("-- substituting default.");
270 Alert::alert(_("Textclass error"), msg);
275 int Buffer::readHeader(LyXLex & lex)
277 int unknown_tokens = 0;
281 string const token = lex.getString();
286 if (token == "\\end_header")
289 lyxerr[Debug::PARSER] << "Handling header token: `"
290 << token << '\'' << endl;
292 string unknown = params.readToken(lex, token);
293 if (!unknown.empty()) {
294 if (unknown[0] != '\\') {
295 unknownClass(unknown);
301 return unknown_tokens;
305 // candidate for move to BufferView
306 // (at least some parts in the beginning of the func)
309 // changed to be public and have one parameter
310 // if par = 0 normal behavior
311 // else insert behavior
312 // Returns false if "\the_end" is not read (Asger)
313 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
316 int unknown_tokens = 0;
318 Paragraph::depth_type depth = 0;
319 bool the_end_read = false;
321 if (paragraphs.empty()) {
322 unknown_tokens += readHeader(lex);
324 if (!params.getLyXTextClass().load()) {
326 Alert::alert(_("Textclass Loading Error!"),
327 boost::io::str(boost::format(_("Can't load textclass %1$s")) %
328 params.getLyXTextClass().name()),
329 _("-- substituting default."));
331 Alert::alert(_("Textclass Loading Error!"),
332 _("Can't load textclass ")
333 + params.getLyXTextClass().name(),
334 _("-- substituting default."));
336 params.textclass = 0;
339 // We are inserting into an existing document
340 users->text->breakParagraph(paragraphs);
342 // We don't want to adopt the parameters from the
343 // document we insert, so read them into a temporary buffer
344 // and then discard it
346 Buffer tmpbuf("", false);
347 tmpbuf.readHeader(lex);
352 string const token = lex.getString();
357 lyxerr[Debug::PARSER] << "Handling token: `"
358 << token << '\'' << endl;
360 if (token == "\\the_end") {
365 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
368 if (unknown_layouts > 0) {
369 string s = _("Couldn't set the layout for ");
370 if (unknown_layouts == 1) {
371 s += _("one paragraph");
373 s += tostr(unknown_layouts);
374 s += _(" paragraphs");
377 Alert::alert(_("Textclass Loading Error!"), s,
378 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
380 Alert::alert(_("Textclass Loading Error!"), s,
381 _("When reading ") + fileName());
385 if (unknown_tokens > 0) {
386 string s = _("Encountered ");
387 if (unknown_tokens == 1) {
388 s += _("one unknown token");
390 s += tostr(unknown_tokens);
391 s += _(" unknown tokens");
394 Alert::alert(_("Textclass Loading Error!"), s,
395 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
397 Alert::alert(_("Textclass Loading Error!"), s,
398 _("When reading ") + fileName());
407 Buffer::readParagraph(LyXLex & lex, string const & token,
408 ParagraphList & pars, ParagraphList::iterator & pit,
409 Paragraph::depth_type & depth)
411 static Change current_change;
414 if (token == "\\layout") {
415 lex.pushToken(token);
417 Paragraph * par = new Paragraph();
418 par->params().depth(depth);
419 if (params.tracking_changes)
421 LyXFont f(LyXFont::ALL_INHERIT, params.language);
424 // FIXME: goddamn InsetTabular makes us pass a Buffer
426 unknown += ::readParagraph(*this, *par, lex);
429 if (pit != pars.end())
431 pit = pars.insert(pit, par);
432 } else if (token == "\\begin_deeper") {
434 } else if (token == "\\end_deeper") {
436 lex.printError("\\end_deeper: " "depth is already null");
447 // needed to insert the selection
448 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
449 LyXFont const & fn,string const & str)
451 LyXLayout_ptr const & layout = par->layout();
455 par->checkInsertChar(font);
456 // insert the string, don't insert doublespace
457 bool space_inserted = true;
458 bool autobreakrows = !par->inInset() ||
459 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
460 for(string::const_iterator cit = str.begin();
461 cit != str.end(); ++cit) {
463 if (autobreakrows && (!par->empty() || layout->keepempty)) {
464 breakParagraph(params, paragraphs, par, pos,
465 layout->isEnvironment());
468 space_inserted = true;
472 // do not insert consecutive spaces if !free_spacing
473 } else if ((*cit == ' ' || *cit == '\t') &&
474 space_inserted && !layout->free_spacing &&
475 !par->isFreeSpacing())
478 } else if (*cit == '\t') {
479 if (!layout->free_spacing && !par->isFreeSpacing()) {
480 // tabs are like spaces here
481 par->insertChar(pos, ' ', font);
483 space_inserted = true;
485 const pos_type nb = 8 - pos % 8;
486 for (pos_type a = 0; a < nb ; ++a) {
487 par->insertChar(pos, ' ', font);
490 space_inserted = true;
492 } else if (!IsPrintable(*cit)) {
493 // Ignore unprintables
496 // just insert the character
497 par->insertChar(pos, *cit, font);
499 space_inserted = (*cit == ' ');
506 bool Buffer::readFile(LyXLex & lex, string const & filename)
508 return readFile(lex, filename, paragraphs.begin());
512 bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iterator pit)
516 string const token(lex.getString());
517 if (token == "\\lyxformat") { // the first token _must_ be...
519 string tmp_format = lex.getString();
520 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
521 // if present remove ".," from string.
522 string::size_type dot = tmp_format.find_first_of(".,");
523 //lyxerr << " dot found at " << dot << endl;
524 if (dot != string::npos)
525 tmp_format.erase(dot, 1);
526 file_format = strToInt(tmp_format);
527 //lyxerr << "format: " << file_format << endl;
528 if (file_format == LYX_FORMAT) {
530 } else if (file_format > LYX_FORMAT) {
532 Alert::alert(_("Warning!"),
533 _("The file was created with a newer version of "
534 "LyX. This is likely to cause problems."));
536 } else if (file_format < LYX_FORMAT) {
538 if (file_format < 200) {
539 Alert::alert(_("ERROR!"),
540 _("Old LyX file format found. "
541 "Use LyX 0.10.x to read this!"));
543 } else if (!filename.empty()) {
545 LibFileSearch("lyx2lyx", "lyx2lyx");
546 if (command.empty()) {
547 Alert::alert(_("ERROR!"),
548 _("Can't find conversion script."));
552 +tostr(LYX_FORMAT) + ' '
553 + QuoteName(filename);
554 lyxerr[Debug::INFO] << "Running '"
557 cmd_ret const ret = RunCommand(command);
559 Alert::alert(_("ERROR!"),
560 _("An error occured while "
561 "running the conversion script."));
564 istringstream is(STRCONV(ret.second));
566 tmplex.setStream(is);
567 return readFile(tmplex, string(), pit);
569 // This code is reached if lyx2lyx failed (for
570 // some reason) to change the file format of
576 bool the_end = readBody(lex, pit);
577 params.setPaperStuff();
580 Alert::alert(_("Warning!"),
581 _("Reading of document is not complete"),
582 _("Maybe the document is truncated"));
585 } else { // "\\lyxformat" not found
586 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
589 Alert::alert(_("ERROR!"), _("Unable to read file!"));
594 // Should probably be moved to somewhere else: BufferView? LyXView?
595 bool Buffer::save() const
597 // We don't need autosaves in the immediate future. (Asger)
598 resetAutosaveTimers();
602 if (lyxrc.make_backup) {
603 s = fileName() + '~';
604 if (!lyxrc.backupdir_path.empty())
605 s = AddName(lyxrc.backupdir_path,
606 subst(os::slashify_path(s),'/','!'));
608 // Rename is the wrong way of making a backup,
609 // this is the correct way.
610 /* truss cp fil fil2:
611 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
612 stat("LyXVC.lyx", 0xEFFFF688) = 0
613 open("LyXVC.lyx", O_RDONLY) = 3
614 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
615 fstat(4, 0xEFFFF508) = 0
616 fstat(3, 0xEFFFF508) = 0
617 read(3, " # T h i s f i l e w".., 8192) = 5579
618 write(4, " # T h i s f i l e w".., 5579) = 5579
619 read(3, 0xEFFFD4A0, 8192) = 0
622 chmod("LyXVC3.lyx", 0100644) = 0
623 lseek(0, 0, SEEK_CUR) = 46440
627 // Should probably have some more error checking here.
628 // Doing it this way, also makes the inodes stay the same.
629 // This is still not a very good solution, in particular we
630 // might loose the owner of the backup.
631 FileInfo finfo(fileName());
633 mode_t fmode = finfo.getMode();
634 struct utimbuf times = {
635 finfo.getAccessTime(),
636 finfo.getModificationTime() };
638 ifstream ifs(fileName().c_str());
639 ofstream ofs(s.c_str(), ios::out|ios::trunc);
644 ::chmod(s.c_str(), fmode);
646 if (::utime(s.c_str(), ×)) {
647 lyxerr << "utime error." << endl;
650 lyxerr << "LyX was not able to make "
651 "backup copy. Beware." << endl;
656 if (writeFile(fileName())) {
658 removeAutosaveFile(fileName());
660 // Saving failed, so backup is not backup
661 if (lyxrc.make_backup) {
662 lyx::rename(s, fileName());
670 bool Buffer::writeFile(string const & fname) const
672 if (read_only && (fname == fileName())) {
676 FileInfo finfo(fname);
677 if (finfo.exist() && !finfo.writable()) {
681 ofstream ofs(fname.c_str());
687 // Use the standard "C" locale for file output.
688 ofs.imbue(std::locale::classic());
691 // The top of the file should not be written by params.
693 // write out a comment in the top of the file
694 ofs << '#' << lyx_docversion
695 << " created this file. For more info see http://www.lyx.org/\n"
696 << "\\lyxformat " << LYX_FORMAT << "\n";
698 // now write out the buffer paramters.
699 params.writeFile(ofs);
701 ofs << "\\end_header\n";
703 Paragraph::depth_type depth = 0;
705 // this will write out all the paragraphs
706 // using recursive descent.
707 ParagraphList::iterator pit = paragraphs.begin();
708 ParagraphList::iterator pend = paragraphs.end();
709 for (; pit != pend; ++pit)
710 pit->write(this, ofs, params, depth);
712 // Write marker that shows file is complete
713 ofs << "\n\\the_end" << endl;
717 // how to check if close went ok?
718 // Following is an attempt... (BE 20001011)
720 // good() returns false if any error occured, including some
722 // bad() returns true if something bad happened in the buffer,
723 // which should include file system full errors.
730 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
732 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
744 pair<int, string> const addDepth(int depth, int ldepth)
748 d += (ldepth - depth) * 2;
749 return make_pair(d, string(d, ' '));
755 string const Buffer::asciiParagraph(Paragraph const & par,
756 unsigned int linelen,
757 bool noparbreak) const
759 ostringstream buffer;
760 Paragraph::depth_type depth = 0;
762 Paragraph::depth_type ltype_depth = 0;
763 bool ref_printed = false;
764 // if (!par->previous()) {
766 // begins or ends a deeper area ?
767 if (depth != par->params().depth()) {
768 if (par->params().depth() > depth) {
769 while (par->params().depth() > depth) {
773 while (par->params().depth() < depth) {
779 depth = par.params().depth();
782 // First write the layout
783 string const & tmp = par.layout()->name();
784 if (compare_no_case(tmp, "itemize") == 0) {
786 ltype_depth = depth + 1;
787 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
789 ltype_depth = depth + 1;
790 } else if (contains(ascii_lowercase(tmp), "ection")) {
792 ltype_depth = depth + 1;
793 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
795 ltype_depth = depth + 1;
796 } else if (compare_ascii_no_case(tmp, "description") == 0) {
798 ltype_depth = depth + 1;
799 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
802 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
810 /* maybe some vertical spaces */
812 /* the labelwidthstring used in lists */
816 /* some pagebreaks? */
820 /* what about the alignment */
822 // lyxerr << "Should this ever happen?" << endl;
825 // linelen <= 0 is special and means we don't have paragraph breaks
827 string::size_type currlinelen = 0;
833 buffer << string(depth * 2, ' ');
834 currlinelen += depth * 2;
837 // we should probably change to the paragraph language in the
838 // gettext here (if possible) so that strings are outputted in
839 // the correct language! (20012712 Jug)
843 case 4: // (Sub)Paragraph
844 case 5: // Description
848 buffer << _("Abstract") << "\n\n";
851 string const abst = _("Abstract: ");
853 currlinelen += abst.length();
856 case 7: // Bibliography
859 buffer << _("References") << "\n\n";
862 string const refs = _("References: ");
864 currlinelen += refs.length();
872 string const parlab = par.params().labelString();
873 buffer << parlab << ' ';
874 currlinelen += parlab.length() + 1;
882 pair<int, string> p = addDepth(depth, ltype_depth);
884 currlinelen += p.first;
887 // this is to change the linebreak to do it by word a bit more
888 // intelligent hopefully! (only in the case where we have a
889 // max linelength!) (Jug)
893 for (pos_type i = 0; i < par.size(); ++i) {
894 char c = par.getUChar(params, i);
896 case Paragraph::META_INSET:
898 Inset const * inset = par.getInset(i);
902 currlinelen += word.length();
905 if (inset->ascii(this, buffer, linelen)) {
906 // to be sure it breaks paragraph
907 currlinelen += linelen;
916 currlinelen + word.length() > linelen - 10) {
918 pair<int, string> p = addDepth(depth, ltype_depth);
920 currlinelen = p.first;
923 buffer << word << ' ';
924 currlinelen += word.length() + 1;
931 lyxerr[Debug::INFO] <<
932 "writeAsciiFile: NULL char in structure." << endl;
935 (currlinelen + word.length()) > linelen)
939 pair<int, string> p =
940 addDepth(depth, ltype_depth);
942 currlinelen = p.first;
949 return STRCONV(buffer.str());
953 void Buffer::writeFileAscii(string const & fname, int linelen)
955 ofstream ofs(fname.c_str());
957 Alert::err_alert(_("Error: Cannot write file:"), fname);
960 writeFileAscii(ofs, linelen);
964 void Buffer::writeFileAscii(ostream & os, int linelen)
966 ParagraphList::iterator beg = paragraphs.begin();
967 ParagraphList::iterator end = paragraphs.end();
968 ParagraphList::iterator it = beg;
969 for (; it != end; ++it) {
970 os << asciiParagraph(*it, linelen, it == beg);
977 void Buffer::makeLaTeXFile(string const & fname,
978 string const & original_path,
979 bool nice, bool only_body, bool only_preamble)
981 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
983 ofstream ofs(fname.c_str());
985 Alert::err_alert(_("Error: Cannot open file: "), fname);
989 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
993 lyxerr << "File was not closed properly." << endl;
998 void Buffer::makeLaTeXFile(ostream & os,
999 string const & original_path,
1000 bool nice, bool only_body, bool only_preamble)
1002 niceFile = nice; // this will be used by Insetincludes.
1004 // validate the buffer.
1005 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1006 LaTeXFeatures features(params);
1008 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1011 // The starting paragraph of the coming rows is the
1012 // first paragraph of the document. (Asger)
1013 texrow.start(&*(paragraphs.begin()), 0);
1015 if (!only_body && nice) {
1016 os << "%% " << lyx_docversion << " created this file. "
1017 "For more info, see http://www.lyx.org/.\n"
1018 "%% Do not edit unless you really know what "
1023 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1024 // There are a few differences between nice LaTeX and usual files:
1025 // usual is \batchmode and has a
1026 // special input@path to allow the including of figures
1027 // with either \input or \includegraphics (what figinsets do).
1028 // input@path is set when the actual parameter
1029 // original_path is set. This is done for usual tex-file, but not
1030 // for nice-latex-file. (Matthias 250696)
1033 // code for usual, NOT nice-latex-file
1034 os << "\\batchmode\n"; // changed
1035 // from \nonstopmode
1038 if (!original_path.empty()) {
1039 string inputpath = os::external_path(original_path);
1040 subst(inputpath, "~", "\\string~");
1041 os << "\\makeatletter\n"
1042 << "\\def\\input@path{{"
1043 << inputpath << "/}}\n"
1044 << "\\makeatother\n";
1050 // Write the preamble
1051 params.writeLaTeX(os, features, texrow);
1057 os << "\\begin{document}\n";
1060 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1062 if (!lyxrc.language_auto_begin) {
1063 os << subst(lyxrc.language_command_begin, "$$lang",
1064 params.language->babel())
1069 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1071 // add this just in case after all the paragraphs
1075 if (!lyxrc.language_auto_end) {
1076 os << subst(lyxrc.language_command_end, "$$lang",
1077 params.language->babel())
1083 os << "\\end{document}\n";
1086 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1088 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1092 // Just to be sure. (Asger)
1095 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1096 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1099 // we want this to be true outside previews (for insetexternal)
1104 bool Buffer::isLatex() const
1106 return params.getLyXTextClass().outputType() == LATEX;
1110 bool Buffer::isLinuxDoc() const
1112 return params.getLyXTextClass().outputType() == LINUXDOC;
1116 bool Buffer::isLiterate() const
1118 return params.getLyXTextClass().outputType() == LITERATE;
1122 bool Buffer::isDocBook() const
1124 return params.getLyXTextClass().outputType() == DOCBOOK;
1128 bool Buffer::isSGML() const
1130 LyXTextClass const & tclass = params.getLyXTextClass();
1132 return tclass.outputType() == LINUXDOC ||
1133 tclass.outputType() == DOCBOOK;
1137 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1139 ofstream ofs(fname.c_str());
1142 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1146 niceFile = nice; // this will be used by included files.
1148 LaTeXFeatures features(params);
1154 LyXTextClass const & tclass = params.getLyXTextClass();
1156 string top_element = tclass.latexname();
1159 ofs << "<!doctype linuxdoc system";
1161 string preamble = params.preamble;
1162 const string name = nice ? ChangeExtension(filename_, ".sgml")
1164 preamble += features.getIncludedFiles(name);
1165 preamble += features.getLyXSGMLEntities();
1167 if (!preamble.empty()) {
1168 ofs << " [ " << preamble << " ]";
1172 if (params.options.empty())
1173 sgml::openTag(ofs, 0, false, top_element);
1175 string top = top_element;
1177 top += params.options;
1178 sgml::openTag(ofs, 0, false, top);
1182 ofs << "<!-- " << lyx_docversion
1183 << " created this file. For more info see http://www.lyx.org/"
1186 Paragraph::depth_type depth = 0; // paragraph depth
1187 Paragraph * par = &*(paragraphs.begin());
1189 vector<string> environment_stack(5);
1192 LyXLayout_ptr const & style = par->layout();
1193 // treat <toc> as a special case for compatibility with old code
1194 if (par->isInset(0)) {
1195 Inset * inset = par->getInset(0);
1196 Inset::Code lyx_code = inset->lyxCode();
1197 if (lyx_code == Inset::TOC_CODE) {
1198 string const temp = "toc";
1199 sgml::openTag(ofs, depth, false, temp);
1206 // environment tag closing
1207 for (; depth > par->params().depth(); --depth) {
1208 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1209 environment_stack[depth].erase();
1212 // write opening SGML tags
1213 switch (style->latextype) {
1214 case LATEX_PARAGRAPH:
1215 if (depth == par->params().depth()
1216 && !environment_stack[depth].empty()) {
1217 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1218 environment_stack[depth].erase();
1224 sgml::openTag(ofs, depth, false, style->latexname());
1230 _("Error: Wrong depth for LatexType Command.\n"));
1232 if (!environment_stack[depth].empty()) {
1233 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1237 environment_stack[depth].erase();
1238 sgml::openTag(ofs, depth, false, style->latexname());
1241 case LATEX_ENVIRONMENT:
1242 case LATEX_ITEM_ENVIRONMENT:
1243 case LATEX_BIB_ENVIRONMENT:
1245 string const & latexname = style->latexname();
1247 if (depth == par->params().depth()
1248 && environment_stack[depth] != latexname) {
1249 sgml::closeTag(ofs, depth, false,
1250 environment_stack[depth]);
1251 environment_stack[depth].erase();
1253 if (depth < par->params().depth()) {
1254 depth = par->params().depth();
1255 environment_stack[depth].erase();
1257 if (environment_stack[depth] != latexname) {
1259 sgml::openTag(ofs, depth, false, "p");
1261 sgml::openTag(ofs, depth, false, latexname);
1263 if (environment_stack.size() == depth + 1)
1264 environment_stack.push_back("!-- --");
1265 environment_stack[depth] = latexname;
1268 if (style->latexparam() == "CDATA")
1271 if (style->latextype == LATEX_ENVIRONMENT) break;
1273 if (style->labeltype == LABEL_MANUAL)
1278 sgml::openTag(ofs, depth + 1, false, item_name);
1283 sgml::openTag(ofs, depth, false, style->latexname());
1287 simpleLinuxDocOnePar(ofs, par, depth);
1292 // write closing SGML tags
1293 switch (style->latextype) {
1296 case LATEX_ENVIRONMENT:
1297 case LATEX_ITEM_ENVIRONMENT:
1298 case LATEX_BIB_ENVIRONMENT:
1299 if (style->latexparam() == "CDATA")
1303 sgml::closeTag(ofs, depth, false, style->latexname());
1309 for (int i = depth; i >= 0; --i)
1310 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1314 sgml::closeTag(ofs, 0, false, top_element);
1318 // How to check for successful close
1320 // we want this to be true outside previews (for insetexternal)
1325 // checks, if newcol chars should be put into this line
1326 // writes newline, if necessary.
1329 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1330 string::size_type newcol)
1333 if (colcount > lyxrc.ascii_linelen) {
1335 colcount = newcol; // assume write after this call
1350 string tag_name(PAR_TAG const & pt) {
1352 case NONE: return "!-- --";
1353 case TT: return "tt";
1354 case SF: return "sf";
1355 case BF: return "bf";
1356 case IT: return "it";
1357 case SL: return "sl";
1358 case EM: return "em";
1365 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1367 p1 = static_cast<PAR_TAG>(p1 | p2);
1372 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1374 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1380 // Handle internal paragraph parsing -- layout already processed.
1381 void Buffer::simpleLinuxDocOnePar(ostream & os,
1383 Paragraph::depth_type /*depth*/)
1385 LyXLayout_ptr const & style = par->layout();
1387 string::size_type char_line_count = 5; // Heuristic choice ;-)
1389 // gets paragraph main font
1392 if (style->labeltype == LABEL_MANUAL) {
1393 font_old = style->labelfont;
1396 font_old = style->font;
1400 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1401 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1402 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1405 stack<PAR_TAG> tag_state;
1406 // parsing main loop
1407 for (pos_type i = 0; i < par->size(); ++i) {
1409 PAR_TAG tag_close = NONE;
1410 list < PAR_TAG > tag_open;
1412 LyXFont const font = par->getFont(params, i);
1414 if (font_old.family() != font.family()) {
1415 switch (family_type) {
1416 case LyXFont::SANS_FAMILY:
1419 case LyXFont::TYPEWRITER_FAMILY:
1426 family_type = font.family();
1428 switch (family_type) {
1429 case LyXFont::SANS_FAMILY:
1430 tag_open.push_back(SF);
1432 case LyXFont::TYPEWRITER_FAMILY:
1433 tag_open.push_back(TT);
1440 if (font_old.series() != font.series()) {
1441 switch (series_type) {
1442 case LyXFont::BOLD_SERIES:
1449 series_type = font.series();
1451 switch (series_type) {
1452 case LyXFont::BOLD_SERIES:
1453 tag_open.push_back(BF);
1461 if (font_old.shape() != font.shape()) {
1462 switch (shape_type) {
1463 case LyXFont::ITALIC_SHAPE:
1466 case LyXFont::SLANTED_SHAPE:
1473 shape_type = font.shape();
1475 switch (shape_type) {
1476 case LyXFont::ITALIC_SHAPE:
1477 tag_open.push_back(IT);
1479 case LyXFont::SLANTED_SHAPE:
1480 tag_open.push_back(SL);
1487 if (font_old.emph() != font.emph()) {
1488 if (font.emph() == LyXFont::ON) {
1489 tag_open.push_back(EM);
1498 list < PAR_TAG > temp;
1499 while (!tag_state.empty() && tag_close) {
1500 PAR_TAG k = tag_state.top();
1502 os << "</" << tag_name(k) << '>';
1509 for(list< PAR_TAG >::const_iterator j = temp.begin();
1510 j != temp.end(); ++j) {
1512 os << '<' << tag_name(*j) << '>';
1515 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1516 j != tag_open.end(); ++j) {
1518 os << '<' << tag_name(*j) << '>';
1521 char c = par->getChar(i);
1523 if (c == Paragraph::META_INSET) {
1524 Inset * inset = par->getInset(i);
1525 inset->linuxdoc(this, os);
1530 if (style->latexparam() == "CDATA") {
1531 // "TeX"-Mode on == > SGML-Mode on.
1538 boost::tie(ws, str) = sgml::escapeChar(c);
1539 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1540 // in freespacing mode, spaces are
1541 // non-breaking characters
1542 if (desc_on) {// if char is ' ' then...
1545 sgmlLineBreak(os, char_line_count, 6);
1549 sgmlLineBreak(os, char_line_count, 1);
1554 char_line_count += str.length();
1560 while (!tag_state.empty()) {
1561 os << "</" << tag_name(tag_state.top()) << '>';
1565 // resets description flag correctly
1567 // <tag> not closed...
1568 sgmlLineBreak(os, char_line_count, 6);
1574 // Print an error message.
1575 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
1576 string const & /*message*/) const
1578 #ifdef WITH_WARNINGS
1579 #warning This is wrong we cannot insert an inset like this!!!
1580 // I guess this was Jose' so I explain you more or less why this
1581 // is wrong. This way you insert something in the paragraph and
1582 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1583 // I deactivate this code, have a look at BufferView::insertErrors
1584 // how you should do this correctly! (Jug 20020315)
1587 // insert an error marker in text
1588 InsetError * new_inset = new InsetError(message);
1589 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1595 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1597 ofstream ofs(fname.c_str());
1599 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1603 Paragraph * par = &*(paragraphs.begin());
1605 niceFile = nice; // this will be used by Insetincludes.
1607 LaTeXFeatures features(params);
1612 LyXTextClass const & tclass = params.getLyXTextClass();
1613 string top_element = tclass.latexname();
1616 ofs << "<!DOCTYPE " << top_element
1617 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1619 string preamble = params.preamble;
1620 const string name = nice ? ChangeExtension(filename_, ".sgml")
1622 preamble += features.getIncludedFiles(name);
1623 preamble += features.getLyXSGMLEntities();
1625 if (!preamble.empty()) {
1626 ofs << "\n [ " << preamble << " ]";
1631 string top = top_element;
1633 top += params.language->code();
1636 if (!params.options.empty()) {
1638 top += params.options;
1640 sgml::openTag(ofs, 0, false, top);
1642 ofs << "<!-- DocBook file was created by " << lyx_docversion
1643 << "\n See http://www.lyx.org/ for more information -->\n";
1645 vector<string> environment_stack(10);
1646 vector<string> environment_inner(10);
1647 vector<string> command_stack(10);
1649 bool command_flag = false;
1650 Paragraph::depth_type command_depth = 0;
1651 Paragraph::depth_type command_base = 0;
1652 Paragraph::depth_type cmd_depth = 0;
1653 Paragraph::depth_type depth = 0; // paragraph depth
1656 string command_name;
1662 int desc_on = 0; // description mode
1664 LyXLayout_ptr const & style = par->layout();
1666 // environment tag closing
1667 for (; depth > par->params().depth(); --depth) {
1668 if (environment_inner[depth] != "!-- --") {
1669 item_name = "listitem";
1670 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1671 if (environment_inner[depth] == "varlistentry")
1672 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1674 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1675 environment_stack[depth].erase();
1676 environment_inner[depth].erase();
1679 if (depth == par->params().depth()
1680 && environment_stack[depth] != style->latexname()
1681 && !environment_stack[depth].empty()) {
1682 if (environment_inner[depth] != "!-- --") {
1683 item_name= "listitem";
1684 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1685 if (environment_inner[depth] == "varlistentry")
1686 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1689 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1691 environment_stack[depth].erase();
1692 environment_inner[depth].erase();
1695 // Write opening SGML tags.
1696 switch (style->latextype) {
1697 case LATEX_PARAGRAPH:
1698 sgml::openTag(ofs, depth + command_depth,
1699 false, style->latexname());
1705 _("Error: Wrong depth for LatexType Command.\n"));
1707 command_name = style->latexname();
1709 sgmlparam = style->latexparam();
1710 c_params = split(sgmlparam, c_depth,'|');
1712 cmd_depth = lyx::atoi(c_depth);
1715 if (cmd_depth < command_base) {
1716 for (Paragraph::depth_type j = command_depth;
1717 j >= command_base; --j) {
1718 sgml::closeTag(ofs, j, false, command_stack[j]);
1721 command_depth = command_base = cmd_depth;
1722 } else if (cmd_depth <= command_depth) {
1723 for (int j = command_depth;
1724 j >= int(cmd_depth); --j) {
1725 sgml::closeTag(ofs, j, false, command_stack[j]);
1728 command_depth = cmd_depth;
1730 command_depth = cmd_depth;
1732 command_depth = command_base = cmd_depth;
1733 command_flag = true;
1735 if (command_stack.size() == command_depth + 1)
1736 command_stack.push_back(string());
1737 command_stack[command_depth] = command_name;
1739 // treat label as a special case for
1740 // more WYSIWYM handling.
1741 // This is a hack while paragraphs can't have
1742 // attributes, like id in this case.
1743 if (par->isInset(0)) {
1744 Inset * inset = par->getInset(0);
1745 Inset::Code lyx_code = inset->lyxCode();
1746 if (lyx_code == Inset::LABEL_CODE) {
1747 command_name += " id=\"";
1748 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1749 command_name += '"';
1754 sgml::openTag(ofs, depth + command_depth, false, command_name);
1756 item_name = c_params.empty() ? "title" : c_params;
1757 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1760 case LATEX_ENVIRONMENT:
1761 case LATEX_ITEM_ENVIRONMENT:
1762 if (depth < par->params().depth()) {
1763 depth = par->params().depth();
1764 environment_stack[depth].erase();
1767 if (environment_stack[depth] != style->latexname()) {
1768 if (environment_stack.size() == depth + 1) {
1769 environment_stack.push_back("!-- --");
1770 environment_inner.push_back("!-- --");
1772 environment_stack[depth] = style->latexname();
1773 environment_inner[depth] = "!-- --";
1774 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1776 if (environment_inner[depth] != "!-- --") {
1777 item_name= "listitem";
1778 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1779 if (environment_inner[depth] == "varlistentry")
1780 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1784 if (style->latextype == LATEX_ENVIRONMENT) {
1785 if (!style->latexparam().empty()) {
1786 if (style->latexparam() == "CDATA")
1789 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1794 desc_on = (style->labeltype == LABEL_MANUAL);
1796 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1797 sgml::openTag(ofs, depth + 1 + command_depth,
1798 false, environment_inner[depth]);
1800 item_name = desc_on ? "term" : "para";
1801 sgml::openTag(ofs, depth + 1 + command_depth,
1805 sgml::openTag(ofs, depth + command_depth,
1806 false, style->latexname());
1810 simpleDocBookOnePar(ofs, par, desc_on,
1811 depth + 1 + command_depth);
1815 // write closing SGML tags
1816 switch (style->latextype) {
1818 end_tag = c_params.empty() ? "title" : c_params;
1819 sgml::closeTag(ofs, depth + command_depth,
1822 case LATEX_ENVIRONMENT:
1823 if (!style->latexparam().empty()) {
1824 if (style->latexparam() == "CDATA")
1827 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1830 case LATEX_ITEM_ENVIRONMENT:
1831 if (desc_on == 1) break;
1833 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1835 case LATEX_PARAGRAPH:
1836 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1839 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1845 for (int d = depth; d >= 0; --d) {
1846 if (!environment_stack[depth].empty()) {
1847 if (environment_inner[depth] != "!-- --") {
1848 item_name = "listitem";
1849 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1850 if (environment_inner[depth] == "varlistentry")
1851 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1854 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1858 for (int j = command_depth; j >= 0 ; --j)
1859 if (!command_stack[j].empty()) {
1860 sgml::closeTag(ofs, j, false, command_stack[j]);
1865 sgml::closeTag(ofs, 0, false, top_element);
1868 // How to check for successful close
1870 // we want this to be true outside previews (for insetexternal)
1875 void Buffer::simpleDocBookOnePar(ostream & os,
1876 Paragraph * par, int & desc_on,
1877 Paragraph::depth_type depth) const
1879 bool emph_flag = false;
1881 LyXLayout_ptr const & style = par->layout();
1883 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1885 int char_line_count = depth;
1886 //if (!style.free_spacing)
1887 // os << string(depth,' ');
1889 // parsing main loop
1890 for (pos_type i = 0; i < par->size(); ++i) {
1891 LyXFont font = par->getFont(params, i);
1893 // handle <emphasis> tag
1894 if (font_old.emph() != font.emph()) {
1895 if (font.emph() == LyXFont::ON) {
1896 if (style->latexparam() == "CDATA")
1899 if (style->latexparam() == "CDATA")
1903 if (style->latexparam() == "CDATA")
1905 os << "</emphasis>";
1906 if (style->latexparam() == "CDATA")
1913 if (par->isInset(i)) {
1914 Inset * inset = par->getInset(i);
1915 // don't print the inset in position 0 if desc_on == 3 (label)
1916 if (i || desc_on != 3) {
1917 if (style->latexparam() == "CDATA")
1919 inset->docbook(this, os, false);
1920 if (style->latexparam() == "CDATA")
1924 char c = par->getChar(i);
1927 boost::tie(ws, str) = sgml::escapeChar(c);
1929 if (style->pass_thru) {
1931 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1933 } else if (desc_on ==1) {
1935 os << "\n</term><listitem><para>";
1945 if (style->latexparam() == "CDATA")
1947 os << "</emphasis>";
1948 if (style->latexparam() == "CDATA")
1952 // resets description flag correctly
1954 // <term> not closed...
1955 os << "</term>\n<listitem><para> </para>";
1957 if (style->free_spacing)
1962 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1963 // Other flags: -wall -v0 -x
1964 int Buffer::runChktex()
1966 if (!users->text) return 0;
1968 users->owner()->busy(true);
1970 // get LaTeX-Filename
1971 string const name = getLatexName();
1972 string path = filePath();
1974 string const org_path = path;
1975 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1979 Path p(path); // path to LaTeX file
1980 users->owner()->message(_("Running chktex..."));
1982 // Remove all error insets
1983 bool const removedErrorInsets = users->removeAutoInsets();
1985 // Generate the LaTeX file if neccessary
1986 makeLaTeXFile(name, org_path, false);
1989 Chktex chktex(lyxrc.chktex_command, name, filePath());
1990 int res = chktex.run(terr); // run chktex
1993 Alert::alert(_("chktex did not work!"),
1994 _("Could not run with file:"), name);
1995 } else if (res > 0) {
1996 // Insert all errors as errors boxes
1997 users->insertErrors(terr);
2000 // if we removed error insets before we ran chktex or if we inserted
2001 // error insets after we ran chktex, this must be run:
2002 if (removedErrorInsets || res) {
2003 #warning repaint needed here, or do you mean update() ?
2007 users->owner()->busy(false);
2013 void Buffer::validate(LaTeXFeatures & features) const
2015 LyXTextClass const & tclass = params.getLyXTextClass();
2017 if (params.tracking_changes) {
2018 features.require("dvipost");
2019 features.require("color");
2022 // AMS Style is at document level
2023 if (params.use_amsmath == BufferParams::AMS_ON
2024 || tclass.provides(LyXTextClass::amsmath))
2025 features.require("amsmath");
2027 for_each(paragraphs.begin(), paragraphs.end(),
2028 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2030 // the bullet shapes are buffer level not paragraph level
2031 // so they are tested here
2032 for (int i = 0; i < 4; ++i) {
2033 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2034 int const font = params.user_defined_bullets[i].getFont();
2036 int const c = params
2037 .user_defined_bullets[i]
2044 features.require("latexsym");
2046 } else if (font == 1) {
2047 features.require("amssymb");
2048 } else if ((font >= 2 && font <= 5)) {
2049 features.require("pifont");
2054 if (lyxerr.debugging(Debug::LATEX)) {
2055 features.showStruct();
2060 vector<string> const Buffer::getLabelList() const
2062 /// if this is a child document and the parent is already loaded
2063 /// Use the parent's list instead [ale990407]
2064 if (!params.parentname.empty()
2065 && bufferlist.exists(params.parentname)) {
2066 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2068 return tmp->getLabelList();
2071 vector<string> label_list;
2072 for (inset_iterator it = inset_const_iterator_begin();
2073 it != inset_const_iterator_end(); ++it) {
2074 vector<string> const l = it->getLabelList();
2075 label_list.insert(label_list.end(), l.begin(), l.end());
2081 // This is also a buffer property (ale)
2082 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2084 /// if this is a child document and the parent is already loaded
2085 /// use the parent's list instead [ale990412]
2086 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2087 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2089 tmp->fillWithBibKeys(keys);
2094 for (inset_iterator it = inset_const_iterator_begin();
2095 it != inset_const_iterator_end(); ++it) {
2096 if (it->lyxCode() == Inset::BIBTEX_CODE)
2097 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2098 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2099 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2100 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2101 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2102 string const key = bib.getContents();
2103 string const opt = bib.getOptions();
2104 string const ref; // = pit->asString(this, false);
2105 string const info = opt + "TheBibliographyRef" + ref;
2106 keys.push_back(pair<string, string>(key, info));
2112 bool Buffer::isDepClean(string const & name) const
2114 DepClean::const_iterator it = dep_clean_.find(name);
2115 if (it == dep_clean_.end())
2121 void Buffer::markDepClean(string const & name)
2123 dep_clean_[name] = true;
2127 bool Buffer::dispatch(string const & command, bool * result)
2129 // Split command string into command and argument
2131 string line = ltrim(command);
2132 string const arg = trim(split(line, cmd, ' '));
2134 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2138 bool Buffer::dispatch(int action, string const & argument, bool * result)
2140 bool dispatched = true;
2144 bool const tmp = Exporter::Export(this, argument, false);
2157 void Buffer::resizeInsets(BufferView * bv)
2159 /// then remove all LyXText in text-insets
2160 for_each(paragraphs.begin(), paragraphs.end(),
2161 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2165 void Buffer::redraw()
2167 #warning repaint needed here, or do you mean update() ?
2173 void Buffer::changeLanguage(Language const * from, Language const * to)
2176 ParIterator end = par_iterator_end();
2177 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2178 (*it)->changeLanguage(params, from, to);
2182 bool Buffer::isMultiLingual()
2184 ParIterator end = par_iterator_end();
2185 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2186 if ((*it)->isMultiLingual(params))
2193 void Buffer::inset_iterator::setParagraph()
2195 while (pit != pend) {
2196 it = pit->insetlist.begin();
2197 if (it != pit->insetlist.end())
2204 Inset * Buffer::getInsetFromID(int id_arg) const
2206 for (inset_iterator it = inset_const_iterator_begin();
2207 it != inset_const_iterator_end(); ++it)
2209 if (it->id() == id_arg)
2211 Inset * in = it->getInsetFromID(id_arg);
2219 Paragraph * Buffer::getParFromID(int id) const
2224 // why should we allow < 0 ??
2225 //lyx::Assert(id >= 0);
2227 ParConstIterator it(par_iterator_begin());
2228 ParConstIterator end(par_iterator_end());
2230 for (; it != end; ++it) {
2231 // go on then, show me how to remove
2233 if ((*it)->id() == id) {
2234 return const_cast<Paragraph*>(*it);
2242 ParIterator Buffer::par_iterator_begin()
2244 return ParIterator(&*(paragraphs.begin()));
2248 ParIterator Buffer::par_iterator_end()
2250 return ParIterator();
2253 ParConstIterator Buffer::par_iterator_begin() const
2255 return ParConstIterator(&*(paragraphs.begin()));
2259 ParConstIterator Buffer::par_iterator_end() const
2261 return ParConstIterator();
2266 void Buffer::addUser(BufferView * u)
2272 void Buffer::delUser(BufferView *)
2278 Language const * Buffer::getLanguage() const
2280 return params.language;
2284 bool Buffer::isClean() const
2290 bool Buffer::isBakClean() const
2296 void Buffer::markClean() const
2302 // if the .lyx file has been saved, we don't need an
2308 void Buffer::markBakClean()
2314 void Buffer::setUnnamed(bool flag)
2320 bool Buffer::isUnnamed()
2326 void Buffer::markDirty()
2334 DepClean::iterator it = dep_clean_.begin();
2335 DepClean::const_iterator const end = dep_clean_.end();
2337 for (; it != end; ++it) {
2343 string const & Buffer::fileName() const
2349 string const & Buffer::filePath() const
2355 bool Buffer::isReadonly() const
2361 BufferView * Buffer::getUser() const
2367 void Buffer::setParentName(string const & name)
2369 params.parentname = name;
2373 Buffer::inset_iterator::inset_iterator()
2378 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2385 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2389 if (it == pit->insetlist.end()) {
2398 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2400 inset_iterator tmp = *this;
2406 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2408 return *it.getInset();
2412 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2414 return it.getInset();
2418 Paragraph * Buffer::inset_iterator::getPar()
2424 lyx::pos_type Buffer::inset_iterator::getPos() const
2430 bool operator==(Buffer::inset_iterator const & iter1,
2431 Buffer::inset_iterator const & iter2)
2433 return iter1.pit == iter2.pit
2434 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2438 bool operator!=(Buffer::inset_iterator const & iter1,
2439 Buffer::inset_iterator const & iter2)
2441 return !(iter1 == iter2);