]> git.lyx.org Git - features.git/commitdiff
* Use default output flavor for View Source.
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 7 Dec 2010 08:36:42 +0000 (08:36 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 7 Dec 2010 08:36:42 +0000 (08:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36758 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/Buffer.h
src/frontends/qt4/GuiViewSource.cpp

index 476d70bcd6b1138cf0e876612b0f612817e7b990..1509b5ba28cd272795bba61d0eba1cc200e6f181 100644 (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   {
index 393951403147be7ca8f08b8b617dba021db6e5e8..c9f82068b3f7efe724048b1c69e458cf7bf6a8e6 100644 (file)
 #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
index a5beae5da691e673c05fa55d77e9ae9274527128..1bfd7a291922289ec063d616d713185ec2266561 100644 (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);