Levente Uzonyi uploaded a new version of ShoutCore to project The Inbox:
http://source.squeak.org/inbox/ShoutCore-ul.65.mcz ==================== Summary ==================== Name: ShoutCore-ul.65 Author: ul Time: 9 July 2019, 11:00:06.496443 pm UUID: 5b4b23fe-b7de-4498-a16b-80959cfb1e62 Ancestors: ShoutCore-mt.64 Further SHTextStyler refactorings: - replaced text instance variable with temporiaries - removed monitor. backgroundProcess consistency is ensured by atomic execution of certain instructions - assume that view is never nil. It makes no sense to style when there's no view, and view is always assigned once, when a styler instance is created =============== Diff against ShoutCore-mt.64 =============== Item was changed: Object subclass: #SHTextStyler + instanceVariableNames: 'backgroundProcess view stylingEnabled' - instanceVariableNames: 'backgroundProcess text monitor view stylingEnabled' classVariableNames: '' poolDictionaries: '' category: 'ShoutCore-Styling'! !SHTextStyler commentStamp: 'tween 8/27/2004 10:54' prior: 0! I am an Abstract class. Subclasses of me can create formatted, coloured, and styled copies of Text that is given to them. They may perform their styling asynchronously, in a background process which I create and manage. My public interface is... view: aViewOrMorph - set the view that will receive notifications when styling has completed. format: aText - modifies aText's string style: aText - modifies the TextAttributes of aText, but does not change the string, then sends #stylerStyled: to the view. styleInBackgroundProcess: aText - performs style: in a background process, then sends #stylerStylednBackground: to the view. styledTextFor: aText - answers a formatted and styled copy of aText unstyledTextFrom: aText - answers a copy of aText with all TextAttributes removed Subclasses of me should re-implement... privateFormat: aText - answer a formatted version of aText; the String may be changed privateStyle: aText - modify the TextAttributes of aText; but do not change the String ! Item was removed: - ----- Method: SHTextStyler>>monitor (in category 'private') ----- - monitor - ^monitor ifNil: [monitor := Monitor new]! Item was changed: ----- Method: SHTextStyler>>style: (in category 'styling') ----- style: aText + + | text | self terminateBackgroundStylingProcess. + stylingEnabled ifFalse: [ ^self ]. + text := aText copy. + self privateStyle: text. + view stylerStyled: text! - stylingEnabled ifTrue:[ - text := aText copy. - self privateStyle: text. - view ifNotNil:[view stylerStyled: text] ]! Item was changed: ----- Method: SHTextStyler>>styleInBackgroundProcess: (in category 'styling') ----- styleInBackgroundProcess: aText + | text newBackgroundProcess | self terminateBackgroundStylingProcess. + stylingEnabled ifFalse: [ ^self ]. + text := aText copy. + newBackgroundProcess := [ + self privateStyle: text. + Project current addDeferredUIMessage: [ + view stylerStyledInBackground: text ]. + Processor activeProcess == backgroundProcess ifTrue: [ + backgroundProcess := nil ] ] newProcess + priority: Processor userBackgroundPriority; + yourself. + backgroundProcess ifNil: [ + (backgroundProcess := newBackgroundProcess) resume ]! - - stylingEnabled ifTrue: [ - text := aText copy. - self monitor critical: [ - backgroundProcess := [ - self privateStyle: text. - view ifNotNil: [:v | Project current addDeferredUIMessage: [v stylerStyledInBackground: text]]. - ] forkAt: Processor userBackgroundPriority] ] - ! Item was changed: ----- Method: SHTextStyler>>terminateBackgroundStylingProcess (in category 'private') ----- terminateBackgroundStylingProcess + "Terminate the background styling process if it exists. Assume that the first two lines are executed atomically." + backgroundProcess ifNotNil: [ :backgroundProcessToTerminate | + backgroundProcess := nil. + backgroundProcessToTerminate terminate ]! - self monitor critical: [ - backgroundProcess - ifNotNil: [ - backgroundProcess terminate. - backgroundProcess := nil]].! Item was changed: ----- Method: SHTextStyler>>veryDeepInner: (in category 'copying') ----- veryDeepInner: aDeepCopier + super veryDeepInner: aDeepCopier. + backgroundProcess := nil. - backgroundProcess := monitor := nil. - text := text veryDeepCopyWith: aDeepCopier. view := view veryDeepCopyWith: aDeepCopier! |
Hi Levente, nice! :-) For the background process, I would either closure "view" or check for nil because any do-it in the UI process might re-configure the styler. Best, Marcel
|
Hi Marcel,
Thanks for the feedback. I checked the senders of #view: and didn't see the possibility of setting it to nil. Based on the current usage, it could even be a "constructor" parameter. I have the following senders in my image: - MorphicToolBuilder >> #buildPluggableText: - the argument will be the result of a #new send - PBClassPreferenceView >> #textField - the argument will be a PluggableTextMorphPlus - PluggableTextMorphPlus >> #useDefaultStyler - the argument will be a PluggableTextMorphPlus By the way, what should the styler do with the styled text when view is nil? Levente On Wed, 10 Jul 2019, Marcel Taeumel wrote: > Hi Levente, > nice! :-) For the background process, I would either closure "view" or check for nil because any do-it in the UI process might re-configure the styler. > > Best, > Marcel > > Am 09.07.2019 23:00:45 schrieb [hidden email] <[hidden email]>: > > Levente Uzonyi uploaded a new version of ShoutCore to project The Inbox: > http://source.squeak.org/inbox/ShoutCore-ul.65.mcz > > ==================== Summary ==================== > > Name: ShoutCore-ul.65 > Author: ul > Time: 9 July 2019, 11:00:06.496443 pm > UUID: 5b4b23fe-b7de-4498-a16b-80959cfb1e62 > Ancestors: ShoutCore-mt.64 > > Further SHTextStyler refactorings: > - replaced text instance variable with temporiaries > - removed monitor. backgroundProcess consistency is ensured by atomic execution of certain instructions > - assume that view is never nil. It makes no sense to style when there's no view, and view is always assigned once, when a styler instance is created > > =============== Diff against ShoutCore-mt.64 =============== > > Item was changed: > Object subclass: #SHTextStyler > + instanceVariableNames: 'backgroundProcess view stylingEnabled' > - instanceVariableNames: 'backgroundProcess text monitor view stylingEnabled' > classVariableNames: '' > poolDictionaries: '' > category: 'ShoutCore-Styling'! > > !SHTextStyler commentStamp: 'tween 8/27/2004 10:54' prior: 0! > I am an Abstract class. > Subclasses of me can create formatted, coloured, and styled copies of Text that is given to them. > They may perform their styling asynchronously, in a background process which I create and manage. > > My public interface is... > > view: aViewOrMorph - set the view that will receive notifications when styling has completed. > > format: aText - modifies aText's string > > style: aText - modifies the TextAttributes of aText, but does not change the string, then sends #stylerStyled: to the view. > > styleInBackgroundProcess: aText - performs style: in a background process, then sends #stylerStylednBackground: to the view. > > styledTextFor: aText - answers a formatted and styled copy of aText > > unstyledTextFrom: aText - answers a copy of aText with all TextAttributes removed > > Subclasses of me should re-implement... > > privateFormat: aText - answer a formatted version of aText; the String may be changed > privateStyle: aText - modify the TextAttributes of aText; but do not change the String > > > > > ! > > Item was removed: > - ----- Method: SHTextStyler>>monitor (in category 'private') ----- > - monitor > - ^monitor ifNil: [monitor := Monitor new]! > > Item was changed: > ----- Method: SHTextStyler>>style: (in category 'styling') ----- > style: aText > + > + | text | > self terminateBackgroundStylingProcess. > + stylingEnabled ifFalse: [ ^self ]. > + text := aText copy. > + self privateStyle: text. > + view stylerStyled: text! > - stylingEnabled ifTrue:[ > - text := aText copy. > - self privateStyle: text. > - view ifNotNil:[view stylerStyled: text] ]! > > Item was changed: > ----- Method: SHTextStyler>>styleInBackgroundProcess: (in category 'styling') ----- > styleInBackgroundProcess: aText > > + | text newBackgroundProcess | > self terminateBackgroundStylingProcess. > + stylingEnabled ifFalse: [ ^self ]. > + text := aText copy. > + newBackgroundProcess := [ > + self privateStyle: text. > + Project current addDeferredUIMessage: [ > + view stylerStyledInBackground: text ]. > + Processor activeProcess == backgroundProcess ifTrue: [ > + backgroundProcess := nil ] ] newProcess > + priority: Processor userBackgroundPriority; > + yourself. > + backgroundProcess ifNil: [ > + (backgroundProcess := newBackgroundProcess) resume ]! > - > - stylingEnabled ifTrue: [ > - text := aText copy. > - self monitor critical: [ > - backgroundProcess := [ > - self privateStyle: text. > - view ifNotNil: [:v | Project current addDeferredUIMessage: [v stylerStyledInBackground: text]]. > - ] forkAt: Processor userBackgroundPriority] ] > - ! > > Item was changed: > ----- Method: SHTextStyler>>terminateBackgroundStylingProcess (in category 'private') ----- > terminateBackgroundStylingProcess > + "Terminate the background styling process if it exists. Assume that the first two lines are executed atomically." > > + backgroundProcess ifNotNil: [ :backgroundProcessToTerminate | > + backgroundProcess := nil. > + backgroundProcessToTerminate terminate ]! > - self monitor critical: [ > - backgroundProcess > - ifNotNil: [ > - backgroundProcess terminate. > - backgroundProcess := nil]].! > > Item was changed: > ----- Method: SHTextStyler>>veryDeepInner: (in category 'copying') ----- > veryDeepInner: aDeepCopier > + > super veryDeepInner: aDeepCopier. > + backgroundProcess := nil. > - backgroundProcess := monitor := nil. > - text := text veryDeepCopyWith: aDeepCopier. > view := view veryDeepCopyWith: aDeepCopier! > > > > |
Hi Levente, hmmm... I think the styler should silently discard the results then. Okay, if the view became nil somehow, there shouldn't be too many debuggers anyway. So, it's unlikely and not even risky for the entire environment if it would happen. Well, messing around with instances of styler might not be as dangerous as is fiddling in the caverns of text rendering. :-) So, just ignore my over-cautious thoughts on this ifNil:-check on "view". Thinking too hard about "exploratory" and "liveness" and "reflection" and "long-running systems" can raise too many concerns... Best, Marcel
|
You've reminded of a question I've meant to ask before; why does Shout need to be done in a separate process? It means we are rendering the text twice. What was the original reason for the process? Does it still make sense?
tim -- tim Rowledge; [hidden email]; http://www.rowledge.org/tim Fractured Idiom:- LE ROI EST MORT. JIVE LE ROI - The King is dead. No kidding. |
So there are not delays between what's typed and what's rendered. On Wed, Jul 10, 2019 at 11:31 AM tim Rowledge <[hidden email]> wrote: You've reminded of a question I've meant to ask before; why does Shout need to be done in a separate process? It means we are rendering the text twice. What was the original reason for the process? Does it still make sense? |
> On 2019-07-10, at 10:32 AM, Chris Muller <[hidden email]> wrote: > > So there are not delays between what's typed and what's rendered. OK, but I can say from experience that it didn't do a very good job of that on a slow machine (e.g. the original Pi with the non-cog vm) where the only way to get tolerable typing response was to uninstall it! tim -- tim Rowledge; [hidden email]; http://www.rowledge.org/tim Everybody repeat after me....."We are all individuals." |
Hi Tim, hi Chris, Shout uses a background process only for texts larger than 4095 characters. See PluggableTextMorphPlus >> #setText:. In all other cases, text styling is synchronuous. Counting local Trunk image, that's - for example - for only 153 out of 61043 methods. So 0.003%. I have no idea, where this character threshold comes from. :-) Maybe that should be reduced for slow machines? Best, Marcel
|
Hi, all. Yeah, I overlooked PluggableTextMorphPlus >> #udpateStyle, which is called after every keystroke. There, it is background-styling all the time. :-) Not sure, why. Immediate styling would reduce some flickering for fast typists. Best, Marcel
|
Free forum by Nabble | Edit this page |