Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/library/os.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2025 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1091,22 +1091,6 @@ JNIEXPORT void JNICALL OS_NATIVE(CFRunLoopObserverInvalidate)
}
#endif

#ifndef NO_CFURLCreateFromFSRef
JNIEXPORT jlong JNICALL OS_NATIVE(CFURLCreateFromFSRef)
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1)
{
jbyte *lparg1=NULL;
jlong rc = 0;
OS_NATIVE_ENTER(env, that, CFURLCreateFromFSRef_FUNC);
if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail;
rc = (jlong)CFURLCreateFromFSRef((CFAllocatorRef)arg0, (FSRef*)lparg1);
fail:
if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
OS_NATIVE_EXIT(env, that, CFURLCreateFromFSRef_FUNC);
return rc;
}
#endif

#ifndef NO_CFURLCreateStringByAddingPercentEscapes
JNIEXPORT jlong JNICALL OS_NATIVE(CFURLCreateStringByAddingPercentEscapes)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jlong arg2, jlong arg3, jint arg4)
Expand Down Expand Up @@ -2106,25 +2090,6 @@ JNIEXPORT jbyte JNICALL OS_NATIVE(LMGetKbdType)
}
#endif

#ifndef NO_LSGetApplicationForInfo
JNIEXPORT jlong JNICALL OS_NATIVE(LSGetApplicationForInfo)
(JNIEnv *env, jclass that, jint arg0, jint arg1, jlong arg2, jint arg3, jbyteArray arg4, jintArray arg5)
{
jbyte *lparg4=NULL;
jint *lparg5=NULL;
jlong rc = 0;
OS_NATIVE_ENTER(env, that, LSGetApplicationForInfo_FUNC);
if (arg4) if ((lparg4 = (*env)->GetByteArrayElements(env, arg4, NULL)) == NULL) goto fail;
if (arg5) if ((lparg5 = (*env)->GetIntArrayElements(env, arg5, NULL)) == NULL) goto fail;
rc = (jlong)LSGetApplicationForInfo((OSType)arg0, (OSType)arg1, (CFStringRef)arg2, (LSRolesMask)arg3, (FSRef *)lparg4, (CFURLRef *)lparg5);
fail:
if (arg5 && lparg5) (*env)->ReleaseIntArrayElements(env, arg5, lparg5, 0);
if (arg4 && lparg4) (*env)->ReleaseByteArrayElements(env, arg4, lparg4, 0);
OS_NATIVE_EXIT(env, that, LSGetApplicationForInfo_FUNC);
return rc;
}
#endif

