+
+
+Buffer * Buffer::getMasterBuffer()
+{
+ if (!params().parentname.empty()
+ && theApp->bufferList().exists(params().parentname)) {
+ Buffer * buf = theApp->bufferList().getBuffer(params().parentname);
+ if (buf)
+ return buf->getMasterBuffer();
+ }
+
+ return this;
+}
+
+
+MacroData const & Buffer::getMacro(std::string const & name) const
+{
+ return pimpl_->macros.get(name);
+}
+
+
+bool Buffer::hasMacro(string const & name) const
+{
+ return pimpl_->macros.has(name);
+}
+
+
+void Buffer::insertMacro(string const & name, MacroData const & data)
+{
+ MacroTable::globalMacros().insert(name, data);
+ pimpl_->macros.insert(name, data);
+}
+
+
+void Buffer::buildMacros()
+{
+ // Start with global table.
+ pimpl_->macros = MacroTable::globalMacros();
+
+ // Now add our own.
+ ParagraphList const & pars = text().paragraphs();
+ for (size_t i = 0, n = pars.size(); i != n; ++i) {
+ //lyxerr << "searching main par " << i
+ // << " for macro definitions" << std::endl;
+ InsetList const & insets = pars[i].insetlist;
+ InsetList::const_iterator it = insets.begin();
+ InsetList::const_iterator end = insets.end();
+ for ( ; it != end; ++it) {
+ //lyxerr << "found inset code " << it->inset->lyxCode() << std::endl;
+ if (it->inset->lyxCode() == InsetBase::MATHMACRO_CODE) {
+ MathMacroTemplate const & mac
+ = static_cast<MathMacroTemplate const &>(*it->inset);
+ insertMacro(mac.name(), mac.asMacroData());
+ }
+ }
+ }
+}
+
+
+void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc)
+{
+ cursor_ = cur;
+ anchor_ = anc;
+}
+
+
+void Buffer::changeRefsIfUnique(string const & from, string const & to)
+{
+ // Check if the label 'from' appears more than once
+ vector<string> labels;
+ getLabelList(labels);
+
+ if (lyx::count(labels.begin(), labels.end(), from) > 1)
+ return;
+
+ InsetBase::Code code = InsetBase::REF_CODE;
+
+ ParIterator it = par_iterator_begin();
+ ParIterator end = par_iterator_end();
+ for ( ; it != end; ++it) {
+ bool changed_inset = false;
+ for (InsetList::iterator it2 = it->insetlist.begin();
+ it2 != it->insetlist.end(); ++it2) {
+ if (it2->inset->lyxCode() == code) {
+ InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
+ if (inset->getContents() == from) {
+ inset->setContents(to);
+ //inset->setButtonLabel();
+ changed_inset = true;
+ }
+ }
+ }
+ }
+}
+
+
+void Buffer::getSourceCode(ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source)
+{
+ OutputParams runparams;
+ runparams.nice = true;
+ runparams.flavor = OutputParams::LATEX;
+ runparams.linelen = lyxrc.ascii_linelen;
+ // No side effect of file copying and image conversion
+ runparams.dryrun = true;
+
+ if (full_source) {
+ os << "% Preview source code\n\n";
+ if (isLatex())
+ writeLaTeXSource(os, filePath(), runparams, true, true);
+ else
+ writeDocBookSource(os, fileName(), runparams, false);
+ } else {
+ runparams.par_begin = par_begin;
+ runparams.par_end = par_end;
+ if (par_begin + 1 == par_end)
+ os << "% Preview source code for paragraph " << par_begin << "\n\n";
+ else
+ os << "% Preview source code from paragraph " << par_begin << " to " << par_end - 1 << "\n\n";
+ // output paragraphs
+ if (isLatex()) {
+ texrow().reset();
+ latexParagraphs(*this, paragraphs(), os, texrow(), runparams);
+ } else // DocBook
+ docbookParagraphs(paragraphs(), *this, os, runparams);
+ }
+}
+
+
+ErrorList const & Buffer::errorList(string const & type) const
+{
+ static ErrorList const emptyErrorList;
+ std::map<std::string, ErrorList>::const_iterator I = errorLists_.find(type);
+ if (I == errorLists_.end())
+ return emptyErrorList;
+
+ return I->second;
+}
+
+
+ErrorList & Buffer::errorList(string const & type)
+{
+ return errorLists_[type];
+}