diff options
author | Silenio Quarti | 2010-01-20 19:06:51 +0000 |
---|---|---|
committer | Silenio Quarti | 2010-01-20 19:06:51 +0000 |
commit | 474c2966568dbeac4b27fdf3fd88e79d3829d960 (patch) | |
tree | a52cf7b561a3f6a654b46e58c95ea03470c480e3 /bundles/org.eclipse.swt/Eclipse SWT Program | |
parent | d68971a6e0260587a83310e14c5dc867f520359b (diff) | |
download | eclipse.platform.swt-474c2966568dbeac4b27fdf3fd88e79d3829d960.tar.gz eclipse.platform.swt-474c2966568dbeac4b27fdf3fd88e79d3829d960.tar.xz eclipse.platform.swt-474c2966568dbeac4b27fdf3fd88e79d3829d960.zip |
Bug 279772 - Clicking on a batch file from within the eclipse IDE does not run it from the file location
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Program')
7 files changed, 242 insertions, 21 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome.c b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome.c index c74ea719a6..56e878adf3 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome.c +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. + * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -141,6 +141,18 @@ JNIEXPORT jintLong JNICALL GNOME_NATIVE(_1gnome_1icon_1theme_1new) } #endif +#ifndef NO__1gnome_1vfs_1get_1mime_1type +JNIEXPORT jintLong JNICALL GNOME_NATIVE(_1gnome_1vfs_1get_1mime_1type) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1get_1mime_1type_FUNC); + rc = (jintLong)gnome_vfs_get_mime_type((const char *)arg0); + GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1get_1mime_1type_FUNC); + return rc; +} +#endif + #ifndef NO__1gnome_1vfs_1get_1registered_1mime_1types JNIEXPORT jintLong JNICALL GNOME_NATIVE(_1gnome_1vfs_1get_1registered_1mime_1types) (JNIEnv *env, jclass that) @@ -165,6 +177,22 @@ JNIEXPORT jboolean JNICALL GNOME_NATIVE(_1gnome_1vfs_1init) } #endif +#ifndef NO__1gnome_1vfs_1is_1executable_1command_1string +JNIEXPORT jboolean JNICALL GNOME_NATIVE(_1gnome_1vfs_1is_1executable_1command_1string) + (JNIEnv *env, jclass that, jbyteArray arg0) +{ + jbyte *lparg0=NULL; + jboolean rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1is_1executable_1command_1string_FUNC); + if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail; + rc = (jboolean)gnome_vfs_is_executable_command_string((const char *)lparg0); +fail: + if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0); + GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1is_1executable_1command_1string_FUNC); + return rc; +} +#endif + #ifndef NO__1gnome_1vfs_1make_1uri_1from_1input JNIEXPORT jintLong JNICALL GNOME_NATIVE(_1gnome_1vfs_1make_1uri_1from_1input) (JNIEnv *env, jclass that, jbyteArray arg0) @@ -235,6 +263,18 @@ JNIEXPORT jint JNICALL GNOME_NATIVE(_1gnome_1vfs_1mime_1application_1launch) } #endif +#ifndef NO__1gnome_1vfs_1mime_1can_1be_1executable +JNIEXPORT jboolean JNICALL GNOME_NATIVE(_1gnome_1vfs_1mime_1can_1be_1executable) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jboolean rc = 0; + GNOME_NATIVE_ENTER(env, that, _1gnome_1vfs_1mime_1can_1be_1executable_FUNC); + rc = (jboolean)gnome_vfs_mime_can_be_executable((const char *)arg0); + GNOME_NATIVE_EXIT(env, that, _1gnome_1vfs_1mime_1can_1be_1executable_FUNC); + return rc; +} +#endif + #ifndef NO__1gnome_1vfs_1mime_1extensions_1list_1free JNIEXPORT void JNICALL GNOME_NATIVE(_1gnome_1vfs_1mime_1extensions_1list_1free) (JNIEnv *env, jclass that, jintLong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.c b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.c index e541d8ef5d..c3e75047c6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. + * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -18,8 +18,8 @@ #ifdef NATIVE_STATS -int GNOME_nativeFunctionCount = 22; -int GNOME_nativeFunctionCallCount[22]; +int GNOME_nativeFunctionCount = 25; +int GNOME_nativeFunctionCallCount[25]; char * GNOME_nativeFunctionNames[] = { "GnomeVFSMimeApplication_1sizeof", "_1g_1free", @@ -30,12 +30,15 @@ char * GNOME_nativeFunctionNames[] = { "_1gnome_1icon_1lookup", "_1gnome_1icon_1theme_1lookup_1icon", "_1gnome_1icon_1theme_1new", + "_1gnome_1vfs_1get_1mime_1type", "_1gnome_1vfs_1get_1registered_1mime_1types", "_1gnome_1vfs_1init", + "_1gnome_1vfs_1is_1executable_1command_1string", "_1gnome_1vfs_1make_1uri_1from_1input", "_1gnome_1vfs_1make_1uri_1from_1input_1with_1dirs", "_1gnome_1vfs_1mime_1application_1free", "_1gnome_1vfs_1mime_1application_1launch", + "_1gnome_1vfs_1mime_1can_1be_1executable", "_1gnome_1vfs_1mime_1extensions_1list_1free", "_1gnome_1vfs_1mime_1get_1default_1application", "_1gnome_1vfs_1mime_1get_1extensions_1list", diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.h b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.h index 8aea1d9165..a4746d2d35 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/library/gnome_stats.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. + * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -38,12 +38,15 @@ typedef enum { _1gnome_1icon_1lookup_FUNC, _1gnome_1icon_1theme_1lookup_1icon_FUNC, _1gnome_1icon_1theme_1new_FUNC, + _1gnome_1vfs_1get_1mime_1type_FUNC, _1gnome_1vfs_1get_1registered_1mime_1types_FUNC, _1gnome_1vfs_1init_FUNC, + _1gnome_1vfs_1is_1executable_1command_1string_FUNC, _1gnome_1vfs_1make_1uri_1from_1input_FUNC, _1gnome_1vfs_1make_1uri_1from_1input_1with_1dirs_FUNC, _1gnome_1vfs_1mime_1application_1free_FUNC, _1gnome_1vfs_1mime_1application_1launch_FUNC, + _1gnome_1vfs_1mime_1can_1be_1executable_FUNC, _1gnome_1vfs_1mime_1extensions_1list_1free_FUNC, _1gnome_1vfs_1mime_1get_1default_1application_FUNC, _1gnome_1vfs_1mime_1get_1extensions_1list_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java index 9802b71f9e..2b73490029 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gnome/org/eclipse/swt/internal/gnome/GNOME.java @@ -138,6 +138,17 @@ public static final int /*long*/ gnome_vfs_get_registered_mime_types() { lock.unlock(); } } +/** @param uri cast=(const char *) */ +public static final native int /*long*/ _gnome_vfs_get_mime_type(int /*long*/ uri); +public static final int /*long*/ gnome_vfs_get_mime_type(int /*long*/ uri) { + lock.lock(); + try { + return _gnome_vfs_get_mime_type(uri); + } finally { + lock.unlock(); + } +} + public static final native boolean _gnome_vfs_init(); public static final boolean gnome_vfs_init() { lock.lock(); @@ -180,6 +191,26 @@ public static final void gnome_vfs_mime_application_free(int /*long*/ applicatio lock.unlock(); } } +/** @param mimeType cast=(const char *) */ +public static final native boolean _gnome_vfs_mime_can_be_executable(int /*long*/ mimeType); +public static final boolean gnome_vfs_mime_can_be_executable(int /*long*/ mimeType) { + lock.lock(); + try { + return _gnome_vfs_mime_can_be_executable(mimeType); + } finally { + lock.unlock(); + } +} +/** @param command_string cast=(const char *) */ +public static final native boolean _gnome_vfs_is_executable_command_string(byte[] command_string); +public static final boolean gnome_vfs_is_executable_command_string(byte[] command_string) { + lock.lock(); + try { + return _gnome_vfs_is_executable_command_string(command_string); + } finally { + lock.unlock(); + } +} /** * @method flags=dynamic * @param application cast=(GnomeVFSMimeApplication *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java index 399b810064..f3ec93417f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java @@ -309,6 +309,11 @@ static boolean cde_init(Display display) { return initOK; } +static boolean cde_isExecutable(String fileName) { + byte [] fileNameBuffer = Converter.wcsToMbcs(null, fileName, true); + return OS.access(fileNameBuffer, OS.X_OK) == 0; +} + static String[] parseCommand(String cmd) { Vector args = new Vector(); int sIndex = 0; @@ -550,6 +555,18 @@ static boolean gnome_init() { } } +static boolean gnome_isExecutable(String fileName) { + /* check if the file is executable */ + byte [] fileNameBuffer = Converter.wcsToMbcs(null, fileName, true); + if (!GNOME.gnome_vfs_is_executable_command_string(fileNameBuffer)) return false; + + /* check if the mime type is executable */ + int /*long*/ uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer); + int /*long*/ mimeType = GNOME.gnome_vfs_get_mime_type(uri); + GNOME.g_free(uri); + return GNOME.gnome_vfs_mime_can_be_executable(mimeType); +} + /** * Finds the program that is associated with an extension. * The extension may or may not begin with a '.'. Note that @@ -878,6 +895,12 @@ static Program[] gio_getPrograms(Display display) { return programList; } +static boolean gio_isExecutable(String fileName) { + byte[] fileNameBuffer = Converter.wcsToMbcs (null, fileName, true); + if (OS.g_file_test(fileNameBuffer, OS.G_FILE_TEST_IS_DIR)) return false; + return OS.g_file_test(fileNameBuffer, OS.G_FILE_TEST_IS_EXECUTABLE); +} + /** * GNOME 2.4 - Launch the default program for the given file. */ @@ -936,6 +959,16 @@ static String[] gio_getExtensions() { return extStrings; } +public static boolean isExecutable(Display display, String fileName) { + switch(getDesktop(display)) { + case DESKTOP_GIO: return gio_isExecutable(fileName); + case DESKTOP_GNOME_24: + case DESKTOP_GNOME: return gnome_isExecutable(fileName); + case DESKTOP_CDE: return cde_isExecutable(fileName); + } + return false; +} + /** * Launches the operating system executable associated with the file or * URL (http:// or https://). If the file is an executable then the @@ -950,15 +983,45 @@ static String[] gio_getExtensions() { * </ul> */ public static boolean launch(String fileName) { - return launch(Display.getCurrent(), fileName); + return launch(Display.getCurrent(), fileName, null); +} + +/** +* Launches the operating system executable associated with the file or +* URL (http:// or https://). If the file is an executable then the +* executable is launched. If a valid working directory is specified +* it is used as the working directory for the launched program. +* Note that a <code>Display</code> must already exist to guarantee +* that this method returns an appropriate result. +* +* @param fileName the file or program name or URL (http:// or https://) +* @param workingDirectory the name of the working directory or null +* @return <code>true</code> if the file is launched, otherwise <code>false</code> +* +* @exception IllegalArgumentException <ul> +* <li>ERROR_NULL_ARGUMENT when fileName is null</li> +* </ul> +* +* @since 3.6 +*/ +/*public*/ static boolean launch (String fileName, String workingDir) { + return launch(Display.getCurrent(), fileName, workingDir); } /* * API: When support for multiple displays is added, this method will * become public and the original method above can be deprecated. */ -static boolean launch (Display display, String fileName) { +static boolean launch (Display display, String fileName, String workingDir) { if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if (isExecutable(display, fileName)) { + try { + Compatibility.exec (new String [] {fileName}, null, workingDir); + return true; + } catch (IOException e) { + // + } + } switch (getDesktop (display)) { case DESKTOP_GIO: if (gio_launch (fileName)) return true; @@ -981,12 +1044,7 @@ static boolean launch (Display display, String fileName) { } break; } - try { - Compatibility.exec (fileName); - return true; - } catch (IOException e) { - return false; - } + return false; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java index 38bfd903f5..6d26bd1f98 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/motif/org/eclipse/swt/program/Program.java @@ -160,6 +160,11 @@ boolean cde_execute(String fileName) { return actionID != 0; } +static boolean cde_isExecutable(String fileName) { + byte [] fileNameBuffer = Converter.wcsToMbcs(null, fileName, true); + return OS.access(fileNameBuffer, OS.X_OK) == 0; +} + static String cde_getAction(String dataType) { String action = null; String actions = cde_getAttribute(dataType, CDE.DtDTS_DA_ACTION_LIST); @@ -569,6 +574,18 @@ static boolean gnome_init() { } } +static boolean gnome_isExecutable(String fileName) { + /* check if the file is executable */ + byte [] fileNameBuffer = Converter.wcsToMbcs(null, fileName, true); + if (!GNOME.gnome_vfs_is_executable_command_string(fileNameBuffer)) return false; + + /* check if the mime type is executable */ + int /*long*/ uri = GNOME.gnome_vfs_make_uri_from_input(fileNameBuffer); + int /*long*/ mimeType = GNOME.gnome_vfs_get_mime_type(uri); + GNOME.g_free(uri); + return GNOME.gnome_vfs_mime_can_be_executable(mimeType); +} + /** * Finds the program that is associated with an extension. * The extension may or may not begin with a '.'. Note that @@ -699,6 +716,15 @@ static Program[] getPrograms(Display display) { return programList; } +static boolean isExecutable(Display display, String fileName) { + switch(getDesktop(display)) { + case DESKTOP_GNOME_24: + case DESKTOP_GNOME: return gnome_isExecutable(fileName); + case DESKTOP_CDE: return cde_isExecutable(fileName); + } + return false; +} + /** * Launches the operating system executable associated with the file or * URL (http:// or https://). If the file is an executable then the @@ -713,15 +739,46 @@ static Program[] getPrograms(Display display) { * </ul> */ public static boolean launch(String fileName) { - return launch(Display.getCurrent(), fileName); + return launch(Display.getCurrent(), fileName, null); } +/** +* Launches the operating system executable associated with the file or +* URL (http:// or https://). If the file is an executable then the +* executable is launched. If a valid working directory is specified +* it is used as the working directory for the launched program. +* Note that a <code>Display</code> must already exist to guarantee +* that this method returns an appropriate result. +* +* @param fileName the file or program name or URL (http:// or https://) +* @param workingDirectory the name of the working directory or null +* @return <code>true</code> if the file is launched, otherwise <code>false</code> +* +* @exception IllegalArgumentException <ul> +* <li>ERROR_NULL_ARGUMENT when fileName is null</li> +* <li>ERROR_INVALID_ARGUMENT when workingDirectory is not valid</li> +* </ul> +* +* @since 3.6 +*/ +public static boolean launch (String fileName, String workingDir) { + return launch(Display.getCurrent(), fileName, workingDir); +} /* * API: When support for multiple displays is added, this method will * become public and the original method above can be deprecated. */ -static boolean launch (Display display, String fileName) { +static boolean launch (Display display, String fileName, String workingDir) { if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + + if (isExecutable(display, fileName)) { + try { + Compatibility.exec (new String [] {fileName}, null, workingDir); + return true; + } catch (IOException e) { + // + } + } switch (getDesktop (display)) { case DESKTOP_GNOME_24: if (gnome_24_launch (fileName)) return true; @@ -742,12 +799,7 @@ static boolean launch (Display display, String fileName) { } break; } - try { - Compatibility.exec (fileName); - return true; - } catch (IOException e) { - return false; - } + return false; } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java index 9cc4031f58..ad1d5cdd72 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java @@ -263,6 +263,29 @@ public static Program [] getPrograms () { * </ul> */ public static boolean launch (String fileName) { + return launch(fileName, null); +} + +/** + * Launches the operating system executable associated with the file or + * URL (http:// or https://). If the file is an executable then the + * executable is launched. If a valid working directory is specified + * it is used as the working directory for the launched program. + * Note that a <code>Display</code> must already exist to guarantee + * that this method returns an appropriate result. + * + * @param fileName the file or program name or URL (http:// or https://) + * @param workingDirectory the name of the working directory or null + * @return <code>true</code> if the file is launched, otherwise <code>false</code> + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT when fileName is null</li> + * <li>ERROR_INVALID_ARGUMENT when workingDirectory is not valid</li> + * </ul> + * + * @since 3.6 + */ +/*public*/ static boolean launch (String fileName, String workingDirectory) { if (fileName == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); /* Use the character encoding for the default locale */ @@ -271,12 +294,23 @@ public static boolean launch (String fileName) { int byteCount = buffer.length () * TCHAR.sizeof; int /*long*/ lpFile = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); OS.MoveMemory (lpFile, buffer, byteCount); + + int /*long*/ lpDirectory = 0; + if (workingDirectory != null && OS.PathIsExe(lpFile)) { + TCHAR buffer1 = new TCHAR (0, workingDirectory, true); + byteCount = buffer1.length () * TCHAR.sizeof; + lpDirectory = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); + OS.MoveMemory (lpDirectory, buffer1, byteCount); + } + SHELLEXECUTEINFO info = new SHELLEXECUTEINFO (); info.cbSize = SHELLEXECUTEINFO.sizeof; info.lpFile = lpFile; + info.lpDirectory = lpDirectory; info.nShow = OS.SW_SHOW; boolean result = OS.ShellExecuteEx (info); if (lpFile != 0) OS.HeapFree (hHeap, 0, lpFile); + if (lpDirectory != 0) OS.HeapFree (hHeap, 0, lpDirectory); return result; } |