]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Micro-optimization.
[lyx.git] / src / Buffer.cpp
index c3fe5e2b32d7122f78d9341f11b162b117fff8d8..4214e31384ae3e9307630b47db4c476982db496a 100644 (file)
@@ -42,7 +42,6 @@
 #include "Lexer.h"
 #include "LyXAction.h"
 #include "LyX.h"
-#include "LyXFunc.h"
 #include "LyXRC.h"
 #include "LyXVC.h"
 #include "output_docbook.h"
@@ -127,7 +126,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 376; // jspitzm: support for unincluded file maintenance
+int const LYX_FORMAT = 378; // ps: rev insetinfo
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -147,7 +146,7 @@ class BufferSet : public std::set<Buffer const *> {};
 class Buffer::Impl
 {
 public:
-       Impl(Buffer & parent, FileName const & file, bool readonly, Buffer const * cloned_buffer);
+       Impl(Buffer * owner, FileName const & file, bool readonly, Buffer const * cloned_buffer);
 
        ~Impl()
        {
@@ -158,6 +157,25 @@ public:
                delete inset;
        }
 
+       /// search for macro in local (buffer) table or in children
+       MacroData const * getBufferMacro(docstring const & name,
+               DocIterator const & pos) const;
+
+       /// Update macro table starting with position of it \param it in some
+       /// text inset.
+       void updateMacros(DocIterator & it, DocIterator & scope);
+       ///
+       void setLabel(ParIterator & it, UpdateType utype) const;
+       ///
+       void collectRelatives(BufferSet & bufs) const;
+
+       /** If we have branches that use the file suffix
+           feature, return the file name with suffix appended.
+       */
+       support::FileName exportFileName() const;
+
+       Buffer * owner_;
+
        BufferParams params;
        LyXVC lyxvc;
        FileName temppath;
@@ -197,7 +215,8 @@ public:
        /// map from the macro name to the position map,
        /// which maps the macro definition position to the scope and the MacroData.
        NamePositionScopeMacroMap macros;
-       bool macro_lock;
+       /// This seem to change the way Buffer::getMacro() works
+       mutable bool macro_lock;
 
        /// positions of child buffers in the buffer
        typedef map<Buffer const * const, DocIterator> BufferPositionMap;
@@ -218,6 +237,8 @@ public:
 
        ///
        frontend::WorkAreaManager * wa_;
+       ///
+       frontend::GuiBufferDelegate * gui_;
 
        ///
        Undo undo_;
@@ -292,17 +313,17 @@ static FileName createBufferTmpDir()
 }
 
 
-Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_,
+Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
        Buffer const * cloned_buffer)
