SmallSense__ClassSearchDialog.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 20 Jun 2014 13:56:46 +0100
changeset 346 88c1d211f9be
parent 344 88d012c17762
child 347 d76d7d8d17a3
permissions -rw-r--r--
Reintroduced PO>>subject. This method is usefull when writing generic code (such as the one in search dialogs). However, PO>>subject is now considered 'private' and should be used with care. It's name is not very intention revealing and it is not clear what it really returns. Don't use it in non-generic code that does care what's the return value.

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

AbstractSearchDialog subclass:#ClassSearchDialog
	instanceVariableNames:'matchFullyQualifiedClassNameHolder
		matchFullyQualifiedClassNameEnabledHolder
		showOnlyInterfacesHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core-Interface-Search'
!

!ClassSearchDialog class methodsFor:'interface specs-content'!

optionsPaneSpec
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the UIPainter may not be able to read the specification."

    "
     UIPainter new openOnClass:SmallSense::ClassSearchDialog andSelector:#optionsPaneSpec
     SmallSense::ClassSearchDialog new openInterface:#optionsPaneSpec
    "

    <resource: #canvas>

    ^ 
    #(FullSpec
       name: optionsPaneSpec
       window: 
      (WindowSpec
         label: 'Search Options...'
         name: 'Search Options...'
         min: (Point 10 10)
         bounds: (Rectangle 0 0 634 25)
       )
       component: 
      (SpecCollection
         collection: (
          (VerticalPanelViewSpec
             name: 'Options'
             layout: (LayoutFrame 0 0 0 0 0 1 0 1)
             horizontalLayout: fit
             verticalLayout: fit
             horizontalSpace: 3
             verticalSpace: 3
             component: 
            (SpecCollection
               collection: (
                (CheckBoxSpec
                   label: 'Match fully qualified class names'
                   name: 'CheckBox1'
                   model: matchFullyQualifiedClassNameHolder
                   extent: (Point 634 25)
                 )
                )
              
             )
           )
          )
        
       )
     )
! !

!ClassSearchDialog methodsFor:'accessing-defaults'!

defaultTitle
    ^ (resources string: 'Search Class...')

    "Created: / 05-05-2014 / 23:39:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassSearchDialog methodsFor:'aspects'!

matchFullyQualifiedClassNameEnabledHolder
    <resource: #uiAspect>

    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."
    "*** (and replace this comment by something more useful ;-)"

    matchFullyQualifiedClassNameEnabledHolder isNil ifTrue:[
        matchFullyQualifiedClassNameEnabledHolder := true asValue.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
"/       matchFullyQualifiedClassNameEnabledHolder addDependent:self.
"/       matchFullyQualifiedClassNameEnabledHolder onChangeSend:#matchFullyQualifiedClassNameEnabledHolderChanged to:self.
    ].
    ^ matchFullyQualifiedClassNameEnabledHolder.
!

matchFullyQualifiedClassNameHolder
    <resource: #uiAspect>

    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."
    "*** (and replace this comment by something more useful ;-)"

    matchFullyQualifiedClassNameHolder isNil ifTrue:[
        matchFullyQualifiedClassNameHolder := false asValue.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
       matchFullyQualifiedClassNameHolder addDependent:self.
"/       matchFullyQualifiedClassNameHolder onChangeSend:#matchFullyQualifiedClassNameHolderChanged to:self.
    ].
    ^ matchFullyQualifiedClassNameHolder.

    "Modified: / 18-03-2013 / 11:19:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showOnlyInterfacesHolder
    "return/create the 'showOnlyIntefacesHolder' value holder (automatically generated)"
    
    showOnlyInterfacesHolder isNil ifTrue:[
        showOnlyInterfacesHolder := false asValue.
        showOnlyInterfacesHolder addDependent:self.
    ].
    ^ showOnlyInterfacesHolder

    "Modified: / 24-04-2014 / 23:42:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showOnlyInterfacesHolder:something 
    "set the 'showOnlyIntefacesHolder' value holder (automatically generated)"
    
    | oldValue  newValue |

    showOnlyInterfacesHolder notNil ifTrue:[
        oldValue := showOnlyInterfacesHolder value.
        showOnlyInterfacesHolder removeDependent:self.
    ].
    showOnlyInterfacesHolder := something.
    showOnlyInterfacesHolder notNil ifTrue:[
        showOnlyInterfacesHolder addDependent:self.
    ].
    newValue := showOnlyInterfacesHolder value.
    oldValue ~~ newValue ifTrue:[
        self 
            update:#value
            with:newValue
            from:showOnlyInterfacesHolder.
    ].
