Browse Source

- fix some events for input controllers
- new hierarchy for input views

Nicolas Petton 10 years ago
parent
commit
8b437534e8
8 changed files with 116 additions and 28 deletions
  1. 14 6
      js/Moka-Controllers.js
  2. 19 3
      js/Moka-Core.js
  3. 21 14
      js/Moka-Examples.js
  4. 34 0
      js/Moka-Views.js
  5. 9 3
      st/Moka-Controllers.st
  6. 6 2
      st/Moka-Core.st
  7. 3 0
      st/Moka-Examples.st
  8. 10 0
      st/Moka-Views.st

+ 14 - 6
js/Moka-Controllers.js

@@ -2,11 +2,11 @@ define("amber_core/Moka-Controllers", ["amber_vm/smalltalk", "amber_vm/nil", "am
 smalltalk.addPackage('Moka-Controllers');
 smalltalk.packages["Moka-Controllers"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
-smalltalk.addClass('MKAnyKeyInputController', smalltalk.MKAspectController, [], 'Moka-Controllers');
+smalltalk.addClass('MKAnyKeyInputController', smalltalk.MKAspectController, ['lastValue'], 'Moka-Controllers');
 smalltalk.addMethod(
 smalltalk.method({
 selector: "inputText",
-category: 'accessing]',
+category: 'accessing',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
@@ -27,12 +27,20 @@ selector: "onKeyPressed:",
 category: 'actions',
 fn: function (anEvent){
 var self=this;
+var newValue;
 return smalltalk.withContext(function($ctx1) { 
-self._performActionWith_(self._inputText());
-return self}, function($ctx1) {$ctx1.fill(self,"onKeyPressed:",{anEvent:anEvent},smalltalk.MKAnyKeyInputController)})},
+var $1;
+newValue=self._inputText();
+$1=_st(newValue).__eq(self["@lastValue"]);
+if(smalltalk.assert($1)){
+return self;
+};
+self["@lastValue"]=newValue;
+self._performActionWith_(newValue);
+return self}, function($ctx1) {$ctx1.fill(self,"onKeyPressed:",{anEvent:anEvent,newValue:newValue},smalltalk.MKAnyKeyInputController)})},
 args: ["anEvent"],
-source: "onKeyPressed: anEvent\x0a\x09self performActionWith: self inputText",
-messageSends: ["performActionWith:", "inputText"],
+source: "onKeyPressed: anEvent\x0a\x09| newValue |\x0a\x09\x0a\x09newValue := self inputText.\x0a\x09newValue = lastValue ifTrue: [ ^ self ].\x0a\x09\x0a\x09lastValue := newValue.\x0a\x09self performActionWith: newValue",
+messageSends: ["inputText", "ifTrue:", "=", "performActionWith:"],
 referencedClasses: []
 }),
 smalltalk.MKAnyKeyInputController);

+ 19 - 3
js/Moka-Core.js

@@ -598,11 +598,10 @@ fn: function (aSelector){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 self["@aspect"]=aSelector;
-_st(self._controller())._aspect_(aSelector);
 return self}, function($ctx1) {$ctx1.fill(self,"aspect:",{aSelector:aSelector},smalltalk.MKAspectView)})},
 args: ["aSelector"],
-source: "aspect: aSelector\x0a\x09aspect := aSelector.\x0a\x09self controller aspect: aSelector",
-messageSends: ["aspect:", "controller"],
+source: "aspect: aSelector\x0a\x09aspect := aSelector",
+messageSends: [],
 referencedClasses: []
 }),
 smalltalk.MKAspectView);
@@ -625,6 +624,23 @@ referencedClasses: []
 }),
 smalltalk.MKAspectView);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "controller:",
+category: 'accessing',
+fn: function (aController){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+smalltalk.MKAspectView.superclass.fn.prototype._controller_.apply(_st(self), [aController]);
+_st(aController)._aspect_(self._aspect());
+return self}, function($ctx1) {$ctx1.fill(self,"controller:",{aController:aController},smalltalk.MKAspectView)})},
+args: ["aController"],
+source: "controller: aController\x0a\x09super controller: aController.\x0a\x09aController aspect: self aspect",
+messageSends: ["controller:", "aspect:", "aspect"],
+referencedClasses: []
+}),
+smalltalk.MKAspectView);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "defaultControllerClass",

+ 21 - 14
js/Moka-Examples.js

