<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40599 >

> [chrisk - Sun Dec 14 06:54:21 2008]:
> 
> 
> Trunk Revision: 15365 GTK
> 
> When selecting a set of cities with items to buy in the
> city report, the total buy costs are shown in the bottom
> of the report window.
>
> Now, when I change the production for these cities, the
> amount is not updated.

Attached patch separates out the label update code and adds
a call to it in the required place.


-----------------------------------------------------------------------
ブロロロッーブロロロロロロ!
diff --git a/client/gui-gtk-2.0/cityrep.c b/client/gui-gtk-2.0/cityrep.c
index 0970394..f16e0a4 100644
--- a/client/gui-gtk-2.0/cityrep.c
+++ b/client/gui-gtk-2.0/cityrep.c
@@ -71,6 +71,7 @@ static void city_command_callback(struct gui_dialog *dlg, int response,
                                   gpointer data);
 
 static void city_selection_changed_callback(GtkTreeSelection *selection);
+static void update_total_buy_cost(void);
 
 static void create_select_menu(GtkWidget *item);
 static void create_change_menu(GtkWidget *item);
@@ -1207,8 +1208,8 @@ void city_report_dialog_update_city(struct city *pcity)
     /* update. */
     if (found) {
       update_row(TREE_ITER_PTR(it), pcity);
-
       select_menu_cached = FALSE;
+      update_total_buy_cost();
     } else {
       city_report_dialog_update();
     }
@@ -1578,59 +1579,74 @@ static void popup_select_menu(GtkMenuShell *menu, gpointer data)
   select_menu_cached = TRUE;
 }
 
-/****************************************************************
-...
-*****************************************************************/
-static void city_selection_changed_callback(GtkTreeSelection *selection)
+/***************************************************************************
+  Update the value displayed by the "total buy cost" label in the city
+  report, or make it blank if nothing can be bought.
+***************************************************************************/
+static void update_total_buy_cost(void)
 {
-  int n;
+  GtkWidget *label, *view;
+  GList *rows, *p;
+  GtkTreeModel *model;
+  GtkTreeSelection *sel;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  gpointer res;
+  struct city *pcity;
   int total = 0;
 
-  n = gtk_tree_selection_count_selected_rows(selection);
+  view = city_view;
+  label = city_total_buy_cost_label;
 
-  if (n == 0) {
-    gtk_widget_set_sensitive(city_production_command, FALSE);
-    gtk_widget_set_sensitive(city_center_command, FALSE);
-    gtk_widget_set_sensitive(city_popup_command, FALSE);
-    gtk_widget_set_sensitive(city_buy_command, FALSE);
-  } else {
-    GList *rows, *p;
-    GtkTreeModel *model;
-    GtkTreePath *path;
-    GtkTreeIter iter;
-    gpointer res;
-    struct city *pcity;
+  if (!view || !label) {
+    return;
+  }
 
-    gtk_widget_set_sensitive(city_production_command,
-			     can_client_issue_orders());
-    gtk_widget_set_sensitive(city_center_command, TRUE);
-    gtk_widget_set_sensitive(city_popup_command, TRUE);
-    gtk_widget_set_sensitive(city_buy_command, can_client_issue_orders());
-
-    rows = gtk_tree_selection_get_selected_rows(selection, &model);
-    for (p = rows; p != NULL; p = p->next) {
-      path = p->data;
-      if (gtk_tree_model_get_iter(model, &iter, path)) {
-        gtk_tree_model_get(model, &iter, 0, &res, -1);
-        pcity = res;
-        if (pcity != NULL) {
-          total += city_production_buy_gold_cost(pcity);
-        }
+  sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+  rows = gtk_tree_selection_get_selected_rows(sel, &model);
+
+  for (p = rows; p != NULL; p = p->next) {
+    path = p->data;
+    if (gtk_tree_model_get_iter(model, &iter, path)) {
+      gtk_tree_model_get(model, &iter, 0, &res, -1);
+      pcity = res;
+      if (pcity != NULL) {
+        total += city_production_buy_gold_cost(pcity);
       }
-      gtk_tree_path_free(path);
     }
-    g_list_free(rows);
+    gtk_tree_path_free(path);
   }
+  g_list_free(rows);
 
   if (total > 0) {
-    char buf[64];
+    char buf[128];
     my_snprintf(buf, sizeof(buf), _("Total Buy Cost: %d"), total);
-    gtk_label_set_text(GTK_LABEL(city_total_buy_cost_label), buf);
+    gtk_label_set_text(GTK_LABEL(label), buf);
   } else {
-    gtk_label_set_text(GTK_LABEL(city_total_buy_cost_label), NULL);
+    gtk_label_set_text(GTK_LABEL(label), NULL);
   }
 }
 
+/***************************************************************************
+  Update city report button sensitivity and total buy cost label when the
+  user makes a change in the selection of cities.
+***************************************************************************/
+static void city_selection_changed_callback(GtkTreeSelection *selection)
+{
+  int n;
+
+  n = gtk_tree_selection_count_selected_rows(selection);
+
+  gtk_widget_set_sensitive(city_production_command,
+                           n > 0 && can_client_issue_orders());
+  gtk_widget_set_sensitive(city_center_command, n > 0);
+  gtk_widget_set_sensitive(city_popup_command, n > 0);
+  gtk_widget_set_sensitive(city_buy_command,
+                           n > 0 && can_client_issue_orders());
+
+  update_total_buy_cost();
+}
+
 /****************************************************************
  After a selection rectangle is defined, make the cities that
  are hilited on the canvas exclusively hilited in the
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to