class: ChangesBrowser
added:
#canDeleteChanges
#compareMethodSource:withVersionInClass:into:
changed:
#compareChange:showResult:
#toolbarMenuSpec
refactored for reusability
--- a/ChangesBrowser.st Thu Dec 11 22:49:15 2014 +0100
+++ b/ChangesBrowser.st Thu Dec 11 22:56:28 2014 +0100
@@ -733,6 +733,7 @@
(MenuItem
activeHelpKey: deleteAllForClass
enabled: hasSelectionHolder
+ isVisible: canDeleteChanges
label: 'Delete all for Class'
itemValue: doDeleteClassAll
translateLabel: true
@@ -742,6 +743,7 @@
(MenuItem
activeHelpKey: deleteForClassToEnd
enabled: hasSelectionHolder
+ isVisible: canDeleteChanges
label: 'Delete for Class to End'
itemValue: doDeleteClassRest
translateLabel: true
@@ -852,6 +854,12 @@
^ autoloadAsRequired
!
+canDeleteChanges
+ "makes the delete buttons in the toolbar visible"
+
+ ^ true.
+!
+
changeListSelectionHolder
changeListSelectionHolder isNil ifTrue:[
changeListSelectionHolder := nil asValue.
@@ -4596,8 +4604,7 @@
Return the result of the compare (same -> true, different -> false, uncomparable -> nil).
If doShowResult is true, the outcome is shown in a dialog/diffViewer."
- |aStream chunk sawExcla parseTree thisClass cat oldSource newSource
- parser sel oldMethod outcome showDiff d t1 t2 selector isLoaded beep superClass thisClassSym varsHere varsInChange addedVars removedVars
+ |aStream chunk sawExcla parseTree thisClass cat oldSource newSource outcome showDiff d selector isLoaded beep superClass thisClassSym varsHere varsInChange addedVars removedVars
isSame ownerClass superClassHere superClassInChange sameAndOutcome|
aStream := self streamForChange:changeNr.
@@ -4745,10 +4752,12 @@
]
]
] ifTrue:[
- Class nameSpaceQuerySignal answer:(self nameSpaceForApply)
- do:[
- parseTree := self parseExpression:chunk.
- ].
+ Class nameSpaceQuerySignal
+ answer:(self nameSpaceForApply)
+ do:[
+ parseTree := self parseExpression:chunk.
+ ].
+
(parseTree notNil
and:[parseTree ~~ #Error
and:[parseTree isMessage]]) ifTrue:[
@@ -4790,11 +4799,6 @@
].
thisClass isBehavior ifTrue:[
- (isLoaded := self checkClassIsLoaded:thisClass) ifFalse:[
- outcome := 'Cannot compare this change\\(compare requires class to be loaded).'.
- isSame := nil.
- ].
-
parseTree selector == #methodsFor ifTrue:[
cat := 'Dolphin methods'.
] ifFalse:[
@@ -4806,69 +4810,21 @@
].
newSource := aStream nextChunk.
- Class nameSpaceQuerySignal answer:(self nameSpaceForApply)
- do:[
- parser := Parser parseMethod:newSource in:thisClass.
+ isSame := self
+ compareMethodSource:newSource
+ withVersionInClass:thisClass
+ into:[:outcomeResult :beepResult :oldSourceResult|
+ outcome := outcomeResult.
+ beep := beepResult.
+ oldSource := oldSourceResult.
+ ].
+
+ isSame isNil ifTrue:[
+ showDiff := false.
+ ] ifFalse:[
+ showDiff := isSame not.
].
- (parser notNil and:[parser ~~ #Error]) ifTrue:[
- sel := parser selector.
- oldMethod := thisClass compiledMethodAt:sel.
- oldMethod notNil ifTrue:[
- (oldMethod category = cat) ifFalse:[
-"/ Transcript showCR:'category changed.'.
- ].
- oldSource := oldMethod source.
- (oldSource = newSource) ifTrue:[
- outcome := 'Same source'.
- isSame := true.
- ] ifFalse:[
- oldSource isNil ifTrue:[
- beep := true.
- outcome := 'No source for compare.'.
- isSame := true.
- ] ifFalse:[
- "/
- "/ compare for tabulator <-> space changes
- "/ before showing diff ...
- "/
- t1 := oldSource asCollectionOfLines collect:[:s | s withTabsExpanded].
- t2 := newSource asCollectionOfLines collect:[:s | s withTabsExpanded].
- t1 = t2 ifTrue:[
- outcome := 'Same source'.
- isSame := true.
- ] ifFalse:[
- outcome := 'Source changed.'.
- showDiff := true.
- isSame := false.
-
- "/
- "/ check if only historyLine diffs
- "/
- (HistoryManager notNil
- and:[HistoryManager isActive]) ifTrue:[
- (HistoryManager withoutHistoryLines:newSource)
- =
- (HistoryManager withoutHistoryLines:oldSource)
- ifTrue:[
- outcome := 'Same source (history only)'.
- isSame := true.
- showDiff := false.
- ]
- ].
- ]
- ]
- ]
- ] ifFalse:[
- isLoaded ifTrue:[
- beep := true.
- outcome := 'Method does not exist.'.
- isSame := nil.
- ]
- ]
- ] ifFalse:[
- outcome := 'Change is unparsable (parse error).'.
- isSame := nil.
- ].
+
doShowResult ifTrue:[
(showDiff and:[oldSource notNil and:[newSource notNil]]) ifTrue:[
d := DiffCodeView
@@ -4956,6 +4912,78 @@
^ nil -> 'Unhandled receiver'
!
+compareMethodSource:newSource withVersionInClass:thisClass into:aThreeArgBlock
+ "returns true/false/nil if same,different,undecided;
+ also provides a message and a beep-boolean via the passed in block"
+
+ |parser sel oldMethod oldSource outcome t1 t2 isLoaded|
+
+ Class nameSpaceQuerySignal answer:(self nameSpaceForApply)
+ do:[
+ parser := Parser parseMethod:newSource in:thisClass.
+ ].
+ (parser isNil or:[parser == #Error]) ifTrue:[
+ outcome := 'Change is unparsable (parse error).'.
+ aThreeArgBlock value:outcome value:true "beep" value:nil.
+ ^ nil.
+ ].
+
+ sel := parser selector.
+ oldMethod := thisClass compiledMethodAt:sel.
+ oldMethod isNil ifTrue:[
+ (isLoaded := self checkClassIsLoaded:thisClass) ifFalse:[
+ outcome := 'Cannot compare this change\\(compare requires class to be loaded).'.
+ ] ifTrue:[
+ outcome := 'Method does not exist.'.
+ ].
+ aThreeArgBlock value:outcome value:true "beep" value:nil.
+ ^ nil.
+ ].
+
+ oldSource := oldMethod source.
+ oldSource isNil ifTrue:[
+ outcome := 'No source for compare.'.
+ aThreeArgBlock value:outcome value:true "beep" value:nil.
+ ^ nil.
+ ].
+ (oldSource = newSource) ifTrue:[
+ outcome := 'Same source'.
+ aThreeArgBlock value:outcome value:false "beep" value:oldSource.
+ ^ true.
+ ].
+
+ "/
+ "/ compare for tabulator <-> space changes
+ "/ before showing diff ...
+ "/
+ t1 := oldSource asCollectionOfLines collect:[:s | s withTabsExpanded].
+ t2 := newSource asCollectionOfLines collect:[:s | s withTabsExpanded].
+ t1 = t2 ifTrue:[
+ outcome := 'Same source'.
+ aThreeArgBlock value:outcome value:false "beep" value:oldSource.
+ ^ true.
+ ].
+
+ "/
+ "/ check if only historyLine diffs
+ "/
+ (HistoryManager notNil
+ and:[HistoryManager isActive]) ifTrue:[
+ (HistoryManager withoutHistoryLines:newSource)
+ =
+ (HistoryManager withoutHistoryLines:oldSource)
+ ifTrue:[
+ outcome := 'Same source (history only)'.
+ aThreeArgBlock value:outcome value:false "beep" value:oldSource.
+ ^ true.
+ ]
+ ].
+
+ outcome := 'Source changed.'.
+ aThreeArgBlock value:outcome value:false "beep" value:oldSource.
+ ^ false.
+!
+
comparePackageChange:parseTree
|receiverExpression method thisClass|
@@ -6498,10 +6526,10 @@
!ChangesBrowser class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libtool/ChangesBrowser.st,v 1.462 2014-12-11 20:48:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/ChangesBrowser.st,v 1.463 2014-12-11 21:56:28 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libtool/ChangesBrowser.st,v 1.462 2014-12-11 20:48:16 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libtool/ChangesBrowser.st,v 1.463 2014-12-11 21:56:28 cg Exp $'
! !