2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
8 * This file is Copyleft (C) 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
30 #include "BufferView.h"
32 #include "bufferparams.h"
35 #include "support/filetools.h"
42 extern void updateAllVisibleBufferRelatedPopups();
43 extern void WarnReadonly();
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 /// should be changed to work for a list.
93 /// Update window titles of all users
96 /// Reset autosave timers for all users
97 void resetAutosaveTimers();
99 /** Adds the BufferView to the users list.
100 Later this func will insert the BufferView into a real list,
101 not just setting a pointer.
103 void addUser(BufferView * u) { users = u; }
105 /** Removes the BufferView from the users list.
106 Since we only can have one at the moment, we just reset it.
108 void delUser(BufferView *){ users = 0; }
111 void update(signed char f);
117 users->updateScrollbar();
120 /// Open and lock an updatable inset
121 void open_new_inset(UpdatableInset *);
124 void loadAutoSaveFile();
127 Returns false if it fails.
128 If par is given, the file is inserted. */
129 bool readFile(LyXLex &, LyXParagraph * par = 0);
131 /** Reads a file without header.
132 Returns false, if file is not completely read.
133 If par is given, the file is inserted. */
134 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
136 /// Inserts a lyx file at cursor position. Returns false if it fails.
137 bool insertLyXFile(string const & filename);
139 /// Write file. Returns false if unsuccesful.
140 bool writeFile(string const &, bool);
143 void writeFileAscii(string const & , int);
146 void makeLaTeXFile(string const & filename,
147 string const & original_path,
148 bool nice, bool only_body = false);
163 void makeLinuxDocFile(string const & filename, int column);
165 void makeDocBookFile(string const & filename, int column);
167 /// returns the main language for the buffer (document)
168 string GetLanguage() const {
169 return params.language;
173 bool isLyxClean() const { return lyx_clean; }
175 /// changed Heinrich Bauer, 23/03/98
179 bool isNwClean() const { return nw_clean; }
182 bool isBakClean() const { return bak_clean; }
185 bool isDepClean(string const & name) const;
188 void markLyxClean() {
193 // if the .lyx file has been saved, we don't need an
198 /// changed Heinrich Bauer, 23/03/98
202 void markNwClean() { nw_clean = true; }
205 void markBakClean() { bak_clean = true; }
208 void markDepClean(string const & name);
214 void markNwDirty() { nw_clean = false; }
222 dvi_clean_tmpd = false;
223 dvi_clean_orgd = false;
226 DEPCLEAN * tmp = dep_clean;
234 string getFileName() const { return filename; }
236 /// A transformed version of the file name, adequate for LaTeX
237 string getLatexName() const {
238 return ChangeExtension(MakeLatexName(filename), ".tex", true);
241 /// Change name of buffer. Updates "read-only" flag.
242 void setFileName(string const & newfile);
244 /// Name of the document's parent
245 void setParentName(string const &);
247 /// Is buffer read-only?
248 bool isReadonly() { return read_only; }
250 /// Set buffer read-only flag
251 void setReadonly(bool flag = true)
253 if (read_only != flag) {
256 updateAllVisibleBufferRelatedPopups();
263 /// returns true if the buffer contains a LaTeX document
264 bool isLatex() const;
265 /// returns true if the buffer contains a LinuxDoc document
266 bool isLinuxDoc() const;
267 /// returns true if the buffer contains a DocBook document
268 bool isDocBook() const;
269 /// returns true if the buffer contains either a LinuxDoc or DocBook document
271 /// returns true if the buffer contains a Wed document
272 bool isLiterate() const;
275 void setPaperStuff();
279 void setOldPaperStuff();
282 /** Validate a buffer for LaTeX.
283 This validates the buffer, and returns a struct for use by
284 makeLaTeX and others. Its main use is to figure out what commands
285 and packages need to be included in the LaTeX file. It (should)
286 also check that the needed constructs are there (i.e. that the \refs
287 points to coresponding \labels). It should perhaps inset "error"
288 insets to help the user correct obvious mistakes.
290 void validate(LaTeXFeatures &); //the correct parameters to be
293 /** Insert an inset into the buffer
294 Insert inset into buffer, placing it in a layout of lout,
295 if no_table make sure that it doesn't end up in a table. */
296 void insertInset(Inset *, string const & lout = string(),
297 bool no_table = false);
300 void setCursorFromRow (int);
303 string getIncludeonlyList(char delim = ',');
305 string getReferenceList(char delim = '|');
307 string getBibkeyList(char delim = '|');
309 bool gotoLabel(string const &);
311 /// removes all autodeletable insets
312 bool removeAutoInsets();
314 /** This will clearly have to change later. Later we can have more
315 than one user per buffer. */
316 BufferView * getUser() const { return users; }
320 /// Does this mean that this is buffer local?
323 /// Does this mean that this is buffer local?
329 /** is a list of paragraphs.
331 LyXParagraph * paragraph;
333 /** This holds the mapping between buffer paragraphs and screen rows.
334 Should be moved to BufferView. (Asger)
339 UpdatableInset * the_locking_inset;
344 /// where the temporaries go if we want them
350 /** While writing as LaTeX, tells whether we are
351 doing a 'nice' LaTeX file */
358 inline void InsetSleep();
361 inline void InsetWakeup();
372 void insertErrors(TeXErrors &);
375 void linuxDocHandleFootnote(ostream & os,
376 LyXParagraph * & par, int const depth);
378 void DocBookHandleCaption(ostream & os, string & inner_tag,
379 int const depth, int desc_on,
380 LyXParagraph * &par);
382 void DocBookHandleFootnote(ostream & os,
383 LyXParagraph * & par, int const depth);
385 void sgmlOpenTag(ostream & os, int depth,
386 string const & latexname) const;
388 void sgmlCloseTag(ostream & os, int depth,
389 string const & latexname) const;
391 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
393 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
394 int desc_on, int const depth);
396 void SimpleDocBookOnePar(string & file, string & extra,
397 LyXParagraph * par, int & desc_on,
401 void push_tag(ostream & os, char const * tag,
402 int & pos, char stack[5][3]);
405 void pop_tag(ostream & os, char const * tag,
406 int & pos, char stack[5][3]);
409 void RoffAsciiTable(ostream &, LyXParagraph * par);
414 /// is autosave needed
417 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
418 We have to distinguish between TeX-runs executed in the original
419 directory (in which the original LyX-file resides) and TeX-runs
420 executed in a temporary directory. The first situation is valid
421 for a dvi-export, the latter one for printing or previewing. */
425 /// do we need to run weave/tangle
428 /// is regenerating .tex necessary
429 DEPCLEAN * dep_clean;
434 /// name of the file the buffer is associated with.
437 /// Format number of buffer
440 /** A list of views using this buffer.
441 Why not keep a list of the BufferViews that use this buffer?
443 At least then we don't have to do a lot of magic like:
444 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
445 of the buffers in the list of users to do a updateLayoutChoice.
450 friend class BufferList;
452 friend class BufferView;
454 /// Used when typesetting to place errorboxes.
460 void Buffer::InsetSleep()
462 if (the_locking_inset && !inset_slept) {
463 the_locking_inset->GetCursorPos(slx, sly);
464 the_locking_inset->InsetUnlock();
471 void Buffer::InsetWakeup()
473 if (the_locking_inset && inset_slept) {
474 the_locking_inset->Edit(slx, sly);
481 void Buffer::setParentName(string const & name)
483 params.parentname = name;