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"
41 extern void updateAllVisibleBufferRelatedPopups();
53 /** The buffer object.
54 The is is the buffer object. It contains all the informations about
55 a document loaded into LyX. I am not sure if the class is complete or
56 minimal, probably not.
60 /**@name Constructors and destructor */
63 explicit Buffer(string const & file, bool b = false);
72 /** save the buffer's parameters as user default
73 This function saves a file user_lyxdir/templates/defaults.lyx
74 which parameters are those of the current buffer. This file
75 is used as a default template when creating a new
76 file. Returns true on success.
78 bool saveParamsAsDefaults();
80 /** high-level interface to buffer functionality
81 This function parses a command string and executes it
83 bool Dispatch(string const & command);
85 /// Maybe we know the function already by number...
86 bool Dispatch(int ac, string const & argument);
88 /// should be changed to work for a list.
95 /// Update window titles of all users
96 void updateTitles() const;
98 /// Reset autosave timers for all users
99 void resetAutosaveTimers() const;
101 /** Adds the BufferView to the users list.
102 Later this func will insert the BufferView into a real list,
103 not just setting a pointer.
105 void addUser(BufferView * u) { users = u; }
107 /** Removes the BufferView from the users list.
108 Since we only can have one at the moment, we just reset it.
110 void delUser(BufferView *) { users = 0; }
116 //users->updateScrollbar();
120 void loadAutoSaveFile();
123 Returns false if it fails.
124 If par is given, the file is inserted. */
125 bool readFile(LyXLex &, LyXParagraph * par = 0);
127 /** Reads a file without header.
128 Returns false, if file is not completely read.
129 If par is given, the file is inserted. */
130 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
132 /* This parses a single LyXformat-Token */
133 bool parseSingleLyXformat2Token(LyXLex &, LyXParagraph *& par,
134 LyXParagraph *& return_par,
135 string const & token, int & pos,
136 char & depth, LyXFont &,
137 LyXParagraph::footnote_flag &,
138 LyXParagraph::footnote_kind &);
141 Takes care of auto-save files and backup file if requested.
142 Returns true if the save is successful, false otherwise.
146 /// Write file. Returns false if unsuccesful.
147 bool writeFile(string const &, bool) const;
150 void writeFileAscii(string const & , int);
153 void makeLaTeXFile(string const & filename,
154 string const & original_path,
155 bool nice, bool only_body = false);
157 // LaTeX all paragraphs from par to endpar,
158 // if endpar == 0 then to the end
160 void latexParagraphs(ostream & os, LyXParagraph *par,
161 LyXParagraph *endpar, TexRow & texrow);
176 void makeLinuxDocFile(string const & filename, int column);
178 void makeDocBookFile(string const & filename, int column);
180 /// returns the main language for the buffer (document)
181 string GetLanguage() const {
182 return params.language;
186 bool isLyxClean() const { return lyx_clean; }
188 /// changed Heinrich Bauer, 23/03/98
189 bool isDviClean() const;
192 bool isNwClean() const { return nw_clean; }
195 bool isBakClean() const { return bak_clean; }
198 bool isDepClean(string const & name) const;
201 void markLyxClean() const {
206 // if the .lyx file has been saved, we don't need an
211 /// changed Heinrich Bauer, 23/03/98
215 void markNwClean() { nw_clean = true; }
218 void markBakClean() { bak_clean = true; }
221 void markDepClean(string const & name);
227 void markNwDirty() { nw_clean = false; }
235 dvi_clean_tmpd = false;
236 dvi_clean_orgd = false;
239 DEPCLEAN * tmp = dep_clean;
247 string const & fileName() const { return filename; }
249 /** A transformed version of the file name, adequate for LaTeX
250 The path is stripped if no_path is true (default) */
251 string getLatexName(bool no_path = true) const;
253 /// Change name of buffer. Updates "read-only" flag.
254 void fileName(string const & newfile);
256 /// Name of the document's parent
257 void setParentName(string const &);
259 /// Is buffer read-only?
260 bool isReadonly() const { return read_only; }
262 /// Set buffer read-only flag
263 void setReadonly(bool flag = true);
265 /// returns true if the buffer contains a LaTeX document
266 bool isLatex() const;
267 /// returns true if the buffer contains a LinuxDoc document
268 bool isLinuxDoc() const;
269 /// returns true if the buffer contains a DocBook document
270 bool isDocBook() const;
271 /** returns true if the buffer contains either a LinuxDoc
272 or DocBook document */
274 /// returns true if the buffer contains a Wed document
275 bool isLiterate() const;
278 void setPaperStuff();
280 /** Validate a buffer for LaTeX.
281 This validates the buffer, and returns a struct for use by
282 makeLaTeX and others. Its main use is to figure out what
283 commands and packages need to be included in the LaTeX file.
284 It (should) also check that the needed constructs are there
285 (i.e. that the \refs points to coresponding \labels). It
286 should perhaps inset "error" insets to help the user correct
289 void validate(LaTeXFeatures &) const;
292 string getIncludeonlyList(char delim = ',');
294 string getReferenceList(char delim = '|');
296 string getBibkeyList(char delim = '|');
298 /** This will clearly have to change later. Later we can have more
299 than one user per buffer. */
300 BufferView * getUser() const { return users; }
303 void ChangeLanguage(Language const * from, Language const * to);
305 bool isMultiLingual();
309 /// Does this mean that this is buffer local?
312 /// Does this mean that this is buffer local?
318 /** is a list of paragraphs.
320 LyXParagraph * paragraph;
325 /// where the temporaries go if we want them
331 /** While writing as LaTeX, tells whether we are
332 doing a 'nice' LaTeX file */
335 /// Used when typesetting to place errorboxes.
339 void linuxDocHandleFootnote(std::ostream & os,
340 LyXParagraph * & par, int const depth);
342 void DocBookHandleCaption(std::ostream & os, string & inner_tag,
343 int const depth, int desc_on,
344 LyXParagraph * & par);
346 void DocBookHandleFootnote(std::ostream & os,
347 LyXParagraph * & par, int const depth);
349 void sgmlOpenTag(std::ostream & os, int depth,
350 string const & latexname) const;
352 void sgmlCloseTag(std::ostream & os, int depth,
353 string const & latexname) const;
355 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
357 void SimpleLinuxDocOnePar(std::ostream & os, LyXParagraph * par,
358 int desc_on, int const depth);
360 void SimpleDocBookOnePar(std::ostream &, string & extra,
361 LyXParagraph * par, int & desc_on,
365 void push_tag(std::ostream & os, char const * tag,
366 int & pos, char stack[5][3]);
369 void pop_tag(std::ostream & os, char const * tag,
370 int & pos, char stack[5][3]);
374 void RoffAsciiTable(std::ostream &, LyXParagraph * par);
378 mutable bool lyx_clean;
380 /// is autosave needed
381 mutable bool bak_clean;
383 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
384 We have to distinguish between TeX-runs executed in the original
385 directory (in which the original LyX-file resides) and TeX-runs
386 executed in a temporary directory. The first situation is valid
387 for a dvi-export, the latter one for printing or previewing. */
391 /// do we need to run weave/tangle
394 /// is regenerating .tex necessary
395 DEPCLEAN * dep_clean;
400 /// name of the file the buffer is associated with.
403 /// Format number of buffer
406 /** A list of views using this buffer.
407 Why not keep a list of the BufferViews that use this buffer?
409 At least then we don't have to do a lot of magic like:
410 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
411 of the buffers in the list of users to do a updateLayoutChoice.
418 void Buffer::setParentName(string const & name)
420 params.parentname = name;