#ifndef NO_LineTo
JNIEXPORT void JNICALL OS_NATIVE(LineTo)
(JNIEnv *env, jclass that, jshort arg0, jshort arg1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2025 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -70,7 +70,6 @@ typedef enum {
CFRunLoopGetCurrent_FUNC,
CFRunLoopObserverCreate_FUNC,
CFRunLoopObserverInvalidate_FUNC,
CFURLCreateFromFSRef_FUNC,
CFURLCreateStringByAddingPercentEscapes_FUNC,
CGAffineTransform_1sizeof_FUNC,
CGBitmapContextCreate_FUNC,
Expand Down Expand Up @@ -149,7 +148,6 @@ typedef enum {
JSStringCreateWithUTF8CString_FUNC,
JSStringRelease_FUNC,
LMGetKbdType_FUNC,
LSGetApplicationForInfo_FUNC,
LineTo_FUNC,
MoveTo_FUNC,
NSAccessibilityAttributedStringForRangeParameterizedAttribute_FUNC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -45,6 +45,16 @@ public boolean openURL(NSURL url) {
return OS.objc_msgSend_bool(this.id, OS.sel_openURL_, url != null ? url.id : 0);
}

public NSURL urlForApplicationToOpenURL(NSURL url) {
long result = OS.objc_msgSend(this.id, OS.sel_URLForApplicationToOpenURL_, url != null ? url.id : 0);
return result != 0 ? new NSURL(result) : null;
}

public NSURL urlForApplicationToOpenContentType(long contentType) {
long result = OS.objc_msgSend(this.id, OS.sel_URLForApplicationToOpenContentType_, contentType);
return result != 0 ? new NSURL(result) : null;
}

public boolean openURLs(NSArray urls, NSString bundleIdentifier, long options, NSAppleEventDescriptor descriptor, long identifiers) {
return OS.objc_msgSend_bool(this.id, OS.sel_openURLs_withAppBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifiers_, urls != null ? urls.id : 0, bundleIdentifier != null ? bundleIdentifier.id : 0, options, descriptor != null ? descriptor.id : 0, identifiers);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2022 IBM Corporation and others.
* Copyright (c) 2007, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -65,9 +65,6 @@ public static int VERSION (int major, int minor, int bugfix) {
public static final int kUIModeNormal = 0;
public static final int kUIModeContentHidden = 2;
public static final int kUIModeAllHidden = 3;
public static final int kLSUnknownType = 0;
public static final int kLSUnknownCreator = 0;
public static final int kLSRolesAll = 0xFFFFFFFF;
public static final int kAXUnderlineStyleNone = 0x0;
public static final int kAXUnderlineStyleSingle = 0x1;
public static final int kAXUnderlineStyleThick = 0x2;
Expand Down Expand Up @@ -313,15 +310,6 @@ public static boolean isBigSurOrLater () {
public static final native long AcquireRootMenu ();
/** @method flags=dynamic */
public static final native int CancelMenuTracking (long inRootMenu, boolean inImmediate, int inDismissalReason);
/**
* @param inType cast=(OSType)
* @param inCreator cast=(OSType)
* @param inExtension cast=(CFStringRef)
* @param inRoleMask cast=(LSRolesMask)
* @param outAppRef cast=(FSRef *)
* @param outAppURL cast=(CFURLRef *)
*/
public static final native long LSGetApplicationForInfo(int inType, int inCreator,long inExtension, int inRoleMask, byte[] outAppRef, int[] outAppURL);
/** @method flags=dynamic
* @param pmSessionInfo cast=(PMPrintSession)
* @param outPMPrinter cast=(PMPrinter *)
Expand Down Expand Up @@ -854,6 +842,8 @@ public static Selector getSelector (long value) {
public static final long sel_TIFFRepresentation = Selector.sel_TIFFRepresentation.value;
public static final long sel_URL = Selector.sel_URL.value;
public static final long sel_URLFromPasteboard_ = Selector.sel_URLFromPasteboard_.value;
public static final long sel_URLForApplicationToOpenURL_ = Selector.sel_URLForApplicationToOpenURL_.value;
public static final long sel_URLForApplicationToOpenContentType_ = Selector.sel_URLForApplicationToOpenContentType_.value;
public static final long sel_URLWithString_ = Selector.sel_URLWithString_.value;
public static final long sel_UTF8String = Selector.sel_UTF8String.value;
public static final long sel_abortEditing = Selector.sel_abortEditing.value;
Expand Down Expand Up @@ -2061,6 +2051,7 @@ public static Selector getSelector (long value) {
public static final long sel_type = Selector.sel_type.value;
public static final long sel_type_conformsToType_ = Selector.sel_type_conformsToType_.value;
public static final long sel_typeOfFile_error_ = Selector.sel_typeOfFile_error_.value;
public static final long sel_typeWithFilenameExtension_ = Selector.sel_typeWithFilenameExtension_.value;
public static final long sel_types = Selector.sel_types.value;
public static final long sel_typesetter = Selector.sel_typesetter.value;
public static final long sel_unarchiveObjectWithData_ = Selector.sel_unarchiveObjectWithData_.value;
Expand Down Expand Up @@ -2975,11 +2966,6 @@ public static Selector getSelector (long value) {
* @param observer cast=(CFRunLoopObserverRef)
*/
public static final native void CFRunLoopObserverInvalidate(long observer);
/**
* @param allocator cast=(CFAllocatorRef)
* @param fsRef cast=(FSRef*)
*/
public static final native long CFURLCreateFromFSRef(long allocator, byte[] fsRef);
/**
* @param allocator cast=(CFAllocatorRef)
* @param originalString cast=(CFStringRef)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 itemis AG and others.
* Copyright (c) 2017, 2026 itemis AG and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -97,6 +97,8 @@ public enum Selector {
, sel_TIFFRepresentation("TIFFRepresentation")
, sel_URL("URL")
, sel_URLFromPasteboard_("URLFromPasteboard:")
, sel_URLForApplicationToOpenURL_("URLForApplicationToOpenURL:")
, sel_URLForApplicationToOpenContentType_("URLForApplicationToOpenContentType:")
, sel_URLWithString_("URLWithString:")
, sel_UTF8String("UTF8String")
, sel_abortEditing("abortEditing")
Expand Down Expand Up @@ -1304,6 +1306,7 @@ public enum Selector {
, sel_type("type")
, sel_type_conformsToType_("type:conformsToType:")
, sel_typeOfFile_error_("typeOfFile:error:")
, sel_typeWithFilenameExtension_("typeWithFilenameExtension:")
, sel_types("types")
, sel_typesetter("typesetter")
, sel_unarchiveObjectWithData_("unarchiveObjectWithData:")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -73,15 +73,10 @@ public static Program findProgram (String extension) {
}
NSString ext = NSString.stringWithCharacters(chars, chars.length);
if (ext != null) {
byte[] fsRef = new byte[80];
if (OS.LSGetApplicationForInfo(OS.kLSUnknownType, OS.kLSUnknownCreator, ext.id, OS.kLSRolesAll, fsRef, null) == OS.noErr) {
long url = OS.CFURLCreateFromFSRef(OS.kCFAllocatorDefault(), fsRef);
if (url != 0) {
NSString bundlePath = new NSURL(url).path();
NSBundle bundle = NSBundle.bundleWithPath(bundlePath);
if (bundle != null) program = getProgram(bundle);
OS.CFRelease(url);
}
NSURL appURL = findAppURLForExtension(ext);
if (appURL != null) {
NSBundle bundle = NSBundle.bundleWithPath(appURL.path());
if (bundle != null) program = getProgram(bundle);
}
}
return program;
Expand Down Expand Up @@ -153,6 +148,27 @@ public static Program findProgram (String extension) {
}
}

private static NSURL findAppURLForExtension(NSString ext) {
NSWorkspace workspace = NSWorkspace.sharedWorkspace();
// On macOS 12.0+, use the content type-based API which works reliably
// for all file types including third-party ones.
if (OS.VERSION >= OS.VERSION(12, 0, 0)) {
long UTTypeClass = OS.objc_getClass("UTType");
if (UTTypeClass != 0) {
long utType = OS.objc_msgSend(UTTypeClass, OS.sel_typeWithFilenameExtension_, ext.id);
if (utType != 0) {
NSURL appURL = workspace.urlForApplicationToOpenContentType(utType);
if (appURL != null) {
return appURL;
}
}
}
}
// Fallback: URL-based lookup (available since macOS 10.6, deprecated in macOS 12.0)
NSURL fileURL = NSURL.fileURLWithPath(NSString.stringWith("/tmp/dummy." + ext.getString()));
return workspace.urlForApplicationToOpenURL(fileURL);
}

static Program getProgram(NSBundle bundle) {
NSString CFBundleName = NSString.stringWith("CFBundleName");
NSString CFBundleDisplayName = NSString.stringWith("CFBundleDisplayName");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2025 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -90,6 +91,17 @@ public void test_findProgramLjava_lang_String() {
assertSWTProblem("Failed to throw ERROR_NULL_ARGUMENT", SWT.ERROR_NULL_ARGUMENT, e);
}

@Test
public void test_findProgramForTxt() {
// Applications for MIME types may not be registered in Linux test environments
assumeFalse(SwtTestUtil.isGTK, "Applications for MIME types may not be registered in Linux test environments");
// .txt files are always associated with a text editor on Windows and macOS
Program program = Program.findProgram(".txt");
assertNotNull(program, "Expected a program for .txt files");
assertNotNull(program.getName(), "Expected program to have a non-null name");
assertTrue(program.getName().length() > 0, "Expected program to have a non-empty name");
}

@Test
public void test_getExtensions() {
String[] extensions = Program.getExtensions();
Expand Down
Loading