Abdelrazak Younes wrote:
Georg Baum wrote:

lyx::frontend::GuiSelection is BTW exactly the place where a real selection with middle mouse paste could be emulated on windows: Just store the string in put(), return it back in get() and clear it in haveSelection() if needed. Then the only thing that would be missing for Enrico is a connection of this emulated selection to the external clipboard, but you could even do that without destroying the simple mental model of selection: In lyx::frontend::GuiSelection::get(), return the system clipboard if it was set from outside of LyX and the LyX internal selection is empty. This could even be implemented without any #ifdef by simply using qApp->clipboard()->supportsSelection(), and would work automatically on all platforms that don't have a selection. This way, no preference setting would be needed, and the behaviour on windows and X11 would be as identical as possible. Or did I miss anything?

I have to think a bit more about that but at first glance this looks like workable. Do you want to implement that? I can do it if you want.

It was easy so I've done it. It works quite well. Could you please it on X11 and verify that I did not miss something? In particular I think there's nothing to do in haveSelection() but I am not sure of that.

Thanks,
Abel.
Index: GuiSelection.C
===================================================================
--- GuiSelection.C      (revision 16476)
+++ GuiSelection.C      (working copy)
@@ -15,6 +15,8 @@
 #include "GuiSelection.h"
 #include "qt_helpers.h"
 
+#include "frontends/Clipboard.h"
+
 #include "debug.h"
 
 #include <QApplication>
@@ -44,13 +46,24 @@
 
 docstring const GuiSelection::get() const
 {
+       if (!qApp->clipboard()->supportsSelection()) {
+               if (!selection_.empty())
+                       return selection_;
+               return theClipboard().get();
+       }
+
+       if (isInternal())
+               return selection_;
+
        QString const str = qApp->clipboard()->text(QClipboard::Selection);
        lyxerr[Debug::ACTION] << "GuiSelection::get: " << fromqstr(str)
                              << endl;
        if (str.isNull())
-               return docstring();
+               selection_.clear();
+       else
+               selection_ = internalLineEnding(qstring_to_ucs4(str));
 
-       return internalLineEnding(qstring_to_ucs4(str));
+       return selection_;
 }
 
 
@@ -58,6 +71,10 @@
 {
        lyxerr[Debug::ACTION] << "GuiSelection::put: " << lyx::to_utf8(str) << 
endl;
 
+       // Store the string for further use within LyX and for platform
+       // that do not support the Selection concept.
+       selection_ = str;
+
        qApp->clipboard()->setText(toqstr(externalLineEnding(str)),
                                   QClipboard::Selection);
 }
Index: GuiSelection.h
===================================================================
--- GuiSelection.h      (revision 16476)
+++ GuiSelection.h      (working copy)
@@ -35,6 +35,8 @@
        void put(docstring const & str);
        bool isInternal() const;
        //@}
+private:
+       mutable docstring selection_;
 };
 
 } // namespace frontend

Reply via email to