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, LyXRC * lyxrc = 0, 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);
135 Takes care of auto-save files and backup file if requested.
136 Returns true if the save is successful, false otherwise.
138 bool save(bool makeBackup) const;
140 /// Write file. Returns false if unsuccesful.
141 bool writeFile(string const &, bool) const;
144 void writeFileAscii(string const & , int);
147 void makeLaTeXFile(string const & filename,
148 string const & original_path,
149 bool nice, bool only_body = false);
164 void makeLinuxDocFile(string const & filename, int column);
166 void makeDocBookFile(string const & filename, int column);
168 /// returns the main language for the buffer (document)
169 string GetLanguage() const {
170 return params.language;
174 bool isLyxClean() const { return lyx_clean; }
176 /// changed Heinrich Bauer, 23/03/98
177 bool isDviClean() const;
180 bool isNwClean() const { return nw_clean; }
183 bool isBakClean() const { return bak_clean; }
186 bool isDepClean(string const & name) const;
189 void markLyxClean() const {
194 // if the .lyx file has been saved, we don't need an
199 /// changed Heinrich Bauer, 23/03/98
203 void markNwClean() { nw_clean = true; }
206 void markBakClean() { bak_clean = true; }
209 void markDepClean(string const & name);
215 void markNwDirty() { nw_clean = false; }
223 dvi_clean_tmpd = false;
224 dvi_clean_orgd = false;
227 DEPCLEAN * tmp = dep_clean;
235 string const & fileName() const { return filename; }
237 /** A transformed version of the file name, adequate for LaTeX
238 The path is stripped if no_path is true (default) */
239 string getLatexName(bool no_path = true) const {
240 return ChangeExtension(MakeLatexName(filename),
244 /// Change name of buffer. Updates "read-only" flag.
245 void fileName(string const & newfile);
247 /// Name of the document's parent
248 void setParentName(string const &);
250 /// Is buffer read-only?
251 bool isReadonly() const { return read_only; }
253 /// Set buffer read-only flag
254 void setReadonly(bool flag = true) {
255 if (read_only != flag) {
258 updateAllVisibleBufferRelatedPopups();
261 WarnReadonly(filename);
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 or DocBook document
273 /// returns true if the buffer contains a Wed document
274 bool isLiterate() const;
277 void setPaperStuff();
279 /** Validate a buffer for LaTeX.
280 This validates the buffer, and returns a struct for use by
281 makeLaTeX and others. Its main use is to figure out what commands
282 and packages need to be included in the LaTeX file. It (should)
283 also check that the needed constructs are there (i.e. that the \refs
284 points to coresponding \labels). It should perhaps inset "error"
285 insets to help the user correct obvious mistakes.
287 void validate(LaTeXFeatures &) const;
290 string getIncludeonlyList(char delim = ',');
292 string getReferenceList(char delim = '|');
294 string getBibkeyList(char delim = '|');
296 /** This will clearly have to change later. Later we can have more
297 than one user per buffer. */
298 BufferView * getUser() const { return users; }
302 /// Does this mean that this is buffer local?
305 /// Does this mean that this is buffer local?
311 /** is a list of paragraphs.
313 LyXParagraph * paragraph;
318 /// where the temporaries go if we want them
324 /** While writing as LaTeX, tells whether we are
325 doing a 'nice' LaTeX file */
328 /// Used when typesetting to place errorboxes.
332 void linuxDocHandleFootnote(ostream & os,
333 LyXParagraph * & par, int const depth);
335 void DocBookHandleCaption(ostream & os, string & inner_tag,
336 int const depth, int desc_on,
337 LyXParagraph * & par);
339 void DocBookHandleFootnote(ostream & os,
340 LyXParagraph * & par, int const depth);
342 void sgmlOpenTag(ostream & os, int depth,
343 string const & latexname) const;
345 void sgmlCloseTag(ostream & os, int depth,
346 string const & latexname) const;
348 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
350 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
351 int desc_on, int const depth);
353 void SimpleDocBookOnePar(string & file, string & extra,
354 LyXParagraph * par, int & desc_on,
358 void push_tag(ostream & os, char const * tag,
359 int & pos, char stack[5][3]);
362 void pop_tag(ostream & os, char const * tag,
363 int & pos, char stack[5][3]);
367 void RoffAsciiTable(ostream &, LyXParagraph * par);
371 mutable bool lyx_clean;
373 /// is autosave needed
374 mutable bool bak_clean;
376 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
377 We have to distinguish between TeX-runs executed in the original
378 directory (in which the original LyX-file resides) and TeX-runs
379 executed in a temporary directory. The first situation is valid
380 for a dvi-export, the latter one for printing or previewing. */
384 /// do we need to run weave/tangle
387 /// is regenerating .tex necessary
388 DEPCLEAN * dep_clean;
393 /// name of the file the buffer is associated with.
396 /// Format number of buffer
399 /** A list of views using this buffer.
400 Why not keep a list of the BufferViews that use this buffer?
402 At least then we don't have to do a lot of magic like:
403 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
404 of the buffers in the list of users to do a updateLayoutChoice.
411 void Buffer::setParentName(string const & name)
413 params.parentname = name;