Skip to content

Commit

Permalink
Merge pull request #664 from pharo-graphics/433-Deprecation-warning-i…
Browse files Browse the repository at this point in the history
…n-BlTextwhendo-Pharo-12

Deprecate BlText>>when:do: and upgrade a couple of uses
  • Loading branch information
tinchodias authored Dec 5, 2024
2 parents 1e8e36e + 28ca176 commit 4dccc31
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Bloc-Text-Tests/BlRopedTextTest2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ BlRopedTextTest2 >> testAppendEmptyText [
wasAnnounced := 0.
aText
when: BlTextStringsInserted
do: [ wasAnnounced := wasAnnounced + 1 ].
do: [ wasAnnounced := wasAnnounced + 1 ]
for: self.

aText , '' asRopedText.

Expand All @@ -61,7 +62,8 @@ BlRopedTextTest2 >> testInsertEmptyStrings [
insertedStrings := #( ).
aText
when: BlTextStringsInserted
do: [ :anAnnouncement | insertedStrings := anAnnouncement strings ].
do: [ :anAnnouncement | insertedStrings := anAnnouncement strings ]
for: self.

aText insertStrings: { ''. 'World' } atAll: { 1. 5 }.

Expand Down
32 changes: 31 additions & 1 deletion src/Bloc-Text/BlText.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ BlText >> allSatisfy: aBlock [
{ #category : #'text - notifying' }
BlText >> announcerDo: aBlockClosure [
"Evaluate a given block closure with an announcer as an argument if it is initialized"

announcer ifNotNil: aBlockClosure
]

Expand Down Expand Up @@ -282,6 +283,7 @@ BlText >> encodeOn: aWriteStream with: aZnCharacterEncoder [

{ #category : #'text - notifying' }
BlText >> ensureAnnouncer [

announcer ifNil: [ announcer := BlTextAnnouncer new ]
]

Expand Down Expand Up @@ -572,6 +574,7 @@ BlText >> notifyStringsInserted: aCollectionOfStrings atAll: aCollectionOfFinalI

{ #category : #copying }
BlText >> postCopy [

announcer := nil
]

Expand Down Expand Up @@ -670,6 +673,7 @@ BlText >> stylerDo: aBlock [

{ #category : #'text - notifying' }
BlText >> suspendAnnouncementsWhile: aBlock [

announcer
ifNil: aBlock
ifNotNil: [ :anAnnouncer | anAnnouncer suspendAllWhile: aBlock ]
Expand Down Expand Up @@ -745,12 +749,38 @@ BlText >> utf8Encoded [

{ #category : #'text - notifying' }
BlText >> when: anAnnouncementClass do: aValuable [
"Extracted on Pharo12's implementation."

| subscriberForDeprecation |
aValuable receiver ifNil: [
self error:
'You must specify a subscriber object for this subscription. Please use #when:do:for: method.' ].

subscriberForDeprecation := thisContext sender receiver = aValuable receiver
ifTrue: [ 'self' ]
ifFalse: [ '`@arg2 receiver' ].
self
deprecated:
'Since there are some block closures (Clean and Constant) without a receiver, the API of announcements was changed to send the subscriber explicitly.
We are deprecating this method because it was asking for the receiver of the block to use it as the subscriber.'
transformWith: '`@receiver when: `@arg1 do: `@arg2'
->
('`@receiver when: `@arg1 do: `@arg2 for: '
, subscriberForDeprecation).

self when: anAnnouncementClass do: aValuable for: aValuable receiver
]

{ #category : #'text - notifying' }
BlText >> when: anAnnouncementClass do: aValuable for: aSubscriber [

self ensureAnnouncer.
announcer when: anAnnouncementClass do: aValuable
announcer when: anAnnouncementClass do: aValuable for: aSubscriber
]

{ #category : #'text - notifying' }
BlText >> when: anAnnouncementClass send: aSelector to: anObject [

self ensureAnnouncer.
announcer weak when: anAnnouncementClass send: aSelector to: anObject
]
Expand Down

0 comments on commit 4dccc31

Please sign in to comment.