1
/***************************************************************
3
* Purpose: Code::Blocks plugin
4
* Author: Ceniza<ceniza@gda.utp.edu.co>
5
* Copyright: (c) Ceniza
7
**************************************************************/
9
#include <wx/frame.h> // GetMenuBar
11
#include <configmanager.h>
14
#include <editormanager.h>
15
#include <editorcolourset.h>
16
#include <logmanager.h>
17
#include <cbexception.h>
18
#include "HTMLExporter.h"
19
#include "RTFExporter.h"
20
#include "ODTExporter.h"
21
#include "PDFExporter.h"
22
#include "cbstyledtextctrl.h"
24
static int idFileExport = wxNewId();
25
static int idFileExportHTML = wxNewId();
26
static int idFileExportRTF = wxNewId();
27
static int idFileExportODT = wxNewId();
28
static int idFileExportPDF = wxNewId();
30
// Register the plugin
33
PluginRegistrant<Exporter> reg(_T("Exporter"));
36
BEGIN_EVENT_TABLE(Exporter, cbPlugin)
37
EVT_MENU(idFileExportHTML, Exporter::OnExportHTML)
38
EVT_MENU(idFileExportRTF, Exporter::OnExportRTF)
39
EVT_MENU(idFileExportODT, Exporter::OnExportODT)
40
EVT_MENU(idFileExportPDF, Exporter::OnExportPDF)
41
EVT_UPDATE_UI(idFileExportHTML, Exporter::OnUpdateUI)
42
EVT_UPDATE_UI(idFileExportRTF, Exporter::OnUpdateUI)
43
EVT_UPDATE_UI(idFileExportODT, Exporter::OnUpdateUI)
56
void Exporter::OnAttach()
58
// do whatever initialization you need for your plugin
59
// NOTE: after this function, the inherited member variable
60
// IsAttached() will be TRUE...
61
// You should check for it in other functions, because if it
62
// is FALSE, it means that the application did *not* "load"
63
// (see: does not need) this plugin...
66
void Exporter::OnRelease(bool /*appShutDown*/)
68
// do de-initialization for your plugin
69
// if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
70
// which means you must not use any of the SDK Managers
71
// NOTE: after this function, the inherited member variable
72
// IsAttached() will be FALSE...
75
void Exporter::BuildMenu(wxMenuBar *menuBar)
77
// find "File" menu position
78
int fileMenuPos = menuBar->FindMenu(_("&File"));
80
if (fileMenuPos == -1)
82
//cbThrow(_T("Can't find \"File\" menu position?!?"));
86
// find actual "File" menu
87
wxMenu *file = menuBar->GetMenu(fileMenuPos);
91
//cbThrow(_T("Can't find \"File\" menu?!?"));
95
// decide where to insert in "File" menu
96
size_t printPos = file->GetMenuItemCount() - 4; // the default location
97
int printID = file->FindItem(_("Print..."));
99
if (printID != wxNOT_FOUND)
101
file->FindChildItem(printID, &printPos);
102
++printPos; // after "Print"
106
wxMenu *export_submenu = new wxMenu;
107
export_submenu->Append(idFileExportHTML, _("As &HTML..."), _("Exports the current file to HTML"));
108
export_submenu->Append(idFileExportRTF, _("As &RTF..."), _("Exports the current file to RTF"));
109
export_submenu->Append(idFileExportODT, _("As &ODT..."), _("Exports the current file to ODT"));
110
export_submenu->Append(idFileExportPDF, _("As &PDF..."), _("Exports the current file to PDF"));
112
wxMenuItem *export_menu = new wxMenuItem(0, idFileExport, _("&Export"), _T(""), wxITEM_NORMAL);
113
export_menu->SetSubMenu(export_submenu);
115
file->Insert(printPos, export_menu);
118
void Exporter::RemoveMenu(wxMenuBar *menuBar)
121
wxMenuItem *item = menuBar->FindItem(idFileExport, &menu);
129
void Exporter::OnUpdateUI(wxUpdateUIEvent &event)
131
if (Manager::IsAppShuttingDown())
137
wxMenuBar *mbar = Manager::Get()->GetAppFrame()->GetMenuBar();
141
EditorManager *em = Manager::Get()->GetEditorManager();
143
// Enabled if there's a source file opened (be sure it isn't the "Start here" page)
144
bool disable = !em || !em->GetActiveEditor() || !em->GetBuiltinActiveEditor();
145
mbar->Enable(idFileExportHTML, !disable);
146
mbar->Enable(idFileExportRTF, !disable);
147
mbar->Enable(idFileExportODT, !disable);
148
mbar->Enable(idFileExportPDF, !disable);
154
void Exporter::OnExportHTML(wxCommandEvent & /*event*/)
157
ExportFile(&exp, _T("html"), _("HTML files|*.html;*.htm"));
160
void Exporter::OnExportRTF(wxCommandEvent & /*event*/)
163
ExportFile(&exp, _T("rtf"), _("RTF files|*.rtf"));
167
void Exporter::OnExportODT(wxCommandEvent & /*event*/)
170
ExportFile(&exp, _T("odt"), _("ODT files|*.odt"));
173
void Exporter::OnExportPDF(wxCommandEvent & /*event*/)
176
ExportFile(&exp, _T("pdf"), _("PDF files|*.pdf"));
179
void Exporter::ExportFile(BaseExporter *exp, const wxString &default_extension, const wxString &wildcard)
186
EditorManager* em = Manager::Get()->GetEditorManager();
187
cbEditor* cb = em->GetBuiltinActiveEditor();
189
wxString filename = wxFileSelector(_("Choose the filename"), _T(""), wxFileName(cb->GetFilename()).GetName() + _T(".") + default_extension, default_extension, wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
190
if (filename.IsEmpty())
195
cbStyledTextCtrl* stc = cb->GetControl();
200
if (wxMessageBox(_("Would you like to have the line numbers printed in the exported file?"), _("Export line numbers"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION) == wxYES)
202
lineCount = stc->GetLineCount();
205
exp->Export(filename, cb->GetFilename(), stc->GetStyledText(0, stc->GetLength() - 1), cb->GetColourSet(), lineCount, stc->GetTabWidth());