I am having a problem trying to mutate a MultilineTextEdit into a
RichTextEdit. After having done the mutation in the ViewComposer and after having changed the Shell subclass's #createComponents to use a RichTextPresenter instead of a TextPresenter I try showing the shell, but this gives the error message "UndefinedObject does not understand #setTextInto:". It seems that the text property of the RichTextEdit is nil when it's #text: method is evaluated. If I simply resume when the error has occurred, the RichTextEdit works properly. If I delete RichTextEdit>>displayValue: (instead causing TextEdit>>displayValue: to be evaluated) the error disappears and everything appears to work correctly. Have I done something wrong when mutating, or can RichTextEdit>>displayValue: be removed without causing any other problems? Best regards, Mikael Svane |
I have now examined this a bit more and there is some problem mutating the
MultilineTextEdit into the RichTextEdit in the VC, because if I create a new view in the VC with the RichTextEdit in it from the beginning, RichTextEdit>>displayValue: works fine. This reproduces the problem (at least in Dolphin 5.1.1 professional edition on Windows XP): - create a Shell subclass, for example called RichTextShell. - add an instance variable called richTextPresenter to the new class. - write a #createComponents method that looks like this: createComponents super createComponents. richTextPresenter := self add: RichTextPresenter new name: 'text' - create a new view in the VC. The view should contain a TextPresenter Multiline Text. Name it 'text'. - save the view as 'Default view'. - mutate the MultilineTextPresenter into a RichTextPresenter. - save the view again. - in a workspace, evaluate 'RichTextShell show'. - this gives the walkback that I described in my first post. I suppose that this is some bug in the mutating process? After successfully having created a view with a RichTextEdit, I would like to show text in bold, in italics and in different fonts and colours and in combinations of the above in it. I have examined RichText, RichTextEdit, RichTextPresenter and of course Google without finding out how to do this. It looked like RichTextEdit>>beBold could be of some use, but I can't get that to work. This is what I tried in a workspace: rtp := RichTextPresenter show. rtp view value: (RichText fromString: 'Plain text'). "this works. Plain text is shown." rtp toggleBold. rtp view value: (RichText fromString: 'Bold text'). "the text is changed but is not bold." trp view isBold "this answers true" Anyway, i presume that this only allows me to make the entire text bold (or in italics) and I must be able to change the appearance on every word (or every character) in the text. Any help on how to do this is very much appreciated. Best regards, Mikael Svane |
"Mikael Svane" <[hidden email]> wrote in message
news:bmkfr0$nofo0$[hidden email]... .... > Anyway, i presume that this only allows me to make the entire text bold (or > in italics) and I must be able to change the appearance on every word (or > every character) in the text. Any help on how to do this is very much > appreciated. I don't know much about how the control methods do formating, but for something simple you could generate the RTF yourself. For example: rtp := RichTextPresenter show. rtp view value: (RichText fromString: 'Plain text {\b Bold text } Plain again'). If what you need is more complex then you could make your own RTF generator or find one. I think Ian has a "kind of report generator" ( http://www.idb.me.uk/goodies5/changes.html#5g ) that might be of use. Chris |
In reply to this post by Mikael Svane
"Mikael Svane" <[hidden email]> wrote in message
news:bmkfr0$nofo0$[hidden email]... > I have now examined this a bit more and there is some problem mutating the > MultilineTextEdit into the RichTextEdit in the VC, because if I create a new > view in the VC with the RichTextEdit in it from the beginning, > RichTextEdit>>displayValue: works fine. This reproduces the problem (at > least in Dolphin 5.1.1 professional edition on Windows XP): > ...[snip]... Thanks, I've recorded this as defect #1344. It is worth noting that generic "Mutate View" is not 100% reliable and may lose information, fail, or produce an invalid result. In some cases this may be unavoidable (at least at reasonable effort). It is sometimes necessary to patch up the resulting view. In this case the mutate fails because the MultilineTextEdit allows a nil model value, but the RichTextEdit does not. As you found out, it is safe to continue through the walkback. I certainly wouldn't recommend removing RichTextEdit>>displayValue:, as although this will prevent the walkback occurring on mutate, it will mean that only plain text strings can be set into the RTE, losing all formatting. This is because the TextEdit implementation sends #displayString to the argument, and RichText implements #displayString by converting itself to a plain text string. > ... > After successfully having created a view with a RichTextEdit, I would like > to show text in bold, in italics and in different fonts and colours and in > combinations of the above in it. I have examined RichText, RichTextEdit, > RichTextPresenter and of course Google without finding out how to do this. > It looked like RichTextEdit>>beBold could be of some use, but I can't get > that to work. This is what I tried in a workspace: > ....[snip]... Try this: rtp := RichTextPresenter show. rtp value: 'Plain text'. rtp selectionRange: (0 to: -1). "move caret to end" rtp toggleBold. rtp replaceSelection: 'Bold text'. The emboldening affects only the "selected" text, or any new text you append if the format is set at the end of the text. Another example: rtp selectionRange: (6 to: 10). rtp toggleItalic. However changing the format of the text like this is really only useful in an editor, or for small jobs. If you want to style large quantities of text it will be too slow and will probably cause the display to flash unpleasantly. Your best bet is to generate RTF in the first place as Chris Demers suggests. Regards Blair |
In reply to this post by Christopher J. Demers
Chris and Blair,
Thanks a lot for the help. Since I don't need to use the more complicated aspects of RTF, I have decided to make a small package that extends RichText with a few methods. Best regards, Mikael Svane |
Free forum by Nabble | Edit this page |