VersionDiffBrowser.st
changeset 2497 ef306e387021
parent 2486 29a320ed5f2a
child 2501 e86fae15642d
equal deleted inserted replaced
2496:6cac06c54187 2497:ef306e387021
     1 ApplicationModel subclass:#VersionDiffBrowser
     1 ApplicationModel subclass:#VersionDiffBrowser
     2 	instanceVariableNames:'classBeingCompared versionA versionB changeSetA changeSetB
     2 	instanceVariableNames:'classChangeSet diffTextView'
     3 		filteredChangeSetA filteredChangeSetB changedMethodsChangeSet
       
     4 		indexFromChangedToA indexFromChangedToB diffTextView'
       
     5 	classVariableNames:''
     3 	classVariableNames:''
     6 	poolDictionaries:''
     4 	poolDictionaries:''
     7 	category:'Interface-Browsers'
     5 	category:'Interface-Browsers'
       
     6 !
       
     7 
       
     8 HierarchicalItem subclass:#ClassChangeSet
       
     9 	instanceVariableNames:'classBeingCompared labelA labelB changeSet onlyInA onlyInB
       
    10 		changedMethods'
       
    11 	classVariableNames:''
       
    12 	poolDictionaries:''
       
    13 	privateIn:VersionDiffBrowser
     8 !
    14 !
     9 
    15 
    10 VersionDiffBrowser comment:'some comment
    16 VersionDiffBrowser comment:'some comment
    11 '!
    17 '!
    12 
    18 
    33         #name: #windowSpec
    39         #name: #windowSpec
    34         #window: 
    40         #window: 
    35        #(#WindowSpec
    41        #(#WindowSpec
    36           #label: 'Version DiffBrowser'
    42           #label: 'Version DiffBrowser'
    37           #name: 'Version DiffBrowser'
    43           #name: 'Version DiffBrowser'
    38           #layout: #(#LayoutFrame 220 0 200 0 1084 0 703 0)
       
    39           #level: 0
       
    40           #min: #(#Point 10 10)
    44           #min: #(#Point 10 10)
    41           #max: #(#Point nil nil)
    45           #max: #(#Point nil nil)
    42           #bounds: #(#Rectangle 220 200 1085 704)
    46           #bounds: #(#Rectangle 110 151 975 655)
    43           #menu: #mainMenu
    47           #menu: #mainMenu
    44           #usePreferredExtent: false
       
    45           #returnIsOKInDialog: true
       
    46           #escapeIsCancelInDialog: true
       
    47         )
    48         )
    48         #component: 
    49         #component: 
    49        #(#SpecCollection
    50        #(#SpecCollection
    50           #collection: #(
    51           #collection: #(
    51            #(#VariableVerticalPanelSpec
    52            #(#VariableVerticalPanelSpec
    52               #name: 'VariableVerticalPanel1'
    53               #name: 'VariableVerticalPanel1'
    53               #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
    54               #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
    54               #handles: #(#Any 0.319444 1.0)
       
    55               #component: 
    55               #component: 
    56              #(#SpecCollection
    56              #(#SpecCollection
    57                 #collection: #(
    57                 #collection: #(
    58                  #(#HorizontalPanelViewSpec
    58                  #(#HorizontalPanelViewSpec
    59                     #name: 'TopHorizontalPanel'
    59                     #name: 'TopHorizontalPanel'
    90                                 #sequenceList: #methodsOnlyInA
    90                                 #sequenceList: #methodsOnlyInA
    91                               )
    91                               )
    92                              )
    92                              )
    93                            
    93                            
    94                           )
    94                           )
    95                           #extent: #(#Point 286 160)
    95                           #extent: #(#Point 286 252)
    96                         )
    96                         )
    97                        #(#ViewSpec
    97                        #(#ViewSpec
    98                           #name: 'BoxM'
    98                           #name: 'BoxM'
    99                           #component: 
    99                           #component: 
   100                          #(#SpecCollection
   100                          #(#SpecCollection
   119                                 #sequenceList: #methodsChanged
   119                                 #sequenceList: #methodsChanged
   120                               )
   120                               )
   121                              )
   121                              )
   122                            
   122                            
   123                           )
   123                           )
   124                           #extent: #(#Point 286 160)
   124                           #extent: #(#Point 286 252)
   125                         )
   125                         )
   126                        #(#ViewSpec
   126                        #(#ViewSpec
   127                           #name: 'BoxB'
   127                           #name: 'BoxB'
   128                           #component: 
   128                           #component: 
   129                          #(#SpecCollection
   129                          #(#SpecCollection
   148                                 #sequenceList: #methodsOnlyInB
   148                                 #sequenceList: #methodsOnlyInB
   149                               )
   149                               )
   150                              )
   150                              )
   151                            
   151                            
   152                           )
   152                           )
   153                           #extent: #(#Point 287 160)
   153                           #extent: #(#Point 287 252)
   154                         )
   154                         )
   155                        )
   155                        )
   156                      
   156                      
   157                     )
   157                     )
   158                   )
   158                   )
   205                     )
   205                     )
   206                   )
   206                   )
   207                  )
   207                  )
   208                
   208                
   209               )
   209               )
       
   210               #handles: #(#Any 0.5 1.0)
   210             )
   211             )
   211            )
   212            )
   212          
   213          
   213         )
   214         )
   214       )
   215       )
   399       )
   400       )
   400 ! !
   401 ! !
   401 
   402 
   402 !VersionDiffBrowser class methodsFor:'startup'!
   403 !VersionDiffBrowser class methodsFor:'startup'!
   403 
   404 
   404 openOnClass:aClass labelA:lblA sourceA:srcA labelB:lblB sourceB:srcB 
   405 openOnClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB 
   405     |browser|
   406     |theBrowser|
   406 
   407 
   407     browser := self new.
   408     theBrowser := self new.
   408     browser allButOpen.
   409     theBrowser allButOpen.
   409 
   410     theBrowser classChangeSet:(ClassChangeSet newForClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB).
   410     browser classBeingCompared:aClass.
   411     theBrowser updateLabels.
   411     browser 
   412     theBrowser updateLists.
   412         labelA:lblA sourceA:srcA
   413     theBrowser openWindow.
   413         labelB:lblB sourceB:srcB.
   414     ^ theBrowser.
   414 
       
   415     browser openWindow.
       
   416 
       
   417     ^ browser.
       
   418 
   415 
   419     "
   416     "
   420      self openOnClass:Array versionA:'1.116' versionB:'1.113'
   417      self openOnClass:Array versionA:'1.116' versionB:'1.113'
   421     "
   418     "
   422 !
   419 !
   423 
   420 
   424 openOnClass:aClass versionA:vsnA versionB:vsnB
   421 openOnClass:aClass versionA:aVersionA versionB:aVersionB
   425     |browser|
   422     |theBrowser|
   426 
   423 
   427     browser := self new.
   424     theBrowser := self new.
   428     browser allButOpen.
   425     theBrowser allButOpen.
   429 
   426     theBrowser classChangeSet:(ClassChangeSet newForClass:aClass versionA:aVersionA versionB:aVersionB).
   430     browser classBeingCompared:aClass.
   427     theBrowser updateLabels.
   431     browser versionA:vsnA.
   428     theBrowser updateLists.
   432     browser versionB:vsnB.
   429     theBrowser openWindow.
   433 
   430     ^ theBrowser.
   434     browser openWindow.
       
   435 
       
   436     ^ browser.
       
   437 
   431 
   438     "
   432     "
   439      self openOnClass:Array versionA:'1.116' versionB:'1.113'
   433      self openOnClass:Array versionA:'1.116' versionB:'1.113'
   440     "
   434     "
   441 ! !
   435 ! !
   442 
   436 
   443 !VersionDiffBrowser methodsFor:'accessing'!
   437 !VersionDiffBrowser methodsFor:'accessing'!
   444 
   438 
       
   439 changeSetA
       
   440 "
       
   441 gets the change set which contains only the new methods
       
   442 in versionA of the class
       
   443 
       
   444 <return: ChangeSet>
       
   445 "
       
   446 
       
   447     ^ self classChangeSet methodsOnlyInA
       
   448 !
       
   449 
       
   450 changeSetB
       
   451 "
       
   452 gets the change set which contains only the new methods
       
   453 in versionB of the class
       
   454 
       
   455 <return: ChangeSet>
       
   456 "
       
   457 
       
   458     ^ self classChangeSet methodsOnlyInB
       
   459 !
       
   460 
   445 classBeingCompared
   461 classBeingCompared
   446     "return the value of the instance variable 'classBeingCompared' (automatically generated)"
   462 
   447 
   463     ^ self classChangeSet classBeingCompared
   448     ^ classBeingCompared!
   464 !
   449 
   465 
   450 classBeingCompared:something
   466 classChangeSet
   451     "set the value of the instance variable 'classBeingCompared' (automatically generated)"
   467     "return the value of the instance variable 'classChangeSet' (automatically generated)"
   452 
   468 
   453     classBeingCompared := something.
   469     ^ classChangeSet!
   454     self updateViewsIfPossible.
   470 
   455 !
   471 classChangeSet:something
   456 
   472     "set the value of the instance variable 'classChangeSet' (automatically generated)"
   457 labelA:lblA sourceA:srcA labelB:lblB sourceB:srcB
   473 
   458     |s|
   474     classChangeSet := something.!
   459 
       
   460     changeSetA := ChangeSet fromStream:(s := srcA readStream).
       
   461     s close.
       
   462     changeSetB := ChangeSet fromStream:(s := srcB readStream).
       
   463     s close.
       
   464     versionA := lblA.
       
   465     versionB := lblB.
       
   466     self updateLabels.
       
   467     self updateLists.
       
   468 
       
   469 !
       
   470 
   475 
   471 versionA
   476 versionA
   472     "return the value of the instance variable 'versionA' (automatically generated)"
   477     "return the value of the instance variable 'versionA' (automatically generated)"
   473 
   478 
   474     ^ versionA!
   479     ^ self classChangeSet labelA
   475 
       
   476 versionA:something
       
   477     "set the value of the instance variable 'versionA' (automatically generated)"
       
   478 
       
   479     versionA := something.
       
   480     self updateViewsIfPossible.
       
   481 
   480 
   482 !
   481 !
   483 
   482 
   484 versionB
   483 versionB
   485     "return the value of the instance variable 'versionB' (automatically generated)"
   484     "return the value of the instance variable 'versionB' (automatically generated)"
   486 
   485 
   487     ^ versionB!
   486     ^ self classChangeSet labelB
   488 
       
   489 versionB:something
       
   490     "set the value of the instance variable 'versionB' (automatically generated)"
       
   491 
       
   492     versionB := something.
       
   493     self updateViewsIfPossible.
       
   494 
   487 
   495 ! !
   488 ! !
   496 
   489 
   497 !VersionDiffBrowser methodsFor:'actions'!
   490 !VersionDiffBrowser methodsFor:'actions'!
   498 
   491 
   502     sel := self methodsChangedSelection value.
   495     sel := self methodsChangedSelection value.
   503     sel notNil ifTrue:[
   496     sel notNil ifTrue:[
   504         self methodsOnlyInASelection value:nil.
   497         self methodsOnlyInASelection value:nil.
   505         self methodsOnlyInBSelection value:nil.
   498         self methodsOnlyInBSelection value:nil.
   506 
   499 
   507         idxA := indexFromChangedToA at:sel ifAbsent:nil.
   500         changeA := (self classChangeSet methodsChanged at:sel) first.
   508         idxB := indexFromChangedToB at:sel ifAbsent:nil.
   501         changeB := (self classChangeSet methodsChanged at:sel) second.
   509 
       
   510         changeA := changeSetA at:idxA.
       
   511         changeB := changeSetB at:idxB.
       
   512 
   502 
   513         self withWaitCursorDo:[
   503         self withWaitCursorDo:[
   514             self diffTextView text1:changeA source text2:changeB source.
   504             self diffTextView text1:changeA source text2:changeB source.
   515             self diffTextView moveToNextChanged.
   505             self diffTextView moveToNextChanged.
   516         ].
   506         ].
   528     sel := self methodsOnlyInASelection value.
   518     sel := self methodsOnlyInASelection value.
   529     sel notNil ifTrue:[
   519     sel notNil ifTrue:[
   530         self methodsOnlyInBSelection value:nil.
   520         self methodsOnlyInBSelection value:nil.
   531         self methodsChangedSelection value:nil.
   521         self methodsChangedSelection value:nil.
   532 
   522 
   533         change := filteredChangeSetA at:sel.
   523         change := self changeSetA at:sel.
   534         self methodText value:(change source).    
   524         self methodText value:(change source).    
   535         self showSingleTextView.
   525         self showSingleTextView.
   536     ]
   526     ]
   537 !
   527 !
   538 
   528 
   542     sel := self methodsOnlyInBSelection value.
   532     sel := self methodsOnlyInBSelection value.
   543     sel notNil ifTrue:[
   533     sel notNil ifTrue:[
   544         self methodsOnlyInASelection value:nil.
   534         self methodsOnlyInASelection value:nil.
   545         self methodsChangedSelection value:nil.
   535         self methodsChangedSelection value:nil.
   546 
   536 
   547         change := filteredChangeSetB at:sel.
   537         change := self changeSetB at:sel.
   548         self methodText value:(change source).    
   538         self methodText value:(change source).    
   549         self showSingleTextView.
   539         self showSingleTextView.
   550     ]
   540     ]
   551 ! !
   541 ! !
   552 
   542 
   595         builder aspectAt:#diffTextLabelB put:(holder :=  ValueHolder new).
   585         builder aspectAt:#diffTextLabelB put:(holder :=  ValueHolder new).
   596     ].
   586     ].
   597     ^ holder.
   587     ^ holder.
   598 !
   588 !
   599 
   589 
       
   590 diffTextView
       
   591     "automatically generated by UIPainter ..."
       
   592 
       
   593     diffTextView isNil ifTrue:[
       
   594         diffTextView := HVScrollableView
       
   595                            for:DiffTextView
       
   596                            miniScrollerH:true miniScrollerV:false.
       
   597         diffTextView addNextPreviousButtons.
       
   598 
       
   599         self addAcceptToTextViewMenus.
       
   600     ].
       
   601     ^ diffTextView
       
   602 !
       
   603 
   600 methodText
   604 methodText
   601     "automatically generated by UIPainter ..."
   605     "automatically generated by UIPainter ..."
   602 
   606 
   603     "*** the code below creates a default model when invoked."
   607     "*** the code below creates a default model when invoked."
   604     "*** (which may not be the one you wanted)"
   608     "*** (which may not be the one you wanted)"
   731     ].
   735     ].
   732     ^ holder.
   736     ^ holder.
   733 ! !
   737 ! !
   734 
   738 
   735 !VersionDiffBrowser methodsFor:'initialization & release'!
   739 !VersionDiffBrowser methodsFor:'initialization & release'!
   736 
       
   737 closeDownViews
       
   738     "This is a hook method generated by the Browser.
       
   739      It will be invoked when your app/dialog-window is really closed."
       
   740 
       
   741     "/ change the code below as required ...
       
   742     "/ This should cleanup any leftover resources
       
   743     "/ (for example, temporary files)
       
   744     "/ super closeRequest will initiate the closeDown
       
   745 
       
   746     "/ add your code here
       
   747 
       
   748     "/ do not remove the one below ...
       
   749     ^ super closeDownViews
       
   750 !
       
   751 
       
   752 closeRequest
       
   753     "This is a hook method generated by the Browser.
       
   754      It will be invoked when your app/dialog-window is about to be
       
   755      closed (and has a chance to suppress the close)."
       
   756 
       
   757     "/ change the code below as required ...
       
   758     "/ Closing can be suppressed, by returning.
       
   759     "/ super closeRequest will initiate the closeDown
       
   760 
       
   761     ^ super closeRequest
       
   762 !
       
   763 
   740 
   764 postBuildWith:aBuilder
   741 postBuildWith:aBuilder
   765     "This is a hook method generated by the Browser.
   742     "This is a hook method generated by the Browser.
   766      It will be invoked during the initialization of your app/dialog,
   743      It will be invoked during the initialization of your app/dialog,
   767      after all of the visual components have been built, 
   744      after all of the visual components have been built, 
   770      values etc.)"
   747      values etc.)"
   771 
   748 
   772     "/ add any code here ...
   749     "/ add any code here ...
   773 
   750 
   774     (aBuilder componentAt:#TopHorizontalPanel) ignoreInvisibleComponents:true.
   751     (aBuilder componentAt:#TopHorizontalPanel) ignoreInvisibleComponents:true.
   775 
       
   776     ^ super postBuildWith:aBuilder
   752     ^ super postBuildWith:aBuilder
   777 ! !
   753 ! !
   778 
   754 
   779 !VersionDiffBrowser methodsFor:'menu action'!
   755 !VersionDiffBrowser methodsFor:'menu action'!
   780 
   756 
   800     "create a pacthFile, to patch the old version (versionB) into
   776     "create a pacthFile, to patch the old version (versionB) into
   801      the new version (versionA)"
   777      the new version (versionA)"
   802 
   778 
   803     |oldVersion newVersion vsnMthdA vsnMthdB vsnA vsnB info|
   779     |oldVersion newVersion vsnMthdA vsnMthdB vsnA vsnB info|
   804 
   780 
   805     ^ self warn:'This function is not yet implemented'.
   781     vsnMthdA := self changeSetA 
   806 
       
   807     vsnMthdA := changeSetA 
       
   808                 detect:[:ch | ch isMethodChange
   782                 detect:[:ch | ch isMethodChange
   809                               and:[ch changeClass isMeta
   783                               and:[ch changeClass isMeta
   810                               and:[ch changeSelector = #version]]]
   784                               and:[ch changeSelector = #version]]]
   811                 ifNone:nil.
   785                 ifNone:nil.
   812     vsnMthdB := changeSetA 
   786     vsnMthdB := self changeSetA 
   813                 detect:[:ch | ch isMethodChange
   787                 detect:[:ch | ch isMethodChange
   814                               and:[ch changeClass isMeta
   788                               and:[ch changeClass isMeta
   815                               and:[ch changeSelector = #version]]]
   789                               and:[ch changeSelector = #version]]]
   816                 ifNone:nil.
   790                 ifNone:nil.
   817 
   791 
   846         self warn:'The generated patch file will not be able to validate/update the class version'.
   820         self warn:'The generated patch file will not be able to validate/update the class version'.
   847     ].
   821     ].
   848 
   822 
   849 self halt.
   823 self halt.
   850 
   824 
   851     "Modified: / 14.12.1999 / 15:34:28 / cg"
       
   852 !
   825 !
   853 
   826 
   854 inspectSelectedChangeInA
   827 inspectSelectedChangeInA
   855     self selectedChangeInA inspect.
   828     self selectedChangeInA inspect.
   856 !
   829 !
   871 selectedChangeInA
   844 selectedChangeInA
   872     |sel change|
   845     |sel change|
   873 
   846 
   874     sel := self methodsOnlyInASelection value.
   847     sel := self methodsOnlyInASelection value.
   875     sel notNil ifTrue:[
   848     sel notNil ifTrue:[
   876         change := (changeSetA at:sel).
   849         change := (self changeSetA at:sel).
   877     ].
   850     ].
   878     ^ change
   851     ^ change
   879 !
   852 !
   880 
   853 
   881 selectedChangeInB
   854 selectedChangeInB
   882     |sel change|
   855     |sel change|
   883 
   856 
   884     sel := self methodsOnlyInBSelection value.
   857     sel := self methodsOnlyInBSelection value.
   885     sel notNil ifTrue:[
   858     sel notNil ifTrue:[
   886         change := (changeSetB at:sel).
   859         change := (self changeSetB at:sel).
   887     ].
   860     ].
   888     ^ change
   861     ^ change
   889 !
   862 !
   890 
   863 
   891 selectedChangesInM
   864 selectedChangesInM
   892     |sel idxA idxB|
   865     |sel idxA idxB|
   893 
   866 
   894     sel := self methodsChangedSelection value.
   867     sel := self methodsChangedSelection value.
   895     sel notNil ifTrue:[
   868     sel notNil ifTrue:[
   896         idxA := indexFromChangedToA at:sel ifAbsent:nil.
   869         idxA := self indexFromChangedToA at:sel ifAbsent:nil.
   897         idxB := indexFromChangedToB at:sel ifAbsent:nil.
   870         idxB := self indexFromChangedToB at:sel ifAbsent:nil.
   898 
   871 
   899         ^ Array with:(changeSetA at:idxA) 
   872         ^ Array with:(self changeSetA at:idxA) 
   900                 with:(changeSetB at:idxB) 
   873                 with:(self changeSetB at:idxB) 
   901     ].
   874     ].
   902     ^ nil
   875     ^ nil
   903 ! !
   876 ! !
   904 
   877 
   905 !VersionDiffBrowser methodsFor:'private'!
   878 !VersionDiffBrowser methodsFor:'private'!
   906 
   879 
   907 showDiffTextView
   880 generator
   908     (self builder componentAt:#diffTextViewBox) raise; beVisible.
   881 
   909     (self builder componentAt:#singleTextView) beInvisible.
   882     ^[:c |
   910     (self builder componentAt:#diffTextView) realizeAllSubViews.
       
   911     self addAcceptToTextViewMenus.
       
   912 
       
   913 !
       
   914 
       
   915 showSingleTextView
       
   916     (self builder componentAt:#singleTextView) raise; beVisible.
       
   917     (self builder componentAt:#diffTextViewBox) beInvisible.
       
   918 
       
   919 !
       
   920 
       
   921 updateFromVersions
       
   922     |mgr versionAStream versionBStream|
       
   923 
       
   924     mgr := classBeingCompared sourceCodeManager.
       
   925 
       
   926     versionAStream := mgr getSourceStreamFor:classBeingCompared revision:versionA.
       
   927     changeSetA := ChangeSet fromStream:versionAStream.
       
   928     versionAStream close.
       
   929 
       
   930     versionBStream := mgr getSourceStreamFor:classBeingCompared revision:versionB.
       
   931     changeSetB := ChangeSet fromStream:versionBStream.
       
   932     versionBStream close.
       
   933 
       
   934     self updateLists
       
   935 
       
   936 !
       
   937 
       
   938 updateLabels
       
   939     versionA notNil ifTrue:[
       
   940         self diffTextLabelA value:versionA.
       
   941         self onlyInALabelHolder value:('Only in ' , versionA).
       
   942         (self builder componentAt:#OnlyInALabel) backgroundColor:Color green darkened.
       
   943     ].
       
   944     versionB notNil ifTrue:[
       
   945         self diffTextLabelB value:versionB.
       
   946         self onlyInBLabelHolder value:('Only in ' , versionB).
       
   947         (self builder componentAt:#OnlyInBLabel) backgroundColor:Color red darkened.
       
   948     ].
       
   949 !
       
   950 
       
   951 updateLists
       
   952     "walk over the two changeSets and add change to one of the tree lists"
       
   953 
       
   954     |mgr nmListA nmListB nmListM generator|
       
   955 
       
   956     filteredChangeSetA := ChangeSet new.
       
   957     filteredChangeSetB := ChangeSet new.
       
   958     changedMethodsChangeSet := ChangeSet new.
       
   959 
       
   960     indexFromChangedToA := OrderedCollection new.
       
   961     indexFromChangedToB := OrderedCollection new.
       
   962 
       
   963     changeSetA keysAndValuesDo:[:idxA :aChangeInA |
       
   964         |anyFound ch|
       
   965 
       
   966         anyFound := false.
       
   967 
       
   968         changeSetB keysAndValuesDo:[:idxB :aChangeInB |
       
   969             (aChangeInA isForSameAs:aChangeInB) ifTrue:[
       
   970                 anyFound := true.
       
   971 
       
   972                 "/ also in B - is it different ?
       
   973                 (aChangeInA sameAs:aChangeInB) ifFalse:[
       
   974                     changedMethodsChangeSet add:aChangeInA.
       
   975                     indexFromChangedToA add:idxA.
       
   976                     indexFromChangedToB add:idxB.
       
   977                 ] ifTrue:[
       
   978                     aChangeInA isMethodChange ifTrue:[
       
   979                         aChangeInA methodCategory ~= aChangeInB methodCategory ifTrue:[
       
   980                             "/ only the category is different;
       
   981                             "/ make it a MethodCategory changes.
       
   982 
       
   983                             ch := MethodCategoryChange new
       
   984                                     className:aChangeInA className
       
   985                                     selector:aChangeInA selector
       
   986                                     category:aChangeInA methodCategory.
       
   987                             changeSetA at:idxA put:ch.
       
   988 
       
   989                             ch := MethodCategoryChange new
       
   990                                     className:aChangeInB className
       
   991                                     selector:aChangeInB selector
       
   992                                     category:aChangeInB methodCategory.
       
   993                             changeSetB at:idxB put:ch.
       
   994 
       
   995                             changedMethodsChangeSet add:aChangeInA.
       
   996                             indexFromChangedToA add:idxA.
       
   997                             indexFromChangedToB add:idxB.
       
   998                         ]
       
   999                     ].
       
  1000                 ]
       
  1001             ] ifFalse:[
       
  1002                 (aChangeInA sameAs:aChangeInB) ifTrue:[
       
  1003                     anyFound := true.
       
  1004                 ] ifFalse:[
       
  1005                 ]
       
  1006             ]
       
  1007         ].
       
  1008 
       
  1009         anyFound ifFalse:[
       
  1010             filteredChangeSetA add:aChangeInA.
       
  1011         ]
       
  1012     ].
       
  1013 
       
  1014     changeSetB keysAndValuesDo:[:idxB :aChangeInB |
       
  1015         |anyFound|
       
  1016 
       
  1017         anyFound := false.
       
  1018 
       
  1019         changeSetA do:[:aChangeInA |
       
  1020             |idxM|
       
  1021 
       
  1022             (aChangeInA isForSameAs:aChangeInB) ifTrue:[
       
  1023                 anyFound := true.
       
  1024 
       
  1025                 "/ also in B - is it different ?
       
  1026                 (aChangeInA sameAs:aChangeInB) ifFalse:[
       
  1027                     "/ already there ?
       
  1028                     idxM := changedMethodsChangeSet findFirst:[:c | c isForSameAs:aChangeInB].
       
  1029                     idxM == 0 ifTrue:[
       
  1030                         changedMethodsChangeSet add:aChangeInB.
       
  1031                         indexFromChangedToB add:idxB.
       
  1032                     ] ifFalse:[
       
  1033                         indexFromChangedToB at:idxM put:idxB
       
  1034                     ]
       
  1035                 ]
       
  1036             ] ifFalse:[
       
  1037                 (aChangeInA sameAs:aChangeInB) ifTrue:[
       
  1038                     anyFound := true.
       
  1039                 ] ifFalse:[
       
  1040                 ]
       
  1041             ]
       
  1042         ].
       
  1043         anyFound ifFalse:[
       
  1044             filteredChangeSetB add:aChangeInB.
       
  1045         ]
       
  1046     ].
       
  1047 
       
  1048     generator := [:c |
       
  1049         |result mPkg cPkg cls m|
   883         |result mPkg cPkg cls m|
  1050 
   884 
  1051         c isClassDefinitionChange ifTrue:[
   885         c isClassDefinitionChange ifTrue:[
  1052             result := c printStringWithoutClass
   886             result := c printStringWithoutClass
  1053         ] ifFalse:[
   887         ] ifFalse:[
  1054             c isDoIt ifTrue:[
   888             c isDoIt ifTrue:[
  1055                 result := c source , ' (doIt)'
   889                 result := c source , ' (doIt)'
  1056             ] ifFalse:[
   890             ] ifFalse:[
  1057                 c className = classBeingCompared name ifTrue:[
   891                 c className = self classBeingCompared name ifTrue:[
  1058                     result := c printStringWithoutClass.
   892                     result := c printStringWithoutClass.
  1059                     c isMethodChange ifTrue:[
   893                     c isMethodChange ifTrue:[
  1060                         cls := c changeClass.
   894                         cls := c changeClass.
  1061                         cls notNil ifTrue:[
   895                         cls notNil ifTrue:[
  1062                             m := cls compiledMethodAt:c selector.
   896                             m := cls compiledMethodAt:c selector.
  1066                             ].
   900                             ].
  1067                         ].
   901                         ].
  1068                     ]
   902                     ]
  1069                 ] ifFalse:[
   903                 ] ifFalse:[
  1070                     "/ include name in private class changes
   904                     "/ include name in private class changes
  1071                     (c className startsWith:(classBeingCompared name , '::')) ifTrue:[
   905                     (c className startsWith:(self classBeingCompared name , '::')) ifTrue:[
  1072                         result := (c className copyFrom:(classBeingCompared name size + 3)) , ' ' ,  c printStringWithoutClass
   906                         result := (c className copyFrom:(self classBeingCompared name size + 3)) , ' ' ,  c printStringWithoutClass
  1073                     ] ifFalse:[
   907                     ] ifFalse:[
  1074                         result := c printString
   908                         result := c printString
  1075                     ]
   909                     ]
  1076                 ]
   910                 ]
  1077             ]
   911             ]
  1078         ].
   912         ].
  1079         result
   913         result
  1080     ].
   914     ].
  1081 
   915 
  1082     nmListA := self methodsOnlyInA.
   916 !
  1083     nmListA removeAll.
   917 
  1084     nmListA addAll:(filteredChangeSetA collect:generator).
   918 showDiffTextView
  1085 
   919     (self builder componentAt:#diffTextViewBox) raise; beVisible.
  1086     nmListB := self methodsOnlyInB.
   920     (self builder componentAt:#singleTextView) beInvisible.
  1087     nmListB removeAll.
   921     (self builder componentAt:#diffTextView) realizeAllSubViews.
  1088     nmListB addAll:(filteredChangeSetB collect:generator).
   922     self addAcceptToTextViewMenus.
  1089 
   923 
  1090     nmListM := self methodsChanged.
   924 !
  1091     nmListM removeAll.
   925 
  1092     nmListM addAll:(changedMethodsChangeSet collect:generator).
   926 showSingleTextView
  1093 
   927     (self builder componentAt:#singleTextView) raise; beVisible.
  1094     nmListA isEmpty ifTrue:[
   928     (self builder componentAt:#diffTextViewBox) beInvisible.
       
   929 
       
   930 !
       
   931 
       
   932 updateLabels
       
   933 
       
   934 
       
   935     |theVersionA theVersionB|
       
   936 
       
   937     (theVersionA := self versionA) notNil ifTrue:[
       
   938         self diffTextLabelA value:theVersionA.
       
   939         self onlyInALabelHolder value:('Only in ' , theVersionA).
       
   940         (self builder componentAt:#OnlyInALabel) backgroundColor:Color green darkened.
       
   941     ].
       
   942     (theVersionB :=self versionB) notNil ifTrue:[
       
   943         self diffTextLabelB value:theVersionB.
       
   944         self onlyInBLabelHolder value:('Only in ' , theVersionB).
       
   945         (self builder componentAt:#OnlyInBLabel) backgroundColor:Color red darkened.
       
   946     ].
       
   947 !
       
   948 
       
   949 updateLists
       
   950     "walk over the two changeSets and add change to one of the tree lists"
       
   951 
       
   952     self methodsOnlyInA removeAll.
       
   953     self methodsOnlyInA addAll: (self classChangeSet methodsOnlyInA collect:self generator).
       
   954     self methodsOnlyInB removeAll.
       
   955     self methodsOnlyInB addAll: (self classChangeSet methodsOnlyInB collect:self generator).
       
   956     self methodsChanged removeAll.
       
   957     self methodsChanged addAll: (self classChangeSet methodsChanged collect:[:arr| self generator value:(arr first)]).
       
   958 
       
   959     self methodsOnlyInA value isEmpty ifTrue:[
  1095         (self builder componentAt:#BoxA) beInvisible.
   960         (self builder componentAt:#BoxA) beInvisible.
  1096     ] ifFalse:[
   961     ] ifFalse:[
  1097         (self builder componentAt:#BoxA) beVisible.
   962         (self builder componentAt:#BoxA) beVisible.
  1098     ].
   963     ].
  1099 
   964 
  1100     nmListB isEmpty ifTrue:[
   965     self methodsOnlyInB value isEmpty ifTrue:[
  1101         (self builder componentAt:#BoxB) beInvisible.
   966         (self builder componentAt:#BoxB) beInvisible.
  1102     ] ifFalse:[
   967     ] ifFalse:[
  1103         (self builder componentAt:#BoxB) beVisible.
   968         (self builder componentAt:#BoxB) beVisible.
  1104     ].
   969     ].
  1105 
   970 
  1106     nmListM isEmpty ifTrue:[
   971     self methodsChanged value isEmpty ifTrue:[
  1107         (nmListA notEmpty or:[nmListB notEmpty]) ifTrue:[
   972         (self methodsOnlyInA value notEmpty or:[self methodsOnlyInB value notEmpty]) ifTrue:[
  1108             (self builder componentAt:#BoxM) beInvisible.
   973             (self builder componentAt:#BoxM) beInvisible.
  1109         ]
   974         ]
  1110     ] ifFalse:[
   975     ] ifFalse:[
  1111         (self builder componentAt:#BoxM) beVisible.
   976         (self builder componentAt:#BoxM) beVisible.
  1112     ]
   977     ]
  1113 !
       
  1114 
       
  1115 updateViewsIfPossible
       
  1116     classBeingCompared notNil ifTrue:[
       
  1117         self window label:'Version Diff Browser on ' , classBeingCompared name.
       
  1118 
       
  1119         self updateLabels.
       
  1120 
       
  1121         changeSetA notNil ifTrue:[
       
  1122             changeSetB notNil ifTrue:[
       
  1123                 self updateLists.
       
  1124                 ^ self
       
  1125             ]
       
  1126         ].
       
  1127 
       
  1128         versionA notNil ifTrue:[
       
  1129             versionB notNil ifTrue:[
       
  1130                 self updateFromVersions
       
  1131             ]
       
  1132         ]
       
  1133     ]
       
  1134 
       
  1135 
       
  1136 ! !
   978 ! !
  1137 
   979 
  1138 !VersionDiffBrowser methodsFor:'values'!
   980 !VersionDiffBrowser methodsFor:'values'!
  1139 
   981 
  1140 addAcceptToTextViewMenus
   982 addAcceptToTextViewMenus
  1141     |m v|
   983     |m v|
  1142 
   984 
  1143     (Array 
   985     (Array 
  1144         with:diffTextView leftTextView
   986         with:self diffTextView leftTextView
  1145         with:diffTextView rightTextView)
   987         with:self diffTextView rightTextView)
  1146     do:[:v |
   988     do:[:v |
  1147         m := v editMenu.
   989         m := v editMenu.
  1148         m addLabels:#('-' 'accept')
   990         m addLabels:#('-' 'accept')
  1149           selectors:(Array with:nil with:#accept)
   991           selectors:(Array with:nil with:#accept)
  1150           after:#copySelection.
   992           after:#copySelection.
  1152             actionAt:#accept 
   994             actionAt:#accept 
  1153             put:[|idx idx2 text change|
   995             put:[|idx idx2 text change|
  1154 
   996 
  1155                  idx := self methodsChangedSelection value.
   997                  idx := self methodsChangedSelection value.
  1156 
   998 
  1157                  v == diffTextView leftTextView ifTrue:[
   999                  v == self diffTextView leftTextView ifTrue:[
  1158                     idx2 := indexFromChangedToA at:idx.
  1000                     idx2 := self indexFromChangedToA at:idx.
  1159                     change := changeSetA at:idx2.
  1001                     change := self changeSetA at:idx2.
  1160                  ] ifFalse:[
  1002                  ] ifFalse:[
  1161                     idx2 := indexFromChangedToB at:idx.
  1003                     idx2 := self indexFromChangedToB at:idx.
  1162                     change := changeSetB at:idx2.
  1004                     change := self changeSetB at:idx2.
  1163                  ].
  1005                  ].
  1164                  change apply
  1006                  change apply
  1165                 ].
  1007                 ].
  1166         m selectorAt:#accept put:nil.
  1008         m selectorAt:#accept put:nil.
  1167         v menuHolder:m.
  1009         v menuHolder:m.
  1168         v menuMessage:#value.
  1010         v menuMessage:#value.
  1169     ]
  1011     ]
  1170 
  1012 
  1171 !
       
  1172 
       
  1173 diffTextView
       
  1174     "automatically generated by UIPainter ..."
       
  1175 
       
  1176     diffTextView isNil ifTrue:[
       
  1177         diffTextView := HVScrollableView
       
  1178                            for:DiffTextView
       
  1179                            miniScrollerH:true miniScrollerV:false.
       
  1180         diffTextView addNextPreviousButtons.
       
  1181 
       
  1182         self addAcceptToTextViewMenus.
       
  1183     ].
       
  1184     ^ diffTextView
       
  1185 ! !
  1013 ! !
  1186 
  1014 
       
  1015 !VersionDiffBrowser::ClassChangeSet class methodsFor:'instance creation'!
       
  1016 
       
  1017 changeSetForClass:aClass andRevision:aVersion
       
  1018 "return a ChangeSet for the class aClass and version aVersion.
       
  1019 The version from the class source stream is checked out from the repositiory
       
  1020 into a source stream. Then the change set is generated from the source stream.
       
  1021 
       
  1022 <return: ChangeSet|nil>
       
  1023 "
       
  1024     |theSourceCodeManager theSourceStream theChangeSet|
       
  1025 
       
  1026     theSourceCodeManager := aClass sourceCodeManager.
       
  1027     [theSourceStream := theSourceCodeManager getSourceStreamFor:aClass revision:aVersion.
       
  1028     theSourceStream notNil
       
  1029         ifTrue:[theChangeSet:=ChangeSet fromStream:theSourceStream]]
       
  1030     valueNowOrOnUnwindDo:
       
  1031         [theSourceStream notNil ifTrue:[theSourceStream close]].
       
  1032     ^theChangeSet
       
  1033 !
       
  1034 
       
  1035 changeSetForClass:aClass andSource:aSource 
       
  1036 "return a ChangeSet for the class aClass and source aSource.
       
  1037 The source is converted to a stream and then the change set is generated
       
  1038 from the source stream.
       
  1039 
       
  1040 <return: ChangeSet|nil>
       
  1041 "
       
  1042     |theChangeSet theSourceStream|
       
  1043 
       
  1044     [(theSourceStream := aSource readStream) notNil
       
  1045         ifTrue:[theChangeSet:=ChangeSet fromStream:(theSourceStream := aSource readStream)]]
       
  1046     valueNowOrOnUnwindDo:
       
  1047         [theSourceStream notNil
       
  1048             ifTrue:[theSourceStream close]].
       
  1049     ^theChangeSet
       
  1050 !
       
  1051 
       
  1052 newForClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB
       
  1053 "return a ClassChangeSet for the class aClass and the two sources.
       
  1054 The two classes are compared via the source files. A new instance of 
       
  1055 ClassChangeSet is generated containing the correspondenting changes.
       
  1056 
       
  1057 <return: ClassChangeSet>
       
  1058 "
       
  1059     |theChangeSetA theChangeSetB theClassChangeSet|
       
  1060 
       
  1061     theClassChangeSet := self new.
       
  1062     theClassChangeSet classBeingCompared:aClass.
       
  1063     theClassChangeSet labelA:aLabelA.
       
  1064     theClassChangeSet labelB:aLabelB.
       
  1065     theChangeSetA:=self changeSetForClass:aClass andSource:aSourceA. 
       
  1066     theChangeSetB:=self changeSetForClass:aClass andSource:aSourceB.
       
  1067     theChangeSetA isNil
       
  1068         ifTrue: [theChangeSetA := ChangeSet new].
       
  1069     theChangeSetB isNil
       
  1070         ifTrue: [theChangeSetB := ChangeSet new].
       
  1071     ^theClassChangeSet changeSet:(theChangeSetA diffSetsAgainst:theChangeSetB)
       
  1072 !
       
  1073 
       
  1074 newForClass:aClass versionA:aVersionA versionB:aVersionB
       
  1075 "return a ClassChangeSet for the class aClass and the two versions.
       
  1076 The two class version are checked out from the repository and then being
       
  1077 compared. A new instance of ClassChangeSet is generated containing 
       
  1078 the correspondenting changes.
       
  1079 
       
  1080 <return: ClassChangeSet>
       
  1081 "
       
  1082     |theChangeSetA theChangeSetB theClassChangeSet|
       
  1083 
       
  1084     theClassChangeSet := self new.
       
  1085     theClassChangeSet classBeingCompared:aClass.
       
  1086     theClassChangeSet labelA:aVersionA.
       
  1087     theClassChangeSet labelB:aVersionB.
       
  1088     theChangeSetA := self changeSetForClass: aClass andRevision: aVersionA.
       
  1089     theChangeSetB := self changeSetForClass: aClass andRevision: aVersionB.
       
  1090     theChangeSetA isNil
       
  1091         ifTrue: [theChangeSetA := ChangeSet new].
       
  1092     theChangeSetB isNil
       
  1093         ifTrue: [theChangeSetB := ChangeSet new].
       
  1094     ^theClassChangeSet changeSet:(theChangeSetA diffSetsAgainst:theChangeSetB)
       
  1095 
       
  1096 ! !
       
  1097 
       
  1098 !VersionDiffBrowser::ClassChangeSet methodsFor:'accessing'!
       
  1099 
       
  1100 changeSet
       
  1101 "returns a identity dictionary containing the different changes.
       
  1102 key:            value:
       
  1103 #changed        OrderedCollection of arrays containing ChangeSets for methods 
       
  1104                 which are changed and exists in the class versionA and versionB
       
  1105 #onlyInArg      ChangeSet for the methods which exists only in the class versionB
       
  1106 #onlyInReceiver ChangeSet for the methods which exists only in the class versionA
       
  1107 
       
  1108 <return: IdentityDictionary>
       
  1109 "  
       
  1110     ^ changeSet
       
  1111 !
       
  1112 
       
  1113 changeSet:something
       
  1114 "sets a identity dictionary containing the different changes.
       
  1115 key:            value:
       
  1116 #changed        OrderedCollection of arrays containing ChangeSets for methods 
       
  1117                 which are changed and exists in the class versionA and versionB
       
  1118 #onlyInArg      ChangeSet for the methods which exists only in the class versionB
       
  1119 #onlyInReceiver ChangeSet for the methods which exists only in the class versionA
       
  1120 
       
  1121 <return: self>
       
  1122 "  
       
  1123 
       
  1124     changeSet := something.
       
  1125 !
       
  1126 
       
  1127 classBeingCompared
       
  1128 "returns the value of the class which is compared
       
  1129 
       
  1130 <return: Behavior>
       
  1131 "
       
  1132 
       
  1133     ^ classBeingCompared
       
  1134 !
       
  1135 
       
  1136 classBeingCompared:something
       
  1137 "set the value of the class which is compared
       
  1138 
       
  1139 <return: self>"
       
  1140 
       
  1141     classBeingCompared := something.
       
  1142 !
       
  1143 
       
  1144 labelA
       
  1145 "returns the label for the class versionA
       
  1146 
       
  1147 <return: String>
       
  1148 "
       
  1149     ^ labelA
       
  1150 !
       
  1151 
       
  1152 labelA:something
       
  1153 "sets the label for the class versionA
       
  1154 
       
  1155 <return: self>
       
  1156 "
       
  1157     labelA := something.
       
  1158 !
       
  1159 
       
  1160 labelB
       
  1161 "returns the label for the class versionB
       
  1162 
       
  1163 <return: String>
       
  1164 "
       
  1165     ^ labelB
       
  1166 !
       
  1167 
       
  1168 labelB:something
       
  1169 "sets the label for the class versionB
       
  1170 
       
  1171 <return: self>
       
  1172 "
       
  1173 
       
  1174     labelB := something.
       
  1175 !
       
  1176 
       
  1177 methodsChanged
       
  1178 "returns a  OrderedCollection of arrays containing ChangeSets for methods 
       
  1179 which are changed and exists in the class versionA and versionB
       
  1180 
       
  1181 <return: OrderedCollection>
       
  1182 "
       
  1183     ^ self changeSet at:#changed
       
  1184 !
       
  1185 
       
  1186 methodsOnlyInA
       
  1187 "returns a ChangeSet for the methods which exists only in the class versionA
       
  1188 
       
  1189 <return: ChangeSet>
       
  1190 "  
       
  1191 
       
  1192     ^ self changeSet at:#onlyInReceiver
       
  1193 !
       
  1194 
       
  1195 methodsOnlyInB
       
  1196 "returns a ChangeSet for the methods which exists only in the class versionB
       
  1197 
       
  1198 <return: ChangeSet>
       
  1199 "  
       
  1200 
       
  1201     ^ self changeSet at:#onlyInArg
       
  1202 ! !
       
  1203 
  1187 !VersionDiffBrowser class methodsFor:'documentation'!
  1204 !VersionDiffBrowser class methodsFor:'documentation'!
  1188 
  1205 
  1189 version
  1206 version
  1190     ^ '$Header: /cvs/stx/stx/libtool/VersionDiffBrowser.st,v 1.13 1999-12-14 14:33:52 cg Exp $'
  1207     ^ '$Header: /cvs/stx/stx/libtool/VersionDiffBrowser.st,v 1.14 1999-12-18 10:57:21 ps Exp $'
  1191 ! !
  1208 ! !