pharo-spec / Spec

Spec is a framework in Pharo for describing user interfaces.
MIT License
62 stars 65 forks source link

Introduce SpMenuPresenter>>#fillWith: and add tests and example #1602

Closed koendehondt closed 1 month ago

koendehondt commented 2 months ago

Code changes for https://github.com/pharo-spec/Spec/issues/1601.

koendehondt commented 2 months ago

This change is important for the Spec book. Please merge the PR to Pharo 12 as well.

estebanlm commented 2 months ago

thing is, I removed this precisely for a reason: it does not produces a correct "DOM", and I cannot be sure that the resulting toolbar will be attached to a parent or an application (hence, I cannot know if backend will be right) :) In this case, I dropped this in favor of the fillWith: idiom, which will end working like this:

toolbar := self newToolbar.
toolbar fillWith: aCommandGroup
... etc...

and with this approach, I do not need two methods, since the configuration of the toolbar can happen where it is created.

estebanlm commented 2 months ago

uhm... but now I see that there are other idioms (asMenuPresenter, asMenuBarPresenter) in the same problem, I need to fix those too...

koendehondt commented 2 months ago

uhm... but now I see that there are other idioms (asMenuPresenter, asMenuBarPresenter) in the same problem, I need to fix those too...

Please do, so that we do not write wrong patterns in the Spec book. cc @Ducasse

Ducasse commented 2 months ago

Yes this is really painful to write a book more than people can think.

koendehondt commented 1 month ago

@estebanlm

thing is, I removed this precisely for a reason: it does not produces a correct "DOM", and I cannot be sure that the resulting toolbar will be attached to a parent or an application (hence, I cannot know if backend will be right) :) In this case, I dropped this in favor of the fillWith: idiom

I read the code and tried some examples. You are right. The fillWith: idom is the way to go. Sadly, there are 33 senders of SpCommandGroup>>#asMenuPresenter, which give bad examples to developers.

uhm... but now I see that there are other idioms (asMenuPresenter, asMenuBarPresenter) in the same problem, I need to fix those too...

Please read the changes in this PR. I adapted the code:

I will rename this PR to express the changes.

I did not:

The removal should be part of another Github ticket to clean up the senders. That is out of the scope of this ticket.

If you approve the changes, I will also be happy to make a PR for Pharo 12, as Pharo 12 is the stable version the Spec book is based on.

koendehondt commented 1 month ago

I forgot to mention: I fixed a bug in SpMenuBarPresenterTest. SpMenuBarPresenterTest>>#classToTest was missing, so that the test class used SpMenuPresenter as the class to test, not SpMenuBarPresenter.