-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Context: Pharo 12.
Problem
When finishing the chapter "Managing windows" of the Spec book, I investigated why the code in the section "Setting the icon" does not work.
After careful inspection of the code, I conclude that setting the taskbar icon for a window is not implemented correctly. It seems that the code is a mix of old and new ways to set the icon of a window in the taskbar.
Root cause
Look at SpPresenter>>#initializeWindow::
initializeWindow: aWindowPresenter
"override this to set window values before opening.
You may want to add a menu, a toolbar or a statusbar"
"IMPORTANT: Please ovirride this method and set yourself the informations you want in your window.
The content of this method is here to help the transition between Spec 1 and 2.
In the next Spec version the content of this method will be removed and it will do nothing by default because the goal is to remove the management of all of those informations from Composable to put them in WindowPresenter."
aWindowPresenter
title: self title;
initialExtent: self initialExtent;
windowIcon: self windowIconSending windowIcon: self windowIcon does not have an effect. The analysis below describes why.
SystemWindow>>#taskbarTask does this:
taskbarTask
"Answer a taskbar task for the receiver.
Answer nil if not required."
(self valueOfProperty: #noTaskbarTask ifAbsent: [false]) ifTrue: [^nil].
taskbarTask := TaskbarTask
morph: self
state: self taskbarState
icon: (self iconNamed: self taskbarIconName)
label: self taskbarLabel.
^taskbarTaskand SystemWindow>>#taskbarIconName does this:
taskbarIconName
"Answer the icon for the receiver in a task bar."
self model ifNotNil: [
self model taskbarIconName
ifNotNil: [ :aName | ^aName ] ].
^ super taskbarIconNameWhich means that the model of a window should respond to taskbarIconName. In Spec applications, the model is a SpWindowPresenter. That class does not implement taskbarIconName. It inherits it from Object:
Object>>#taskbarIconName
"Answer the icon for the receiver in a task bar
or nil for the default."
^self class taskbarIconNameand Object class implements:
taskbarIconName
"Answer the icon for an instance of the receiver in a task bar"
^#smallWindowDue to this implementation, all Spec windows in the task bar are shown with the #smallWindow icon. And there is no way to change it!
Here is an example that does not work as expected. StPlaygroundPresenter has this method to specify the taskbar icon:
windowIcon
^ self application iconNamed: #workspacebut that method is never invoked, and therefore playground windows show up like this in the taskbar:
This icon should be shown according to the intentions of the StPlaygroundPresenter class:
Suggested solution
Suppose one creates a subclass of SpPresenter. Then it would be nice to configure the associated SpWindowPresenter as follows:
initializeWindow: aWindowPresenter
aWindowPresenter
taskbarIconName: #thumbsUp;
title: 'Test'So that the taskbars shows:
instead of
This does not require many changes. First, SpWindowPresenter requires a new slot:
#taskbarIconName => ObservableSlotand accessors:
taskbarIconName
^ taskbarIconName ifNil: [ super taskbarIconName ]
taskbarIconName: anIconNameSymbol
taskbarIconName := anIconNameSymbol@estebanlm Please tell me whether this is the way to go. If so, I will create a PR. If not, let's discuss here and/or at the Pharo Sprint on May 31, 2024.