fl_message copy/paste

20 views
Skip to first unread message

Rob McDonald

unread,
Feb 8, 2022, 6:29:31 PM2/8/22
to fltk.general
Is it possible to enable the end-user to copy the text from a fl_message to the OS clipboard?

I'm not interested in making the fl_message work with drag-n-drop events or an application specific clipboard.  When I use a fl_message to display an error message to my users, I'd like for them to be able to copy/paste that message into an email for error reporting (and other use cases).

My wish is that this would be a simple behavior flag to turn on/off.  I suspect it will involve inheriting a custom fl_message_copyable and implementing an event handler with some magic sauce...  I have no experience with the system clipboard through FLTK, so I'm not sure where to start here.

Best,

Rob

Bill Spitzak

unread,
Feb 8, 2022, 7:47:16 PM2/8/22
to fltkg...@googlegroups.com
This would be easy to implement if a method could be figured out to trigger the copy to be made to the clipboard.

For X it may be enough to just set the "secondary selection" (what you paste with middle-mouse click) when the dialog is created. However I don't know if this is a good idea for the primary selection and that is the only thing that works on Windows.

Maybe clicking the text, or the icon, should cause a copy to the clipboard. Would prefer not to add a widget to the dialog just for this purpose.


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/a129daa1-035e-4837-82c2-7ba7f209df83n%40googlegroups.com.

Albrecht Schlosser

unread,
Feb 8, 2022, 7:47:41 PM2/8/22
to fltkg...@googlegroups.com
On 2/9/22 00:29 Rob McDonald wrote:
> Is it possible to enable the end-user to copy the text from a
> fl_message to the OS clipboard?

I thought of this already but didn't do anything yet. I'm sure this
would be doable, either with a shortcut like ctrl/c or by adding a
"copy" button (as I've seen elsewhere).

> I'm not interested in making the fl_message work with drag-n-drop
> events or an application specific clipboard.  When I use a fl_message
> to display an error message to my users, I'd like for them to be able
> to copy/paste that message into an email for error reporting (and
> other use cases).

Please open a GitHub issue, title maybe "[RFE] <your text here>".

> My wish is that this would be a simple behavior flag to turn on/off. 
> I suspect it will involve inheriting a custom fl_message_copyable and
> implementing an event handler with some magic sauce...

There will be a way, but maybe not before the 1.4.0 release. We can also
add it later if we don't need to break the ABI.

> I have no experience with the system clipboard through FLTK, so I'm
> not sure where to start here.

If you want to copy something to the clipboard Fl::copy() is your friend
although this will not help with fl_message() unless you patch it.

https://fltk.gitlab.io/fltk/group__fl__clipboard.html#gafe46352043c48d38b090203db417c398

Albrecht Schlosser

unread,
Feb 8, 2022, 7:54:38 PM2/8/22
to fltkg...@googlegroups.com
On 2/9/22 01:47 Bill Spitzak wrote:
> This would be easy to implement if a method could be figured out to
> trigger the copy to be made to the clipboard.
>
> Maybe clicking the text, or the icon, should cause a copy to the
> clipboard. Would prefer not to add a widget to the dialog just for
> this purpose.

Clicking the icon would be cute but I think we can also make the text
"selectable" and handle ctrl/c to copy it or something like that.

Rob McDonald

unread,
Feb 8, 2022, 8:16:30 PM2/8/22
to fltk.general
On Tuesday, February 8, 2022 at 4:54:38 PM UTC-8 Albrecht Schlosser wrote:
On 2/9/22 01:47 Bill Spitzak wrote:

Thanks for the input Albrecht and Bill.

Making the text selectable and allowing Ctrl-C to work would be the most desirable end state.

I will think about adding an explicit copy button.  That might work in the interim.

Rob

 

Bill Spitzak

unread,
Feb 8, 2022, 8:46:12 PM2/8/22
to fltkg...@googlegroups.com
Probably just having Ctrl+C work would be good enough and is probably the best idea. I think the code needed to highlight the message as though it was selected would be too much work.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.

Ian MacArthur

unread,
Feb 9, 2022, 3:29:54 AM2/9/22
to fltk.general
As a "pragmatic" short-term solution, you could make a fl_message-alike dialog that wraps a flat Fl_Output widget to get the Ctrl-C working.


I mention this only because I recall doing just that, at some time in the past when I needed basically this functionality (and also the message was sometimes loooong, but the dialog was fixed size, so scroll-bars etc...)
But I can't now find that code or I'd post it. Bother.
And now that I type this, it might have been a Fl_Help_View widget rather than Fl_Output anyway, but you get the idea anyway.


Albrecht Schlosser

unread,
Feb 9, 2022, 10:49:34 AM2/9/22
to fltkg...@googlegroups.com
I implemented ctrl-c (command-c on macOS) to copy the entire text w/o
explicit selection.

If the new implementation is sufficient I'd like to leave it like this
in 'master':

commit f6c2531b5b4d939352dccd9f8295f4471d7e1c4c
Author: Albrecht Schlosser <albrech...@online.de>
Date:   Wed Feb 9 16:32:48 2022 +0100

    Enable end user to copy standard dialog text to clipboard (#388)

    All standard dialogs like fl_message() now handle command-c (macOS)
    and ctrl-c (other platforms) to copy the message text of standard
    dialogs to the clipboard as requested by GitHub Issue #388.


See https://github.com/fltk/fltk/issues/388

FTR: The current implementation is based on the label of an Fl_Box
widget. Changing this to make the text selectable would need another
widget (maybe Fl_Output as Ian suggested) but that would likely require
more work.

Reply all
Reply to author
Forward
0 new messages