]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiSelection.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiSelection.cpp
index f4d9051148df200950267c73ffed8f25298a3d6a..23878b32328f49b90117ff6f03b8de9753945cab 100644 (file)
 #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())
@@ -60,8 +71,7 @@ docstring const GuiSelection::get() const
 {
        QString const str = qApp->clipboard()->text(QClipboard::Selection)
                                .normalized(QString::NormalizationForm_C);
-       LYXERR(Debug::ACTION) << "GuiSelection::get: " << fromqstr(str)
-                             << endl;
+       LYXERR(Debug::ACTION, "GuiSelection::get: " << fromqstr(str));
        if (str.isNull())
                return docstring();
 
@@ -71,20 +81,31 @@ docstring const GuiSelection::get() const
 
 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"