2

I am writing a text editor using gtk+-2.0 & gtksourceview-2.0. I am having trouble finding a way to programmatically select a block of text and add it to the OS (linux) primary selection clipboard. Just like if I hightlighted a block of text with the mouse or held down the shift key and selected the text with the arrow key.

I have found in devhelp under "gtk_text_buffer_get_selection_bound ()" the statement:

The currently-selected text in buffer is the region between the "selection_bound" and "insert" marks.

Edit: gtk_text_buffer_select_range (), sets the location of these two marks.

The following block of code copies, the region specified using the text iters start & end, to the primary selection clipboard (as desired):

            gtk_text_buffer_select_range (tbuffer, &start, &end); 
            GtkClipboard *cb = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
            gtk_text_buffer_copy_clipboard (tbuffer,cb);

Thanks for the ideas!!!

nomadicME
  • 1,389
  • 5
  • 15
  • 35

1 Answers1

1

Perhaps you should try gtk_editable_copy_clipboard (). The documentation says that "copies the contents of the currently selected content in the editable and puts it on the clipboard". Then paste using gtk_editable_paste_clipboard () which "pastes the content of the clipboard to the current position of the cursor in the editable."

PALEN
  • 2,784
  • 2
  • 23
  • 24
  • Take a look at this post http://stackoverflow.com/questions/10508810/find-out-which-gtk-widget-has-the-current-selection/10510123#10510123. – PALEN May 20 '12 at 22:46