Move XRC pointer checking/error throwing to a templated function (More backporting from Arthur, next few commits will be importing his improvements)
This commit is contained in:
parent
54eac49a59
commit
76ef5906a0
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "wxvbam.h"
|
#include "wxvbam.h"
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <wx/stockitem.h>
|
#include <wx/stockitem.h>
|
||||||
|
@ -1942,19 +1943,27 @@ public:
|
||||||
} throttle_ctrl;
|
} throttle_ctrl;
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
//Check if a pointer from the XRC file is valid. If it's not, throw an error telling the user.
|
||||||
|
template <typename T>
|
||||||
|
void CheckThrowXRCError(T pointer,std::string name)
|
||||||
|
{
|
||||||
|
if(pointer == NULL)
|
||||||
|
{
|
||||||
|
std::string errormessage = "Unable to load a ";
|
||||||
|
errormessage+=typeid(pointer).name();
|
||||||
|
errormessage+=" from the builtin xrc file: ";
|
||||||
|
errormessage+=name;
|
||||||
|
throw std::runtime_error(errormessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
wxDialog * MainFrame::LoadXRCDialog(const char * name)
|
wxDialog * MainFrame::LoadXRCDialog(const char * name)
|
||||||
{
|
{
|
||||||
wxString dname = wxString::FromUTF8(name);
|
wxString dname = wxString::FromUTF8(name);
|
||||||
/* using this instead of LoadDialog() allows non-wxDialog classes that */
|
/* using this instead of LoadDialog() allows non-wxDialog classes that */
|
||||||
/* are derived from wxDialog (like wxPropertySheetDialog) to work */
|
/* are derived from wxDialog (like wxPropertySheetDialog) to work */
|
||||||
wxDialog * dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString), wxDialog);
|
wxDialog * dialog = wxDynamicCast(wxXmlResource::Get()->LoadObject(this, dname, wxEmptyString), wxDialog);
|
||||||
if(!dialog)
|
CheckThrowXRCError(dialog,name);
|
||||||
{
|
|
||||||
std::string errormessage = "Unable to load a dialog from the builtin xrc file: ";
|
|
||||||
errormessage+=name;
|
|
||||||
throw std::runtime_error(errormessage);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
/* wx-2.9.1 doesn't set parent for propertysheetdialogs for some reason */
|
/* wx-2.9.1 doesn't set parent for propertysheetdialogs for some reason */
|
||||||
/* this will generate a gtk warning but it is necessary for later */
|
/* this will generate a gtk warning but it is necessary for later */
|
||||||
/* retrieval using FindWindow() */
|
/* retrieval using FindWindow() */
|
||||||
|
|
Loading…
Reference in New Issue