mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-13 14:32:04 +00:00
3500af60ba
LyX instances. This re-enables copy/paste from the internal clipboard on OS X (currently broken since Clipboard::isInternal() always returns false for some reason). * src/insets/insettabular.C (InsetTabular::doDispatch): adjust to clipboard interface change (InsetTabular::copySelection): ditto * src/mathed/InsetMathGrid.C (InsetMathGrid::doDispatch): ditto * src/mathed/InsetMathNest.C (InsetMathNest::doDispatch): ditto * src/buffer.[Ch] (Buffer::readString): New method: Read document from a string (Buffer::readFile): Change return value from bool to enum (needed for readString). Return wrongversion if we are reading from a string and the version does not match. (Buffer::do_writeFile): make public and rename to write * src/CutAndPaste.C (putClipboard): New helper, put stuff to the system clipboard (void copySelectionHelper): Use putClipboard instead of theClipboard().put() (void copySelection): ditto (void pasteClipboard): new method for pasting in text (void pasteParagraphList): * src/frontends/Clipboard.h (Clipboard::get): Rename to getAsText (Clipboard::getAsLyX): New method for getting the system clipboard in LyX format (Clipboard::hasLyXContents): New method telling whether there is LyX contents in the clipboard * src/frontends/qt4/GuiClipboard.[Ch]: Implement the new methods * src/text3.C (LyXText::dispatch): Use pasteClipboard for pasting the system clipboard git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16669 a592a061-630c-0410-9148-cb99ea01b6c8
122 lines
2.9 KiB
C
122 lines
2.9 KiB
C
// -*- C++ -*-
|
|
/**
|
|
* \file qt4/GuiClipboard.C
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author John Levon
|
|
* \author Abdelrazak Younes
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "GuiClipboard.h"
|
|
#include "qt_helpers.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include <QApplication>
|
|
#include <QClipboard>
|
|
#include <QMimeData>
|
|
#include <QString>
|
|
|
|
#include "support/lstrings.h"
|
|
using lyx::support::internalLineEnding;
|
|
using lyx::support::externalLineEnding;
|
|
|
|
using std::endl;
|
|
using std::string;
|
|
|
|
|
|
namespace {
|
|
|
|
char const * const mime_type = "application/x-lyx";
|
|
|
|
}
|
|
|
|
|
|
namespace lyx {
|
|
namespace frontend {
|
|
|
|
string const GuiClipboard::getAsLyX() const
|
|
{
|
|
lyxerr[Debug::ACTION] << "GuiClipboard::getAsLyX(): `";
|
|
// We don't convert encodings here since the encoding of the
|
|
// clipboard contents is specified in the data itself
|
|
QMimeData const * source =
|
|
qApp->clipboard()->mimeData(QClipboard::Clipboard);
|
|
if (!source) {
|
|
lyxerr[Debug::ACTION] << "' (no QMimeData)" << endl;
|
|
return string();
|
|
}
|
|
if (source->hasFormat(mime_type)) {
|
|
// data from ourself or some other LyX instance
|
|
QByteArray const ar = source->data(mime_type);
|
|
string const s(ar.data(), ar.count());
|
|
if (lyxerr.debugging(Debug::ACTION))
|
|
lyxerr[Debug::ACTION] << s << "'" << endl;
|
|
return s;
|
|
}
|
|
lyxerr[Debug::ACTION] << "'" << endl;
|
|
return string();
|
|
}
|
|
|
|
|
|
docstring const GuiClipboard::getAsText() const
|
|
{
|
|
// text data from other applications
|
|
QString const str = qApp->clipboard()->text(QClipboard::Clipboard);
|
|
if (lyxerr.debugging(Debug::ACTION))
|
|
lyxerr[Debug::ACTION] << "GuiClipboard::getAsText(): `"
|
|
<< fromqstr(str) << "'" << endl;
|
|
if (str.isNull())
|
|
return docstring();
|
|
|
|
return internalLineEnding(qstring_to_ucs4(str));
|
|
}
|
|
|
|
|
|
void GuiClipboard::put(string const & lyx, docstring const & text)
|
|
{
|
|
if (lyxerr.debugging(Debug::ACTION))
|
|
lyxerr[Debug::ACTION] << "GuiClipboard::put(`" << lyx << "' `"
|
|
<< to_utf8(text) << "')" << endl;
|
|
// 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;
|
|
if (!lyx.empty()) {
|
|
QByteArray const qlyx(lyx.c_str(), lyx.size());
|
|
data->setData(mime_type, qlyx);
|
|
}
|
|
// Don't test for text.empty() since we want to be able to clear the
|
|
// clipboard.
|
|
QString const qtext = toqstr(text);
|
|
data->setText(qtext);
|
|
qApp->clipboard()->setMimeData(data, QClipboard::Clipboard);
|
|
}
|
|
|
|
|
|
bool GuiClipboard::hasLyXContents() const
|
|
{
|
|
QMimeData const * const source =
|
|
qApp->clipboard()->mimeData(QClipboard::Clipboard);
|
|
return source && source->hasFormat(mime_type);
|
|
}
|
|
|
|
|
|
bool GuiClipboard::isInternal() const
|
|
{
|
|
return qApp->clipboard()->ownsClipboard();
|
|
}
|
|
|
|
|
|
bool GuiClipboard::empty() const
|
|
{
|
|
return qApp->clipboard()->text(QClipboard::Clipboard).isEmpty();
|
|
}
|
|
|
|
} // namespace frontend
|
|
} // namespace lyx
|