[Freeciv-Dev] (PR#949) city report fields don't sort well
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This patch provides what I consider the best features of Raimar's and
Christian's patches, to implement a simple method of field sorting.
It will not behave well on complex fields like G/L/S (it will just sort
by the first number in the field). But with the new city report fields
these can be split up into individual fields if you want to sort by them.
In short, it is a simple solution that provides a simple but adequate
fix. I still hope for a more complete and elegant solution in the future.
jason
? client/gui-gtk/diff
? client/gui-stub/stub-update.diff
? client/gui-xaw/diff
Index: client//cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.25
diff -u -r1.25 cityrepdata.c
--- client//cityrepdata.c 2002/11/14 09:14:50 1.25
+++ client//cityrepdata.c 2002/11/16 22:23:13
@@ -526,3 +526,26 @@
p->explanation = _(p->explanation);
}
}
+
+/**********************************************************************
+ This allows more intelligent sorting city report fields by column,
+ although it is a hack and should be replaced by something better.
+ The GUI can give us the two fields and we will try to guess if
+ they are text or numeric fields. It returns a number less then,
+ equal to, or greater than 0 if field1 is less than, equal to, or
+ greater than field2, respectively.
+**********************************************************************/
+int cityrepfield_compare(const char *field1, const char *field2)
+{
+ int scanned1, scanned2;
+ int number1, number2;
+
+ scanned1 = sscanf(field1, "%d", &number1);
+ scanned2 = sscanf(field2, "%d", &number2);
+
+ if (scanned1 == 1 && scanned2 == 1) {
+ return number1 - number2;
+ } else {
+ return strcmp(field1, field2);
+ }
+}
Index: client//cityrepdata.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.h,v
retrieving revision 1.7
diff -u -r1.7 cityrepdata.h
--- client//cityrepdata.h 2002/11/14 05:13:16 1.7
+++ client//cityrepdata.h 2002/11/16 22:23:13
@@ -63,4 +63,6 @@
void init_city_report_data(void);
+int cityrepfield_compare(const char *field1, const char *field2);
+
#endif /* FC__CITYREPDATA_H */
Index: client//gui-gtk/cityrep.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/cityrep.c,v
retrieving revision 1.68
diff -u -r1.68 cityrep.c
--- client//gui-gtk/cityrep.c 2002/11/14 09:14:53 1.68
+++ client//gui-gtk/cityrep.c 2002/11/16 22:23:13
@@ -87,6 +87,23 @@
static int city_dialog_shell_is_modal;
+/*******************************************************************
+ Replacement for the Gtk+ standard compare function for CLISTs,
+ to enable correct sorting of numbers included in text strings.
+*******************************************************************/
+static gint report_sort(GtkCList *report,
+ gconstpointer ptr1, gconstpointer ptr2)
+{
+ const GtkCListRow *row1 = ptr1;
+ const GtkCListRow *row2 = ptr2;
+ const char *buf1, *buf2;
+
+ buf1 = GTK_CELL_TEXT(row1->cell[report->sort_column])->text;
+ buf2 = GTK_CELL_TEXT(row2->cell[report->sort_column])->text;
+
+ return cityrepfield_compare(buf1, buf2);
+}
+
/****************************************************************
Sort cities by column...
*****************************************************************/
@@ -658,6 +675,8 @@
gtk_widget_show_all( GTK_DIALOG(city_dialog_shell)->vbox );
gtk_widget_show_all( GTK_DIALOG(city_dialog_shell)->action_area );
+
+ gtk_clist_set_compare_func(GTK_CLIST(city_list), report_sort);
gtk_widget_add_accelerator(close_command, "clicked",
accel, GDK_Escape, 0, 0);
- [Freeciv-Dev] (PR#949) city report fields don't sort well,
Jason Short via RT <=
[Freeciv-Dev] (PR#949) city report fields don't sort well, Jason Short via RT, 2002/11/16
[Freeciv-Dev] (PR#949) city report fields don't sort well, Jason Short via RT, 2002/11/29
[Freeciv-Dev] (PR#949) city report fields don't sort well, Jason Short via RT, 2002/11/29
|
|