Przeglądaj źródła

Avoids having several warnings in a row about unsaved changes

Nicolas Petton 10 lat temu
rodzic
commit
5844191975
4 zmienionych plików z 78 dodań i 29 usunięć
  1. 43 13
      src/Helios-Core.js
  2. 19 4
      src/Helios-Core.st
  3. 9 7
      src/Helios-Workspace.js
  4. 7 5
      src/Helios-Workspace.st

+ 43 - 13
src/Helios-Core.js

@@ -1772,6 +1772,22 @@ referencedClasses: []
 }),
 globals.HLWidget);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "confirm:ifTrue:ifFalse:",
+protocol: 'actions',
+fn: function (aString,aBlock,anotherBlock){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(self._manager())._confirm_ifTrue_ifFalse_(aString,aBlock,anotherBlock);
+return self}, function($ctx1) {$ctx1.fill(self,"confirm:ifTrue:ifFalse:",{aString:aString,aBlock:aBlock,anotherBlock:anotherBlock},globals.HLWidget)})},
+args: ["aString", "aBlock", "anotherBlock"],
+source: "confirm: aString ifTrue: aBlock ifFalse: anotherBlock\x0a\x09self manager \x0a\x09\x09confirm: aString \x0a\x09\x09ifTrue: aBlock\x0a\x09\x09ifFalse: anotherBlock",
+messageSends: ["confirm:ifTrue:ifFalse:", "manager"],
+referencedClasses: []
+}),
+globals.HLWidget);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "cssClass",
@@ -3579,18 +3595,14 @@ selector: "confirm:ifFalse:",
 protocol: 'actions',
 fn: function (aString,aBlock){
 var self=this;
-function $HLConfirmationWidget(){return globals.HLConfirmationWidget||(typeof HLConfirmationWidget=="undefined"?nil:HLConfirmationWidget)}
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2;
-$1=_st($HLConfirmationWidget())._new();
-_st($1)._confirmationString_(aString);
-_st($1)._cancelBlock_(aBlock);
-$2=_st($1)._show();
+self._confirm_ifTrue_ifFalse_(aString,(function(){
+}),aBlock);
 return self}, function($ctx1) {$ctx1.fill(self,"confirm:ifFalse:",{aString:aString,aBlock:aBlock},globals.HLManager)})},
 args: ["aString", "aBlock"],
-source: "confirm: aString ifFalse: aBlock\x0a\x09HLConfirmationWidget new\x0a\x09\x09confirmationString: aString;\x0a\x09\x09cancelBlock: aBlock;\x0a\x09\x09show",
-messageSends: ["confirmationString:", "new", "cancelBlock:", "show"],
-referencedClasses: ["HLConfirmationWidget"]
+source: "confirm: aString ifFalse: aBlock\x0a\x09self \x0a\x09\x09confirm: aString\x0a\x09\x09ifTrue: []\x0a\x09\x09ifFalse: aBlock",
+messageSends: ["confirm:ifTrue:ifFalse:"],
+referencedClasses: []
 }),
 globals.HLManager);
 
@@ -3600,17 +3612,35 @@ selector: "confirm:ifTrue:",
 protocol: 'actions',
 fn: function (aString,aBlock){
 var self=this;
+return smalltalk.withContext(function($ctx1) { 
+self._confirm_ifTrue_ifFalse_(aString,aBlock,(function(){
+}));
+return self}, function($ctx1) {$ctx1.fill(self,"confirm:ifTrue:",{aString:aString,aBlock:aBlock},globals.HLManager)})},
+args: ["aString", "aBlock"],
+source: "confirm: aString ifTrue: aBlock\x0a\x09self \x0a\x09\x09confirm: aString\x0a\x09\x09ifTrue: aBlock\x0a\x09\x09ifFalse: []",
+messageSends: ["confirm:ifTrue:ifFalse:"],
+referencedClasses: []
+}),
+globals.HLManager);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "confirm:ifTrue:ifFalse:",
+protocol: 'actions',
+fn: function (aString,aBlock,anotherBlock){
+var self=this;
 function $HLConfirmationWidget(){return globals.HLConfirmationWidget||(typeof HLConfirmationWidget=="undefined"?nil:HLConfirmationWidget)}
 return smalltalk.withContext(function($ctx1) { 
 var $1,$2;
 $1=_st($HLConfirmationWidget())._new();
 _st($1)._confirmationString_(aString);
 _st($1)._actionBlock_(aBlock);
+_st($1)._cancelBlock_(anotherBlock);
 $2=_st($1)._show();
-return self}, function($ctx1) {$ctx1.fill(self,"confirm:ifTrue:",{aString:aString,aBlock:aBlock},globals.HLManager)})},
-args: ["aString", "aBlock"],
-source: "confirm: aString ifTrue: aBlock\x0a\x09HLConfirmationWidget new\x0a\x09\x09confirmationString: aString;\x0a\x09\x09actionBlock: aBlock;\x0a\x09\x09show",
-messageSends: ["confirmationString:", "new", "actionBlock:", "show"],
+return self}, function($ctx1) {$ctx1.fill(self,"confirm:ifTrue:ifFalse:",{aString:aString,aBlock:aBlock,anotherBlock:anotherBlock},globals.HLManager)})},
+args: ["aString", "aBlock", "anotherBlock"],
+source: "confirm: aString ifTrue: aBlock ifFalse: anotherBlock\x0a\x09HLConfirmationWidget new\x0a\x09\x09confirmationString: aString;\x0a\x09\x09actionBlock: aBlock;\x0a\x09\x09cancelBlock: anotherBlock;\x0a\x09\x09show",
+messageSends: ["confirmationString:", "new", "actionBlock:", "cancelBlock:", "show"],
 referencedClasses: ["HLConfirmationWidget"]
 }),
 globals.HLManager);

