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"
43 extern void updateAllVisibleBufferRelatedPopups();
44 extern void WarnReadonly();
56 /** The buffer object.
57 The is is the buffer object. It contains all the informations about
58 a document loaded into LyX. I am not sure if the class is complete or
59 minimal, probably not.
63 /**@name Constructors and destructor */
66 Buffer(string const & file, LyXRC * lyxrc = 0, bool b = false);
75 /** save the buffer's parameters as user default
76 This function saves a file user_lyxdir/templates/defaults.lyx
77 which parameters are those of the current buffer. This file
78 is used as a default template when creating a new
79 file. Returns true on success.
81 bool saveParamsAsDefaults();
83 /** high-level interface to buffer functionality
84 This function parses a command string and executes it
86 void Dispatch(const string & command);
88 /// Maybe we know the function already by number...
89 void Dispatch(int ac, const string & argument);
91 /// should be changed to work for a list.
105 /// Update window titles of all users
108 /// Reset autosave timers for all users
109 void resetAutosaveTimers();
111 /** Adds the BufferView to the users list.
112 Later this func will insert the BufferView into a real list,
113 not just setting a pointer.
115 void addUser(BufferView * u) { users = u; }
117 /** Removes the BufferView from the users list.
118 Since we only can have one at the moment, we just reset it.
120 void delUser(BufferView *){ users = 0; }
124 void update(signed char f);
131 users->updateScrollbar();
134 /// Open and lock an updatable inset
135 void open_new_inset(UpdatableInset *);
138 void loadAutoSaveFile();
141 Returns false if it fails.
142 If par is given, the file is inserted. */
143 bool readFile(LyXLex &, LyXParagraph * par = 0);
145 /** Reads a file without header.
146 Returns false, if file is not completely read.
147 If par is given, the file is inserted. */
148 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
150 /// Inserts a lyx file at cursor position. Returns false if it fails.
151 bool insertLyXFile(string const & filename);
153 /// Write file. Returns false if unsuccesful.
154 bool writeFile(string const &, bool);
157 void writeFileAscii(string const & , int);
160 void makeLaTeXFile(string const & filename,
161 string const & original_path,
162 bool nice, bool only_body = false);
177 void makeLinuxDocFile(string const & filename, int column);
179 void makeDocBookFile(string const & filename, int column);
181 /// returns the main language for the buffer (document)
182 string GetLanguage() const {
183 return params.language;
187 bool isLyxClean() const { return lyx_clean; }
189 /// changed Heinrich Bauer, 23/03/98
193 bool isNwClean() const { return nw_clean; }
196 bool isBakClean() const { return bak_clean; }
199 bool isDepClean(string const & name) const;
202 void markLyxClean() {
207 // if the .lyx file has been saved, we don't need an
212 /// changed Heinrich Bauer, 23/03/98
216 void markNwClean() { nw_clean = true; }
219 void markBakClean() { bak_clean = true; }
222 void markDepClean(string const & name);
228 void markNwDirty() { nw_clean = false; }
236 dvi_clean_tmpd = false;
237 dvi_clean_orgd = false;
240 DEPCLEAN * tmp = dep_clean;
248 string const & fileName() const { return filename; }
250 /// A transformed version of the file name, adequate for LaTeX
251 string getLatexName() const {
252 return ChangeExtension(MakeLatexName(filename), ".tex", true);
255 /// Change name of buffer. Updates "read-only" flag.
256 void fileName(string const & newfile);
258 /// Name of the document's parent
259 void setParentName(string const &);
261 /// Is buffer read-only?
262 bool isReadonly() { return read_only; }
264 /// Set buffer read-only flag
265 void setReadonly(bool flag = true)
267 if (read_only != flag) {
270 updateAllVisibleBufferRelatedPopups();
277 /// returns true if the buffer contains a LaTeX document
278 bool isLatex() const;
279 /// returns true if the buffer contains a LinuxDoc document
280 bool isLinuxDoc() const;
281 /// returns true if the buffer contains a DocBook document
282 bool isDocBook() const;
283 /// returns true if the buffer contains either a LinuxDoc or DocBook document
285 /// returns true if the buffer contains a Wed document
286 bool isLiterate() const;
289 void setPaperStuff();
293 void setOldPaperStuff();
296 /** Validate a buffer for LaTeX.
297 This validates the buffer, and returns a struct for use by
298 makeLaTeX and others. Its main use is to figure out what commands
299 and packages need to be included in the LaTeX file. It (should)
300 also check that the needed constructs are there (i.e. that the \refs
301 points to coresponding \labels). It should perhaps inset "error"
302 insets to help the user correct obvious mistakes.
304 void validate(LaTeXFeatures &); //the correct parameters to be
307 /** Insert an inset into the buffer
308 Insert inset into buffer, placing it in a layout of lout,
309 if no_table make sure that it doesn't end up in a table. */
310 void insertInset(Inset *, string const & lout = string(),
311 bool no_table = false);
314 void setCursorFromRow (int);
317 string getIncludeonlyList(char delim = ',');
319 string getReferenceList(char delim = '|');
321 string getBibkeyList(char delim = '|');
323 bool gotoLabel(string const &);
325 /// removes all autodeletable insets
326 bool removeAutoInsets();
328 /** This will clearly have to change later. Later we can have more
329 than one user per buffer. */
330 BufferView * getUser() const { return users; }
334 /// Does this mean that this is buffer local?
337 /// Does this mean that this is buffer local?
343 /** is a list of paragraphs.
345 LyXParagraph * paragraph;
348 /** This holds the mapping between buffer paragraphs and screen rows.
349 Should be moved to BufferView. (Asger)
353 /// per view not per buffer?
354 UpdatableInset * the_locking_inset;
359 /// where the temporaries go if we want them
365 /** While writing as LaTeX, tells whether we are
366 doing a 'nice' LaTeX file */
373 inline void InsetSleep();
376 inline void InsetWakeup();
387 void insertErrors(TeXErrors &);
390 void linuxDocHandleFootnote(ostream & os,
391 LyXParagraph * & par, int const depth);
393 void DocBookHandleCaption(ostream & os, string & inner_tag,
394 int const depth, int desc_on,
395 LyXParagraph * & par);
397 void DocBookHandleFootnote(ostream & os,
398 LyXParagraph * & par, int const depth);
400 void sgmlOpenTag(ostream & os, int depth,
401 string const & latexname) const;
403 void sgmlCloseTag(ostream & os, int depth,
404 string const & latexname) const;
406 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
408 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
409 int desc_on, int const depth);
411 void SimpleDocBookOnePar(string & file, string & extra,
412 LyXParagraph * par, int & desc_on,
416 void push_tag(ostream & os, char const * tag,
417 int & pos, char stack[5][3]);
420 void pop_tag(ostream & os, char const * tag,
421 int & pos, char stack[5][3]);
424 void RoffAsciiTable(ostream &, LyXParagraph * par);
429 /// is autosave needed
432 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
433 We have to distinguish between TeX-runs executed in the original
434 directory (in which the original LyX-file resides) and TeX-runs
435 executed in a temporary directory. The first situation is valid
436 for a dvi-export, the latter one for printing or previewing. */
440 /// do we need to run weave/tangle
443 /// is regenerating .tex necessary
444 DEPCLEAN * dep_clean;
449 /// name of the file the buffer is associated with.
452 /// Format number of buffer
455 /** A list of views using this buffer.
456 Why not keep a list of the BufferViews that use this buffer?
458 At least then we don't have to do a lot of magic like:
459 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
460 of the buffers in the list of users to do a updateLayoutChoice.
464 /// Used when typesetting to place errorboxes.
470 void Buffer::InsetSleep()
472 if (the_locking_inset && !inset_slept) {
473 the_locking_inset->GetCursorPos(slx, sly);
474 the_locking_inset->InsetUnlock();
481 void Buffer::InsetWakeup()
483 if (the_locking_inset && inset_slept) {
484 the_locking_inset->Edit(slx, sly);
491 void Buffer::setParentName(string const & name)
493 params.parentname = name;