. .


Adding a Custom Tab to the Smalltalk Browser

June 8, 2010 21:48:53.338

This is a written companion piece to this morning's screencast - I'm going to cover how to add a custom tab to the browser. The example I'm using is simple - every class understands the method #printHierarchy, which gives you a textual hierarchy diagram. At one time, that was a view possibility in the browser (circa 5i). Today, we'll add that back in a tab. To start, create a new package:

With that package created, we need a UI for the tab. It's a simple one, with a text widget filling the canvas. Using the UIPainter, create something like this:

Once that's created, install it as a subclass of Refactory.Browser.CodeTool. Select the "other" drop down option in the install tool and enter that in:

With that installed, we need to write some code - in this case, three instance side methods:

	^self classOrNameSpace notNil

#isActive is sent to determine whether or not the tab should be visible. In this example, it should only be there if a class or namespace is selected. You an examine the methods in class CodeTool to see what's easily possible. Next, the tab needs a name:

	^'Print Hierarchy'

Finally, something needs to actually happen when the tab is selected; we'll add a #postBuildWith: method to fill our text widget with the text for the "diagram"

postBuildWith: bldr
	| classOrNamespace |
	super postBuildWith: bldr.

	classOrNamespace := codeModel classOrNameSpace.
	self printText value: classOrNamespace printHierarchy

That's almost enough. What we need to do now is tell the browser that our new extension exists. To do that, we'll extend class CodeModel

Go to the class side, and add this method:



The part in brackets is a pragma. The code simply tells the browser what class to throw into our tab. That's it; open a new browser, and select a class:

Now, select a class, and watch your new tab in action:

You can download the code here, or just head over to the Public Store Repository and load the RBPrintHierarchyTool package

Technorati Tags: ,

posted by James Robertson

 Share Tweet This