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"
35 #include "support/filetools.h"
36 #include "lyx_gui_misc.h"
44 extern void updateAllVisibleBufferRelatedPopups();
56 /** The buffer object.
57 The is is the buffer object. It contains all the informations about
58 a document loaded into LyX. I am not sure if the class is complete or
59 minimal, probably not.
63 /**@name Constructors and destructor */
66 Buffer(string const & file, bool b = false);
75 /** save the buffer's parameters as user default
76 This function saves a file user_lyxdir/templates/defaults.lyx
77 which parameters are those of the current buffer. This file
78 is used as a default template when creating a new
79 file. Returns true on success.
81 bool saveParamsAsDefaults();
83 /** high-level interface to buffer functionality
84 This function parses a command string and executes it
86 void Dispatch(const string & command);
88 /// Maybe we know the function already by number...
89 void Dispatch(int ac, const string & argument);
91 /// should be changed to work for a list.
98 /// Update window titles of all users
99 void updateTitles() const;
101 /// Reset autosave timers for all users
102 void resetAutosaveTimers() const;
104 /** Adds the BufferView to the users list.
105 Later this func will insert the BufferView into a real list,
106 not just setting a pointer.
108 void addUser(BufferView * u) { users = u; }
110 /** Removes the BufferView from the users list.
111 Since we only can have one at the moment, we just reset it.
113 void delUser(BufferView *) { users = 0; }
119 users->updateScrollbar();
123 void loadAutoSaveFile();
126 Returns false if it fails.
127 If par is given, the file is inserted. */
128 bool readFile(LyXLex &, LyXParagraph * par = 0);
130 /** Reads a file without header.
131 Returns false, if file is not completely read.
132 If par is given, the file is inserted. */
133 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
135 /* This parses a single LyXformat-Token */
136 bool parseSingleLyXformat2Token(LyXLex &, LyXParagraph *& par,
137 LyXParagraph *& return_par,
138 const string & token, int & pos,
139 char & depth, LyXFont &,
140 LyXParagraph::footnote_flag &,
141 LyXParagraph::footnote_kind &);
144 Takes care of auto-save files and backup file if requested.
145 Returns true if the save is successful, false otherwise.
149 /// Write file. Returns false if unsuccesful.
150 bool writeFile(string const &, bool) const;
153 void writeFileAscii(string const & , int);
156 void makeLaTeXFile(string const & filename,
157 string const & original_path,
158 bool nice, bool only_body = false);
173 void makeLinuxDocFile(string const & filename, int column);
175 void makeDocBookFile(string const & filename, int column);
177 /// returns the main language for the buffer (document)
178 string GetLanguage() const {
179 return params.language;
183 bool isLyxClean() const { return lyx_clean; }
185 /// changed Heinrich Bauer, 23/03/98
186 bool isDviClean() const;
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
208 /// changed Heinrich Bauer, 23/03/98
212 void markNwClean() { nw_clean = true; }
215 void markBakClean() { bak_clean = true; }
218 void markDepClean(string const & name);
224 void markNwDirty() { nw_clean = false; }
232 dvi_clean_tmpd = false;
233 dvi_clean_orgd = false;
236 DEPCLEAN * tmp = dep_clean;
244 string const & fileName() const { return filename; }
246 /** A transformed version of the file name, adequate for LaTeX
247 The path is stripped if no_path is true (default) */
248 string getLatexName(bool no_path = true) const {
249 return ChangeExtension(MakeLatexName(filename),
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) {
264 if (read_only != flag) {
267 updateAllVisibleBufferRelatedPopups();
270 WarnReadonly(filename);
274 /// returns true if the buffer contains a LaTeX document
275 bool isLatex() const;
276 /// returns true if the buffer contains a LinuxDoc document
277 bool isLinuxDoc() const;
278 /// returns true if the buffer contains a DocBook document
279 bool isDocBook() const;
280 /// returns true if the buffer contains either a LinuxDoc or DocBook document
282 /// returns true if the buffer contains a Wed document
283 bool isLiterate() const;
286 void setPaperStuff();
288 /** Validate a buffer for LaTeX.
289 This validates the buffer, and returns a struct for use by
290 makeLaTeX and others. Its main use is to figure out what commands
291 and packages need to be included in the LaTeX file. It (should)
292 also check that the needed constructs are there (i.e. that the \refs
293 points to coresponding \labels). It should perhaps inset "error"
294 insets to help the user correct obvious mistakes.
296 void validate(LaTeXFeatures &) const;
299 string getIncludeonlyList(char delim = ',');
301 string getReferenceList(char delim = '|');
303 string getBibkeyList(char delim = '|');
305 /** This will clearly have to change later. Later we can have more
306 than one user per buffer. */
307 BufferView * getUser() const { return users; }
311 /// Does this mean that this is buffer local?
314 /// Does this mean that this is buffer local?
320 /** is a list of paragraphs.
322 LyXParagraph * paragraph;
327 /// where the temporaries go if we want them
333 /** While writing as LaTeX, tells whether we are
334 doing a 'nice' LaTeX file */
337 /// Used when typesetting to place errorboxes.
341 void linuxDocHandleFootnote(ostream & os,
342 LyXParagraph * & par, int const depth);
344 void DocBookHandleCaption(ostream & os, string & inner_tag,
345 int const depth, int desc_on,
346 LyXParagraph * & par);
348 void DocBookHandleFootnote(ostream & os,
349 LyXParagraph * & par, int const depth);
351 void sgmlOpenTag(ostream & os, int depth,
352 string const & latexname) const;
354 void sgmlCloseTag(ostream & os, int depth,
355 string const & latexname) const;
357 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
359 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
360 int desc_on, int const depth);
362 void SimpleDocBookOnePar(ostream &, string & extra,
363 LyXParagraph * par, int & desc_on,
367 void push_tag(ostream & os, char const * tag,
368 int & pos, char stack[5][3]);
371 void pop_tag(ostream & os, char const * tag,
372 int & pos, char stack[5][3]);
376 void RoffAsciiTable(ostream &, LyXParagraph * par);
380 mutable bool lyx_clean;
382 /// is autosave needed
383 mutable bool bak_clean;
385 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
386 We have to distinguish between TeX-runs executed in the original
387 directory (in which the original LyX-file resides) and TeX-runs
388 executed in a temporary directory. The first situation is valid
389 for a dvi-export, the latter one for printing or previewing. */
393 /// do we need to run weave/tangle
396 /// is regenerating .tex necessary
397 DEPCLEAN * dep_clean;
402 /// name of the file the buffer is associated with.
405 /// Format number of buffer
408 /** A list of views using this buffer.
409 Why not keep a list of the BufferViews that use this buffer?
411 At least then we don't have to do a lot of magic like:
412 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
413 of the buffers in the list of users to do a updateLayoutChoice.
420 void Buffer::setParentName(string const & name)
422 params.parentname = name;