|
@@ -1922,3 +1922,310 @@ referencedClasses: []
|
|
|
smalltalk.HLKeyBinderHelper.klass);
|
|
|
|
|
|
|
|
|
+smalltalk.addClass('HLRepeatingKeyBindingHandler', smalltalk.Object, ['repeatInterval', 'delay', 'interval', 'keyBindings', 'widget', 'isKeyCurrentlyPressed'], 'Helios-KeyBindings');
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler.comment="##Usage\x0a\x0a (HLRepeatingKeyBindingHandler forWidget: aWidget)\x0a whileKeyPressed: keyCode do: [xxxx];\x0a whileKeyPressed: anotherKey do: [yyy];\x0a rebind\x0a\x0aPerforms an action on a key press, waits for 300 ms and then preforms the action every repeatInterval ms until the button is released";
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "bindKeys",
|
|
|
+category: 'actions',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+_st(self["@widget"])._bindKeyDown_up_((function(e){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+return self._handleKeyDown_(e);
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}),(function(e){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+return self._handleKeyUp_(e);
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({e:e},$ctx1)})}));
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"bindKeys",{},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: [],
|
|
|
+source: "bindKeys\x0a\x09widget bindKeyDown: [ :e | self handleKeyDown: e ] up: [ :e | self handleKeyUp: e ]",
|
|
|
+messageSends: ["bindKeyDown:up:", "handleKeyDown:", "handleKeyUp:"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "delayBeforeStartingRepeatWithAction:",
|
|
|
+category: 'actions',
|
|
|
+fn: function (action){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1;
|
|
|
+$1=_st((function(){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+self["@interval"]=self._startRepeatingAction_(action);
|
|
|
+return self["@interval"];
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._valueWithTimeout_((300));
|
|
|
+return $1;
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"delayBeforeStartingRepeatWithAction:",{action:action},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: ["action"],
|
|
|
+source: "delayBeforeStartingRepeatWithAction: action\x0a\x09^ [ interval := self startRepeatingAction: action ] valueWithTimeout: 300",
|
|
|
+messageSends: ["valueWithTimeout:", "startRepeatingAction:"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "handleKeyDown:",
|
|
|
+category: 'events-processing',
|
|
|
+fn: function (e){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+_st(self["@keyBindings"])._keysAndValuesDo_((function(key,action){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+return self._ifKey_wasPressedIn_thenDo_(key,e,action);
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({key:key,action:action},$ctx1)})}));
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"handleKeyDown:",{e:e},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: ["e"],
|
|
|
+source: "handleKeyDown: e\x0a\x09 keyBindings keysAndValuesDo: [ :key :action | \x0a\x09\x09self ifKey: key wasPressedIn: e thenDo: action ]",
|
|
|
+messageSends: ["keysAndValuesDo:", "ifKey:wasPressedIn:thenDo:"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "handleKeyUp",
|
|
|
+category: 'actions',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1,$2;
|
|
|
+self["@isKeyCurrentlyPressed"]=false;
|
|
|
+$1=self["@interval"];
|
|
|
+if(($receiver = $1) == nil || $receiver == undefined){
|
|
|
+$1;
|
|
|
+} else {
|
|
|
+_st(self["@interval"])._clearInterval();
|
|
|
+};
|
|
|
+$2=self["@delay"];
|
|
|
+if(($receiver = $2) == nil || $receiver == undefined){
|
|
|
+$2;
|
|
|
+} else {
|
|
|
+_st(self["@delay"])._clearTimeout();
|
|
|
+};
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"handleKeyUp",{},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: [],
|
|
|
+source: "handleKeyUp\x0a\x09isKeyCurrentlyPressed := false.\x0a\x09interval ifNotNil: [ interval clearInterval ].\x0a\x09delay ifNotNil: [ delay clearTimeout ]",
|
|
|
+messageSends: ["ifNotNil:", "clearInterval", "clearTimeout"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "handleKeyUp:",
|
|
|
+category: 'events-processing',
|
|
|
+fn: function (e){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1;
|
|
|
+$1=self["@isKeyCurrentlyPressed"];
|
|
|
+if(smalltalk.assert($1)){
|
|
|
+self._handleKeyUp();
|
|
|
+};
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"handleKeyUp:",{e:e},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: ["e"],
|
|
|
+source: "handleKeyUp: e\x0a\x09isKeyCurrentlyPressed\x0a\x09\x09ifTrue: [ self handleKeyUp ] ",
|
|
|
+messageSends: ["ifTrue:", "handleKeyUp"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "ifKey:wasPressedIn:thenDo:",
|
|
|
+category: 'events-processing',
|
|
|
+fn: function (key,e,action){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1;
|
|
|
+$1=_st(_st(_st(e)._which()).__eq(key))._and_((function(){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+return _st(self["@isKeyCurrentlyPressed"]).__eq(false);
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
|
|
|
+if(smalltalk.assert($1)){
|
|
|
+self._whileTheKeyIsPressedDo_(action);
|
|
|
+};
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"ifKey:wasPressedIn:thenDo:",{key:key,e:e,action:action},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: ["key", "e", "action"],
|
|
|
+source: "ifKey: key wasPressedIn: e thenDo: action\x0a\x09(e which = key and: [ isKeyCurrentlyPressed = false ])\x0a\x09\x09ifTrue: [ self whileTheKeyIsPressedDo: action ]",
|
|
|
+messageSends: ["ifTrue:", "whileTheKeyIsPressedDo:", "and:", "=", "which"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "initialize",
|
|
|
+category: 'initialization',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+smalltalk.Object.fn.prototype._initialize.apply(_st(self), []);
|
|
|
+self["@keyBindings"]=_st($Dictionary())._new();
|
|
|
+self["@isKeyCurrentlyPressed"]=false;
|
|
|
+self["@repeatInterval"]=(70);
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: [],
|
|
|
+source: "initialize \x0a\x09super initialize.\x0a\x09keyBindings := Dictionary new.\x0a\x09isKeyCurrentlyPressed := false.\x0a\x09repeatInterval := 70.",
|
|
|
+messageSends: ["initialize", "new"],
|
|
|
+referencedClasses: ["Dictionary"]
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "rebindKeys",
|
|
|
+category: 'actions',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1,$2;
|
|
|
+$1=self;
|
|
|
+_st($1)._unbindKeys();
|
|
|
+$2=_st($1)._bindKeys();
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"rebindKeys",{},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: [],
|
|
|
+source: "rebindKeys\x0a\x09self unbindKeys;\x0a\x09\x09bindKeys",
|
|
|
+messageSends: ["unbindKeys", "bindKeys"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "repeatInterval:",
|
|
|
+category: 'accessing',
|
|
|
+fn: function (aMillisecondIntegerValue){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+self["@repeatInterval"]=aMillisecondIntegerValue;
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"repeatInterval:",{aMillisecondIntegerValue:aMillisecondIntegerValue},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: ["aMillisecondIntegerValue"],
|
|
|
+source: "repeatInterval: aMillisecondIntegerValue \x0a\x09repeatInterval := aMillisecondIntegerValue",
|
|
|
+messageSends: [],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "startRepeatingAction:",
|
|
|
+category: 'actions',
|
|
|
+fn: function (action){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $2,$1;
|
|
|
+$1=_st((function(){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+$2=_st(self["@widget"])._hasFocus();
|
|
|
+if(smalltalk.assert($2)){
|
|
|
+return _st(action)._value();
|
|
|
+} else {
|
|
|
+return self._handleKeyUp();
|
|
|
+};
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._valueWithInterval_(self["@repeatInterval"]);
|
|
|
+return $1;
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"startRepeatingAction:",{action:action},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: ["action"],
|
|
|
+source: "startRepeatingAction: action\x0a\x09^ [ (widget hasFocus)\x0a\x09\x09ifTrue: [ action value ]\x0a\x09\x09ifFalse: [ self handleKeyUp ] ] valueWithInterval: repeatInterval",
|
|
|
+messageSends: ["valueWithInterval:", "ifTrue:ifFalse:", "value", "handleKeyUp", "hasFocus"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "unbindKeys",
|
|
|
+category: 'actions',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+_st(self["@widget"])._unbindKeyDownUp();
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"unbindKeys",{},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: [],
|
|
|
+source: "unbindKeys\x0a\x09widget unbindKeyDownUp",
|
|
|
+messageSends: ["unbindKeyDownUp"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "whileKeyPressed:do:",
|
|
|
+category: 'accessing',
|
|
|
+fn: function (aKey,aBlock){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+_st(self["@keyBindings"])._at_put_(aKey,aBlock);
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"whileKeyPressed:do:",{aKey:aKey,aBlock:aBlock},smalltalk.HLRepeatingKeyBindingHandler)})},
|
|
|
+args: ["aKey", "aBlock"],
|
|
|
+source: "whileKeyPressed: aKey do: aBlock\x0a\x09keyBindings at: aKey put: aBlock",
|
|
|
+messageSends: ["at:put:"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "whileTheKeyIsPressedDo:",
|
|
|
+category: 'events-processing',
|
|
|
+fn: function (action){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+self["@isKeyCurrentlyPressed"]=true;
|
|
|
+_st(action)._value();
|
|
|
+self["@delay"]=self._delayBeforeStartingRepeatWithAction_(action);
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"whileTheKeyIsPressedDo:",{action:action},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: ["action"],
|
|
|
+source: "whileTheKeyIsPressedDo: action\x0a\x09isKeyCurrentlyPressed := true.\x0a\x09action value.\x0a\x09delay := self delayBeforeStartingRepeatWithAction: action",
|
|
|
+messageSends: ["value", "delayBeforeStartingRepeatWithAction:"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "widget:",
|
|
|
+category: 'accessing',
|
|
|
+fn: function (aWidget){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+self["@widget"]=aWidget;
|
|
|
+return self}, function($ctx1) {$ctx1.fill(self,"widget:",{aWidget:aWidget},smalltalk.HLRepeatingKeyBinderForWidget)})},
|
|
|
+args: ["aWidget"],
|
|
|
+source: "widget: aWidget\x0a\x09widget := aWidget",
|
|
|
+messageSends: [],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler);
|
|
|
+
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "forWidget:",
|
|
|
+category: 'instance-creation',
|
|
|
+fn: function (aWidget){
|
|
|
+var self=this;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $2,$3,$1;
|
|
|
+$2=self._new();
|
|
|
+_st($2)._widget_(aWidget);
|
|
|
+$3=_st($2)._yourself();
|
|
|
+$1=$3;
|
|
|
+return $1;
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"forWidget:",{aWidget:aWidget},smalltalk.HLRepeatingKeyBindingHandler.klass)})},
|
|
|
+args: ["aWidget"],
|
|
|
+source: "forWidget: aWidget\x0a\x09^self new\x0a\x09\x09widget: aWidget;\x0a\x09\x09yourself",
|
|
|
+messageSends: ["widget:", "new", "yourself"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HLRepeatingKeyBindingHandler.klass);
|
|
|
+
|
|
|
+
|