-
Notifications
You must be signed in to change notification settings - Fork 4
/
wxCrafterCB.cpp
152 lines (131 loc) · 4.76 KB
/
wxCrafterCB.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
#include <wx/app.h>
#include "wxCrafterCB.h"
#include <sdk.h> // Code::Blocks SDK
#include <configurationpanel.h>
#include <manager.h>
#include <projectmanager.h>
#include <cbproject.h>
#include <wx/menu.h>
#include <wx/filedlg.h>
#include <wx/ffile.h>
#include "wxcLib/wxcReplyEventData.h"
#include "wxcHelper.h"
#include <algorithm>
#include <editormanager.h>
#include "wxCrafterTab.h"
#include <cbauibook.h>
#include "wxCrafterCBSettings.h"
// Register the plugin with Code::Blocks.
// We are using an anonymous namespace so we don't litter the global one.
namespace
{
PluginRegistrant<wxCrafterCB> reg(_T("wxCrafterCB"));
}
wxCrafterCB::wxCrafterCB()
: m_projectTree(NULL)
{
}
wxCrafterCB::~wxCrafterCB()
{
}
void wxCrafterCB::OnAttach()
{
m_projectTree = Manager::Get()->GetProjectManager()->GetUI().GetTree();
wxASSERT( m_projectTree );
m_projectTree->Connect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler(wxCrafterCB::OnTreeItemActivated), NULL, this);
m_connector.Connect(wxcEVT_NET_REPLY_FILES_GENERATED, wxCommandEventHandler(wxCrafterCB::OnFilesGenerated), NULL, this);
// Add our tab to the project view
wxcImages images;
cbAuiNotebook* book = Manager::Get()->GetProjectManager()->GetUI().GetNotebook();
m_tabView = new wxCrafterTab( book, this );
book->AddPage( m_tabView, _("wxCrafter"), false, images.Bitmap(wxT("m_bmpWxCrafterLogo")));
}
void wxCrafterCB::OnRelease(bool appShutDown)
{
// Shutdown wxCrafter
m_connector.Shutdown();
m_projectTree->Disconnect(wxEVT_COMMAND_TREE_ITEM_ACTIVATED, wxTreeEventHandler(wxCrafterCB::OnTreeItemActivated), NULL, this);
m_connector.Disconnect(wxcEVT_NET_REPLY_FILES_GENERATED, wxCommandEventHandler(wxCrafterCB::OnFilesGenerated), NULL, this);
}
void wxCrafterCB::BuildMenu(wxMenuBar* menuBar)
{
wxUnusedVar( menuBar );
}
void wxCrafterCB::OnTreeItemActivated(wxTreeEvent& event)
{
// Call skip to make sure that the default operation works, unless
// we decide otherwise
event.Skip(true);
if ( event.GetItem().IsOk() ) {
ProjectManager *prjManager = Manager::Get()->GetProjectManager();
FileTreeData* ftd = (FileTreeData*) m_projectTree->GetItemData( event.GetItem() );
if ( IsWxCrafterFile( ftd ) ) {
event.Skip(false);
if ( EnsureWxCrafterIsRunning() ) {
m_connector.LoadFile( ftd->GetProjectFile()->file.GetFullPath() );
}
}
}
}
void wxCrafterCB::BuildModuleMenu(const ModuleType type, wxMenu* menu, const FileTreeData* data)
{
wxUnusedVar(type);
wxUnusedVar(menu);
wxUnusedVar(data);
}
bool wxCrafterCB::IsWxCrafterFile(const FileTreeData* ftd) const
{
return ftd &&
ftd->GetKind() == FileTreeData::ftdkFile &&
ftd->GetProjectFile() &&
ftd->GetProjectFile()->file.GetExt() == wxT("wxcp");
}
wxArrayString wxCrafterCB::DoGetAllProjectTargets(cbProject* proj) const
{
int targetCounts = proj->GetBuildTargetsCount();
wxArrayString allTargets;
for(int i=0; i<targetCounts; ++i) {
allTargets.Add( proj->GetBuildTarget(i)->GetTitle() );
}
return allTargets;
}
bool wxCrafterCB::EnsureWxCrafterIsRunning()
{
if ( m_connector.IsConnected() ) {
return true;
}
// Launch wxCrafter process is server mode
try {
wxCrafterCBSettings settings;
wxString wxcrafterPath = settings.Load().GetWxcPath();
if ( wxcrafterPath.IsEmpty() ) {
::cbMessageBox(_("Could not locate wxCrafter executable path"), wxT("wxCrafter"), wxICON_ERROR|wxCENTER|wxOK);
return false;
}
m_connector.LaunchAndConnect( wxcrafterPath );
} catch (clSocketException &e) {
::cbMessageBox(_("Failed to launch wxCrafter"), wxT("wxCrafter"), wxICON_ERROR|wxCENTER|wxOK);
return false;
}
return true;
}
void wxCrafterCB::OnFilesGenerated(wxCommandEvent& event)
{
wxcReplyEventData *red = dynamic_cast<wxcReplyEventData*>( event.GetClientObject() );
if ( red ) {
const wxcReplyEventData::StringVec_t& files = red->GetFiles();
wxFileName wxcpFile(red->GetWxcpFile());
// Load the project that has this file
cbProject* proj = Manager::Get()->GetProjectManager()->FindProjectForFile(wxcpFile.GetFullPath(), NULL, false, false);
if ( proj ) {
std::vector<wxFileName> vFiles;
std::for_each( files.begin(), files.end(), StrToFileNameVecFunctor( vFiles ) );
// Add the files
wxcHelper::AddFilesToProject( proj, vFiles, true );
// Reload externally modified files if needed
Manager::Get()->GetEditorManager()->CheckForExternallyModifiedFiles();
}
// And free the event data
wxDELETE( red );
}
}