DictionaryInspectorView.st
author claus
Tue, 28 Feb 1995 22:57:00 +0100
changeset 73 e332d9c71624
parent 57 36e13831b62d
child 77 bfb07ce94a87
permissions -rw-r--r--
*** empty log message ***

"
 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.11 1995-02-28 21:55:46 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.11 1995-02-28 21:55:46 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
	].
    ]
!

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

    |key|

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

doInspectKey
    "inspect selected items key"

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

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:'private'!

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

    |aList|

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

release 
    "release inspected object"

    keys := nil.
    super release
! !

!DictionaryInspectorView methodsFor:'initialization'!

fieldMenu
    |labels selectors|

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

    ^ PopUpMenu
	 labels:(resources array:labels)
	 selectors:selectors
! !