Skip to content

Commit 5616e40

Browse files
committed
Fixes a regression caused by f107cdd: Move keys stopped working.
1 parent 8243743 commit 5616e40

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

Diff for: src/net/sf/freecol/client/gui/Canvas.java

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import net.sf.freecol.client.ClientOptions;
6262
import net.sf.freecol.client.FreeColClient;
6363
import net.sf.freecol.client.gui.SwingGUI.PopupPosition;
64+
import net.sf.freecol.client.gui.action.FreeColAction;
6465
import net.sf.freecol.client.gui.dialog.FreeColDialog;
6566
import net.sf.freecol.client.gui.mapviewer.CanvasMapViewer;
6667
import net.sf.freecol.client.gui.mapviewer.MapViewer;
@@ -81,6 +82,7 @@
8182
import net.sf.freecol.common.i18n.Messages;
8283
import net.sf.freecol.common.model.Specification;
8384
import net.sf.freecol.common.option.IntegerOption;
85+
import net.sf.freecol.common.option.Option;
8486
import net.sf.freecol.common.option.OptionGroup;
8587
import net.sf.freecol.common.resources.Video;
8688

@@ -231,6 +233,15 @@ public void componentHidden(ComponentEvent e) {
231233
setLayout(null);
232234
setFocusable(true);
233235
setFocusTraversalKeysEnabled(false);
236+
// Create key bindings for all actions
237+
for (FreeColAction action : freeColClient.getActionManager().getFreeColActions()) {
238+
if (!action.isCanvasKeyBinding()) {
239+
continue;
240+
}
241+
getInputMap().put(action.getAccelerator(), action.getId());
242+
getActionMap().put(action.getId(), action);
243+
}
244+
234245

235246
this.parentFrame.setVisible(true);
236247

Diff for: src/net/sf/freecol/client/gui/action/ActionManager.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package net.sf.freecol.client.gui.action;
2121

2222
import java.util.logging.Logger;
23-
23+
import java.util.stream.Collectors;
2424
import java.util.ArrayList;
2525
import java.util.List;
2626

@@ -212,6 +212,17 @@ public FreeColAction getFreeColAction(String id) {
212212
? getOption(id, FreeColAction.class)
213213
: null;
214214
}
215+
216+
/***
217+
* Gets all registered {@code FreeColAction}s.
218+
* @return The list of all actions.
219+
*/
220+
public List<FreeColAction> getFreeColActions() {
221+
return getOptions().stream()
222+
.filter(o -> o instanceof FreeColAction)
223+
.map(o -> (FreeColAction) o)
224+
.collect(Collectors.toList());
225+
}
215226

216227
/**
217228
* Updates every {@code FreeColAction} this object keeps.

Diff for: src/net/sf/freecol/client/gui/action/FreeColAction.java

+19
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public void menuKeyTyped(MenuKeyEvent e) {
118118

119119
private int orderButtonImageCount = 0;
120120
private List<String> imageIconKeys = new ArrayList<>();
121+
private boolean canvasKeyBinding = false;
121122

122123
/**
123124
* Creates a new {@code FreeColAction}.
@@ -416,6 +417,24 @@ public String getEnabledBy() {
416417
/* FreeColAction cannot be enabled/disabled by other options. */
417418
return null;
418419
}
420+
421+
/**
422+
* Checks if this action should have its accelerator key added to the {@code Canvas}.
423+
* @return {@code true} if the accelerator key should be added to the {@code Canvas}. This
424+
* is typically used when this action is not used in any menu.
425+
*/
426+
public boolean isCanvasKeyBinding() {
427+
return canvasKeyBinding;
428+
}
429+
430+
/**
431+
* Defines if this action should have its accelerator key added to the {@code Canvas}.
432+
* @param canvasKeyBinding {@code true} if the accelerator key should be added to the
433+
* {@code Canvas}. This is typically used when this action is not used in any menu.
434+
*/
435+
public void setCanvasKeyBinding(boolean canvasKeyBinding) {
436+
this.canvasKeyBinding = canvasKeyBinding;
437+
}
419438

420439

421440
// Serialization

Diff for: src/net/sf/freecol/client/gui/action/MoveAction.java

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public MoveAction(FreeColClient freeColClient, Direction direction) {
4747
super(freeColClient, id + direction);
4848

4949
this.direction = direction;
50+
51+
setCanvasKeyBinding(true);
5052
}
5153

5254
/**

0 commit comments

Comments
 (0)