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 /** 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.
98 /// Update window titles of all users
101 /// Reset autosave timers for all users
102 void resetAutosaveTimers();
104 /** Adds the BufferView to the users list.
105 Later this func will insert the BufferView into a real list,
106 not just setting a pointer.
108 void addUser(BufferView * u) { users = u; }
110 /** Removes the BufferView from the users list.
111 Since we only can have one at the moment, we just reset it.
113 void delUser(BufferView *){ users = 0; }
119 users->updateScrollbar();
122 /// Open and lock an updatable inset
123 void open_new_inset(UpdatableInset *);
126 void loadAutoSaveFile();
129 Returns false if it fails.
130 If par is given, the file is inserted. */
131 bool readFile(LyXLex &, LyXParagraph * par = 0);
133 /** Reads a file without header.
134 Returns false, if file is not completely read.
135 If par is given, the file is inserted. */
136 bool readLyXformat2(LyXLex &, LyXParagraph * par = 0);
138 /// Inserts a lyx file at cursor position. Returns false if it fails.
139 bool insertLyXFile(string const & filename);
141 /// Write file. Returns false if unsuccesful.
142 bool writeFile(string const &, bool);
145 void writeFileAscii(string const & , int);
148 void makeLaTeXFile(string const & filename,
149 string const & original_path,
150 bool nice, bool only_body = false);
165 void makeLinuxDocFile(string const & filename, int column);
167 void makeDocBookFile(string const & filename, int column);
169 /// returns the main language for the buffer (document)
170 string GetLanguage() const {
171 return params.language;
175 bool isLyxClean() const { return lyx_clean; }
177 /// changed Heinrich Bauer, 23/03/98
181 bool isNwClean() const { return nw_clean; }
184 bool isBakClean() const { return bak_clean; }
187 bool isDepClean(string const & name) const;
190 void markLyxClean() {
195 // if the .lyx file has been saved, we don't need an
200 /// changed Heinrich Bauer, 23/03/98
204 void markNwClean() { nw_clean = true; }
207 void markBakClean() { bak_clean = true; }
210 void markDepClean(string const & name);
216 void markNwDirty() { nw_clean = false; }
224 dvi_clean_tmpd = false;
225 dvi_clean_orgd = false;
228 DEPCLEAN * tmp = dep_clean;
236 string const & fileName() const { return filename; }
238 /// A transformed version of the file name, adequate for LaTeX
239 string getLatexName() const {
240 return ChangeExtension(MakeLatexName(filename), ".tex", true);
243 /// Change name of buffer. Updates "read-only" flag.
244 void fileName(string const & newfile);
246 /// Name of the document's parent
247 void setParentName(string const &);
249 /// Is buffer read-only?
250 bool isReadonly() { return read_only; }
252 /// Set buffer read-only flag
253 void setReadonly(bool flag = true)
255 if (read_only != flag) {
258 updateAllVisibleBufferRelatedPopups();
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();
281 void setOldPaperStuff();
284 /** Validate a buffer for LaTeX.
285 This validates the buffer, and returns a struct for use by
286 makeLaTeX and others. Its main use is to figure out what commands
287 and packages need to be included in the LaTeX file. It (should)
288 also check that the needed constructs are there (i.e. that the \refs
289 points to coresponding \labels). It should perhaps inset "error"
290 insets to help the user correct obvious mistakes.
292 void validate(LaTeXFeatures &); //the correct parameters to be
295 /** Insert an inset into the buffer
296 Insert inset into buffer, placing it in a layout of lout,
297 if no_table make sure that it doesn't end up in a table. */
298 void insertInset(Inset *, string const & lout = string(),
299 bool no_table = false);
302 void setCursorFromRow (int);
305 string getIncludeonlyList(char delim = ',');
307 string getReferenceList(char delim = '|');
309 string getBibkeyList(char delim = '|');
311 bool gotoLabel(string const &);
313 /// removes all autodeletable insets
314 bool removeAutoInsets();
316 /** This will clearly have to change later. Later we can have more
317 than one user per buffer. */
318 BufferView * getUser() const { return users; }
322 /// Does this mean that this is buffer local?
325 /// Does this mean that this is buffer local?
331 /** is a list of paragraphs.
333 LyXParagraph * paragraph;
335 /// per view not per buffer?
336 UpdatableInset * the_locking_inset;
341 /// where the temporaries go if we want them
347 /** While writing as LaTeX, tells whether we are
348 doing a 'nice' LaTeX file */
355 inline void InsetSleep();
358 inline void InsetWakeup();
369 void insertErrors(TeXErrors &);
372 void linuxDocHandleFootnote(ostream & os,
373 LyXParagraph * & par, int const depth);
375 void DocBookHandleCaption(ostream & os, string & inner_tag,
376 int const depth, int desc_on,
377 LyXParagraph * & par);
379 void DocBookHandleFootnote(ostream & os,
380 LyXParagraph * & par, int const depth);
382 void sgmlOpenTag(ostream & os, int depth,
383 string const & latexname) const;
385 void sgmlCloseTag(ostream & os, int depth,
386 string const & latexname) const;
388 void LinuxDocError(LyXParagraph * par, int pos, char const * message);
390 void SimpleLinuxDocOnePar(ostream & os, LyXParagraph * par,
391 int desc_on, int const depth);
393 void SimpleDocBookOnePar(string & file, string & extra,
394 LyXParagraph * par, int & desc_on,
398 void push_tag(ostream & os, char const * tag,
399 int & pos, char stack[5][3]);
402 void pop_tag(ostream & os, char const * tag,
403 int & pos, char stack[5][3]);
406 void RoffAsciiTable(ostream &, LyXParagraph * par);
411 /// is autosave needed
414 /** do we need to run LaTeX, changed 23/03/98, Heinrich Bauer
415 We have to distinguish between TeX-runs executed in the original
416 directory (in which the original LyX-file resides) and TeX-runs
417 executed in a temporary directory. The first situation is valid
418 for a dvi-export, the latter one for printing or previewing. */
422 /// do we need to run weave/tangle
425 /// is regenerating .tex necessary
426 DEPCLEAN * dep_clean;
431 /// name of the file the buffer is associated with.
434 /// Format number of buffer
437 /** A list of views using this buffer.
438 Why not keep a list of the BufferViews that use this buffer?
440 At least then we don't have to do a lot of magic like:
441 buffer->lyx_gui->bufferview->updateLayoutChoice. Just ask each
442 of the buffers in the list of users to do a updateLayoutChoice.
446 /// Used when typesetting to place errorboxes.
452 void Buffer::InsetSleep()
454 if (the_locking_inset && !inset_slept) {
455 the_locking_inset->GetCursorPos(slx, sly);
456 the_locking_inset->InsetUnlock();
463 void Buffer::InsetWakeup()
465 if (the_locking_inset && inset_slept) {
466 the_locking_inset->Edit(slx, sly);
473 void Buffer::setParentName(string const & name)
475 params.parentname = name;