Last time I said we would show how to allow multiple selection of protocols, and show all of the methods associated with them in the list of methods. Before I show you the one line of code that enables that, we have to talk about one set of the features of all enumeration panes.
Which right there brings up the question: "What Do I Mean By 'Enumeration Panes'?" In Pollock, any pane that has a list/collection like object as it's model is considered an enumeration pane. In Pollock, these are ListBox, TreeView and Grid. In actual fact, all of these panes are subclassed from an abstract class named "EnumerationPane."
All of these panes have many things in common. They can have scrollbars, they have search as you type lookup and other things. In our case, we're focusing on the fact that all of these panes have both a single-select and multi-select mode. When you are selecting things from one of these panes in single select mode, you can use one of the following methods to get the current selection:
selection - <Answers the current object that is selected, or nil if no object is selected>
selectionIndex - <Answers the current linear selection index that is selected, or 0 if no object is selected>
When you are selecting things from one of these panes in multi-select mode, you can use one of the following methods to get a collection of the current selections
selections - <Answers a collection of the objects that are selected, in the order they were selected, or an empty collection if no object is selected>
selectionIndexs - <Answers a collection of the current linear selection indexes, in the order they were selected that is selected, or an empty collection if no object is selected>
Here is were Pollock goes one step further... Both sets of these methods are available and meaningful in the "other" mode.
In Single Select mode, the following is true:
selections - <Answers a collection of the selected object, or an empty collection if no object is selected>
selectionIndexs - <Answers a collection of the current linear selection indexes, or an empty collection if no object is selected>
In Multi-Select mode, the following is true:
selection - <Answers a the last item selected, or nil if no object is selected>
selectionIndex - <Answers the linear selection index of the last item selected, or an empty collection if no object is selected>
Why does Pollock bother to do this? Because you can dynamically, at runtime, change the mode of an enumeration pane from multi to single select or visa versa.
In our case, we don't need to change the mode dynamically, but, we do want to turn it to multi-select for the protocol list box. All enumeration panes are single select by default when they are created. Here's the code changes the modes:
Now all we have to do is change two methods in our ClassHierarchyBrowser. First, we need to change our createInterface to add the line to change the protocol list box to be multi-select:
Then we want to (but don't actually have to) change our use of #selection to #selections in our #fillMethodList method, as well as use a different lookup method for the selectors. While we're at it, we'll add code to sort the selectors:
The above is published as version 1.9 in the Package named "PollockBlog" on the Cincom public repository.
Let's open the result and see
ClassHierarchyBrowser open.
I told you it was E-Z! Now, you'll notice you can do multiple select in the protocol list. Clicking on one protocol and then another changes the methods. Ctrl clicking adds or removes a protocol to the selections. Shift clicking adds all items from the first selection to the current mouse point. And all the keyboard selection and navigation works as you would expect... including Ctrl-A to select all protocols
That was simple. Our Class Hierarchy Browser is pretty nice, but, it would be nicer if we could resize the panes. So, next time, we'll show you how to add ResizingSplitters to our browser, so we can resize the panes.