-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProjectExporter.cpp
258 lines (219 loc) · 9.98 KB
/
ProjectExporter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// System include files
// CB include files
#include <sdk.h> // Code::Blocks SDK
#include "manager.h"
#include <logmanager.h>
#include <configurationpanel.h>
// ProjectExporter include files
#include "ProjectExporter.h"
#include "Exporter_AutoTools/AutotoolsExporter.h"
#include "Exporter_BakeFile/BakefileExporter.h"
#include "Exporter_CMake/CMakeListsExporter.h"
#include "Exporter_PreMake4/Premake4Dlg.h"
#include "Exporter_PreMake5/premake5cb.h"
// Register the plugin with Code::Blocks.
// We are using an anonymous namespace so we don't litter the global one.
namespace
{
PluginRegistrant<ProjectExporter> reg("ProjectExporter");
}
int ID_Menu_ExportProject = wxNewId();
int ID_Menu_AutotoolsExport = wxNewId();
int ID_Menu_BakefileExport = wxNewId();
int ID_Menu_Premake4Export = wxNewId();
int ID_Menu_Premake5Export = wxNewId();
int ID_Menu_CMakeExport = wxNewId();
// events handling
BEGIN_EVENT_TABLE(ProjectExporter, cbPlugin)
// add any events you want to handle here
END_EVENT_TABLE()
// constructor
ProjectExporter::ProjectExporter()
{
// Make sure our resources are available.
// In the generated boilerplate code we have no resources but when
// we add some, it will be nice that this code is in place already ;)
if (!Manager::LoadResource("ProjectExporter.zip"))
{
NotifyMissingFile("ProjectExporter.zip");
}
pm5ExportClass = new premake5cb();
}
// destructor
ProjectExporter::~ProjectExporter()
{
delete pm5ExportClass;
}
void ProjectExporter::OnAttach()
{
// do whatever initialization you need for your plugin
// NOTE: after this function, the inherited member variable
// m_IsAttached will be TRUE...
// You should check for it in other functions, because if it
// is FALSE, it means that the application did *not* "load"
// (see: does not need) this plugin...
Manager::Get()->RegisterEventSink(cbEVT_PROJECT_CLOSE, new cbEventFunctor<ProjectExporter, CodeBlocksEvent>(this, &ProjectExporter::OnProjectClose));
Manager::Get()->RegisterEventSink(cbEVT_PROJECT_OPEN, new cbEventFunctor<ProjectExporter, CodeBlocksEvent>(this, &ProjectExporter::OnProjectOpen));
Manager::Get()->RegisterEventSink(cbEVT_PROJECT_ACTIVATE, new cbEventFunctor<ProjectExporter, CodeBlocksEvent>(this, &ProjectExporter::OnProjectActivate));
Manager::Get()->RegisterEventSink(cbEVT_APP_STARTUP_DONE, new cbEventFunctor<ProjectExporter, CodeBlocksEvent>(this, &ProjectExporter::OnStartupDone));
Manager::Get()->RegisterEventSink(cbEVT_MENUBAR_CREATE_END, new cbEventFunctor<ProjectExporter, CodeBlocksEvent>(this, &ProjectExporter::OnMenuCreateEnd));
}
void ProjectExporter::OnRelease(bool appShutDown)
{
// do de-initialization for your plugin
// if appShutDown is true, the plugin is unloaded because Code::Blocks is being shut down,
// which means you must not use any of the SDK Managers
// NOTE: after this function, the inherited member variable
// m_IsAttached will be FALSE...
}
int ProjectExporter::Execute()
{
return pm5ExportClass->Execute();
}
void ProjectExporter::BuildMenu(wxMenuBar * menuBar)
{
//The application is offering its menubar for your plugin,
//to add any menu items you want...
//Append any items you need in the menu...
//NOTE: Be careful in here... The application's menubar is at your disposal.
}
//Delayed menu build (change this if projects importer recognizes this menu item)
void ProjectExporter::OnStartupDone(CodeBlocksEvent & event)
{
wxMenu * submenu = Manager::Get()->GetAppFrame()->GetMenuBar()->GetMenu(0);
if (submenu->FindItem(_("E&xport project")) != wxNOT_FOUND)
{
return;
}
wxMenu * SubmenuExportProject = new wxMenu;
wxMenuItem * MenuItemExportAutotools = new wxMenuItem(SubmenuExportProject, ID_Menu_AutotoolsExport, _("&Autotools build system"), _("Set up an Autotools build system for the active project"));
wxMenuItem * MenuItemExportBakefile = new wxMenuItem(SubmenuExportProject, ID_Menu_BakefileExport, _("&Bakefile"), _("Export active project as a Bakefile"));
wxMenuItem * MenuItemExportPremake4 = new wxMenuItem(SubmenuExportProject, ID_Menu_Premake4Export, _("&Premake4 script..."), _("Export active project as a Premake4 script"));
wxMenuItem * MenuItemExportPremake5 = new wxMenuItem(SubmenuExportProject, ID_Menu_Premake5Export, _("Premake&5 script..."), _("Export active project as a Premake5 script"));
wxMenuItem * MenuItemExportCMake = new wxMenuItem(SubmenuExportProject, ID_Menu_CMakeExport, _("C&MakeLists.txt (WIP)..."), _("Export active project to a simple CMakeLists.txt file"));
SubmenuExportProject->Append(MenuItemExportAutotools);
SubmenuExportProject->Append(MenuItemExportBakefile);
SubmenuExportProject->Append(MenuItemExportPremake4);
SubmenuExportProject->Append(MenuItemExportPremake5);
SubmenuExportProject->Append(MenuItemExportCMake);
int idx = submenu->GetMenuItems().IndexOf(submenu->FindItem(submenu->FindItem(_("&Import project"))));
if (idx == wxNOT_FOUND)
{
idx = submenu->GetMenuItems().IndexOf(submenu->FindItem(submenu->FindItem(_("R&ecent files"))));
if (idx++ == wxNOT_FOUND)
{
idx = 7;
}
submenu->Insert(++idx, ID_Menu_ExportProject, _("E&xport project"), SubmenuExportProject);
//submenu->(++idx, SubmenuExportProject);
submenu->InsertSeparator(++idx);
}
else
{
submenu->Insert(++idx, ID_Menu_ExportProject, _("E&xport project"), SubmenuExportProject);
//submenu->Insert(++idx, SubmenuExportProject);
}
MenuItemExportAutotools->Enable(IsProjectOpen());
MenuItemExportBakefile->Enable(IsProjectOpen());
MenuItemExportPremake4->Enable(IsProjectOpen());
MenuItemExportPremake5->Enable(IsProjectOpen());
MenuItemExportCMake->Enable(IsProjectOpen());
Connect(ID_Menu_AutotoolsExport, wxEVT_MENU, (wxObjectEventFunction)&ProjectExporter::RunExportAutotools);
Connect(ID_Menu_BakefileExport, wxEVT_MENU, (wxObjectEventFunction)&ProjectExporter::RunExportBakefile);
Connect(ID_Menu_Premake4Export, wxEVT_MENU, (wxObjectEventFunction)&ProjectExporter::RunExportPremake4);
Connect(ID_Menu_Premake5Export, wxEVT_MENU, (wxObjectEventFunction)&ProjectExporter::RunExportPremake5);
Connect(ID_Menu_CMakeExport, wxEVT_MENU, (wxObjectEventFunction)&ProjectExporter::RunExportCMake);
}
void ProjectExporter::RunExportAutotools(wxCommandEvent & event)
{
AutotoolsExporter * exportObjectTmp = new AutotoolsExporter();
exportObjectTmp->RunExport();
Manager::Get()->GetLogManager()->Log(_("Autotools build system created"));
}
void ProjectExporter::RunExportBakefile(wxCommandEvent & event)
{
BakefileExporter * exportObjectTmp = new BakefileExporter();
exportObjectTmp->RunExport();
Manager::Get()->GetLogManager()->Log(_("Bakefile exported"));
}
void ProjectExporter::RunExportPremake4(wxCommandEvent & event)
{
Premake4Dlg SettingsDialog(Manager::Get()->GetAppWindow());
if (SettingsDialog.ShowModal() == wxID_OK)
{
Manager::Get()->GetLogManager()->Log(_("Premake4 script exported"));
}
else
{
Manager::Get()->GetLogManager()->Log(_("Premake4 export canceled"));
}
}
void ProjectExporter::RunExportPremake5(wxCommandEvent & event)
{
Manager::Get()->GetLogManager()->Log(_("Premake4 export started"));
pm5ExportClass->OnFileExport(event);
Manager::Get()->GetLogManager()->Log(_("Premake4 export completed"));
}
void ProjectExporter::RunExportCMake(wxCommandEvent & event)
{
Manager::Get()->GetLogManager()->Log(_("RunExportCMake started"));
CMakeListsExporter * exportObjectTmp = new CMakeListsExporter();
exportObjectTmp->RunExport();
Manager::Get()->GetLogManager()->Log(_("RunExportCMake completed"));
}
bool ProjectExporter::IsProjectOpen() const
{
const cbProject * project = Manager::Get()->GetProjectManager()->GetActiveProject();
if (!project)
{
return false;
}
return true;
}
void ProjectExporter::OnProjectClose(CodeBlocksEvent & event)
{
wxMenu * submenu = Manager::Get()->GetAppFrame()->GetMenuBar()->GetMenu(0);
if (submenu->FindItem(_("E&xport project")) == wxNOT_FOUND)
{
OnStartupDone(event);
}
submenu->FindItem(ID_Menu_AutotoolsExport)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_BakefileExport)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_Premake4Export)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_Premake5Export)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_CMakeExport)->Enable(IsProjectOpen());
}
void ProjectExporter::OnProjectOpen(CodeBlocksEvent & event)
{
wxMenu * submenu = Manager::Get()->GetAppFrame()->GetMenuBar()->GetMenu(0);
if (submenu->FindItem(_("E&xport project")) == wxNOT_FOUND)
{
OnStartupDone(event);
}
submenu->FindItem(ID_Menu_AutotoolsExport)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_BakefileExport)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_Premake4Export)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_Premake5Export)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_CMakeExport)->Enable(IsProjectOpen());
}
void ProjectExporter::OnProjectActivate(CodeBlocksEvent & event)
{
wxMenu * submenu = Manager::Get()->GetAppFrame()->GetMenuBar()->GetMenu(0);
if (submenu->FindItem(_("E&xport project")) == wxNOT_FOUND)
{
OnStartupDone(event);
}
submenu->FindItem(ID_Menu_AutotoolsExport)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_BakefileExport)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_Premake4Export)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_Premake5Export)->Enable(IsProjectOpen());
submenu->FindItem(ID_Menu_CMakeExport)->Enable(IsProjectOpen());
}
void ProjectExporter::OnMenuCreateEnd(CodeBlocksEvent & event)
{
wxMenu * submenu = Manager::Get()->GetAppFrame()->GetMenuBar()->GetMenu(0);
if (submenu->FindItem(_("E&xport project")) == wxNOT_FOUND)
{
OnStartupDone(event);
}
}