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"
43 extern void updateAllVisibleBufferRelatedPopups();
55 /** The buffer object.
56 The is is the buffer object. It contains all the informations about
57 a document loaded into LyX. I am not sure if the class is complete or
58 minimal, probably not.
62 /**@name Constructors and destructor */
65 Buffer(string const & file, bool b = false);
74 /** save the buffer's parameters as user default
75 This function saves a file user_lyxdir/templates/defaults.lyx
76 which parameters are those of the current buffer. This file
77 is used as a default template when creating a new
78 file. Returns true on success.
80 bool saveParamsAsDefaults();
82 /** high-level interface to buffer functionality
83 This function parses a command string and executes it
85 void Dispatch(const string & command);
87 /// Maybe we know the function already by number...
88 void Dispatch(int ac, const string & argument);
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 const string & 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);
172 void makeLinuxDocFile(string const & filename, int column);
174 void makeDocBookFile(string const & filename, int column);
176 /// returns the main language for the buffer (document)
177 string GetLanguage() const {
178 return params.language;
182 bool isLyxClean() const { return lyx_clean; }
184 /// changed Heinrich Bauer, 23/03/98
185 bool isDviClean() const;
188 bool isNwClean() const { return nw_clean; }
191 bool isBakClean() const { return bak_clean; }
194 bool isDepClean(string const & name) const;
197 void markLyxClean() const {
202 // if the .lyx file has been saved, we don't need an
207 /// changed Heinrich Bauer, 23/03/98
211 void markNwClean() { nw_clean = true; }
214 void markBakClean() { bak_clean = true; }
217 void markDepClean(string const & name);
223 void markNwDirty() { nw_clean = false; }
231 dvi_clean_tmpd = false;
232 dvi_clean_orgd = false;
235 DEPCLEAN * tmp = dep_clean;
243 string const & fileName() const { return filename; }
245 /** A transformed version of the file name, adequate for LaTeX
246 The path is stripped if no_path is true (default) */
247 string getLatexName(bool no_path = true) const {
248 return ChangeExtension(MakeLatexName(filename),
252 /// Change name of buffer. Updates "read-only" flag.
253 void fileName(string const & newfile);
255 /// Name of the document's parent
256 void setParentName(string const &);
258 /// Is buffer read-only?
259 bool isReadonly() const { return read_only; }
261 /// Set buffer read-only flag
262 void setReadonly(bool flag = true) {
263 if (read_only != flag) {
266 updateAllVisibleBufferRelatedPopups();
269 WarnReadonly(filename);
273 /// returns true if the buffer contains a LaTeX document
274 bool isLatex() const;
275 /// returns true if the buffer contains a LinuxDoc document
276 bool isLinuxDoc() const;
277 /// returns true if the buffer contains a DocBook document
278 bool isDocBook() const;
279 /// returns true if the buffer contains either a LinuxDoc or DocBook document
281 /// returns true if the buffer contains a Wed document
282 bool isLiterate() const;
285 void setPaperStuff();
287 /** Validate a buffer for LaTeX.
288 This validates the buffer, and returns a struct for use by
289 makeLaTeX and others. Its main use is to figure out what commands
290 and packages need to be included in the LaTeX file. It (should)
291 also check that the needed constructs are there (i.e. that the \refs
292 points to coresponding \labels). It should perhaps inset "error"
293 insets to help the user correct obvious mistakes.
295 void validate(LaTeXFeatures &) const;
298 string getIncludeonlyList(char delim = ',');
300 string getReferenceList(char delim = '|');
302 string getBibkeyList(char delim = '|');
304 /** This will clearly have to change later. Later we can have more
305 than one user per buffer. */
306 BufferView * getUser() const { return users; }
310 /// Does this mean that this is buffer local?
313 /// Does this mean that this is buffer local?
319 /** is a list of paragraphs.
321 LyXParagraph * paragraph;
326 /// where the temporaries go if we want them
332 /** While writing as LaTeX, tells whether we are
333 doing a 'nice' LaTeX file */
336 /// Used when typesetting to place errorboxes.
340 void linuxDocHandleFootnote(ostream & os,
341 LyXParagraph * & par, int const depth);
343 void DocBookHandleCaption(ostream & os, string & inner_tag,
344 int const depth, int desc_on,
345 LyXParagraph * & par);
347 void DocBookHandleFootnote(ostream & os,
348 LyXParagraph * & par, int const depth);
350 void sgmlOpenTag(ostream & os, int depth,
351 string const & latexname) const;
353 void sgmlCloseTag(ostream & os, int depth,
354 string const & latexname) const;
356 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
358 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
359 int desc_on, int const depth);
361 void SimpleDocBookOnePar(ostream &, string & extra,
362 LyXParagraph * par, int & desc_on,
366 void push_tag(ostream & os, char const * tag,
367 int & pos, char stack[5][3]);
370 void pop_tag(ostream & os, char const * tag,
371 int & pos, char stack[5][3]);
375 void RoffAsciiTable(ostream &, LyXParagraph * par);
379 mutable bool lyx_clean;
381 /// is autosave needed
382 mutable bool bak_clean;
384 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
385 We have to distinguish between TeX-runs executed in the original
386 directory (in which the original LyX-file resides) and TeX-runs
387 executed in a temporary directory. The first situation is valid
388 for a dvi-export, the latter one for printing or previewing. */
392 /// do we need to run weave/tangle
395 /// is regenerating .tex necessary
396 DEPCLEAN * dep_clean;
401 /// name of the file the buffer is associated with.
404 /// Format number of buffer
407 /** A list of views using this buffer.
408 Why not keep a list of the BufferViews that use this buffer?
410 At least then we don't have to do a lot of magic like:
411 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
412 of the buffers in the list of users to do a updateLayoutChoice.
419 void Buffer::setParentName(string const & name)
421 params.parentname = name;