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 = 222;
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(users, paragraphs);
343 // We don't want to adopt the parameters from the
344 // document we insert, so read them into a temporary buffer
345 // and then discard it
347 Buffer tmpbuf("", false);
348 tmpbuf.readHeader(lex);
353 string const token = lex.getString();
358 lyxerr[Debug::PARSER] << "Handling token: `"
359 << token << '\'' << endl;
361 if (token == "\\the_end") {
366 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
369 if (unknown_layouts > 0) {
370 string s = _("Couldn't set the layout for ");
371 if (unknown_layouts == 1) {
372 s += _("one paragraph");
374 s += tostr(unknown_layouts);
375 s += _(" paragraphs");
378 Alert::alert(_("Textclass Loading Error!"), s,
379 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
381 Alert::alert(_("Textclass Loading Error!"), s,
382 _("When reading ") + fileName());
386 if (unknown_tokens > 0) {
387 string s = _("Encountered ");
388 if (unknown_tokens == 1) {
389 s += _("one unknown token");
391 s += tostr(unknown_tokens);
392 s += _(" unknown tokens");
395 Alert::alert(_("Textclass Loading Error!"), s,
396 boost::io::str(boost::format(_("When reading %1$s")) % fileName()));
398 Alert::alert(_("Textclass Loading Error!"), s,
399 _("When reading ") + fileName());
408 Buffer::readParagraph(LyXLex & lex, string const & token,
409 ParagraphList & pars, ParagraphList::iterator & pit,
410 Paragraph::depth_type & depth)
412 static Change current_change;
415 if (token == "\\layout") {
416 lex.pushToken(token);
418 Paragraph * par = new Paragraph();
419 par->params().depth(depth);
420 if (params.tracking_changes)
422 LyXFont f(LyXFont::ALL_INHERIT, params.language);
425 // FIXME: goddamn InsetTabular makes us pass a Buffer
427 unknown += ::readParagraph(*this, *par, lex);
430 if (pit != pars.end())
432 pit = pars.insert(pit, par);
433 } else if (token == "\\begin_deeper") {
435 } else if (token == "\\end_deeper") {
437 lex.printError("\\end_deeper: " "depth is already null");
448 // needed to insert the selection
449 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
450 LyXFont const & fn,string const & str)
452 LyXLayout_ptr const & layout = par->layout();
456 par->checkInsertChar(font);
457 // insert the string, don't insert doublespace
458 bool space_inserted = true;
459 bool autobreakrows = !par->inInset() ||
460 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
461 for(string::const_iterator cit = str.begin();
462 cit != str.end(); ++cit) {
464 if (autobreakrows && (!par->empty() || layout->keepempty)) {
465 breakParagraph(params, paragraphs, par, pos,
466 layout->isEnvironment());
469 space_inserted = true;
473 // do not insert consecutive spaces if !free_spacing
474 } else if ((*cit == ' ' || *cit == '\t') &&
475 space_inserted && !layout->free_spacing &&
476 !par->isFreeSpacing())
479 } else if (*cit == '\t') {
480 if (!layout->free_spacing && !par->isFreeSpacing()) {
481 // tabs are like spaces here
482 par->insertChar(pos, ' ', font);
484 space_inserted = true;
486 const pos_type nb = 8 - pos % 8;
487 for (pos_type a = 0; a < nb ; ++a) {
488 par->insertChar(pos, ' ', font);
491 space_inserted = true;
493 } else if (!IsPrintable(*cit)) {
494 // Ignore unprintables
497 // just insert the character
498 par->insertChar(pos, *cit, font);
500 space_inserted = (*cit == ' ');
507 bool Buffer::readFile(LyXLex & lex, string const & filename)
509 return readFile(lex, filename, paragraphs.begin());
513 bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iterator pit)
517 string const token(lex.getString());
518 if (token == "\\lyxformat") { // the first token _must_ be...
520 string tmp_format = lex.getString();
521 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
522 // if present remove ".," from string.
523 string::size_type dot = tmp_format.find_first_of(".,");
524 //lyxerr << " dot found at " << dot << endl;
525 if (dot != string::npos)
526 tmp_format.erase(dot, 1);
527 file_format = strToInt(tmp_format);
528 //lyxerr << "format: " << file_format << endl;
529 if (file_format == LYX_FORMAT) {
531 } else if (file_format > LYX_FORMAT) {
533 Alert::alert(_("Warning!"),
534 _("The file was created with a newer version of "
535 "LyX. This is likely to cause problems."));
537 } else if (file_format < LYX_FORMAT) {
539 if (file_format < 200) {
540 Alert::alert(_("ERROR!"),
541 _("Old LyX file format found. "
542 "Use LyX 0.10.x to read this!"));
544 } else if (!filename.empty()) {
546 LibFileSearch("lyx2lyx", "lyx2lyx");
547 if (command.empty()) {
548 Alert::alert(_("ERROR!"),
549 _("Can't find conversion script."));
553 +tostr(LYX_FORMAT) + ' '
554 + QuoteName(filename);
555 lyxerr[Debug::INFO] << "Running '"
558 cmd_ret const ret = RunCommand(command);
560 Alert::alert(_("ERROR!"),
561 _("An error occured while "
562 "running the conversion script."));
565 istringstream is(STRCONV(ret.second));
567 tmplex.setStream(is);
568 return readFile(tmplex, string(), pit);
570 // This code is reached if lyx2lyx failed (for
571 // some reason) to change the file format of
577 bool the_end = readBody(lex, pit);
578 params.setPaperStuff();
581 Alert::alert(_("Warning!"),
582 _("Reading of document is not complete"),
583 _("Maybe the document is truncated"));
586 } else { // "\\lyxformat" not found
587 Alert::alert(_("ERROR!"), _("Not a LyX file!"));
590 Alert::alert(_("ERROR!"), _("Unable to read file!"));
595 // Should probably be moved to somewhere else: BufferView? LyXView?
596 bool Buffer::save() const
598 // We don't need autosaves in the immediate future. (Asger)
599 resetAutosaveTimers();
603 if (lyxrc.make_backup) {
604 s = fileName() + '~';
605 if (!lyxrc.backupdir_path.empty())
606 s = AddName(lyxrc.backupdir_path,
607 subst(os::slashify_path(s),'/','!'));
609 // Rename is the wrong way of making a backup,
610 // this is the correct way.
611 /* truss cp fil fil2:
612 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
613 stat("LyXVC.lyx", 0xEFFFF688) = 0
614 open("LyXVC.lyx", O_RDONLY) = 3
615 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
616 fstat(4, 0xEFFFF508) = 0
617 fstat(3, 0xEFFFF508) = 0
618 read(3, " # T h i s f i l e w".., 8192) = 5579
619 write(4, " # T h i s f i l e w".., 5579) = 5579
620 read(3, 0xEFFFD4A0, 8192) = 0
623 chmod("LyXVC3.lyx", 0100644) = 0
624 lseek(0, 0, SEEK_CUR) = 46440
628 // Should probably have some more error checking here.
629 // Doing it this way, also makes the inodes stay the same.
630 // This is still not a very good solution, in particular we
631 // might loose the owner of the backup.
632 FileInfo finfo(fileName());
634 mode_t fmode = finfo.getMode();
635 struct utimbuf times = {
636 finfo.getAccessTime(),
637 finfo.getModificationTime() };
639 ifstream ifs(fileName().c_str());
640 ofstream ofs(s.c_str(), ios::out|ios::trunc);
645 ::chmod(s.c_str(), fmode);
647 if (::utime(s.c_str(), ×)) {
648 lyxerr << "utime error." << endl;
651 lyxerr << "LyX was not able to make "
652 "backup copy. Beware." << endl;
657 if (writeFile(fileName())) {
659 removeAutosaveFile(fileName());
661 // Saving failed, so backup is not backup
662 if (lyxrc.make_backup) {
663 lyx::rename(s, fileName());
671 bool Buffer::writeFile(string const & fname) const
673 if (read_only && (fname == fileName())) {
677 FileInfo finfo(fname);
678 if (finfo.exist() && !finfo.writable()) {
682 ofstream ofs(fname.c_str());
688 // Use the standard "C" locale for file output.
689 ofs.imbue(std::locale::classic());
692 // The top of the file should not be written by params.
694 // write out a comment in the top of the file
695 ofs << '#' << lyx_docversion
696 << " created this file. For more info see http://www.lyx.org/\n"
697 << "\\lyxformat " << LYX_FORMAT << "\n";
699 // now write out the buffer paramters.
700 params.writeFile(ofs);
702 ofs << "\\end_header\n";
704 Paragraph::depth_type depth = 0;
706 // this will write out all the paragraphs
707 // using recursive descent.
708 ParagraphList::iterator pit = paragraphs.begin();
709 ParagraphList::iterator pend = paragraphs.end();
710 for (; pit != pend; ++pit)
711 pit->write(this, ofs, params, depth);
713 // Write marker that shows file is complete
714 ofs << "\n\\the_end" << endl;
718 // how to check if close went ok?
719 // Following is an attempt... (BE 20001011)
721 // good() returns false if any error occured, including some
723 // bad() returns true if something bad happened in the buffer,
724 // which should include file system full errors.
731 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
733 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
745 pair<int, string> const addDepth(int depth, int ldepth)
749 d += (ldepth - depth) * 2;
750 return make_pair(d, string(d, ' '));
756 string const Buffer::asciiParagraph(Paragraph const & par,
757 unsigned int linelen,
758 bool noparbreak) const
760 ostringstream buffer;
761 Paragraph::depth_type depth = 0;
763 Paragraph::depth_type ltype_depth = 0;
764 bool ref_printed = false;
765 // if (!par->previous()) {
767 // begins or ends a deeper area ?
768 if (depth != par->params().depth()) {
769 if (par->params().depth() > depth) {
770 while (par->params().depth() > depth) {
774 while (par->params().depth() < depth) {
780 depth = par.params().depth();
783 // First write the layout
784 string const & tmp = par.layout()->name();
785 if (compare_no_case(tmp, "itemize") == 0) {
787 ltype_depth = depth + 1;
788 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
790 ltype_depth = depth + 1;
791 } else if (contains(ascii_lowercase(tmp), "ection")) {
793 ltype_depth = depth + 1;
794 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
796 ltype_depth = depth + 1;
797 } else if (compare_ascii_no_case(tmp, "description") == 0) {
799 ltype_depth = depth + 1;
800 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
803 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
811 /* maybe some vertical spaces */
813 /* the labelwidthstring used in lists */
817 /* some pagebreaks? */
821 /* what about the alignment */
823 // lyxerr << "Should this ever happen?" << endl;
826 // linelen <= 0 is special and means we don't have paragraph breaks
828 string::size_type currlinelen = 0;
834 buffer << string(depth * 2, ' ');
835 currlinelen += depth * 2;
838 // we should probably change to the paragraph language in the
839 // gettext here (if possible) so that strings are outputted in
840 // the correct language! (20012712 Jug)
844 case 4: // (Sub)Paragraph
845 case 5: // Description
849 buffer << _("Abstract") << "\n\n";
852 string const abst = _("Abstract: ");
854 currlinelen += abst.length();
857 case 7: // Bibliography
860 buffer << _("References") << "\n\n";
863 string const refs = _("References: ");
865 currlinelen += refs.length();
873 string const parlab = par.params().labelString();
874 buffer << parlab << ' ';
875 currlinelen += parlab.length() + 1;
883 pair<int, string> p = addDepth(depth, ltype_depth);
885 currlinelen += p.first;
888 // this is to change the linebreak to do it by word a bit more
889 // intelligent hopefully! (only in the case where we have a
890 // max linelength!) (Jug)
894 for (pos_type i = 0; i < par.size(); ++i) {
895 char c = par.getUChar(params, i);
897 case Paragraph::META_INSET:
899 Inset const * inset = par.getInset(i);
903 currlinelen += word.length();
906 if (inset->ascii(this, buffer, linelen)) {
907 // to be sure it breaks paragraph
908 currlinelen += linelen;
917 currlinelen + word.length() > linelen - 10) {
919 pair<int, string> p = addDepth(depth, ltype_depth);
921 currlinelen = p.first;
924 buffer << word << ' ';
925 currlinelen += word.length() + 1;
932 lyxerr[Debug::INFO] <<
933 "writeAsciiFile: NULL char in structure." << endl;
936 (currlinelen + word.length()) > linelen)
940 pair<int, string> p =
941 addDepth(depth, ltype_depth);
943 currlinelen = p.first;
950 return STRCONV(buffer.str());
954 void Buffer::writeFileAscii(string const & fname, int linelen)
956 ofstream ofs(fname.c_str());
958 Alert::err_alert(_("Error: Cannot write file:"), fname);
961 writeFileAscii(ofs, linelen);
965 void Buffer::writeFileAscii(ostream & os, int linelen)
967 ParagraphList::iterator beg = paragraphs.begin();
968 ParagraphList::iterator end = paragraphs.end();
969 ParagraphList::iterator it = beg;
970 for (; it != end; ++it) {
971 os << asciiParagraph(*it, linelen, it == beg);
978 void Buffer::makeLaTeXFile(string const & fname,
979 string const & original_path,
980 bool nice, bool only_body, bool only_preamble)
982 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
984 ofstream ofs(fname.c_str());
986 Alert::err_alert(_("Error: Cannot open file: "), fname);
990 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
994 lyxerr << "File was not closed properly." << endl;
999 void Buffer::makeLaTeXFile(ostream & os,
1000 string const & original_path,
1001 bool nice, bool only_body, bool only_preamble)
1003 niceFile = nice; // this will be used by Insetincludes.
1005 // validate the buffer.
1006 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1007 LaTeXFeatures features(params);
1009 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1012 // The starting paragraph of the coming rows is the
1013 // first paragraph of the document. (Asger)
1014 texrow.start(&*(paragraphs.begin()), 0);
1016 if (!only_body && nice) {
1017 os << "%% " << lyx_docversion << " created this file. "
1018 "For more info, see http://www.lyx.org/.\n"
1019 "%% Do not edit unless you really know what "
1024 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1025 // There are a few differences between nice LaTeX and usual files:
1026 // usual is \batchmode and has a
1027 // special input@path to allow the including of figures
1028 // with either \input or \includegraphics (what figinsets do).
1029 // input@path is set when the actual parameter
1030 // original_path is set. This is done for usual tex-file, but not
1031 // for nice-latex-file. (Matthias 250696)
1034 // code for usual, NOT nice-latex-file
1035 os << "\\batchmode\n"; // changed
1036 // from \nonstopmode
1039 if (!original_path.empty()) {
1040 string inputpath = os::external_path(original_path);
1041 subst(inputpath, "~", "\\string~");
1042 os << "\\makeatletter\n"
1043 << "\\def\\input@path{{"
1044 << inputpath << "/}}\n"
1045 << "\\makeatother\n";
1051 // Write the preamble
1052 params.writeLaTeX(os, features, texrow);
1058 os << "\\begin{document}\n";
1061 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1063 if (!lyxrc.language_auto_begin) {
1064 os << subst(lyxrc.language_command_begin, "$$lang",
1065 params.language->babel())
1070 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1072 // add this just in case after all the paragraphs
1076 if (!lyxrc.language_auto_end) {
1077 os << subst(lyxrc.language_command_end, "$$lang",
1078 params.language->babel())
1084 os << "\\end{document}\n";
1087 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1089 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1093 // Just to be sure. (Asger)
1096 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1097 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1100 // we want this to be true outside previews (for insetexternal)
1105 bool Buffer::isLatex() const
1107 return params.getLyXTextClass().outputType() == LATEX;
1111 bool Buffer::isLinuxDoc() const
1113 return params.getLyXTextClass().outputType() == LINUXDOC;
1117 bool Buffer::isLiterate() const
1119 return params.getLyXTextClass().outputType() == LITERATE;
1123 bool Buffer::isDocBook() const
1125 return params.getLyXTextClass().outputType() == DOCBOOK;
1129 bool Buffer::isSGML() const
1131 LyXTextClass const & tclass = params.getLyXTextClass();
1133 return tclass.outputType() == LINUXDOC ||
1134 tclass.outputType() == DOCBOOK;
1138 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1140 ofstream ofs(fname.c_str());
1143 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1147 niceFile = nice; // this will be used by included files.
1149 LaTeXFeatures features(params);
1155 LyXTextClass const & tclass = params.getLyXTextClass();
1157 string top_element = tclass.latexname();
1160 ofs << "<!doctype linuxdoc system";
1162 string preamble = params.preamble;
1163 const string name = nice ? ChangeExtension(filename_, ".sgml")
1165 preamble += features.getIncludedFiles(name);
1166 preamble += features.getLyXSGMLEntities();
1168 if (!preamble.empty()) {
1169 ofs << " [ " << preamble << " ]";
1173 if (params.options.empty())
1174 sgml::openTag(ofs, 0, false, top_element);
1176 string top = top_element;
1178 top += params.options;
1179 sgml::openTag(ofs, 0, false, top);
1183 ofs << "<!-- " << lyx_docversion
1184 << " created this file. For more info see http://www.lyx.org/"
1187 Paragraph::depth_type depth = 0; // paragraph depth
1188 Paragraph * par = &*(paragraphs.begin());
1190 vector<string> environment_stack(5);
1193 LyXLayout_ptr const & style = par->layout();
1194 // treat <toc> as a special case for compatibility with old code
1195 if (par->isInset(0)) {
1196 Inset * inset = par->getInset(0);
1197 Inset::Code lyx_code = inset->lyxCode();
1198 if (lyx_code == Inset::TOC_CODE) {
1199 string const temp = "toc";
1200 sgml::openTag(ofs, depth, false, temp);
1207 // environment tag closing
1208 for (; depth > par->params().depth(); --depth) {
1209 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1210 environment_stack[depth].erase();
1213 // write opening SGML tags
1214 switch (style->latextype) {
1215 case LATEX_PARAGRAPH:
1216 if (depth == par->params().depth()
1217 && !environment_stack[depth].empty()) {
1218 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1219 environment_stack[depth].erase();
1225 sgml::openTag(ofs, depth, false, style->latexname());
1231 _("Error: Wrong depth for LatexType Command.\n"));
1233 if (!environment_stack[depth].empty()) {
1234 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1238 environment_stack[depth].erase();
1239 sgml::openTag(ofs, depth, false, style->latexname());
1242 case LATEX_ENVIRONMENT:
1243 case LATEX_ITEM_ENVIRONMENT:
1244 case LATEX_BIB_ENVIRONMENT:
1246 string const & latexname = style->latexname();
1248 if (depth == par->params().depth()
1249 && environment_stack[depth] != latexname) {
1250 sgml::closeTag(ofs, depth, false,
1251 environment_stack[depth]);
1252 environment_stack[depth].erase();
1254 if (depth < par->params().depth()) {
1255 depth = par->params().depth();
1256 environment_stack[depth].erase();
1258 if (environment_stack[depth] != latexname) {
1260 sgml::openTag(ofs, depth, false, "p");
1262 sgml::openTag(ofs, depth, false, latexname);
1264 if (environment_stack.size() == depth + 1)
1265 environment_stack.push_back("!-- --");
1266 environment_stack[depth] = latexname;
1269 if (style->latexparam() == "CDATA")
1272 if (style->latextype == LATEX_ENVIRONMENT) break;
1274 if (style->labeltype == LABEL_MANUAL)
1279 sgml::openTag(ofs, depth + 1, false, item_name);
1284 sgml::openTag(ofs, depth, false, style->latexname());
1288 simpleLinuxDocOnePar(ofs, par, depth);
1293 // write closing SGML tags
1294 switch (style->latextype) {
1297 case LATEX_ENVIRONMENT:
1298 case LATEX_ITEM_ENVIRONMENT:
1299 case LATEX_BIB_ENVIRONMENT:
1300 if (style->latexparam() == "CDATA")
1304 sgml::closeTag(ofs, depth, false, style->latexname());
1310 for (int i = depth; i >= 0; --i)
1311 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1315 sgml::closeTag(ofs, 0, false, top_element);
1319 // How to check for successful close
1321 // we want this to be true outside previews (for insetexternal)
1326 // checks, if newcol chars should be put into this line
1327 // writes newline, if necessary.
1330 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1331 string::size_type newcol)
1334 if (colcount > lyxrc.ascii_linelen) {
1336 colcount = newcol; // assume write after this call
1351 string tag_name(PAR_TAG const & pt) {
1353 case NONE: return "!-- --";
1354 case TT: return "tt";
1355 case SF: return "sf";
1356 case BF: return "bf";
1357 case IT: return "it";
1358 case SL: return "sl";
1359 case EM: return "em";
1366 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1368 p1 = static_cast<PAR_TAG>(p1 | p2);
1373 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1375 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1381 // Handle internal paragraph parsing -- layout already processed.
1382 void Buffer::simpleLinuxDocOnePar(ostream & os,
1384 Paragraph::depth_type /*depth*/)
1386 LyXLayout_ptr const & style = par->layout();
1388 string::size_type char_line_count = 5; // Heuristic choice ;-)
1390 // gets paragraph main font
1393 if (style->labeltype == LABEL_MANUAL) {
1394 font_old = style->labelfont;
1397 font_old = style->font;
1401 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1402 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1403 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1406 stack<PAR_TAG> tag_state;
1407 // parsing main loop
1408 for (pos_type i = 0; i < par->size(); ++i) {
1410 PAR_TAG tag_close = NONE;
1411 list < PAR_TAG > tag_open;
1413 LyXFont const font = par->getFont(params, i);
1415 if (font_old.family() != font.family()) {
1416 switch (family_type) {
1417 case LyXFont::SANS_FAMILY:
1420 case LyXFont::TYPEWRITER_FAMILY:
1427 family_type = font.family();
1429 switch (family_type) {
1430 case LyXFont::SANS_FAMILY:
1431 tag_open.push_back(SF);
1433 case LyXFont::TYPEWRITER_FAMILY:
1434 tag_open.push_back(TT);
1441 if (font_old.series() != font.series()) {
1442 switch (series_type) {
1443 case LyXFont::BOLD_SERIES:
1450 series_type = font.series();
1452 switch (series_type) {
1453 case LyXFont::BOLD_SERIES:
1454 tag_open.push_back(BF);
1462 if (font_old.shape() != font.shape()) {
1463 switch (shape_type) {
1464 case LyXFont::ITALIC_SHAPE:
1467 case LyXFont::SLANTED_SHAPE:
1474 shape_type = font.shape();
1476 switch (shape_type) {
1477 case LyXFont::ITALIC_SHAPE:
1478 tag_open.push_back(IT);
1480 case LyXFont::SLANTED_SHAPE:
1481 tag_open.push_back(SL);
1488 if (font_old.emph() != font.emph()) {
1489 if (font.emph() == LyXFont::ON) {
1490 tag_open.push_back(EM);
1499 list < PAR_TAG > temp;
1500 while (!tag_state.empty() && tag_close) {
1501 PAR_TAG k = tag_state.top();
1503 os << "</" << tag_name(k) << '>';
1510 for(list< PAR_TAG >::const_iterator j = temp.begin();
1511 j != temp.end(); ++j) {
1513 os << '<' << tag_name(*j) << '>';
1516 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1517 j != tag_open.end(); ++j) {
1519 os << '<' << tag_name(*j) << '>';
1522 char c = par->getChar(i);
1524 if (c == Paragraph::META_INSET) {
1525 Inset * inset = par->getInset(i);
1526 inset->linuxdoc(this, os);
1531 if (style->latexparam() == "CDATA") {
1532 // "TeX"-Mode on == > SGML-Mode on.
1539 boost::tie(ws, str) = sgml::escapeChar(c);
1540 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1541 // in freespacing mode, spaces are
1542 // non-breaking characters
1543 if (desc_on) {// if char is ' ' then...
1546 sgmlLineBreak(os, char_line_count, 6);
1550 sgmlLineBreak(os, char_line_count, 1);
1555 char_line_count += str.length();
1561 while (!tag_state.empty()) {
1562 os << "</" << tag_name(tag_state.top()) << '>';
1566 // resets description flag correctly
1568 // <tag> not closed...
1569 sgmlLineBreak(os, char_line_count, 6);
1575 // Print an error message.
1576 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
1577 string const & /*message*/) const
1579 #ifdef WITH_WARNINGS
1580 #warning This is wrong we cannot insert an inset like this!!!
1581 // I guess this was Jose' so I explain you more or less why this
1582 // is wrong. This way you insert something in the paragraph and
1583 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1584 // I deactivate this code, have a look at BufferView::insertErrors
1585 // how you should do this correctly! (Jug 20020315)
1588 // insert an error marker in text
1589 InsetError * new_inset = new InsetError(message);
1590 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1596 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1598 ofstream ofs(fname.c_str());
1600 Alert::alert(_("LYX_ERROR:"), _("Cannot write file"), fname);
1604 Paragraph * par = &*(paragraphs.begin());
1606 niceFile = nice; // this will be used by Insetincludes.
1608 LaTeXFeatures features(params);
1613 LyXTextClass const & tclass = params.getLyXTextClass();
1614 string top_element = tclass.latexname();
1617 ofs << "<!DOCTYPE " << top_element
1618 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1620 string preamble = params.preamble;
1621 const string name = nice ? ChangeExtension(filename_, ".sgml")
1623 preamble += features.getIncludedFiles(name);
1624 preamble += features.getLyXSGMLEntities();
1626 if (!preamble.empty()) {
1627 ofs << "\n [ " << preamble << " ]";
1632 string top = top_element;
1634 top += params.language->code();
1637 if (!params.options.empty()) {
1639 top += params.options;
1641 sgml::openTag(ofs, 0, false, top);
1643 ofs << "<!-- DocBook file was created by " << lyx_docversion
1644 << "\n See http://www.lyx.org/ for more information -->\n";
1646 vector<string> environment_stack(10);
1647 vector<string> environment_inner(10);
1648 vector<string> command_stack(10);
1650 bool command_flag = false;
1651 Paragraph::depth_type command_depth = 0;
1652 Paragraph::depth_type command_base = 0;
1653 Paragraph::depth_type cmd_depth = 0;
1654 Paragraph::depth_type depth = 0; // paragraph depth
1657 string command_name;
1663 int desc_on = 0; // description mode
1665 LyXLayout_ptr const & style = par->layout();
1667 // environment tag closing
1668 for (; depth > par->params().depth(); --depth) {
1669 if (environment_inner[depth] != "!-- --") {
1670 item_name = "listitem";
1671 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1672 if (environment_inner[depth] == "varlistentry")
1673 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1675 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1676 environment_stack[depth].erase();
1677 environment_inner[depth].erase();
1680 if (depth == par->params().depth()
1681 && environment_stack[depth] != style->latexname()
1682 && !environment_stack[depth].empty()) {
1683 if (environment_inner[depth] != "!-- --") {
1684 item_name= "listitem";
1685 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1686 if (environment_inner[depth] == "varlistentry")
1687 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1690 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1692 environment_stack[depth].erase();
1693 environment_inner[depth].erase();
1696 // Write opening SGML tags.
1697 switch (style->latextype) {
1698 case LATEX_PARAGRAPH:
1699 sgml::openTag(ofs, depth + command_depth,
1700 false, style->latexname());
1706 _("Error: Wrong depth for LatexType Command.\n"));
1708 command_name = style->latexname();
1710 sgmlparam = style->latexparam();
1711 c_params = split(sgmlparam, c_depth,'|');
1713 cmd_depth = lyx::atoi(c_depth);
1716 if (cmd_depth < command_base) {
1717 for (Paragraph::depth_type j = command_depth;
1718 j >= command_base; --j) {
1719 sgml::closeTag(ofs, j, false, command_stack[j]);
1722 command_depth = command_base = cmd_depth;
1723 } else if (cmd_depth <= command_depth) {
1724 for (int j = command_depth;
1725 j >= int(cmd_depth); --j) {
1726 sgml::closeTag(ofs, j, false, command_stack[j]);
1729 command_depth = cmd_depth;
1731 command_depth = cmd_depth;
1733 command_depth = command_base = cmd_depth;
1734 command_flag = true;
1736 if (command_stack.size() == command_depth + 1)
1737 command_stack.push_back(string());
1738 command_stack[command_depth] = command_name;
1740 // treat label as a special case for
1741 // more WYSIWYM handling.
1742 // This is a hack while paragraphs can't have
1743 // attributes, like id in this case.
1744 if (par->isInset(0)) {
1745 Inset * inset = par->getInset(0);
1746 Inset::Code lyx_code = inset->lyxCode();
1747 if (lyx_code == Inset::LABEL_CODE) {
1748 command_name += " id=\"";
1749 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1750 command_name += '"';
1755 sgml::openTag(ofs, depth + command_depth, false, command_name);
1757 item_name = c_params.empty() ? "title" : c_params;
1758 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1761 case LATEX_ENVIRONMENT:
1762 case LATEX_ITEM_ENVIRONMENT:
1763 if (depth < par->params().depth()) {
1764 depth = par->params().depth();
1765 environment_stack[depth].erase();
1768 if (environment_stack[depth] != style->latexname()) {
1769 if (environment_stack.size() == depth + 1) {
1770 environment_stack.push_back("!-- --");
1771 environment_inner.push_back("!-- --");
1773 environment_stack[depth] = style->latexname();
1774 environment_inner[depth] = "!-- --";
1775 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1777 if (environment_inner[depth] != "!-- --") {
1778 item_name= "listitem";
1779 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1780 if (environment_inner[depth] == "varlistentry")
1781 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1785 if (style->latextype == LATEX_ENVIRONMENT) {
1786 if (!style->latexparam().empty()) {
1787 if (style->latexparam() == "CDATA")
1790 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1795 desc_on = (style->labeltype == LABEL_MANUAL);
1797 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1798 sgml::openTag(ofs, depth + 1 + command_depth,
1799 false, environment_inner[depth]);
1801 item_name = desc_on ? "term" : "para";
1802 sgml::openTag(ofs, depth + 1 + command_depth,
1806 sgml::openTag(ofs, depth + command_depth,
1807 false, style->latexname());
1811 simpleDocBookOnePar(ofs, par, desc_on,
1812 depth + 1 + command_depth);
1816 // write closing SGML tags
1817 switch (style->latextype) {
1819 end_tag = c_params.empty() ? "title" : c_params;
1820 sgml::closeTag(ofs, depth + command_depth,
1823 case LATEX_ENVIRONMENT:
1824 if (!style->latexparam().empty()) {
1825 if (style->latexparam() == "CDATA")
1828 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1831 case LATEX_ITEM_ENVIRONMENT:
1832 if (desc_on == 1) break;
1834 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1836 case LATEX_PARAGRAPH:
1837 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1840 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1846 for (int d = depth; d >= 0; --d) {
1847 if (!environment_stack[depth].empty()) {
1848 if (environment_inner[depth] != "!-- --") {
1849 item_name = "listitem";
1850 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1851 if (environment_inner[depth] == "varlistentry")
1852 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1855 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1859 for (int j = command_depth; j >= 0 ; --j)
1860 if (!command_stack[j].empty()) {
1861 sgml::closeTag(ofs, j, false, command_stack[j]);
1866 sgml::closeTag(ofs, 0, false, top_element);
1869 // How to check for successful close
1871 // we want this to be true outside previews (for insetexternal)
1876 void Buffer::simpleDocBookOnePar(ostream & os,
1877 Paragraph * par, int & desc_on,
1878 Paragraph::depth_type depth) const
1880 bool emph_flag = false;
1882 LyXLayout_ptr const & style = par->layout();
1884 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1886 int char_line_count = depth;
1887 //if (!style.free_spacing)
1888 // os << string(depth,' ');
1890 // parsing main loop
1891 for (pos_type i = 0; i < par->size(); ++i) {
1892 LyXFont font = par->getFont(params, i);
1894 // handle <emphasis> tag
1895 if (font_old.emph() != font.emph()) {
1896 if (font.emph() == LyXFont::ON) {
1897 if (style->latexparam() == "CDATA")
1900 if (style->latexparam() == "CDATA")
1904 if (style->latexparam() == "CDATA")
1906 os << "</emphasis>";
1907 if (style->latexparam() == "CDATA")
1914 if (par->isInset(i)) {
1915 Inset * inset = par->getInset(i);
1916 // don't print the inset in position 0 if desc_on == 3 (label)
1917 if (i || desc_on != 3) {
1918 if (style->latexparam() == "CDATA")
1920 inset->docbook(this, os, false);
1921 if (style->latexparam() == "CDATA")
1925 char c = par->getChar(i);
1928 boost::tie(ws, str) = sgml::escapeChar(c);
1930 if (style->pass_thru) {
1932 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1934 } else if (desc_on ==1) {
1936 os << "\n</term><listitem><para>";
1946 if (style->latexparam() == "CDATA")
1948 os << "</emphasis>";
1949 if (style->latexparam() == "CDATA")
1953 // resets description flag correctly
1955 // <term> not closed...
1956 os << "</term>\n<listitem><para> </para>";
1958 if (style->free_spacing)
1963 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
1964 // Other flags: -wall -v0 -x
1965 int Buffer::runChktex()
1967 if (!users->text) return 0;
1969 users->owner()->busy(true);
1971 // get LaTeX-Filename
1972 string const name = getLatexName();
1973 string path = filePath();
1975 string const org_path = path;
1976 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
1980 Path p(path); // path to LaTeX file
1981 users->owner()->message(_("Running chktex..."));
1983 // Remove all error insets
1984 bool const removedErrorInsets = users->removeAutoInsets();
1986 // Generate the LaTeX file if neccessary
1987 makeLaTeXFile(name, org_path, false);
1990 Chktex chktex(lyxrc.chktex_command, name, filePath());
1991 int res = chktex.run(terr); // run chktex
1994 Alert::alert(_("chktex did not work!"),
1995 _("Could not run with file:"), name);
1996 } else if (res > 0) {
1997 // Insert all errors as errors boxes
1998 users->insertErrors(terr);
2001 // if we removed error insets before we ran chktex or if we inserted
2002 // error insets after we ran chktex, this must be run:
2003 if (removedErrorInsets || res) {
2004 #warning repaint needed here, or do you mean update() ?
2008 users->owner()->busy(false);
2014 void Buffer::validate(LaTeXFeatures & features) const
2016 LyXTextClass const & tclass = params.getLyXTextClass();
2018 if (params.tracking_changes) {
2019 features.require("dvipost");
2020 features.require("color");
2023 // AMS Style is at document level
2024 if (params.use_amsmath == BufferParams::AMS_ON
2025 || tclass.provides(LyXTextClass::amsmath))
2026 features.require("amsmath");
2028 for_each(paragraphs.begin(), paragraphs.end(),
2029 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2031 // the bullet shapes are buffer level not paragraph level
2032 // so they are tested here
2033 for (int i = 0; i < 4; ++i) {
2034 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2035 int const font = params.user_defined_bullets[i].getFont();
2037 int const c = params
2038 .user_defined_bullets[i]
2045 features.require("latexsym");
2047 } else if (font == 1) {
2048 features.require("amssymb");
2049 } else if ((font >= 2 && font <= 5)) {
2050 features.require("pifont");
2055 if (lyxerr.debugging(Debug::LATEX)) {
2056 features.showStruct();
2061 vector<string> const Buffer::getLabelList() const
2063 /// if this is a child document and the parent is already loaded
2064 /// Use the parent's list instead [ale990407]
2065 if (!params.parentname.empty()
2066 && bufferlist.exists(params.parentname)) {
2067 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2069 return tmp->getLabelList();
2072 vector<string> label_list;
2073 for (inset_iterator it = inset_const_iterator_begin();
2074 it != inset_const_iterator_end(); ++it) {
2075 vector<string> const l = it->getLabelList();
2076 label_list.insert(label_list.end(), l.begin(), l.end());
2082 // This is also a buffer property (ale)
2083 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2085 /// if this is a child document and the parent is already loaded
2086 /// use the parent's list instead [ale990412]
2087 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2088 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2090 tmp->fillWithBibKeys(keys);
2095 for (inset_iterator it = inset_const_iterator_begin();
2096 it != inset_const_iterator_end(); ++it) {
2097 if (it->lyxCode() == Inset::BIBTEX_CODE)
2098 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2099 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2100 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2101 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2102 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2103 string const key = bib.getContents();
2104 string const opt = bib.getOptions();
2105 string const ref; // = pit->asString(this, false);
2106 string const info = opt + "TheBibliographyRef" + ref;
2107 keys.push_back(pair<string, string>(key, info));
2113 bool Buffer::isDepClean(string const & name) const
2115 DepClean::const_iterator it = dep_clean_.find(name);
2116 if (it == dep_clean_.end())
2122 void Buffer::markDepClean(string const & name)
2124 dep_clean_[name] = true;
2128 bool Buffer::dispatch(string const & command, bool * result)
2130 // Split command string into command and argument
2132 string line = ltrim(command);
2133 string const arg = trim(split(line, cmd, ' '));
2135 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2139 bool Buffer::dispatch(int action, string const & argument, bool * result)
2141 bool dispatched = true;
2145 bool const tmp = Exporter::Export(this, argument, false);
2158 void Buffer::resizeInsets(BufferView * bv)
2160 /// then remove all LyXText in text-insets
2161 for_each(paragraphs.begin(), paragraphs.end(),
2162 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2166 void Buffer::redraw()
2168 #warning repaint needed here, or do you mean update() ?
2174 void Buffer::changeLanguage(Language const * from, Language const * to)
2177 ParIterator end = par_iterator_end();
2178 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2179 (*it)->changeLanguage(params, from, to);
2183 bool Buffer::isMultiLingual()
2185 ParIterator end = par_iterator_end();
2186 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2187 if ((*it)->isMultiLingual(params))
2194 void Buffer::inset_iterator::setParagraph()
2196 while (pit != pend) {
2197 it = pit->insetlist.begin();
2198 if (it != pit->insetlist.end())
2205 Inset * Buffer::getInsetFromID(int id_arg) const
2207 for (inset_iterator it = inset_const_iterator_begin();
2208 it != inset_const_iterator_end(); ++it)
2210 if (it->id() == id_arg)
2212 Inset * in = it->getInsetFromID(id_arg);
2220 Paragraph * Buffer::getParFromID(int id) const
2225 // why should we allow < 0 ??
2226 //lyx::Assert(id >= 0);
2228 ParConstIterator it(par_iterator_begin());
2229 ParConstIterator end(par_iterator_end());
2231 for (; it != end; ++it) {
2232 // go on then, show me how to remove
2234 if ((*it)->id() == id) {
2235 return const_cast<Paragraph*>(*it);
2243 ParIterator Buffer::par_iterator_begin()
2245 return ParIterator(&*(paragraphs.begin()));
2249 ParIterator Buffer::par_iterator_end()
2251 return ParIterator();
2254 ParConstIterator Buffer::par_iterator_begin() const
2256 return ParConstIterator(&*(paragraphs.begin()));
2260 ParConstIterator Buffer::par_iterator_end() const
2262 return ParConstIterator();
2267 void Buffer::addUser(BufferView * u)
2273 void Buffer::delUser(BufferView *)
2279 Language const * Buffer::getLanguage() const
2281 return params.language;
2285 bool Buffer::isClean() const
2291 bool Buffer::isBakClean() const
2297 void Buffer::markClean() const
2303 // if the .lyx file has been saved, we don't need an
2309 void Buffer::markBakClean()
2315 void Buffer::setUnnamed(bool flag)
2321 bool Buffer::isUnnamed()
2327 void Buffer::markDirty()
2335 DepClean::iterator it = dep_clean_.begin();
2336 DepClean::const_iterator const end = dep_clean_.end();
2338 for (; it != end; ++it) {
2344 string const & Buffer::fileName() const
2350 string const & Buffer::filePath() const
2356 bool Buffer::isReadonly() const
2362 BufferView * Buffer::getUser() const
2368 void Buffer::setParentName(string const & name)
2370 params.parentname = name;
2374 Buffer::inset_iterator::inset_iterator()
2379 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2386 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2390 if (it == pit->insetlist.end()) {
2399 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2401 inset_iterator tmp = *this;
2407 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2409 return *it.getInset();
2413 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2415 return it.getInset();
2419 Paragraph * Buffer::inset_iterator::getPar()
2425 lyx::pos_type Buffer::inset_iterator::getPos() const
2431 bool operator==(Buffer::inset_iterator const & iter1,
2432 Buffer::inset_iterator const & iter2)
2434 return iter1.pit == iter2.pit
2435 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2439 bool operator!=(Buffer::inset_iterator const & iter1,
2440 Buffer::inset_iterator const & iter2)
2442 return !(iter1 == iter2);