DictionaryInspectorView.st
author claus
Mon, 10 Oct 1994 04:16:24 +0100
changeset 45 950b84ba89e6
parent 36 ccde5a941840
child 52 7b48409ae088
permissions -rw-r--r--
*** empty log message ***

"{ Package: 'Programming Tools' }"

"
 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  comment:'
COPYRIGHT (c) 1993 by Claus Gittinger
              All Rights Reserved

$Header: /cvs/stx/stx/libtool/DictionaryInspectorView.st,v 1.7 1994-10-10 03:15:31 claus Exp $
'!

!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.
"
!

version
"
$Header: /cvs/stx/stx/libtool/DictionaryInspectorView.st,v 1.7 1994-10-10 03:15:31 claus Exp $
"
!

documentation
"
    a modified Inspector for Dictionaries
"
! !

!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
        ].
    ]
!

doInspect
    "inspect selected item"

    |k objectToInspect|

    selectedLine notNil ifTrue:[
        selectedLine == 1 ifTrue:[
            objectToInspect := inspectedObject
        ] ifFalse:[
            k := (keys at:selectedLine - 1).
            objectToInspect := inspectedObject at:k.
        ].
        objectToInspect inspect
    ]
!

showSelection:lineNr
    "user clicked on an instvar - show value in workspace"

    |val string|

"
    workspace contents:nil.
"
    lineNr == 1 ifTrue:[
        "selecting self also does a re-set, this allows updating the list"
        self inspect:inspectedObject.
        val := inspectedObject
    ] ifFalse:[
        val := inspectedObject at:(keys at:lineNr - 1)
    ].
    string := val displayString.
    workspace replace:string.
    selectedLine := lineNr
!

doAddKey
    "add a key"

    |keyName key|

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

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"
        ].
    ]
!

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
        ].
    ]
! !

!DictionaryInspectorView methodsFor:'accessing'!

listOfNames
    "return a list of names for the selectionlist"

    |aList|

    aList := OrderedCollection new.
    keys := inspectedObject keys asSortedCollection:[:a :b | a printString < b printString].
    keys do:[:aKey |
        aList add:(aKey printString)
    ].
    aList addFirst:'self'.
    ^ aList
!

release 
    "release inspected object"

    keys := nil.
    super release
! !

!DictionaryInspectorView methodsFor:'initialization'!

initializeListViewMiddleButtonMenus
    |labels selectors|

    inspectedObject == Smalltalk ifTrue:[
        labels := resources array:#(
                                   'inspect'
                                   'references'
                                   '-'
                                   'add key'
                                   'remove key').
        selectors := #(doInspect doReferences nil doAddKey doRemoveKey).
    ] ifFalse:[
        labels := resources array:#(
                                   'inspect'
                                   '-'
                                   'add key'
                                   'remove key').
        selectors := #(doInspect nil doAddKey doRemoveKey).
    ].

    menu1 := (PopUpMenu
                                   labels:(resources array:labels)
                                selectors:selectors
                                 receiver:self
                                      for:listView).
    workspace acceptAction:[:theText | self doAccept:theText asString]
! !