Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button API seems unfriendly for changing click action #44

Closed
tinchodias opened this issue Jun 2, 2023 · 4 comments
Closed

Button API seems unfriendly for changing click action #44

tinchodias opened this issue Jun 2, 2023 · 4 comments

Comments

@tinchodias
Copy link
Collaborator

This is because whenClickedDo adds a new event handler for click each time. Example:

| but lab ico pane |
pane := ToPane new.
lab := ToLabel new text: 'Button'; yourself.
ico := ToImage inner: (self iconNamed: #remove).
pane addChildren: { ico. lab }.
but := ToGeneralButton new
	dresser: ToGeneralButtonDresser new;
	addChild: pane;
	whenClickedDo: [ self inform: '1' ];
	whenClickedDo: [ self inform: '2' ];
	yourself.
but openInOBlSpace 

it pop ups 2 messages each time.

@plantec
Copy link
Collaborator

plantec commented Jun 2, 2023

In general, the whenXXXXDo: pattern leads to this kind of issue.
I have to think about it

@tinchodias
Copy link
Collaborator Author

A possible solution: the button has in initialize:

action := [].
self whenClickedDo: [ action value ]

and it's prepared to somebody that updates the valuable via action:. And there is a single "official action" of the button.

@tinchodias
Copy link
Collaborator Author

It could be more efficient to remember in the button the event handler, and that the mutator method updates the block in the event handler. But not sure how much more efficient.

@plantec
Copy link
Collaborator

plantec commented Jun 28, 2023

the event handler is now stored so that it can be replaced or removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants