Skip to content

Commit

Permalink
#19 Use lists instead of sets for command palette and menu items
Browse files Browse the repository at this point in the history
This ensures that the order is stable and allows the server to control
the order of elements in the command palette on the client.

Resolves #19
  • Loading branch information
planger committed Dec 2, 2019
1 parent 3ec0494 commit e543eb0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,30 @@
******************************************************************************/
package org.eclipse.glsp.api.action.kind;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.glsp.api.action.Action;
import org.eclipse.glsp.api.types.LabeledAction;

public class SetContextActions extends ResponseAction {

private Set<LabeledAction> actions;
private List<LabeledAction> actions;
private Map<String, String> args;

public SetContextActions() {
super(Action.Kind.SET_CONTEXT_ACTIONS);
}

public SetContextActions(final Set<LabeledAction> actions, final Map<String, String> map) {
public SetContextActions(final List<LabeledAction> actions, final Map<String, String> map) {
this();
this.actions = actions;
this.args = map;
}

public Set<LabeledAction> getActions() { return actions; }
public List<LabeledAction> getActions() { return actions; }

public void setActions(final Set<LabeledAction> commandPaletteActions) { this.actions = commandPaletteActions; }
public void setActions(final List<LabeledAction> commandPaletteActions) { this.actions = commandPaletteActions; }

public Map<String, String> getArgs() { return args; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.eclipse.glsp.api.model.GraphicalModelState;
import org.eclipse.glsp.api.types.LabeledAction;
Expand All @@ -32,10 +31,10 @@ public interface CommandPaletteActionProvider {
String TEXT = "text";
String INDEX = "index";

Set<LabeledAction> getActions(GraphicalModelState modelState, List<String> selectedElementIds,
List<LabeledAction> getActions(GraphicalModelState modelState, List<String> selectedElementIds,
Optional<GPoint> lastMousePosition, Map<String, String> args);

default Set<LabeledAction> getActions(final GraphicalModelState modelState, final List<String> selectedElementIds,
default List<LabeledAction> getActions(final GraphicalModelState modelState, final List<String> selectedElementIds,
final GPoint lastMousePosition, final Map<String, String> args) {
return getActions(modelState, selectedElementIds, Optional.ofNullable(lastMousePosition), args);
}
Expand All @@ -50,9 +49,9 @@ default int getIndex(final Map<String, String> args) {

class NullImpl implements CommandPaletteActionProvider {
@Override
public Set<LabeledAction> getActions(final GraphicalModelState modelState, final List<String> selectedElementIds,
public List<LabeledAction> getActions(final GraphicalModelState modelState, final List<String> selectedElementIds,
final Optional<GPoint> lastMousePosition, final Map<String, String> args) {
return Collections.emptySet();
return Collections.emptyList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.eclipse.glsp.api.model.GraphicalModelState;
import org.eclipse.glsp.api.types.MenuItem;
Expand All @@ -30,19 +29,19 @@ public interface ContextMenuItemProvider {

String KEY = "context-menu";

Set<MenuItem> getItems(GraphicalModelState modelState, List<String> selectedElementIds,
List<MenuItem> getItems(GraphicalModelState modelState, List<String> selectedElementIds,
Optional<GPoint> lastMousePosition, Map<String, String> args);

default Set<MenuItem> getItems(final GraphicalModelState modelState, final List<String> selectedElementIds,
default List<MenuItem> getItems(final GraphicalModelState modelState, final List<String> selectedElementIds,
final GPoint lastMousePosition, final Map<String, String> args) {
return getItems(modelState, selectedElementIds, Optional.ofNullable(lastMousePosition), args);
}

class NullImpl implements ContextMenuItemProvider {
@Override
public Set<MenuItem> getItems(final GraphicalModelState modelState, final List<String> selectedElementIds,
public List<MenuItem> getItems(final GraphicalModelState modelState, final List<String> selectedElementIds,
final Optional<GPoint> lastMousePosition, final Map<String, String> args) {
return Collections.emptySet();
return Collections.emptyList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
********************************************************************************/
package org.eclipse.glsp.server.actionhandler;

import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import org.eclipse.glsp.api.action.Action;
import org.eclipse.glsp.api.action.kind.RequestContextActions;
Expand Down Expand Up @@ -52,7 +51,7 @@ public Optional<Action> execute(final Action action, final GraphicalModelState m
RequestContextActions requestContextAction = (RequestContextActions) action;
List<String> selectedElementIds = requestContextAction.getSelectedElementIds();
Map<String, String> args = requestContextAction.getArgs();
Set<LabeledAction> items = new HashSet<>();
List<LabeledAction> items = new ArrayList<>();
if (equalsUiControl(args, CommandPaletteActionProvider.KEY)) {
items.addAll(commandPaletteActionProvider.getActions(modelState, selectedElementIds,
requestContextAction.getLastMousePosition(), args));
Expand Down

0 comments on commit e543eb0

Please sign in to comment.