ResourceSelectionBrowser.st
author tz
Mon, 26 Jan 1998 16:18:30 +0100
changeset 478 7ba29987cc0d
parent 477 857d4289a2bd
child 481 e2e1ea013229
permissions -rw-r--r--
do not save modified but empty help dicts

"
 COPYRIGHT (c) 1997 by eXept Software AG / Thomas Zwick
              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.
"


SelectionBrowser subclass:#ResourceSelectionBrowser
	instanceVariableNames:'resourceMethod resourceClass resourceSuperclass resourceTypes
		allClasses'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Advanced-Tools'
!

!ResourceSelectionBrowser class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG / Thomas Zwick
              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
"
    documentation to be added.
"
!

history
    "Created: / 10.1.1998 / 10:59:18 / tz"
! !

!ResourceSelectionBrowser class methodsFor:'instance creation'!

request: aTitle onSuperclass: aSuperclass andClass: aClass andSelector: aSelector withResourceTypes: aResourceTypes

    "self
        request: 'Select A Resource Selector'
        onSuperclass: #ApplicationModel 
        andClass: #ToolApplicationModel 
        andSelector: #saveIcon 
        withResourceTypes: #(canvas menu image) 
    "

    ^self new
        title: aTitle;
        openOnSuperclass: aSuperclass
        andClass: aClass
        andSelector: aSelector
        withResourceTypes: aResourceTypes
! !

!ResourceSelectionBrowser class methodsFor:'interface specs'!

windowSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:ResourceSelectionBrowser andSelector:#windowSpec
     ResourceSelectionBrowser new openInterface:#windowSpec
    "
    "ResourceSelectionBrowser open"

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'Resource Browser'
              #'layout:' #(#LayoutFrame 315 0 311 0 726 0 610 0)
              #'label:' 'Resource Browser'
              #'min:' #(#Point 400 300)
              #'max:' #(#Point 1152 864)
              #'bounds:' #(#Rectangle 315 311 727 611)
              #'usePreferredExtent:' false
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#VariableHorizontalPanelSpec
                    #'name:' 'variableHorizontalPanel'
                    #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -40 1.0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#ViewSpec
                              #'name:' 'view1'
                              #'component:' 
                               #(#SpecCollection
                                  #'collection:' 
                                   #(
                                     #(#SelectionInTreeViewSpec
                                        #'name:' 'listOfClassesView'
                                        #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -22 1.0)
                                        #'model:' #selectionOfClass
                                        #'hasHorizontalScrollBar:' true
                                        #'hasVerticalScrollBar:' true
                                        #'miniScrollerHorizontal:' true
                                        #'showRoot:' false
                                        #'showDirectoryIndicatorForRoot:' false
                                        #'showDirectoryIndicator:' true
                                        #'valueChangeSelector:' #'classSelected:'
                                        #'hierarchicalList:' #listOfClasses
                                    )
                                     #(#InputFieldSpec
                                        #'name:' 'classNameInputField'
                                        #'layout:' #(#LayoutFrame 0 0.0 -22 1 -1 1.0 0 1)
                                        #'model:' #valueOfClassName
                                    )
                                  )
                              )
                          )
                           #(#ViewSpec
                              #'name:' 'view2'
                              #'component:' 
                               #(#SpecCollection
                                  #'collection:' 
                                   #(
                                     #(#DataSetSpec
                                        #'name:' 'resourcesDataSetView'
                                        #'layout:' #(#LayoutFrame 2 0.0 0 0.0 2 1.0 -22 1.0)
                                        #'model:' #selectionOfResource
                                        #'hasHorizontalScrollBar:' true
                                        #'hasVerticalScrollBar:' true
                                        #'miniScrollerHorizontal:' true
                                        #'dataList:' #listOfResources
                                        #'useIndex:' false
                                        #'has3Dsepartors:' true
                                        #'doubleClickSelector:' #resourceDoubleClicked
                                        #'valueChangeSelector:' #resourceSelected
                                        #'verticalSpacing:' 1
                                        #'columns:' 
                                         #(
                                           #(#DataSetColumnSpec
                                              #'width:' 20
                                              #'printSelector:' #'iconOn:'
                                              #'canSelect:' false
                                          )
                                           #(#DataSetColumnSpec
                                              #'label:' 'Selector'
                                              #'model:' #selector
                                              #'canSelect:' false
                                          )
                                           #(#DataSetColumnSpec
                                              #'label:' 'Resource'
                                              #'model:' #resourceType
                                              #'canSelect:' false
                                          )
                                        )
                                    )
                                     #(#InputFieldSpec
                                        #'name:' 'selectorInputField'
                                        #'layout:' #(#LayoutFrame 2 0.0 -22 1 2 1.0 0 1)
                                        #'model:' #valueOfSelector
                                    )
                                  )
                              )
                          )
                        )
                    )
                    #'handles:' #(#Any 0.5 1.0)
                )
                 #(#UISubSpecification
                    #'name:' 'SubSpecification'
                    #'layout:' #(#LayoutFrame 2 0.0 -32 1 -2 1.0 -8 1.0)
                    #'majorKey:' #ToolApplicationModel
                    #'minorKey:' #windowSpecForCommitWithoutChannels
                )
              )
          )
      )
! !

!ResourceSelectionBrowser methodsFor:'accessing - views'!

