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
100 /// Reset autosave timers for all users
101 void resetAutosaveTimers();
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 /// Write file. Returns false if unsuccesful.
135 bool writeFile(string const &, bool);
138 void writeFileAscii(string const & , int);
141 void makeLaTeXFile(string const & filename,
142 string const & original_path,
143 bool nice, bool only_body = false);
158 void makeLinuxDocFile(string const & filename, int column);
160 void makeDocBookFile(string const & filename, int column);
162 /// returns the main language for the buffer (document)
163 string GetLanguage() const {
164 return params.language;
168 bool isLyxClean() const { return lyx_clean; }
170 /// changed Heinrich Bauer, 23/03/98
171 bool isDviClean() const;
174 bool isNwClean() const { return nw_clean; }
177 bool isBakClean() const { return bak_clean; }
180 bool isDepClean(string const & name) const;
183 void markLyxClean() {
188 // if the .lyx file has been saved, we don't need an
193 /// changed Heinrich Bauer, 23/03/98
197 void markNwClean() { nw_clean = true; }
200 void markBakClean() { bak_clean = true; }
203 void markDepClean(string const & name);
209 void markNwDirty() { nw_clean = false; }
217 dvi_clean_tmpd = false;
218 dvi_clean_orgd = false;
221 DEPCLEAN * tmp = dep_clean;
229 string const & fileName() const { return filename; }
231 /** A transformed version of the file name, adequate for LaTeX
232 The path is stripped if no_path is true (default) */
233 string getLatexName(bool no_path = true) const {
234 return ChangeExtension(MakeLatexName(filename),
238 /// Change name of buffer. Updates "read-only" flag.
239 void fileName(string const & newfile);
241 /// Name of the document's parent
242 void setParentName(string const &);
244 /// Is buffer read-only?
245 bool isReadonly() const { return read_only; }
247 /// Set buffer read-only flag
248 void setReadonly(bool flag = true) {
249 if (read_only != flag) {
252 updateAllVisibleBufferRelatedPopups();
255 WarnReadonly(filename);
259 /// returns true if the buffer contains a LaTeX document
260 bool isLatex() const;
261 /// returns true if the buffer contains a LinuxDoc document
262 bool isLinuxDoc() const;
263 /// returns true if the buffer contains a DocBook document
264 bool isDocBook() const;
265 /// returns true if the buffer contains either a LinuxDoc or DocBook document
267 /// returns true if the buffer contains a Wed document
268 bool isLiterate() const;
271 void setPaperStuff();
273 /** Validate a buffer for LaTeX.
274 This validates the buffer, and returns a struct for use by
275 makeLaTeX and others. Its main use is to figure out what commands
276 and packages need to be included in the LaTeX file. It (should)
277 also check that the needed constructs are there (i.e. that the \refs
278 points to coresponding \labels). It should perhaps inset "error"
279 insets to help the user correct obvious mistakes.
281 void validate(LaTeXFeatures &) const;
284 string getIncludeonlyList(char delim = ',');
286 string getReferenceList(char delim = '|');
288 string getBibkeyList(char delim = '|');
290 /** This will clearly have to change later. Later we can have more
291 than one user per buffer. */
292 BufferView * getUser() const { return users; }
296 /// Does this mean that this is buffer local?
299 /// Does this mean that this is buffer local?
305 /** is a list of paragraphs.
307 LyXParagraph * paragraph;
312 /// where the temporaries go if we want them
318 /** While writing as LaTeX, tells whether we are
319 doing a 'nice' LaTeX file */
322 /// Used when typesetting to place errorboxes.
326 void linuxDocHandleFootnote(ostream & os,
327 LyXParagraph * & par, int const depth);
329 void DocBookHandleCaption(ostream & os, string & inner_tag,
330 int const depth, int desc_on,
331 LyXParagraph * & par);
333 void DocBookHandleFootnote(ostream & os,
334 LyXParagraph * & par, int const depth);
336 void sgmlOpenTag(ostream & os, int depth,
337 string const & latexname) const;
339 void sgmlCloseTag(ostream & os, int depth,
340 string const & latexname) const;
342 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
344 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
345 int desc_on, int const depth);
347 void SimpleDocBookOnePar(string & file, string & extra,
348 LyXParagraph * par, int & desc_on,
352 void push_tag(ostream & os, char const * tag,
353 int & pos, char stack[5][3]);
356 void pop_tag(ostream & os, char const * tag,
357 int & pos, char stack[5][3]);
360 void RoffAsciiTable(ostream &, LyXParagraph * par);
365 /// is autosave needed
368 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
369 We have to distinguish between TeX-runs executed in the original
370 directory (in which the original LyX-file resides) and TeX-runs
371 executed in a temporary directory. The first situation is valid
372 for a dvi-export, the latter one for printing or previewing. */
376 /// do we need to run weave/tangle
379 /// is regenerating .tex necessary
380 DEPCLEAN * dep_clean;
385 /// name of the file the buffer is associated with.
388 /// Format number of buffer
391 /** A list of views using this buffer.
392 Why not keep a list of the BufferViews that use this buffer?
394 At least then we don't have to do a lot of magic like:
395 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
396 of the buffers in the list of users to do a updateLayoutChoice.
403 void Buffer::setParentName(string const & name)
405 params.parentname = name;