! !

!ClassSearchDialog methodsFor:'change & update'!

update:something with:aParameter from:changedObject
    changedObject == matchFullyQualifiedClassNameHolder ifTrue:[
        matchingObjectsUpdateJob restart.
        ^ self.
    ].
    changedObject == showOnlyInterfacesHolder ifTrue:[
        matchingObjectsUpdateJob restart.
        ^ self.
    ].  

    ^ super update:something with:aParameter from:changedObject

    "Created: / 27-04-2014 / 23:45:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateMatchingObjectsIgnorePattern
    "/ There's a lot of classes, do not display them all but
    "/ rather display only recent selections.

    | recent objects |

    matchingObjects := nil.

    "/ Make sure current environment contains them...
    objects := Set new.
    recent := self recentlySearchedObjects asArray reversed.
    self environment allClassesDo:[:cls|
        (recent includes: cls) ifTrue:[ 
            objects add: cls.
        ].
    ].
    recent := recent collect:[ :cls | objects includes: cls ].
    matchingObjects := recent.
    self updateMatchingObjects: recent.

    "Created: / 10-05-2014 / 11:49:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassSearchDialog methodsFor:'hooks'!

commonPostOpen
"/    self updateMatching.
"/    recentlySearchedPatterns notEmptyOrNil ifTrue:[
"/        matchPatternView contents: self recentlySearchedPatterns last.
"/        matchPatternView selectAll.
"/    ].
    matchPatternHolder addDependent:self.          
    self recentlySearchedObjects notEmptyOrNil ifTrue:[
        self updateMatchingObjects: self recentlySearchedObjects asArray reverse.
        self updateMatchingLabelToRecentSearches.
    ].
    self updateAcceptEnabled.

    "Created: / 08-03-2013 / 13:15:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 10-05-2014 / 01:06:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassSearchDialog methodsFor:'queries'!

canSelect: selection
    ^ selection askFor: #isSmallSenseClassPO.

    "Created: / 22-04-2014 / 13:08:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-05-2014 / 23:52:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hasOptions
    ^ true

    "Created: / 09-05-2014 / 23:59:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassSearchDialog methodsFor:'searching'!

matchingObjectPOsFor: objects
    | matchFullyQualifiedClassName |

    matchFullyQualifiedClassName := self matchFullyQualifiedClassNameHolder value.
    matchFullyQualifiedClassName ifTrue:[
        objects sort:[:a :b | a displayString < b displayString ].
    ] ifFalse:[
        objects sort:[:a :b | a nameWithoutPrefix < b nameWithoutPrefix ].
    ].

    ^ objects collect:[:each | 
        (ClassPO new)
            klass:each;
            showPrefix:matchFullyQualifiedClassName
    ].

    "Created: / 30-04-2014 / 09:50:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

matchingObjectsForPattern:pattern inEnvironment:environment 
    | matching matchFullyQualifiedClassName |

    matching := OrderedCollection new.
    matchFullyQualifiedClassName := self matchFullyQualifiedClassNameHolder 
            value.
    self matchPatternHolder value notEmptyOrNil ifTrue:[
        matchFullyQualifiedClassName ifFalse:[
            environment 
                allClassesDo:[:cls | 
                    ((filter isNil or:[filter value: cls]) and:[(pattern match:cls nameWithoutPrefix)]) ifTrue:[
                        matching add:cls.
                    ].
                ].
        ] ifTrue:[
            environment 
                allClassesDo:[:cls | 
                    ((filter isNil or:[filter value: cls]) and:[(pattern match:cls displayString)]) ifTrue:[
                        matching add:cls
                    ]
                ].
        ]
    ].

    ^ matching

    "Created: / 28-04-2014 / 23:20:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-05-2014 / 23:47:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !