[Gambas-user] TextEdit copy&Paste and removal of hyper tags

Benoît Minisini gambas at ...1...
Fri Oct 2 21:37:55 CEST 2009


> hi,
> 
> I wanted to make a text editor that recognized hyper links. So I used
> 'TextEdit'. To extract the plain text I tried to use SelectAll + Copy +
> Paste like this:
> 
> PUBLIC SUB Form_Open()
>   DIM txt AS String
> 
>   PRINT "“abc”"
>   TextEdit1.Text = "“abc”"
>   TextEdit1.SelectAll()
>   TextEdit1.Copy()
>   txt = Clipboard.Paste()
>   PRINT txt
> 
> END
> 
> “abc”
> ?abc?
> 
> but noticed that while it handles some special characters (like 'ö') other
> gets lost (and replaced by '?'). Above example uses 'Left & Right double
> quotation mark's which are lost and replaced by '?' (code 63).

Did you look at all the different format that could be stored in the clipboard 
after .Copy() and before .Paste()?

Why don't you use the Text property instead, that normally returns the text 
without the tags?

> 
> So it seems the only option is to parse the 'TextEdit1.Text' buffer or some
> special characters are lost.
> 
> By trial and error I've noted that if I set 'TextEdit.ReadOnly=true' it
>  will remove all hypertext tags. Except when it doesn't. I don't know how
>  to predict when the 'TextEdit1.Text' buffer will contain hypertext tags
>  and when it will not.
> 
> Is there a way to remove the hypertext links that always works ? Or make it
> predictable (which amounts to the same thing).

I'm afraid all that is a wrong path, as it depends on the way TextEdit 
internally works, and I can hardly do anything about that. TextEdit is 
intended to be a small rich text editor, not a HTML editor. There is some 
hyperlink detection, but as you noticed it seems to be a bit strange. 
Moreover, TextEdit is based on a deprecated Qt 3 widget.

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!

> 
> * Can the latest stable version (2.16.0) coexist with my current straight
> from 'Debian lenny' repository 2.7 ? I.e. can I have both installed ?

The easy answer is no. Only different major version of Gambas can be installed 
on the same system without clash.

But you can install two versions of gambas 2.x inside two different 
directories by hand, and switch between both by hand too (by rewriting all the 
/usr/bin/gb* symbolic links). You must know what you do then!

Regards,

-- 
Benoît Minisini




More information about the User mailing list