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"
40 class auto_mem_buffer;
52 /** The buffer object.
53 The is is the buffer object. It contains all the informations about
54 a document loaded into LyX. I am not sure if the class is complete or
55 minimal, probably not.
59 /**@name Constructors and destructor */
62 explicit Buffer(string const & file, bool b = false);
71 /** save the buffer's parameters as user default
72 This function saves a file user_lyxdir/templates/defaults.lyx
73 which parameters are those of the current buffer. This file
74 is used as a default template when creating a new
75 file. Returns true on success.
77 bool saveParamsAsDefaults();
79 /** high-level interface to buffer functionality
80 This function parses a command string and executes it
82 bool Dispatch(string const & command);
84 /// Maybe we know the function already by number...
85 bool Dispatch(int ac, string const & argument);
87 /// and have an xtl buffer to work with.
88 bool Dispatch(int, auto_mem_buffer &);
90 /// should be changed to work for a list.
97 /// Update window titles of all users
98 void updateTitles() const;
100 /// Reset autosave timers for all users
101 void resetAutosaveTimers() const;
103 /** Adds the BufferView to the users list.
104 Later this func will insert the BufferView into a real list,
105 not just setting a pointer.
107 void addUser(BufferView * u) { users = u; }
109 /** Removes the BufferView from the users list.
110 Since we only can have one at the moment, we just reset it.
112 void delUser(BufferView *) { users = 0; }
118 //users->updateScrollbar();
122 void loadAutoSaveFile();
125 Returns false if it fails.
126 If par is given, the file is inserted. */
127 bool readFile(LyXLex &, LyXParagraph * par = 0);
129 /** Reads a file without header.
130 Returns false, if file is not completely read.
131 If par is given, the file is inserted. */
132 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
134 /* This parses a single LyXformat-Token */
135 bool parseSingleLyXformat2Token(LyXLex &, LyXParagraph *& par,
136 LyXParagraph *& return_par,
137 string const & token, int & pos,
138 char & depth, LyXFont &,
139 LyXParagraph::footnote_flag &,
140 LyXParagraph::footnote_kind &);
143 Takes care of auto-save files and backup file if requested.
144 Returns true if the save is successful, false otherwise.
148 /// Write file. Returns false if unsuccesful.
149 bool writeFile(string const &, bool) const;
152 void writeFileAscii(string const & , int);
155 void makeLaTeXFile(string const & filename,
156 string const & original_path,
157 bool nice, bool only_body = false);
159 // LaTeX all paragraphs from par to endpar,
160 // if endpar == 0 then to the end
162 void latexParagraphs(std::ostream & os, LyXParagraph *par,
163 LyXParagraph *endpar, TexRow & texrow) const;
178 void makeLinuxDocFile(string const & filename, int column);
180 void makeDocBookFile(string const & filename, int column);
182 /// returns the main language for the buffer (document)
183 string GetLanguage() const {
184 return params.language;
188 bool isLyxClean() const { return lyx_clean; }
190 /// changed Heinrich Bauer, 23/03/98
191 bool isDviClean() const;
194 bool isNwClean() const { return nw_clean; }
197 bool isBakClean() const { return bak_clean; }
200 bool isDepClean(string const & name) const;
203 void markLyxClean() const {
208 // if the .lyx file has been saved, we don't need an
213 /// changed Heinrich Bauer, 23/03/98
217 void markNwClean() { nw_clean = true; }
220 void markBakClean() { bak_clean = true; }
223 void markDepClean(string const & name);
229 void markNwDirty() { nw_clean = false; }
237 dvi_clean_tmpd = false;
238 dvi_clean_orgd = false;
241 DEPCLEAN * tmp = dep_clean;
249 string const & fileName() const { return filename; }
251 /** A transformed version of the file name, adequate for LaTeX
252 The path is stripped if no_path is true (default) */
253 string getLatexName(bool no_path = true) const;
255 /// Change name of buffer. Updates "read-only" flag.
256 void fileName(string const & newfile);
258 /// Name of the document's parent
259 void setParentName(string const &);
261 /// Is buffer read-only?
262 bool isReadonly() const { return read_only; }
264 /// Set buffer read-only flag
265 void setReadonly(bool flag = true);
267 /// returns true if the buffer contains a LaTeX document
268 bool isLatex() const;
269 /// returns true if the buffer contains a LinuxDoc document
270 bool isLinuxDoc() const;
271 /// returns true if the buffer contains a DocBook document
272 bool isDocBook() const;
273 /** returns true if the buffer contains either a LinuxDoc
274 or DocBook document */
276 /// returns true if the buffer contains a Wed document
277 bool isLiterate() const;
280 void setPaperStuff();
282 /** Validate a buffer for LaTeX.
283 This validates the buffer, and returns a struct for use by
284 makeLaTeX and others. Its main use is to figure out what
285 commands and packages need to be included in the LaTeX file.
286 It (should) also check that the needed constructs are there
287 (i.e. that the \refs points to coresponding \labels). It
288 should perhaps inset "error" insets to help the user correct
291 void validate(LaTeXFeatures &) const;
294 string getIncludeonlyList(char delim = ',');
296 std::vector<std::pair<string,string> > getBibkeyList();
315 std::vector<std::vector<TocItem> > getTocList();
317 std::vector<string> getLabelList();
319 /** This will clearly have to change later. Later we can have more
320 than one user per buffer. */
321 BufferView * getUser() const { return users; }
324 void ChangeLanguage(Language const * from, Language const * to);
326 bool isMultiLingual();
330 /// Does this mean that this is buffer local?
333 /// Does this mean that this is buffer local?
339 /** is a list of paragraphs.
341 LyXParagraph * paragraph;
346 /// where the temporaries go if we want them
352 /** While writing as LaTeX, tells whether we are
353 doing a 'nice' LaTeX file */
356 /// Used when typesetting to place errorboxes.
360 void linuxDocHandleFootnote(std::ostream & os,
361 LyXParagraph * & par, int const depth);
363 void DocBookHandleCaption(std::ostream & os, string & inner_tag,
364 int const depth, int desc_on,
365 LyXParagraph * & par);
367 void DocBookHandleFootnote(std::ostream & os,
368 LyXParagraph * & par, int const depth);
370 void sgmlOpenTag(std::ostream & os, int depth,
371 string const & latexname) const;
373 void sgmlCloseTag(std::ostream & os, int depth,
374 string const & latexname) const;
376 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
378 void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par,
379 int desc_on, int const depth);
381 void SimpleDocBookOnePar(std::ostream &, string & extra,
382 LyXParagraph * par, int & desc_on,
386 void push_tag(std::ostream & os, char const * tag,
387 int & pos, char stack[5][3]);
390 void pop_tag(std::ostream & os, char const * tag,
391 int & pos, char stack[5][3]);
395 void RoffAsciiTable(std::ostream &, LyXParagraph * par);
399 mutable bool lyx_clean;
401 /// is autosave needed
402 mutable bool bak_clean;
404 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
405 We have to distinguish between TeX-runs executed in the original
406 directory (in which the original LyX-file resides) and TeX-runs
407 executed in a temporary directory. The first situation is valid
408 for a dvi-export, the latter one for printing or previewing. */
412 /// do we need to run weave/tangle
415 /// is regenerating .tex necessary
416 DEPCLEAN * dep_clean;
421 /// name of the file the buffer is associated with.
424 /// Format number of buffer
427 /** A list of views using this buffer.
428 Why not keep a list of the BufferViews that use this buffer?
430 At least then we don't have to do a lot of magic like:
431 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
432 of the buffers in the list of users to do a updateLayoutChoice.
437 class inset_iterator {
439 inset_iterator() : par(0) /*, it(0)*/ {}
440 inset_iterator(LyXParagraph * paragraph) : par(paragraph) {
443 inset_iterator(LyXParagraph * paragraph, LyXParagraph::size_type pos);
444 inset_iterator & operator++() {
447 if (it == par->inset_iterator_end()) {
454 Inset * operator*() {return *it; }
455 LyXParagraph * getPar() { return par; }
456 LyXParagraph::size_type getPos() {return it.getPos(); }
458 bool operator==(inset_iterator const & iter1,
459 inset_iterator const & iter2) {
460 return iter1.par == iter2.par
461 && (iter1.par == 0 || iter1.it == iter2.it);
464 bool operator!=(inset_iterator const & iter1,
465 inset_iterator const & iter2) {
466 return !(iter1 == iter2);
471 LyXParagraph::inset_iterator it;
475 inset_iterator inset_iterator_begin() {
476 return inset_iterator(paragraph);
479 inset_iterator inset_iterator_end() {
480 return inset_iterator();
486 void Buffer::setParentName(string const & name)
488 params.parentname = name;
492 bool operator==(Buffer::TocItem const & a, Buffer::TocItem const & b) {
493 return a.par == b.par && a.str == b.str;
494 // No need to compare depth.
499 bool operator!=(Buffer::TocItem const & a, Buffer::TocItem const & b) {
501 // No need to compare depth.