]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
comment
[lyx.git] / src / Buffer.cpp
index 2caf701774cb5387551f997ec1e8da9c3a84e940..b38a394b48d164d40455db83d492d09a4acc5494 100644 (file)
@@ -76,7 +76,7 @@
 
 #include "graphics/Previews.h"
 
-#include "support/assert.h"
+#include "support/lassert.h"
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/ExceptionMessage.h"
@@ -115,7 +115,7 @@ namespace os = support::os;
 
 namespace {
 
-int const LYX_FORMAT = 328;
+int const LYX_FORMAT = 338; //Uwe: support for polytonic Greek
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -204,8 +204,16 @@ public:
        /// documents), needed for appropriate update of natbib labels.
        mutable support::FileNameList bibfilesCache_;
 
+       // FIXME The caching mechanism could be improved. At present, we have a 
+       // cache for each Buffer, that caches all the bibliography info for that
+       // Buffer. A more efficient solution would be to have a global cache per 
+       // file, and then to construct the Buffer's bibinfo from that.
        /// A cache for bibliography info
        mutable BiblioInfo bibinfo_;
+       /// whether the bibinfo cache is valid
+       bool bibinfoCacheValid_;
+       /// Cache of timestamps of .bib files
+       map<FileName, time_t> bibfileStatus_;
 
        mutable RefCache ref_cache_;
 
@@ -237,7 +245,7 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_)
        : parent_buffer(0), lyx_clean(true), bak_clean(true), unnamed(false),
          read_only(readonly_), filename(file), file_fully_loaded(false),
          toc_backend(&parent), macro_lock(false), timestamp_(0), 
-         checksum_(0), wa_(0), undo_(parent)
+         checksum_(0), wa_(0), undo_(parent), bibinfoCacheValid_(false)
 {
        temppath = createBufferTmpDir();
        lyxvc.setBuffer(&parent);
@@ -267,6 +275,13 @@ Buffer::~Buffer()
        // GuiView already destroyed
        gui_ = 0;
 
+
+       // loop over children
+       Impl::BufferPositionMap::iterator it = d->children_positions.begin();
+       Impl::BufferPositionMap::iterator end = d->children_positions.end();
+       for (; it != end; ++it)
+               theBufferList().releaseChild(this, const_cast<Buffer *>(it->first));
+
        // clear references to children in macro tables
        d->children_positions.clear();
        d->position_to_children.clear();
@@ -278,7 +293,7 @@ Buffer::~Buffer()
        }
 
        // Remove any previewed LaTeX snippets associated with this buffer.
-       graphics::Previews::get().removeLoader(*this);
+       thePreviews().removeLoader(*this);
 
        delete d;
 }
@@ -441,6 +456,7 @@ int Buffer::readHeader(Lexer & lex)
        params().branchlist().clear();
        params().preamble.erase();
        params().options.erase();
+       params().master.erase();
        params().float_placement.erase();
        params().paperwidth.erase();
        params().paperheight.erase();
@@ -452,6 +468,7 @@ int Buffer::readHeader(Lexer & lex)
        params().headsep.erase();
        params().footskip.erase();
        params().columnsep.erase();
+       params().fontsCJK.erase();
        params().listings_params.clear();
        params().clearLayoutModules();
        params().pdfoptions().clear();
@@ -550,6 +567,15 @@ bool Buffer::readDocument(Lexer & lex)
                }
        }
 
+       if (!params().master.empty()) {
+               FileName const master_file = makeAbsPath(params().master,
+                          onlyPath(absFileName()));
+               if (isLyXFilename(master_file.absFilename())) {
+                       Buffer * master = checkAndLoadLyXFile(master_file);
+                       d->parent_buffer = master;
+               }
+       }
+
        // read main text
        bool const res = text().read(*this, lex, errorList, &(d->inset));
 
@@ -972,7 +998,7 @@ bool Buffer::makeLaTeXFile(FileName const & fname,
        }
        catch (...) {
                lyxerr << "Caught some really weird exception..." << endl;
-               LyX::cref().exit(1);
+               lyx_exit(1);
        }
 
        ofs.close();
