瀏覽代碼

Use ifEmpty:ifNotEmpty: family.

Herbert Vojčík 8 年之前
父節點
當前提交
26c5f01fb4
共有 2 個文件被更改,包括 45 次插入39 次删除
  1. 42 36
      src/Helios-Core.js
  2. 3 3
      src/Helios-Core.st

+ 42 - 36
src/Helios-Core.js

@@ -3297,7 +3297,7 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$receiver;
+var $1,$receiver;
 (
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true,
@@ -3306,15 +3306,20 @@ $ctx1.supercall = true,
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-$1=$recv(self._items())._isEmpty();
-if(!$core.assert($1)){
-$2=self._selectedItem();
-if(($receiver = $2) == null || $receiver.isNil){
-self._activateFirstListItem();
+$recv(self._items())._ifNotEmpty_((function(){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+$1=self._selectedItem();
+if(($receiver = $1) == null || $receiver.isNil){
+return self._activateFirstListItem();
 } else {
-$2;
-};
+return $1;
 };
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
+//>>excludeEnd("ctx");
+}));
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"focus",{},$globals.HLListWidget)});
@@ -3322,10 +3327,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "focus\x0a\x09super focus.\x0a    self items isEmpty ifFalse: [ \x0a\x09\x09self selectedItem ifNil: [ self activateFirstListItem ] ]",
+source: "focus\x0a\x09super focus.\x0a    self items ifNotEmpty: [ \x0a\x09\x09self selectedItem ifNil: [ self activateFirstListItem ] ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["focus", "ifFalse:", "isEmpty", "items", "ifNil:", "selectedItem", "activateFirstListItem"]
+messageSends: ["focus", "ifNotEmpty:", "items", "ifNil:", "selectedItem", "activateFirstListItem"]
 }),
 $globals.HLListWidget);
 
