changed: #apply
authorClaus Gittinger <cg@exept.de>
Wed, 07 Sep 2011 15:42:14 +0200
changeset 2512 9caca2c0b8ed
parent 2511 6bd0081d93bb
child 2513 870cc96b3fbc
changed: #apply replacement classes
MethodChange.st
--- a/MethodChange.st	Wed Sep 07 14:34:03 2011 +0200
+++ b/MethodChange.st	Wed Sep 07 15:42:14 2011 +0200
@@ -221,23 +221,56 @@
 apply
     "apply the change"
 
-    |class className|
+    |class replacementClassName suggestion|
 
     class := self changeClass.
     class isNil ifTrue:[
-        className := Dialog 
-                        request:('Cannot apply change for missing class: %1\\Use replacement class (or press cancel)' bindWith:className) withCRs
-                        initialAnswer:LastReplacementClass.
-        (className isEmptyOrNil
-        or:[ (class := Smalltalk classNamed:className) isNil]) ifTrue:[
-            self error:('Cannot apply change for missing class: ' , className) mayProceed:true.
-            ^ self
-        ].
-        LastReplacementClass := className
+        "/ try the same replacement class again
+        (LastReplacementClass notEmptyOrNil 
+            and:[ (class := Smalltalk classNamed:LastReplacementClass) notNil
+            and:[ 
+                (className endsWith:' class') ifTrue:[
+                    class := class theMetaclass
+                ] ifFalse:[
+                    class := class theNonMetaclass
+                ].
+                class nameWithoutPrefix = className    
+            ]])
+        ifFalse:[
+            "/ try a replacement class in the same namespace again
+            suggestion := LastReplacementClass.
+            (class notNil
+            and:[ (class := class nameSpace classNamed:className) notNil
+            and:[ 
+                (className endsWith:' class') ifTrue:[
+                    class := class theMetaclass
+                ] ifFalse:[
+                    class := class theNonMetaclass
+                ].
+                class nameWithoutPrefix = className    
+            ]])
+            ifFalse:[
+                "/ ask for a replacement class
+                replacementClassName := Dialog 
+                                request:('Cannot apply change for missing class: %1\\Use replacement class (or press cancel)' bindWith:className) withCRs
+                                initialAnswer:suggestion.
+                (replacementClassName isEmptyOrNil
+                or:[ (class := Smalltalk classNamed:replacementClassName) isNil]) ifTrue:[
+                    self error:('Cannot apply change for missing class: ' , replacementClassName) mayProceed:true.
+                    ^ self
+                ].
+                (className endsWith:' class') ifTrue:[
+                    class := class theMetaclass
+                ] ifFalse:[
+                    class := class theNonMetaclass
+                ].
+                LastReplacementClass := replacementClassName
+            ]
+        ]
     ].
     class compile:source classified:methodCategory logged:true.
 
-    "Modified: / 05-09-2011 / 09:27:14 / cg"
+    "Modified: / 07-09-2011 / 15:39:16 / cg"
 ! !
 
 !MethodChange methodsFor:'comparing'!
@@ -398,7 +431,7 @@
 !MethodChange class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic3/MethodChange.st,v 1.60 2011-09-05 07:54:45 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic3/MethodChange.st,v 1.61 2011-09-07 13:42:14 cg Exp $'
 !
 
 version_SVN