DictionaryInspectorView.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Jul 1998 23:15:03 +0200
changeset 1740 5dd8db18c0cf
parent 1665 7e3fc40e26ad
child 1742 982fa0fdf9e3
permissions -rw-r--r--
added show references

"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

InspectorView subclass:#DictionaryInspectorView
	instanceVariableNames:'keys'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Inspector'
!

!DictionaryInspectorView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    a modified Inspector for Dictionaries

    [author:]
        Claus Gittinger
"
! !

!DictionaryInspectorView methodsFor:'menu'!

fieldMenu
    <resource: #programMenu >

    |items m|

    inspectedObject == Smalltalk ifTrue:[
        items := #(
                       ('inspect'              doInspect      )
                       ('inspect key'          doInspectKey   )
                       ('basicInspect'         doBasicInspect )
                       ('inspect hierarchical' doNewInspect   )
                       ('references'           showReferences )
                       ('references to key'    showKeyReferences )
                       ('-'                    nil            )
                       ('add key'              doAddKey       )
                       ('remove key'           doRemoveKey    )
                   ).
    ] ifFalse:[
        items := #(
                       ('inspect'              doInspect      )
                       ('inspect key'          doInspectKey   )
                       ('basicInspect'         doBasicInspect )
                       ('inspect hierarchical' doNewInspect   )
                       ('references'           showReferences )
                       ('-'                    nil            )
                       ('add key'              doAddKey       )
                       ('remove key'           doRemoveKey    )
                   ).
    ].

    monitorProcess isNil ifTrue:[
        items := items , #(
                       ('-'                nil            )
                       ('start monitor'    doStartMonitor )
                          ).
    ] ifFalse:[
        items := items , #(
                       ('-'                nil            )
                       ('stop monitor'     doStopMonitor  )
                          ).
    ].

    m := PopUpMenu itemList:items resources:resources.

    selectedLine isNil ifTrue:[
        m disableAll:#(doInspect doInspectKey doBasicInspect doNewInspect
                       doRemoveKey doStartMonitor doStopMonitor
                      )
    ].
    ^ m.

    "Modified: / 21.5.1998 / 13:25:10 / cg"
! !

!DictionaryInspectorView methodsFor:'menu actions'!

doAddKey
    "add a key"

    |keyName key|

    keyName := Dialog request:'key to add:' initialAnswer:''.
    keyName notEmpty ifTrue:[
	key := keyName asSymbol.
	(inspectedObject includesKey:key) ifFalse:[
	    inspectedObject at:key put:nil.
	    selectedLine := nil.
	    inspectedObject changed.
	    self inspect:inspectedObject. "force list update"
	]
    ]
!

doInspectKey
    "inspect selected items key"

    selectedLine notNil ifTrue:[
	selectedLine ~~ 1 ifTrue:[
	    (keys at:selectedLine - 1) inspect
	].
    ]
!

doReferences
    "show users of selected key (i.e. global)"

    |k|

    selectedLine notNil ifTrue:[
	selectedLine == 1 ifFalse:[
	    k := (keys at:selectedLine - 1).
	    SystemBrowser browseReferendsOf:k asSymbol
	].
    ]
!

doRemoveKey
    "remove selected item from keys"

    |key|

    selectedLine == 1 ifFalse:[
	key := (keys at:selectedLine - 1).
	(inspectedObject includesKey:key) ifTrue:[
	    listView cursor:(Cursor wait).
	    inspectedObject removeKey:key.
	    keys := nil.
	    selectedLine := nil.
	    inspectedObject changed.
	    listView cursor:(Cursor hand).
	    self inspect:inspectedObject. "force list update"
	].
    ]
!

showKeyReferences
    "show users of selected key (i.e. global)"

    |k|

    selectedLine notNil ifTrue:[
        selectedLine == 1 ifFalse:[
            k := (keys at:selectedLine - 1).
            self withWaitCursorDo:[
                SystemBrowser browseReferendsOf:k asSymbol
            ]
        ].
    ]

! !

!DictionaryInspectorView methodsFor:'private'!

defaultLabel
    ^ 'keys'

    "Created: 28.6.1996 / 19:46:51 / cg"
!

fieldList 
    "return a list of names for the selectionlist. Leave hasMore as
     true, if a '...' entry should be added."

    |aList|

    inspectedObject isNil ifTrue:[^ #()].

    self topView withWaitCursorDo:[
        keys := inspectedObject keys asSortedCollection:[:a :b | a displayString < b displayString].
        aList := keys collect:[:k | k isSymbol ifTrue:[
                                                    k printString
                                                   ] ifFalse:[
                                                    k displayString
                                                   ]
                                             ].
        aList := aList asOrderedCollection.
        hideReceiver ifFalse:[aList addFirst:'self'].
    ].
    ^ aList

    "Modified: 8.5.1996 / 14:16:35 / stefan"
    "Modified: 14.2.1997 / 18:26:29 / cg"
!

release 
    "release inspected object"

    keys := nil.
    super release
! !

!DictionaryInspectorView methodsFor:'user interaction'!

doAccept:theText
    "accept value for selected item"

    |value|

    value := Compiler evaluate:theText receiver:inspectedObject notifying:workspace.

    selectedLine notNil ifTrue:[
	selectedLine == 1 ifFalse:[
	    inspectedObject at:(keys at:selectedLine - 1) put:value.
	    inspectedObject changed
	].
    ]
!

valueAtLine:lineNr
    "helper - return the value of the selected entry"

    |key idx|

    hideReceiver ifTrue:[
        idx := lineNr.
    ] ifFalse:[
        (lineNr == 1 or:[lineNr isNil]) ifTrue:[
            ^ inspectedObject
        ].
        idx := lineNr - 1.
    ].
    key := keys at:idx.
    ^ inspectedObject at:key ifAbsent:nil.

    "Modified: 30.7.1996 / 17:44:50 / cg"
! !

!DictionaryInspectorView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/DictionaryInspectorView.st,v 1.30 1998-07-23 21:15:03 cg Exp $'
! !