[Freeciv-Dev] (PR#3522) Sorting connect dialog
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hello,
I've made an attempt at sorting the serverlist in the Connect-dialog,
since the default metaserver list is random. Clicking on a title
sorts the list of servers by that topic, clicking again reverse-sorts it.
It's for the gtk client, cvs version 02.24.2003
Andreas Røsdal
diff -Nur -Xfreeciv/diff_ignore freeciv/client/gui-gtk/connectdlg.c
freeciv.patched/client/gui-gtk/connectdlg.c
--- freeciv/client/gui-gtk/connectdlg.c 2002-11-15 07:01:04.000000000 +0100
+++ freeciv.patched/client/gui-gtk/connectdlg.c 2003-02-25 23:06:45.000000000
+0100
@@ -38,8 +38,11 @@
static GtkWidget *iname, *ihost, *iport;
static GtkWidget *connw, *quitw;
+static GtkWidget *slist; /* sorted list of servers */
static GtkWidget *dialog;
+static int sort_column;
+
/* meta Server */
static bool update_meta_dialog(GtkWidget *meta_list);
@@ -48,6 +51,8 @@
static int get_meta_list(GtkWidget *list, char *errbuf, int n_errbuf);
+#define DEF_SORT_COLUMN 0 /* default sort column (server) */
+
/**************************************************************************
...
**************************************************************************/
@@ -69,6 +74,24 @@
}
/**************************************************************************
+ Sort the list of metaservers
+**************************************************************************/
+static void sort_servers_callback(GtkButton *button, gpointer *data)
+{
+ sort_column = GPOINTER_TO_INT(data);
+ if (slist!=NULL) {
+ if (GTK_CLIST(slist)->sort_type == GTK_SORT_ASCENDING) {
+ gtk_clist_set_sort_type(GTK_CLIST(slist), GTK_SORT_DESCENDING);
+ } else {
+ gtk_clist_set_sort_type(GTK_CLIST(slist), GTK_SORT_ASCENDING);
+ }
+ gtk_clist_set_sort_column(GTK_CLIST(slist), sort_column);
+ gtk_clist_sort( GTK_CLIST(slist));
+ }
+}
+
+
+/**************************************************************************
...
**************************************************************************/
static bool update_meta_dialog(GtkWidget *meta_list)
@@ -209,7 +232,6 @@
gtk_notebook_append_page (GTK_NOTEBOOK (book), vbox, label);
list=gtk_clist_new_with_titles(6, titles);
- gtk_clist_column_titles_passive(GTK_CLIST(list));
for(i=0; i<6; i++)
gtk_clist_set_column_auto_resize(GTK_CLIST(list), i, TRUE);
@@ -253,7 +275,18 @@
GTK_SIGNAL_FUNC(connect_callback), NULL);
gtk_signal_connect(GTK_OBJECT(quitw), "clicked",
GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
+ /* default sort column */
+ gtk_clist_set_sort_column(GTK_CLIST(list), DEF_SORT_COLUMN);
+ /* all columns are clickable */
+ for (i = 0; i <6 ; i++) {
+ gtk_signal_connect(GTK_OBJECT
+ (GTK_CLIST(list)->column[i].button),
+ "clicked", GTK_SIGNAL_FUNC(sort_servers_callback),
+ GINT_TO_POINTER(i));
+ }
+
+
gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
gtk_widget_show_all(GTK_DIALOG(dialog)->action_area);
@@ -294,6 +327,12 @@
delete_server_list(server_list);
gtk_clist_thaw(GTK_CLIST(list));
+ /* sort the list */
+ slist = list;
+ gtk_clist_set_sort_type(GTK_CLIST(list), GTK_SORT_ASCENDING);
+ gtk_clist_set_sort_column(GTK_CLIST(list), sort_column);
+ gtk_clist_sort(GTK_CLIST(list));
+
return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#3522) Sorting connect dialog,
andrearo@xxxxxxxxxxxx <=
|
|