瀏覽代碼

- several fixes for Views
- New label view

Nicolas Petton 10 年之前
父節點
當前提交
6cbf4e4406
共有 6 個文件被更改,包括 163 次插入31 次删除
  1. 3 3
      js/Moka-Controllers.js
  2. 25 11
      js/Moka-Core.js
  3. 85 8
      js/Moka-Views.js
  4. 1 1
      st/Moka-Controllers.st
  5. 11 4
      st/Moka-Core.st
  6. 38 4
      st/Moka-Views.st

+ 3 - 3
js/Moka-Controllers.js

@@ -51,11 +51,11 @@ category: 'actions',
 fn: function (aString){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-self._performAtionWith_(aString);
+self._performActionWith_(aString);
 return self}, function($ctx1) {$ctx1.fill(self,"onEnterPressed:",{aString:aString},smalltalk.MKInputController)})},
 args: ["aString"],
-source: "onEnterPressed: aString\x0a\x09self performAtionWith: aString",
-messageSends: ["performAtionWith:"],
+source: "onEnterPressed: aString\x0a\x09self performActionWith: aString",
+messageSends: ["performActionWith:"],
 referencedClasses: []
 }),
 smalltalk.MKInputController);

+ 25 - 11
js/Moka-Core.js

@@ -142,21 +142,19 @@ category: 'actions',
 fn: function (anObject){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2,$4,$3;
+var $1;
 $1=self._aspect();
 $ctx1.sendIdx["aspect"]=1;
 if(($receiver = $1) == nil || $receiver == null){
-$1;
+return self;
 } else {
-$2=self._model();
-$4=self._aspect();
-$3=_st($4)._asMutator();
-_st($2)._perform_withArguments_($3,[anObject]);
+$1;
 };
+_st(self._model())._perform_withArguments_(_st(self._aspect())._asMutator(),[anObject]);
 return self}, function($ctx1) {$ctx1.fill(self,"performActionWith:",{anObject:anObject},smalltalk.MKAspectController)})},
 args: ["anObject"],
-source: "performActionWith: anObject\x0a\x09self aspect ifNotNil: [\x0a\x09\x09self model \x0a\x09\x09\x09perform: self aspect asMutator\x0a\x09\x09\x09withArguments: { anObject } ]",
-messageSends: ["ifNotNil:", "aspect", "perform:withArguments:", "model", "asMutator"],
+source: "performActionWith: anObject\x0a\x09self aspect ifNil: [ ^ self ].\x0a\x09\x0a\x09self model \x0a\x09\x09perform: self aspect asMutator\x0a\x09\x09withArguments: { anObject }",
+messageSends: ["ifNil:", "aspect", "perform:withArguments:", "model", "asMutator"],
 referencedClasses: []
 }),
 smalltalk.MKAspectController);
@@ -627,6 +625,23 @@ referencedClasses: []
 }),
 smalltalk.MKAspectView);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultControllerClass",
+category: 'defaults',
+fn: function (){
+var self=this;
+function $MKAspectController(){return smalltalk.MKAspectController||(typeof MKAspectController=="undefined"?nil:MKAspectController)}
+return smalltalk.withContext(function($ctx1) { 
+return $MKAspectController();
+}, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKAspectView)})},
+args: [],
+source: "defaultControllerClass\x0a\x09^ MKAspectController",
+messageSends: [],
+referencedClasses: ["MKAspectController"]
+}),
+smalltalk.MKAspectView);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "observeModel",
@@ -652,11 +667,10 @@ category: 'updating',
 fn: function (anAnnouncement){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-var $2,$3,$1;
+var $2,$1;
 $2=_st(anAnnouncement)._aspect();
 $ctx1.sendIdx["aspect"]=1;
-$3=self._aspect();
-$1=_st($2).__eq($3);
+$1=_st($2).__eq(self._aspect());
 if(smalltalk.assert($1)){
 self._update();
 };

+ 85 - 8
js/Moka-Views.js

@@ -224,6 +224,23 @@ referencedClasses: []
 }),
 smalltalk.MKCheckboxView);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultControllerClass",
