Browse Source

- fixed HLProgressBar collection iteration
- fixed HLToolModel error handling for remote environments

Nicolas Petton 11 years ago
parent
commit
ed42e9ef01
3 changed files with 169 additions and 61 deletions
  1. 17 13
      js/Helios-Core.deploy.js
  2. 22 18
      js/Helios-Core.js
  3. 130 30
      st/Helios-Core.st

+ 17 - 13
js/Helios-Core.deploy.js

@@ -790,28 +790,28 @@ smalltalk.method({
 selector: "withCompileErrorHandling:",
 fn: function (aBlock){
 var self=this;
-function $CompilerError(){return smalltalk.CompilerError||(typeof CompilerError=="undefined"?nil:CompilerError)}
-function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
 function $ParseError(){return smalltalk.ParseError||(typeof ParseError=="undefined"?nil:ParseError)}
+function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
+function $CompilerError(){return smalltalk.CompilerError||(typeof CompilerError=="undefined"?nil:CompilerError)}
 return smalltalk.withContext(function($ctx1) { 
-_st((function(){
+_st(_st(self)._environment())._evaluate_on_do_((function(){
 return smalltalk.withContext(function($ctx2) {
-return _st((function(){
+return _st(_st(self)._environment())._evaluate_on_do_((function(){
 return smalltalk.withContext(function($ctx3) {
-return _st(aBlock)._on_do_($ParseError(),(function(ex){
+return _st(_st(self)._environment())._evaluate_on_do_(aBlock,$ParseError(),(function(ex){
 return smalltalk.withContext(function($ctx4) {
 return _st(self)._handleParseError_(ex);
-}, function($ctx4) {$ctx4.fillBlock({ex:ex},$ctx1)})}));
-}, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}))._on_do_($UnknownVariableError(),(function(ex){
+}, function($ctx4) {$ctx4.fillBlock({ex:ex},$ctx3)})}));
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}),$UnknownVariableError(),(function(ex){
 return smalltalk.withContext(function($ctx3) {
 return _st(self)._handleUnkownVariableError_(ex);
-}, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx1)})}));
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._on_do_($CompilerError(),(function(ex){
+}, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx2)})}));
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$CompilerError(),(function(ex){
 return smalltalk.withContext(function($ctx2) {
 return _st(self)._handleCompileError_(ex);
 }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"withCompileErrorHandling:",{aBlock:aBlock},smalltalk.HLToolModel)})},
-messageSends: ["on:do:", "handleCompileError:", "handleUnkownVariableError:", "handleParseError:"]}),
+messageSends: ["evaluate:on:do:", "handleParseError:", "environment", "handleUnkownVariableError:", "handleCompileError:"]}),
 smalltalk.HLToolModel);
 
 smalltalk.addMethod(
@@ -2579,17 +2579,21 @@ smalltalk.method({
 selector: "initialize",
 fn: function (){
 var self=this;
+function $HLErrorHandler(){return smalltalk.HLErrorHandler||(typeof HLErrorHandler=="undefined"?nil:HLErrorHandler)}
+function $HLProgressHandler(){return smalltalk.HLProgressHandler||(typeof HLProgressHandler=="undefined"?nil:HLProgressHandler)}
 function $HLInspector(){return smalltalk.HLInspector||(typeof HLInspector=="undefined"?nil:HLInspector)}
 function $ErrorHandler(){return smalltalk.ErrorHandler||(typeof ErrorHandler=="undefined"?nil:ErrorHandler)}
 function $ProgressHandler(){return smalltalk.ProgressHandler||(typeof ProgressHandler=="undefined"?nil:ProgressHandler)}
 return smalltalk.withContext(function($ctx1) { 
 smalltalk.HLWidget.fn.prototype._initialize.apply(_st(self), []);
+_st($HLErrorHandler())._register();
+_st($HLProgressHandler())._register();
 _st(self)._registerInspector_($HLInspector());
 _st(self)._registerErrorHandler_(_st($ErrorHandler())._current());
 _st(self)._registerProgressHandler_(_st($ProgressHandler())._current());
 _st(_st(self)._keyBinder())._setupEvents();
 return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLManager)})},
-messageSends: ["initialize", "registerInspector:", "registerErrorHandler:", "current", "registerProgressHandler:", "setupEvents", "keyBinder"]}),
+messageSends: ["initialize", "register", "registerInspector:", "registerErrorHandler:", "current", "registerProgressHandler:", "setupEvents", "keyBinder"]}),
 smalltalk.HLManager);
 
 smalltalk.addMethod(
@@ -3498,7 +3502,7 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
 _st(self)._updateProgress_(_st(_st(anInteger).__slash(_st(_st(self)._collection())._size())).__star((100)));
-$1=_st(_st(_st(self)._collection())._size()).__gt(anInteger);
+$1=_st(anInteger).__lt_eq(_st(_st(self)._collection())._size());
 if(smalltalk.assert($1)){
 _st((function(){
 return smalltalk.withContext(function($ctx2) {
@@ -3512,7 +3516,7 @@ return _st(self)._remove();
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._valueWithTimeout_((500));
 };
 return self}, function($ctx1) {$ctx1.fill(self,"evaluateAt:",{anInteger:anInteger},smalltalk.HLProgressBar)})},
-messageSends: ["updateProgress:", "*", "/", "size", "collection", "ifTrue:ifFalse:", "valueWithTimeout:", "value:", "at:", "workBlock", "evaluateAt:", "+", "remove", ">"]}),
+messageSends: ["updateProgress:", "*", "/", "size", "collection", "ifTrue:ifFalse:", "valueWithTimeout:", "value:", "at:", "workBlock", "evaluateAt:", "+", "remove", "<="]}),
 smalltalk.HLProgressBar);
 
 smalltalk.addMethod(

+ 22 - 18
js/Helios-Core.js

@@ -1033,31 +1033,31 @@ selector: "withCompileErrorHandling:",
 category: 'error handling',
 fn: function (aBlock){
 var self=this;
-function $CompilerError(){return smalltalk.CompilerError||(typeof CompilerError=="undefined"?nil:CompilerError)}
-function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
 function $ParseError(){return smalltalk.ParseError||(typeof ParseError=="undefined"?nil:ParseError)}
+function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
+function $CompilerError(){return smalltalk.CompilerError||(typeof CompilerError=="undefined"?nil:CompilerError)}
 return smalltalk.withContext(function($ctx1) { 
-_st((function(){
+_st(_st(self)._environment())._evaluate_on_do_((function(){
 return smalltalk.withContext(function($ctx2) {
-return _st((function(){
+return _st(_st(self)._environment())._evaluate_on_do_((function(){
 return smalltalk.withContext(function($ctx3) {
-return _st(aBlock)._on_do_($ParseError(),(function(ex){
+return _st(_st(self)._environment())._evaluate_on_do_(aBlock,$ParseError(),(function(ex){
 return smalltalk.withContext(function($ctx4) {
 return _st(self)._handleParseError_(ex);
-}, function($ctx4) {$ctx4.fillBlock({ex:ex},$ctx1)})}));
-}, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}))._on_do_($UnknownVariableError(),(function(ex){
+}, function($ctx4) {$ctx4.fillBlock({ex:ex},$ctx3)})}));
+}, function($ctx3) {$ctx3.fillBlock({},$ctx2)})}),$UnknownVariableError(),(function(ex){
 return smalltalk.withContext(function($ctx3) {
 return _st(self)._handleUnkownVariableError_(ex);
-}, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx1)})}));
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._on_do_($CompilerError(),(function(ex){
+}, function($ctx3) {$ctx3.fillBlock({ex:ex},$ctx2)})}));
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$CompilerError(),(function(ex){
 return smalltalk.withContext(function($ctx2) {
 return _st(self)._handleCompileError_(ex);
 }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"withCompileErrorHandling:",{aBlock:aBlock},smalltalk.HLToolModel)})},
 args: ["aBlock"],
-source: "withCompileErrorHandling: aBlock\x0a\x09[\x0a\x09\x09[\x0a\x09\x09\x09aBlock \x0a\x09\x09\x09\x09on: ParseError\x0a\x09\x09\x09\x09do: [:ex | self handleParseError: ex ]\x0a\x09\x09]\x0a\x09\x09\x09on: UnknownVariableError\x0a\x09\x09\x09do: [ :ex | self handleUnkownVariableError: ex ]\x0a\x09]\x0a\x09\x09on: CompilerError\x0a\x09\x09do: [ :ex | self handleCompileError: ex ]",
-messageSends: ["on:do:", "handleCompileError:", "handleUnkownVariableError:", "handleParseError:"],
-referencedClasses: ["CompilerError", "UnknownVariableError", "ParseError"]
+source: "withCompileErrorHandling: aBlock\x0a\x09self environment\x0a\x09\x09evaluate: [\x0a\x09\x09\x09self environment \x0a\x09\x09\x09evaluate: [\x0a\x09\x09\x09\x09self environment \x0a\x09\x09\x09\x09\x09evaluate: aBlock\x0a\x09\x09\x09\x09\x09on: ParseError\x0a\x09\x09\x09\x09\x09do: [:ex | self handleParseError: ex ] ]\x0a\x09\x09\x09on: UnknownVariableError\x0a\x09\x09\x09do: [ :ex | self handleUnkownVariableError: ex ] ]\x0a\x09\x09on: CompilerError\x0a\x09\x09do: [ :ex | self handleCompileError: ex ]",
+messageSends: ["evaluate:on:do:", "handleParseError:", "environment", "handleUnkownVariableError:", "handleCompileError:"],
+referencedClasses: ["ParseError", "UnknownVariableError", "CompilerError"]
 }),
 smalltalk.HLToolModel);
 
@@ -3371,20 +3371,24 @@ selector: "initialize",
 category: 'initialization',
 fn: function (){
 var self=this;
+function $HLErrorHandler(){return smalltalk.HLErrorHandler||(typeof HLErrorHandler=="undefined"?nil:HLErrorHandler)}
+function $HLProgressHandler(){return smalltalk.HLProgressHandler||(typeof HLProgressHandler=="undefined"?nil:HLProgressHandler)}
 function $HLInspector(){return smalltalk.HLInspector||(typeof HLInspector=="undefined"?nil:HLInspector)}
 function $ErrorHandler(){return smalltalk.ErrorHandler||(typeof ErrorHandler=="undefined"?nil:ErrorHandler)}
 function $ProgressHandler(){return smalltalk.ProgressHandler||(typeof ProgressHandler=="undefined"?nil:ProgressHandler)}
 return smalltalk.withContext(function($ctx1) { 
 smalltalk.HLWidget.fn.prototype._initialize.apply(_st(self), []);
+_st($HLErrorHandler())._register();
+_st($HLProgressHandler())._register();
 _st(self)._registerInspector_($HLInspector());
 _st(self)._registerErrorHandler_(_st($ErrorHandler())._current());
 _st(self)._registerProgressHandler_(_st($ProgressHandler())._current());
 _st(_st(self)._keyBinder())._setupEvents();
 return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLManager)})},
 args: [],
-source: "initialize\x0a\x09super initialize.\x0a\x09self registerInspector: HLInspector.\x0a\x09self registerErrorHandler: ErrorHandler current.\x0a\x09self registerProgressHandler: ProgressHandler current.\x0a    self keyBinder setupEvents",
-messageSends: ["initialize", "registerInspector:", "registerErrorHandler:", "current", "registerProgressHandler:", "setupEvents", "keyBinder"],
-referencedClasses: ["HLInspector", "ErrorHandler", "ProgressHandler"]
+source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09HLErrorHandler register.\x0a\x09HLProgressHandler register.\x0a\x09\x0a\x09self registerInspector: HLInspector.\x0a\x09self registerErrorHandler: ErrorHandler current.\x0a\x09self registerProgressHandler: ProgressHandler current.\x0a    self keyBinder setupEvents",
+messageSends: ["initialize", "register", "registerInspector:", "registerErrorHandler:", "current", "registerProgressHandler:", "setupEvents", "keyBinder"],
+referencedClasses: ["HLErrorHandler", "HLProgressHandler", "HLInspector", "ErrorHandler", "ProgressHandler"]
 }),
 smalltalk.HLManager);
 
