From 50b440c6944e69ecc2878bade24cbbf409053ee3 Mon Sep 17 00:00:00 2001 From: Vincent Privat Date: Sun, 19 Jan 2014 03:08:08 +0100 Subject: [PATCH] Fix #5 buttons hidden after reopening map frame --- .../josm/plugins/todo/TodoDialog.java | 29 ++++++++++++------- .../josm/plugins/todo/TodoPlugin.java | 7 +++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoDialog.java b/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoDialog.java index c04de0a..29af217 100644 --- a/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoDialog.java +++ b/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoDialog.java @@ -40,7 +40,11 @@ public class TodoDialog extends ToggleDialog implements PropertyChangeListener { private JList lstPrimitives; private final TodoPopup popupMenu; private AddAction actAdd; + private PassAction actPass; + private MarkAction actMark; private MarkSelectedAction actMarkSelected; + private Shortcut sctPass; + private Shortcut sctMark; /** * Builds the content panel for this dialog @@ -61,20 +65,18 @@ protected void buildContentPanel() { // the add button final SideButton addButton = new SideButton(actAdd = new AddAction(model)); - actAdd.updateEnabledState(); + actAdd.updateEnabledState(); // the pass button - PassAction actPass; final SideButton passButton = new SideButton(actPass = new PassAction(model)); lstPrimitives.getSelectionModel().addListSelectionListener(actPass); - Main.registerActionShortcut(actPass, Shortcut.registerShortcut("subwindow:todo:pass", + Main.registerActionShortcut(actPass, sctPass = Shortcut.registerShortcut("subwindow:todo:pass", tr("Pass over element without marking it"), KeyEvent.VK_OPEN_BRACKET, Shortcut.DIRECT)); // the mark button - MarkAction actMark; final SideButton markButton = new SideButton(actMark = new MarkAction(model)); lstPrimitives.getSelectionModel().addListSelectionListener(actMark); - Main.registerActionShortcut(actMark, Shortcut.registerShortcut("subwindow:todo:mark", + Main.registerActionShortcut(actMark, sctMark = Shortcut.registerShortcut("subwindow:todo:mark", tr("Mark element done"), KeyEvent.VK_CLOSE_BRACKET, Shortcut.DIRECT)); createLayout(lstPrimitives, true, Arrays.asList(new SideButton[] { @@ -91,22 +93,22 @@ public TodoDialog() { lstPrimitives.addMouseListener(new DblClickHandler()); lstPrimitives.addMouseListener(new TodoPopupLauncher()); - this.toggleAction.addPropertyChangeListener(this); + toggleAction.addPropertyChangeListener(this); popupMenu = new TodoPopup(lstPrimitives); } protected static void selectAndZoom(OsmPrimitive object) { if (object == null) return; - if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return; - Main.map.mapView.getEditLayer().data.setSelected(object); + if (Main.main.getEditLayer() == null) return; + Main.main.getEditLayer().data.setSelected(object); AutoScaleAction.autoScale("selection"); } protected static void selectAndZoom(Collection object) { if (object == null) return; - if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return; - Main.map.mapView.getEditLayer().data.setSelected(object); + if (Main.main.getEditLayer() == null) return; + Main.main.getEditLayer().data.setSelected(object); AutoScaleAction.autoScale("selection"); } @@ -401,4 +403,11 @@ public TodoPopup(JList list) { public void propertyChange(PropertyChangeEvent arg0) { actAdd.updateEnabledState(); } + + @Override + public void destroy() { + super.destroy(); + Main.unregisterActionShortcut(actPass, sctPass); + Main.unregisterActionShortcut(actMark, sctMark); + } } diff --git a/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoPlugin.java b/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoPlugin.java index 6ba8681..3784728 100644 --- a/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoPlugin.java +++ b/josm-todo/src/org/openstreetmap/josm/plugins/todo/TodoPlugin.java @@ -14,10 +14,11 @@ public TodoPlugin(PluginInformation info) { @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { - if(newFrame != null && newFrame.mapView != null) { - if (todoDialog == null) - todoDialog = new TodoDialog(); + if (newFrame != null && newFrame.mapView != null) { + todoDialog = new TodoDialog(); newFrame.addToggleDialog(todoDialog); + } else if (newFrame == null) { + todoDialog = null; } } }