#OTHER by stefan
authorStefan Vogel <sv@exept.de>
Thu, 08 Sep 2016 15:49:30 +0200
changeset 20365 9df67358e291
parent 20364 190857959db0
child 20366 5c949545fd4a
#OTHER by stefan class: AbstractOperatingSystem added: #openApplicationForDocument:operation:mimeType:inDirectory: #openApplicationForDocument:operation:mimeType:inDirectory:ifNone: changed: #exec:withArguments:environment:fileDescriptors:fork:newPgrp:inDirectory: #executeCommand:inputFrom:outputTo:errorTo:auxFrom:environment:inDirectory:lineWise:onError: #openApplicationForDocument:operation:mimeType: #openApplicationForDocument:operation:mimeType:ifNone: Revert behavior back to pre-September version: showWindow is false by default
AbstractOperatingSystem.st
--- a/AbstractOperatingSystem.st	Thu Sep 08 15:48:05 2016 +0200
+++ b/AbstractOperatingSystem.st	Thu Sep 08 15:49:30 2016 +0200
@@ -619,21 +619,22 @@
     "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
      This is typically used to present help-files, html documents, pdf documents etc.
      operationSymbol is one of:
-	open
-	edit
-	explore
+        open
+        edit
+        explore
      mimeTypeStringArgOrNil is e.g. 'text/html' or: 'application/pdf'.
      If nil is passed in, the file's suffix is used to guess the mime type.
     "
 
     self
-	openApplicationForDocument:aFilenameOrString
-	operation:operationSymbol
-	mimeType:mimeTypeStringArgOrNil
-	ifNone:[
-	    "/ last resort: use a fileBrowser
-	    UserPreferences fileBrowserClass openOn:aFilenameOrString
-	].
+        openApplicationForDocument:aFilenameOrString
+        operation:operationSymbol
+        mimeType:mimeTypeStringArgOrNil
+        inDirectory:nil
+        ifNone:[
+            "/ last resort: use a fileBrowser
+            UserPreferences fileBrowserClass openOn:aFilenameOrString
+        ].
 
     "
      self openApplicationForDocument: Filename currentDirectory operation:#open
@@ -650,9 +651,26 @@
     "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
      This is typically used to present help-files, html documents, pdf documents etc.
      operationSymbol is one of:
-	open
-	edit
-	explore
+        open
+        edit
+        explore
+     mimeTypeStringArgOrNil is e.g. 'text/html' or: 'application/pdf';
+     if nil is passed in, the file's suffix is used to guess it.
+    "
+
+    ^ self 
+        openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil 
+        inDirectory:nil ifNone:exceptionBlock
+!
+
+openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil 
+    inDirectory:directoryStringOrFilenameOrNil
+    "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
+     This is typically used to present help-files, html documents, pdf documents etc.
+     operationSymbol is one of:
+        open
+        edit
+        explore
      mimeTypeStringArgOrNil is e.g. 'text/html' or: 'application/pdf';
      if nil is passed in, the file's suffix is used to guess it.
     "
@@ -662,30 +680,30 @@
     mimeTypeString := mimeTypeStringArgOrNil.
 
     MIMETypes notNil ifTrue:[
-	mimeTypeString isNil ifTrue:[
-	    mimeTypeString := MIMETypes mimeTypeForFilename:aFilenameOrString.
-	].
-	mimeTypeString notNil ifTrue:[
-	    openCommand := MIMETypes defaultCommandTemplateToOpenMimeType:mimeTypeString.
-	].
-    ].
+        mimeTypeString isNil ifTrue:[
+            mimeTypeString := MIMETypes mimeTypeForFilename:aFilenameOrString.
+        ].
+        mimeTypeString notNil ifTrue:[
+            openCommand := MIMETypes defaultCommandTemplateToOpenMimeType:mimeTypeString.
+        ].
+    ].                                                                                         
     openCommand notEmptyOrNil ifTrue:[
-	(openCommand includesSubString:'%1') ifTrue:[
-	    openCommand := openCommand bindWith:aFilenameOrString asString.
-	] ifFalse:[
-	    openCommand := openCommand, ' "', aFilenameOrString asString, '"'.
-	].
-
-	(self
-		startProcess:openCommand
-		inputFrom:nil outputTo:nil
-		errorTo:nil auxFrom:nil
-		environment:nil inDirectory:nil) notNil
-	ifTrue:[
-	    ^ self.
-	].
+        (openCommand includesSubString:'%1') ifTrue:[
+            openCommand := openCommand bindWith:aFilenameOrString asString.
+        ] ifFalse:[
+            openCommand := openCommand, ' "', aFilenameOrString asString, '"'.
+        ].
+
+        (self
+                startProcess:openCommand
+                inputFrom:nil outputTo:nil
+                errorTo:nil auxFrom:nil
+                environment:nil inDirectory:directoryStringOrFilenameOrNil) notNil
+        ifTrue:[
+            ^ self.
+        ].
     ].
-    exceptionBlock notNil ifTrue:[ exceptionBlock value ].
+    ExecutionError raiseErrorString:'execution of command failed: ', openCommand.
 
     "
      self openApplicationForDocument: Filename currentDirectory operation:#open
@@ -696,6 +714,28 @@
 
     "Created: / 29-10-2010 / 12:16:38 / cg"
     "Modified: / 05-02-2011 / 16:13:42 / cg"
+!
+
+openApplicationForDocument:aFilenameOrString operation:operationSymbol mimeType:mimeTypeStringArgOrNil 
+    inDirectory:directoryStringOrFilenameOrNil ifNone:exceptionBlock
+    "open a windows-shell/mac finder/desktop application to present the document contained in aFilenameOrString.
+     This is typically used to present help-files, html documents, pdf documents etc.
+     operationSymbol is one of:
+        open
+        edit
+        explore
+     mimeTypeStringArgOrNil is e.g. 'text/html' or: 'application/pdf';
+     if nil is passed in, the file's suffix is used to guess it.
+    "
+
+    [
+        ^ self 
+            openApplicationForDocument:aFilenameOrString 
+            operation:operationSymbol mimeType:mimeTypeStringArgOrNil 
+            inDirectory:directoryStringOrFilenameOrNil.
+    ] on:ExecutionError do:[:ex|
+        exceptionBlock value.
+    ].
 ! !
 
 !AbstractOperatingSystem class methodsFor:'error messages'!
@@ -866,7 +906,7 @@
 
     ^ self 
         exec:aCommandPath withArguments:argArray environment:env fileDescriptors:fds fork:doFork 
-        newPgrp:newGrp inDirectory:aDirectory showWindow:nil
+        newPgrp:newGrp inDirectory:aDirectory showWindow:false
 
     "Created: / 12.11.1998 / 14:46:15 / cg"
 !
@@ -1368,7 +1408,7 @@
     ^ self
         executeCommand:aCommandStringOrArray inputFrom:anInStream outputTo:anOutStream
         errorTo:anErrStream auxFrom:anAuxStream environment:environmentDictionary
-        inDirectory:dirOrNil lineWise:lineWise showWindow:nil onError:aBlock
+        inDirectory:dirOrNil lineWise:lineWise showWindow:false onError:aBlock
 
     "
         |outStream errStream|