* Use default output flavor for View Source.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36758 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2010-12-07 08:36:42 +00:00
parent c420c81ec2
commit 2653011613
3 changed files with 55 additions and 6 deletions

View File

@ -3072,12 +3072,11 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to,
void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
pit_type par_end, bool full_source) const
pit_type par_end, bool full_source)
{
OutputParams runparams(&params().encoding());
runparams.nice = true;
runparams.flavor = params().useNonTeXFonts ?
OutputParams::XETEX : OutputParams::LATEX;
runparams.flavor = getDefaultOutputFlavor();
runparams.linelen = lyxrc.plaintext_linelen;
// No side effect of file copying and image conversion
runparams.dryrun = true;
@ -3089,6 +3088,8 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
d->texrow.newline();
if (isDocBook())
writeDocBookSource(os, absFileName(), runparams, false);
else if (runparams.flavor == OutputParams::HTML)
writeLyXHTMLSource(os, runparams, false);
else
// latex or literate
writeLaTeXSource(os, string(), runparams, true, true);
@ -3113,7 +3114,10 @@ void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
// output paragraphs
if (isDocBook())
docbookParagraphs(text(), *this, os, runparams);
else
else if (runparams.flavor == OutputParams::HTML) {
XHTMLStream xs(os);
xhtmlParagraphs(text(), *this, xs, runparams);
} else
// latex or literate
latexParagraphs(*this, text(), os, texrow, runparams);
}
@ -3384,6 +3388,42 @@ string Buffer::getDefaultOutputFormat() const
}
OutputParams::FLAVOR Buffer::getDefaultOutputFlavor()
{
string const dformat = getDefaultOutputFormat();
DefaultFlavorCache::const_iterator it =
default_flavors_.find(dformat);
if (it != default_flavors_.end())
return it->second;
OutputParams::FLAVOR result = OutputParams::LATEX;
if (dformat == "xhtml")
result = OutputParams::HTML;
else {
// Try to determine flavor of default output format
vector<string> backs = backends();
if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
// Get shortest path to format
Graph::EdgePath path;
for (vector<string>::const_iterator it = backs.begin();
it != backs.end(); ++it) {
Graph::EdgePath p = theConverters().getPath(*it, dformat);
if (!p.empty() && (path.empty() || p.size() < path.size())) {
path = p;
}
}
if (!path.empty())
result = theConverters().getFlavor(path);
}
}
// cache this flavor
default_flavors_[dformat] = result;
return result;
}
namespace {
// helper class, to guarantee this gets reset properly
class MarkAsExporting {

View File

@ -13,12 +13,14 @@
#define BUFFER_H
#include "OutputEnums.h"
#include "OutputParams.h"
#include "insets/InsetCode.h"
#include "support/strfwd.h"
#include "support/types.h"
#include <map>
#include <list>
#include <set>
#include <string>
@ -552,7 +554,7 @@ public:
/// get source code (latex/docbook) for some paragraphs, or all paragraphs
/// including preamble
void getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end,
bool full_source) const;
bool full_source);
/// Access to error list.
/// This method is used only for GUI visualisation of Buffer related
@ -600,6 +602,8 @@ public:
std::string bufferFormat() const;
/// return the default output format of the current backend
std::string getDefaultOutputFormat() const;
/// return the default output flavor
OutputParams::FLAVOR getDefaultOutputFlavor();
///
bool doExport(std::string const & format, bool put_in_tempdir,
@ -662,6 +666,10 @@ private:
void setFileName(support::FileName const & fname);
///
std::vector<std::string> backends() const;
/// A cache for the default flavors
typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
///
DefaultFlavorCache default_flavors_;
///
void getLanguages(std::set<Language const *> &) const;
/// Checks whether any of the referenced bibfiles have changed since the

View File

@ -102,7 +102,8 @@ static bool getContent(BufferView const * view, bool fullSource, QString & qstr)
if (par_begin > par_end)
swap(par_begin, par_end);
odocstringstream ostr;
view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
const_cast<BufferView *>(view)->buffer().getSourceCode(
ostr, par_begin, par_end + 1, fullSource);
docstring s = ostr.str();
static size_t crc = 0;
size_t newcrc = crcCheck(s);