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
99
bool CheckRequirements()
101
cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject();
102
// if no project open, exit
105
wxString msg = _("You need to open a project\nbefore using the plugin!");
106
cbMessageBox(msg, _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
107
Manager::Get()->GetLogManager()->DebugLog(msg);
111
} // end of CheckRequirements
116
if(!CheckRequirements())
121
cbProject* Project = Manager::Get()->GetProjectManager()->GetActiveProject();
122
::wxSetWorkingDirectory(Project->GetBasePath());
123
wxString ListOfFileNames;
124
for (FilesList::iterator it = Project->GetFilesList().begin(); it != Project->GetFilesList().end(); ++it)
126
ProjectFile* pf = *it;
127
ListOfFileNames += _T("\"") + pf->relativeFilename + _T("\" ");
130
wxString CommandLine = m_CcccApp + _T(" ") + ListOfFileNames.Trim();
131
AppendToLog(CommandLine);
132
wxArrayString Output, Errors;
135
wxWindowDisabler disableAll;
136
wxBusyInfo running(_("Running cccc... please wait (this may take several minutes)..."),
137
Manager::Get()->GetAppWindow());
138
pid = wxExecute(CommandLine, Output, Errors);
139
} // end lifetime of wxWindowDisabler, wxBusyInfo
143
if (cbMessageBox(_("Failed to lauch cccc.\nDo you want to select the cccc executable?"),
144
_("Question"), wxICON_QUESTION | wxYES_NO, Manager::Get()->GetAppWindow()) == wxID_YES)
146
wxString filename = wxFileSelector(_("Select the cccc executable"));
147
if (!filename.empty()) // otherwise the user selected cancel
149
// try again using the user-provided executable
150
CommandLine = filename + _T(" ") + ListOfFileNames.Trim();
151
AppendToLog(CommandLine);
153
wxWindowDisabler disableAll;
154
wxBusyInfo running(_("Running cccc... please wait (this may take several minutes)..."),
155
Manager::Get()->GetAppWindow());
156
pid = wxExecute(CommandLine, Output, Errors);
157
} // end lifetime of wxWindowDisabler, wxBusyInfo
164
m_CcccApp = filename;
171
AppendToLog(_("Failed to lauch cccc."));
172
cbMessageBox(_("Failed to lauch cccc."), _("Error"), wxICON_ERROR | wxOK, Manager::Get()->GetAppWindow());
177
size_t Count = Output.GetCount();
178
for(size_t idxCount = 0; idxCount < Count; ++idxCount)
180
AppendToLog(Output[idxCount]);
181
} // end for : idx: idxCount
182
Count = Errors.GetCount();
183
for(size_t idxCount = 0; idxCount < Count; ++idxCount)
185
AppendToLog(Errors[idxCount]);
186
} // end for : idx: idxCount
187
const wxString FileName = _T("./.cccc/cccc.html");
188
if(wxFile::Exists(FileName))
190
if (cbMimePlugin* p = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(FileName))
192
p->OpenFile(FileName);