diff options
author | Thomas Wolf | 2017-10-16 20:59:37 +0000 |
---|---|---|
committer | Thomas Wolf | 2017-10-19 19:06:24 +0000 |
commit | 20e65d22fa25e6a0756357703b5f162506560548 (patch) | |
tree | 15ddfb7de0f0f95a748558f1babfda09eee73e01 | |
parent | 5bd784a872a64e6004ae80ca5aa17696e527b271 (diff) | |
download | egit-20e65d22fa25e6a0756357703b5f162506560548.tar.gz egit-20e65d22fa25e6a0756357703b5f162506560548.tar.xz egit-20e65d22fa25e6a0756357703b5f162506560548.zip |
Use newer trash icon on Eclipse Photon or newer
Copy the SVG and PNGs from the eclipse.platform.images git repository
and rename them from "trash.*" to "trash_flat.*".
Add a version check for the first version of the "org.eclipse.ui"
bundle that uses the new icon to decide which one to use in EGit.
EGit UI has a hard (non-optional) dependency on org.eclipse.ui
anyway, so this version check is acceptable.
Since we have a reference to the "trash can" icon in plugin.xml,
add a property tester for this bundle version check and use it in
plugin.xml to display one or the other icon in the context menu
entry for the "Garbage Collect" command in the context menu of the
repository view.
This ensures that EGit uses a trash icon visually identical to the
one used by the platform on which EGit runs, and thus the user is
presented with a consistent UI.
Bug: 525600
Change-Id: I98c869b0b84677bc67575edd7358a0a17954727c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | icons/org.eclipse.egit.ui/icons/elcl16/trash_flat.svg | 203 | ||||
-rw-r--r-- | org.eclipse.egit.ui/icons/elcl16/trash_flat.png | bin | 0 -> 175 bytes | |||
-rw-r--r-- | org.eclipse.egit.ui/icons/elcl16/trash_flat@2x.png | bin | 0 -> 271 bytes | |||
-rw-r--r-- | org.eclipse.egit.ui/plugin.xml | 31 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java | 10 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/expressions/BundlePropertyTester.java | 68 |
6 files changed, 310 insertions, 2 deletions
diff --git a/icons/org.eclipse.egit.ui/icons/elcl16/trash_flat.svg b/icons/org.eclipse.egit.ui/icons/elcl16/trash_flat.svg new file mode 100644 index 0000000000..b44f6f0a99 --- /dev/null +++ b/icons/org.eclipse.egit.ui/icons/elcl16/trash_flat.svg @@ -0,0 +1,203 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- From eclipse.platform.images; org.eclipse.ui/icons/full/elcl16/trash.svg --> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + height="16" + viewBox="0 0 16 16" + width="16" + id="svg2" + version="1.1" + inkscape:version="0.91 r13725" + sodipodi:docname="trash_flat.svg" + style="fill:#000000"> + <metadata + id="metadata12"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs10"> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient6168" + id="radialGradient6174" + cx="10.152482" + cy="1045.8538" + fx="10.152482" + fy="1045.8538" + r="5.0078058" + gradientTransform="matrix(-0.04400863,-1.6558063,1.1452248,-0.03043823,-1162.7367,54.412022)" + gradientUnits="userSpaceOnUse" /> + <linearGradient + id="linearGradient6168"> + <stop + style="stop-color:#fff891;stop-opacity:1;" + offset="0" + id="stop6170" /> + <stop + style="stop-color:#4090ce;stop-opacity:1;" + offset="1" + id="stop6172" /> + </linearGradient> + <linearGradient + gradientTransform="translate(26.490719,-1036.4924)" + inkscape:collect="always" + xlink:href="#linearGradient6176" + id="linearGradient6182" + x1="3.0355341" + y1="1045.7552" + x2="7.8229179" + y2="1037.4633" + gradientUnits="userSpaceOnUse" /> + <linearGradient + id="linearGradient6176"> + <stop + style="stop-color:#166b9b;stop-opacity:1;" + offset="0" + id="stop6178" /> + <stop + style="stop-color:#169b6e;stop-opacity:1;" + offset="1" + id="stop6180" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient6176" + id="linearGradient6198" + gradientUnits="userSpaceOnUse" + x1="19.58931" + y1="1048.307" + x2="19.58931" + y2="1039.0699" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient6176" + id="linearGradient6200" + gradientUnits="userSpaceOnUse" + x1="22.736761" + y1="1046.0887" + x2="22.736761" + y2="1038.9832" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient6168" + id="radialGradient6343" + cx="8.0400419" + cy="1038.7124" + fx="8.0400419" + fy="1038.7124" + r="6.0875001" + gradientTransform="matrix(0.96462225,1.3001557e-8,0,0.36634733,26.778462,-378.30949)" + gradientUnits="userSpaceOnUse" /> + </defs> + <sodipodi:namedview + pagecolor="#515658" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1440" + inkscape:window-height="852" + id="namedview8" + showgrid="true" + inkscape:snap-bbox="true" + inkscape:bbox-nodes="true" + inkscape:zoom="23.147693" + inkscape:cx="12.67061" + inkscape:cy="6.3370634" + inkscape:window-x="0" + inkscape:window-y="0" + inkscape:window-maximized="1" + inkscape:current-layer="layer2"> + <inkscape:grid + type="xygrid" + id="grid4140" /> + </sodipodi:namedview> + <g + inkscape:groupmode="layer" + id="layer1" + inkscape:label="old" + style="display:inline" + sodipodi:insensitive="true"> + <rect + style="display:inline;fill:#166b9b;fill-opacity:1;stroke:none" + id="rect6283" + width="3.8750002" + height="3.8750002" + x="32.596558" + y="-0.13019475" /> + <path + id="path5339-5" + style="display:inline;fill:url(#radialGradient6174);fill-opacity:1;stroke:url(#linearGradient6182);stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 30.026253,2.9209222 c 0,0 0,5.7561004 0,9.5900998 0,1.189 1.635185,1.9888 2.96101,1.9888 1.757376,4e-4 2.13047,0 3.093592,0 1.325826,0 2.96101,-0.7998 2.96101,-1.9887 0,-3.8339994 0,-9.5901998 0,-9.5901998" + inkscape:connector-curvature="0" + sodipodi:nodetypes="csccsc" /> + <g + style="display:inline;fill:#000000" + id="g6194" + transform="translate(13.487183,-1036.4924)"> + <path + inkscape:connector-curvature="0" + id="path5361" + d="m 19.531251,1051.0185 0,-11.1683" + style="fill:none;stroke:url(#linearGradient6198);stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + sodipodi:nodetypes="cc" /> + <path + inkscape:connector-curvature="0" + id="path5361-0" + d="m 22.562501,1051.0185 0,-11.1683" + style="display:inline;fill:none;stroke:url(#linearGradient6200);stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + sodipodi:nodetypes="cc" /> + </g> + <path + style="display:inline;fill:url(#radialGradient6343);fill-opacity:1;stroke:#166b9b;stroke-width:0.80000001;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 30.034059,1.2982222 c -0.657875,0 -1.1875,0.5296 -1.1875,1.1875 l 0,0.6562 11.375,0 0,-0.6562 c 0,-0.6579 -0.529625,-1.1875 -1.1875,-1.1875 l -9,0 z" + id="rect6322" + inkscape:connector-curvature="0" /> + </g> + <g + inkscape:groupmode="layer" + id="layer2" + inkscape:label="new" + style="display:inline"> + <path + d="m 3.5,13.5 c 0,0.864286 1.4250001,2 2.25,2 l 4.5,0 c 0.824999,0 2.25,-1.135714 2.25,-2 l 0,-9 -9,0 z" + id="path4144" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ssssccs" + style="fill:#b8d0ea;fill-opacity:1;stroke:#6883a7;stroke-width:1;stroke-opacity:1" /> + <path + d="M 14,2 11,2 10.4,1 5.6,1 5,2 2,2 2,2.9996667 14,3 Z" + id="path4" + inkscape:connector-curvature="0" + sodipodi:nodetypes="ccccccccc" + style="fill:#6883a7;fill-opacity:1" /> + <path + style="fill:none;fill-rule:evenodd;stroke:#6883a7;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 6.5,4 0,11" + id="path5058" + inkscape:connector-curvature="0" /> + <path + style="display:inline;fill:none;fill-rule:evenodd;stroke:#6883a7;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m 9.5,4 0,11" + id="path5058-1" + inkscape:connector-curvature="0" /> + </g> +</svg> diff --git a/org.eclipse.egit.ui/icons/elcl16/trash_flat.png b/org.eclipse.egit.ui/icons/elcl16/trash_flat.png Binary files differnew file mode 100644 index 0000000000..53b1a9954b --- /dev/null +++ b/org.eclipse.egit.ui/icons/elcl16/trash_flat.png diff --git a/org.eclipse.egit.ui/icons/elcl16/trash_flat@2x.png b/org.eclipse.egit.ui/icons/elcl16/trash_flat@2x.png Binary files differnew file mode 100644 index 0000000000..29f293424b --- /dev/null +++ b/org.eclipse.egit.ui/icons/elcl16/trash_flat@2x.png diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index cab0ca8a0d..27ed6e9280 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -4611,13 +4611,37 @@ </menuContribution> <menuContribution locationURI="popup:org.eclipse.egit.ui.RepositoriesView?after=repo-4"> + <!-- Use newer flat trash icon when running on Eclipse Photon or newer --> <command commandId="org.eclipse.egit.ui.team.GarbageCollect" label="%GarbageCollectCommand.label" + icon="icons/elcl16/trash_flat.png" style="push"> <visibleWhen checkEnabled="false"> <and> + <test property="org.eclipse.egit.ui.BundleProperty.isBundleInstalled" args="org.eclipse.ui,3.109.100" /> + <count + value="+"> + </count> + <iterate> + <instanceof + value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode"> + </instanceof> + </iterate> + </and> + </visibleWhen> + </command> + <!-- Use older trash icon when running on Eclipse Oxygen or older --> + <command + commandId="org.eclipse.egit.ui.team.GarbageCollect" + label="%GarbageCollectCommand.label" + icon="icons/elcl16/trash.png" + style="push"> + <visibleWhen + checkEnabled="false"> + <and> + <test property="org.eclipse.egit.ui.BundleProperty.isBundleInstalled" args="org.eclipse.ui,3.109.100" value="false" /> <count value="+"> </count> @@ -6284,6 +6308,13 @@ properties="isSingleFileHistory" type="org.eclipse.team.ui.history.IHistoryView"> </propertyTester> + <propertyTester + class="org.eclipse.egit.ui.internal.expressions.BundlePropertyTester" + id="org.eclipse.egit.ui.BundlePropertyTester" + namespace="org.eclipse.egit.ui.BundleProperty" + properties="isBundleInstalled" + type="java.util.Collection"> + </propertyTester> </extension> <extension point="org.eclipse.ui.navigator.linkHelper"> diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java index 4b743dca56..eef5f6786f 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIIcons.java @@ -19,11 +19,13 @@ package org.eclipse.egit.ui.internal; import java.net.MalformedURLException; import java.net.URL; +import org.eclipse.core.runtime.Platform; import org.eclipse.egit.ui.Activator; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.ResourceManager; import org.eclipse.jface.viewers.IDecoration; import org.eclipse.swt.graphics.Image; +import org.osgi.framework.Version; /** * Icons for the the Eclipse plugin. Mostly decorations. @@ -379,7 +381,10 @@ public class UIIcons { ELCL16_DELETE = map("elcl16/delete.png"); //$NON-NLS-1$ ELCL16_ADD = map("elcl16/add.png"); //$NON-NLS-1$ ELCL16_ADD_ALL = map("elcl16/add_all.png"); //$NON-NLS-1$ - ELCL16_TRASH = map("elcl16/trash.png"); //$NON-NLS-1$ + // For Photon and newer, use the new "flat look" trash icon + ELCL16_TRASH = map(Platform.getBundle("org.eclipse.ui").getVersion() //$NON-NLS-1$ + .compareTo(Version.valueOf("3.109.100")) >= 0 ? //$NON-NLS-1$ + "elcl16/trash_flat.png" : "elcl16/trash.png"); //$NON-NLS-1$ //$NON-NLS-2$ ELCL16_CLEAR = map("elcl16/clear_co.png"); //$NON-NLS-1$ ELCL16_REFRESH = map("elcl16/refresh.png"); //$NON-NLS-1$ ELCL16_SYNCED = map("elcl16/synced.png"); //$NON-NLS-1$ @@ -460,12 +465,13 @@ public class UIIcons { } private static ImageDescriptor map(final String icon) { - if (base != null) + if (base != null) { try { return ImageDescriptor.createFromURL(new URL(base, icon)); } catch (MalformedURLException mux) { Activator.logError(UIText.UIIcons_errorLoadingPluginImage, mux); } + } return ImageDescriptor.getMissingImageDescriptor(); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/expressions/BundlePropertyTester.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/expressions/BundlePropertyTester.java new file mode 100644 index 0000000000..a1e30e9dd4 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/expressions/BundlePropertyTester.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.ui.internal.expressions; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.osgi.framework.Version; + +/** + * A {@link PropertyTester} to test some properties related to bundles. Offers + * the following property tests: + * <dl> + * <dt>isBundleInstalled + * args="bundleName[,minimumVersionInclusive[,maximumVersionExclusive]]"</dt> + * <dd>Like the org.eclipse.core.runtime.isBundleInstalled property test, but + * additionally allows to check for a version range. Specify 0.0.0 for the + * minimum version if you only want to test for < maximumVersionExclusive, and + * omit the maximum version if you only want to test >= + * minimumVersionInclusive.</dd> + * </dl> + */ +public class BundlePropertyTester extends AbstractPropertyTester { + + @Override + public boolean test(Object receiver, String property, Object[] args, + Object expectedValue) { + if ("isBundleInstalled".equals(property)) { //$NON-NLS-1$ + return computeResult(expectedValue, versionCheck(args)); + } + return false; + } + + private boolean versionCheck(Object[] args) { + if (args != null && args.length > 0 && args[0] instanceof String) { + Bundle bundle = Platform.getBundle((String) args[0]); + if (bundle == null) { + return false; + } + Version min = args.length > 1 ? toVersion(args[1]) : null; + Version max = args.length > 2 ? toVersion(args[2]) : null; + boolean inRange = true; + if (min != null) { + inRange = bundle.getVersion().compareTo(min) >= 0; + } + if (inRange && max != null) { + inRange = bundle.getVersion().compareTo(max) < 0; + } + return inRange; + } + return false; + } + + private Version toVersion(Object arg) { + try { + return Version.valueOf(arg.toString()); + } catch (IllegalArgumentException e) { + return null; + } + } + +} |