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"
40 extern void updateAllVisibleBufferRelatedPopups();
41 extern void WarnReadonly();
53 /** The buffer object.
54 The is is the buffer object. It contains all the informations about
55 a document loaded into LyX. I am not sure if the class is complete or
56 minimal, probably not.
60 /**@name Constructors and destructor */
63 Buffer(string const & file, LyXRC * lyxrc = 0, bool b= false);
72 /** save the buffer's parameters as user default
73 This function saves a file user_lyxdir/templates/defaults.lyx
74 which parameters are those of the current buffer. This file
75 is used as a default template when creating a new
76 file. Returns true on success.
78 bool saveParamsAsDefaults();
80 /// should be changed to work for a list.
91 /// Update window titles of all users
94 /// Reset autosave timers for all users
95 void resetAutosaveTimers();
97 /** Adds the BufferView to the users list.
98 Later this func will insert the BufferView into a real list,
99 not just setting a pointer.
101 void addUser(BufferView *u) { users = u; }
103 /** Removes the BufferView from the users list.
104 Since we only can have one at the moment, we just reset it.
106 void delUser(BufferView *){ users = 0; }
109 void update(signed char f);
115 users->updateScrollbar(); }
117 /// Open and lock an updatable inset
118 void open_new_inset(UpdatableInset*);
121 void loadAutoSaveFile();
124 Returns false if it fails.
125 If par is given, the file is inserted. */
126 bool readFile(LyXLex &, LyXParagraph *par = 0);
128 /** Reads a file without header.
129 Returns false, if file is not completely read.
130 If par is given, the file is inserted. */
131 bool readLyXformat2(LyXLex &,LyXParagraph *par = 0);
133 /// Inserts a lyx file at cursor position. Returns false if it fails.
134 bool insertLyXFile(string const & filename);
136 /// Write file. Returns false if unsuccesful.
137 bool writeFile(string const &, bool);
140 void writeFileAscii(string const & , int);
143 void makeLaTeXFile(string const & filename,
144 string const & original_path,
145 bool nice, bool only_body = false);
160 void makeLinuxDocFile(string const & filename, int column);
162 void makeDocBookFile(string const & filename, int column);
164 /// returns the main language for the buffer (document)
165 string GetLanguage() const {
166 return params.language;
170 bool isLyxClean() const { return lyx_clean; }
172 /// changed Heinrich Bauer, 23/03/98
176 bool isNwClean() const { return nw_clean; }
179 bool isBakClean() const { return bak_clean; }
182 bool isDepClean(string const & name) const;
185 void markLyxClean() {
190 // if the .lyx file has been saved, we don't need an
195 /// changed Heinrich Bauer, 23/03/98
199 void markNwClean() { nw_clean = true; }
202 void markBakClean() { bak_clean = true; }
205 void markDepClean(string const & name);
211 void markNwDirty() { nw_clean = false; }
219 dvi_clean_tmpd = false;
220 dvi_clean_orgd = false;
223 DEPCLEAN* tmp = dep_clean;
231 string getFileName() const { return filename; }
233 /// Change name of buffer. Updates "read-only" flag.
234 void setFileName(string const & newfile);
236 /// Name of the document's parent
237 void setParentName(string const &);
239 /// Is buffer read-only?
240 bool isReadonly() { return read_only; }
242 /// Set buffer read-only flag
243 void setReadonly(bool flag = true)
245 if (read_only != flag) {
248 updateAllVisibleBufferRelatedPopups();
255 /// returns true if the buffer contains a LaTeX document
257 /// returns true if the buffer contains a LinuxDoc document
259 /// returns true if the buffer contains a DocBook document
261 /// returns true if the buffer contains either a LinuxDoc or DocBook document
263 /// returns true if the buffer contains a Wed document
267 void setPaperStuff();
270 void setOldPaperStuff();
272 /** Validate a buffer for LaTeX.
273 This validates the buffer, and returns a struct for use by
274 makeLaTeX and others. Its main use is to figure out what commands
275 and packages need to be included in the LaTeX file. It (should)
276 also check that the needed constructs are there (i.e. that the \refs
277 points to coresponding \labels). It should perhaps inset "error"
278 insets to help the user correct obvious mistakes.
280 void validate(LaTeXFeatures&); //the correct parameters to be
283 /** Insert an inset into the buffer
284 Insert inset into buffer, placing it in a layout of lout,
285 if no_table make sure that it doesn't end up in a table. */
286 void insertInset(Inset *, string const &lout=string(),
287 bool no_table = false);
290 void setCursorFromRow (int);
293 string getIncludeonlyList(char delim=',');
295 string getReferenceList(char delim='|');
297 string getBibkeyList(char delim='|');
299 bool gotoLabel(const string&);
301 /// removes all autodeletable insets
302 bool removeAutoInsets();
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;
323 /** This holds the mapping between buffer paragraphs and screen rows.
324 Should be moved to BufferView. (Asger)
329 UpdatableInset* the_locking_inset;
334 /// where the temporaries go if we want them
340 /** While writing as LaTeX, tells whether we are
341 doing a 'nice' LaTeX file */
348 inline void InsetSleep();
351 inline void InsetWakeup();
362 void insertErrors(TeXErrors &);
365 void linuxDocHandleFootnote(FILE *file,LyXParagraph* &par, int const depth);
367 void DocBookHandleCaption(FILE *file, string &inner_tag,
368 int const depth, int desc_on,
371 void DocBookHandleFootnote(FILE *file,LyXParagraph* &par, int const depth);
373 void sgmlOpenTag(FILE * file,int depth,string & latexname);
375 void sgmlCloseTag(FILE * file,int depth,string & latexname);
377 void LinuxDocError(LyXParagraph *par, int pos, char const *message);
379 void SimpleLinuxDocOnePar(FILE *file, LyXParagraph *par, int desc_on, int const depth);
381 void SimpleDocBookOnePar(string &file, string &extra, LyXParagraph *par, int & desc_on, int const depth);
384 void push_tag(FILE *file, char const *tag, int& pos, char stack[5][3]);
387 void pop_tag(FILE *file, char const * tag, int& pos, char stack[5][3]);
390 void RoffAsciiTable(FILE *file, LyXParagraph *par);
395 /// is autosave needed
398 /// do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
399 /// We have to distinguish between TeX-runs executed in the original
400 /// directory (in which the original LyX-file resides) and TeX-runs
401 /// executed in a temporary directory. The first situation is valid
402 /// for a dvi-export, the latter one for printing or previewing.
406 /// do we need to run weave/tangle
409 /// is regenerating .tex necessary
415 /// name of the file the buffer is associated with.
418 /// Format number of buffer
421 /** A list of views using this buffer.
422 Why not keep a list of the BufferViews that use this buffer?
424 At least then we don't have to do a lot of magic like:
425 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
426 of the buffers in the list of users to do a updateLayoutChoice.
431 friend class BufferList;
433 friend class BufferView;
435 /// Used when typesetting to place errorboxes.
441 void Buffer::InsetSleep()
443 if (the_locking_inset && !inset_slept) {
444 the_locking_inset->GetCursorPos(slx, sly);
445 the_locking_inset->InsetUnlock();
452 void Buffer::InsetWakeup()
454 if (the_locking_inset && inset_slept) {
455 the_locking_inset->Edit(slx, sly);
462 void Buffer::setParentName(string const &name)
464 params.parentname = name;