+
+
+void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc)
+{
+ cursor_ = cur;
+ anchor_ = anc;
+}
+
+
+void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
+ InsetBase::Code code)
+{
+ //FIXME: This does not work for child documents yet.
+ BOOST_ASSERT(code == InsetBase::CITE_CODE || code == InsetBase::REF_CODE);
+ // Check if the label 'from' appears more than once
+ vector<docstring> labels;
+
+ if (code == InsetBase::CITE_CODE) {
+ vector<pair<string, docstring> > keys;
+ fillWithBibKeys(keys);
+ vector<pair<string, docstring> >::const_iterator bit = keys.begin();
+ vector<pair<string, docstring> >::const_iterator bend = keys.end();
+
+ for (; bit != bend; ++bit)
+ // FIXME UNICODE
+ labels.push_back(from_utf8(bit->first));
+ } else
+ getLabelList(labels);
+
+ if (lyx::count(labels.begin(), labels.end(), from) > 1)
+ return;
+
+ for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
+ if (it->lyxCode() == code) {
+ InsetCommand & inset = dynamic_cast<InsetCommand &>(*it);
+ inset.replaceContents(to_utf8(from), to_utf8(to));
+ }
+ }
+}
+
+
+void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
+ 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;
+
+ /* Support for docbook temprarily commented out. */
+ 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<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];
+}
+
+
+} // namespace lyx