On Fri, 7 Aug 2015 07:34:43 +0930
"Michael T. Pope" <mp...@computer.org> wrote:
> On Thu, 6 Aug 2015 16:00:43 +0200
> win...@genial.ms wrote:
> > > I have been working on the client IGC and the way it sets the active unit 
> > > and
> > > interacts with the GUI in general.  The patch is now fairly intrusive so I
> > > have held it up for some play testing. 
> > 
> > Well, if you would have attached a diff, I could take a look at it or
> > try it out.
> 
> Its still too flakey...

However part of it has been sorted out, so there is an attached diff this
time.  There are many calls to updateMenuBar almost always associated with
a call to FreeColClient.updateActions (although the ordering is
sometimes inconsistent!).  IGC quite rightly does this after almost
every action through IGC.updateControls.  There is no reason to
separate the action update from the menu bar update, and clearly the
actions need to be correctly set first.  The same applies to resetMenuBar.
The patch therefore moves the updateActions call into the GUI-level routine.

Selecting the active unit or tile can clearly change the available
user actions, so I have likewise made sure setActiveUnit and
setSelectedTile call gui.updateMenuBar, which simplifies the
corresponding MapViewer routines.

Cheers,
Mike Pope
diff --git a/src/net/sf/freecol/client/control/InGameController.java b/src/net/sf/freecol/client/control/InGameController.java
index 24bd079..ea8c0a3 100644
--- a/src/net/sf/freecol/client/control/InGameController.java
+++ b/src/net/sf/freecol/client/control/InGameController.java
@@ -314,7 +314,6 @@ public final class InGameController implements NetworkConstants {
         SwingUtilities.invokeLater(new Runnable() {
                 @Override
                 public void run() {
-                    freeColClient.updateActions();
                     gui.updateMenuBar();
                 }
             });
diff --git a/src/net/sf/freecol/client/control/MapEditorController.java b/src/net/sf/freecol/client/control/MapEditorController.java
index c6e7f5e..54b945c 100644
--- a/src/net/sf/freecol/client/control/MapEditorController.java
+++ b/src/net/sf/freecol/client/control/MapEditorController.java
@@ -186,7 +186,7 @@ public final class MapEditorController {
             .createMap(new LogBuilder(-1));
         requireNativeNations(game);
         gui.setFocus(game.getMap().getTile(1,1));
-        freeColClient.updateActions();
+        gui.updateMenuBar();
         gui.refresh();
     }
 
@@ -308,7 +308,7 @@ public final class MapEditorController {
                                     gui.closeStatusPanel();
                                     gui.setFocus(freeColClient.getGame()
                                         .getMap().getTile(1,1));
-                                    freeColClient.updateActions();
+                                    gui.updateMenuBar();
                                     gui.refresh();
                                 }
                             });
diff --git a/src/net/sf/freecol/client/gui/Canvas.java b/src/net/sf/freecol/client/gui/Canvas.java
index 31572bd..caf09d6 100644
--- a/src/net/sf/freecol/client/gui/Canvas.java
+++ b/src/net/sf/freecol/client/gui/Canvas.java
@@ -986,8 +986,7 @@ public final class Canvas extends JDesktopPane {
      */
     public void add(Component comp, Integer i) {
         addToCanvas(comp, i);
-        updateMenuBar();
-        freeColClient.updateActions();
+        gui.updateMenuBar();
     }
 
     /**
@@ -1407,10 +1406,8 @@ public final class Canvas extends JDesktopPane {
     @Override
     public void remove(Component comp) {
         removeFromCanvas(comp);
-        final boolean takeFocus = (comp != statusPanel);
-        updateMenuBar();
-        freeColClient.updateActions();
-        if (takeFocus && !isShowingSubPanel()) {
+        gui.updateMenuBar();
+        if (comp != statusPanel && !isShowingSubPanel()) {
             requestFocus();
         }
     }
@@ -1623,8 +1620,7 @@ public final class Canvas extends JDesktopPane {
         } finally {
             clientOptionsDialogShowing = false;
             if (group != null) {
-                freeColClient.updateActions();
-                resetMenuBar();
+                gui.resetMenuBar();
                 // Immediately redraw the minimap if that was updated.
                 gui.updateMapControls();
             }
diff --git a/src/net/sf/freecol/client/gui/MapViewer.java b/src/net/sf/freecol/client/gui/MapViewer.java
index 55d0710..31faeeb 100644
--- a/src/net/sf/freecol/client/gui/MapViewer.java
+++ b/src/net/sf/freecol/client/gui/MapViewer.java
@@ -933,7 +933,6 @@ public final class MapViewer {
 
         if (activeUnit == null || tile == null) {
             gui.getCanvas().stopGoto();
-            freeColClient.updateActions();
         } else {
             updateCurrentPathForActiveUnit();
             if (!gui.setSelectedTile(tile)
@@ -1069,11 +1068,6 @@ public final class MapViewer {
             }
         }
 
-        freeColClient.updateActions();
-        gui.updateMenuBar();
-
-        gui.updateMapControls();
-
         // Check for refocus
         if (!onScreen(newTile)
             || freeColClient.getClientOptions().getBoolean(ClientOptions.ALWAYS_CENTER)) {
diff --git a/src/net/sf/freecol/client/gui/SwingGUI.java b/src/net/sf/freecol/client/gui/SwingGUI.java
index 98ab308..95f1c29 100644
--- a/src/net/sf/freecol/client/gui/SwingGUI.java
+++ b/src/net/sf/freecol/client/gui/SwingGUI.java
@@ -543,6 +543,7 @@ public class SwingGUI extends GUI {
      */
     @Override
     public void resetMenuBar() {
+        freeColClient.updateActions();
         canvas.resetMenuBar();
     }
 
@@ -585,20 +586,24 @@ public class SwingGUI extends GUI {
      */
     @Override
     public boolean setActiveUnit(Unit unit) {
-        boolean result=mapViewer.setActiveUnit(unit);
+        boolean result = mapViewer.setActiveUnit(unit);
         updateMapControls();
+        updateMenuBar();
         if (unit != null && !freeColClient.getMyPlayer().owns(unit)) {
             canvas.refresh();
         }
-        canvas.updateMenuBar();
         return result;
     }
 
     /**
      * Update the menu bar.
+     *
+     * Always update the actions first so that the enabled/disabled
+     * state is correct.
      */
     @Override
     public void updateMenuBar() {
+        freeColClient.updateActions();
         canvas.updateMenuBar();
     }
 
@@ -1706,8 +1711,9 @@ public class SwingGUI extends GUI {
 
     @Override
     public boolean setSelectedTile(Tile newTileToSelect) {
-        boolean result=mapViewer.setSelectedTile(newTileToSelect);
+        boolean result = mapViewer.setSelectedTile(newTileToSelect);
         updateMapControls();
+        updateMenuBar();
         return result;
     }
 
diff --git a/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java b/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java
index bae1978..8c8b96f 100644
--- a/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java
+++ b/src/net/sf/freecol/client/gui/action/NewEmptyMapAction.java
@@ -72,7 +72,7 @@ public class NewEmptyMapAction extends MapboardAction {
         game.setMap(map);
         Tile tile = map.getTile(size.width/2, size.height/2);
         getGUI().setFocus(tile);
-        getFreeColClient().updateActions();
+        getGUI().updateMenuBar();
         getGUI().refresh();
     }
 }

Attachment: pgpDR0Qm7h9oK.pgp
Description: OpenPGP digital signature

------------------------------------------------------------------------------
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to