Tools__VariableList.st
branchjv
changeset 16571 cf319f2e56d0
parent 16213 f667b5b42a11
parent 16537 bfe8be86fde5
child 16709 ff5b5c8d8549
equal deleted inserted replaced
16570:dc5e958a20dc 16571:cf319f2e56d0
    12 "{ Package: 'stx:libtool' }"
    12 "{ Package: 'stx:libtool' }"
    13 
    13 
    14 "{ NameSpace: Tools }"
    14 "{ NameSpace: Tools }"
    15 
    15 
    16 BrowserList subclass:#VariableList
    16 BrowserList subclass:#VariableList
    17 	instanceVariableNames:'variableList classHolder showClassVars sortVariablesByName
    17 	instanceVariableNames:'classHolder groupVariablesByInheritance selectedVariableEntries
    18 		selectedVariableEntries showWarningAboutMissingEntryInXmlSpec'
    18 		showClassVars showWarningAboutMissingEntryInXmlSpec
       
    19 		sortVariablesByName variableList'
    19 	classVariableNames:''
    20 	classVariableNames:''
    20 	poolDictionaries:''
    21 	poolDictionaries:''
    21 	category:'Interface-Browsers-New'
    22 	category:'Interface-Browsers-New'
    22 !
    23 !
    23 
    24 
    24 Object subclass:#VariableEntry
    25 Object subclass:#VariableEntry
    25 	instanceVariableNames:'label application class name type icon sortingByNameHolder
    26 	instanceVariableNames:'label application class name type icon sortingByNameHolder
    26 		classShown'
    27 		classShown groupByInheritanceHolder'
    27 	classVariableNames:''
    28 	classVariableNames:''
    28 	poolDictionaries:''
    29 	poolDictionaries:''
    29 	privateIn:VariableList
    30 	privateIn:VariableList
    30 !
    31 !
    31 
    32 
   129         #selectionChangeCondition
   130         #selectionChangeCondition
   130         #updateTrigger
   131         #updateTrigger
   131         #showClassVarsInVariableList
   132         #showClassVarsInVariableList
   132         #slaveMode
   133         #slaveMode
   133         #sortVariablesByName
   134         #sortVariablesByName
       
   135         #groupVariablesByInheritance
   134       ).
   136       ).
   135 
   137 
   136     "Modified: / 24-02-2014 / 10:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   138     "Modified: / 24-02-2014 / 10:37:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   137 ! !
   139 ! !
   138 
   140 
   161 
   163 
   162 defaultSlaveModeValue
   164 defaultSlaveModeValue
   163     ^ false.
   165     ^ false.
   164 !
   166 !
   165 
   167 
       
   168 groupVariablesByInheritance
       
   169     "/ groupVariablesByInheritance and sortVariablesByName form a 3-state value
       
   170     "/      groupVariablesByInheritance sortVariablesByName
       
   171     "/                  T                   T                   - sort within each defining class
       
   172     "/                  T                   F                   - by inst-order grouped by defining class
       
   173     "/                  F                   T                   - show all of them in one big sorted list
       
   174     "/                  F                   F                   - useless - show all of them by inst-order
       
   175     groupVariablesByInheritance isNil ifTrue:[
       
   176         groupVariablesByInheritance := true asValue.
       
   177         groupVariablesByInheritance addDependent:self
       
   178     ].
       
   179     ^ groupVariablesByInheritance
       
   180 !
       
   181 
       
   182 groupVariablesByInheritance:aValueHolder
       
   183     "/ self assert:(aValueHolder value isBoolean).
       
   184 
       
   185     groupVariablesByInheritance notNil ifTrue:[
       
   186         groupVariablesByInheritance removeDependent:self
       
   187     ].
       
   188     groupVariablesByInheritance := aValueHolder.
       
   189     groupVariablesByInheritance notNil ifTrue:[
       
   190         groupVariablesByInheritance addDependent:self
       
   191     ].
       
   192 !
       
   193 
   166 selectedVariableEntries
   194 selectedVariableEntries
   167     <resource: #uiAspect>
   195     <resource: #uiAspect>
   168 
   196 
   169     "automatically generated by UIPainter ..."
   197     "automatically generated by UIPainter ..."
   170 
   198 
   209     ^ false
   237     ^ false
   210     "/ ^ true
   238     "/ ^ true
   211 !
   239 !
   212 
   240 
   213 sortVariablesByName
   241 sortVariablesByName
       
   242     "/ groupVariablesByInheritance and sortVariablesByName form a 3-state value
       
   243     "/      groupVariablesByInheritance sortVariablesByName
       
   244     "/                  T                   T                   - sort within each defining class
       
   245     "/                  T                   F                   - by inst-order grouped by defining class
       
   246     "/                  F                   T                   - show all of them in one big sorted list
       
   247     "/                  F                   F                   - useless - show all of them by inst-order
   214     sortVariablesByName isNil ifTrue:[
   248     sortVariablesByName isNil ifTrue:[
   215 	sortVariablesByName := false asValue.
   249         sortVariablesByName := false asValue.
   216 	sortVariablesByName addDependent:self
   250         sortVariablesByName addDependent:self
   217     ].
   251     ].
   218     ^ sortVariablesByName
   252     ^ sortVariablesByName
   219 !
   253 !
   220 
   254 
   221 sortVariablesByName:aValueHolder
   255 sortVariablesByName:aValueHolder
   261     changedObject == showClassVars ifTrue:[
   295     changedObject == showClassVars ifTrue:[
   262         self invalidateList.
   296         self invalidateList.
   263         ^ self.
   297         ^ self.
   264     ].
   298     ].
   265     changedObject == sortVariablesByName ifTrue:[
   299     changedObject == sortVariablesByName ifTrue:[
       
   300         self invalidateList.
       
   301         ^ self.
       
   302     ].
       
   303     changedObject == groupVariablesByInheritance ifTrue:[
   266         self invalidateList.
   304         self invalidateList.
   267         ^ self.
   305         ^ self.
   268     ].
   306     ].
   269     changedObject == environment ifTrue:[
   307     changedObject == environment ifTrue:[
   270         (something == #projectOrganization) ifTrue:[^ self].
   308         (something == #projectOrganization) ifTrue:[^ self].
   489     "Modified: / 15-07-2011 / 18:32:47 / cg"
   527     "Modified: / 15-07-2011 / 18:32:47 / cg"
   490     "Modified: / 22-06-2012 / 13:17:28 / sr"
   528     "Modified: / 22-06-2012 / 13:17:28 / sr"
   491 !
   529 !
   492 
   530 
   493 listEntryForClass: cls name:name
   531 listEntryForClass: cls name:name
   494 
   532     ^ self listEntryForClass: cls name:name info:nil
   495   "  (showWarningAboutMissingEntryInXmlSpec not
   533 !
   496         and:[Expecco::ExpeccoXMLDecoder notNil 
   534 
   497             and:[cls canUnderstand: #xmlSpecFor:]]) ifTrue:
   535 listEntryForClass: cls name:name info: classInfoOrNil
   498                 [| hasSpecEntry |
   536     | entry |
   499                 hasSpecEntry := false.
   537 
   500                 (Expecco::ExpeccoXMLDecoder xmlSpecForObject:cls basicNew)
   538     entry := Tools::VariableList::VariableEntry application: self class: cls name: name.
   501                     do:[:spec|spec getter = name ifTrue:
       
   502                             [
       
   503                             hasSpecEntry := true]].
       
   504                 showWarningAboutMissingEntryInXmlSpec := hasSpecEntry not].    "
       
   505 
       
   506     |entry|
       
   507 
       
   508     entry := VariableEntry application: self class: cls name: name.
       
   509     entry sortingByNameHolder:sortVariablesByName.
   539     entry sortingByNameHolder:sortVariablesByName.
   510     ^ entry
   540     entry groupByInheritanceHolder:groupVariablesByInheritance.
   511 
   541     classInfoOrNil notNil ifTrue:[
   512     "Created: / 12-04-2011 / 15:41:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   542         entry type: (classInfoOrNil infoForInstvarOrNil: name).
   513     "Modified: / 12-04-2011 / 21:36:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   514 !
       
   515 
       
   516 listEntryForClass: cls name:name info: classInfo
       
   517 
       
   518     | nm entry |
       
   519 
       
   520     nm := name.
       
   521     entry := Tools::VariableList::VariableEntry application: self class: cls name: nm.
       
   522     entry sortingByNameHolder:sortVariablesByName.
       
   523     classInfo notNil ifTrue:[
       
   524         entry type: (classInfo infoForInstvarOrNil: name).
       
   525     ].
   543     ].
   526     ^entry
   544     ^entry
   527 
   545 
   528     "Created: / 27-11-2011 / 17:17:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   546     "Created: / 27-11-2011 / 17:17:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   529     "Modified: / 07-10-2013 / 08:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   547     "Modified: / 07-10-2013 / 08:28:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   530 !
   548 !
   531 
   549 
   532 listOfVariables
   550 listOfVariables
   533 
   551 
   534     |nameList numClasses classes class commonSubclass showingClassVars
   552     |nameList numClasses classes class commonSubclass showingClassVars
   535      sortByName classesAlreadyProcessed hasSmallSense smallSenseManager info |
   553      sortByName groupByInheritance classesAlreadyProcessed hasSmallSense smallSenseManager info |
   536 
   554 
   537     classHolder isNil ifTrue:[
   555     classHolder isNil ifTrue:[
   538         "/ testing
   556         "/ testing
   539         ^ #()
   557         ^ #()
   540     ].
   558     ].
   545         smallSenseManager := (Smalltalk at: #'SmallSense::Manager') instance.
   563         smallSenseManager := (Smalltalk at: #'SmallSense::Manager') instance.
   546     ].
   564     ].
   547 
   565 
   548     showingClassVars := self showClassVarsInVariableList value == true.
   566     showingClassVars := self showClassVarsInVariableList value == true.
   549     sortByName := self sortVariablesByName value.
   567     sortByName := self sortVariablesByName value.
   550     "/ self assert:(sortByName isBoolean).
   568     groupByInheritance := self groupVariablesByInheritance value.
       
   569     self assert:(sortByName isBoolean).
       
   570     self assert:(groupByInheritance isBoolean).
   551 
   571 
   552     classes := classHolder value.
   572     classes := classHolder value.
   553     (numClasses := classes size) == 0 ifTrue:[^ #() ].
   573     (numClasses := classes size) == 0 ifTrue:[^ #() ].
   554     numClasses > 1 ifTrue:[
   574     numClasses > 1 ifTrue:[
   555         "/ multiple classes - see if there is a common subclass ...
   575         "/ multiple classes - see if there is a common subclass ...
   655                     (hasSmallSense and:[showingClassVars not]) ifTrue:[
   675                     (hasSmallSense and:[showingClassVars not]) ifTrue:[
   656                         info := smallSenseManager infoForClassOrNil: cls.
   676                         info := smallSenseManager infoForClassOrNil: cls.
   657                     ].                            
   677                     ].                            
   658                     varNames := showingClassVars ifTrue:[ cls classVarNames ] ifFalse:[ cls instVarNames ].
   678                     varNames := showingClassVars ifTrue:[ cls classVarNames ] ifFalse:[ cls instVarNames ].
   659                     classShown := (cls ~~ class). "/ only append the class in the shown name, if the var is inherited
   679                     classShown := (cls ~~ class). "/ only append the class in the shown name, if the var is inherited
   660 
   680                     sortByName ifTrue:[
       
   681                         varNames sort.
       
   682                     ].    
   661                     varNames reversed do:[:varName|
   683                     varNames reversed do:[:varName|
   662                         |entry|
   684                         |entry|
   663                         nameList addFirst: (entry := self listEntryForClass: cls name: varName info: info).
   685                         nameList addFirst: (entry := self listEntryForClass: cls name: varName info: info).
   664                         classShown ifFalse:[ entry classShown:classShown ].
   686                         classShown ifFalse:[ entry classShown:classShown ].
   665                     ].
   687                     ].
   666                     sortByName ifFalse:[
   688                     groupByInheritance ifTrue:[
   667                         nameList addFirst:(("'----- ' , "cls nameInBrowser" , ' -----'") asText colorizeAllWith: Color gray).
   689                         nameList addFirst:(("'----- ' , "cls nameInBrowser" , ' -----'") withColor: Color gray).
   668                     ]
   690                     ]
   669                 ].
   691                 ].
   670             ].
   692             ].
   671         ].
   693         ].
   672     ].
   694     ].
   673 
   695 
   674     (numClasses > 1 or:[sortByName]) ifTrue:[
   696     (numClasses > 1 or:[sortByName and:[groupByInheritance not]]) ifTrue:[
   675         nameList := nameList asSortedCollection:[:a :b|a name < b name].
   697         nameList := nameList asSortedCollection:[:a :b|a name < b name].
   676     ].
   698     ].
   677     ^ nameList
   699     ^ nameList
   678 
   700 
   679     "Created: / 05-02-2000 / 13:42:11 / cg"
   701     "Created: / 05-02-2000 / 13:42:11 / cg"
   789 
   811 
   790 classShown:aBoolean
   812 classShown:aBoolean
   791     classShown := aBoolean.
   813     classShown := aBoolean.
   792 !
   814 !
   793 
   815 
       
   816 groupByInheritanceHolder:aValueHolder
       
   817     "/ is there a need for a valueHolder?
       
   818     groupByInheritanceHolder := aValueHolder.
       
   819 !
       
   820 
   794 icon
   821 icon
   795     icon isNil ifTrue:[
   822     icon isNil ifTrue:[
   796         icon := application iconInBrowserForVariable: name in: class.
   823         icon := application iconInBrowserForVariable: name in: class.
   797         icon isNil ifTrue:[icon := #NOICON].        
   824         icon isNil ifTrue:[icon := #NOICON].        
   798     ].
   825     ].
   812 label
   839 label
   813 
   840 
   814     label isNil ifTrue:[
   841     label isNil ifTrue:[
   815         label := name.
   842         label := name.
   816         type notNil ifTrue:[
   843         type notNil ifTrue:[
   817             label := (label , ' ' ,  (type displayString colorizeAllWith: Color brown))
   844             label := (label , ' ' ,  (type displayString withColor: Color brown))
   818         ] ifFalse:[
   845         ] ifFalse:[
   819             "/ Hack for Java classes to display field type
   846             "/ Hack for Java classes to display field type
   820             class theNonMetaclass isJavaClass ifTrue:[
   847             class theNonMetaclass isJavaClass ifTrue:[
   821                 | field |
   848                 | field |
   822                 field := class theNonMetaclass lookupFieldFor:name static: (class isMetaclass) onlyPublic: false.
   849                 field := class theNonMetaclass lookupFieldFor:name static: (class isMetaclass) onlyPublic: false.
   823                 field notNil ifTrue:[
   850                 field notNil ifTrue:[
   824                     label := label asText , 
   851                     label := label asText , 
   825                             ' ' , 
   852                             ' ' , 
   826                                 (('< ' , (JavaMethod fieldTypeFromStream: (field descriptor readStream) in: class theNonMetaclass javaPackage) , ' >')
   853                                 (('< ' , (JavaMethod fieldTypeFromStream: (field descriptor readStream) in: class theNonMetaclass javaPackage) , ' >')
   827                                         asText colorizeAllWith: Color brown).
   854                                         withColor: Color brown).
   828                 ].
   855                 ].
   829             ].    
   856             ].    
   830         ].
   857         ].
   831     ].
   858     ].
   832     ^label
   859     ^label
   838 labelWithClass
   865 labelWithClass
   839     |l|
   866     |l|
   840 
   867 
   841     l := self label.
   868     l := self label.
   842     class notNil ifTrue:[
   869     class notNil ifTrue:[
   843         ^ label,' (' ,(class nameWithoutPrefix colorizeAllWith: Color gray),')' 
   870         ^ label,' (' ,(class nameWithoutPrefix withColor: Color gray),')' 
   844     ].
   871     ].
   845     ^label
   872     ^label
   846 !
   873 !
   847 
   874 
   848 name
   875 name
   851 
   878 
   852 name:aString
   879 name:aString
   853     name := aString.
   880     name := aString.
   854 !
   881 !
   855 
   882 
   856 sortingByNameHolder:something
   883 sortingByNameHolder:aValueHolder
   857     sortingByNameHolder := something.
   884     "/ is there a need for a valueHolder?
       
   885     sortingByNameHolder := aValueHolder.
   858 !
   886 !
   859 
   887 
   860 string
   888 string
   861 
   889 
   862     ^name
   890     ^name
   888     icn := self icon.
   916     icn := self icon.
   889     icn ~~ #NOICON ifTrue:[
   917     icn ~~ #NOICON ifTrue:[
   890         icn displayOn:aGC x:x + 1 y:y - icn height.
   918         icn displayOn:aGC x:x + 1 y:y - icn height.
   891     ].
   919     ].
   892 
   920 
   893     shownLabel := ((classShown ? true) and:[sortingByNameHolder value]) 
   921     shownLabel := ((classShown ? true) and:[sortingByNameHolder value and:[groupByInheritanceHolder value not]]) 
   894                     ifTrue:[ self labelWithClass ]
   922                     ifTrue:[ self labelWithClass ]
   895                     ifFalse: [ self label ].
   923                     ifFalse: [ self label ].
   896 
   924 
   897     shownLabel displayOn:aGC x:x + 20 y:y opaque: opaque
   925     shownLabel displayOn:aGC x:x + 20 y:y opaque: opaque
   898 
   926