@@ -4517,34 +4522,33 @@ var commands;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$4,$5,$6,$8,$7,$3;
+var $1,$3,$4,$5,$7,$6,$2;
+var $early={};
+try {
 commands=self._menuCommands();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["menuCommands"]=1;
-//>>excludeEnd("ctx");
-$1=$recv(commands)._isEmpty();
-if($core.assert($1)){
-return self;
-};
-$2=$recv(html)._div();
-$recv($2)._class_("btn-group cog");
+$recv(commands)._ifEmpty_((function(){
+throw $early=[self];
+
+}));
+$1=$recv(html)._div();
+$recv($1)._class_("btn-group cog");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["class:"]=1;
 //>>excludeEnd("ctx");
-$3=$recv($2)._with_((function(){
+$2=$recv($1)._with_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$4=$recv(html)._a();
+$3=$recv(html)._a();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["a"]=1;
 //>>excludeEnd("ctx");
-$recv($4)._class_("btn btn-default dropdown-toggle");
+$recv($3)._class_("btn btn-default dropdown-toggle");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["class:"]=2;
 //>>excludeEnd("ctx");
-$recv($4)._at_put_("data-toggle","dropdown");
-$5=$recv($4)._with_((function(){
+$recv($3)._at_put_("data-toggle","dropdown");
+$4=$recv($3)._with_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
@@ -4559,14 +4563,14 @@ $ctx3.sendIdx["class:"]=3;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["with:"]=2;
 //>>excludeEnd("ctx");
-$5;
-$6=$recv(html)._ul();
-$recv($6)._class_("dropdown-menu pull-right");
-$7=$recv($6)._with_((function(){
+$4;
+$5=$recv(html)._ul();
+$recv($5)._class_("dropdown-menu pull-right");
+$6=$recv($5)._with_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
-return $recv(self._menuCommands())._do_((function(each){
+return $recv(commands)._do_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx4) {
 //>>excludeEnd("ctx");
@@ -4574,9 +4578,9 @@ return $recv($recv(html)._li())._with_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx5) {
 //>>excludeEnd("ctx");
-$8=$recv(html)._a();
-$recv($8)._with_($recv(each)._menuLabel());
-return $recv($8)._onClick_((function(){
+$7=$recv(html)._a();
+$recv($7)._with_($recv(each)._menuLabel());
+return $recv($7)._onClick_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx6) {
 //>>excludeEnd("ctx");
@@ -4603,7 +4607,7 @@ $ctx4.sendIdx["with:"]=4;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["with:"]=3;
 //>>excludeEnd("ctx");
-return $7;
+return $6;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)});
 //>>excludeEnd("ctx");
@@ -4612,16 +4616,18 @@ return $7;
 $ctx1.sendIdx["with:"]=1;
 //>>excludeEnd("ctx");
 return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"renderMenuOn:",{html:html,commands:commands},$globals.HLToolListWidget)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["html"],
-source: "renderMenuOn: html\x0a\x09| commands |\x0a\x09\x0a\x09commands := self menuCommands.\x0a\x09commands isEmpty ifTrue: [ ^ self ].\x0a\x09\x0a\x09html div \x0a\x09\x09class: 'btn-group cog';\x0a\x09\x09with: [\x0a\x09\x09\x09html a\x0a\x09\x09\x09\x09class: 'btn btn-default dropdown-toggle';\x0a\x09\x09\x09\x09at: 'data-toggle' put: 'dropdown';\x0a\x09\x09\x09\x09with: [ (html tag: 'i') class: 'glyphicon glyphicon-chevron-down' ].\x0a\x09\x09html ul \x0a\x09\x09\x09class: 'dropdown-menu pull-right';\x0a\x09\x09\x09with: [ \x0a\x09\x09\x09\x09self menuCommands do: [ :each | \x0a\x09\x09\x09\x09\x09html li with: [ html a \x0a\x09\x09\x09\x09\x09\x09with: each menuLabel;\x0a\x09\x09\x09\x09\x09\x09onClick: [ self execute: each ] ] ] ] ]",
+source: "renderMenuOn: html\x0a\x09| commands |\x0a\x09\x0a\x09commands := self menuCommands.\x0a\x09commands ifEmpty: [ ^ self ].\x0a\x09\x0a\x09html div \x0a\x09\x09class: 'btn-group cog';\x0a\x09\x09with: [\x0a\x09\x09\x09html a\x0a\x09\x09\x09\x09class: 'btn btn-default dropdown-toggle';\x0a\x09\x09\x09\x09at: 'data-toggle' put: 'dropdown';\x0a\x09\x09\x09\x09with: [ (html tag: 'i') class: 'glyphicon glyphicon-chevron-down' ].\x0a\x09\x09html ul \x0a\x09\x09\x09class: 'dropdown-menu pull-right';\x0a\x09\x09\x09with: [ \x0a\x09\x09\x09\x09commands do: [ :each | \x0a\x09\x09\x09\x09\x09html li with: [ html a \x0a\x09\x09\x09\x09\x09\x09with: each menuLabel;\x0a\x09\x09\x09\x09\x09\x09onClick: [ self execute: each ] ] ] ] ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["menuCommands", "ifTrue:", "isEmpty", "class:", "div", "with:", "a", "at:put:", "tag:", "ul", "do:", "li", "menuLabel", "onClick:", "execute:"]
+messageSends: ["menuCommands", "ifEmpty:", "class:", "div", "with:", "a", "at:put:", "tag:", "ul", "do:", "li", "menuLabel", "onClick:", "execute:"]
 }),
 $globals.HLToolListWidget);
 

+ 3 - 3
src/Helios-Core.st

@@ -847,7 +847,7 @@ ensureVisible: aListItem
 
 focus
 	super focus.
-    self items isEmpty ifFalse: [ 
+    self items ifNotEmpty: [ 
 		self selectedItem ifNil: [ self activateFirstListItem ] ]
 !
 
@@ -1068,7 +1068,7 @@ renderMenuOn: html
 	| commands |
 	
 	commands := self menuCommands.
-	commands isEmpty ifTrue: [ ^ self ].
+	commands ifEmpty: [ ^ self ].
 	
 	html div 
 		class: 'btn-group cog';
@@ -1080,7 +1080,7 @@ renderMenuOn: html
 		html ul 
 			class: 'dropdown-menu pull-right';
 			with: [ 
-				self menuCommands do: [ :each | 
+				commands do: [ :each | 
 					html li with: [ html a 
 						with: each menuLabel;
 						onClick: [ self execute: each ] ] ] ] ]