@@ -4565,7 +4569,7 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
 _st(self)._updateProgress_(_st(_st(anInteger).__slash(_st(_st(self)._collection())._size())).__star((100)));
-$1=_st(_st(_st(self)._collection())._size()).__gt(anInteger);
+$1=_st(anInteger).__lt_eq(_st(_st(self)._collection())._size());
 if(smalltalk.assert($1)){
 _st((function(){
 return smalltalk.withContext(function($ctx2) {
@@ -4580,8 +4584,8 @@ return _st(self)._remove();
 };
 return self}, function($ctx1) {$ctx1.fill(self,"evaluateAt:",{anInteger:anInteger},smalltalk.HLProgressBar)})},
 args: ["anInteger"],
-source: "evaluateAt: anInteger\x0a\x09self updateProgress: (anInteger / self collection size) * 100.\x0a\x09self collection size > anInteger \x0a\x09\x09ifTrue: [ \x0a\x09\x09\x09[ \x0a\x09\x09\x09\x09self workBlock value: (self collection at: anInteger).\x0a\x09\x09\x09\x09self evaluateAt: anInteger + 1 ] valueWithTimeout: 10 ]\x0a\x09\x09ifFalse: [ [ self remove ] valueWithTimeout: 500 ]",
-messageSends: ["updateProgress:", "*", "/", "size", "collection", "ifTrue:ifFalse:", "valueWithTimeout:", "value:", "at:", "workBlock", "evaluateAt:", "+", "remove", ">"],
+source: "evaluateAt: anInteger\x0a\x09self updateProgress: (anInteger / self collection size) * 100.\x0a\x09anInteger <= self collection size\x0a\x09\x09ifTrue: [ \x0a\x09\x09\x09[ \x0a\x09\x09\x09\x09self workBlock value: (self collection at: anInteger).\x0a\x09\x09\x09\x09self evaluateAt: anInteger + 1 ] valueWithTimeout: 10 ]\x0a\x09\x09ifFalse: [ [ self remove ] valueWithTimeout: 500 ]",
+messageSends: ["updateProgress:", "*", "/", "size", "collection", "ifTrue:ifFalse:", "valueWithTimeout:", "value:", "at:", "workBlock", "evaluateAt:", "+", "remove", "<="],
 referencedClasses: []
 }),
 smalltalk.HLProgressBar);

