1
/***************************************************************
3
* Purpose: Code::Blocks Cccc plugin: main functions
4
* Author: Lieven de Cock (aka killerbot)
6
* Copyright: (c) Lieven de Cock (aka killerbot)
8
**************************************************************/
11
#include <wx/arrstr.h>
13
#include <wx/fs_zip.h>
16
#include <wx/string.h>
17
#include <wx/xrc/xmlres.h>
18
#include "cbproject.h"
20
#include "logmanager.h"
21
#include "projectmanager.h"
23
#include <wx/busyinfo.h>
24
#include <wx/filedlg.h>
25
#include <wx/filefn.h>
30
// Register the plugin
33
PluginRegistrant<Cccc> reg(_T("Cccc"));
38
if(!Manager::LoadResource(_T("Cccc.zip")))
40
NotifyMissingFile(_T("Cccc.zip"));
43
m_LogPageIndex = 0; // good init value ???
44
m_CcccApp = _T("cccc");
45
} // end of constructor
49
} // end of destruccor
53
// do whatever initialization you need for your plugin
54
// NOTE: after this function, the inherited member variable
55
// IsAttached() will be TRUE...
56
// You should check for it in other functions, because if it
57
// is FALSE, it means that the application did *not* "load"
58
// (see: does not need) this plugin...
59
if(LogManager* LogMan = Manager::Get()->GetLogManager())
61
m_CcccLog = new TextCtrlLogger();
62
m_LogPageIndex = LogMan->SetLog(m_CcccLog);
63
LogMan->Slot(m_LogPageIndex).title = _("Cccc");
64
CodeBlocksLogEvent evtAdd1(cbEVT_ADD_LOG_WINDOW, m_CcccLog, LogMan->Slot(m_LogPageIndex).title);
65
Manager::Get()->ProcessEvent(evtAdd1);
69
void Cccc::OnRelease(bool appShutDown)
71
// do de-initialization for your plugin
72
// if appShutDown is false, the plugin is unloaded because Code::Blocks is being shut down,
73
// which means you must not use any of the SDK Managers
74
// NOTE: after this function, the inherited member variable
75
// IsAttached() will be FALSE...
76
if(Manager::Get()->GetLogManager())
80
CodeBlocksLogEvent evt(cbEVT_REMOVE_LOG_WINDOW, m_CcccLog);
81
Manager::Get()->ProcessEvent(evt);
87
void Cccc::AppendToLog(const wxString& Text)
89
if(LogManager* LogMan = Manager::Get()->GetLogManager())
91
CodeBlocksLogEvent evtSwitch(cbEVT_SWITCH_TO_LOG_WINDOW, m_CcccLog);
92
Manager::Get()->ProcessEvent(evtSwitch);
93
LogMan->Log(Text, m_LogPageIndex);
95
} // end of AppendToLog
97
bool CheckRequirements()
99
cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject();
100
// if no project open, exit
103
wxString msg = _("You need to open a project\nbefore using the plugin!");
104
cbMessageBox(msg, _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
105
Manager::Get()->GetLogManager()->DebugLog(msg);
109
} // end of CheckRequirements
113
if(!CheckRequirements())
118
cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject();
119
::wxSetWorkingDirectory(Project->GetBasePath());
120
const long Files = Project->GetFilesCount();
121
wxString ListOfFileNames;
122
for (int File = 0; File < Files; ++File)
124
ProjectFile* pf = Project->GetFile(File);
125
ListOfFileNames += _T("\"") + pf->relativeFilename + _T("\" ");
128
wxString CommandLine = m_CcccApp + _T(" ") + ListOfFileNames.Trim();
129
AppendToLog(CommandLine);
130
wxArrayString Output, Errors;
133
wxWindowDisabler disableAll;
134
wxBusyInfo running(_("Running cccc... please wait (this may take several minutes)..."),
135
Manager::Get()->GetAppWindow());
136
pid = wxExecute(CommandLine, Output, Errors);
137
} // end lifetime of wxWindowDisabler, wxBusyInfo
141
if (cbMessageBox(_("Failed to lauch cccc.\nDo you want to select the cccc executable?"),
142
_("Question"), wxICON_QUESTION | wxYES_NO, Manager::Get()->GetAppWindow()) == wxID_YES)
144
wxString filename = wxFileSelector(_("Select the cccc executable"));
145
if (!filename.empty()) // otherwise the user selected cancel
147
// try again using the user-provided executable
148
CommandLine = filename + _T(" ") + ListOfFileNames.Trim();
149
AppendToLog(CommandLine);
151
wxWindowDisabler disableAll;
152
wxBusyInfo running(_("Running cccc... please wait (this may take several minutes)..."),
153
Manager::Get()->GetAppWindow());
154
pid = wxExecute(CommandLine, Output, Errors);
155
} // end lifetime of wxWindowDisabler, wxBusyInfo
162
m_CcccApp = filename;
169
AppendToLog(_("Failed to lauch cccc."));
170
cbMessageBox(_("Failed to lauch cccc."), _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
175
size_t Count = Output.GetCount();
176
for(size_t idxCount = 0; idxCount < Count; ++idxCount)
178
AppendToLog(Output[idxCount]);
179
} // end for : idx: idxCount
180
Count = Errors.GetCount();
181
for(size_t idxCount = 0; idxCount < Count; ++idxCount)
183
AppendToLog(Errors[idxCount]);
184
} // end for : idx: idxCount
185
const wxString FileName = _T("./.cccc/cccc.html");
186
if(wxFile::Exists(FileName))
188
if (cbMimePlugin* p = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(FileName))
190
p->OpenFile(FileName);