Browse Source

switch tabs with shift+tab

Nicolas Petton 10 years ago
parent
commit
736343b2e0
2 changed files with 66 additions and 15 deletions
  1. 48 12
      src/Helios-Core.js
  2. 18 3
      src/Helios-Core.st

+ 48 - 12
src/Helios-Core.js

@@ -3702,6 +3702,34 @@ referencedClasses: []
 }),
 globals.HLManager);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "activateNextTab",
+protocol: 'actions',
+fn: function (){
+var self=this;
+var nextTab;
+return smalltalk.withContext(function($ctx1) { 
+var $1,$4,$3,$2;
+$1=self._tabs();
+$ctx1.sendIdx["tabs"]=1;
+$4=self._tabs();
+$ctx1.sendIdx["tabs"]=2;
+$3=_st($4)._indexOf_(self._activeTab());
+$2=_st($3).__plus((1));
+nextTab=_st($1)._at_ifAbsent_($2,(function(){
+return smalltalk.withContext(function($ctx2) {
+return _st(self._tabs())._first();
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
+self._activate_(nextTab);
+return self}, function($ctx1) {$ctx1.fill(self,"activateNextTab",{nextTab:nextTab},globals.HLManager)})},
+args: [],
+source: "activateNextTab\x0a\x09| nextTab |\x0a\x09\x0a\x09nextTab := self tabs \x0a\x09\x09at: (self tabs indexOf: self activeTab) + 1 \x0a\x09\x09ifAbsent: [ self tabs first ].\x0a\x09\x09\x0a\x09self activate: nextTab",
+messageSends: ["at:ifAbsent:", "tabs", "+", "indexOf:", "activeTab", "first", "activate:"],
+referencedClasses: []
+}),
+globals.HLManager);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "activeTab",
@@ -4399,34 +4427,42 @@ protocol: 'private',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2,$3,$4,$5;
+var $1,$2,$3,$4,$5,$6;
 $1="body"._asJQuery();
 $ctx1.sendIdx["asJQuery"]=1;
 _st($1)._keydown_((function(event){
 return smalltalk.withContext(function($ctx2) {
-$2=_st(event)._ctrlKey();
+$2=_st(_st(_st(event)._which()).__eq((9)))._and_((function(){
+return smalltalk.withContext(function($ctx3) {
+return _st(event)._shiftKey();
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
 if(smalltalk.assert($2)){
-$3="body"._asJQuery();
+self._activateNextTab();
+_st(event)._preventDefault();
+};
+$3=_st(event)._ctrlKey();
+if(smalltalk.assert($3)){
+$4="body"._asJQuery();
 $ctx2.sendIdx["asJQuery"]=2;
-return _st($3)._addClass_("navigation");
+return _st($4)._addClass_("navigation");
 };
 }, function($ctx2) {$ctx2.fillBlock({event:event},$ctx1,1)})}));
-$4="body"._asJQuery();
+$5="body"._asJQuery();
 $ctx1.sendIdx["asJQuery"]=3;
-_st($4)._keyup_((function(event){
+_st($5)._keyup_((function(event){
 return smalltalk.withContext(function($ctx2) {
-$5="body"._asJQuery();
+$6="body"._asJQuery();
 $ctx2.sendIdx["asJQuery"]=4;
-return _st($5)._removeClass_("navigation");
-}, function($ctx2) {$ctx2.fillBlock({event:event},$ctx1,3)})}));
+return _st($6)._removeClass_("navigation");
+}, function($ctx2) {$ctx2.fillBlock({event:event},$ctx1,5)})}));
 _st(_st(window)._asJQuery())._resize_((function(event){
 return smalltalk.withContext(function($ctx2) {
 return self._refresh();
-}, function($ctx2) {$ctx2.fillBlock({event:event},$ctx1,4)})}));
+}, function($ctx2) {$ctx2.fillBlock({event:event},$ctx1,6)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"setupEvents",{},globals.HLManager)})},
 args: [],
-source: "setupEvents\x0a\x09\x22on ctrl keydown, adds a 'navigation' css class to <body>\x0a\x09for the CodeMirror navigation links. See `HLCodeWidget`.\x22\x0a\x09\x0a\x09'body' asJQuery keydown: [ :event |\x0a\x09\x09event ctrlKey ifTrue: [\x0a\x09\x09\x09'body' asJQuery addClass: 'navigation' ] ].\x0a\x09\x09\x09\x0a\x09'body' asJQuery keyup: [ :event |\x0a\x09\x09'body' asJQuery removeClass: 'navigation' ].\x0a\x09\x09\x0a\x09window asJQuery resize: [ :event |\x0a\x09\x09self refresh ]",
-messageSends: ["keydown:", "asJQuery", "ifTrue:", "ctrlKey", "addClass:", "keyup:", "removeClass:", "resize:", "refresh"],
+source: "setupEvents\x0a\x09'body' asJQuery keydown: [ :event |\x0a\x09\x0a\x09\x09\x22shift+tab\x22\x0a\x09\x09(event which = 9 and: [ event shiftKey ]) ifTrue: [\x0a\x09\x09\x09self activateNextTab.\x0a\x09\x09\x09event preventDefault ].\x0a\x09\x09\x09\x0a\x09\x09\x22On ctrl keydown, adds a 'navigation' css class to <body>\x0a\x09\x09for the CodeMirror navigation links. See `HLCodeWidget`.\x22\x0a\x09\x09event ctrlKey ifTrue: [\x0a\x09\x09\x09'body' asJQuery addClass: 'navigation' ] ].\x0a\x09\x09\x09\x0a\x09'body' asJQuery keyup: [ :event |\x0a\x09\x09'body' asJQuery removeClass: 'navigation' ].\x0a\x09\x09\x0a\x09window asJQuery resize: [ :event |\x0a\x09\x09self refresh ]",
+messageSends: ["keydown:", "asJQuery", "ifTrue:", "and:", "=", "which", "shiftKey", "activateNextTab", "preventDefault", "ctrlKey", "addClass:", "keyup:", "removeClass:", "resize:", "refresh"],
 referencedClasses: []
 }),
 globals.HLManager);

+ 18 - 3
src/Helios-Core.st

@@ -1311,6 +1311,16 @@ activate: aTab
 		show: aTab
 !
 
+activateNextTab
+	| nextTab |
+	
+	nextTab := self tabs 
+		at: (self tabs indexOf: self activeTab) + 1 
+		ifAbsent: [ self tabs first ].
+		
+	self activate: nextTab
+!
+
 addTab: aTab
 	self tabs add: aTab.
     self activate: aTab
@@ -1423,10 +1433,15 @@ registerServices
 !
 
 setupEvents
-	"on ctrl keydown, adds a 'navigation' css class to <body>
-	for the CodeMirror navigation links. See `HLCodeWidget`."
-	
 	'body' asJQuery keydown: [ :event |
+	
+		"shift+tab"
+		(event which = 9 and: [ event shiftKey ]) ifTrue: [
+			self activateNextTab.
+			event preventDefault ].
+			
+		"On ctrl keydown, adds a 'navigation' css class to <body>
+		for the CodeMirror navigation links. See `HLCodeWidget`."
 		event ctrlKey ifTrue: [
 			'body' asJQuery addClass: 'navigation' ] ].