2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
8 * This file is Copyleft 1996
11 * ====================================================== */
15 // 23/03/98 Heinrich Bauer (heinrich.bauer@t-mobil.de)
16 // Spots marked "changed Heinrich Bauer, 23/03/98" modified due to the
17 // following bug: dvi file export did not work after printing (or previewing)
18 // and vice versa as long as the same file was concerned. This happened
19 // every time the LyX-file was left unchanged between the two actions mentioned
31 #include "BufferView.h"
33 #include "bufferparams.h"
51 /** The buffer object.
52 The is is the buffer object. It contains all the informations about
53 a document loaded into LyX. I am not sure if the class is complete or
54 minimal, probably not.
58 /**@name Constructors and destructor */
61 explicit Buffer(string const & file, bool b = false);
70 /** save the buffer's parameters as user default
71 This function saves a file user_lyxdir/templates/defaults.lyx
72 which parameters are those of the current buffer. This file
73 is used as a default template when creating a new
74 file. Returns true on success.
76 bool saveParamsAsDefaults();
78 /** high-level interface to buffer functionality
79 This function parses a command string and executes it
81 bool Dispatch(string const & command);
83 /// Maybe we know the function already by number...
84 bool Dispatch(int ac, string const & argument);
86 /// should be changed to work for a list.
93 /// Update window titles of all users
94 void updateTitles() const;
96 /// Reset autosave timers for all users
97 void resetAutosaveTimers() const;
99 /** Adds the BufferView to the users list.
100 Later this func will insert the BufferView into a real list,
101 not just setting a pointer.
103 void addUser(BufferView * u) { users = u; }
105 /** Removes the BufferView from the users list.
106 Since we only can have one at the moment, we just reset it.
108 void delUser(BufferView *) { users = 0; }
114 //users->updateScrollbar();
118 void loadAutoSaveFile();
121 Returns false if it fails.
122 If par is given, the file is inserted. */
123 bool readFile(LyXLex &, LyXParagraph * par = 0);
125 /** Reads a file without header.
126 Returns false, if file is not completely read.
127 If par is given, the file is inserted. */
128 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
130 /* This parses a single LyXformat-Token */
131 bool parseSingleLyXformat2Token(LyXLex &, LyXParagraph *& par,
132 LyXParagraph *& return_par,
133 string const & token, int & pos,
134 char & depth, LyXFont &,
135 LyXParagraph::footnote_flag &,
136 LyXParagraph::footnote_kind &);
139 Takes care of auto-save files and backup file if requested.
140 Returns true if the save is successful, false otherwise.
144 /// Write file. Returns false if unsuccesful.
145 bool writeFile(string const &, bool) const;
148 void writeFileAscii(string const & , int);
151 void makeLaTeXFile(string const & filename,
152 string const & original_path,
153 bool nice, bool only_body = false);
155 // LaTeX all paragraphs from par to endpar,
156 // if endpar == 0 then to the end
158 void latexParagraphs(std::ostream & os, LyXParagraph *par,
159 LyXParagraph *endpar, TexRow & texrow) const;
174 void makeLinuxDocFile(string const & filename, int column);
176 void makeDocBookFile(string const & filename, int column);
178 /// returns the main language for the buffer (document)
179 string GetLanguage() const {
180 return params.language;
184 bool isLyxClean() const { return lyx_clean; }
186 /// changed Heinrich Bauer, 23/03/98
187 bool isDviClean() const;
190 bool isNwClean() const { return nw_clean; }
193 bool isBakClean() const { return bak_clean; }
196 bool isDepClean(string const & name) const;
199 void markLyxClean() const {
204 // if the .lyx file has been saved, we don't need an
209 /// changed Heinrich Bauer, 23/03/98
213 void markNwClean() { nw_clean = true; }
216 void markBakClean() { bak_clean = true; }
219 void markDepClean(string const & name);
225 void markNwDirty() { nw_clean = false; }
233 dvi_clean_tmpd = false;
234 dvi_clean_orgd = false;
237 DEPCLEAN * tmp = dep_clean;
245 string const & fileName() const { return filename; }
247 /** A transformed version of the file name, adequate for LaTeX
248 The path is stripped if no_path is true (default) */
249 string getLatexName(bool no_path = true) const;
251 /// Change name of buffer. Updates "read-only" flag.
252 void fileName(string const & newfile);
254 /// Name of the document's parent
255 void setParentName(string const &);
257 /// Is buffer read-only?
258 bool isReadonly() const { return read_only; }
260 /// Set buffer read-only flag
261 void setReadonly(bool flag = true);
263 /// returns true if the buffer contains a LaTeX document
264 bool isLatex() const;
265 /// returns true if the buffer contains a LinuxDoc document
266 bool isLinuxDoc() const;
267 /// returns true if the buffer contains a DocBook document
268 bool isDocBook() const;
269 /** returns true if the buffer contains either a LinuxDoc
270 or DocBook document */
272 /// returns true if the buffer contains a Wed document
273 bool isLiterate() const;
276 void setPaperStuff();
278 /** Validate a buffer for LaTeX.
279 This validates the buffer, and returns a struct for use by
280 makeLaTeX and others. Its main use is to figure out what
281 commands and packages need to be included in the LaTeX file.
282 It (should) also check that the needed constructs are there
283 (i.e. that the \refs points to coresponding \labels). It
284 should perhaps inset "error" insets to help the user correct
287 void validate(LaTeXFeatures &) const;
290 string getIncludeonlyList(char delim = ',');
292 std::vector<std::pair<string,string> > getBibkeyList();
311 std::vector<std::vector<TocItem> > getTocList();
313 std::vector<string> getLabelList();
315 /** This will clearly have to change later. Later we can have more
316 than one user per buffer. */
317 BufferView * getUser() const { return users; }
320 void ChangeLanguage(Language const * from, Language const * to);
322 bool isMultiLingual();
326 /// Does this mean that this is buffer local?
329 /// Does this mean that this is buffer local?
335 /** is a list of paragraphs.
337 LyXParagraph * paragraph;
342 /// where the temporaries go if we want them
348 /** While writing as LaTeX, tells whether we are
349 doing a 'nice' LaTeX file */
352 /// Used when typesetting to place errorboxes.
356 void linuxDocHandleFootnote(std::ostream & os,
357 LyXParagraph * & par, int const depth);
359 void DocBookHandleCaption(std::ostream & os, string & inner_tag,
360 int const depth, int desc_on,
361 LyXParagraph * & par);
363 void DocBookHandleFootnote(std::ostream & os,
364 LyXParagraph * & par, int const depth);
366 void sgmlOpenTag(std::ostream & os, int depth,
367 string const & latexname) const;
369 void sgmlCloseTag(std::ostream & os, int depth,
370 string const & latexname) const;
372 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
374 void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par,
375 int desc_on, int const depth);
377 void SimpleDocBookOnePar(std::ostream &, string & extra,
378 LyXParagraph * par, int & desc_on,
382 void push_tag(std::ostream & os, char const * tag,
383 int & pos, char stack[5][3]);
386 void pop_tag(std::ostream & os, char const * tag,
387 int & pos, char stack[5][3]);
391 void RoffAsciiTable(std::ostream &, LyXParagraph * par);
395 mutable bool lyx_clean;
397 /// is autosave needed
398 mutable bool bak_clean;
400 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
401 We have to distinguish between TeX-runs executed in the original
402 directory (in which the original LyX-file resides) and TeX-runs
403 executed in a temporary directory. The first situation is valid
404 for a dvi-export, the latter one for printing or previewing. */
408 /// do we need to run weave/tangle
411 /// is regenerating .tex necessary
412 DEPCLEAN * dep_clean;
417 /// name of the file the buffer is associated with.
420 /// Format number of buffer
423 /** A list of views using this buffer.
424 Why not keep a list of the BufferViews that use this buffer?
426 At least then we don't have to do a lot of magic like:
427 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
428 of the buffers in the list of users to do a updateLayoutChoice.
433 class inset_iterator {
435 inset_iterator() : par(0) /*, it(0)*/ {}
436 inset_iterator(LyXParagraph * paragraph) : par(paragraph) {
439 inset_iterator(LyXParagraph * paragraph, LyXParagraph::size_type pos);
440 inset_iterator & operator++() {
443 if (it == par->inset_iterator_end()) {
450 Inset * operator*() {return *it; }
451 LyXParagraph * getPar() { return par; }
452 LyXParagraph::size_type getPos() {return it.getPos(); }
454 bool operator==(inset_iterator const & iter1,
455 inset_iterator const & iter2) {
456 return iter1.par == iter2.par
457 && (iter1.par == 0 || iter1.it == iter2.it);
460 bool operator!=(inset_iterator const & iter1,
461 inset_iterator const & iter2) {
462 return !(iter1 == iter2);
467 LyXParagraph::inset_iterator it;
471 inset_iterator inset_iterator_begin() {
472 return inset_iterator(paragraph);
475 inset_iterator inset_iterator_end() {
476 return inset_iterator();
482 void Buffer::setParentName(string const & name)
484 params.parentname = name;
488 bool operator==(Buffer::TocItem const & a, Buffer::TocItem const & b) {
489 return a.par == b.par && a.str == b.str;
490 // No need to compare depth.
495 bool operator!=(Buffer::TocItem const & a, Buffer::TocItem const & b) {
497 // No need to compare depth.