Tip: Finding views in ResourceIdentifiers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Tip: Finding views in ResourceIdentifiers

Louis Sumberg
I've had occasion where I subclass a view (e.g., MyTextEdit), then create or
edit a view in the ViewComposer with the new subview, do some testing, and
then rename or delete the new subview without changing the view.  When I
bring up VC on the view it won't load.  So I wrote the following snippet of
code (that can be displayed or inspected in a workspace) that checks what
ResourceIdentifiers use a given class:

(SessionManager current resourceManager allResourceIdentifiers) select:
[:resID |
    resID resource hiddenClassReferences includes: MyView]

To make things a little easier, I installed it as an instance method in
class Class, i.e.

!Class methodsFor!

findResourceIDs
 "Return a collection of all ResourceIdentifiers that reference the
receiver."

 ^SessionManager current resourceManager allResourceIdentifiers
  select: [:resID | resID resource hiddenClassReferences includes: self]! !
!Class categoriesFor: #findResourceIDs!accessing!public! !

This way you can just display "MyView findResourceIDs" or evaluate
"ListPresenter showOn: MyView findResourceIDs".  For example, displaying
"StaticIcon findResourceIDs" yields "an
OrderedCollection(ImagePresenter.Static icon TipOfTheDay.Default view)".

Now I make sure to run this method before renaming or deleting a subview.
Hopefully, this is of use to others.  Two questions I have are: 1) Does this
already exist and I reinvented the wheel? and 2) Is Class the logical place
for this to be?  (I chose Class over ResourceManager because, all things
being equal, it's shorter and easier to have "MyView findResourceIDs" then
"SessionManager current resourceManager findResourceIDs: MyView").

-- Louis