+ 19 - 4
src/Helios-Core.st

@@ -650,6 +650,13 @@ confirm: aString ifTrue: aBlock
 	self manager confirm: aString ifTrue: aBlock
 !
 
+confirm: aString ifTrue: aBlock ifFalse: anotherBlock
+	self manager 
+		confirm: aString 
+		ifTrue: aBlock
+		ifFalse: anotherBlock
+!
+
 execute: aCommand
 	HLManager current keyBinder
 		activate;
@@ -1250,16 +1257,24 @@ addToHistory: aTab
 !
 
 confirm: aString ifFalse: aBlock
-	HLConfirmationWidget new
-		confirmationString: aString;
-		cancelBlock: aBlock;
-		show
+	self 
+		confirm: aString
+		ifTrue: []
+		ifFalse: aBlock
 !
 
 confirm: aString ifTrue: aBlock
+	self 
+		confirm: aString
+		ifTrue: aBlock
+		ifFalse: []
+!
+
+confirm: aString ifTrue: aBlock ifFalse: anotherBlock
 	HLConfirmationWidget new
 		confirmationString: aString;
 		actionBlock: aBlock;
+		cancelBlock: anotherBlock;
 		show
 !
 

+ 9 - 7
src/Helios-Workspace.js

@@ -1643,24 +1643,26 @@ selector: "onBrowserAboutToChange:",
 protocol: 'reactions',
 fn: function (anAnnouncement){
 var self=this;
-var block;
+var block,currentContents;
 function $HLChangeForbidden(){return globals.HLChangeForbidden||(typeof HLChangeForbidden=="undefined"?nil:HLChangeForbidden)}
 return smalltalk.withContext(function($ctx1) { 
 var $1;
 block=_st(anAnnouncement)._actionBlock();
+currentContents=self._methodContents();
 $1=self._hasModification();
 if(smalltalk.assert($1)){
-self._confirm_ifTrue_("Changes have not been saved. Do you want to discard these changes?",(function(){
-return smalltalk.withContext(function($ctx2) {
 self._methodContents_(self._contents());
-return _st(block)._value();
+$ctx1.sendIdx["methodContents:"]=1;
+self._confirm_ifTrue_ifFalse_("Changes have not been saved. Do you want to discard these changes?",block,(function(){
+return smalltalk.withContext(function($ctx2) {
+return self._methodContents_(currentContents);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
 _st($HLChangeForbidden())._signal();
 };
-return self}, function($ctx1) {$ctx1.fill(self,"onBrowserAboutToChange:",{anAnnouncement:anAnnouncement,block:block},globals.HLBrowserCodeWidget)})},
+return self}, function($ctx1) {$ctx1.fill(self,"onBrowserAboutToChange:",{anAnnouncement:anAnnouncement,block:block,currentContents:currentContents},globals.HLBrowserCodeWidget)})},
 args: ["anAnnouncement"],
-source: "onBrowserAboutToChange: anAnnouncement\x0a\x09| block |\x0a\x09\x0a\x09block := anAnnouncement actionBlock.\x0a\x09\x0a\x09self hasModification\x0a\x09\x09ifTrue: [\x0a\x09\x09\x09self \x0a\x09\x09\x09\x09confirm: 'Changes have not been saved. Do you want to discard these changes?' \x0a\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x22Don't ask twice\x22\x0a\x09\x09\x09\x09\x09self methodContents: self contents.\x0a\x09\x09\x09\x09\x09block value ].\x0a\x09\x09\x09\x0a\x09\x09\x09\x0a\x09\x09\x09HLChangeForbidden signal ]",
-messageSends: ["actionBlock", "ifTrue:", "hasModification", "confirm:ifTrue:", "methodContents:", "contents", "value", "signal"],
+source: "onBrowserAboutToChange: anAnnouncement\x0a\x09| block currentContents |\x0a\x09\x0a\x09block := anAnnouncement actionBlock.\x0a\x09currentContents := self methodContents.\x0a\x09\x0a\x09self hasModification\x0a\x09\x09ifTrue: [\x0a\x09\x09\x09\x22Don't ask twice\x22\x0a\x09\x09\x09self methodContents: self contents.\x0a\x09\x09\x09\x0a\x09\x09\x09self \x0a\x09\x09\x09\x09confirm: 'Changes have not been saved. Do you want to discard these changes?' \x0a\x09\x09\x09\x09ifTrue: block\x0a\x09\x09\x09\x09ifFalse: [ self methodContents: currentContents ].\x0a\x09\x09\x09\x0a\x09\x09\x09\x0a\x09\x09\x09HLChangeForbidden signal ]",
+messageSends: ["actionBlock", "methodContents", "ifTrue:", "hasModification", "methodContents:", "contents", "confirm:ifTrue:ifFalse:", "signal"],
 referencedClasses: ["HLChangeForbidden"]
 }),
 globals.HLBrowserCodeWidget);

+ 7 - 5
src/Helios-Workspace.st

@@ -653,18 +653,20 @@ unregister
 !HLBrowserCodeWidget methodsFor: 'reactions'!
 
 onBrowserAboutToChange: anAnnouncement
-	| block |
+	| block currentContents |
 	
 	block := anAnnouncement actionBlock.
+	currentContents := self methodContents.
 	
 	self hasModification
 		ifTrue: [
+			"Don't ask twice"
+			self methodContents: self contents.
+			
 			self 
 				confirm: 'Changes have not been saved. Do you want to discard these changes?' 
-				ifTrue: [
-					"Don't ask twice"
-					self methodContents: self contents.
-					block value ].
+				ifTrue: block
+				ifFalse: [ self methodContents: currentContents ].
 			
 			
 			HLChangeForbidden signal ]