]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
* output_plaintext.C: cosmetics in comment: line length cannot be < 0
[lyx.git] / src / text3.C
index f448e414bc3949c1b43767b1af24e02249a5ab20..86c69d0646be73b59307edcc411b1dd33e30883a 100644 (file)
@@ -76,6 +76,7 @@ namespace lyx {
 
 using cap::copySelection;
 using cap::cutSelection;
+using cap::pasteClipboard;
 using cap::pasteSelection;
 using cap::replaceSelection;
 
@@ -121,8 +122,7 @@ namespace {
        {
                if (selecting || cur.mark())
                        cur.setSelection();
-               if (!cur.selection())
-                       theSelection().haveSelection(false);
+               theSelection().haveSelection(cur.selection());
                cur.bv().switchKeyMap();
        }
 
@@ -554,6 +554,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_BREAK_LINE: {
                // Not allowed by LaTeX (labels or empty par)
                if (cur.pos() > cur.paragraph().beginOfBody()) {
+                       if (!cur.selection())
+                               recordUndo(cur);
                        cap::replaceSelection(cur);
                        cur.insert(new InsetNewline);
                        cur.posRight();
@@ -759,15 +761,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                cur.message(_("Paste"));
                cap::replaceSelection(cur);
                if (cmd.argument().empty() && !theClipboard().isInternal())
-                       pasteString(cur, theClipboard().get(), true);
+                       pasteClipboard(cur, bv->buffer()->errorList("Paste"));
                else {
                        string const arg(to_utf8(cmd.argument()));
                        pasteSelection(cur, bv->buffer()->errorList("Paste"),
                                        isStrUnsignedInt(arg) ?
                                                convert<unsigned int>(arg) :
                                                0);
-                       bv->buffer()->errors("Paste");
                }
+               bv->buffer()->errors("Paste");
                cur.clearSelection(); // bug 393
                bv->switchKeyMap();
                finishUndo();
@@ -866,8 +868,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_CLIPBOARD_PASTE:
-               pasteString(cur, theClipboard().get(),
-                           cmd.argument() == "paragraph");
+               cur.clearSelection();
+               pasteClipboard(cur, bv->buffer()->errorList("Paste"),
+                              cmd.argument() == "paragraph");
+               bv->buffer()->errors("Paste");
                break;
 
        case LFUN_PRIMARY_SELECTION_PASTE:
@@ -1065,7 +1069,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                if (lyxrc.auto_region_delete) {
                        if (cur.selection())
                                cutSelection(cur, false, false);
-                       theSelection().haveSelection(false);
+                               // cutSelection clears the X selection.
+                       else
+                               theSelection().haveSelection(false);
                }
 
                cur.clearSelection();
@@ -1735,23 +1741,28 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
                break;
 
        case LFUN_PASTE:
-               // FIXME: This is not correct, but the correct code below is
-               // expensive
-               enable = cap::numberOfSelections() > 0 ||
-                       !theClipboard().isInternal();
-#if 0
                if (cmd.argument().empty()) {
                        if (theClipboard().isInternal())
                                enable = cap::numberOfSelections() > 0;
                        else
-                               enable = !theClipboard().get().empty();
-               } else if (isStrUnsignedInt(to_utf8(cmd.argument()))) {
-                       int n = convert<unsigned int>(to_utf8(cmd.argument()));
-                       enable = cap::numberOfSelections() > n;
-               } else
-                       // unknown argument
-                       enable = false;
-#endif
+                               enable = !theClipboard().empty();
+               } else {
+                       string const arg = to_utf8(cmd.argument());
+                       if (isStrUnsignedInt(arg)) {
+                               unsigned int n = convert<unsigned int>(arg);
+                               enable = cap::numberOfSelections() > n;
+                       } else
+                               // unknown argument
+                               enable = false;
+               }
+               break;
+
+       case LFUN_CLIPBOARD_PASTE:
+               enable = !theClipboard().empty();
+               break;
+
+       case LFUN_PRIMARY_SELECTION_PASTE:
+               enable = cur.selection() || !theSelection().empty();
                break;
 
        case LFUN_PARAGRAPH_MOVE_UP:
@@ -1824,8 +1835,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_SERVER_GET_FONT:
        case LFUN_SERVER_GET_LAYOUT:
        case LFUN_LAYOUT:
-       case LFUN_CLIPBOARD_PASTE:
-       case LFUN_PRIMARY_SELECTION_PASTE:
        case LFUN_DATE_INSERT:
        case LFUN_SELF_INSERT:
        case LFUN_LINE_INSERT: