Gtk+2 Clipboard - handling EOL better on paste or copy/cut?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Gtk+2 Clipboard - handling EOL better on paste or copy/cut?

David C. Rankin
All,

  I have a simple editor project I've been tinkering with
(https://github.com/drankinatty/gtkwrite) and I've implemented EOL handling
for LF, CRLF, and CR to accommodate Linux/Unix/OSX, DOS/Win, and Mac
(pre-OSX). I've run into a question on implementing the EOL in text pasted
from the clipboard.

  By default, all cut/copy/paste operations use LF. If I understand the
clipboard documentation, I should be able to use:

  gtk_clipboard_request_text

with the:

  (*GtkClipboardTextReceivedFunc) callback

so that when a request to paste text is made, I can call
gtk_clipboard_request_text, pass the callback (which will scan the text in the
clipboard, (and if necessary allocate a larger buffer to handle inserting CR
before LF to make CRLF), pass the EOL flag to determine which to change to as
the 'gpointer *data', and finally returning a pointer to the reformatted
clipboard text through the 'text' parameter to the callback (or NULL if
something fails).

  My question is -- does this sound sane? To handle the EOL fix only for text
*pasted* into the textview buffer, or is it better to handle the EOL fix
during copy/paste so the text in the clipboard is formatted for the host OS?

(my thought was to just do it on paste)

  Basically, I have a variable that holds (0,1,2) that serves as a flag for
EOL type (based on an 'enum eolorder { LF, CRLF, CR };') that I can pass as
the pointer to the callback to allow the EOL adjustments to be made.

  Does this approach sound reasonable, or like one I'll spend 1/2 day coming
to regret?


--
David C. Rankin, J.D.,P.E.
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Gtk+2 Clipboard - handling EOL better on paste or copy/cut?

David C. Rankin
On 07/31/2017 02:05 AM, David C. Rankin wrote:
>   Does this approach sound reasonable, or like one I'll spend 1/2 day coming
> to regret?

It was... something to regret (but was solved without regret...)

  I decided to write the conversion routine first -- it answered the question.
You don't care what format the cut/copy/paste end-of-line is. You simply
handle the conversion on file-save, or run though the range of lines after
paste providing the conversion 'in-buffer' on a per-paste basis. Much simpler.


(Win32 builds need the conversion on a per-paste basis due to the way
'indention' is handled, on Linux/Unix you can just do a one-time conversion on
save)

--
David C. Rankin, J.D.,P.E.
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Loading...