-       : lyx_clean(true), bak_clean(true), unnamed(false),
+       : owner_(owner), 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), bibinfo_cache_valid_(false),
+         toc_backend(owner), macro_lock(false), timestamp_(0),
+         checksum_(0), wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
          cloned_buffer_(cloned_buffer), parent_buffer(0)
 {
        if (!cloned_buffer_) {
                temppath = createBufferTmpDir();
-               lyxvc.setBuffer(&parent);
+               lyxvc.setBuffer(owner_);
                if (use_gui)
                        wa_ = new frontend::WorkAreaManager;
                return;
@@ -318,7 +339,7 @@ Buffer::Impl::Impl(Buffer & parent, FileName const & file, bool readonly_,
 
 
 Buffer::Buffer(string const & file, bool readonly, Buffer const * cloned_buffer)
-       : d(new Impl(*this, FileName(file), readonly, cloned_buffer)), gui_(0)
+       : d(new Impl(this, FileName(file), readonly, cloned_buffer))
 {
        LYXERR(Debug::INFO, "Buffer::Buffer()");
        if (cloned_buffer) {
@@ -344,7 +365,7 @@ Buffer::~Buffer()
        // saved properly, before it goes into the void.
 
        // GuiView already destroyed
-       gui_ = 0;
+       d->gui_ = 0;
 
        if (isInternal()) {
                // No need to do additional cleanups for internal buffer.
@@ -522,23 +543,23 @@ void Buffer::setChild(DocIterator const & dit, Buffer * child)
 string Buffer::latexName(bool const no_path) const
 {
        FileName latex_name =
-               makeLatexName(exportFileName());
+               makeLatexName(d->exportFileName());
        return no_path ? latex_name.onlyFileName()
                : latex_name.absFilename();
 }
 
 
-FileName Buffer::exportFileName() const
+FileName Buffer::Impl::exportFileName() const
 {
        docstring const branch_suffix =
-               params().branchlist().getFilenameSuffix();
+               params.branchlist().getFilenameSuffix();
        if (branch_suffix.empty())
-               return fileName();
+               return filename;
 
-       string const name = fileName().onlyFileNameWithoutExt()
+       string const name = filename.onlyFileNameWithoutExt()
                + to_utf8(branch_suffix);
-       FileName res(fileName().onlyPath().absFilename() + "/" + name);
-       res.changeExtension(fileName().extension());
+       FileName res(filename.onlyPath().absFilename() + "/" + name);
+       res.changeExtension(filename.extension());
 
        return res;
 }
@@ -909,7 +930,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                        << ' ' << quoteName(lyx2lyx.toFilesystemEncoding())
                        << " -t " << convert<string>(LYX_FORMAT)
                        << " -o " << quoteName(tmpfile.toFilesystemEncoding())
-                       << ' ' << quoteName(filename.toFilesystemEncoding());
+                       << ' ' << quoteName(filename.toSafeFilesystemEncoding());
                string const command_str = command.str();
 
                LYXERR(Debug::INFO, "Running '" << command_str << '\'');
@@ -942,6 +963,7 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
                             bformat(_("%1$s ended unexpectedly, which means"
                                                    " that it is probably corrupted."),
                                       from_utf8(filename.absFilename())));
+               return failure;
        }
 
        d->file_fully_loaded = true;
@@ -949,14 +971,12 @@ Buffer::ReadStatus Buffer::readFile(Lexer & lex, FileName const & filename,
 }
 
 
-// Should probably be moved to somewhere else: BufferView? LyXView?
+// Should probably be moved to somewhere else: BufferView? GuiView?
 bool Buffer::save() const
 {
        // We don't need autosaves in the immediate future. (Asger)
        resetAutosaveTimers();
 
-       string const encodedFilename = d->filename.toFilesystemEncoding();
-
        FileName backupName;
        bool madeBackup = false;
 
@@ -1014,11 +1034,13 @@ bool Buffer::writeFile(FileName const & fname) const
                makeDisplayPath(fname.absFilename()));
        message(str);
 
+       string const encoded_fname = fname.toSafeFilesystemEncoding(os::CREATE);
+
        if (params().compressed) {
-               gz::ogzstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+               gz::ogzstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
                retval = ofs && write(ofs);
        } else {
-               ofstream ofs(fname.toFilesystemEncoding().c_str(), ios::out|ios::trunc);
+               ofstream ofs(encoded_fname.c_str(), ios::out|ios::trunc);
                retval = ofs && write(ofs);
        }
 
@@ -1286,14 +1308,41 @@ void Buffer::writeLaTeXSource(odocstream & os,
                if (!original_path.empty()) {
                        // FIXME UNICODE
                        // We don't know the encoding of inputpath
-                       docstring const inputpath = from_utf8(latex_path(original_path));
-                       os << "\\makeatletter\n"
-                          << "\\def\\input@path{{"
-                          << inputpath << "/}}\n"
-                          << "\\makeatother\n";
-                       d->texrow.newline();
-                       d->texrow.newline();
-                       d->texrow.newline();
+                       docstring const inputpath = from_utf8(support::latex_path(original_path));
+                       docstring uncodable_glyphs;
+                       Encoding const * const enc = runparams.encoding;
+                       if (enc) {
+                               for (size_t n = 0; n < inputpath.size(); ++n) {
+                                       docstring const glyph =
+                                               docstring(1, inputpath[n]);
+                                       if (enc->latexChar(inputpath[n], true) != glyph) {
+                                               LYXERR0("Uncodable character '"
+                                                       << glyph
+                                                       << "' in input path!");
+                                               uncodable_glyphs += glyph;
+                                       }
+                               }
+                       }
+
+                       // warn user if we found uncodable glyphs.
+                       if (!uncodable_glyphs.empty()) {
+                               frontend::Alert::warning(_("Uncodable character in file path"),
+                                               support::bformat(_("The path of your document\n"
+                                                 "(%1$s)\n"
+                                                 "contains glyphs that are unknown in the\n"
+                                                 "current document encoding (namely %2$s).\n"
+                                                 "This will likely result in incomplete output.\n\n"
+                                                 "Chose an appropriate document encoding (such as utf8)\n"
+                                                 "or change the file path name."), inputpath, uncodable_glyphs));
+                       } else {
+                               os << "\\makeatletter\n"
+                                  << "\\def\\input@path{{"
+                                  << inputpath << "/}}\n"
+                                  << "\\makeatother\n";
+                               d->texrow.newline();
+                               d->texrow.newline();
+                               d->texrow.newline();
+                       }
                }
 
                // get parent macros (if this buffer has a parent) which will be
@@ -1318,8 +1367,11 @@ void Buffer::writeLaTeXSource(odocstream & os,
                // output the parent macros
                MacroSet::iterator it = parentMacros.begin();
                MacroSet::iterator end = parentMacros.end();
-               for (; it != end; ++it)
-                       (*it)->write(os, true);
+               for (; it != end; ++it) {
+                       int num_lines = (*it)->write(os, true);
+                       d->texrow.newlines(num_lines);
+               }
+               
        } // output_preamble
 
        d->texrow.start(paragraphs().begin()->id(), 0);
@@ -1498,7 +1550,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
 {
        LaTeXFeatures features(*this, params(), runparams);
        validate(features);
-       updateLabels(UpdateMaster, OutputUpdate);
+       updateBuffer(UpdateMaster, OutputUpdate);
        checkBibInfoCache();
        d->bibinfo_.makeCitationLabels(*this);
        updateMacros();
@@ -1555,6 +1607,7 @@ int Buffer::runChktex()
        OutputParams runparams(&params().encoding());
        runparams.flavor = OutputParams::LATEX;
        runparams.nice = false;
+       runparams.linelen = lyxrc.plaintext_linelen;
        makeLaTeXFile(FileName(name), org_path, runparams);
 
        TeXErrors terr;
@@ -1841,7 +1894,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
 
        case LFUN_BUFFER_EXPORT: {
                bool success = doExport(argument, false, false);
-               dr.setError(success);
+               dr.setError(!success);
                if (!success)
                        dr.setMessage(bformat(_("Error exporting to format: %1$s."), 
                                              func.argument()));
@@ -2149,6 +2202,30 @@ bool Buffer::isMultiLingual() const
 }
 
 
+std::set<Language const *> Buffer::getLanguages() const
+{
+       std::set<Language const *> languages;
+       getLanguages(languages);
+       return languages;
+}
+
+
+void Buffer::getLanguages(std::set<Language const *> & languages) const
+{
+       ParConstIterator end = par_iterator_end();
+       // add the buffer language, even if it's not actively used
+       languages.insert(language());
+       // iterate over the paragraphs
+       for (ParConstIterator it = par_iterator_begin(); it != end; ++it)
+               it->getLanguages(languages);
+       // also children
+       std::vector<Buffer *> clist = getChildren();
+       for (vector<Buffer *>::const_iterator cit = clist.begin();
+            cit != clist.end(); ++cit)
+               (*cit)->getLanguages(languages);
+}
+
+
 DocIterator Buffer::getParFromID(int const id) const
 {
        Buffer * buf = const_cast<Buffer *>(this);
@@ -2326,15 +2403,15 @@ Buffer const * Buffer::parent() const
 }
 
 
-void Buffer::collectRelatives(BufferSet & bufs) const
+void Buffer::Impl::collectRelatives(BufferSet & bufs) const
 {
-       bufs.insert(this);
+       bufs.insert(owner_);
        if (parent())
-               parent()->collectRelatives(bufs);
+               parent()->d->collectRelatives(bufs);
 
        // loop over children
-       Impl::BufferPositionMap::iterator it = d->children_positions.begin();
-       Impl::BufferPositionMap::iterator end = d->children_positions.end();
+       BufferPositionMap::const_iterator it = children_positions.begin();
+       BufferPositionMap::const_iterator end = children_positions.end();
        for (; it != end; ++it)
                bufs.insert(const_cast<Buffer *>(it->first));
 }
@@ -2343,7 +2420,7 @@ void Buffer::collectRelatives(BufferSet & bufs) const
 std::vector<Buffer const *> Buffer::allRelatives() const
 {
        BufferSet bufs;
-       collectRelatives(bufs);
+       d->collectRelatives(bufs);
        BufferSet::iterator it = bufs.begin();
        std::vector<Buffer const *> ret;
        for (; it != bufs.end(); ++it)
@@ -2406,12 +2483,12 @@ std::vector<Buffer *> Buffer::getChildren(bool grand_children) const
 
 
 template<typename M>
-typename M::iterator greatest_below(M & m, typename M::key_type const & x)
+typename M::const_iterator greatest_below(M & m, typename M::key_type const & x)
 {
        if (m.empty())
                return m.end();
 
-       typename M::iterator it = m.lower_bound(x);
+       typename M::const_iterator it = m.lower_bound(x);
        if (it == m.begin())
                return m.end();
 
@@ -2420,7 +2497,7 @@ typename M::iterator greatest_below(M & m, typename M::key_type const & x)
 }
 
 
-MacroData const * Buffer::getBufferMacro(docstring const & name,
+MacroData const * Buffer::Impl::getBufferMacro(docstring const & name,
                                         DocIterator const & pos) const
 {
        LYXERR(Debug::MACROS, "Searching for " << to_ascii(name) << " at " << pos);
@@ -2430,15 +2507,14 @@ MacroData const * Buffer::getBufferMacro(docstring const & name,
                return 0;
 
        // we haven't found anything yet
-       DocIterator bestPos = par_iterator_begin();
+       DocIterator bestPos = owner_->par_iterator_begin();
        MacroData const * bestData = 0;
 
        // find macro definitions for name
-       Impl::NamePositionScopeMacroMap::iterator nameIt
-               = d->macros.find(name);
-       if (nameIt != d->macros.end()) {
+       NamePositionScopeMacroMap::const_iterator nameIt = macros.find(name);
+       if (nameIt != macros.end()) {
                // find last definition in front of pos or at pos itself
-               Impl::PositionScopeMacroMap::const_iterator it
+               PositionScopeMacroMap::const_iterator it
                        = greatest_below(nameIt->second, pos);
                if (it != nameIt->second.end()) {
                        while (true) {
@@ -2461,9 +2537,9 @@ MacroData const * Buffer::getBufferMacro(docstring const & name,
        }
 
        // find macros in included files
-       Impl::PositionScopeBufferMap::const_iterator it
-               = greatest_below(d->position_to_children, pos);
-       if (it == d->position_to_children.end())
+       PositionScopeBufferMap::const_iterator it
+               = greatest_below(position_to_children, pos);
+       if (it == position_to_children.end())
                // no children before
                return bestData;
 
@@ -2475,10 +2551,10 @@ MacroData const * Buffer::getBufferMacro(docstring const & name,
                // scope ends behind pos?
                if (pos < it->second.first) {
                        // look for macro in external file
-                       d->macro_lock = true;
+                       macro_lock = true;
                        MacroData const * data
-                       = it->second.second->getMacro(name, false);
-                       d->macro_lock = false;
+                               = it->second.second->getMacro(name, false);
+                       macro_lock = false;
                        if (data) {
                                bestPos = it->first;
                                bestData = data;
@@ -2487,7 +2563,7 @@ MacroData const * Buffer::getBufferMacro(docstring const & name,
                }
 
                // try previous file if there is one
-               if (it == d->position_to_children.begin())
+               if (it == position_to_children.begin())
                        break;
                --it;
        }
@@ -2504,7 +2580,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
                return 0;
 
        // query buffer macros
-       MacroData const * data = getBufferMacro(name, pos);
+       MacroData const * data = d->getBufferMacro(name, pos);
        if (data != 0)
                return data;
 
@@ -2552,7 +2628,7 @@ MacroData const * Buffer::getMacro(docstring const & name,
 }
 
 
-void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
+void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
 {
        pit_type const lastpit = it.lastpit();
 
@@ -2589,20 +2665,20 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
                                // get buffer of external file
                                InsetInclude const & inset =
                                        static_cast<InsetInclude const &>(*iit->inset);
-                               d->macro_lock = true;
+                               macro_lock = true;
                                Buffer * child = inset.getChildBuffer();
-                               d->macro_lock = false;
+                               macro_lock = false;
                                if (!child)
                                        continue;
 
                                // register its position, but only when it is
                                // included first in the buffer
-                               if (d->children_positions.find(child) ==
-                                       d->children_positions.end())
-                                               d->children_positions[child] = it;
+                               if (children_positions.find(child) ==
+                                       children_positions.end())
+                                               children_positions[child] = it;
 
                                // register child with its scope
-                               d->position_to_children[it] = Impl::ScopeBuffer(scope, child);
+                               position_to_children[it] = Impl::ScopeBuffer(scope, child);
                                continue;
                        }
 
@@ -2612,7 +2688,7 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
                        // get macro data
                        MathMacroTemplate & macroTemplate =
                                static_cast<MathMacroTemplate &>(*iit->inset);
-                       MacroContext mc(this, it);
+                       MacroContext mc(owner_, it);
                        macroTemplate.updateToContext(mc);
 
                        // valid?
@@ -2626,8 +2702,8 @@ void Buffer::updateMacros(DocIterator & it, DocIterator & scope) const
                        // register macro
                        // FIXME (Abdel), I don't understandt why we pass 'it' here
                        // instead of 'macroTemplate' defined above... is this correct?
-                       d->macros[macroTemplate.name()][it] =
-                               Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(this), it));
+                       macros[macroTemplate.name()][it] =
+                               Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(owner_), it));
                }
 
                // next paragraph
@@ -2656,7 +2732,7 @@ void Buffer::updateMacros() const
        DocIterator it = par_iterator_begin();
        DocIterator outerScope = it;
        outerScope.pit() = outerScope.lastpit() + 2;
-       updateMacros(it, outerScope);
+       d->updateMacros(it, outerScope);
 }
 
 
@@ -2907,36 +2983,36 @@ ErrorList & Buffer::errorList(string const & type) const
 void Buffer::updateTocItem(std::string const & type,
        DocIterator const & dit) const
 {
-       if (gui_)
-               gui_->updateTocItem(type, dit);
+       if (d->gui_)
+               d->gui_->updateTocItem(type, dit);
 }
 
 
 void Buffer::structureChanged() const
 {
-       if (gui_)
-               gui_->structureChanged();
+       if (d->gui_)
+               d->gui_->structureChanged();
 }
 
 
 void Buffer::errors(string const & err, bool from_master) const
 {
-       if (gui_)
-               gui_->errors(err, from_master);
+       if (d->gui_)
+               d->gui_->errors(err, from_master);
 }
 
 
 void Buffer::message(docstring const & msg) const
 {
-       if (gui_)
-               gui_->message(msg);
+       if (d->gui_)
+               d->gui_->message(msg);
 }
 
 
 void Buffer::setBusy(bool on) const
 {
-       if (gui_)
-               gui_->setBusy(on);
+       if (d->gui_)
+               d->gui_->setBusy(on);
 }
 
 
@@ -2949,20 +3025,20 @@ void Buffer::updateTitles() const
 
 void Buffer::resetAutosaveTimers() const
 {
-       if (gui_)
-               gui_->resetAutosaveTimers();
+       if (d->gui_)
+               d->gui_->resetAutosaveTimers();
 }
 
 
 bool Buffer::hasGuiDelegate() const
 {
-       return gui_;
+       return d->gui_;
 }
 
 
 void Buffer::setGuiDelegate(frontend::GuiBufferDelegate * gui)
 {
-       gui_ = gui;
+       d->gui_ = gui;
 }
 
 
@@ -3077,8 +3153,10 @@ void Buffer::removeAutosaveFile() const
 void Buffer::moveAutosaveFile(support::FileName const & oldauto) const
 {
        FileName const newauto = getAutosaveFilename();
-       if (!(oldauto == newauto || oldauto.moveTo(newauto)))
-               LYXERR0("Unable to remove autosave file `" << oldauto << "'!");
+       oldauto.refresh();
+       if (newauto != oldauto && oldauto.exists())
+               if (!oldauto.moveTo(newauto))
+                       LYXERR0("Unable to move autosave file `" << oldauto << "'!");
 }
 
 
@@ -3248,7 +3326,7 @@ bool Buffer::doExport(string const & format, bool put_in_tempdir,
                return true;
        }
 
-       result_file = changeExtension(exportFileName().absFilename(), ext);
+       result_file = changeExtension(d->exportFileName().absFilename(), ext);
        // We need to copy referenced files (e. g. included graphics
        // if format == "dvi") to the result dir.
        vector<ExportedFile> const files =
@@ -3445,11 +3523,13 @@ bool Buffer::loadLyXFile(FileName const & s)
                  && !LyXVC::file_not_found_hook(s))
                return false;
        
-       if (s.isReadableFile()
-                 && readFileHelper(s)) {
+       if (s.isReadableFile()){
+               // InsetInfo needs to know if file is under VCS
                lyxvc().file_found_hook(s);
-               setReadonly(!s.isWritable());
-               return true;
+               if (readFileHelper(s)) {
+                       d->read_only = !s.isWritable();
+                       return true;
+               }
        }
        return false;
 }
@@ -3485,7 +3565,7 @@ void Buffer::setBuffersForInsets() const
 }
 
 
-void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
+void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 {
        // Use the master text class also for child documents
        Buffer const * const master = masterBuffer();
@@ -3503,10 +3583,10 @@ void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
                // If this is a child document start with the master
                if (master != this) {
                        bufToUpdate.insert(this);
-                       master->updateLabels(UpdateMaster, utype);
+                       master->updateBuffer(UpdateMaster, utype);
                        // Do this here in case the master has no gui associated with it. Then, 
                        // the TocModel is not updated and TocModel::toc_ is invalid (bug 5699).
-                       if (!master->gui_)
+                       if (!master->d->gui_)
                                structureChanged();
 
                        // was buf referenced from the master (i.e. not in bufToUpdate anymore)?
@@ -3531,7 +3611,7 @@ void Buffer::updateLabels(UpdateScope scope, UpdateType utype) const
 
        // do the real work
        ParIterator parit = cbuf.par_iterator_begin();
-       updateLabels(parit, utype);
+       updateBuffer(parit, utype);
 
        if (master != this)
                // TocBackend update will be done later.
@@ -3613,9 +3693,9 @@ static bool needEnumCounterReset(ParIterator const & it)
 
 
 // set the label of a paragraph. This includes the counters.
-void Buffer::setLabel(ParIterator & it, UpdateType utype) const
+void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
 {
-       BufferParams const & bp = this->masterBuffer()->params();
+       BufferParams const & bp = owner_->masterBuffer()->params();
        DocumentClass const & textclass = bp.documentClass();
        Paragraph & par = it.paragraph();
        Layout const & layout = par.layout();
@@ -3711,9 +3791,9 @@ void Buffer::setLabel(ParIterator & it, UpdateType utype) const
                string const & type = counters.current_float();
                docstring full_label;
                if (type.empty())
-                       full_label = this->B_("Senseless!!! ");
+                       full_label = owner_->B_("Senseless!!! ");
                else {
-                       docstring name = this->B_(textclass.floats().getType(type).name());
+                       docstring name = owner_->B_(textclass.floats().getType(type).name());
                        if (counters.hasCounter(from_utf8(type))) {
                                string const & lang = par.getParLanguage(bp)->code();
                                counters.step(from_utf8(type), utype);
@@ -3742,7 +3822,7 @@ void Buffer::setLabel(ParIterator & it, UpdateType utype) const
 }
 
 
-void Buffer::updateLabels(ParIterator & parit, UpdateType utype) const
+void Buffer::updateBuffer(ParIterator & parit, UpdateType utype) const
 {
        LASSERT(parit.pit() == 0, /**/);
 
@@ -3768,14 +3848,14 @@ void Buffer::updateLabels(ParIterator & parit, UpdateType utype) const
                }
                
                // set the counter for this paragraph
-               setLabel(parit, utype);
+               d->setLabel(parit, utype);
 
                // now the insets
                InsetList::const_iterator iit = parit->insetList().begin();
                InsetList::const_iterator end = parit->insetList().end();
                for (; iit != end; ++iit) {
                        parit.pos() = iit->pos;
-                       iit->inset->updateLabels(parit, utype);
+                       iit->inset->updateBuffer(parit, utype);
                }
        }
 }
@@ -3826,7 +3906,7 @@ bool Buffer::reload()
 
        bool const success = loadLyXFile(d->filename);
        if (success) {
-               updateLabels();
+               updateBuffer();
                changed(true);
                markClean();
                message(bformat(_("Document %1$s reloaded."), disp_fn));