+ 130 - 30
st/Helios-Core.st

@@ -190,9 +190,9 @@ saveSourceCode
 !HLToolModel methodsFor: 'commands actions'!
 
 commitPackage
-	self 
+	"self 
 		withHelperLabelled: 'Committing package ', self selectedPackage name, '...'
-		do: [ self environment commitPackage: self selectedPackage ]
+		do: [ "self environment commitPackage: self selectedPackage" ]"
 !
 
 copyClassTo: aClassName
@@ -340,15 +340,16 @@ handleUnkownVariableError: anError
 !
 
 withCompileErrorHandling: aBlock
-	[
-		[
-			aBlock 
-				on: ParseError
-				do: [:ex | self handleParseError: ex ]
-		]
+	self environment
+		evaluate: [
+			self environment 
+			evaluate: [
+				self environment 
+					evaluate: aBlock
+					on: ParseError
+					do: [:ex | self handleParseError: ex ] ]
 			on: UnknownVariableError
-			do: [ :ex | self handleUnkownVariableError: ex ]
-	]
+			do: [ :ex | self handleUnkownVariableError: ex ] ]
 		on: CompilerError
 		do: [ :ex | self handleCompileError: ex ]
 ! !
@@ -413,12 +414,10 @@ I am a specific progress handler for Helios, displaying progresses in a modal wi
 !HLProgressHandler methodsFor: 'progress handling'!
 
 do: aBlock on: aCollection displaying: aString