classNameInputField

    ^builder componentAt: #classNameInputField
!

listOfClassesView

    ^builder componentAt: #listOfClassesView
! !

!ResourceSelectionBrowser methodsFor:'aspects'!

listOfClasses

    |holder|
    (holder := builder bindingAt:#listOfClasses) isNil ifTrue:[
        builder aspectAt:#listOfClasses put:
            (holder := 
                (TreeItem name: (resourceSuperclass ? #Object))
                    children: (OrderedCollection with:
                        (TreeItem newAsTreeFromSmalltalkClass: (Smalltalk at:(resourceSuperclass ? #Object)))))
    ].
    ^ holder


!

listOfResources

    |holder|
    (holder := builder bindingAt:#listOfResources) isNil ifTrue:[
        builder aspectAt:#listOfResources put:(holder :=  List new).
    ].
    ^ holder
!

selectionOfClass

    |holder|
    (holder := builder bindingAt:#selectionOfClass) isNil ifTrue:[
        builder aspectAt:#selectionOfClass put:(holder :=  ValueHolder new).
    ].
    ^ holder
!

selectionOfResource

    |holder|
    (holder := builder bindingAt:#selectionOfResource) isNil ifTrue:[
        builder aspectAt:#selectionOfResource put:(holder :=  '' asValue).
    ].
    ^ holder
!

valueOfClassName

    |holder|
    (holder := builder bindingAt:#valueOfClassName) isNil ifTrue:[
        builder aspectAt:#valueOfClassName put:(holder :=  '' asValue).
    ].
    ^ holder
!

valueOfSelector

    |holder|
    (holder := builder bindingAt:#valueOfSelector) isNil ifTrue:[
        builder aspectAt:#valueOfSelector put:(holder :=  '' asValue).
    ].
    ^ holder
! !

!ResourceSelectionBrowser methodsFor:'callbacks'!

classSelected: anIndex
    
    self selectionOfClass value isNil ifTrue: [^nil].
    self withWaitCursorDo:
    [
        |clsName|
        resourceTypes isNil ifTrue: [resourceTypes := #(canvas menu image fileImage)].
        clsName := self listOfClassesView list at: anIndex.
        self valueOfClassName value: clsName.
        self class lastSelection: clsName.
        self listOfResources contents:
            ((Smalltalk at: clsName) 
                class methodDictionary
                asOrderedCollection select: 
                    [:m| m resources notNil and: [resourceTypes includes: m resourceType]]).
    ]
!

resourceDoubleClicked

    resourceMethod := self selectionOfResource value.
    accept value: true.
    self close
!

resourceSelected

    resourceMethod := self selectionOfResource value.
    self valueOfSelector value: self selectionOfResource value selector
! !

!ResourceSelectionBrowser methodsFor:'initialization'!

postBuildWith:aBuilder

    |classSelection classSelectionBlock|
    allClasses := Smalltalk allClasses asArray.
    classSelection := self class lastSelection ? resourceClass ? #Object.
    classSelectionBlock := 
    [:clsPattern|                                  
        |foundClass classes|         
        ((foundClass := Smalltalk at: clsPattern asSymbol) isNil or:
        [foundClass name ~= clsPattern])
        ifTrue:
        [
            classes := allClasses select: [:cls| cls name size >= clsPattern size].
            1 to: clsPattern size do: 
            [:i|    
                 classes := classes select: [:cls| (cls name at: i) == (clsPattern at: i)].
            ].    
            foundClass := classes at: 1 ifAbsent: [nil] 
        ].
        foundClass notNil
        ifTrue:
        [
            self listOfClassesView selectFromListOfNames: (foundClass 
                withAllSuperclasses reverse collect: [:cls| cls name asString])
        ].
        self valueOfClassName value: clsPattern
    ].
    classSelectionBlock value: classSelection.
    self valueOfClassName value: classSelection.
    self classNameInputField entryCompletionBlock:
    [:value|
        |what|
        what := Smalltalk classnameCompletion: value withoutSpaces.
        self classNameInputField contents:what first.
        (what at:2) size ~~ 1 ifTrue:[Display beep].
        classSelectionBlock value: self classNameInputField contents
    ].
    ^super postBuildWith:aBuilder

! !

!ResourceSelectionBrowser methodsFor:'instance creation'!

openOnSuperclass: aSuperclassOrSymbol andClass: aClassOrSymbol andSelector: aSelector withResourceTypes: aResourceTypes

    |cls sel|
    resourceTypes := aResourceTypes.
    resourceSuperclass := aSuperclassOrSymbol isClass ifTrue: [aSuperclassOrSymbol name] ifFalse: [aSuperclassOrSymbol].
    resourceClass := aClassOrSymbol isClass ifTrue: [aClassOrSymbol name] ifFalse: [aClassOrSymbol].
    self valueOfSelector value: aSelector.

    self open.

    (self selectionOfClass value notNil and: 
    [(cls := Smalltalk at: self selectionOfClass value name) isClass and:
    [accept value]])
    ifTrue:
    [
        ^cls name, ' ', self valueOfSelector value
    ].
    ^nil
! !

!ResourceSelectionBrowser methodsFor:'startup / release'!

closeCancel

    resourceMethod := nil.
    super closeCancel



! !

!ResourceSelectionBrowser class methodsFor:'documentation'!

version
    ^ '$Header$'
! !