Browse files

Prevent a crash that could happen if further changes

were made on a dialogue after using the Apply button.
  • Loading branch information...
1 parent 18621d9 commit cb5dba55dc491107e4152bd80ec496294e449934 @akshay-joshi akshay-joshi committed with dpage Dec 3, 2012
View
3 CHANGELOG
@@ -37,6 +37,9 @@ Changes
Date Dev Ver Change details
---------- --- ------ --------------
+2012-12-03 DP 1.16.1 Prevent a crash that could happen if further changes
+ were made on a dialogue after using the Apply button.
+ [Akshay Joshi]
2012-11-29 GL 1.16.1 Save new comments on already existing columns when
editing a table. Per a report from Jeff Janes.
2012-11-29 GL 1.16.1 Fix the query editor behaviour when executing COPY TO
View
49 pgadmin/dlg/dlgProperty.cpp
@@ -98,6 +98,8 @@ BEGIN_EVENT_TABLE(dlgProperty, DialogWithHelp)
EVT_BUTTON(wxID_HELP, dlgProperty::OnHelp)
EVT_BUTTON(wxID_OK, dlgProperty::OnOK)
EVT_BUTTON(wxID_APPLY, dlgProperty::OnApply)
+ EVT_BUTTON(wxID_CANCEL, dlgProperty::OnCancel)
+ EVT_CLOSE ( dlgProperty::OnClose)
END_EVENT_TABLE();
@@ -233,6 +235,26 @@ void dlgProperty::EnableOK(bool enable)
}
}
+void dlgProperty::OnClose(wxCloseEvent &ev)
+{
+ // Sets the window pointer to NULL when the dialog gets closed
+ if (GetObject())
+ {
+ GetObject()->SetWindowPtr(NULL);
+ }
+ pgDialog::OnClose(ev);
+}
+
+void dlgProperty::OnCancel(wxCommandEvent &ev)
+{
+ // Sets the window pointer to NULL when the dialog gets closed
+ if (GetObject())
+ {
+ GetObject()->SetWindowPtr(NULL);
+ }
+ pgDialog::OnCancel(ev);
+}
+
void dlgProperty::SetSqlReadOnly(bool readonly)
{
@@ -826,10 +848,18 @@ void dlgProperty::ShowObject()
ownDialog = data->GetWindowPtr();
data->SetWindowPtr(NULL);
}
- mainForm->Refresh(tblobj);
- if (data)
+
+ // The Refresh call creates a new data object so we will use the newly
+ // created object and set it's window pointer to NULL.
+ // In addition, we set the dialog's object to the newly created object.
+ pgObject *newData = mainForm->Refresh(tblobj);
+ if (newData)
{
- data->SetWindowPtr(ownDialog);
+ newData->SetWindowPtr(NULL);
+ if (ownDialog)
+ ownDialog->SetObject(newData);
+
+ // Note that the object's window pointer will be reset by dlgProperty::Apply.
}
}
@@ -974,6 +1004,13 @@ bool dlgProperty::apply(const wxString &sql, const wxString &sql2)
ShowObject();
+ // Reset the window pointer of the object to the current window as this may
+ // have been set to NULL during the refresh operation.
+ if (GetObject())
+ {
+ GetObject()->SetWindowPtr(this);
+ }
+
return true;
}
@@ -1125,6 +1162,12 @@ void dlgProperty::OnOK(wxCommandEvent &ev)
return;
}
+ // Sets the window pointer to NULL when the dialog gets closed
+ if (GetObject())
+ {
+ GetObject()->SetWindowPtr(NULL);
+ }
+
Destroy();
}
View
6 pgadmin/frm/frmMain.cpp
@@ -515,7 +515,7 @@ void frmMain::CreateMenus()
}
-void frmMain::Refresh(pgObject *data)
+pgObject * frmMain::Refresh(pgObject *data)
{
bool done = false;
pgObject *obj = NULL;
@@ -577,7 +577,7 @@ void frmMain::Refresh(pgObject *data)
{
CheckAlive();
browser->Thaw();
- return;
+ return data;
}
wxTreeItemId delItem = currentItem;
@@ -600,6 +600,8 @@ void frmMain::Refresh(pgObject *data)
browser->Thaw();
EndMsg(done);
+
+ return currentObject;
}
void frmMain::OnCopy(wxCommandEvent &ev)
View
2 pgadmin/include/dlg/dlgFunction.h
@@ -32,6 +32,8 @@ class dlgFunction : public dlgSecurityProperty
void SetObject(pgObject *obj)
{
function = (pgFunction *)obj;
+ if(seclabelPage)
+ seclabelPage->SetObject(obj);
}
wxString GetHelpPage(bool forCreate) const
View
3 pgadmin/include/dlg/dlgProperty.h
@@ -125,6 +125,9 @@ class dlgProperty : public DialogWithHelp
{
return true;
};
+ void OnClose(wxCloseEvent &ev);
+ void OnCancel(wxCommandEvent &ev);
+
void ShowObject();
void FillSQLTextfield();
View
2 pgadmin/include/dlg/dlgView.h
@@ -34,6 +34,8 @@ class dlgView : public dlgSecurityProperty
void SetObject(pgObject *obj)
{
view = (pgView *)obj;
+ if(seclabelPage)
+ seclabelPage->SetObject(obj);
}
private:
View
2 pgadmin/include/frm/frmMain.h
@@ -103,7 +103,7 @@ class frmMain : public pgFrame
bool CheckAlive();
void execSelChange(wxTreeItemId item, bool currentNode);
- void Refresh(pgObject *data);
+ pgObject * Refresh(pgObject *data);
void ExecDrop(bool cascaded);
void ShowObjStatistics(pgObject *data, wxWindow *ctrl = NULL);

0 comments on commit cb5dba5

Please sign in to comment.