| 1 |
#include "preview_dialog.h" |
| 2 |
#include "DirectoryChanger.h" |
| 3 |
#include "wxc_aui_manager.h" |
| 4 |
#include "wxgui_helpers.h" |
| 5 |
#include "wxguicraft_main_view.h" |
| 6 |
#include <wx/app.h> |
| 7 |
#include <wx/sstream.h> |
| 8 |
#include <wx/xml/xml.h> |
| 9 |
|
| 10 |
BEGIN_EVENT_TABLE(PreviewDialog, wxDialog) |
| 11 |
EVT_CLOSE(PreviewDialog::OnClose) |
| 12 |
END_EVENT_TABLE() |
| 13 |
PreviewDialog::PreviewDialog(wxWindow* parent, const DialogWrapper& dw) |
| 14 |
{ |
| 15 |
wxSize sz = wxCrafter::DecodeSize(dw.SizeAsString()); |
| 16 |
|
| 17 |
wxString text; |
| 18 |
dw.ToXRC(text, wxcWidget::XRC_PREVIEW); |
| 19 |
wxXmlDocument doc; |
| 20 |
|
| 21 |
wxStringInputStream str(text); |
| 22 |
doc.Load(str); |
| 23 |
|
| 24 |
wxString xrcFilePath = wxFileName(wxCrafter::GetUserDataDir(), wxT("mydlg.xrc")).GetFullPath(); |
| 25 |
doc.Save(xrcFilePath); |
| 26 |
DirectoryChanger dc(wxcProjectMetadata::Get().GetProjectPath()); |
| 27 |
|
| 28 |
wxXmlResource::Get()->Load(xrcFilePath); |
| 29 |
wxXmlResource::Get()->LoadDialog(this, parent, dw.GetName()); |
| 30 |
wxXmlResource::Get()->Unload(xrcFilePath); |
| 31 |
|
| 32 |
{ |
| 33 |
// wxLogNull nl; |
| 34 |
// wxRemoveFile(xrcFile.GetFullPath()); |
| 35 |
} |
| 36 |
|
| 37 |
Center(); |
| 38 |
SetSizeHints(sz); |
| 39 |
|
| 40 |
Layout(); |
| 41 |
EventNotifier::Get()->Connect(wxEVT_CLOSE_PREVIEW, wxCommandEventHandler(PreviewDialog::OnClosePreview), NULL, |
| 42 |
this); |
| 43 |
} |
| 44 |
|
| 45 |
PreviewDialog::~PreviewDialog() |
| 46 |
{ |
| 47 |
wxcAuiManager::Get().UnInit(this); |
| 48 |
EventNotifier::Get()->Disconnect(wxEVT_CLOSE_PREVIEW, wxCommandEventHandler(PreviewDialog::OnClosePreview), NULL, |
| 49 |
this); |
| 50 |
|
| 51 |
wxCommandEvent event(wxEVT_PREVIEW_CLOSED); |
| 52 |
EventNotifier::Get()->AddPendingEvent(event); |
| 53 |
} |
| 54 |
|
| 55 |
void PreviewDialog::OnClosePreview(wxCommandEvent& e) { Destroy(); } |
| 56 |
|
| 57 |
void PreviewDialog::OnClose(wxCloseEvent& e) |
| 58 |
{ |
| 59 |
e.Skip(); |
| 60 |
Destroy(); |
| 61 |
} |