Adding "browse" to system menus 
Author Message
 Adding "browse" to system menus

Some time ago, I enhanced some of the menus in my development
tools (VW1.0) by adding a "browse" entry along with the "do it"
"print it" and "inspect".  I've gotten to the point that I can't live
without the feature and thought others might like it also, so I'm posting
this messages to let people know about it.

The "browse" feature works like "do it", in that you selcet some
code which gets compiled and executed, but instead of showing you
the resulting object, a browser is opened on the class of the object.

Before adding this entry to the menus, I found I had to spend a lot
of time either typing class names or searching for classes in
browsers.  Now I almost never have to.

If the code you are looking at makes a reference to a class, like:

   list := OrderedCollection new.

And you decided you want to browse the OrderedCollection class, all you
have to do is select the class name and pick browse.

If I'm debugging some code which blew up on a "Does not understand"
signal, then I can click on self in the debuger - which displays
the class name of the object, then double click the name to select
it and then use "browse" to browse the class.

I find this much easer than trying to use the copy feature to get
the class name into the paste buffer, or having to type the name,
or typing "browse" after the expresion and using "doit".

If people are interested, I can post the code (for VW1.0) - the changes are
very simple, but you have to make them in multiple places.

I've only used VW1.0, so for all I know, this feature has been added
in VW2.0 or already exists in other verisons of Smalltalk.

Curt



Sun, 16 Nov 1997 03:00:00 GMT  
 Adding "browse" to system menus

Quote:

>Some time ago, I enhanced some of the menus in my development
>tools (VW1.0) by adding a "browse" entry along with the "do it"
>"print it" and "inspect".  I've gotten to the point that I can't live
>without the feature and thought others might like it also, so I'm posting
>this messages to let people know about it.
>If people are interested, I can post the code (for VW1.0) - the changes are
>very simple, but you have to make them in multiple places.

I got a few requests for the code, so here it is.  This is comming from:

'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992
ENVY/Developer R1.41 of 1 February 1993 on 1 June 1995 at 9:47:37 am'!

Which is VisualWorks 1.0.  I don't know if this code works in VW 2, or
any other version of Smalltalk.  I also haven't tried to actuall file
in of this in to a new image, so I don't know for sure I've packaged
it all correctly....

Anyway, the main change is the new brosweIt method in ParagrahEditor and
the change to the initialize method which defines the menu.  To make
the change show up in all the places where there's a "do it" on the menu
you have to modify mutiple methods that define menus.  I've included
code below for the Inspector and Tools objects.  You can find others
by browsing variable refs to: printIt.

The Tools object seems to have a lot to do with Envy, so I'm not sure
if my mod to it will work in a non-Envy system.  (I don't have easy
access to a non-Envy version of VW to check.)

Note that for windows like the Worksapce, you must open a new
Workspace to see the new menu.  Your old Workspace will continue to
have the old version of the menu.

Good luck,
Curt

'--- Begin mods for browseIt ------------------------------------------'!
!ParagraphEditor methodsFor: 'menu messages'!

browseIt
        | it compileError |
        compileError := false.
        it := self class compilationErrorSignal
                handle: [:ex | compileError := true. ex return]
                do: [self evaluateSelection].
        compileError ifTrue: [^self].
        [it class class ~= Metaclass] whileTrue: [it := it class].
        HierarchyBrowser newOnClass: it.! !

!ParagraphEditor methodsFor: 'menu processing'!

localMenuItem: selector
        "Answer whether selector is one of the operate button menu items
        for the receiver."

        ^#(#cut #paste #copySelection #again #undo #cancel #accept #alwaysAccept #hardcopy #toggleWordWrap #doIt #printIt #inspectIt #browseIt #changeTextStyle #align) includes: selector! !

!ParagraphEditor class methodsFor: 'class initialization'!