+category: 'defaults',
+fn: function (){
+var self=this;
+function $MKCheckboxController(){return smalltalk.MKCheckboxController||(typeof MKCheckboxController=="undefined"?nil:MKCheckboxController)}
+return smalltalk.withContext(function($ctx1) { 
+return $MKCheckboxController();
+}, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKCheckboxView)})},
+args: [],
+source: "defaultControllerClass\x0a\x09^ MKCheckboxController",
+messageSends: [],
+referencedClasses: ["MKCheckboxController"]
+}),
+smalltalk.MKCheckboxView);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "label",
@@ -285,20 +302,25 @@ selector: "renderContentOn:",
 category: 'rendering',
 fn: function (html){
 var self=this;
+var checkbox;
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2;
+var $1,$2,$3;
 $1=_st(html)._input();
 _st($1)._type_("checkbox");
-_st($1)._at_put_("checked",self._checked());
 _st($1)._value_(self._label());
 $2=_st($1)._onClick_((function(){
 return smalltalk.withContext(function($ctx2) {
 return self._pressed();
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
-return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKCheckboxView)})},
+checkbox=$2;
+$3=self._checked();
+if(smalltalk.assert($3)){
+_st(checkbox)._at_put_("checked","checked");
+};
+return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html,checkbox:checkbox},smalltalk.MKCheckboxView)})},
 args: ["html"],
-source: "renderContentOn: html\x0a\x09html input\x0a\x09\x09type: 'checkbox';\x0a\x09\x09at: 'checked' put: self checked;\x0a\x09\x09value: self label;\x0a\x09\x09onClick: [ self pressed ]",
-messageSends: ["type:", "input", "at:put:", "checked", "value:", "label", "onClick:", "pressed"],
+source: "renderContentOn: html\x0a\x09| checkbox |\x0a\x09\x0a\x09checkbox := html input\x0a\x09\x09type: 'checkbox';\x0a\x09\x09value: self label;\x0a\x09\x09onClick: [ self pressed ].\x0a\x09\x09\x0a\x09self checked ifTrue: [ \x0a\x09\x09checkbox at: 'checked' put: 'checked' ]",
+messageSends: ["type:", "input", "value:", "label", "onClick:", "pressed", "ifTrue:", "checked", "at:put:"],
 referencedClasses: []
 }),
 smalltalk.MKCheckboxView);
@@ -307,6 +329,23 @@ smalltalk.MKCheckboxView);
 
 smalltalk.addClass('MKInputView', smalltalk.MKAspectView, ['input'], 'Moka-Views');
 smalltalk.MKInputView.comment="I am an input view. My default controller is `MKInputController`.\x0a\x0aMy controller must answer to `#onEnterPressed:`.";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultControllerClass",
+category: 'defaults',
+fn: function (){
+var self=this;
+function $MKInputController(){return smalltalk.MKInputController||(typeof MKInputController=="undefined"?nil:MKInputController)}
+return smalltalk.withContext(function($ctx1) { 
+return $MKInputController();
+}, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKInputView)})},
+args: [],
+source: "defaultControllerClass\x0a\x09^ MKInputController",
+messageSends: [],
+referencedClasses: ["MKInputController"]
+}),
+smalltalk.MKInputView);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "enterPressed",
@@ -332,14 +371,14 @@ var self=this;
 function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-$1=_st(_st(anEvent)._which()).__eq(_st(_st($String())._cr())._asciiValue());
+$1=_st(_st(anEvent)._keyCode()).__eq(_st(_st($String())._cr())._asciiValue());
 if(smalltalk.assert($1)){
 self._enterPressed();
 };
 return self}, function($ctx1) {$ctx1.fill(self,"keyDown:",{anEvent:anEvent},smalltalk.MKInputView)})},
 args: ["anEvent"],
-source: "keyDown: anEvent\x0a\x09anEvent which = String cr asciiValue ifTrue: [\x0a\x09\x09self enterPressed ]",
-messageSends: ["ifTrue:", "=", "which", "asciiValue", "cr", "enterPressed"],
+source: "keyDown: anEvent\x0a\x09anEvent keyCode = String cr asciiValue ifTrue: [\x0a\x09\x09self enterPressed ]",
+messageSends: ["ifTrue:", "=", "keyCode", "asciiValue", "cr", "enterPressed"],
 referencedClasses: ["String"]
 }),
 smalltalk.MKInputView);
@@ -387,4 +426,42 @@ referencedClasses: []
 smalltalk.MKInputView);
 
 