@@ -16,7 +16,7 @@ function $MKTextAreaView(){return smalltalk.MKTextAreaView||(typeof MKTextAreaVi
 function $MKCheckboxView(){return smalltalk.MKCheckboxView||(typeof MKCheckboxView=="undefined"?nil:MKCheckboxView)}
 function $MKSwitchView(){return smalltalk.MKSwitchView||(typeof MKSwitchView=="undefined"?nil:MKSwitchView)}
 return smalltalk.withContext(function($ctx1) { 
-var $2,$1,$4,$3,$5,$7,$6,$9,$8,$11,$10,$13,$12,$14,$15;
+var $2,$1,$4,$3,$5,$7,$6,$9,$8,$10,$12,$11,$14,$13,$16,$15,$17,$18;
 $2=self._counter();
 $ctx1.sendIdx["counter"]=1;
 $1=_st($MKLabelView())._model_aspect_($2,"count");
@@ -39,29 +39,36 @@ _st($6)._render();
 $ctx1.sendIdx["render"]=3;
 $9=self._counter();
 $ctx1.sendIdx["counter"]=4;
-$8=_st($MKTextAreaView())._model_aspect_($9,"text");
+$8=_st($MKInputView())._model_aspect_($9,"text");
 $ctx1.sendIdx["model:aspect:"]=4;
-_st($8)._render();
+_st($8)._triggerChangeOnAnyKey();
+$10=_st($8)._render();
 $ctx1.sendIdx["render"]=4;
-$11=self._counter();
+$12=self._counter();
 $ctx1.sendIdx["counter"]=5;
-$10=_st($MKCheckboxView())._model_aspect_($11,"checked");
+$11=_st($MKTextAreaView())._model_aspect_($12,"text");
 $ctx1.sendIdx["model:aspect:"]=5;
-_st($10)._render();
+_st($11)._render();
 $ctx1.sendIdx["render"]=5;
-$13=self._counter();
+$14=self._counter();
 $ctx1.sendIdx["counter"]=6;
-$12=_st($MKSwitchView())._model_aspect_($13,"checked");
+$13=_st($MKCheckboxView())._model_aspect_($14,"checked");
 $ctx1.sendIdx["model:aspect:"]=6;
-_st($12)._render();
+_st($13)._render();
 $ctx1.sendIdx["render"]=6;
-$14=_st($MKButtonView())._model_aspect_(self._counter(),"decrease");
-_st($14)._label_("Decrease");
-$15=_st($14)._render();
+$16=self._counter();
+$ctx1.sendIdx["counter"]=7;
+$15=_st($MKSwitchView())._model_aspect_($16,"checked");
+$ctx1.sendIdx["model:aspect:"]=7;
+_st($15)._render();
+$ctx1.sendIdx["render"]=7;
+$17=_st($MKButtonView())._model_aspect_(self._counter(),"decrease");
+_st($17)._label_("Decrease");
+$18=_st($17)._render();
 return self}, function($ctx1) {$ctx1.fill(self,"build",{},smalltalk.MKCounterBuilder)})},
 args: [],
-source: "build\x0a\x09(MKLabelView model: self counter aspect: #count) render.\x0a\x09(MKButtonView model: self counter aspect: #increase) \x0a\x09\x09label: 'Increase';\x0a\x09\x09render.\x0a\x09(MKInputView model: self counter aspect: #text)\x0a\x09\x09render.\x0a\x09(MKTextAreaView model: self counter aspect: #text)\x0a\x09\x09render.\x0a\x09(MKCheckboxView model: self counter aspect: #checked)\x0a\x09\x09render.\x0a\x09(MKSwitchView model: self counter aspect: #checked)\x0a\x09\x09render.\x0a\x09(MKButtonView model: self counter aspect: #decrease) \x0a\x09\x09label: 'Decrease';\x0a\x09\x09render",
-messageSends: ["render", "model:aspect:", "counter", "label:"],
+source: "build\x0a\x09(MKLabelView model: self counter aspect: #count) render.\x0a\x09(MKButtonView model: self counter aspect: #increase) \x0a\x09\x09label: 'Increase';\x0a\x09\x09render.\x0a\x09(MKInputView model: self counter aspect: #text)\x0a\x09\x09render.\x0a\x09(MKInputView model: self counter aspect: #text)\x0a\x09\x09triggerChangeOnAnyKey;\x0a\x09\x09render.\x0a\x09(MKTextAreaView model: self counter aspect: #text)\x0a\x09\x09render.\x0a\x09(MKCheckboxView model: self counter aspect: #checked)\x0a\x09\x09render.\x0a\x09(MKSwitchView model: self counter aspect: #checked)\x0a\x09\x09render.\x0a\x09(MKButtonView model: self counter aspect: #decrease) \x0a\x09\x09label: 'Decrease';\x0a\x09\x09render",
+messageSends: ["render", "model:aspect:", "counter", "label:", "triggerChangeOnAnyKey"],
 referencedClasses: ["MKLabelView", "MKButtonView", "MKInputView", "MKTextAreaView", "MKCheckboxView", "MKSwitchView"]
 }),
 smalltalk.MKCounterBuilder);

