diff --git a/src/Application.vala b/src/Application.vala index e9a39de..a6d7e43 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -68,7 +68,10 @@ public class Annotator : Gtk.Application { Process.exit( 1 ); } } else if( use_clipboard ) { - appwin.do_paste(); + if( !appwin.do_paste_image() ) { + stderr.printf( _( "\nERROR: Image does not exist on the clipboard\n" ) ); + Process.exit( 1 ); + } } else if( take_screenshot ) { appwin.do_screenshot(); } diff --git a/src/Clipboard.vala b/src/Clipboard.vala index 4aea834..720bb41 100644 --- a/src/Clipboard.vala +++ b/src/Clipboard.vala @@ -72,9 +72,10 @@ public class AnnotatorClipboard { } /* Called to paste current item in clipboard to the given Canvas */ - public static void paste( Editor editor ) { + public static bool paste( Editor editor, bool image_only = false ) { var clipboard = Display.get_default().get_clipboard(); + var retval = false; try { if( clipboard.get_formats().contain_mime_type( "image/png" ) ) { @@ -85,21 +86,26 @@ public class AnnotatorClipboard { editor.paste_image( pixbuf, true ); } }); - } else if( clipboard.get_formats().contain_mime_type( "application/xml" ) ) { + retval = true; + } else if( !image_only && clipboard.get_formats().contain_mime_type( "application/xml" ) ) { clipboard.read_async.begin( {"application/xml"}, 0, null, (obj, res) => { string str; var stream = clipboard.read_async.end( res, out str ); var contents = Utils.read_stream( stream ); editor.paste_items( contents ); }); - } else if( clipboard.get_formats().contain_gtype( Type.STRING ) ) { + retval = true; + } else if( !image_only && clipboard.get_formats().contain_gtype( Type.STRING ) ) { clipboard.read_text_async.begin( null, (obj, res) => { var text = clipboard.read_text_async.end( res ); editor.paste_text( text ); }); + retval = true; } } catch( Error e ) {} + return( retval ); + } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index beb029d..6e3b9f9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -505,12 +505,25 @@ public class MainWindow : Gtk.ApplicationWindow { _editor.canvas.do_cut(); } - /* Pastes text or images to the editor */ + /* Pastes clipboard contents to the editor. This may also paste only images, if specified. */ + private bool do_paste_internal( bool image_only ) { + if( AnnotatorClipboard.paste( _editor, image_only ) ) { + _welcome.sensitive = false; + _zoom_btn.set_sensitive( true ); + _export_btn.set_sensitive( true ); + return( true ); + } + return( false ); + } + + /* Pastes text, images or items to the editor */ public void do_paste() { - _welcome.sensitive = false; - AnnotatorClipboard.paste( _editor ); - _zoom_btn.set_sensitive( true ); - _export_btn.set_sensitive( true ); + do_paste_internal( false ); + } + + /* Pasts only an image from the clipboard to the editor */ + public bool do_paste_image() { + return( do_paste_internal( true ) ); } public void do_screenshot() {