added: #openApplicationForDocument:operation:
authorClaus Gittinger <cg@exept.de>
Tue, 06 Oct 2009 10:31:04 +0200
changeset 12154 646c4171f0d2
parent 12153 2a550010208b
child 12155 bd7ed01c3a94
added: #openApplicationForDocument:operation: changed: #openDocumentationFilename: #shellExecute:lpOperation:lpFile:lpParameters:lpDirectory:nShowCmd: code cleanup: shell operations
Win32OperatingSystem.st
--- a/Win32OperatingSystem.st	Tue Oct 06 09:53:54 2009 +0200
+++ b/Win32OperatingSystem.st	Tue Oct 06 10:31:04 2009 +0200
@@ -5970,29 +5970,52 @@
 
 !Win32OperatingSystem class methodsFor:'help support'!
 
+openApplicationForDocument:aFilenameOrString operation:operationSymbol
+    "open a windows-shell application to present the document contained in aFilenameOrString.
+     This looks for the files extension, and is typically used to present help-files,
+     html documents, pdf documents etc.
+     operationSymbol is one of:
+        open
+        edit"
+
+    |result filename|
+
+    filename := aFilenameOrString asFilename.
+    result := self
+        shellExecute:nil
+        lpOperation:operationSymbol
+        lpFile:filename pathName
+        lpParameters:nil
+        lpDirectory:filename directory pathName
+        nShowCmd:#SW_SHOWNORMAL.
+    ^ self.
+
+    "
+     self openApplicationForDocument: Filename currentDirectory operation:#open
+     self openApplicationForDocument: '..\..\doc\books\ArtOfSmalltalk\artMissing186187Fix1.pdf' asFilename operation:#open
+
+     self openApplicationForDocument: 'C:\WINDOWS\Help\clipbrd.chm' asFilename operation:#open
+    "
+
+    "Created: / 04-08-2006 / 18:04:52 / fm"
+    "Modified: / 26-01-2007 / 14:05:44 / cg"
+!
+
 openDocumentationFilename: aFilenameOrString
+    <resource: #obsolete>
+
+    self obsoleteMethodWarning:'call openApplicationForDocument:operation: and provide a proper error handler yourself'.
+
     "open a windows-shell application to present the document contained in aFilenameOrString.
      This looks for the files extension, and is typically used to present help-files,
      html documents, pdf documents etc."
 
-    |result|
-
     Error
-	handle:[:ex |
-	    self halt:'shell execution failed'
-	] do:[
-	    |filename|
-
-	    filename := aFilenameOrString asFilename.
-	    result := self
-		shellExecute:nil
-		lpOperation:'open'
-		lpFile:filename pathName
-		lpParameters:nil
-		lpDirectory:filename directory pathName
-		nShowCmd:#SW_SHOWNORMAL.
-	    ^ self.
-	]
+        handle:[:ex |
+            Dialog warn:'Shell execution failed'
+        ] do:[
+            self openApplicationForDocument:aFilenameOrString operation:#open
+        ]
 
     "
      self openDocumentationFilename: 'C:\WINDOWS\Help\clipbrd.chm' asFilename
@@ -9331,12 +9354,12 @@
 
     "
      HINSTANCE ShellExecute(
-	     HWND hwnd,                      // handle to parent window
-	     LPCTSTR lpOperation,    // pointer to string that specifies operation to perform
-	     LPCTSTR lpFile,         // pointer to filename or folder name string
-	     LPCTSTR lpParameters,   // pointer to string that specifies executable-file parameters
-	     LPCTSTR lpDirectory,    // pointer to string that specifies default directory
-	     INT nShowCmd                    // whether file is shown when opened
+             HWND hwnd,                      // handle to parent window
+             LPCTSTR lpOperation,    // pointer to string that specifies operation to perform
+             LPCTSTR lpFile,         // pointer to filename or folder name string
+             LPCTSTR lpParameters,   // pointer to string that specifies executable-file parameters
+             LPCTSTR lpDirectory,    // pointer to string that specifies default directory
+             INT nShowCmd                    // whether file is shown when opened
      );
     "
 "/  <apicall: long 'ShellExecuteA' (long char* char* char* char* ulong) module:'shell32.dll'>
