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.
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,
175 bool nice, bool only_body = false);
177 void makeDocBookFile(string const & filename,
178 bool nice, bool only_body = false);
180 /// returns the main language for the buffer (document)
181 string GetLanguage() const {
182 return params.language;
186 bool isLyxClean() const { return lyx_clean; }
189 bool isNwClean() const { return nw_clean; }
192 bool isBakClean() const { return bak_clean; }
195 bool isDepClean(string const & name) const;
198 void markLyxClean() const {
203 // if the .lyx file has been saved, we don't need an
209 void markNwClean() { nw_clean = true; }
212 void markBakClean() { bak_clean = true; }
215 void markDepClean(string const & name);
218 void markNwDirty() { nw_clean = false; }
228 DEPCLEAN * tmp = dep_clean;
236 string const & fileName() const { return filename; }
238 /** A transformed version of the file name, adequate for LaTeX
239 The path is stripped if no_path is true (default) */
240 string getLatexName(bool no_path = true) const;
242 /// Change name of buffer. Updates "read-only" flag.
243 void fileName(string const & newfile);
245 /// Name of the document's parent
246 void setParentName(string const &);
248 /// Is buffer read-only?
249 bool isReadonly() const { return read_only; }
251 /// Set buffer read-only flag
252 void setReadonly(bool flag = true);
254 /// returns true if the buffer contains a LaTeX document
255 bool isLatex() const;
256 /// returns true if the buffer contains a LinuxDoc document
257 bool isLinuxDoc() const;
258 /// returns true if the buffer contains a DocBook document
259 bool isDocBook() const;
260 /** returns true if the buffer contains either a LinuxDoc
261 or DocBook document */
263 /// returns true if the buffer contains a Wed document
264 bool isLiterate() const;
267 void setPaperStuff();
269 /** Validate a buffer for LaTeX.
270 This validates the buffer, and returns a struct for use by
271 makeLaTeX and others. Its main use is to figure out what
272 commands and packages need to be included in the LaTeX file.
273 It (should) also check that the needed constructs are there
274 (i.e. that the \refs points to coresponding \labels). It
275 should perhaps inset "error" insets to help the user correct
278 void validate(LaTeXFeatures &) const;
281 string getIncludeonlyList(char delim = ',');
283 std::vector<std::pair<string,string> > getBibkeyList();
302 std::vector<std::vector<TocItem> > getTocList();
304 std::vector<string> getLabelList();
306 /** This will clearly have to change later. Later we can have more
307 than one user per buffer. */
308 BufferView * getUser() const { return users; }
311 void ChangeLanguage(Language const * from, Language const * to);
313 bool isMultiLingual();
317 /// Does this mean that this is buffer local?
320 /// Does this mean that this is buffer local?
326 /** is a list of paragraphs.
328 LyXParagraph * paragraph;
333 /// where the temporaries go if we want them
339 /** While writing as LaTeX, tells whether we are
340 doing a 'nice' LaTeX file */
343 /// Used when typesetting to place errorboxes.
347 void linuxDocHandleFootnote(std::ostream & os,
348 LyXParagraph * & par, int const depth);
350 void DocBookHandleCaption(std::ostream & os, string & inner_tag,
351 int const depth, int desc_on,
352 LyXParagraph * & par);
354 void DocBookHandleFootnote(std::ostream & os,
355 LyXParagraph * & par, int const depth);
357 void sgmlOpenTag(std::ostream & os, int depth,
358 string const & latexname) const;
360 void sgmlCloseTag(std::ostream & os, int depth,
361 string const & latexname) const;
363 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
365 void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par,
366 int desc_on, int const depth);
368 void SimpleDocBookOnePar(std::ostream &, string & extra,
369 LyXParagraph * par, int & desc_on,
373 void push_tag(std::ostream & os, char const * tag,
374 int & pos, char stack[5][3]);
377 void pop_tag(std::ostream & os, char const * tag,
378 int & pos, char stack[5][3]);
381 mutable bool lyx_clean;
383 /// is autosave needed
384 mutable bool bak_clean;
386 /// do we need to run weave/tangle
389 /// is regenerating .tex necessary
390 DEPCLEAN * dep_clean;
395 /// name of the file the buffer is associated with.
398 /// Format number of buffer
401 /** A list of views using this buffer.
402 Why not keep a list of the BufferViews that use this buffer?
404 At least then we don't have to do a lot of magic like:
405 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
406 of the buffers in the list of users to do a updateLayoutChoice.
411 class inset_iterator {
413 inset_iterator() : par(0) /*, it(0)*/ {}
414 inset_iterator(LyXParagraph * paragraph) : par(paragraph) {
417 inset_iterator(LyXParagraph * paragraph, LyXParagraph::size_type pos);
418 inset_iterator & operator++() {
421 if (it == par->inset_iterator_end()) {
428 Inset * operator*() {return *it; }
429 LyXParagraph * getPar() { return par; }
430 LyXParagraph::size_type getPos() {return it.getPos(); }
432 bool operator==(inset_iterator const & iter1,
433 inset_iterator const & iter2) {
434 return iter1.par == iter2.par
435 && (iter1.par == 0 || iter1.it == iter2.it);
438 bool operator!=(inset_iterator const & iter1,
439 inset_iterator const & iter2) {
440 return !(iter1 == iter2);
445 LyXParagraph::inset_iterator it;
449 inset_iterator inset_iterator_begin() {
450 return inset_iterator(paragraph);
453 inset_iterator inset_iterator_end() {
454 return inset_iterator();
460 void Buffer::setParentName(string const & name)
462 params.parentname = name;
466 bool operator==(Buffer::TocItem const & a, Buffer::TocItem const & b) {
467 return a.par == b.par && a.str == b.str;
468 // No need to compare depth.
473 bool operator!=(Buffer::TocItem const & a, Buffer::TocItem const & b) {
475 // No need to compare depth.