Doug Blank
Doug Blank

Reputation: 2289

How to connect Copy/Paste/Select/Cut menu items to Gtk# widgets?

How do you create menu items in Gtk# that are correctly handled by all of the possible widgets? I have added Copy/Paste/etc Actions in the Gtk# menu, but how does that get passed to whatever widget has the focus? Do you need to connect up something for every possible widget?

For example, I'd like to be able to Copy from Gtk.Labels and Gtk.TextAreas, and Paste to Gtk.Entries and Gtk.TextAreas. Likewise, the Paste menu option should not be Sensitive when on, say, a read-only Gtk.TextArea.

Related, I would like to be able to copy/paste between applications, and this should work on Linux, Mac, and Windows.

Any pointers appreciated! Would love to see a simple example in C# that handles this correctly. I'm working in MonoDevelop, BTW.

Upvotes: 0

Views: 1053

Answers (1)

ptomato
ptomato

Reputation: 57930

I have a simple example in C, in any case. See the functions action_cut(), action_copy(), and action_paste() in this file: https://github.com/ptomato/gnome-inform7/blob/master/src/actions.c

If you want to keep your actions sensitive or insensitive depending on which widget has the focus, you will need to connect to some signal that tells you when the focus changes and then adjust the sensitivity of those actions accordingly. Off the top of my head, that would be notify::focus-child.

Upvotes: 2

Related Questions