#include <config.h>
#include "GuiSelection.h"
+
#include "qt_helpers.h"
-#include "debug.h"
+#include "support/debug.h"
+#include "support/lstrings.h"
#include <QApplication>
#include <QClipboard>
#include <QString>
-#include "support/lstrings.h"
-using lyx::support::internalLineEnding;
-using lyx::support::externalLineEnding;
-
-using std::endl;
namespace lyx {
namespace frontend {
+using support::internalLineEnding;
+using support::externalLineEnding;
+
+
+GuiSelection::GuiSelection()
+ : selection_supported_(qApp->clipboard()->supportsSelection())
+{
+ connect(qApp->clipboard(), SIGNAL(selectionChanged()),
+ this, SLOT(on_dataChanged()));
+ // initialize clipboard status.
+ on_dataChanged();
+}
+
+
void GuiSelection::haveSelection(bool own)
{
if (!qApp->clipboard()->supportsSelection())
docstring const GuiSelection::get() const
{
QString const str = qApp->clipboard()->text(QClipboard::Selection)
- .normalized(QString::NormalizationForm_KC);
- LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
- << endl;
+ .normalized(QString::NormalizationForm_C);
+ LYXERR(Debug::ACTION, "GuiSelection::get: " << str);
if (str.isNull())
return docstring();
void GuiSelection::put(docstring const & str)
{
- LYXERR(Debug::ACTION) << "GuiSelection::put: " << to_utf8(str) << endl;
+ LYXERR(Debug::ACTION, "GuiSelection::put: " << to_utf8(str));
qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
QClipboard::Selection);
}
+void GuiSelection::on_dataChanged()
+{
+ text_selection_empty_ = qApp->clipboard()->
+ text(QClipboard::Selection).isEmpty();
+}
+
+
bool GuiSelection::empty() const
{
- if (!qApp->clipboard()->supportsSelection())
+ if (!selection_supported_)
return true;
- return qApp->clipboard()->text(QClipboard::Selection).isEmpty();
+ LYXERR(Debug::ACTION, "GuiSelection::empty: " << text_selection_empty_);
+
+ return text_selection_empty_;
}
} // namespace frontend
} // namespace lyx
+
+#include "GuiSelection_moc.cpp"