SetInspV.st
author Claus Gittinger <cg@exept.de>
Wed, 23 Jun 1999 18:04:06 +0200
changeset 2192 c7bce869223c
parent 2191 06957119a0ac
child 2193 3d7b1044e8c8
permissions -rw-r--r--
*** empty log message ***

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

!SetInspectorView class methodsFor:'documentation'!

documentation
"
    A modified inspector for Sets

    [author:]
        Stefan Vogel
"
!

examples
"
    #(a b c d e) asSet inspect
"
! !

!SetInspectorView methodsFor:'initialization'!

fieldMenu
    <resource: #programMenu >

    |menu|

    menu := super fieldMenu.
    menu addLabels:#(
                       '-'
                       'remove element'
                   )
         selectors:#(
                       nil 
                       doRemoveKey
                   ).

    ^ menu

    "Modified: / 29.10.1997 / 03:41:47 / cg"
! !

!SetInspectorView methodsFor:'private'!

defaultLabel
    ^ 'contents'

    "
     (Set with:1 with:2 with:3) inspect
    "

    "Modified: 28.6.1996 / 16:05:42 / cg"
!

fieldList 
    "return a list of names for the selectionlist."

    |aList l|

    inspectedObject isNil ifTrue:[^ #()].

    self topView withWaitCursorDo:[
        aList := inspectedObject class allInstVarNames asOrderedCollection.
        "/ hide Set stuff
        aList := aList copyFrom:(Set instSize + 1).
        hideReceiver ifFalse:[aList addFirst:'self'].

        keys := inspectedObject asSortedCollection:[:a :b | a displayString < b displayString].
        l := keys collect:[:k | k isSymbol ifTrue:[
                                                    k printString
                                                   ] ifFalse:[
                                                    k displayString
                                                   ]
                                             ].
        aList addAll:l.
    ].

    ^ aList


!

release 
    "release inspected object"

    keys := nil.
    super release

    "Created: 9.2.1996 / 12:04:30 / stefan"
! !

!SetInspectorView methodsFor:'user interaction'!

doAccept:theText
    "accept value for selected item"

    |value|

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

    inspectedObject add:value.
    inspectedObject changed.
    self inspect:inspectedObject


!

doRemoveKey
    "remove selected item from keys"

    |key idx|

    idx := selectedLine.
    (idx notNil and:[idx ~~ 1]) ifTrue:[
        idx := idx + Set instSize.
        idx <= inspectedObject class instSize ifTrue:[
            ^ self
        ].
        idx := idx - inspectedObject class instSize.

        key := keys at:idx.
        (inspectedObject includes:key) ifTrue:[
            listView cursor:(Cursor wait).
            inspectedObject remove:key.
            keys := nil.
            selectedLine := nil.
            inspectedObject changed.
            listView cursor:(Cursor hand).
            self inspect:inspectedObject. "force list update"
        ].
    ]


!

valueAtLine:lineNr
    "helper - return the value of the selected entry;
     Here, the key itself is the value."

    |key idx|

    idx := lineNr.
    hideReceiver ifFalse:[
        (lineNr == 1 or:[lineNr isNil]) ifTrue:[
            ^ inspectedObject
        ].
        idx := idx - 1.
    ].

    idx := idx + Set instSize.
    idx <= inspectedObject class instSize ifTrue:[
        ^ inspectedObject instVarAt:idx
    ].
    idx := idx - inspectedObject class instSize.

    key := keys at:idx.
    ^ key.

! !

!SetInspectorView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/Attic/SetInspV.st,v 1.10 1999-06-23 16:04:06 cg Exp $'
! !