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

> [book - Sat Feb 07 02:35:55 2009]:
> 
> > [book - Thu Jan 29 01:21:42 2009]:
> > 
> > > [book - Mon Jan 26 02:56:39 2009]:
> > > 
> > > The order of city report columns was changed for no good reason
> > > as a bundled "feature" of r12989 (39385, not even part of the
> > > original ticket request?!). This patch changes the ordering
> > > back so that concise rapture/disorder, city name, and city size
> > > are again back as the first 3 columns.
> > 
> > Version 2 allows the city report columns to be reordered by
> > dragging the column headers, so users can setup any order
> > they like if they really want to. Later, I will think of a
> > way the ordering information can be saved and restored in
> > the civclientrc.
> 
> Ok, this needs more work, since being able to re-order the columns
> breaks the show menu in the city report (it shows/hides the wrong
> column).

Here is a version that allows columns to be reordered
without breaking the "Display" menu.


-----------------------------------------------------------------------
コラムニストの攻撃だ!
diff --git a/client/cityrepdata.c b/client/cityrepdata.c
index 8fef84d..c78e0f5 100644
--- a/client/cityrepdata.c
+++ b/client/cityrepdata.c
@@ -443,17 +443,21 @@ static const char *cr_entry_cma(const struct city *pcity,
 #define FUNC_TAG(var)  cr_entry_##var, #var 
 
 static const struct city_report_spec base_city_report_specs[] = {
+  { TRUE, -15, 0, NULL,  N_("?city:Name"), N_("City Name"),
+    NULL, FUNC_TAG(cityname) },
+  { TRUE,   2, 1, NULL,  N_("?size [short]:Sz"), N_("Size"),
+    NULL, FUNC_TAG(size) },
+  { TRUE,  -8, 1, NULL,  N_("State"),   N_("Rapture/Peace/Disorder"),
+    NULL, FUNC_TAG(hstate_verbose) },
+  { FALSE,  1, 1, NULL,  NULL,          N_("Concise *=Rapture, X=Disorder"),
+    NULL, FUNC_TAG(hstate_concise) },
+
   /* Specialists grouped with init_city_report_game_data specialists */ 
   { FALSE,  7, 1, N_("Special"),
     N_("?entertainers/scientists/taxmen:E/S/T"),
     N_("Entertainers, Scientists, Taxmen"),
     NULL, FUNC_TAG(specialists) },
 
-  { FALSE,  1, 1, NULL,  NULL,          N_("Concise *=Rapture, X=Disorder"),
-    NULL, FUNC_TAG(hstate_concise) },
-  { TRUE,  -8, 1, NULL,  N_("State"),   N_("Rapture/Peace/Disorder"),
-    NULL, FUNC_TAG(hstate_verbose) },
-
   { FALSE, 2, 1, NULL, N_("?Happy workers:H"), N_("Workers: Happy"),
     NULL, FUNC_TAG(happy) },
   { FALSE, 2, 1, NULL, N_("?Content workers:C"), N_("Workers: Content"),
@@ -485,12 +489,6 @@ static const struct city_report_spec base_city_report_specs[] = {
     N_("?Stock/Target:(Have/Need)"),
     N_("Turns until growth/famine"),
     NULL, FUNC_TAG(growturns) },
-  { TRUE,   2, 1, NULL,  N_("?size [short]:Sz"), N_("Size"),
-    NULL, FUNC_TAG(size) },
-
-  /* city name closer to center, try to keep within scroll window */
-  { TRUE, -15, 0, NULL,  N_("?city:Name"), N_("City Name"),
-    NULL, FUNC_TAG(cityname) },
 
   { TRUE,  10, 1, N_("Surplus"), N_("?food/production/trade:F/P/T"),
                                  N_("Surplus: Food, Production, Trade"),
diff --git a/client/gui-gtk-2.0/cityrep.c b/client/gui-gtk-2.0/cityrep.c
index 32cde71..4ed96e1 100644
--- a/client/gui-gtk-2.0/cityrep.c
+++ b/client/gui-gtk-2.0/cityrep.c
@@ -643,14 +643,22 @@ static void append_cma_to_menu_item(GtkMenuItem *parent_item, bool change_cma)
 static void city_report_update_views(void)
 {
   struct city_report_spec *spec;
-  int i;
+  GtkTreeView *view;
+  GtkTreeViewColumn *col;
+  GList *columns, *p;
 
-  for (i=0, spec=city_report_specs; i<NUM_CREPORT_COLS; i++, spec++) {
-    GtkTreeViewColumn *col;
+  view = GTK_TREE_VIEW(city_view);
+  g_return_if_fail(view != NULL);
 
-    col = gtk_tree_view_get_column(GTK_TREE_VIEW(city_view), i);
+  columns = gtk_tree_view_get_columns(view);
+
+  for (p = columns; p != NULL; p = p->next) {
+    col = p->data;
+    spec = g_object_get_data(G_OBJECT(col), "city_report_spec");
     gtk_tree_view_column_set_visible(col, spec->show);
   }
+
+  g_list_free(columns);
 }
 
 /****************************************************************
@@ -877,6 +885,8 @@ static void create_city_report_dialog(bool make_modal)
     col = gtk_tree_view_column_new_with_attributes(titles[i], renderer,NULL);
     gtk_tree_view_column_set_visible(col, spec->show);
     gtk_tree_view_column_set_sort_column_id(col, i);
+    gtk_tree_view_column_set_reorderable(col, TRUE);
+    g_object_set_data(G_OBJECT(col), "city_report_spec", spec);
     gtk_tree_view_append_column(GTK_TREE_VIEW(city_view), col);
     gtk_tree_view_column_set_cell_data_func(col, renderer,
       cityrep_cell_data_func, GINT_TO_POINTER(i), NULL);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to