The mixing comes from the fact that cap::copySelection() fills in theClipboard(), independantly of the caller. This patch fixes this by properly filling in theSelection() or theClipboard() depending on the argument at LFUN_COPY time. It also fills in the X Selection at mouse release time instead of mouse press time which is obviously correct if we want to be able to use the X selection into other apps.

I still have to fix LFUN_CUT and probably also special tabular mode but I want to be sure that that's what we want.

Please comment,
Abdel.



Index: CutAndPaste.C
===================================================================
--- CutAndPaste.C       (revision 16460)
+++ CutAndPaste.C       (working copy)
@@ -45,15 +45,12 @@
 
 #include "support/lstrings.h"
 
-#include "frontends/Clipboard.h"
-
 #include <boost/tuple/tuple.hpp>
 
 
 namespace lyx {
 
 using support::bformat;
-using frontend::Clipboard;
 
 using std::endl;
 using std::for_each;
@@ -563,9 +560,6 @@
 
 void copySelection(LCursor & cur)
 {
-       // stuff the selection onto the X clipboard, from an explicit copy 
request
-       theClipboard().put(cur.selectionAsString(true));
-
        // this doesn't make sense, if there is no selection
        if (!cur.selection())
                return;
Index: insets/insettabular.C
===================================================================
--- insets/insettabular.C       (revision 16460)
+++ insets/insettabular.C       (working copy)
@@ -700,12 +700,24 @@
                        break;
                if (tablemode(cur)) {
                        finishUndo();
+                       if (cmd.argument() == "selection") {
+                               // stuff the selection onto the X selection.
+                               theSelection().haveSelection(true);
+                               theSelection().put(cur.selectionAsString(true));
+                       }
+                       else {
+                               theClipboard().put(cur.selectionAsString(true));
+                       }
                        copySelection(cur);
                } else
                        cell(cur.idx())->dispatch(cur, cmd);
                break;
 
        case LFUN_CLIPBOARD_PASTE:
Index: mathed/InsetMathNest.C
===================================================================
--- mathed/InsetMathNest.C      (revision 16460)
+++ mathed/InsetMathNest.C      (working copy)
@@ -51,6 +51,7 @@
 #include "support/lstrings.h"
 
 #include "frontends/Painter.h"
+#include "frontends/Clipboard.h"
 #include "frontends/Selection.h"
 
 #include "funcrequest.h"
@@ -458,6 +459,16 @@
                break;
 
        case LFUN_COPY:
+               if (!cur.selection())
+                       break;
+               if (cmd.argument() == "selection") {
+                       // stuff the selection onto the X selection.
+                       theSelection().haveSelection(true);
+                       theSelection().put(cur.selectionAsString(true));
+               }
+               else {
+                       theClipboard().put(cur.selectionAsString(true));
+               }
                copySelection(cur);
                // FIXME UNICODE
                cur.message(_("Copy"));
@@ -1218,6 +1229,8 @@
                //theSelection().put(cur.grabSelection());
                if (!cur.selection())
                        cur.noUpdate();
+
+               lyx::dispatch(FuncRequest(LFUN_COPY, "selection"));
                return;
        }
 
Index: text3.C
===================================================================
--- text3.C     (revision 16475)
+++ text3.C     (working copy)
@@ -774,6 +774,18 @@
                break;
 
        case LFUN_COPY:
+               if (!cur.selection())
+                       break;
+
+               if (cmd.argument() == "selection") {
+                       // stuff the selection onto the X selection.
+                       theSelection().haveSelection(true);
+                       theSelection().put(cur.selectionAsString(true));
+               }
+               else {
+                       theClipboard().put(cur.selectionAsString(true));
+               }
+
                copySelection(cur);
                cur.message(_("Copy"));
                break;
@@ -954,11 +970,8 @@
                // We do this here as if the selection was inside an inset
                // it could get cleared on the unlocking of the inset so
                // we have to check this first
-               bool paste_internally = false;
-               if (cmd.button() == mouse_button::button2 && cur.selection()) {
-                       lyx::dispatch(FuncRequest(LFUN_COPY));
-                       paste_internally = true;
-               }
+               bool paste_internally = cmd.button() == mouse_button::button2
+                       && cur.selection();
 
                // we have to update after dePM triggered
                bool update = bv->mouseSetCursor(cur);
@@ -1029,7 +1042,7 @@
                // finish selection
                if (cmd.button() == mouse_button::button1) {
                        if (cur.selection())
-                               theSelection().haveSelection(cur.selection());
+                               lyx::dispatch(FuncRequest(LFUN_COPY, 
"selection"));
                        needsUpdate = false;
                        cur.noUpdate();
                }

Reply via email to