mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Also put HTML on the clipboard when copying
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.
This commit is contained in:
parent
8c8e19bb1c
commit
0613a218aa
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user