@@ -9344,106 +9367,108 @@
     unsigned long __nShowCmd = 0;
 
     if (__isSmallInteger(nShowCmd)) {
-	__nShowCmd = __intVal(nShowCmd);
+        __nShowCmd = __intVal(nShowCmd);
     } else {
-	if (nShowCmd == @symbol(SW_SHOW)) {
-	    __nShowCmd = SW_SHOW;
-	} else if (nShowCmd == @symbol(SW_SHOWNORMAL)) {
-	    __nShowCmd = SW_SHOWNORMAL;
-	} else if (nShowCmd == @symbol(SW_SHOWDEFAULT)) {
-	    __nShowCmd = SW_SHOWDEFAULT;
-	} else if (nShowCmd == @symbol(SW_SHOWMAXIMIZED)) {
-	    __nShowCmd = SW_SHOWMAXIMIZED;
-	} else if (nShowCmd == @symbol(SW_SHOWMINIMIZED)) {
-	    __nShowCmd = SW_SHOWMINIMIZED;
-	} else if (nShowCmd == @symbol(SW_SHOWMINNOACTIVE)) {
-	    __nShowCmd = SW_SHOWMINNOACTIVE;
-	} else if (nShowCmd == @symbol(SW_SHOWNA)) {
-	    __nShowCmd = SW_SHOWNA;
-	} else if (nShowCmd == @symbol(SW_SHOWNOACTIVATE)) {
-	    __nShowCmd = SW_SHOWNOACTIVATE;
-	} else if (nShowCmd == @symbol(SW_MAXIMIZE)) {
-	    __nShowCmd = SW_MAXIMIZE;
-	} else if (nShowCmd == @symbol(SW_RESTORE)) {
-	    __nShowCmd = SW_RESTORE;
-	} else {
-	    goto badArgument;
-	}
-    }
-
-    if (((lpOperation == nil) || __isString(lpOperation))
+        if (nShowCmd == @symbol(SW_SHOW)) {
+            __nShowCmd = SW_SHOW;
+        } else if (nShowCmd == @symbol(SW_SHOWNORMAL)) {
+            __nShowCmd = SW_SHOWNORMAL;
+        } else if (nShowCmd == @symbol(SW_SHOWDEFAULT)) {
+            __nShowCmd = SW_SHOWDEFAULT;
+        } else if (nShowCmd == @symbol(SW_SHOWMAXIMIZED)) {
+            __nShowCmd = SW_SHOWMAXIMIZED;
+        } else if (nShowCmd == @symbol(SW_SHOWMINIMIZED)) {
+            __nShowCmd = SW_SHOWMINIMIZED;
+        } else if (nShowCmd == @symbol(SW_SHOWMINNOACTIVE)) {
+            __nShowCmd = SW_SHOWMINNOACTIVE;
+        } else if (nShowCmd == @symbol(SW_SHOWNA)) {
+            __nShowCmd = SW_SHOWNA;
+        } else if (nShowCmd == @symbol(SW_SHOWNOACTIVATE)) {
+            __nShowCmd = SW_SHOWNOACTIVATE;
+        } else if (nShowCmd == @symbol(SW_MAXIMIZE)) {
+            __nShowCmd = SW_MAXIMIZE;
+        } else if (nShowCmd == @symbol(SW_RESTORE)) {
+            __nShowCmd = SW_RESTORE;
+        } else {
+            goto badArgument;
+        }
+    }
+
+    if (((lpOperation == nil) || __isString(lpOperation) || __isSymbol(lpOperation))
      && ((lpFile == nil) || __isString(lpFile))
      && ((lpParameters == nil) || __isString(lpParameters))
      && ((lpDirectory == nil) || __isString(lpDirectory))
     ) {
-	HANDLE __hwnd = 0;
-	char *__lpOperation   = (lpOperation != nil) ? __stringVal(lpOperation) : NULL;
-	char *__lpFile        = (lpFile != nil) ? __stringVal(lpFile) : NULL;
-	char *__lpParameters  = (lpParameters != nil) ? __stringVal(lpParameters) : NULL;
-	char *__lpDirectory   = (lpDirectory != nil) ? __stringVal(lpDirectory) : NULL;
-	long result;
-
-	if (hwnd != nil) {
-	    if (__isExternalAddressLike(hwnd)) {
-		__hwnd = (HANDLE)(__externalAddressVal(hwnd));
-	    } else
-		goto badArgument;
-	}
-	result = ShellExecuteA(__hwnd, __lpOperation, __lpFile, __lpParameters, __lpDirectory, __nShowCmd);
-
-	/* MS programmers are brain damaged - here's the proof... */
-	if (result > 32) {
-	    RETURN ( self ); /* OK */
-	}
-
-	switch (result) {
-	    case 0:
-	    case SE_ERR_OOM:
-		result = ERROR_NOT_ENOUGH_MEMORY;
-		break;
-
-	    case SE_ERR_ACCESSDENIED:
-		result = ERROR_ACCESS_DENIED;
-		break;
-
-	    case SE_ERR_FNF:
-		result = ERROR_FILE_NOT_FOUND;
-		break;
-
-	    case SE_ERR_PNF:
-		result = ERROR_PATH_NOT_FOUND;
-		break;
-
-	    default:
-		result = ERROR_INVALID_FUNCTION;
-		break;
-	}
-	errorNumber = __MKUINT( result );
+        HANDLE __hwnd = 0;
+        char *__lpOperation   = (lpOperation != nil) ? __stringVal(lpOperation) : NULL;
+        char *__lpFile        = (lpFile != nil) ? __stringVal(lpFile) : NULL;
+        char *__lpParameters  = (lpParameters != nil) ? __stringVal(lpParameters) : NULL;
+        char *__lpDirectory   = (lpDirectory != nil) ? __stringVal(lpDirectory) : NULL;
+        long result;
+
+        if (hwnd != nil) {
+            if (__isExternalAddressLike(hwnd)) {
+                __hwnd = (HANDLE)(__externalAddressVal(hwnd));
+            } else
+                goto badArgument;
+        }
+        result = ShellExecuteA(__hwnd, __lpOperation, __lpFile, __lpParameters, __lpDirectory, __nShowCmd);
+
+        /* MS programmers are brain damaged - here's the proof... */
+        if (result > 32) {
+            RETURN ( self ); /* OK */
+        }
+
+        switch (result) {
+            case 0:
+            case SE_ERR_OOM:
+                result = ERROR_NOT_ENOUGH_MEMORY;
+                break;
+
+            case SE_ERR_ACCESSDENIED:
+                result = ERROR_ACCESS_DENIED;
+                break;
+
+            case SE_ERR_FNF:
+                result = ERROR_FILE_NOT_FOUND;
+                break;
+
+            case SE_ERR_PNF:
+                result = ERROR_PATH_NOT_FOUND;
+                break;
+
+            default:
+                result = ERROR_INVALID_FUNCTION;
+                break;
+        }
+        errorNumber = __MKUINT( result );
     }
 badArgument: ;
 %}.
     errorNumber isNil ifTrue:[
-	self error:'invalid argument(s)'.
+        self error:'invalid argument(s)'.
     ] ifFalse:[
-	(OperatingSystem errorHolderForNumber:errorNumber) reportError
+        (OperatingSystem errorHolderForNumber:errorNumber)
+            parameter:lpFile;
+            reportError
     ].
 
     "
      self
