# HG changeset patch # User peter1138 # Date 1165328338 0 # Node ID 2aa0c4cc8f23fc63f7ccadb2fa3ca137ee35679d # Parent c3eece01af11c17ced52627439c82adeb43a34ca (svn r7373) -Codechange: when removing a GRF from the list, make the next one selected, or the previous file if the last item is being removed. This makes clearing the list easier. diff -r c3eece01af11 -r 2aa0c4cc8f23 newgrf_gui.c --- a/newgrf_gui.c Tue Dec 05 13:58:20 2006 +0000 +++ b/newgrf_gui.c Tue Dec 05 14:18:58 2006 +0000 @@ -331,15 +331,24 @@ } case 4: { /* Remove GRF */ - GRFConfig **pc, *c; + GRFConfig **pc, *c, *newsel; + + /* Choose the next GRF file to be the selected file */ + newsel = WP(w, newgrf_d).sel->next; + for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { + /* If the new selection is empty (i.e. we're deleting the last item + * in the list, pick the file just before the selected file */ + if (newsel == NULL && c->next == WP(w, newgrf_d).sel) newsel = c; + if (c == WP(w, newgrf_d).sel) { *pc = c->next; free(c); break; } } - WP(w, newgrf_d).sel = NULL; + + WP(w, newgrf_d).sel = newsel; SetupNewGRFWindow(w); SetWindowDirty(w); break;