Debian Codegraph @

wxcrafter/src/output_nbook.cpp

raw
1 #include "output_nbook.h"
2 #include "event_notifier.h"
3 #include "top_level_win_wrapper.h"
4 #include "wxc_project_metadata.h"
5 #include "wxgui_helpers.h"
6 #include "wxguicraft_main_view.h"
7 #include <wx/debug.h>
8 #include <wx/filename.h>
9 #include <wx/msgdlg.h>
10 #include <wx/sstream.h>
11 #include <wx/stc/stc.h>
12 #include <wx/textctrl.h>
13 #include <wx/xml/xml.h>
14
15 OutputNBook::OutputNBook(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
16 const wxString& name)
17 : wxNotebook(parent, id, pos, size, style, name)
18 {
19 }
20
21 OutputNBook::~OutputNBook() {}
22
23 void OutputNBook::CppPageSelected(wxStyledTextCtrl* cpptext, wxStyledTextCtrl* headertext) const
24 {
25 wxArrayString headers;
26 wxString cpp, header;
27 wxStringMap_t additionalFiles;
28
29 GUICraftMainPanel::m_MainPanel->GenerateCppOutput(cpp, header, headers, additionalFiles,
30 GUICraftMainPanel::kGenCodeForPreview |
31 GUICraftMainPanel::kGenCodeSelectionOnly);
32
33 wxString prefix;
34 headers = wxCrafter::MakeUnique(headers);
35 prefix << wxCrafter::Join(headers, wxT("\n")) << wxT("\n");
36 // Prepare the project additional include files
37 wxString projectIncludes;
38 const wxArrayString& includes = wxcProjectMetadata::Get().GetIncludeFiles();
39 for(size_t i = 0; i < includes.GetCount(); i++) {
40 projectIncludes << wxT("#include ") << wxCrafter::AddQuotes(includes.Item(i)) << wxT("\n");
41 }
42 prefix << projectIncludes;
43
44 wxFileName headerFile = wxcProjectMetadata::Get().BaseHeaderFile();
45 wxCrafter::MakeAbsToProject(headerFile);
46 wxString cppPrefix;
47 cppPrefix << "// clang-format off\n";
48 cppPrefix << wxT("#include \"") << headerFile.GetFullName() << wxT("\"\n");
49 cppPrefix << projectIncludes << wxT("\n");
50 cppPrefix << "// clang-format on\n\n";
51
52 header.Prepend(prefix);
53 cpp.Prepend(cppPrefix);
54
55 cpptext->SetReadOnly(false);
56 cpptext->SetText(cpp);
57 cpptext->SetReadOnly(true);
58
59 headertext->SetReadOnly(false);
60 headertext->SetText(header);
61 headertext->SetReadOnly(true);
62 }
63
64 void OutputNBook::XrcPageSelected(wxStyledTextCtrl* text) const
65 {
66 wxString output;
67 GUICraftMainPanel::m_MainPanel->GenerateXrcOutput(output, true);
68 TopLevelWinWrapper::WrapXRC(output);
69 // Format the output
70 wxStringInputStream str(output);
71 wxStringOutputStream out;
72 wxXmlDocument doc(str);
73 if(!doc.Save(out)) { ::wxMessageBox(output); }
74
75 text->SetReadOnly(false);
76 text->SetText(out.GetString());
77 text->SetReadOnly(true);
78 }