Mercurial > octave
changeset 27554:d0f778462a51
Restore hability to copy figure to clipboard (bug #55970)
* __add_default_menu__.m: add "Edit>CopyFigure to Clipboard" menu that triggers
clipboard_cb callback.
(clipboard_cb): New callback that prints the figure to png and calls
F__event_manager_copy_image_to_clipboard__.
* event-manager.cc (F__event_manager_copy_image_to_clipboard__): New builtin
function to copy image from a PNG file to clipboard.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Fri, 27 Sep 2019 13:14:13 +0200 |
parents | 9b72eb111b7e |
children | c2f2fb1df9ed |
files | libinterp/corefcn/event-manager.cc scripts/plot/util/private/__add_default_menu__.m |
diffstat | 2 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/event-manager.cc Thu Oct 24 03:47:41 2019 -0400 +++ b/libinterp/corefcn/event-manager.cc Fri Sep 27 13:14:13 2019 +0200 @@ -564,3 +564,19 @@ return ovl (evmgr.unregister_doc (file)); } + +DEFMETHOD (__event_manager_copy_image_to_clipboard__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_copy_image_to_clipboard__ (@var{filename}) +Undocumented internal function. +@end deftypefn */) +{ + std::string file; + + if (args.length () >= 1) + file = args(0).string_value(); + + octave::event_manager& evmgr = interp.get_event_manager (); + evmgr.copy_image_to_clipboard (file); + return ovl (); +}
--- a/scripts/plot/util/private/__add_default_menu__.m Thu Oct 24 03:47:41 2019 -0400 +++ b/scripts/plot/util/private/__add_default_menu__.m Fri Sep 27 13:14:13 2019 +0200 @@ -62,6 +62,9 @@ "callback", "clf (gcbf ());"); uimenu (hui, "label", "Reset Figure", "callback", "reset (gcbf ());"); + uimenu (hui, "label", "Copy Figure to Clipboard", ... + "callback", @clipboard_cb, "separator", "on", ... + "accelerator", "c"); hmenu(2) = hui; ## Tools menu @@ -381,3 +384,17 @@ axis (hax, "auto"); endif endfunction + +function clipboard_cb (h) + hf = gcbf (); + fname = tempname (); + props = {"inverthardcopy", "paperposition", "paperpositionmode"}; + values = get (hf, props); + set (hf, "inverthardcopy", "off", "paperpositionmode", "auto"); + unwind_protect + print ("-r0", "-dpng", "-svgconvert", fname); + __event_manager_copy_image_to_clipboard__ (fname); + unwind_protect_cleanup + set (hf, props, values); + end_unwind_protect +endfunction