SetInspectorView.st
author Claus Gittinger <cg@exept.de>
Mon, 02 Feb 2009 17:51:35 +0100
changeset 8526 5ecd6ffcfa6c
parent 7379 55d5b77c7136
child 11894 968f5c4e9b41
child 12123 4bde08cebd48
permissions -rw-r--r--
also show only the first nShown names; much better for big sets.

"
 COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG
              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.
"
"{ Package: 'stx:libtool' }"

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

!SetInspectorView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996 by Claus Gittinger / eXept Software AG
              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 Sets

    [author:]
        Stefan Vogel
"
!

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

!SetInspectorView methodsFor:'menu'!

fieldMenu
    <resource: #programMenu >

    |menu|

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

    (self keyIndexForLine:selectionIndex) isNil ifTrue:[
        menu disableAll:#(doRemoveKey)
    ].

    ^ menu

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

!SetInspectorView methodsFor:'private'!

baseInspectedObjectClass
    (inspectedObject class inheritsFrom:Set) ifFalse:[
        ^ Object
    ].
    ^ Set
!

defaultLabel
    ^ 'Contents'

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

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

derivedFields
    ^ Dictionary new
        declareAllNewFrom:(super derivedFields ? #());
        add:('-size' -> [ object size ]);
        yourself

    "Modified: / 09-10-2006 / 12:27:21 / cg"
!

indexList 
    "return a list of indexes to show in the selectionList.
     Set hasMore to true, if a '...' entry should be added."

    inspectedObject size > nShown ifTrue:[
        |coll|

        coll := (SortedCollection new:nShown) sortBlock:[:a :b | a displayString < b displayString].
        inspectedObject do:[:el |
            coll add:el.
            coll size >= nShown ifTrue:[ 
                hasMore := true.
                ^ coll
            ].
        ].
    ].

    ^ inspectedObject asSortedCollection:[:a :b | a displayString < b displayString].
!

indexedFieldList 
    "return a list of indexed-variable names to show in the selectionList.
     Set hasMore to true, if a '...' entry should be added."

    keys := self indexList.
    ^ keys collect:[:k | k isSymbol ifTrue:[
                             k printString
                         ] ifFalse:[
                             k displayString
                         ]
                   ].
!

release 
    "release inspected object"

    keys := nil.
    super release

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

showAllIndexedVarsInFieldList
    ^ false
! !

!SetInspectorView methodsFor:'user interaction'!

doRemoveKey
    "remove selected item from keys"

    |key idx|

    idx := self keyIndexForLine:selectionIndex.
    idx notNil ifTrue:[
        key := keys at:idx.
        (inspectedObject includes:key) ifTrue:[
            listView cursor:(Cursor wait).
            inspectedObject remove:key.
            keys := nil.
            selectionIndex := selectedLine := nil.
            inspectedObject changed.
            listView cursor:(Cursor hand).
            self reinspect.
        ].
    ]


!

indexedValueAtIndex:idx
    ^ keys at:idx
!

indexedValueAtKey:idx
    ^ keys at:idx
!

valueAtLine:lineNr put:newValue
    "store newValue;
     For non-named instvars, we add the new value - ignoring the selection"

    |idx|

    idx := self instVarIndexForLine:selectionIndex.
    idx notNil ifTrue:[
        inspectedObject instVarAt:idx put:newValue.
    ] ifFalse:[
        inspectedObject add:newValue.

"/        inspectedObject changed.
        self reinspect.
    ].


! !

!SetInspectorView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/SetInspectorView.st,v 1.25 2009-02-02 16:51:35 cg Exp $'
! !