@@ -1329,6 +1355,14 @@ void Buffer::updateBibfilesCache() const
                                bibfiles.end());
                }
        }
+       // the bibinfo cache is now invalid
+       d->bibinfoCacheValid_ = false;
+}
+
+
+void Buffer::invalidateBibinfoCache() 
+{
+       d->bibinfoCacheValid_ = false;
 }
 
 
@@ -1359,27 +1393,27 @@ BiblioInfo const & Buffer::masterBibInfo() const
 
 
 BiblioInfo const & Buffer::localBibInfo() const
-{      
-       // cache the timestamp of the bibliography files.
-       static map<FileName, time_t> bibfileStatus;
-
-       support::FileNameList const & bibfilesCache = getBibfilesCache();
-       // compare the cached timestamps with the actual ones.
-       bool changed = false;
-       support::FileNameList::const_iterator ei = bibfilesCache.begin();
-       support::FileNameList::const_iterator en = bibfilesCache.end();
-       for (; ei != en; ++ ei) {
-               time_t lastw = ei->lastModified();
-               if (lastw != bibfileStatus[*ei]) {
-                       changed = true;
-                       bibfileStatus[*ei] = lastw;
-                       break;
+{
+       if (d->bibinfoCacheValid_) {
+               support::FileNameList const & bibfilesCache = getBibfilesCache();
+               // compare the cached timestamps with the actual ones.
+               support::FileNameList::const_iterator ei = bibfilesCache.begin();
+               support::FileNameList::const_iterator en = bibfilesCache.end();
+               for (; ei != en; ++ ei) {
+                       time_t lastw = ei->lastModified();
+                       if (lastw != d->bibfileStatus_[*ei]) {
+                               d->bibinfoCacheValid_ = false;
+                               d->bibfileStatus_[*ei] = lastw;
+                               break;
+                       }
                }
        }
 
-       if (changed) {
+       if (!d->bibinfoCacheValid_) {
+               d->bibinfo_.clear();
                for (InsetIterator it = inset_iterator_begin(inset()); it; ++it)
                        it->fillWithBibKeys(d->bibinfo_, it);
+               d->bibinfoCacheValid_ = true;
        }
        return d->bibinfo_;
 }
@@ -1418,6 +1452,19 @@ bool Buffer::dispatch(FuncRequest const & func, bool * result)
                        break;
                }
 
+               case LFUN_BRANCH_ACTIVATE:
+               case LFUN_BRANCH_DEACTIVATE: {
+                       BranchList & branchList = params().branchlist();
+                       docstring const branchName = func.argument();
+                       Branch * branch = branchList.find(branchName);
+                       if (!branch)
+                               LYXERR0("Branch " << branchName << " does not exist.");
+                       else 
+                               branch->setSelected(func.action == LFUN_BRANCH_ACTIVATE);
+                       if (result)
+                               *result = true;
+               }
+
                default:
                        dispatched = false;
        }
@@ -1634,6 +1681,12 @@ Buffer const * Buffer::masterBuffer() const
 }
 
 
+bool Buffer::isChild(Buffer * child) const
+{
+       return d->children_positions.find(child) != d->children_positions.end();
+}
+
+
 template<typename M>
 typename M::iterator greatest_below(M & m, typename M::key_type const & x)
 {
@@ -2334,11 +2387,12 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
 
        string const error_type = (format == "program")
                ? "Build" : bufferFormat();
+       ErrorList & error_list = d->errorLists[error_type];
        string const ext = formats.extension(format);
        FileName const tmp_result_file(changeExtension(filename, ext));
        bool const success = theConverters().convert(this, FileName(filename),
                tmp_result_file, FileName(absFileName()), backend_format, format,
-               errorList(error_type));
+               error_list);
        // Emit the signal to show the error list.
        if (format != backend_format)
                errors(error_type);