-	HLProgress new
-		label: aString;
-		workBlock: aBlock;
-		collection: aCollection;
-		appendToJQuery: 'body' asJQuery;
-		start
+	HLProgress default
+		do: aBlock 
+		on: aCollection 
+		displaying: aString
 ! !
 
 Widget subclass: #HLTab
@@ -1260,6 +1259,10 @@ defaultEnvironment
 
 initialize
 	super initialize.
+	
+	HLErrorHandler register.
+	HLProgressHandler register.
+	
 	self registerInspector: HLInspector.
 	self registerErrorHandler: ErrorHandler current.
 	self registerProgressHandler: ProgressHandler current.
@@ -1520,15 +1523,94 @@ renderMainOn: html
 ! !
 
 HLModal subclass: #HLProgress
-	instanceVariableNames: 'label workBlock collection progressBar'
+	instanceVariableNames: 'progressBars visible'
 	package: 'Helios-Core'!
 !HLProgress commentStamp!
 I am a widget used to display progress modal dialogs.
 
-See `HLProgressHandler`!
+My default instance is accessed with `HLProgress >> #default`.
+
+See `HLProgressHandler`.!
 
 !HLProgress methodsFor: 'accessing'!
 
+progressBars
+	^ progressBars ifNil: [ progressBars := OrderedCollection new ]
+! !
+
+!HLProgress methodsFor: 'actions'!
+
+addProgressBar: aProgressBar
+	self show.
+	self progressBars add: aProgressBar.
+	aProgressBar appendToJQuery: (self wrapper asJQuery find: '.dialog')
+!
+
+do: aBlock on: aCollection displaying: aString
+	| progressBar |
+	
+	progressBar := HLProgressBar new
+		parent: self;
+		label: aString;
+		workBlock: aBlock;
+		collection: aCollection;
+		yourself.
+	
+	self addProgressBar: progressBar.
+	progressBar start
+!
+
+remove
+	self isVisible ifTrue: [
+		visible := false.
+		super remove ]
+!
+
+removeProgressBar: aProgressBar
+	self progressBars remove: aProgressBar ifAbsent: [].
+	aProgressBar wrapper asJQuery remove.
+	
+	self progressBars ifEmpty: [ self remove ]
+!
+
+show
+	self isVisible ifFalse: [
+		visible := true.
+		self appendToJQuery: 'body' asJQuery ]
+! !
+
+!HLProgress methodsFor: 'rendering'!
+
+renderButtonsOn: html
+!
+
+renderMainOn: html
+	self progressBars do: [ :each |
+		html with: each ]
+! !
+
+!HLProgress methodsFor: 'testing'!
+
+isVisible
+	^ visible ifNil: [ false ]
+! !
+
+HLProgress class instanceVariableNames: 'default'!
+
+!HLProgress class methodsFor: 'accessing'!
+
+default
+	^ default ifNil: [ default := self new ]
+! !
+
+HLWidget subclass: #HLProgressBar
+	instanceVariableNames: 'label parent workBlock collection bar'
+	package: 'Helios-Core'!
+!HLProgressBar commentStamp!
+I am a widget used to display a progress bar while iterating over a collection.!
+
+!HLProgressBar methodsFor: 'accessing'!
+
 collection
 	^ collection
 !
