Fix #7089: Close NewGRF textfile windows when their data is invalid (#7106)

This commit is contained in:
glx22 2019-01-31 23:15:22 +01:00 committed by Charles Pigott
parent 8e02b7952b
commit bb9b8eb464
1 changed files with 20 additions and 4 deletions

View File

@ -725,7 +725,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
GRFConfig *d = new GRFConfig(*a);
d->next = (*c)->next;
d->CopyParams(**c);
if (this->active_sel == *c) this->active_sel = NULL;
if (this->active_sel == *c) {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
this->active_sel = NULL;
}
delete *c;
*c = d;
iter->second = d;
@ -1022,7 +1026,10 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
GRFConfig *c;
for (c = this->actives; c != NULL && i > 0; c = c->next, i--) {}
if (this->active_sel != c) DeleteWindowByClass(WC_GRF_PARAMETERS);
if (this->active_sel != c) {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
}
this->active_sel = c;
this->avail_sel = NULL;
this->avail_pos = -1;
@ -1039,6 +1046,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case WID_NS_REMOVE: { // Remove GRF
if (this->active_sel == NULL || !this->editable) break;
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
/* Choose the next GRF file to be the selected file. */
GRFConfig *newsel = this->active_sel->next;
@ -1080,6 +1088,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
this->active_sel = NULL;
DeleteWindowByClass(WC_GRF_PARAMETERS);
if (i < this->avails.Length()) {
if (this->avail_sel != this->avails[i]) DeleteWindowByClass(WC_TEXTFILE);
this->avail_sel = this->avails[i];
this->avail_pos = i;
}
@ -1152,11 +1161,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
virtual void OnNewGRFsScanned()
{
if (this->active_sel == NULL) DeleteWindowByClass(WC_TEXTFILE);
this->avail_sel = NULL;
this->avail_pos = -1;
this->avails.ForceRebuild();
this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
this->DeleteChildWindows(WC_TEXTFILE); // Remove the view textfile window
}
virtual void OnDropdownSelect(int widget, int index)
@ -1173,6 +1182,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
ResetObjectToPlace();
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
this->active_sel = NULL;
this->InvalidateData(GOID_NEWGRF_PRESET_LOADED);
}
@ -1221,7 +1231,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
*l = new GRFConfig(*f);
(*l)->next = c->next;
if (active_sel == c) active_sel = *l;
if (this->active_sel == c) this->active_sel = *l;
delete c;
}
@ -1347,6 +1357,9 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
if (this->avails.Length() == 0) this->avail_pos = -1;
if (this->avail_pos >= 0) {
this->active_sel = NULL;
DeleteWindowByClass(WC_GRF_PARAMETERS);
if (this->avail_sel != this->avails[this->avail_pos]) DeleteWindowByClass(WC_TEXTFILE);
this->avail_sel = this->avails[this->avail_pos];
this->vscroll2->ScrollTowards(this->avail_pos);
this->InvalidateData(0);
@ -1509,6 +1522,8 @@ private:
{
if (this->avail_sel == NULL || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;
DeleteWindowByClass(WC_TEXTFILE);
uint count = 0;
GRFConfig **entry = NULL;
GRFConfig **list;
@ -1968,6 +1983,7 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed)
{
if (confirmed) {
DeleteWindowByClass(WC_GRF_PARAMETERS);
DeleteWindowByClass(WC_TEXTFILE);
NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
GamelogStartAction(GLAT_GRF);