Skip to content
Permalink
Browse files

Merge pull request #71 from jenkinsci/use-iconset

[JENKINS-38960 Follow-up] Switch to IconSet
  • Loading branch information...
stephenc committed Oct 17, 2016
2 parents ac54766 + 5dfa20e commit fc2cff09dfc0282a9d83fc5d0f68d1ba872cd88f

Large diffs are not rendered by default.

@@ -0,0 +1,19 @@
#!/bin/sh -e

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
for src in "$dir"/*.svg
do
echo "Processing $(basename "$src")..."
file=$(basename "$src" | sed -e s/.svg/.png/ )
for sz in 16 24 32 48
do
mkdir -p "${dir}/../../src/main/webapp/images/${sz}x${sz}"
dst="${dir}/../../src/main/webapp/images/${sz}x${sz}/${file}"
if [ ! -e "$dst" -o "$src" -nt "$dst" ]
then
echo -n " generating ${sz}x${sz}..."
mkdir "${dir}/../../src/main/webapp/images/${sz}x${sz}" > /dev/null 2>&1 || true
inkscape -z -C -w ${sz} -h ${sz} -e "$dst" "$src" 2>&1 | grep "Bitmap saved as"
fi
done
done
@@ -42,6 +42,9 @@
import hudson.util.DescribableList;
import hudson.views.ListViewColumn;
import hudson.views.ViewJobFilter;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

@@ -337,7 +340,7 @@ public DescriptorImpl getDescriptor() {
}

@Extension
public static class DescriptorImpl extends AbstractFolderDescriptor {
public static class DescriptorImpl extends AbstractFolderDescriptor implements IconSpec {

/**
* Needed if it wants Folders are categorized in Jenkins 2.x.
@@ -361,11 +364,27 @@ public String getIconFilePathPattern() {
return "plugin/cloudbees-folder/images/:size/folder.png";
}

@Override
public String getIconClassName() {
return "icon-folder";
}

@Override
public TopLevelItem newInstance(ItemGroup parent, String name) {
return new Folder(parent, name);
}

static {
IconSet.icons.addIcon(new Icon("icon-item-move-folder icon-sm", "plugin/cloudbees-folder/images/16x16/move.png", Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(new Icon("icon-item-move-folder icon-md", "plugin/cloudbees-folder/images/24x24/move.png", Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(new Icon("icon-item-move-folder icon-lg", "plugin/cloudbees-folder/images/32x32/move.png", Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(new Icon("icon-item-move-folder icon-xlg", "plugin/cloudbees-folder/images/48x48/move.png", Icon.ICON_XLARGE_STYLE));
// fix the IconSet defaults because some of them are .gif files and icon-folder should really be here and not in core
IconSet.icons.addIcon(new Icon("icon-folder icon-sm", "plugin/cloudbees-folder/images/16x16/folder.png", Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(new Icon("icon-folder icon-md", "plugin/cloudbees-folder/images/24x24/folder.png", Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(new Icon("icon-folder icon-lg", "plugin/cloudbees-folder/images/32x32/folder.png", Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(new Icon("icon-folder icon-xlg", "plugin/cloudbees-folder/images/48x48/folder.png", Icon.ICON_XLARGE_STYLE));
}
}

private class MixInImpl extends ItemGroupMixIn {
@@ -29,6 +29,11 @@
import hudson.model.Describable;
import hudson.model.StatusIcon;
import jenkins.model.Jenkins;
import org.apache.commons.jelly.JellyContext;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.Stapler;

/**
* Renders {@link StatusIcon} for a folder.
@@ -37,7 +42,8 @@
* Possible subtypes can range from dumb icons that always render the same thing to smarter icons
* that change its icon based on the properties/contents of the folder.
*/
public abstract class FolderIcon extends AbstractStatusIcon implements Describable<FolderIcon>, ExtensionPoint {
public abstract class FolderIcon extends AbstractStatusIcon implements Describable<FolderIcon>, ExtensionPoint,
IconSpec {
/**
* Called by {@link AbstractFolder} to set the owner that this icon is used for.
* <p>
@@ -50,6 +56,33 @@ protected void setOwner(AbstractFolder<?> folder) {
}
}

@Override
public String getIconClassName() {
return null;
}

protected String iconClassNameImageOf(String size) {
String spec = null;
if ("16x16".equals(size)) {
spec = "icon-sm";
} else if ("24x24".equals(size)) {
spec = "icon-md";
} else if ("32x32".equals(size)) {
spec = "icon-lg";
} else if ("48x48".equals(size)) {
spec = "icon-xlg";
}
if (spec != null) {
Icon icon = IconSet.icons.getIconByClassSpec("icon-folder " + spec);
if (icon != null) {
JellyContext ctx = new JellyContext();
ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
return icon.getQualifiedUrl(ctx);
}
}
return null;
}

/** @deprecated */
protected void setFolder(Folder folder) {}

@@ -28,6 +28,10 @@
import com.cloudbees.hudson.plugins.folder.FolderIconDescriptor;
import hudson.Extension;
import hudson.model.Hudson;
import jenkins.model.Jenkins;
import org.apache.commons.jelly.JellyContext;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;

@@ -40,7 +44,11 @@ public StockFolderIcon() {
}

public String getImageOf(String size) {
return Stapler.getCurrentRequest().getContextPath()+ Hudson.RESOURCE_PATH+"/images/"+size+"/folder.png";
String image = iconClassNameImageOf(size);
return image != null
? image
: (Stapler.getCurrentRequest().getContextPath() + Hudson.RESOURCE_PATH
+ "/plugin/cloudbees-folder/images/"+size+"/folder.png");
}

public String getDescription() {
@@ -33,6 +33,7 @@
import hudson.security.Permission;
import hudson.security.PermissionScope;
import jenkins.model.TransientActionFactory;
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerFallback;
@@ -46,7 +47,7 @@
* Does the actual work of relocating an item.
*/
@Restricted(NoExternalUse.class)
public class RelocationAction implements Action, StaplerFallback {
public class RelocationAction implements Action, StaplerFallback, IconSpec {

/**
* The permission required to move an item.
@@ -90,6 +91,14 @@ public String getIconFileName() {
return !item.hasPermission(RELOCATE) || ui == null || !ui.isAvailable(item) ? null : ui.getIconFileName();
}

/**
* {@inheritDoc}
*/
@Override
public String getIconClassName() {
return !item.hasPermission(RELOCATE) || ui == null || !ui.isAvailable(item) ? null : ui.getIconClassName();
}

/**
* {@inheritDoc}
*/
@@ -30,17 +30,17 @@
import hudson.ExtensionPoint;
import hudson.model.Action;
import hudson.model.Item;
import jenkins.model.Jenkins;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.jenkins.ui.icon.IconSpec;

/**
* Extension point to provide a plugable UI for moving {@link Item} instances.
*
* @since 4.9
*/
public abstract class RelocationUI implements ExtensionPoint {
public abstract class RelocationUI implements ExtensionPoint, IconSpec {

/**
* The {@link Action#getDisplayName()} to present for this UI.
@@ -75,6 +75,14 @@ public String getIconFileName() {
return "/plugin/cloudbees-folder/images/24x24/move.png";
}

/**
* {@inheritDoc}
*/
@Override
public String getIconClassName() {
return "icon-item-move-folder";
}

/**
* Checks if the relocation operation is currently available for the specific item
* (as {@link Jenkins#getAuthentication()} if the user is a factor). You can assume that the current user
@@ -1,7 +1,7 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<h1><img src="${resURL}/plugin/cloudbees-folder/images/48x48/move.png" alt=""/>${%Move}</h1>
<h1><l:icon class="icon-item-move-folder icon-xlg"/>${%Move}</h1>
<form method="post" action="move">
${%blurb(item.pronoun, item.displayName)}
<select name="destination" class="select setting-input">
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit fc2cff0

Please sign in to comment.
You can’t perform that action at this time.