@@ -1545,6 +1627,14 @@ label: aString
 	label := aString
 !
 
+parent
+	^ parent
+!
+
+parent: aProgress
+	parent := aProgress
+!
+
 workBlock
 	^ workBlock
 !
@@ -1553,17 +1643,22 @@ workBlock: aBlock
 	workBlock := aBlock
 ! !
 
-!HLProgress methodsFor: 'actions'!
+!HLProgressBar methodsFor: 'actions'!
 
 evaluateAt: anInteger
 	self updateProgress: (anInteger / self collection size) * 100.
-	self collection size > anInteger 
+	anInteger <= self collection size
 		ifTrue: [ 
-			self workBlock value: (self collection at: anInteger).
-			[ self evaluateAt: anInteger + 1 ] valueWithTimeout: 1 ]
+			[ 
+				self workBlock value: (self collection at: anInteger).
+				self evaluateAt: anInteger + 1 ] valueWithTimeout: 10 ]
 		ifFalse: [ [ self remove ] valueWithTimeout: 500 ]
 !
 
+remove
+	self parent removeProgressBar: self
+!
+
 start
 	"Make sure the UI has some time to update itself between each iteration"
 	
@@ -1571,24 +1666,29 @@ start
 !
 
 updateProgress: anInteger
-	progressBar asJQuery css: 'width' put: anInteger asString, '%'
+	bar asJQuery css: 'width' put: anInteger asString, '%'
 ! !
 
-!HLProgress methodsFor: 'rendering'!
+!HLProgressBar methodsFor: 'rendering'!
 
-renderButtonsOn: html
-!
-
-renderMainOn: html
+renderContentOn: html
 	html span with: self label.
 	html div 
-		class: 'progress progress-stripped progress-info active';
+		class: 'progress';
 		with: [
-			progressBar := html div 
+			bar := html div 
 				class: 'bar';
 				style: 'width: 0%' ]
 ! !
 
+HLProgressBar class instanceVariableNames: 'default'!
+
+!HLProgressBar class methodsFor: 'accessing'!
+
+default
+	^ default ifNil: [ default := self new ]
+! !
+
 HLWidget subclass: #HLSUnit
 	instanceVariableNames: ''
 	package: 'Helios-Core'!