Browse Source

Recompile a method moved to protocol. Fix #1142.

Herbert Vojčík 8 years ago
parent
commit
cf50796cc9
2 changed files with 28 additions and 19 deletions
  1. 14 8
      src/IDE.js
  2. 14 11
      src/IDE.st

+ 14 - 8
src/IDE.js

@@ -4690,37 +4690,43 @@ selector: "setMethodProtocol:",
 protocol: "actions",
 fn: function (aString){
 var self=this;
+var klass;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2;
+var $1,$2,$3;
+klass=self._selectedClassOrMetaClass();
 $1=self._cancelChanges();
 if($core.assert($1)){
-$2=$recv(self._protocols())._includes_(aString);
+$2=$recv($recv(self["@selectedMethod"])._methodClass()).__eq(klass);
 if($core.assert($2)){
+$3=$recv(self._protocols())._includes_(aString);
+if($core.assert($3)){
 $recv(self["@selectedMethod"])._protocol_(aString);
+$recv(klass)._compile_protocol_($recv(self["@selectedMethod"])._source(),aString);
 self["@selectedProtocol"]=aString;
 self["@selectedProtocol"];
-self["@selectedMethod"]=self["@selectedMethod"];
-self["@selectedMethod"];
 self._updateProtocolsList();
 self._updateMethodsList();
 self._updateSourceAndButtons();
 } else {
 self._addNewProtocol();
 }
+} else {
+$recv($globals.Terminal)._alert_("Method is from trait composition.");
+}
 }
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"setMethodProtocol:",{aString:aString},$globals.Browser)});
+}, function($ctx1) {$ctx1.fill(self,"setMethodProtocol:",{aString:aString,klass:klass},$globals.Browser)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["aString"],
-source: "setMethodProtocol: aString\x0a\x09self cancelChanges ifTrue: [\x0a\x09(self protocols includes: aString)\x0a\x09\x09ifFalse: [ self addNewProtocol ]\x0a\x09\x09ifTrue: [\x0a\x09\x09selectedMethod protocol: aString.\x0a\x09\x09selectedProtocol := aString.\x0a\x09\x09selectedMethod := selectedMethod.\x0a\x09\x09self\x0a\x09\x09\x09updateProtocolsList;\x0a\x09\x09\x09updateMethodsList;\x0a\x09\x09\x09updateSourceAndButtons ]]",
-referencedClasses: [],
+source: "setMethodProtocol: aString\x0a\x09| klass |\x0a\x09klass := self selectedClassOrMetaClass.\x0a\x09self cancelChanges ifTrue: [ selectedMethod methodClass = klass\x0a\x09\x09ifFalse: [ Terminal alert: 'Method is from trait composition.' ]\x0a\x09\x09ifTrue: [ (self protocols includes: aString)\x0a\x09\x09\x09ifFalse: [ self addNewProtocol ]\x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09selectedMethod protocol: aString.\x0a\x09\x09\x09\x09klass compile: selectedMethod source protocol: aString.\x0a\x09\x09\x09\x09selectedProtocol := aString.\x0a\x09\x09\x09\x09self\x0a\x09\x09\x09\x09\x09updateProtocolsList;\x0a\x09\x09\x09\x09\x09updateMethodsList;\x0a\x09\x09\x09\x09\x09updateSourceAndButtons ]]]",
+referencedClasses: ["Terminal"],
 //>>excludeEnd("ide");
-messageSends: ["ifTrue:", "cancelChanges", "ifFalse:ifTrue:", "includes:", "protocols", "addNewProtocol", "protocol:", "updateProtocolsList", "updateMethodsList", "updateSourceAndButtons"]
+messageSends: ["selectedClassOrMetaClass", "ifTrue:", "cancelChanges", "ifFalse:ifTrue:", "=", "methodClass", "alert:", "includes:", "protocols", "addNewProtocol", "protocol:", "compile:protocol:", "source", "updateProtocolsList", "updateMethodsList", "updateSourceAndButtons"]
 }),
 $globals.Browser);
 

+ 14 - 11
src/IDE.st

@@ -990,17 +990,20 @@ selectTab: aString
 !
 
 setMethodProtocol: aString
-	self cancelChanges ifTrue: [
-	(self protocols includes: aString)
-		ifFalse: [ self addNewProtocol ]
-		ifTrue: [
-		selectedMethod protocol: aString.
-		selectedProtocol := aString.
-		selectedMethod := selectedMethod.
-		self
-			updateProtocolsList;
-			updateMethodsList;
-			updateSourceAndButtons ]]
+	| klass |
+	klass := self selectedClassOrMetaClass.
+	self cancelChanges ifTrue: [ selectedMethod methodClass = klass
+		ifFalse: [ Terminal alert: 'Method is from trait composition.' ]
+		ifTrue: [ (self protocols includes: aString)
+			ifFalse: [ self addNewProtocol ]
+			ifTrue: [
+				selectedMethod protocol: aString.
+				klass compile: selectedMethod source protocol: aString.
+				selectedProtocol := aString.
+				self
+					updateProtocolsList;
+					updateMethodsList;
+					updateSourceAndButtons ]]]
 !
 
 showClassButtons