[Gambas-user] TextEdit copy&Paste and removal of hyper tags
stderr
ihedenius at ...43...
Mon Oct 5 16:33:21 CEST 2009
Benoît Minisini wrote:
Thanks for replying.
>
> Why don't you use the Text property instead, that normally returns the
> text
> without the tags?
No it doesn't (?). By 'Text property' I assume you mean "TextEdit.Text".
TextEdit.Text will contain tags as soon as the control gets edited or
TextEdit.text is assigned. That's fine, it's what it's supposed to do. I use
the tags, but I also want to extract the plain text (with all UTF-8 codes
preserved).
New example. For the purpose of this example I pasted the comment "“abc”"
into the TextEdit control and then clicked 'Button1'. I added PRINTs for
stuff I thought interesting.
PUBLIC SUB Button1_Click()
' “abc”
TextEdit1.SelectAll()
TextEdit1.Copy()
PRINT Clipboard.Paste()
PRINT TextEdit1.Text
PRINT Clipboard.Type
PRINT Clipboard.format
PRINT Clipboard.formats[0]
PRINT Clipboard.formats[1]
PRINT Clipboard.formats[2]
PRINT Clipboard.formats[3]
END
Console:
?abc?
<html><head><meta name="qrichtext" content="1" /></head><body
style="font-size:12pt;font-family:Helvetica">
<p>“abc”</p>
</body></html>
1
text/plain
text/plain;charset=UTF-8
text/plain;charset=ISO-10646-UCS-2
text/plain
application/x-qrichtext
"?abc?" is the copypaste output. Next is 'TextEdit1.Text' (with tags). "1"
belongs to Clipboard.Type etc ...
> Did you look at all the different format that could be stored in the
> clipboard
> after .Copy() and before .Paste()?
I looked at Clipboard (gb.qt) documentation again. This time I noticed that
Clipboard "Paste" offers the optional argument "Format". Sounds promising
but doesn't appear to do what I want.
I edited the example above and tried each of the four mime types to see what
would happen:
Clipboard.Paste("text/plain;charset=UTF-8")
Clipboard.Paste("text/plain;charset=ISO-10646-UCS-2")
Clipboard.Paste("text/plain")
Clipboard.Paste("application/x-qrichtext")
The first two produces no printout while the last two produces the same
printout as plain "Clipboard.Paste()" i.e. the printout: "?abc?".
In the original post I indicated that special character "ö" 'works' with
Copy&Paste. Well, sort of. The UTF-8 code for "ö" hex "C3 B6" gets
transformed to dec 246. Which had me headscratching until I found that 246
is HTML code for "ö". See
http://personalwebs.oakland.edu/~grossman/ascii.codes.html here . So either
'clipboard.paste' or 'textedit.copy', transforms from UTF-8 to HTML code.
>Maybe I will find some time to make a new rich text editor control based on
a
>Qt 4 widget for Gambas 3. Anyway, I don't see a lot of solutions for your
>problem!
I can always parse 'TextEdit.Text' and remove tags 'manually'. I'm fine with
that.
'TextArea' control behaves the same. So whatever it is is common to TextEdit
and TextArea.
stderr
--
View this message in context: http://www.nabble.com/TextEdit-copy-Paste-and-removal-of-hyper-tags-tp25666934p25751932.html
Sent from the gambas-user mailing list archive at Nabble.com.
More information about the User
mailing list