SetInspectorView.st
author Claus Gittinger <cg@exept.de>
Sat, 04 Oct 1997 19:54:57 +0200
changeset 1338 1acdf87256b7
parent 956 afea28c682be
child 1361 20c353524524
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
    |menu|

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

    ^ menu
! !

!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. Leave hasMore as
     true, if a '...' entry should be added."

    |aList|

    inspectedObject isNil ifTrue:[^ #()].

    self topView withWaitCursorDo:[
        keys := inspectedObject 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:29:45 / stefan"
    "Modified: 14.2.1997 / 18:26:04 / cg"
!

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|

    selectedLine == 1 ifFalse:[
        key := (keys at:selectedLine - 1).
        (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"

    |key|

    lineNr == 1 ifTrue:[
        ^ inspectedObject
    ].
    key := (keys at:lineNr - 1).
    ^ key.

    "Created: 9.2.1996 / 12:03:29 / stefan"
! !

!SetInspectorView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/SetInspectorView.st,v 1.7 1997-01-14 17:26:58 cg Exp $'
! !