VersionDiffBrowser.st
changeset 2745 8fa3af64f96e
parent 2731 5628e2514bfa
child 2751 f2fbe11e166a
equal deleted inserted replaced
2744:0ebeada0fee0 2745:8fa3af64f96e
    12 
    12 
    13 
    13 
    14 "{ Package: 'stx:libtool' }"
    14 "{ Package: 'stx:libtool' }"
    15 
    15 
    16 ApplicationModel subclass:#VersionDiffBrowser
    16 ApplicationModel subclass:#VersionDiffBrowser
    17 	instanceVariableNames:'classChangeSet diffTextView'
    17 	instanceVariableNames:'classChangeSet diffTextView boxAVisible boxBVisible boxMVisible'
    18 	classVariableNames:''
    18 	classVariableNames:''
    19 	poolDictionaries:''
    19 	poolDictionaries:''
    20 	category:'Interface-Browsers'
    20 	category:'Interface-Browsers'
    21 !
    21 !
    22 
    22 
   642 "
   642 "
   643 get the two method changes for the selected 'changed method'.
   643 get the two method changes for the selected 'changed method'.
   644 
   644 
   645 <return: <Array with:MethodChange with:MethodChange | nil>>
   645 <return: <Array with:MethodChange with:MethodChange | nil>>
   646 "
   646 "
   647     |sel changeA changeB|
   647     |sel changeA changeB theTwoChanges|
   648 
   648 
   649     sel := self methodsChangedSelection value.
   649     sel := self methodsChangedSelection value.
   650     sel notNil ifTrue:[
   650     sel notNil ifTrue:[
   651         changeA := (self classChangeSet methodsChanged at:sel) first.
   651         theTwoChanges := self classChangeSet methodsChanged at:sel.
   652         changeB := (self classChangeSet methodsChanged at:sel) second.
   652         changeA := theTwoChanges first.
   653         ^ Array with:changeA 
   653         changeB := theTwoChanges second.
   654                 with:changeB 
   654         ^ Array with:changeA with:changeB 
   655     ].
   655     ].
   656     ^ nil
   656     ^ nil
   657 !
   657 !
   658 
   658 
   659 versionA
   659 versionA
   745 ! !
   745 ! !
   746 
   746 
   747 !VersionDiffBrowser methodsFor:'aspects'!
   747 !VersionDiffBrowser methodsFor:'aspects'!
   748 
   748 
   749 boxAVisible
   749 boxAVisible
   750     |holder|
   750     boxAVisible isNil ifTrue:[
   751 
   751         boxAVisible := true asValue.
   752     (holder := builder bindingAt:#boxAVisible) isNil ifTrue:[
   752     ].
   753         builder aspectAt:#boxAVisible put:(holder := true asValue).
   753     ^ boxAVisible.
   754     ].
       
   755     ^ holder.
       
   756 !
   754 !
   757 
   755 
   758 boxBVisible
   756 boxBVisible
   759     |holder|
   757     boxBVisible isNil ifTrue:[
   760 
   758         boxBVisible := true asValue.
   761     (holder := builder bindingAt:#boxBVisible) isNil ifTrue:[
   759     ].
   762         builder aspectAt:#boxBVisible put:(holder := true asValue).
   760     ^ boxBVisible.
   763     ].
       
   764     ^ holder.
       
   765 !
   761 !
   766 
   762 
   767 boxMVisible
   763 boxMVisible
   768     |holder|
   764     boxMVisible isNil ifTrue:[
   769 
   765         boxMVisible := true asValue.
   770     (holder := builder bindingAt:#boxMVisible) isNil ifTrue:[
   766     ].
   771         builder aspectAt:#boxMVisible put:(holder := true asValue).
   767     ^ boxMVisible.
   772     ].
       
   773     ^ holder.
       
   774 !
   768 !
   775 
   769 
   776 changedLabelHolder
   770 changedLabelHolder
   777 "
   771 "
   778 aspect for the label of the changed method box.
   772 aspect for the label of the changed method box.
  1192     ].
  1186     ].
  1193     ^ nil
  1187     ^ nil
  1194 ! !
  1188 ! !
  1195 
  1189 
  1196 !VersionDiffBrowser methodsFor:'private'!
  1190 !VersionDiffBrowser methodsFor:'private'!
  1197 
       
  1198 generator
       
  1199 "
       
  1200 generate a print string for a change.
       
  1201 
       
  1202 <return: Block>
       
  1203 "
       
  1204     ^[:aChange |
       
  1205         |result mPkg cPkg cls m changeClassName|
       
  1206 
       
  1207         aChange isClassDefinitionChange ifTrue:[
       
  1208             result := aChange printStringWithoutClassName
       
  1209         ] ifFalse:[
       
  1210             aChange isDoIt ifTrue:[
       
  1211                 result := aChange source , ' (doIt)'
       
  1212             ] ifFalse:[
       
  1213                 changeClassName := aChange className.
       
  1214                 changeClassName = self classBeingCompared name ifTrue:[
       
  1215                     result := aChange printStringWithoutClassName.
       
  1216                     aChange isMethodChange ifTrue:[
       
  1217                         cls := aChange changeClass.
       
  1218                         cls notNil ifTrue:[
       
  1219                             m := cls compiledMethodAt:aChange selector.
       
  1220                             (m notNil 
       
  1221                             and:[m package ~= cls package]) ifTrue:[
       
  1222                                 result := aChange printStringWithoutClassName , ' [' , m package , ']'.
       
  1223                             ].
       
  1224                         ].
       
  1225                     ]
       
  1226                 ] ifFalse:[
       
  1227                     "/ include name in private class changes
       
  1228                     (changeClassName startsWith:(self classBeingCompared name , '::')) ifTrue:[
       
  1229                         result := (changeClassName copyFrom:(self classBeingCompared name size + 3)) , ' ' ,  aChange printStringWithoutClassName
       
  1230                     ] ifFalse:[
       
  1231                         result := aChange printString
       
  1232                     ]
       
  1233                 ]
       
  1234             ]
       
  1235         ].
       
  1236         result
       
  1237     ].
       
  1238 
       
  1239 !
       
  1240 
       
  1241 resetSelectionHolders
       
  1242 "
       
  1243 reset all selection holders when a new change set is given.
       
  1244 First set the selection to nil. 
       
  1245 
       
  1246 <return: self>
       
  1247 "
       
  1248 
       
  1249     self methodsChangedSelection value:nil.
       
  1250     self methodsOnlyInASelection value:nil.
       
  1251     self methodsOnlyInBSelection value:nil.
       
  1252     self diffTextView text1:'' text2:''.
       
  1253     self methodText value:''.
       
  1254 
       
  1255 "/    self methodsChangedSelectionChanged.
       
  1256 "/    self methodsOnlyInASelectionChanged.
       
  1257 "/    self methodsOnlyInBSelectionChanged.
       
  1258 
       
  1259 !
       
  1260 
       
  1261 showDiffTextView
       
  1262 "
       
  1263 if a method change is selected, then show the diff text view.
       
  1264 Add an accept entry to the popup menu.
       
  1265 
       
  1266 <return: self>
       
  1267 "
       
  1268     |builder|
       
  1269 
       
  1270     builder := self builder.
       
  1271     (builder componentAt:#diffTextViewBox) raise; beVisible.
       
  1272     (builder componentAt:#singleTextView) beInvisible.
       
  1273     (builder componentAt:#diffTextView) realizeAllSubViews.
       
  1274 
       
  1275     self addAcceptToTextViewMenus.
       
  1276 !
       
  1277 
       
  1278 showSingleTextView
       
  1279 "
       
  1280 if a method  is selected which is only in version A or B of the class,
       
  1281 then show the text view.
       
  1282 Add an accept entry to the popup menu.
       
  1283 
       
  1284 <return: self>
       
  1285 "
       
  1286 
       
  1287     |builder|
       
  1288 
       
  1289     builder := self builder.
       
  1290     (builder componentAt:#singleTextView) raise; beVisible.
       
  1291     (builder componentAt:#diffTextViewBox) beInvisible.
       
  1292     self addAcceptToTextViewMenus.
       
  1293 !
       
  1294 
       
  1295 updateLabels
       
  1296 "
       
  1297 update the labels of the diff text view. Show the version numbers
       
  1298 of the class.
       
  1299 
       
  1300 <return: self>
       
  1301 "
       
  1302 
       
  1303     |theVersionA theVersionB builder|
       
  1304 
       
  1305     builder := self builder.
       
  1306     (theVersionA := self versionA) notNil ifTrue:[
       
  1307         self diffTextLabelA value:theVersionA.
       
  1308         self onlyInALabelHolder value:('Only in ' , theVersionA).
       
  1309         (builder componentAt:#OnlyInALabel) backgroundColor:Color green darkened.
       
  1310     ].
       
  1311     (theVersionB :=self versionB) notNil ifTrue:[
       
  1312         self diffTextLabelB value:theVersionB.
       
  1313         self onlyInBLabelHolder value:('Only in ' , theVersionB).
       
  1314         (builder componentAt:#OnlyInBLabel) backgroundColor:Color red darkened.
       
  1315     ].
       
  1316 !
       
  1317 
       
  1318 updateLists
       
  1319 "walk over the two changeSets and add change to one of the tree lists.
       
  1320 Methods which belong to the version A of the class or version B go
       
  1321 to the list methodsOnlyInA or methodsOnlyInB.
       
  1322 Methods which are changed from version A to B go to the list methodsChanged.
       
  1323 
       
  1324 <return: self>
       
  1325 "
       
  1326     |classChangeSet listOnlyInA listOnlyInB listChanged|
       
  1327 
       
  1328     classChangeSet := self classChangeSet.
       
  1329 
       
  1330     listOnlyInA := self methodsOnlyInA. 
       
  1331     listOnlyInA removeAll.
       
  1332     classChangeSet notNil ifTrue:[
       
  1333         listOnlyInA addAll: (classChangeSet methodsOnlyInA collect:self generator).
       
  1334     ].
       
  1335 
       
  1336     listOnlyInB := self methodsOnlyInB. 
       
  1337     listOnlyInB removeAll.
       
  1338     classChangeSet notNil ifTrue:[
       
  1339         listOnlyInB addAll: (classChangeSet methodsOnlyInB collect:self generator).
       
  1340     ].
       
  1341 
       
  1342     listChanged := self methodsChanged. 
       
  1343     listChanged removeAll.
       
  1344     classChangeSet notNil ifTrue:[
       
  1345         listChanged addAll: (classChangeSet methodsChanged collect:[:arr| self generator value:(arr first)]).
       
  1346     ].
       
  1347 
       
  1348     self boxAVisible value:(listOnlyInA notEmpty).
       
  1349     self boxBVisible value:(listOnlyInB notEmpty).
       
  1350 
       
  1351     self boxMVisible value:(listChanged isEmpty 
       
  1352                             and: [(listOnlyInA notEmpty 
       
  1353                                   or:[listOnlyInB notEmpty])]) not.
       
  1354 ! !
       
  1355 
       
  1356 !VersionDiffBrowser methodsFor:'setup'!
       
  1357 
       
  1358 setupForClass:aClass againstVersion:aVersionA
       
  1359 "
       
  1360 compute the class change set for the class aClass of its current version against the repository version A.
       
  1361 When setting the class change set, the labels, list etc. of the receiver
       
  1362 are updated.
       
  1363 
       
  1364 <return: self>
       
  1365 "
       
  1366     |changeSet|
       
  1367 
       
  1368     aClass isNameSpace ifFalse:[
       
  1369         aClass isLoaded ifTrue:[
       
  1370             changeSet := (ClassChangeSet newForClass:aClass againstVersion:aVersionA).
       
  1371         ]
       
  1372     ].
       
  1373     self classChangeSet:changeSet
       
  1374 !
       
  1375 
       
  1376 setupForClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB
       
  1377 "
       
  1378 generate the class change set from the two source files A and B.
       
  1379 When setting the class change set, the labels, list etc. of the receiver
       
  1380 are updated.
       
  1381 
       
  1382 <return: self>
       
  1383 "
       
  1384     |changeSet|
       
  1385 
       
  1386     aClass isNameSpace ifFalse:[
       
  1387         aClass isLoaded ifTrue:[
       
  1388             changeSet := (ClassChangeSet newForClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB).
       
  1389         ]
       
  1390     ].
       
  1391     self classChangeSet:changeSet
       
  1392 !
       
  1393 
       
  1394 setupForClass:aClass versionA:aVersionA versionB:aVersionB
       
  1395 "
       
  1396 compute the class change set for the class aClass and the versions A and B.
       
  1397 When setting the class change set, the labels, list etc. of the receiver
       
  1398 are updated.
       
  1399 
       
  1400 <return: self>
       
  1401 "
       
  1402     |changeSet|
       
  1403 
       
  1404     aClass isNameSpace ifFalse:[
       
  1405         aClass isLoaded ifTrue:[
       
  1406             changeSet := (ClassChangeSet newForClass:aClass versionA:aVersionA versionB:aVersionB).
       
  1407         ]
       
  1408     ].
       
  1409     self classChangeSet:changeSet
       
  1410 ! !
       
  1411 
       
  1412 !VersionDiffBrowser methodsFor:'values'!
       
  1413 
  1191 
  1414 addAcceptToTextViewMenus
  1192 addAcceptToTextViewMenus
  1415 "
  1193 "
  1416 add to the standard diff text view or single text views menu an accept entry.
  1194 add to the standard diff text view or single text views menu an accept entry.
  1417 The acceptAction will fetch the corresponding change and apply it
  1195 The acceptAction will fetch the corresponding change and apply it
  1465             ].
  1243             ].
  1466         m selectorAt:#accept put:nil.
  1244         m selectorAt:#accept put:nil.
  1467         v menuHolder:m.
  1245         v menuHolder:m.
  1468         v menuMessage:#value.
  1246         v menuMessage:#value.
  1469     ]
  1247     ]
       
  1248 !
       
  1249 
       
  1250 generator
       
  1251 "
       
  1252 generate a print string for a change.
       
  1253 
       
  1254 <return: Block>
       
  1255 "
       
  1256     ^[:aChange |
       
  1257         |result mPkg cPkg cls m changeClassName|
       
  1258 
       
  1259         aChange isClassDefinitionChange ifTrue:[
       
  1260             result := aChange printStringWithoutClassName
       
  1261         ] ifFalse:[
       
  1262             aChange isDoIt ifTrue:[
       
  1263                 result := aChange source , ' (doIt)'
       
  1264             ] ifFalse:[
       
  1265                 changeClassName := aChange className.
       
  1266                 changeClassName = self classBeingCompared name ifTrue:[
       
  1267                     result := aChange printStringWithoutClassName.
       
  1268 
       
  1269                     aChange isMethodCategoryChange ifTrue:[
       
  1270                         result := result , ' (category)'
       
  1271                     ] ifFalse:[
       
  1272                         aChange isMethodChange ifTrue:[
       
  1273                             cls := aChange changeClass.
       
  1274                             cls notNil ifTrue:[
       
  1275                                 m := cls compiledMethodAt:aChange selector.
       
  1276                                 (m notNil 
       
  1277                                 and:[m package ~= cls package]) ifTrue:[
       
  1278                                     result := aChange printStringWithoutClassName , ' [' , m package , ']'.
       
  1279                                 ].
       
  1280                             ].
       
  1281                         ]
       
  1282                     ]
       
  1283                 ] ifFalse:[
       
  1284                     "/ include name in private class changes
       
  1285                     (changeClassName startsWith:(self classBeingCompared name , '::')) ifTrue:[
       
  1286                         result := (changeClassName copyFrom:(self classBeingCompared name size + 3)) , ' ' ,  aChange printStringWithoutClassName
       
  1287                     ] ifFalse:[
       
  1288                         result := aChange printString
       
  1289                     ]
       
  1290                 ]
       
  1291             ]
       
  1292         ].
       
  1293         result
       
  1294     ].
       
  1295 !
       
  1296 
       
  1297 resetSelectionHolders
       
  1298 "
       
  1299 reset all selection holders when a new change set is given.
       
  1300 First set the selection to nil. 
       
  1301 
       
  1302 <return: self>
       
  1303 "
       
  1304 
       
  1305     self methodsChangedSelection value:nil.
       
  1306     self methodsOnlyInASelection value:nil.
       
  1307     self methodsOnlyInBSelection value:nil.
       
  1308     self diffTextView text1:'' text2:''.
       
  1309     self methodText value:''.
       
  1310 
       
  1311 "/    self methodsChangedSelectionChanged.
       
  1312 "/    self methodsOnlyInASelectionChanged.
       
  1313 "/    self methodsOnlyInBSelectionChanged.
       
  1314 
       
  1315 !
       
  1316 
       
  1317 showDiffTextView
       
  1318 "
       
  1319 if a method change is selected, then show the diff text view.
       
  1320 Add an accept entry to the popup menu.
       
  1321 
       
  1322 <return: self>
       
  1323 "
       
  1324     |builder|
       
  1325 
       
  1326     builder := self builder.
       
  1327     (builder componentAt:#diffTextViewBox) raise; beVisible.
       
  1328     (builder componentAt:#singleTextView) beInvisible.
       
  1329     (builder componentAt:#diffTextView) realizeAllSubViews.
       
  1330 
       
  1331     self addAcceptToTextViewMenus.
       
  1332 !
       
  1333 
       
  1334 showSingleTextView
       
  1335 "
       
  1336 if a method  is selected which is only in version A or B of the class,
       
  1337 then show the text view.
       
  1338 Add an accept entry to the popup menu.
       
  1339 
       
  1340 <return: self>
       
  1341 "
       
  1342 
       
  1343     |builder|
       
  1344 
       
  1345     builder := self builder.
       
  1346     (builder componentAt:#singleTextView) raise; beVisible.
       
  1347     (builder componentAt:#diffTextViewBox) beInvisible.
       
  1348     self addAcceptToTextViewMenus.
       
  1349 !
       
  1350 
       
  1351 updateLabels
       
  1352 "
       
  1353 update the labels of the diff text view. Show the version numbers
       
  1354 of the class.
       
  1355 
       
  1356 <return: self>
       
  1357 "
       
  1358 
       
  1359     |theVersionA theVersionB builder|
       
  1360 
       
  1361     builder := self builder.
       
  1362     (theVersionA := self versionA) notNil ifTrue:[
       
  1363         self diffTextLabelA value:theVersionA.
       
  1364         self onlyInALabelHolder value:('Only in ' , theVersionA).
       
  1365         (builder componentAt:#OnlyInALabel) backgroundColor:Color green darkened.
       
  1366     ].
       
  1367     (theVersionB :=self versionB) notNil ifTrue:[
       
  1368         self diffTextLabelB value:theVersionB.
       
  1369         self onlyInBLabelHolder value:('Only in ' , theVersionB).
       
  1370         (builder componentAt:#OnlyInBLabel) backgroundColor:Color red darkened.
       
  1371     ].
       
  1372 !
       
  1373 
       
  1374 updateLists
       
  1375 "walk over the two changeSets and add change to one of the tree lists.
       
  1376 Methods which belong to the version A of the class or version B go
       
  1377 to the list methodsOnlyInA or methodsOnlyInB.
       
  1378 Methods which are changed from version A to B go to the list methodsChanged.
       
  1379 
       
  1380 <return: self>
       
  1381 "
       
  1382     |classChangeSet listOnlyInA listOnlyInB listChanged|
       
  1383 
       
  1384     classChangeSet := self classChangeSet.
       
  1385 
       
  1386     listOnlyInA := self methodsOnlyInA. 
       
  1387     listOnlyInA removeAll.
       
  1388     classChangeSet notNil ifTrue:[
       
  1389         listOnlyInA addAll: (classChangeSet methodsOnlyInA collect:self generator).
       
  1390     ].
       
  1391 
       
  1392     listOnlyInB := self methodsOnlyInB. 
       
  1393     listOnlyInB removeAll.
       
  1394     classChangeSet notNil ifTrue:[
       
  1395         listOnlyInB addAll: (classChangeSet methodsOnlyInB collect:self generator).
       
  1396     ].
       
  1397 
       
  1398     listChanged := self methodsChanged. 
       
  1399     listChanged removeAll.
       
  1400     classChangeSet notNil ifTrue:[
       
  1401         listChanged addAll: (classChangeSet methodsChanged collect:[:arr| self generator value:(arr first)]).
       
  1402     ].
       
  1403 
       
  1404     self boxAVisible value:(listOnlyInA notEmpty).
       
  1405     self boxBVisible value:(listOnlyInB notEmpty).
       
  1406 
       
  1407     self boxMVisible value:(listChanged isEmpty 
       
  1408                             and: [(listOnlyInA notEmpty 
       
  1409                                   or:[listOnlyInB notEmpty])]) not.
       
  1410 ! !
       
  1411 
       
  1412 !VersionDiffBrowser methodsFor:'setup'!
       
  1413 
       
  1414 setupForClass:aClass againstVersion:aVersionA
       
  1415 "
       
  1416 compute the class change set for the class aClass of its current version against the repository version A.
       
  1417 When setting the class change set, the labels, list etc. of the receiver
       
  1418 are updated.
       
  1419 
       
  1420 <return: self>
       
  1421 "
       
  1422     |changeSet|
       
  1423 
       
  1424     aClass isNil ifTrue:[
       
  1425         changeSet := nil
       
  1426     ] ifFalse:[
       
  1427         aClass isNameSpace ifFalse:[
       
  1428             aClass isLoaded ifTrue:[
       
  1429                 changeSet := (ClassChangeSet newForClass:aClass againstVersion:aVersionA).
       
  1430             ]
       
  1431         ].
       
  1432     ].
       
  1433     self classChangeSet:changeSet
       
  1434 !
       
  1435 
       
  1436 setupForClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB
       
  1437 "
       
  1438 generate the class change set from the two source files A and B.
       
  1439 When setting the class change set, the labels, list etc. of the receiver
       
  1440 are updated.
       
  1441 
       
  1442 <return: self>
       
  1443 "
       
  1444     |changeSet|
       
  1445 
       
  1446     aClass isNameSpace ifFalse:[
       
  1447         aClass isLoaded ifTrue:[
       
  1448             changeSet := (ClassChangeSet newForClass:aClass labelA:aLabelA sourceA:aSourceA labelB:aLabelB sourceB:aSourceB).
       
  1449         ]
       
  1450     ].
       
  1451     self classChangeSet:changeSet
       
  1452 !
       
  1453 
       
  1454 setupForClass:aClass versionA:aVersionA versionB:aVersionB
       
  1455 "
       
  1456 compute the class change set for the class aClass and the versions A and B.
       
  1457 When setting the class change set, the labels, list etc. of the receiver
       
  1458 are updated.
       
  1459 
       
  1460 <return: self>
       
  1461 "
       
  1462     |changeSet|
       
  1463 
       
  1464     aClass isNameSpace ifFalse:[
       
  1465         aClass isLoaded ifTrue:[
       
  1466             changeSet := (ClassChangeSet newForClass:aClass versionA:aVersionA versionB:aVersionB).
       
  1467         ]
       
  1468     ].
       
  1469     self classChangeSet:changeSet
  1470 ! !
  1470 ! !
  1471 
  1471 
  1472 !VersionDiffBrowser::ClassChangeSet class methodsFor:'instance creation'!
  1472 !VersionDiffBrowser::ClassChangeSet class methodsFor:'instance creation'!
  1473 
  1473 
  1474 changeSetForClass:aClass 
  1474 changeSetForClass:aClass 
  1719 ! !
  1719 ! !
  1720 
  1720 
  1721 !VersionDiffBrowser class methodsFor:'documentation'!
  1721 !VersionDiffBrowser class methodsFor:'documentation'!
  1722 
  1722 
  1723 version
  1723 version
  1724     ^ '$Header: /cvs/stx/stx/libtool/VersionDiffBrowser.st,v 1.32 2000-08-23 12:19:43 cg Exp $'
  1724     ^ '$Header: /cvs/stx/stx/libtool/VersionDiffBrowser.st,v 1.33 2000-08-31 10:04:21 cg Exp $'
  1725 ! !
  1725 ! !