Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Mar 16, 2024
1 parent e412d9b commit 5d85564
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 126 deletions.
3 changes: 0 additions & 3 deletions core/src/main/java/hudson/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,6 @@ public List<Action> getTransientActions() {
// System.out.println("Ignoring " + ignored);
}

System.out.println(collect);
System.out.println("----");

return collect;
}
}
43 changes: 42 additions & 1 deletion core/src/main/java/jenkins/model/ModelObjectWithContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.util.List;
import javax.servlet.ServletException;
import jenkins.management.Badge;
import jenkins.model.menu.Group;
import jenkins.model.menu.Semantic;
import jenkins.model.menu.event.DropdownAction;
import jenkins.model.menu.event.LinkAction;
import org.apache.commons.jelly.JellyException;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
Expand Down Expand Up @@ -83,6 +87,20 @@ public ContextMenu add(Action action) {
MenuItem menuItem = new MenuItem()
.withDisplayName(action.getDisplayName());

menuItem.badge = action.getBadge();
menuItem.semantic = action.getSemantic();
menuItem.group = action.getGroup();
menuItem.action = action.getAction();

if (action.getAction().getClass() == LinkAction.class) {
menuItem.url = ((LinkAction)action.getAction()).getUrl();
}

if (action.getAction().getClass() == DropdownAction.class) {
ContextMenu cm = new ContextMenu();
menuItem.subMenu = cm.addAll(((DropdownAction)action.getAction()).getActions());
}

if (action.getIconFileName() != null && action.getIconFileName().startsWith("symbol-")) {
menuItem.icon = action.getIconFileName();
menuItem.iconXml = Symbol.get(new SymbolRequest.Builder()
Expand Down Expand Up @@ -230,9 +248,17 @@ class MenuItem {
@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", justification = "read by Stapler")
public boolean requiresConfirmation;


private Badge badge;

// @Exported(inline = true)
private Group group;

// @Exported(inline = true)
private jenkins.model.menu.event.Action action;

// @Exported(inline = true)
private Semantic semantic;

private String message;

/**
Expand Down Expand Up @@ -264,6 +290,21 @@ public Badge getBadge() {
return badge;
}

@Exported(inline = true)
public Group getGroup() {
return group;
}

@Exported(inline = true)
public jenkins.model.menu.event.Action getAction() {
return action;
}

@Exported
public Semantic getSemantic() {
return semantic;
}

@Exported
public String getMessage() {
return message;
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/model/menu/Group.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package jenkins.model.menu;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public class Group {

private final int order;
Expand Down Expand Up @@ -28,6 +32,7 @@ public static Group of(int customOrder) {
return new Group(customOrder);
}

@Exported
public int getOrder() {
return order;
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/jenkins/model/menu/event/Action.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package jenkins.model.menu.event;

import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public interface Action {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package jenkins.model.menu.event;

import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public final class DoNothingAction implements Action {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public final class DropdownAction implements Action {

private final List<hudson.model.Action> actions;
Expand All @@ -16,6 +19,7 @@ public static DropdownAction of(hudson.model.Action... actions) {
return new DropdownAction(Arrays.stream(actions).collect(Collectors.toList()));
}

@Exported(inline = true)
public List<hudson.model.Action> getActions() {
return actions;
}
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/model/menu/event/LinkAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package jenkins.model.menu.event;

import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

@ExportedBean
public final class LinkAction implements Action {

private final String url;
Expand All @@ -12,6 +16,7 @@ public static LinkAction of(String url) {
return new LinkAction(url);
}

@Exported
public String getUrl() {
return url;
}
Expand Down
48 changes: 48 additions & 0 deletions core/src/main/java/jenkins/model/view/NewProjectActionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package jenkins.model.view;

import hudson.Extension;
import hudson.model.Action;
import hudson.model.View;
import java.util.Collection;
import java.util.Set;
import jenkins.model.TransientActionFactory;
import jenkins.model.menu.Group;
import jenkins.model.menu.event.LinkAction;

@Extension
public class NewProjectActionFactory extends TransientActionFactory<View> {

@Override
public Class<View> type() {
return View.class;
}

@Override
public Collection<? extends Action> createFor(View target) {
if (!target.hasPermission(View.CREATE)) {
return Set.of();
}

return Set.of(new Action() {
@Override
public String getDisplayName() {
return "New " + target.getNewPronoun();
}

@Override
public String getIconFileName() {
return "symbol-add";
}

@Override
public Group getGroup() {
return Group.FIRST_IN_APP_BAR;
}

@Override
public jenkins.model.menu.event.Action getAction() {
return LinkAction.of("newJob");
}
});
}
}
70 changes: 0 additions & 70 deletions core/src/main/java/jenkins/model/view/NewProjectMenuItem.java

This file was deleted.

Loading

0 comments on commit 5d85564

Please sign in to comment.