Author: cazfi
Date: Wed Nov 18 17:07:37 2015
New Revision: 30667

URL: http://svn.gna.org/viewcvs/freeciv?rev=30667&view=rev
Log:
Make sure "Airlift" button is insensitive when the gtk-clients' "Goto City" 
dialog has no cities
listed at all.

See bug #24060

Modified:
    branches/S2_6/client/gui-gtk-2.0/gotodlg.c
    branches/S2_6/client/gui-gtk-3.0/gotodlg.c

Modified: branches/S2_6/client/gui-gtk-2.0/gotodlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-2.0/gotodlg.c?rev=30667&r1=30666&r2=30667&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-2.0/gotodlg.c  (original)
+++ branches/S2_6/client/gui-gtk-2.0/gotodlg.c  Wed Nov 18 17:07:37 2015
@@ -287,13 +287,19 @@
 /**************************************************************************
   Appends the list of the city owned by the player in the goto dialog.
 **************************************************************************/
-static void list_store_append_player_cities(GtkListStore *store,
+static bool list_store_append_player_cities(GtkListStore *store,
                                             const struct player *pplayer)
 {
   GtkTreeIter it;
   struct nation_type *pnation = nation_of_player(pplayer);
   const char *nation = nation_adjective_translation(pnation);
-  GdkPixbuf *pixbuf = get_flag(pnation);
+  GdkPixbuf *pixbuf;
+
+  if (city_list_size(pplayer->cities) == 0) {
+    return FALSE;
+  }
+
+  pixbuf = get_flag(pnation);
 
   city_list_iterate(pplayer->cities, pcity) {
     gtk_list_store_append(store, &it);
@@ -306,6 +312,8 @@
                        -1);
   } city_list_iterate_end;
   g_object_unref(pixbuf);
+
+  return TRUE;
 }
 
 /**************************************************************************
@@ -419,6 +427,8 @@
 **************************************************************************/
 static void update_goto_dialog(GtkToggleButton *button)
 {
+  bool nonempty = FALSE;
+
   gtk_list_store_clear(goto_list_store);
 
   if (!client_has_player()) {
@@ -428,13 +438,19 @@
 
   if (gtk_toggle_button_get_active(button)) {
     players_iterate(pplayer) {
-      list_store_append_player_cities(goto_list_store, pplayer);
+      nonempty |= list_store_append_player_cities(goto_list_store, pplayer);
     } players_iterate_end;
   } else {
-    list_store_append_player_cities(goto_list_store, client_player());
+    nonempty |= list_store_append_player_cities(goto_list_store, 
client_player());
   }
 
   refresh_airlift_column();
+
+  if (!nonempty) {
+    /* No selection causes callbacks to fire, causing also Airlift button
+     * to update. Do it here. */
+    refresh_airlift_button();
+  }
 }
 
 /**************************************************************************
@@ -498,6 +514,7 @@
                                     gpointer data)
 {
   struct city *pdestcity = get_selected_city();
+
   if (NULL != pdestcity) {
     center_tile_mapcanvas(city_tile(pdestcity));
   }

Modified: branches/S2_6/client/gui-gtk-3.0/gotodlg.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-gtk-3.0/gotodlg.c?rev=30667&r1=30666&r2=30667&view=diff
==============================================================================
--- branches/S2_6/client/gui-gtk-3.0/gotodlg.c  (original)
+++ branches/S2_6/client/gui-gtk-3.0/gotodlg.c  Wed Nov 18 17:07:37 2015
@@ -291,13 +291,19 @@
 /**************************************************************************
   Appends the list of the city owned by the player in the goto dialog.
 **************************************************************************/
-static void list_store_append_player_cities(GtkListStore *store,
+static bool list_store_append_player_cities(GtkListStore *store,
                                             const struct player *pplayer)
 {
   GtkTreeIter it;
   struct nation_type *pnation = nation_of_player(pplayer);
   const char *nation = nation_adjective_translation(pnation);
-  GdkPixbuf *pixbuf = get_flag(pnation);
+  GdkPixbuf *pixbuf;
+
+  if (city_list_size(pplayer->cities) == 0) {
+    return FALSE;
+  }
+
+  pixbuf = get_flag(pnation);
 
   city_list_iterate(pplayer->cities, pcity) {
     gtk_list_store_append(store, &it);
@@ -310,6 +316,8 @@
                        -1);
   } city_list_iterate_end;
   g_object_unref(pixbuf);
+
+  return TRUE;
 }
 
 /**************************************************************************
@@ -423,6 +431,8 @@
 **************************************************************************/
 static void update_goto_dialog(GtkToggleButton *button)
 {
+  bool nonempty = FALSE;
+  
   if (!client_has_player()) {
     /* Case global observer. */
     return;
@@ -434,15 +444,21 @@
 
   if (gtk_toggle_button_get_active(button)) {
     players_iterate(pplayer) {
-      list_store_append_player_cities(goto_list_store, pplayer);
+      nonempty |= list_store_append_player_cities(goto_list_store, pplayer);
     } players_iterate_end;
   } else {
-    list_store_append_player_cities(goto_list_store, client_player());
+    nonempty |= list_store_append_player_cities(goto_list_store, 
client_player());
   }
 
   gotodlg_updating = FALSE;
 
   refresh_airlift_column();
+
+  if (!nonempty) {
+    /* No selection causes callbacks to fire, causing also Airlift button
+     * to update. Do it here. */
+    refresh_airlift_button();
+  }
 }
 
 /**************************************************************************


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to