]> git.lyx.org Git - features.git/commitdiff
Also put HTML on the clipboard when copying
authorGeorg Baum <baum@lyx.org>
Fri, 12 Apr 2013 20:12:47 +0000 (22:12 +0200)
committerGeorg Baum <baum@lyx.org>
Fri, 12 Apr 2013 20:12:47 +0000 (22:12 +0200)
The HTML export is now mature enough so that it can be used to transfer
formatted text to the clipboard. This enhances interoperability e.g. with
office applications.

src/CutAndPaste.cpp
src/frontends/Clipboard.h
src/frontends/qt4/GuiClipboard.cpp
src/frontends/qt4/GuiClipboard.h

index 65344758855b9d5041fe1d0d3e517579497c519a..da5739d2896487ab404ddc2488254fb422af8d6a 100644 (file)
@@ -23,6 +23,7 @@
 #include "BufferView.h"
 #include "Changes.h"
 #include "Cursor.h"
+#include "Encoding.h"
 #include "ErrorList.h"
 #include "FuncCode.h"
 #include "FuncRequest.h"
@@ -474,11 +475,14 @@ void putClipboard(ParagraphList const & paragraphs,
        buffer->paragraphs() = paragraphs;
        buffer->inset().setBuffer(*buffer);
        buffer->params().setDocumentClass(docclass);
-       ostringstream lyx;
-       if (buffer->write(lyx))
-               theClipboard().put(lyx.str(), plaintext);
-       else
-               theClipboard().put(string(), plaintext);
+       string lyx;
+       ostringstream oslyx;
+       if (buffer->write(oslyx))
+               lyx = oslyx.str();
+       odocstringstream oshtml;
+       OutputParams runparams(encodings.fromLyXName("utf8"));
+       buffer->writeLyXHTMLSource(oshtml, runparams, Buffer::FullSource);
+       theClipboard().put(lyx, oshtml.str(), plaintext);
        // Save that memory
        buffer->paragraphs().clear();
 }
index 92e7167708ae9a50adc8093726bb1af1f024f5a6..1e0d48685d738917f9e060076935bc58c4fa1556 100644 (file)
@@ -55,7 +55,7 @@ public:
        virtual docstring const getAsText() const = 0;
        /// Get the contents of the window system clipboard as graphics file.
        virtual FileName getAsGraphics(Cursor const & cur, GraphicsType type) const = 0;
-       
+
        /**
         * Fill the system clipboard. The format of \p lyx is as written in
         * .lyx files, the format of \p text is plain text.
@@ -65,7 +65,7 @@ public:
         * This should be called when the user requests to cut or copy to
         * the clipboard.
         */
-       virtual void put(std::string const & lyx, docstring const & text) = 0;
+       virtual void put(std::string const & lyx, docstring const & html, docstring const & text) = 0;
 
        /// Does the clipboard contain LyX contents?
        virtual bool hasLyXContents() const = 0;
index 438feac97bc28cf2fc5923c85e3a4b44b14f71bc..b2a97d60776a4543eb59f3e77b3f1ffdb4a07a3b 100644 (file)
@@ -296,9 +296,9 @@ FileName GuiClipboard::getAsGraphics(Cursor const & cur, GraphicsType type) cons
                return FileName();
        // data from ourself or some other LyX instance
        QByteArray const ar = cache_.data(mime);
-       LYXERR(Debug::ACTION, "Getting from clipboard: mime = " << mime.data()
+       LYXERR(Debug::ACTION, "Getting from clipboard: mime = " << mime.constData()
               << "length = " << ar.count());
-       
+
        QFile f(toqstr(filename.absFileName()));
        if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
                LYXERR(Debug::ACTION, "Error opening file "
@@ -341,10 +341,10 @@ docstring const GuiClipboard::getAsText() const
 }
 
 
-void GuiClipboard::put(string const & lyx, docstring const & text)
+void GuiClipboard::put(string const & lyx, docstring const & html, docstring const & text)
 {
        LYXERR(Debug::ACTION, "GuiClipboard::put(`" << lyx << "' `"
-                             << to_utf8(text) << "')");
+                             << to_utf8(html) << "' `" << to_utf8(text) << "')");
        // We don't convert the encoding of lyx since the encoding of the
        // clipboard contents is specified in the data itself
        QMimeData * data = new QMimeData;
@@ -363,6 +363,8 @@ void GuiClipboard::put(string const & lyx, docstring const & text)
        // clipboard.
        QString const qtext = toqstr(text);
        data->setText(qtext);
+       QString const qhtml = toqstr(html);
+       data->setHtml(qhtml);
        qApp->clipboard()->setMimeData(data, QClipboard::Clipboard);
 }
 
@@ -470,7 +472,7 @@ void GuiClipboard::on_dataChanged()
        LYXERR(Debug::ACTION, "Qt Clipboard changed. We found the following mime types:");
        for (int i = 0; i < l.count(); i++)
                LYXERR(Debug::ACTION, l.value(i));
-       
+
        text_clipboard_empty_ = qApp->clipboard()->
                text(QClipboard::Clipboard).isEmpty();
 
index a6540f1ce8a15eef7bfcc90d7c6cbfa8309d982a..5b452beae8446762c3006b4bba3703262b80963c 100644 (file)
@@ -70,7 +70,7 @@ public:
        std::string const getAsLyX() const;
        FileName getAsGraphics(Cursor const & cur, GraphicsType type) const;
        docstring const getAsText() const;
-       void put(std::string const & lyx, docstring const & text);
+       void put(std::string const & lyx, docstring const & html, docstring const & text);
        bool hasLyXContents() const;
        bool hasGraphicsContents(GraphicsType type = AnyGraphicsType) const;
        bool hasTextContents() const;