Thread: [Gambas-user] TextEdit copy&Paste and removal of hyper tags
Brought to you by:
gambas
From: stderr <ihe...@ya...> - 2009-09-29 17:02:41
|
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). 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). * 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 ? Gambas 2.7 on Debian Lenny. regards, -- View this message in context: http://www.nabble.com/TextEdit-copy-Paste-and-removal-of-hyper-tags-tp25666934p25666934.html Sent from the gambas-user mailing list archive at Nabble.com. |
From: Benoît M. <ga...@us...> - 2009-10-02 19:38:17
|
> 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 |
From: stderr <ihe...@ya...> - 2009-10-05 14:33:36
|
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. |