Spec icon indicating copy to clipboard operation
Spec copied to clipboard

About whenResizingDo:

Open Ducasse opened this issue 11 months ago • 2 comments

I improved the logic of the size remembering and now it also pays attention to resizable I wrote tests https://github.com/pharo-spec/Spec/pull/1739

But now Im seeing that the block of the whenResizingDo: is invoked when we do not resize but when the extent: is set.

aWindowPresenter
		title: self windowTitle;
		initialExtent: self class preferredExtent;
		windowIcon: self windowIcon;
		"Pay attention preferredExtent: is used here because it is stateful
		in the sense that it will set the preferred extent to be remembered.
		Of course only when resizable allows it."

		whenResizingDo: [ :ann | aWindowPresenter isResizable 
								ifTrue: [ self preferredExtent: ann newSize ]].
SpWindow >> extent: aPoint 
	| announcement oldExtent |

	oldExtent := self extent. 
	super extent: aPoint.
	announcement := SpWindowResizing new
		window: self;
		oldSize: oldExtent;
		newSize: aPoint;
		yourself.
	self announce: announcement.
		^^^^^^^^^^^^^^^^^^^^^^^^^^
	self currentWorld announcer announce: announcement

So it breaks the logic because I cannot distinguish between window is opened with a size window is resized by the user.

Even worse it is called each time we move the window with the mouse. This is not a resize. so the logic of extent: is wrong.

I changed extent:

extent: aPoint 
	| announcement oldExtent |
	oldExtent := self extent. 
	super extent: aPoint.
	
	oldExtent = aPoint
		ifFalse: [  
			self haltOnce.
			"we have a size change so a resize" 	
	announcement := SpWindowResizing new
		window: self;
		oldSize: oldExtent;
		newSize: aPoint;
		yourself.
	self announce: announcement.
	self currentWorld announcer announce: announcement ]

Now we get a resize only when the extent is different. When the window is opened it has a default extent: But

initialize
	"Initialize a system window. Add label, stripes, etc., if desired"

	super initialize.
	labelString ifNil: [labelString := 'Untitled Window'].
	isCollapsed := false.
	paneMorphs := Array new.
	self layoutPolicy: ProportionalLayout new.
	self clipSubmorphs: true.
	self theme
		configureWindowBorderFor: self;
		configureWindowDropShadowFor: self.
	self initializeLabelArea.

	self cellPositioning: #topLeft. "make the offsets easy to calculate!"
	self addGripsIfWanted.

	self extent: (300 @ 200) scaledByDisplayScaleFactor.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

	mustNotClose := false.
	updatablePanes := Array new.
	self bindKeyCombination: ($k meta shift alt ) toAction: [self taskbarMoveLeft ].
	self bindKeyCombination: ($l meta shift alt) toAction: [self taskbarMoveRight ]

I tried to remove it and it broke Pharo.

So I added a new variable to the SpPresenter metaclass and redefined

initializeWindow: aWindowPresenter
	"override this to set window values before opening, but always do a super send message. You may want to add a menu, a toolbar or a statusbar."

	"IMPORTANT: please always include
	initializeWindow: aWindowPresenter
		
		super initializeWindow: aWindowPresenter
		your code
		
	"
	
	"Since the system raises one notification of resize for every size changes, 
	we cannot distinguish between a extent set by the system and a resize by the users.
	so we use this trick to get more context and deduce a user one."

	self class setByInteraction: true.
	
	aWindowPresenter
		title: self windowTitle;
		initialExtent: self class preferredExtent;
		windowIcon: self windowIcon;
		"Pay attention preferredExtent: is used here because it is stateful
		in the sense that it will set the preferred extent to be remembered.
		Of course only when resizable allows it."

		whenResizingDo: [ :ann | aWindowPresenter isResizable 
									ifTrue: [ self preferredExtent: ann newSize ]].
preferredExtent: aPoint
	"Since the system raises one notification of resize for every size changes, 
	we cannot distinguish between a extent set by the system and a resize by the users. So we use this trick to get more context and deduce a user one."
	
	self setByInteraction ifTrue: [ 
		customExtent := aPoint ]

setByInteraction

	^ setByInteraction ifNil: [ setByInteraction := false ]

This way it works.

Ducasse avatar Mar 03 '25 12:03 Ducasse

No it does not work :(

Ducasse avatar Mar 03 '25 13:03 Ducasse

Will have to debug this.

Ducasse avatar Mar 03 '25 13:03 Ducasse