+ 34 - 0
js/Moka-Views.js

@@ -563,5 +563,39 @@ referencedClasses: []
 }),
 smalltalk.MKInputView);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "triggerChangeOnAnyKey",
+category: 'settings',
+fn: function (){
+var self=this;
+function $MKAnyKeyInputController(){return smalltalk.MKAnyKeyInputController||(typeof MKAnyKeyInputController=="undefined"?nil:MKAnyKeyInputController)}
+return smalltalk.withContext(function($ctx1) { 
+self._controller_(_st($MKAnyKeyInputController())._new());
+return self}, function($ctx1) {$ctx1.fill(self,"triggerChangeOnAnyKey",{},smalltalk.MKInputView)})},
+args: [],
+source: "triggerChangeOnAnyKey\x0a\x09self controller: MKAnyKeyInputController new",
+messageSends: ["controller:", "new"],
+referencedClasses: ["MKAnyKeyInputController"]
+}),
+smalltalk.MKInputView);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "triggerChangeOnEnter",
+category: 'settings',
+fn: function (){
+var self=this;
+function $MKEnterInputController(){return smalltalk.MKEnterInputController||(typeof MKEnterInputController=="undefined"?nil:MKEnterInputController)}
+return smalltalk.withContext(function($ctx1) { 
+self._controller_(_st($MKEnterInputController())._new());
+return self}, function($ctx1) {$ctx1.fill(self,"triggerChangeOnEnter",{},smalltalk.MKInputView)})},
+args: [],
+source: "triggerChangeOnEnter\x0a\x09self controller: MKEnterInputController new",
+messageSends: ["controller:", "new"],
+referencedClasses: ["MKEnterInputController"]
+}),
+smalltalk.MKInputView);
+
 
 });

+ 9 - 3
st/Moka-Controllers.st

@@ -1,9 +1,9 @@
 Smalltalk current createPackage: 'Moka-Controllers'!
 MKAspectController subclass: #MKAnyKeyInputController
-	instanceVariableNames: ''
+	instanceVariableNames: 'lastValue'
 	package: 'Moka-Controllers'!
 
-!MKAnyKeyInputController methodsFor: 'accessing]'!
+!MKAnyKeyInputController methodsFor: 'accessing'!
 
 inputText
 	^ self view value
@@ -12,7 +12,13 @@ inputText
 !MKAnyKeyInputController methodsFor: 'actions'!
 
 onKeyPressed: anEvent
-	self performActionWith: self inputText
+	| newValue |
+	
+	newValue := self inputText.
+	newValue = lastValue ifTrue: [ ^ self ].
+	
+	lastValue := newValue.
+	self performActionWith: newValue
 ! !
 
 MKAnyKeyInputController subclass: #MKEnterInputController

+ 6 - 2
st/Moka-Core.st

@@ -260,12 +260,16 @@ aspect
 !
 
 aspect: aSelector
-	aspect := aSelector.
-	self controller aspect: aSelector
+	aspect := aSelector
 !
 
 aspectValue
 	^ self model perform: self aspect
+!
+
+controller: aController
+	super controller: aController.
+	aController aspect: self aspect
 ! !
 
 !MKAspectView methodsFor: 'defaults'!

+ 3 - 0
st/Moka-Examples.st

@@ -12,6 +12,9 @@ build
 		render.
 	(MKInputView model: self counter aspect: #text)
 		render.
+	(MKInputView model: self counter aspect: #text)
+		triggerChangeOnAnyKey;
+		render.
 	(MKTextAreaView model: self counter aspect: #text)
 		render.
 	(MKCheckboxView model: self counter aspect: #checked)

+ 10 - 0
st/Moka-Views.st

@@ -229,3 +229,13 @@ renderContentOn: html
 		yourself
 ! !
 
+!MKInputView methodsFor: 'settings'!
+
+triggerChangeOnAnyKey
+	self controller: MKAnyKeyInputController new
+!
+
+triggerChangeOnEnter
+	self controller: MKEnterInputController new
+! !
+