]> git.lyx.org Git - features.git/commitdiff
Fix pasting of PDF from clipboard
authorScott Kostyshak <skostysh@lyx.org>
Sat, 9 May 2015 03:26:57 +0000 (23:26 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Sun, 10 May 2015 00:46:43 +0000 (20:46 -0400)
The command "paste pdf" was always disabled because the
condition in the following "if" statement always returns false

  if (arg == "pdf" && (type = Clipboard::PdfGraphicsType))

The value of "type" is zero in this case because PdfGraphicsType is
the first enum value (and it is not set explicitly to non-zero).

An alternative patch is to put AnyGraphicsType as the first
element of enum GraphicsType, or to set the first element to a
number greater than 0.

To test the bug that this commit fixes, either copy a PDF and try to
paste with the action "paste pdf", or click on the "Edit" menu and
notice (before this commit) the terminal output "Unrecognized
graphics type: pdf".

src/Text3.cpp

index 3d73e1ef66eccbbfbfdca83dce4ec233502ea728..5c9b812ef50292d6d952acc2b198586289cdb32e 100644 (file)
@@ -2959,25 +2959,30 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
                }
 
-               // explicit graphics type?
                Clipboard::GraphicsType type = Clipboard::AnyGraphicsType;
-               if ((arg == "pdf" && (type = Clipboard::PdfGraphicsType))
-                         || (arg == "png" && (type = Clipboard::PngGraphicsType))
-                         || (arg == "jpeg" && (type = Clipboard::JpegGraphicsType))
-                         || (arg == "linkback" &&  (type = Clipboard::LinkBackGraphicsType))
-                         || (arg == "emf" &&  (type = Clipboard::EmfGraphicsType))
-                         || (arg == "wmf" &&  (type = Clipboard::WmfGraphicsType))) {
-                       enable = theClipboard().hasGraphicsContents(type);
+               if (arg == "pdf")
+                       type = Clipboard::PdfGraphicsType;
+               else if (arg == "png")
+                       type = Clipboard::PngGraphicsType;
+               else if (arg == "jpeg")
+                       type = Clipboard::JpegGraphicsType;
+               else if (arg == "linkback")
+                       type = Clipboard::LinkBackGraphicsType;
+               else if (arg == "emf")
+                       type = Clipboard::EmfGraphicsType;
+               else if (arg == "wmf")
+                       type = Clipboard::WmfGraphicsType;
+               else {
+                       // unknown argument
+                       LYXERR0("Unrecognized graphics type: " << arg);
+                       // we don't want to assert if the user just mistyped the LFUN
+                       LATTEST(cmd.origin() != FuncRequest::INTERNAL);
+                       enable = false;
                        break;
                }
-
-               // unknown argument
-               LYXERR0("Unrecognized graphics type: " << arg);
-               // we don't want to assert if the user just mistyped the LFUN
-               LATTEST(cmd.origin() != FuncRequest::INTERNAL);
-               enable = false;
+               enable = theClipboard().hasGraphicsContents(type);
                break;
-        }
+       }
 
        case LFUN_CLIPBOARD_PASTE:
        case LFUN_CLIPBOARD_PASTE_SIMPLE: