3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS
14 #include "bufferlist.h"
15 #include "LyXAction.h"
18 #include "tex-strings.h"
20 #include "bufferview_funcs.h"
26 #include "LaTeXFeatures.h"
33 #include "BufferView.h"
34 #include "ParagraphParameters.h"
35 #include "iterators.h"
36 #include "lyxtextclasslist.h"
38 #include "paragraph_funcs.h"
41 #include "frontends/LyXView.h"
43 #include "mathed/formulamacro.h"
44 #include "mathed/formula.h"
46 #include "insets/inseterror.h"
47 #include "insets/insetbibitem.h"
48 #include "insets/insetbibtex.h"
49 #include "insets/insetinclude.h"
50 #include "insets/insettext.h"
52 #include "frontends/Dialogs.h"
53 #include "frontends/Alert.h"
55 #include "graphics/Previews.h"
57 #include "support/textutils.h"
58 #include "support/filetools.h"
59 #include "support/path.h"
60 #include "support/os.h"
61 #include "support/lyxlib.h"
62 #include "support/FileInfo.h"
63 #include "support/lyxmanip.h"
64 #include "support/lyxtime.h"
66 #include <boost/bind.hpp>
67 #include <boost/tuple/tuple.hpp>
68 #include "BoostFormat.h"
80 #include <sys/types.h>
87 #ifndef CXX_GLOBAL_CSTD
107 using lyx::textclass_type;
109 // all these externs should eventually be removed.
110 extern BufferList bufferlist;
114 const int LYX_FORMAT = 223;
118 Buffer::Buffer(string const & file, bool ronly)
119 : niceFile(true), lyx_clean(true), bak_clean(true),
120 unnamed(false), read_only(ronly),
121 filename_(file), users(0)
123 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
124 filepath_ = OnlyPath(file);
126 if (read_only || lyxrc.use_tempdir) {
127 tmppath = CreateBufferTmpDir();
132 // set initial author
133 authors().record(Author(lyxrc.user_name, lyxrc.user_email));
139 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
140 // here the buffer should take care that it is
141 // saved properly, before it goes into the void.
143 // make sure that views using this buffer
148 if (!tmppath.empty() && destroyDir(tmppath) != 0) {
150 boost::format fmt = _("Could not remove the temporary directory %1$s");
152 string msg = fmt.str();
154 string msg = _("Could not remove the temporary directory ") + tmppath;
156 Alert::warning(_("Could not remove temporary directory"), msg);
161 // Remove any previewed LaTeX snippets assocoated with this buffer.
162 grfx::Previews::get().removeLoader(this);
166 string const Buffer::getLatexName(bool no_path) const
168 string const name = ChangeExtension(MakeLatexName(fileName()), ".tex");
170 return OnlyFilename(name);
176 pair<Buffer::LogType, string> const Buffer::getLogName() const
178 string const filename = getLatexName(false);
180 if (filename.empty())
181 return make_pair(Buffer::latexlog, string());
183 string path = OnlyPath(filename);
185 if (lyxrc.use_tempdir || !IsDirWriteable(path))
188 string const fname = AddName(path,
189 OnlyFilename(ChangeExtension(filename,
192 AddName(path, OnlyFilename(
193 ChangeExtension(filename,
194 formats.extension("literate") + ".out")));
196 // If no Latex log or Build log is newer, show Build log
198 FileInfo const f_fi(fname);
199 FileInfo const b_fi(bname);
202 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
203 lyxerr[Debug::FILES] << "Log name calculated as: " << bname << endl;
204 return make_pair(Buffer::buildlog, bname);
206 lyxerr[Debug::FILES] << "Log name calculated as: " << fname << endl;
207 return make_pair(Buffer::latexlog, fname);
211 void Buffer::setReadonly(bool flag)
213 if (read_only != flag) {
216 users->owner()->getDialogs().updateBufferDependent(false);
221 AuthorList & Buffer::authors()
223 return params.authorlist;
227 /// Update window titles of all users
228 // Should work on a list
229 void Buffer::updateTitles() const
232 users->owner()->updateWindowTitle();
236 /// Reset autosave timer of all users
237 // Should work on a list
238 void Buffer::resetAutosaveTimers() const
241 users->owner()->resetAutosaveTimer();
245 void Buffer::setFileName(string const & newfile)
247 filename_ = MakeAbsPath(newfile);
248 filepath_ = OnlyPath(filename_);
249 setReadonly(IsFileWriteable(filename_) == 0);
254 // We'll remove this later. (Lgb)
257 void unknownClass(string const & unknown)
261 boost::io::str(boost::format(
262 _("Using the default document class, because the "
263 " class %1$s is unknown.")) % unknown);
265 _("Using the default document class, because the "
266 " class ") + unknown + (" is unknown.");
268 Alert::warning(_("Unknown document class"), msg);
273 int Buffer::readHeader(LyXLex & lex)
275 int unknown_tokens = 0;
279 string const token = lex.getString();
284 if (token == "\\end_header")
287 lyxerr[Debug::PARSER] << "Handling header token: `"
288 << token << '\'' << endl;
290 string unknown = params.readToken(lex, token);
291 if (!unknown.empty()) {
292 if (unknown[0] != '\\') {
293 unknownClass(unknown);
299 return unknown_tokens;
303 // candidate for move to BufferView
304 // (at least some parts in the beginning of the func)
307 // changed to be public and have one parameter
308 // if par = 0 normal behavior
309 // else insert behavior
310 // Returns false if "\the_end" is not read (Asger)
311 bool Buffer::readBody(LyXLex & lex, ParagraphList::iterator pit)
313 int unknown_tokens = 0;
315 Paragraph::depth_type depth = 0;
316 bool the_end_read = false;
318 if (paragraphs.empty()) {
319 unknown_tokens += readHeader(lex);
321 if (!params.getLyXTextClass().load()) {
322 string theclass = params.getLyXTextClass().name();
325 boost::io::str(boost::format(
326 _("Using the default document class, because the "
327 " class %1$s could not be loaded.")) % theclass);
329 _("Using the default document class, because the "
330 " class ") + theclass + (" could not be loaded.");
332 Alert::error(_("Can't load document class"), msg);
333 params.textclass = 0;
336 // We are inserting into an existing document
337 users->text->breakParagraph(paragraphs);
339 // We don't want to adopt the parameters from the
340 // document we insert, so read them into a temporary buffer
341 // and then discard it
343 Buffer tmpbuf("", false);
344 tmpbuf.readHeader(lex);
349 string const token = lex.getString();
354 lyxerr[Debug::PARSER] << "Handling token: `"
355 << token << '\'' << endl;
357 if (token == "\\the_end") {
362 unknown_tokens += readParagraph(lex, token, paragraphs, pit, depth);
366 if (unknown_tokens > 0) {
369 if (unknown_tokens == 1) {
370 boost::format fmt(_("Encountered one unknown token when reading the document %1$s."));
374 boost::format fmt(_("Encountered %1$s unknown tokens when reading the document %2$s."));
375 fmt % tostr(unknown_tokens);
380 string s = _("Encountered ");
381 if (unknown_tokens == 1) {
382 s += _("one unknown token");
384 s += tostr(unknown_tokens);
385 s += _(" unknown tokens");
387 Alert::warning(_("Document format failure"), s);
396 Buffer::readParagraph(LyXLex & lex, string const & token,
397 ParagraphList & pars, ParagraphList::iterator & pit,
398 Paragraph::depth_type & depth)
400 static Change current_change;
403 if (token == "\\layout") {
404 lex.pushToken(token);
406 Paragraph * par = new Paragraph();
407 par->params().depth(depth);
408 if (params.tracking_changes)
410 LyXFont f(LyXFont::ALL_INHERIT, params.language);
413 // FIXME: goddamn InsetTabular makes us pass a Buffer
415 unknown += ::readParagraph(*this, *par, lex);
418 if (pit != pars.end())
420 pit = pars.insert(pit, par);
421 } else if (token == "\\begin_deeper") {
423 } else if (token == "\\end_deeper") {
425 lex.printError("\\end_deeper: " "depth is already null");
436 // needed to insert the selection
437 void Buffer::insertStringAsLines(Paragraph *& par, pos_type & pos,
438 LyXFont const & fn,string const & str)
440 LyXLayout_ptr const & layout = par->layout();
444 par->checkInsertChar(font);
445 // insert the string, don't insert doublespace
446 bool space_inserted = true;
447 bool autobreakrows = !par->inInset() ||
448 static_cast<InsetText *>(par->inInset())->getAutoBreakRows();
449 for(string::const_iterator cit = str.begin();
450 cit != str.end(); ++cit) {
452 if (autobreakrows && (!par->empty() || layout->keepempty)) {
453 breakParagraph(params, paragraphs, par, pos,
454 layout->isEnvironment());
457 space_inserted = true;
461 // do not insert consecutive spaces if !free_spacing
462 } else if ((*cit == ' ' || *cit == '\t') &&
463 space_inserted && !layout->free_spacing &&
464 !par->isFreeSpacing())
467 } else if (*cit == '\t') {
468 if (!layout->free_spacing && !par->isFreeSpacing()) {
469 // tabs are like spaces here
470 par->insertChar(pos, ' ', font);
472 space_inserted = true;
474 const pos_type nb = 8 - pos % 8;
475 for (pos_type a = 0; a < nb ; ++a) {
476 par->insertChar(pos, ' ', font);
479 space_inserted = true;
481 } else if (!IsPrintable(*cit)) {
482 // Ignore unprintables
485 // just insert the character
486 par->insertChar(pos, *cit, font);
488 space_inserted = (*cit == ' ');
495 bool Buffer::readFile(LyXLex & lex, string const & filename)
497 return readFile(lex, filename, paragraphs.begin());
501 // FIXME: all the below Alerts should give the filename..
502 bool Buffer::readFile(LyXLex & lex, string const & filename, ParagraphList::iterator pit)
505 Alert::error(_("Document could not be read"),
506 _("The specified document could not be read."));
511 string const token(lex.getString());
514 Alert::error(_("Document could not be read"),
515 _("The specified document could not be read."));
519 // the first token _must_ be...
520 if (token != "\\lyxformat") {
521 Alert::error(_("Document format failure"),
522 _("The specified document is not a LyX document."));
527 string tmp_format = lex.getString();
528 //lyxerr << "LyX Format: `" << tmp_format << '\'' << endl;
529 // if present remove ".," from string.
530 string::size_type dot = tmp_format.find_first_of(".,");
531 //lyxerr << " dot found at " << dot << endl;
532 if (dot != string::npos)
533 tmp_format.erase(dot, 1);
534 file_format = strToInt(tmp_format);
535 //lyxerr << "format: " << file_format << endl;
536 if (file_format == LYX_FORMAT) {
538 } else if (file_format > LYX_FORMAT) {
539 Alert::warning(_("Document format failure"),
540 _("This document was created with a newer version of "
541 "LyX. This is likely to cause problems."));
542 } else if (file_format < LYX_FORMAT) {
544 if (file_format < 200) {
545 Alert::error(_("Document format failure"),
546 _("This LyX document is too old to be read "
547 "by this version of LyX. Try LyX 0.10."));
549 } else if (!filename.empty()) {
551 LibFileSearch("lyx2lyx", "lyx2lyx");
552 if (command.empty()) {
553 Alert::error(_("Conversion script not found"),
554 _("The document is from an earlier version "
555 "of LyX, but the conversion script lyx2lyx "
556 "could not be found."));
560 +tostr(LYX_FORMAT) + ' '
561 + QuoteName(filename);
562 lyxerr[Debug::INFO] << "Running '"
565 cmd_ret const ret = RunCommand(command);
567 Alert::error(_("Conversion script failed"),
568 _("The document is from an earlier version "
569 "of LyX, but the lyx2lyx script failed "
573 istringstream is(STRCONV(ret.second));
575 tmplex.setStream(is);
576 return readFile(tmplex, string(), pit);
578 // This code is reached if lyx2lyx failed (for
579 // some reason) to change the file format of
585 bool the_end = readBody(lex, pit);
586 params.setPaperStuff();
589 Alert::error(_("Document format failure"),
590 _("The document ended unexpectedly, which means "
591 "that it is probably corrupted."));
597 // Should probably be moved to somewhere else: BufferView? LyXView?
598 bool Buffer::save() const
600 // We don't need autosaves in the immediate future. (Asger)
601 resetAutosaveTimers();
605 if (lyxrc.make_backup) {
606 s = fileName() + '~';
607 if (!lyxrc.backupdir_path.empty())
608 s = AddName(lyxrc.backupdir_path,
609 subst(os::slashify_path(s),'/','!'));
611 // Rename is the wrong way of making a backup,
612 // this is the correct way.
613 /* truss cp fil fil2:
614 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
615 stat("LyXVC.lyx", 0xEFFFF688) = 0
616 open("LyXVC.lyx", O_RDONLY) = 3
617 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
618 fstat(4, 0xEFFFF508) = 0
619 fstat(3, 0xEFFFF508) = 0
620 read(3, " # T h i s f i l e w".., 8192) = 5579
621 write(4, " # T h i s f i l e w".., 5579) = 5579
622 read(3, 0xEFFFD4A0, 8192) = 0
625 chmod("LyXVC3.lyx", 0100644) = 0
626 lseek(0, 0, SEEK_CUR) = 46440
630 // Should probably have some more error checking here.
631 // Doing it this way, also makes the inodes stay the same.
632 // This is still not a very good solution, in particular we
633 // might loose the owner of the backup.
634 FileInfo finfo(fileName());
636 mode_t fmode = finfo.getMode();
637 struct utimbuf times = {
638 finfo.getAccessTime(),
639 finfo.getModificationTime() };
641 ifstream ifs(fileName().c_str());
642 ofstream ofs(s.c_str(), ios::out|ios::trunc);
647 ::chmod(s.c_str(), fmode);
649 if (::utime(s.c_str(), ×)) {
650 lyxerr << "utime error." << endl;
653 lyxerr << "LyX was not able to make "
654 "backup copy. Beware." << endl;
659 if (writeFile(fileName())) {
661 removeAutosaveFile(fileName());
663 // Saving failed, so backup is not backup
664 if (lyxrc.make_backup) {
665 lyx::rename(s, fileName());
673 bool Buffer::writeFile(string const & fname) const
675 if (read_only && (fname == fileName())) {
679 FileInfo finfo(fname);
680 if (finfo.exist() && !finfo.writable()) {
684 ofstream ofs(fname.c_str());
690 // Use the standard "C" locale for file output.
691 ofs.imbue(std::locale::classic());
694 // The top of the file should not be written by params.
696 // write out a comment in the top of the file
697 ofs << '#' << lyx_docversion
698 << " created this file. For more info see http://www.lyx.org/\n"
699 << "\\lyxformat " << LYX_FORMAT << "\n";
701 // now write out the buffer paramters.
702 params.writeFile(ofs);
704 ofs << "\\end_header\n";
706 Paragraph::depth_type depth = 0;
708 // this will write out all the paragraphs
709 // using recursive descent.
710 ParagraphList::iterator pit = paragraphs.begin();
711 ParagraphList::iterator pend = paragraphs.end();
712 for (; pit != pend; ++pit)
713 pit->write(this, ofs, params, depth);
715 // Write marker that shows file is complete
716 ofs << "\n\\the_end" << endl;
720 // how to check if close went ok?
721 // Following is an attempt... (BE 20001011)
723 // good() returns false if any error occured, including some
725 // bad() returns true if something bad happened in the buffer,
726 // which should include file system full errors.
733 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
735 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
747 pair<int, string> const addDepth(int depth, int ldepth)
751 d += (ldepth - depth) * 2;
752 return make_pair(d, string(d, ' '));
758 string const Buffer::asciiParagraph(Paragraph const & par,
759 unsigned int linelen,
760 bool noparbreak) const
762 ostringstream buffer;
763 Paragraph::depth_type depth = 0;
765 Paragraph::depth_type ltype_depth = 0;
766 bool ref_printed = false;
767 // if (!par->previous()) {
769 // begins or ends a deeper area ?
770 if (depth != par->params().depth()) {
771 if (par->params().depth() > depth) {
772 while (par->params().depth() > depth) {
776 while (par->params().depth() < depth) {
782 depth = par.params().depth();
785 // First write the layout
786 string const & tmp = par.layout()->name();
787 if (compare_no_case(tmp, "itemize") == 0) {
789 ltype_depth = depth + 1;
790 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
792 ltype_depth = depth + 1;
793 } else if (contains(ascii_lowercase(tmp), "ection")) {
795 ltype_depth = depth + 1;
796 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
798 ltype_depth = depth + 1;
799 } else if (compare_ascii_no_case(tmp, "description") == 0) {
801 ltype_depth = depth + 1;
802 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
805 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
813 /* maybe some vertical spaces */
815 /* the labelwidthstring used in lists */
819 /* some pagebreaks? */
823 /* what about the alignment */
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 string const file = MakeDisplayPath(fname, 50);
959 boost::format fmt(_("Could not save the document\n%1$s."));
961 string text = fmt.str();
963 string text = _("Could not save the document\n");
966 Alert::error(_("Could not save document"), text);
969 writeFileAscii(ofs, linelen);
973 void Buffer::writeFileAscii(ostream & os, int linelen)
975 ParagraphList::iterator beg = paragraphs.begin();
976 ParagraphList::iterator end = paragraphs.end();
977 ParagraphList::iterator it = beg;
978 for (; it != end; ++it) {
979 os << asciiParagraph(*it, linelen, it == beg);
986 void Buffer::makeLaTeXFile(string const & fname,
987 string const & original_path,
988 bool nice, bool only_body, bool only_preamble)
990 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
992 ofstream ofs(fname.c_str());
994 string const file = MakeDisplayPath(fname, 50);
996 boost::format fmt(_("Could not open the specified document\n%1$s."));
998 string text = fmt.str();
1000 string text = _("Could not open the specified document\n");
1003 Alert::error(_("Could not open file"), text);
1007 makeLaTeXFile(ofs, original_path, nice, only_body, only_preamble);
1011 lyxerr << "File was not closed properly." << endl;
1016 void Buffer::makeLaTeXFile(ostream & os,
1017 string const & original_path,
1018 bool nice, bool only_body, bool only_preamble)
1020 niceFile = nice; // this will be used by Insetincludes.
1022 // validate the buffer.
1023 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1024 LaTeXFeatures features(params);
1026 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1029 // The starting paragraph of the coming rows is the
1030 // first paragraph of the document. (Asger)
1031 texrow.start(&*(paragraphs.begin()), 0);
1033 if (!only_body && nice) {
1034 os << "%% " << lyx_docversion << " created this file. "
1035 "For more info, see http://www.lyx.org/.\n"
1036 "%% Do not edit unless you really know what "
1041 lyxerr[Debug::INFO] << "lyx header finished" << endl;
1042 // There are a few differences between nice LaTeX and usual files:
1043 // usual is \batchmode and has a
1044 // special input@path to allow the including of figures
1045 // with either \input or \includegraphics (what figinsets do).
1046 // input@path is set when the actual parameter
1047 // original_path is set. This is done for usual tex-file, but not
1048 // for nice-latex-file. (Matthias 250696)
1051 // code for usual, NOT nice-latex-file
1052 os << "\\batchmode\n"; // changed
1053 // from \nonstopmode
1056 if (!original_path.empty()) {
1057 string inputpath = os::external_path(original_path);
1058 subst(inputpath, "~", "\\string~");
1059 os << "\\makeatletter\n"
1060 << "\\def\\input@path{{"
1061 << inputpath << "/}}\n"
1062 << "\\makeatother\n";
1068 // Write the preamble
1069 params.writeLaTeX(os, features, texrow);
1075 os << "\\begin{document}\n";
1078 lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
1080 if (!lyxrc.language_auto_begin) {
1081 os << subst(lyxrc.language_command_begin, "$$lang",
1082 params.language->babel())
1087 latexParagraphs(this, paragraphs, paragraphs.begin(), paragraphs.end(), os, texrow);
1089 // add this just in case after all the paragraphs
1093 if (!lyxrc.language_auto_end) {
1094 os << subst(lyxrc.language_command_end, "$$lang",
1095 params.language->babel())
1101 os << "\\end{document}\n";
1104 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
1106 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
1110 // Just to be sure. (Asger)
1113 lyxerr[Debug::INFO] << "Finished making LaTeX file." << endl;
1114 lyxerr[Debug::INFO] << "Row count was " << texrow.rows() - 1
1117 // we want this to be true outside previews (for insetexternal)
1122 bool Buffer::isLatex() const
1124 return params.getLyXTextClass().outputType() == LATEX;
1128 bool Buffer::isLinuxDoc() const
1130 return params.getLyXTextClass().outputType() == LINUXDOC;
1134 bool Buffer::isLiterate() const
1136 return params.getLyXTextClass().outputType() == LITERATE;
1140 bool Buffer::isDocBook() const
1142 return params.getLyXTextClass().outputType() == DOCBOOK;
1146 bool Buffer::isSGML() const
1148 LyXTextClass const & tclass = params.getLyXTextClass();
1150 return tclass.outputType() == LINUXDOC ||
1151 tclass.outputType() == DOCBOOK;
1155 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
1157 ofstream ofs(fname.c_str());
1160 string const file = MakeDisplayPath(fname, 50);
1161 #if USE_BOOST_FORMAT
1162 boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
1164 string text = fmt.str();
1166 string text = _("Could not save the specified document\n");
1167 text += file + _(".\n");
1169 Alert::error(_("Could not save document"), text);
1173 niceFile = nice; // this will be used by included files.
1175 LaTeXFeatures features(params);
1181 LyXTextClass const & tclass = params.getLyXTextClass();
1183 string top_element = tclass.latexname();
1186 ofs << "<!doctype linuxdoc system";
1188 string preamble = params.preamble;
1189 const string name = nice ? ChangeExtension(filename_, ".sgml")
1191 preamble += features.getIncludedFiles(name);
1192 preamble += features.getLyXSGMLEntities();
1194 if (!preamble.empty()) {
1195 ofs << " [ " << preamble << " ]";
1199 if (params.options.empty())
1200 sgml::openTag(ofs, 0, false, top_element);
1202 string top = top_element;
1204 top += params.options;
1205 sgml::openTag(ofs, 0, false, top);
1209 ofs << "<!-- " << lyx_docversion
1210 << " created this file. For more info see http://www.lyx.org/"
1213 Paragraph::depth_type depth = 0; // paragraph depth
1214 Paragraph * par = &*(paragraphs.begin());
1216 vector<string> environment_stack(5);
1219 LyXLayout_ptr const & style = par->layout();
1220 // treat <toc> as a special case for compatibility with old code
1221 if (par->isInset(0)) {
1222 Inset * inset = par->getInset(0);
1223 Inset::Code lyx_code = inset->lyxCode();
1224 if (lyx_code == Inset::TOC_CODE) {
1225 string const temp = "toc";
1226 sgml::openTag(ofs, depth, false, temp);
1233 // environment tag closing
1234 for (; depth > par->params().depth(); --depth) {
1235 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1236 environment_stack[depth].erase();
1239 // write opening SGML tags
1240 switch (style->latextype) {
1241 case LATEX_PARAGRAPH:
1242 if (depth == par->params().depth()
1243 && !environment_stack[depth].empty()) {
1244 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1245 environment_stack[depth].erase();
1251 sgml::openTag(ofs, depth, false, style->latexname());
1257 _("Error: Wrong depth for LatexType Command.\n"));
1259 if (!environment_stack[depth].empty()) {
1260 sgml::closeTag(ofs, depth, false, environment_stack[depth]);
1264 environment_stack[depth].erase();
1265 sgml::openTag(ofs, depth, false, style->latexname());
1268 case LATEX_ENVIRONMENT:
1269 case LATEX_ITEM_ENVIRONMENT:
1270 case LATEX_BIB_ENVIRONMENT:
1272 string const & latexname = style->latexname();
1274 if (depth == par->params().depth()
1275 && environment_stack[depth] != latexname) {
1276 sgml::closeTag(ofs, depth, false,
1277 environment_stack[depth]);
1278 environment_stack[depth].erase();
1280 if (depth < par->params().depth()) {
1281 depth = par->params().depth();
1282 environment_stack[depth].erase();
1284 if (environment_stack[depth] != latexname) {
1286 sgml::openTag(ofs, depth, false, "p");
1288 sgml::openTag(ofs, depth, false, latexname);
1290 if (environment_stack.size() == depth + 1)
1291 environment_stack.push_back("!-- --");
1292 environment_stack[depth] = latexname;
1295 if (style->latexparam() == "CDATA")
1298 if (style->latextype == LATEX_ENVIRONMENT) break;
1300 if (style->labeltype == LABEL_MANUAL)
1305 sgml::openTag(ofs, depth + 1, false, item_name);
1310 sgml::openTag(ofs, depth, false, style->latexname());
1314 simpleLinuxDocOnePar(ofs, par, depth);
1319 // write closing SGML tags
1320 switch (style->latextype) {
1323 case LATEX_ENVIRONMENT:
1324 case LATEX_ITEM_ENVIRONMENT:
1325 case LATEX_BIB_ENVIRONMENT:
1326 if (style->latexparam() == "CDATA")
1330 sgml::closeTag(ofs, depth, false, style->latexname());
1336 for (int i = depth; i >= 0; --i)
1337 sgml::closeTag(ofs, depth, false, environment_stack[i]);
1341 sgml::closeTag(ofs, 0, false, top_element);
1345 // How to check for successful close
1347 // we want this to be true outside previews (for insetexternal)
1352 // checks, if newcol chars should be put into this line
1353 // writes newline, if necessary.
1356 void sgmlLineBreak(ostream & os, string::size_type & colcount,
1357 string::size_type newcol)
1360 if (colcount > lyxrc.ascii_linelen) {
1362 colcount = newcol; // assume write after this call
1377 string tag_name(PAR_TAG const & pt) {
1379 case NONE: return "!-- --";
1380 case TT: return "tt";
1381 case SF: return "sf";
1382 case BF: return "bf";
1383 case IT: return "it";
1384 case SL: return "sl";
1385 case EM: return "em";
1392 void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
1394 p1 = static_cast<PAR_TAG>(p1 | p2);
1399 void reset(PAR_TAG & p1, PAR_TAG const & p2)
1401 p1 = static_cast<PAR_TAG>(p1 & ~p2);
1407 // Handle internal paragraph parsing -- layout already processed.
1408 void Buffer::simpleLinuxDocOnePar(ostream & os,
1410 Paragraph::depth_type /*depth*/)
1412 LyXLayout_ptr const & style = par->layout();
1414 string::size_type char_line_count = 5; // Heuristic choice ;-)
1416 // gets paragraph main font
1419 if (style->labeltype == LABEL_MANUAL) {
1420 font_old = style->labelfont;
1423 font_old = style->font;
1427 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
1428 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
1429 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
1432 stack<PAR_TAG> tag_state;
1433 // parsing main loop
1434 for (pos_type i = 0; i < par->size(); ++i) {
1436 PAR_TAG tag_close = NONE;
1437 list < PAR_TAG > tag_open;
1439 LyXFont const font = par->getFont(params, i);
1441 if (font_old.family() != font.family()) {
1442 switch (family_type) {
1443 case LyXFont::SANS_FAMILY:
1446 case LyXFont::TYPEWRITER_FAMILY:
1453 family_type = font.family();
1455 switch (family_type) {
1456 case LyXFont::SANS_FAMILY:
1457 tag_open.push_back(SF);
1459 case LyXFont::TYPEWRITER_FAMILY:
1460 tag_open.push_back(TT);
1467 if (font_old.series() != font.series()) {
1468 switch (series_type) {
1469 case LyXFont::BOLD_SERIES:
1476 series_type = font.series();
1478 switch (series_type) {
1479 case LyXFont::BOLD_SERIES:
1480 tag_open.push_back(BF);
1488 if (font_old.shape() != font.shape()) {
1489 switch (shape_type) {
1490 case LyXFont::ITALIC_SHAPE:
1493 case LyXFont::SLANTED_SHAPE:
1500 shape_type = font.shape();
1502 switch (shape_type) {
1503 case LyXFont::ITALIC_SHAPE:
1504 tag_open.push_back(IT);
1506 case LyXFont::SLANTED_SHAPE:
1507 tag_open.push_back(SL);
1514 if (font_old.emph() != font.emph()) {
1515 if (font.emph() == LyXFont::ON) {
1516 tag_open.push_back(EM);
1525 list < PAR_TAG > temp;
1526 while (!tag_state.empty() && tag_close) {
1527 PAR_TAG k = tag_state.top();
1529 os << "</" << tag_name(k) << '>';
1536 for(list< PAR_TAG >::const_iterator j = temp.begin();
1537 j != temp.end(); ++j) {
1539 os << '<' << tag_name(*j) << '>';
1542 for(list< PAR_TAG >::const_iterator j = tag_open.begin();
1543 j != tag_open.end(); ++j) {
1545 os << '<' << tag_name(*j) << '>';
1548 char c = par->getChar(i);
1550 if (c == Paragraph::META_INSET) {
1551 Inset * inset = par->getInset(i);
1552 inset->linuxdoc(this, os);
1557 if (style->latexparam() == "CDATA") {
1558 // "TeX"-Mode on == > SGML-Mode on.
1565 boost::tie(ws, str) = sgml::escapeChar(c);
1566 if (ws && !style->free_spacing && !par->isFreeSpacing()) {
1567 // in freespacing mode, spaces are
1568 // non-breaking characters
1569 if (desc_on) {// if char is ' ' then...
1572 sgmlLineBreak(os, char_line_count, 6);
1576 sgmlLineBreak(os, char_line_count, 1);
1581 char_line_count += str.length();
1587 while (!tag_state.empty()) {
1588 os << "</" << tag_name(tag_state.top()) << '>';
1592 // resets description flag correctly
1594 // <tag> not closed...
1595 sgmlLineBreak(os, char_line_count, 6);
1601 // Print an error message.
1602 void Buffer::sgmlError(Paragraph * /*par*/, int /*pos*/,
1603 string const & /*message*/) const
1605 #ifdef WITH_WARNINGS
1606 #warning This is wrong we cannot insert an inset like this!!!
1607 // I guess this was Jose' so I explain you more or less why this
1608 // is wrong. This way you insert something in the paragraph and
1609 // don't tell it to LyXText (row rebreaking and undo handling!!!)
1610 // I deactivate this code, have a look at BufferView::insertErrors
1611 // how you should do this correctly! (Jug 20020315)
1614 // insert an error marker in text
1615 InsetError * new_inset = new InsetError(message);
1616 par->insertInset(pos, new_inset, LyXFont(LyXFont::ALL_INHERIT,
1622 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
1624 ofstream ofs(fname.c_str());
1626 string const file = MakeDisplayPath(fname, 50);
1627 #if USE_BOOST_FORMAT
1628 boost::format fmt(_("Could not save the specified document\n%1$s.\n"));
1630 string text = fmt.str();
1632 string text = _("Could not save the specified document\n");
1633 text += file + _(".\n");
1635 Alert::error(_("Could not save document"), text);
1640 Paragraph * par = &*(paragraphs.begin());
1642 niceFile = nice; // this will be used by Insetincludes.
1644 LaTeXFeatures features(params);
1649 LyXTextClass const & tclass = params.getLyXTextClass();
1650 string top_element = tclass.latexname();
1653 ofs << "<!DOCTYPE " << top_element
1654 << " PUBLIC \"-//OASIS//DTD DocBook V4.1//EN\"";
1656 string preamble = params.preamble;
1657 const string name = nice ? ChangeExtension(filename_, ".sgml")
1659 preamble += features.getIncludedFiles(name);
1660 preamble += features.getLyXSGMLEntities();
1662 if (!preamble.empty()) {
1663 ofs << "\n [ " << preamble << " ]";
1668 string top = top_element;
1670 top += params.language->code();
1673 if (!params.options.empty()) {
1675 top += params.options;
1677 sgml::openTag(ofs, 0, false, top);
1679 ofs << "<!-- DocBook file was created by " << lyx_docversion
1680 << "\n See http://www.lyx.org/ for more information -->\n";
1682 vector<string> environment_stack(10);
1683 vector<string> environment_inner(10);
1684 vector<string> command_stack(10);
1686 bool command_flag = false;
1687 Paragraph::depth_type command_depth = 0;
1688 Paragraph::depth_type command_base = 0;
1689 Paragraph::depth_type cmd_depth = 0;
1690 Paragraph::depth_type depth = 0; // paragraph depth
1693 string command_name;
1699 int desc_on = 0; // description mode
1701 LyXLayout_ptr const & style = par->layout();
1703 // environment tag closing
1704 for (; depth > par->params().depth(); --depth) {
1705 if (environment_inner[depth] != "!-- --") {
1706 item_name = "listitem";
1707 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1708 if (environment_inner[depth] == "varlistentry")
1709 sgml::closeTag(ofs, depth+command_depth, false, environment_inner[depth]);
1711 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1712 environment_stack[depth].erase();
1713 environment_inner[depth].erase();
1716 if (depth == par->params().depth()
1717 && environment_stack[depth] != style->latexname()
1718 && !environment_stack[depth].empty()) {
1719 if (environment_inner[depth] != "!-- --") {
1720 item_name= "listitem";
1721 sgml::closeTag(ofs, command_depth+depth, false, item_name);
1722 if (environment_inner[depth] == "varlistentry")
1723 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1726 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1728 environment_stack[depth].erase();
1729 environment_inner[depth].erase();
1732 // Write opening SGML tags.
1733 switch (style->latextype) {
1734 case LATEX_PARAGRAPH:
1735 sgml::openTag(ofs, depth + command_depth,
1736 false, style->latexname());
1742 _("Error: Wrong depth for LatexType Command.\n"));
1744 command_name = style->latexname();
1746 sgmlparam = style->latexparam();
1747 c_params = split(sgmlparam, c_depth,'|');
1749 cmd_depth = lyx::atoi(c_depth);
1752 if (cmd_depth < command_base) {
1753 for (Paragraph::depth_type j = command_depth;
1754 j >= command_base; --j) {
1755 sgml::closeTag(ofs, j, false, command_stack[j]);
1758 command_depth = command_base = cmd_depth;
1759 } else if (cmd_depth <= command_depth) {
1760 for (int j = command_depth;
1761 j >= int(cmd_depth); --j) {
1762 sgml::closeTag(ofs, j, false, command_stack[j]);
1765 command_depth = cmd_depth;
1767 command_depth = cmd_depth;
1769 command_depth = command_base = cmd_depth;
1770 command_flag = true;
1772 if (command_stack.size() == command_depth + 1)
1773 command_stack.push_back(string());
1774 command_stack[command_depth] = command_name;
1776 // treat label as a special case for
1777 // more WYSIWYM handling.
1778 // This is a hack while paragraphs can't have
1779 // attributes, like id in this case.
1780 if (par->isInset(0)) {
1781 Inset * inset = par->getInset(0);
1782 Inset::Code lyx_code = inset->lyxCode();
1783 if (lyx_code == Inset::LABEL_CODE) {
1784 command_name += " id=\"";
1785 command_name += (static_cast<InsetCommand *>(inset))->getContents();
1786 command_name += '"';
1791 sgml::openTag(ofs, depth + command_depth, false, command_name);
1793 item_name = c_params.empty() ? "title" : c_params;
1794 sgml::openTag(ofs, depth + 1 + command_depth, false, item_name);
1797 case LATEX_ENVIRONMENT:
1798 case LATEX_ITEM_ENVIRONMENT:
1799 if (depth < par->params().depth()) {
1800 depth = par->params().depth();
1801 environment_stack[depth].erase();
1804 if (environment_stack[depth] != style->latexname()) {
1805 if (environment_stack.size() == depth + 1) {
1806 environment_stack.push_back("!-- --");
1807 environment_inner.push_back("!-- --");
1809 environment_stack[depth] = style->latexname();
1810 environment_inner[depth] = "!-- --";
1811 sgml::openTag(ofs, depth + command_depth, false, environment_stack[depth]);
1813 if (environment_inner[depth] != "!-- --") {
1814 item_name= "listitem";
1815 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1816 if (environment_inner[depth] == "varlistentry")
1817 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1821 if (style->latextype == LATEX_ENVIRONMENT) {
1822 if (!style->latexparam().empty()) {
1823 if (style->latexparam() == "CDATA")
1826 sgml::openTag(ofs, depth + command_depth, false, style->latexparam());
1831 desc_on = (style->labeltype == LABEL_MANUAL);
1833 environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
1834 sgml::openTag(ofs, depth + 1 + command_depth,
1835 false, environment_inner[depth]);
1837 item_name = desc_on ? "term" : "para";
1838 sgml::openTag(ofs, depth + 1 + command_depth,
1842 sgml::openTag(ofs, depth + command_depth,
1843 false, style->latexname());
1847 simpleDocBookOnePar(ofs, par, desc_on,
1848 depth + 1 + command_depth);
1852 // write closing SGML tags
1853 switch (style->latextype) {
1855 end_tag = c_params.empty() ? "title" : c_params;
1856 sgml::closeTag(ofs, depth + command_depth,
1859 case LATEX_ENVIRONMENT:
1860 if (!style->latexparam().empty()) {
1861 if (style->latexparam() == "CDATA")
1864 sgml::closeTag(ofs, depth + command_depth, false, style->latexparam());
1867 case LATEX_ITEM_ENVIRONMENT:
1868 if (desc_on == 1) break;
1870 sgml::closeTag(ofs, depth + 1 + command_depth, false, end_tag);
1872 case LATEX_PARAGRAPH:
1873 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1876 sgml::closeTag(ofs, depth + command_depth, false, style->latexname());
1882 for (int d = depth; d >= 0; --d) {
1883 if (!environment_stack[depth].empty()) {
1884 if (environment_inner[depth] != "!-- --") {
1885 item_name = "listitem";
1886 sgml::closeTag(ofs, command_depth + depth, false, item_name);
1887 if (environment_inner[depth] == "varlistentry")
1888 sgml::closeTag(ofs, depth + command_depth, false, environment_inner[depth]);
1891 sgml::closeTag(ofs, depth + command_depth, false, environment_stack[depth]);
1895 for (int j = command_depth; j >= 0 ; --j)
1896 if (!command_stack[j].empty()) {
1897 sgml::closeTag(ofs, j, false, command_stack[j]);
1902 sgml::closeTag(ofs, 0, false, top_element);
1905 // How to check for successful close
1907 // we want this to be true outside previews (for insetexternal)
1912 void Buffer::simpleDocBookOnePar(ostream & os,
1913 Paragraph * par, int & desc_on,
1914 Paragraph::depth_type depth) const
1916 bool emph_flag = false;
1918 LyXLayout_ptr const & style = par->layout();
1920 LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font);
1922 int char_line_count = depth;
1923 //if (!style.free_spacing)
1924 // os << string(depth,' ');
1926 // parsing main loop
1927 for (pos_type i = 0; i < par->size(); ++i) {
1928 LyXFont font = par->getFont(params, i);
1930 // handle <emphasis> tag
1931 if (font_old.emph() != font.emph()) {
1932 if (font.emph() == LyXFont::ON) {
1933 if (style->latexparam() == "CDATA")
1936 if (style->latexparam() == "CDATA")
1940 if (style->latexparam() == "CDATA")
1942 os << "</emphasis>";
1943 if (style->latexparam() == "CDATA")
1950 if (par->isInset(i)) {
1951 Inset * inset = par->getInset(i);
1952 // don't print the inset in position 0 if desc_on == 3 (label)
1953 if (i || desc_on != 3) {
1954 if (style->latexparam() == "CDATA")
1956 inset->docbook(this, os, false);
1957 if (style->latexparam() == "CDATA")
1961 char c = par->getChar(i);
1964 boost::tie(ws, str) = sgml::escapeChar(c);
1966 if (style->pass_thru) {
1968 } else if (style->free_spacing || par->isFreeSpacing() || c != ' ') {
1970 } else if (desc_on ==1) {
1972 os << "\n</term><listitem><para>";
1982 if (style->latexparam() == "CDATA")
1984 os << "</emphasis>";
1985 if (style->latexparam() == "CDATA")
1989 // resets description flag correctly
1991 // <term> not closed...
1992 os << "</term>\n<listitem><para> </para>";
1994 if (style->free_spacing)
1999 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
2000 // Other flags: -wall -v0 -x
2001 int Buffer::runChktex()
2003 if (!users->text) return 0;
2005 users->owner()->busy(true);
2007 // get LaTeX-Filename
2008 string const name = getLatexName();
2009 string path = filePath();
2011 string const org_path = path;
2012 if (lyxrc.use_tempdir || !IsDirWriteable(path)) {
2016 Path p(path); // path to LaTeX file
2017 users->owner()->message(_("Running chktex..."));
2019 // Remove all error insets
2020 bool const removedErrorInsets = users->removeAutoInsets();
2022 // Generate the LaTeX file if neccessary
2023 makeLaTeXFile(name, org_path, false);
2026 Chktex chktex(lyxrc.chktex_command, name, filePath());
2027 int res = chktex.run(terr); // run chktex
2030 Alert::error(_("chktex failure"),
2031 _("Could not run chktex successfully."));
2032 } else if (res > 0) {
2033 // Insert all errors as errors boxes
2034 users->insertErrors(terr);
2037 // if we removed error insets before we ran chktex or if we inserted
2038 // error insets after we ran chktex, this must be run:
2039 if (removedErrorInsets || res) {
2040 #warning repaint needed here, or do you mean update() ?
2044 users->owner()->busy(false);
2050 void Buffer::validate(LaTeXFeatures & features) const
2052 LyXTextClass const & tclass = params.getLyXTextClass();
2054 if (params.tracking_changes) {
2055 features.require("dvipost");
2056 features.require("color");
2059 // AMS Style is at document level
2060 if (params.use_amsmath == BufferParams::AMS_ON
2061 || tclass.provides(LyXTextClass::amsmath))
2062 features.require("amsmath");
2064 for_each(paragraphs.begin(), paragraphs.end(),
2065 boost::bind(&Paragraph::validate, _1, boost::ref(features)));
2067 // the bullet shapes are buffer level not paragraph level
2068 // so they are tested here
2069 for (int i = 0; i < 4; ++i) {
2070 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2071 int const font = params.user_defined_bullets[i].getFont();
2073 int const c = params
2074 .user_defined_bullets[i]
2081 features.require("latexsym");
2083 } else if (font == 1) {
2084 features.require("amssymb");
2085 } else if ((font >= 2 && font <= 5)) {
2086 features.require("pifont");
2091 if (lyxerr.debugging(Debug::LATEX)) {
2092 features.showStruct();
2097 vector<string> const Buffer::getLabelList() const
2099 /// if this is a child document and the parent is already loaded
2100 /// Use the parent's list instead [ale990407]
2101 if (!params.parentname.empty()
2102 && bufferlist.exists(params.parentname)) {
2103 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2105 return tmp->getLabelList();
2108 vector<string> label_list;
2109 for (inset_iterator it = inset_const_iterator_begin();
2110 it != inset_const_iterator_end(); ++it) {
2111 vector<string> const l = it->getLabelList();
2112 label_list.insert(label_list.end(), l.begin(), l.end());
2118 // This is also a buffer property (ale)
2119 void Buffer::fillWithBibKeys(vector<pair<string, string> > & keys) const
2121 /// if this is a child document and the parent is already loaded
2122 /// use the parent's list instead [ale990412]
2123 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
2124 Buffer const * tmp = bufferlist.getBuffer(params.parentname);
2126 tmp->fillWithBibKeys(keys);
2131 for (inset_iterator it = inset_const_iterator_begin();
2132 it != inset_const_iterator_end(); ++it) {
2133 if (it->lyxCode() == Inset::BIBTEX_CODE)
2134 static_cast<InsetBibtex &>(*it).fillWithBibKeys(this, keys);
2135 else if (it->lyxCode() == Inset::INCLUDE_CODE)
2136 static_cast<InsetInclude &>(*it).fillWithBibKeys(keys);
2137 else if (it->lyxCode() == Inset::BIBITEM_CODE) {
2138 InsetBibitem & bib = static_cast<InsetBibitem &>(*it);
2139 string const key = bib.getContents();
2140 string const opt = bib.getOptions();
2141 string const ref; // = pit->asString(this, false);
2142 string const info = opt + "TheBibliographyRef" + ref;
2143 keys.push_back(pair<string, string>(key, info));
2149 bool Buffer::isDepClean(string const & name) const
2151 DepClean::const_iterator it = dep_clean_.find(name);
2152 if (it == dep_clean_.end())
2158 void Buffer::markDepClean(string const & name)
2160 dep_clean_[name] = true;
2164 bool Buffer::dispatch(string const & command, bool * result)
2166 // Split command string into command and argument
2168 string line = ltrim(command);
2169 string const arg = trim(split(line, cmd, ' '));
2171 return dispatch(lyxaction.LookupFunc(cmd), arg, result);
2175 bool Buffer::dispatch(int action, string const & argument, bool * result)
2177 bool dispatched = true;
2181 bool const tmp = Exporter::Export(this, argument, false);
2194 void Buffer::resizeInsets(BufferView * bv)
2196 /// then remove all LyXText in text-insets
2197 for_each(paragraphs.begin(), paragraphs.end(),
2198 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
2202 void Buffer::redraw()
2204 #warning repaint needed here, or do you mean update() ?
2210 void Buffer::changeLanguage(Language const * from, Language const * to)
2213 ParIterator end = par_iterator_end();
2214 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2215 (*it)->changeLanguage(params, from, to);
2219 bool Buffer::isMultiLingual()
2221 ParIterator end = par_iterator_end();
2222 for (ParIterator it = par_iterator_begin(); it != end; ++it)
2223 if ((*it)->isMultiLingual(params))
2230 void Buffer::inset_iterator::setParagraph()
2232 while (pit != pend) {
2233 it = pit->insetlist.begin();
2234 if (it != pit->insetlist.end())
2241 Inset * Buffer::getInsetFromID(int id_arg) const
2243 for (inset_iterator it = inset_const_iterator_begin();
2244 it != inset_const_iterator_end(); ++it)
2246 if (it->id() == id_arg)
2248 Inset * in = it->getInsetFromID(id_arg);
2256 Paragraph * Buffer::getParFromID(int id) const
2261 // why should we allow < 0 ??
2262 //lyx::Assert(id >= 0);
2264 ParConstIterator it(par_iterator_begin());
2265 ParConstIterator end(par_iterator_end());
2267 for (; it != end; ++it) {
2268 // go on then, show me how to remove
2270 if ((*it)->id() == id) {
2271 return const_cast<Paragraph*>(*it);
2279 ParIterator Buffer::par_iterator_begin()
2281 return ParIterator(&*(paragraphs.begin()));
2285 ParIterator Buffer::par_iterator_end()
2287 return ParIterator();
2290 ParConstIterator Buffer::par_iterator_begin() const
2292 return ParConstIterator(&*(paragraphs.begin()));
2296 ParConstIterator Buffer::par_iterator_end() const
2298 return ParConstIterator();
2303 void Buffer::addUser(BufferView * u)
2309 void Buffer::delUser(BufferView *)
2315 Language const * Buffer::getLanguage() const
2317 return params.language;
2321 bool Buffer::isClean() const
2327 bool Buffer::isBakClean() const
2333 void Buffer::markClean() const
2339 // if the .lyx file has been saved, we don't need an
2345 void Buffer::markBakClean()
2351 void Buffer::setUnnamed(bool flag)
2357 bool Buffer::isUnnamed()
2363 void Buffer::markDirty()
2371 DepClean::iterator it = dep_clean_.begin();
2372 DepClean::const_iterator const end = dep_clean_.end();
2374 for (; it != end; ++it) {
2380 string const & Buffer::fileName() const
2386 string const & Buffer::filePath() const
2392 bool Buffer::isReadonly() const
2398 BufferView * Buffer::getUser() const
2404 void Buffer::setParentName(string const & name)
2406 params.parentname = name;
2410 Buffer::inset_iterator::inset_iterator()
2415 Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
2422 Buffer::inset_iterator & Buffer::inset_iterator::operator++()
2426 if (it == pit->insetlist.end()) {
2435 Buffer::inset_iterator Buffer::inset_iterator::operator++(int)
2437 inset_iterator tmp = *this;
2443 Buffer::inset_iterator::reference Buffer::inset_iterator::operator*()
2445 return *it.getInset();
2449 Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
2451 return it.getInset();
2455 Paragraph * Buffer::inset_iterator::getPar()
2461 lyx::pos_type Buffer::inset_iterator::getPos() const
2467 bool operator==(Buffer::inset_iterator const & iter1,
2468 Buffer::inset_iterator const & iter2)
2470 return iter1.pit == iter2.pit
2471 && (iter1.pit == iter1.pend || iter1.it == iter2.it);
2475 bool operator!=(Buffer::inset_iterator const & iter1,
2476 Buffer::inset_iterator const & iter2)
2478 return !(iter1 == iter2);