-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Product file editor: Support for <bundleUrlTypes> on macOS
Support editing of <launcher><macosx><bundleUrlTypes> entries in the product editor. These are translated to CFBundleURLTypes entries in the Info.plist dictionary of the macOS app bundle. Contributes to eclipse-platform/eclipse.platform.ui#1901.
- Loading branch information
1 parent
edf6f1b
commit 9b87c23
Showing
9 changed files
with
489 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2005, 2016 IBM Corporation and others. | ||
* Copyright (c) 2005, 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -11,26 +11,29 @@ | |
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
* Martin Karpisek <[email protected]> - Bug 438509 | ||
* SAP SE - support macOS bundle URL types | ||
*******************************************************************************/ | ||
package org.eclipse.pde.internal.core.iproduct; | ||
|
||
import java.util.List; | ||
|
||
public interface ILauncherInfo extends IProductObject { | ||
|
||
public static final String LINUX_ICON = "linuxIcon"; //$NON-NLS-1$ | ||
String LINUX_ICON = "linuxIcon"; //$NON-NLS-1$ | ||
|
||
public static final String MACOSX_ICON = "macosxIcon"; //$NON-NLS-1$ | ||
String MACOSX_ICON = "macosxIcon"; //$NON-NLS-1$ | ||
|
||
public static final String WIN32_16_LOW = "winSmallLow"; //$NON-NLS-1$ | ||
public static final String WIN32_16_HIGH = "winSmallHigh"; //$NON-NLS-1$ | ||
public static final String WIN32_32_LOW = "winMediumLow"; //$NON-NLS-1$ | ||
public static final String WIN32_32_HIGH = "winMediumHigh"; //$NON-NLS-1$ | ||
public static final String WIN32_48_LOW = "winLargeLow"; //$NON-NLS-1$ | ||
public static final String WIN32_48_HIGH = "winLargeHigh"; //$NON-NLS-1$ | ||
public static final String WIN32_256_HIGH = "winExtraLargeHigh"; //$NON-NLS-1$ | ||
String WIN32_16_LOW = "winSmallLow"; //$NON-NLS-1$ | ||
String WIN32_16_HIGH = "winSmallHigh"; //$NON-NLS-1$ | ||
String WIN32_32_LOW = "winMediumLow"; //$NON-NLS-1$ | ||
String WIN32_32_HIGH = "winMediumHigh"; //$NON-NLS-1$ | ||
String WIN32_48_LOW = "winLargeLow"; //$NON-NLS-1$ | ||
String WIN32_48_HIGH = "winLargeHigh"; //$NON-NLS-1$ | ||
String WIN32_256_HIGH = "winExtraLargeHigh"; //$NON-NLS-1$ | ||
|
||
public static final String P_USE_ICO = "useIco"; //$NON-NLS-1$ | ||
public static final String P_ICO_PATH = "icoFile"; //$NON-NLS-1$ | ||
public static final String P_LAUNCHER = "launcher"; //$NON-NLS-1$ | ||
String P_USE_ICO = "useIco"; //$NON-NLS-1$ | ||
String P_ICO_PATH = "icoFile"; //$NON-NLS-1$ | ||
String P_LAUNCHER = "launcher"; //$NON-NLS-1$ | ||
|
||
String getLauncherName(); | ||
|
||
|
@@ -43,4 +46,11 @@ public interface ILauncherInfo extends IProductObject { | |
boolean usesWinIcoFile(); | ||
|
||
void setUseWinIcoFile(boolean use); | ||
|
||
List<IMacBundleUrlType> getMacBundleUrlTypes(); | ||
|
||
void addMacBundleUrlTypes(List<IMacBundleUrlType> schemes); | ||
|
||
void removeMacBundleUrlTypes(List<IMacBundleUrlType> schemes); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/iproduct/IMacBundleUrlType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 SAP SE and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* SAP SE - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.pde.internal.core.iproduct; | ||
|
||
public interface IMacBundleUrlType extends IProductObject { | ||
|
||
String getScheme(); | ||
|
||
void setScheme(String scheme); | ||
|
||
String getName(); | ||
|
||
void setName(String name); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2005, 2016 IBM Corporation and others. | ||
* Copyright (c) 2005, 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -11,15 +11,22 @@ | |
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
* Martin Karpisek <[email protected]> - Bug 438509 | ||
* SAP SE - support macOS bundle URL types | ||
*******************************************************************************/ | ||
package org.eclipse.pde.internal.core.product; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.TreeMap; | ||
|
||
import org.eclipse.pde.core.IModelChangedEvent; | ||
import org.eclipse.pde.internal.core.iproduct.ILauncherInfo; | ||
import org.eclipse.pde.internal.core.iproduct.IMacBundleUrlType; | ||
import org.eclipse.pde.internal.core.iproduct.IProductModel; | ||
import org.eclipse.pde.internal.core.iproduct.IProductObject; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
|
@@ -30,6 +37,7 @@ public class LauncherInfo extends ProductObject implements ILauncherInfo { | |
private boolean fUseIcoFile; | ||
private final Map<String, String> fIcons = new HashMap<>(); | ||
private String fLauncherName; | ||
private final TreeMap<String, IMacBundleUrlType> fMacBundleUrlTypes = new TreeMap<>(); | ||
|
||
public LauncherInfo(IProductModel model) { | ||
super(model); | ||
|
@@ -131,6 +139,26 @@ private void parseWin(Element element) { | |
|
||
private void parseMac(Element element) { | ||
fIcons.put(MACOSX_ICON, element.getAttribute("icon")); //$NON-NLS-1$ | ||
NodeList children = element.getChildNodes(); | ||
for (int i = 0; i < children.getLength(); i++) { | ||
if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { | ||
Node child = children.item(i); | ||
String name = child.getNodeName(); | ||
if (name.equals("bundleUrlTypes")) { //$NON-NLS-1$ | ||
NodeList grandChildren = child.getChildNodes(); | ||
for (int j = 0; j < grandChildren.getLength(); j++) { | ||
Node grandChild = grandChildren.item(j); | ||
if (grandChild.getNodeType() == Node.ELEMENT_NODE) { | ||
if (grandChild.getNodeName().equals("bundleUrlType")) { //$NON-NLS-1$ | ||
IMacBundleUrlType bundleUrlType = getModel().getFactory().createMacBundleUrlType(); | ||
bundleUrlType.parse(grandChild); | ||
fMacBundleUrlTypes.put(bundleUrlType.getScheme(), bundleUrlType); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void parseLinux(Element element) { | ||
|
@@ -180,8 +208,22 @@ private void writeIcon(String indent, String iconId, PrintWriter writer) { | |
|
||
private void writeMac(String indent, PrintWriter writer) { | ||
String icon = fIcons.get(MACOSX_ICON); | ||
if (icon != null && icon.length() > 0) { | ||
writer.println(indent + "<macosx icon=\"" + getWritableString(icon) + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
if (icon != null && icon.length() > 0 || !fMacBundleUrlTypes.isEmpty()) { | ||
writer.print(indent + "<macosx"); //$NON-NLS-1$ | ||
if (icon != null && icon.length() > 0) { | ||
writer.print(" icon=\"" + getWritableString(icon) + "\""); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
if (fMacBundleUrlTypes.isEmpty()) { | ||
writer.println("/>"); //$NON-NLS-1$ | ||
} else { | ||
writer.println(">"); //$NON-NLS-1$ | ||
writer.println(indent + " <bundleUrlTypes>"); //$NON-NLS-1$ | ||
for (IMacBundleUrlType bundleUrlType : fMacBundleUrlTypes.values()) { | ||
bundleUrlType.write(indent + " ", writer); //$NON-NLS-1$ | ||
} | ||
writer.println(indent + " </bundleUrlTypes>"); //$NON-NLS-1$ | ||
writer.println(indent + "</macosx>"); //$NON-NLS-1$ | ||
} | ||
} | ||
} | ||
|
||
|
@@ -192,4 +234,38 @@ private void writeLinux(String indent, PrintWriter writer) { | |
} | ||
} | ||
|
||
@Override | ||
public List<IMacBundleUrlType> getMacBundleUrlTypes() { | ||
return List.copyOf(fMacBundleUrlTypes.values()); | ||
} | ||
|
||
@Override | ||
public void addMacBundleUrlTypes(List<IMacBundleUrlType> bundleUrlTypes) { | ||
IMacBundleUrlType[] addedUrlSchemes = bundleUrlTypes.stream().map(urlType -> { | ||
if (urlType != null) { | ||
String scheme = urlType.getScheme(); | ||
if (scheme != null && !fMacBundleUrlTypes.containsKey(scheme)) { | ||
urlType.setModel(getModel()); | ||
fMacBundleUrlTypes.put(scheme, urlType); | ||
return urlType; | ||
} | ||
} | ||
return null; | ||
}).filter(Objects::nonNull).toArray(IMacBundleUrlType[]::new); | ||
if (addedUrlSchemes.length > 0 && isEditable()) { | ||
fireStructureChanged(addedUrlSchemes, IModelChangedEvent.INSERT); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeMacBundleUrlTypes(List<IMacBundleUrlType> bundleUrlTypes) { | ||
IProductObject[] removedUrlSchemes = bundleUrlTypes.stream() // | ||
.map(IMacBundleUrlType::getScheme).map(fMacBundleUrlTypes::remove) // | ||
.filter(Objects::nonNull).toArray(IProductObject[]::new); | ||
|
||
if (removedUrlSchemes.length > 0 && isEditable()) { | ||
fireStructureChanged(removedUrlSchemes, IModelChangedEvent.REMOVE); | ||
} | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/product/MacBundleUrlType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 SAP SE and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* SAP SE - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.pde.internal.core.product; | ||
|
||
import java.io.PrintWriter; | ||
|
||
import org.eclipse.pde.internal.core.iproduct.IMacBundleUrlType; | ||
import org.eclipse.pde.internal.core.iproduct.IProductModel; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
|
||
public class MacBundleUrlType extends ProductObject implements IMacBundleUrlType { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private String fScheme; | ||
private String fName; | ||
|
||
public MacBundleUrlType(IProductModel model) { | ||
super(model); | ||
} | ||
|
||
@Override | ||
public void parse(Node node) { | ||
if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
Element element = (Element) node; | ||
fScheme = element.getAttribute("scheme"); //$NON-NLS-1$ | ||
fName = element.getAttribute("name"); //$NON-NLS-1$ | ||
} | ||
} | ||
|
||
@Override | ||
public void write(String indent, PrintWriter writer) { | ||
writer.println(indent + "<bundleUrlType scheme=\"" + fScheme + "\"" + " name=\"" + fName + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ | ||
} | ||
|
||
|
||
@Override | ||
public String getScheme() { | ||
return fScheme; | ||
} | ||
|
||
@Override | ||
public void setScheme(String scheme) { | ||
fScheme = scheme; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return fName; | ||
} | ||
|
||
@Override | ||
public void setName(String name) { | ||
fName = name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014, 2023 IBM Corporation and others. | ||
* Copyright (c) 2014, 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -17,6 +17,7 @@ | |
* Axel Richard (Obeo) - Bug 41353 - Launch configurations prototypes | ||
* Kit Lo (IBM) - Bug 244461 - Duplicating colon in error message | ||
* Alexander Fedorov <[email protected]> - Bug 547222 | ||
* SAP SE - support macOS bundle URL types | ||
*******************************************************************************/ | ||
package org.eclipse.pde.internal.ui; | ||
|
||
|
@@ -1176,6 +1177,18 @@ public class PDEUIMessages extends NLS { | |
public static String LauncherSection_256High; | ||
public static String LauncherSection_linuxLabel; | ||
public static String LauncherSection_macLabel; | ||
public static String LauncherSection_macBundleUrlTypes_DialogTitle; | ||
public static String LauncherSection_macBundleUrlTypes_Scheme; | ||
public static String LauncherSection_macBundleUrlTypes_Name; | ||
public static String LauncherSection_macBundleUrlTypes_ErrorNoScheme; | ||
public static String LauncherSection_macBundleUrlTypes_ErrorNoName; | ||
public static String LauncherSection_macBundleUrlTypes_ErrorSchemeExists; | ||
public static String LauncherSection_macBundleUrlTypes_Add; | ||
public static String LauncherSection_macBundleUrlTypes_Edit; | ||
public static String LauncherSection_macBundleUrlTypes_Remove; | ||
public static String LauncherSection_macBundleUrlTypes_LauncherSection_macBundleUrlTypesTitle; | ||
public static String LauncherSection_macBundleUrlTypes_SchemeColumn; | ||
public static String LauncherSection_macBundleUrlTypes_NameColumn; | ||
public static String OSGiBundlesTab_frameworkLabel; | ||
|
||
// Preferences #################################### | ||
|
Oops, something went wrong.