initialize
        "Initialize the yellow button menu information, the keyboard map for special
        control characters, and the shared buffers for copying text across views and
        managing undo."

        "ParagraphEditor initialize."
        PreviousSelections := OrderedCollection with: ' ' asText.
        self currentSelection: (self undoSelection: Text new).
        TextEditorYellowButtonMenu :=
                PopUpMenu labels: 'again\undo\copy\cut\paste\accept\cancel' withCRs
                                        lines: #(2 5 )
                                        values: #(again undo copySelection cut paste accept cancel).
        CodeYellowButtonMenu :=
                PopUpMenu
                        labelList: #((again undo) (copy cut paste) ('do it' 'print it' 'inspect' 'browse') (accept cancel) (hardcopy))
                        values: #(again undo copySelection cut paste doIt printIt inspectIt browseIt accept cancel hardcopy).
        self initializeDispatchTable.
        CompilationErrorSignal := (self errorSignal newSignalMayProceed: true)
                notifierString: 'Compilation failed';
                nameClass: self message: #compilationErrorSignal.! !

!Inspector methodsFor: 'text'!

textMenu
        "Answer a Menu of operations on the text of the selected
        variable's value that is to be displayed when the operate menu
        button is pressed."
        "Inspector flushMenus"
        TextMenu == nil ifTrue:
                [TextMenu := PopUpMenu
                        labelList: #((again undo) (copy cut paste) ('do it' 'print it' 'inspect' browse) (accept cancel) (hardcopy))
                        values: #(again undo copySelection cut paste doIt printIt inspectIt browseIt accept cancel hardcopy)].
        ^ TextMenu! !

!Tools class methodsFor: 'Envy'!

textMenu
        "Answer a Menu of operations on the source code that is to         be displayed when the operate menu button is pressed."
        "Evaluate if this method is changed:  TextMenu := nil "

        TextMenu == nil ifTrue: [
                TextMenu := PopUpMenu
                        labelList: #((again undo) (copy cut paste) ('do it' 'print it' inspect browse) (accept cancel) (format explain) (hardcopy))
                        values: #(again undo copySelection cut paste doIt printIt inspectIt browseIt accept cancel format:from: explain:fromController: hardcopy)].
        ^TextMenu! !

!Tools class methodsFor: 'Envy'!

textMenuReset
        "Force a rebuild of the menu - needed with Envy"
        TextMenu := nil.
! !

ParagraphEditor initialize.!
Inspector flushMenus.!
Tools textMenuReset.!

'--- End mods for browseIt ------------------------------------------'!



Mon, 17 Nov 1997 03:00:00 GMT  
 Adding "browse" to system menus

Quote:
>If people are interested, I can post the code (for VW1.0) - the changes are
>very simple, but you have to make them in multiple places.

>I've only used VW1.0, so for all I know, this feature has been added
>in VW2.0 or already exists in other verisons of Smalltalk.

Sounds nice. Pleas post!

--------------------------------------------------------------------------------

CVI (Dutch Rail Automation)             Phone: +31 (0)30 924486
PO Box 2233, 3500 GE  Utrecht       Fax: +31 (0)30 924235
The Netherlands



Tue, 18 Nov 1997 03:00:00 GMT  
 Adding "browse" to system menus


Quote:
>Some time ago, I enhanced some of the menus in my development
>tools (VW1.0) by adding a "browse" entry along with the "do it"
>"print it" and "inspect".  I've gotten to the point that I can't live
>without the feature and thought others might like it also, so I'm posting
>this messages to let people know about it.

That's a great idea, Kurt.  Hope you don't mind if I swipe it for an edIt
extension (I'll credit you).  For those of you using edIt, I've posted the
code below. I've also been putting these on the Smalltalk archive at
st.cs.uiuc.edu, as well as in Digitalk's Compuserve Third Party library.

Ken Cooper
Cooper & Peters, Inc.

------------------------ CUT HERE ---------------------------

"This filein contains an edIt extension that provides functionality
similar to the Show It command.  Instead of printing the result of
the selected expression, Browse It brings up a ClassHierarchyBrowser
on the class of the result.

Kudos to Curt Welch for providing the idea (he wrote similar functionality
for VisualWorks 1.0).

Category: Code Execution
Key Binding: Ctrl-Y+Ctrl-B

Methods:
  CPBaseEdIt>>browseIt
  CPEdIt>>browseIt
  Object>>browsableClass
  Class>>browsableClass
  MetaClass>>browsableClass
"!

!CPBaseEdIt methods!
browseIt

     | result |

     self selectionEmpty ifTrue: [
         self selectCurrentLine
     ].

     CursorManager execute changeFor: [
         result := (self evaluate: self selectionString ifError: [ ^self ]) browsableClass.
     ].

    ClassHierarchyBrowser new openSelecting: result.! !

!CPEdIt methods!
browseIt

    self mainEditor browseIt.! !

!Object methods!
browsableClass

    #addedByCnP.
    ^self class! !

!Class methods!
browsableClass

    #addedByCnP.
    ^self! !

!MetaClass methods!
browsableClass

    #addedByCnP.
    ^self instanceClass! !

CPCategoryManager current addMethod: #browseIt inClass: #CPEdIt toCategory: 'Code Execution'.
CPKeyBindingsSet current bindKey: 'Ctrl-Y+Ctrl-B' toSelector: #browseIt inClass: #CPEdIt.!



Tue, 18 Nov 1997 03:00:00 GMT  
 Adding "browse" to system menus


Quote:
> '--- Begin mods for browseIt ------------------------------------------'!
> !ParagraphEditor methodsFor: 'menu messages'!

> browseIt
>         | it compileError |
>         compileError := false.
>         it := self class compilationErrorSignal
>                 handle: [:ex | compileError := true. ex return]
>                 do: [self evaluateSelection].
>         compileError ifTrue: [^self].
>         [it class class ~= Metaclass] whileTrue: [it := it class].
>         HierarchyBrowser newOnClass: it.! !

Adding browse to the text edit menus helps out a lot.  We use the AT Class
Reporter to
check for errors etc.  It produces a report that will list problems with
methods.  I made the
 following change to browseIt (VW2) so that by selecting a method, I could
bring up
a methodListBrowser.  If the selection doesn't match a method, then it
falls thru to the
original browseIt.

browseIt

   (self selection isNil or: [self selection isEmpty])
   ifTrue:
   [
      view flash.
   ]
   ifFalse:
   [
      | xCollection |

      "Get a sorted collection of methods that match the given selection.
If none, try opening a Browser on"
      "the results of evaluating selection"

      ((xCollection := Browser allImplementorsOf: self selection asSymbol)
isEmpty not)
      ifTrue:
      [
         MethodListBrowser openListBrowserOn: xCollection label:
'Implementors of ' , self selection.
      ]
      ifFalse:
      [
         self class compilationErrorSignal handle:
         [
            :ex | view flash. ex return
         ]
         do:
         [
            | xResult |

            "Evaluate the selection, raising compilationErrorSignal if
anything goes wrong"

            xResult := self evaluateSelection.

            [
               xResult class class ~= Metaclass
            ]
            whileTrue:
            [
               xResult := xResult class
            ].
            HierarchyBrowser newOnClass: xResult.
         ].
      ].
   ].
   ^self.

--
regards,

dan gersten



Tue, 25 Nov 1997 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Adding menu to mac "system tray"

2. Control of System Menu "X"

3. IBM system 370 system call "DMXINV"

4. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

5. VSW: an "add:" replacement for SortedCollections

6. FileDrop[Combo] - Adding "Empty" item

7. Adding a "control" to a procedure

8. "Subtract C, add Ada"

9. Adding "()" operator to Ada 200X

10. "Subtract C, add Ada"

11. "Subtract C, add Ada"

12. "Subtract C, Add Ada": More Details

 

 
Powered by phpBB® Forum Software