source: josm/trunk/src/org/openstreetmap/josm/actions/ViewportFollowToggleAction.java

Last change on this file was 17795, checked in by simon04, 3 years ago

fix #16848 - Disable "Viewport following" shortcut when not in "Expert mode"

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9
10import org.openstreetmap.josm.actions.mapmode.DrawAction;
11import org.openstreetmap.josm.data.preferences.BooleanProperty;
12import org.openstreetmap.josm.gui.Notification;
13import org.openstreetmap.josm.gui.util.GuiHelper;
14import org.openstreetmap.josm.tools.Shortcut;
15
16/**
17 * This action toggles automatic moving of the map view to last placed node
18 * @since 3837
19 */
20public class ViewportFollowToggleAction extends ToggleAction {
21
22 /**
23 * Defines if a notification should be displayed after enabling and disabling
24 */
25 public static final BooleanProperty PROP_NOTIFICATION = new BooleanProperty("viewportfollow.notification", true);
26
27 /**
28 * Constructs a new {@code ViewportFollowToggleAction}.
29 */
30 public ViewportFollowToggleAction() {
31 super(tr("Viewport Following"),
32 "viewport-follow",
33 tr("Enable/disable automatic moving of the map view to last placed node"),
34 Shortcut.registerShortcut("menu:view:viewportfollow", tr("View: {0}", tr("Viewport Following")),
35 KeyEvent.VK_F, Shortcut.CTRL_SHIFT),
36 true /* register shortcut */
37 );
38 setHelpId(ht("/Action/ViewportFollowing"));
39 setSelected(DrawAction.VIEWPORT_FOLLOWING.get());
40 notifySelectedState();
41 }
42
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 if (!ExpertToggleAction.isExpert()) {
46 // #16848 (Possible to activate "Viewport following" mode when not in "Expert mode" through keyboard shortcut)
47 return;
48 }
49 toggleSelectedState(e);
50 DrawAction.VIEWPORT_FOLLOWING.put(isSelected());
51 if (!getShortcut().getKeyText().isEmpty() && PROP_NOTIFICATION.get()) {
52 String msg = isSelected()
53 ? tr("Viewport following is enabled, press {0} to disable it", getShortcut().getKeyText())
54 : tr("Viewport following is disabled");
55 GuiHelper.runInEDT(() -> new Notification(msg).show());
56 }
57 notifySelectedState();
58 }
59
60 @Override
61 protected boolean listenToSelectionChange() {
62 return false;
63 }
64
65 @Override
66 protected void updateEnabledState() {
67 setEnabled(getLayerManager().getEditDataSet() != null);
68 }
69}
Note: See TracBrowser for help on using the repository browser.