+
+smalltalk.addClass('MKLabelView', smalltalk.MKAspectView, ['input'], 'Moka-Views');
+smalltalk.MKLabelView.comment="I am an label view. I display a `String`.";
+smalltalk.addMethod(
+smalltalk.method({
+selector: "defaultControllerClass",
+category: 'defaults',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=smalltalk.MKLabelView.superclass.fn.prototype._defaultControllerClass.apply(_st(self), []);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"defaultControllerClass",{},smalltalk.MKLabelView)})},
+args: [],
+source: "defaultControllerClass\x0a\x09^ super defaultControllerClass",
+messageSends: ["defaultControllerClass"],
+referencedClasses: []
+}),
+smalltalk.MKLabelView);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "renderContentOn:",
+category: 'rendering',
+fn: function (html){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(html)._with_(self._aspectValue());
+return self}, function($ctx1) {$ctx1.fill(self,"renderContentOn:",{html:html},smalltalk.MKLabelView)})},
+args: ["html"],
+source: "renderContentOn: html\x0a\x09html with: self aspectValue",
+messageSends: ["with:", "aspectValue"],
+referencedClasses: []
+}),
+smalltalk.MKLabelView);
+
+
 });

+ 1 - 1
st/Moka-Controllers.st

@@ -32,6 +32,6 @@ I am the default controller for `MKInputView`.!
 !MKInputController methodsFor: 'actions'!
 
 onEnterPressed: aString
-	self performAtionWith: aString
+	self performActionWith: aString
 ! !
 

+ 11 - 4
st/Moka-Core.st

@@ -55,10 +55,11 @@ performAction
 !
 
 performActionWith: anObject
-	self aspect ifNotNil: [
-		self model 
-			perform: self aspect asMutator
-			withArguments: { anObject } ]
+	self aspect ifNil: [ ^ self ].
+	
+	self model 
+		perform: self aspect asMutator
+		withArguments: { anObject }
 ! !
 
 Object subclass: #MKModel
@@ -267,6 +268,12 @@ aspectValue
 	^ self model perform: self aspect
 ! !
 
+!MKAspectView methodsFor: 'defaults'!
+
+defaultControllerClass
+	^ MKAspectController
+! !
+
 !MKAspectView methodsFor: 'observing'!
 
 observeModel

+ 38 - 4
st/Moka-Views.st

@@ -86,6 +86,12 @@ checked
 	^ self aspectValue ifNil: [ false ]
 ! !
 
+!MKCheckboxView methodsFor: 'defaults'!
+
+defaultControllerClass
+	^ MKCheckboxController
+! !
+
 !MKCheckboxView methodsFor: 'events'!
 
 pressed
@@ -103,11 +109,15 @@ label: aString
 !
 
 renderContentOn: html
-	html input
+	| checkbox |
+	
+	checkbox := html input
 		type: 'checkbox';
-		at: 'checked' put: self checked;
 		value: self label;
-		onClick: [ self pressed ]
+		onClick: [ self pressed ].
+		
+	self checked ifTrue: [ 
+		checkbox at: 'checked' put: 'checked' ]
 ! !
 
 MKAspectView subclass: #MKInputView
@@ -124,6 +134,12 @@ value
 	^ input asJQuery val
 ! !
 
+!MKInputView methodsFor: 'defaults'!
+
+defaultControllerClass
+	^ MKInputController
+! !
+
 !MKInputView methodsFor: 'events'!
 
 enterPressed
@@ -131,7 +147,7 @@ enterPressed
 !
 
 keyDown: anEvent
-	anEvent which = String cr asciiValue ifTrue: [
+	anEvent keyCode = String cr asciiValue ifTrue: [
 		self enterPressed ]
 ! !
 
@@ -145,3 +161,21 @@ renderContentOn: html
 		yourself
 ! !
 
+MKAspectView subclass: #MKLabelView
+	instanceVariableNames: 'input'
+	package: 'Moka-Views'!
+!MKLabelView commentStamp!
+I am an label view. I display a `String`.!
+
+!MKLabelView methodsFor: 'defaults'!
+
+defaultControllerClass
+	^ super defaultControllerClass
+! !
+
+!MKLabelView methodsFor: 'rendering'!
+
+renderContentOn: html
+	html with: self aspectValue
+! !
+