-	shellExecute:nil
-	lpOperation:'open'
-	lpFile:(Filename currentDirectory pathName)
-	lpParameters:nil
-	lpDirectory:(Filename currentDirectory pathName)
-	nShowCmd:#SW_SHOWNORMAL
+        shellExecute:nil
+        lpOperation:'open'
+        lpFile:(Filename currentDirectory pathName)
+        lpParameters:nil
+        lpDirectory:(Filename currentDirectory pathName)
+        nShowCmd:#SW_SHOWNORMAL
 
     self
-	shellExecute:nil
-	lpOperation:'explore'
-	lpFile:(Filename currentDirectory pathName)
-	lpParameters:nil
-	lpDirectory:(Filename currentDirectory pathName)
-	nShowCmd:#SW_SHOWNORMAL
+        shellExecute:nil
+        lpOperation:'explore'
+        lpFile:(Filename currentDirectory pathName)
+        lpParameters:nil
+        lpDirectory:(Filename currentDirectory pathName)
+        nShowCmd:#SW_SHOWNORMAL
     "
 
     "Modified: / 26-01-2007 / 14:29:21 / cg"
@@ -16237,7 +16262,11 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.377 2009-09-14 20:43:29 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.378 2009-10-06 08:31:04 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.378 2009-10-06 08:31:04 cg Exp $'
 ! !
 
 Win32OperatingSystem initialize!