~ubuntu-branches/debian/stretch/codelite/stretch

« back to all changes in this revision

Viewing changes to QmakePlugin/qmakeplugin.cpp

  • Committer: Package Import Robot
  • Author(s): James Cowgill
  • Date: 2014-09-01 00:23:18 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20140901002318-wx98wxrjb2e0ifi8
Tags: 6.1.1+dfsg-1
* New upstream release.

* debian/control
  - Build depend on libhunspell-dev.
  - Re-enable SFTP support using libssh-gcrypt.
  - Recommend valgrind (for new MemChecker plugin).
* debian/copyright
  - Remove bundled version of hunspell.
* debian/patches
  - Refresh patches.
  - Patch 10_move-helper-binaries.patch rewritten due to upstream changes.
  - Add 19_remove-bundled-clang-format.patch to fix clang-format paths.
  - Add 20_Compilation-fix-for-non-precompiled-header-builds.patch from
    upstream to fix build.
* debian/*.1
  - Remove manpages in debian/ - moved to upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
//////////////////////////////////////////////////////////////////////////////
 
3
//
 
4
// copyright            : (C) 2014 The CodeLite Team
 
5
// file name            : qmakeplugin.cpp
 
6
//
 
7
// -------------------------------------------------------------------------
 
8
// A
 
9
//              _____           _      _     _ _
 
10
//             /  __ \         | |    | |   (_) |
 
11
//             | /  \/ ___   __| | ___| |    _| |_ ___
 
12
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
 
13
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
 
14
//              \____/\___/ \__,_|\___\_____/_|\__\___|
 
15
//
 
16
//                                                  F i l e
 
17
//
 
18
//    This program is free software; you can redistribute it and/or modify
 
19
//    it under the terms of the GNU General Public License as published by
 
20
//    the Free Software Foundation; either version 2 of the License, or
 
21
//    (at your option) any later version.
 
22
//
 
23
//////////////////////////////////////////////////////////////////////////////
 
24
//////////////////////////////////////////////////////////////////////////////
 
25
 
1
26
#include <wx/app.h>
2
27
#include <wx/stdpaths.h>
3
28
#include "environmentconfig.h"
21
46
#include "qmakeconf.h"
22
47
#include "build_system.h"
23
48
#include "cl_standard_paths.h"
 
49
#include "macros.h"
 
50
#include <wx/msgdlg.h>
 
51
#include "processreaderthread.h"
 
52
#include "asyncprocess.h"
24
53
 
25
54
static QMakePlugin* thePlugin = NULL;
26
55
 
27
 
//Define the plugin entry point
28
 
extern "C" EXPORT IPlugin *CreatePlugin(IManager *manager)
 
56
// Define the plugin entry point
 
57
extern "C" EXPORT IPlugin* CreatePlugin(IManager* manager)
29
58
{
30
 
    if (thePlugin == 0) {
 
59
    if(thePlugin == 0) {
31
60
        thePlugin = new QMakePlugin(manager);
32
61
    }
33
62
    return thePlugin;
43
72
    return info;
44
73
}
45
74
 
46
 
extern "C" EXPORT int GetPluginInterfaceVersion()
47
 
{
48
 
    return PLUGIN_INTERFACE_VERSION;
49
 
}
50
 
 
51
 
QMakePlugin::QMakePlugin(IManager *manager)
 
75
extern "C" EXPORT int GetPluginInterfaceVersion() { return PLUGIN_INTERFACE_VERSION; }
 
76
 
 
77
BEGIN_EVENT_TABLE(QMakePlugin, wxEvtHandler)
 
78
EVT_COMMAND(wxID_ANY, wxEVT_PROC_DATA_READ, QMakePlugin::OnQmakeOutput)
 
79
EVT_COMMAND(wxID_ANY, wxEVT_PROC_TERMINATED, QMakePlugin::OnQmakeTerminated)
 
80
END_EVENT_TABLE()
 
81
 
 
82
QMakePlugin::QMakePlugin(IManager* manager)
52
83
    : IPlugin(manager)
 
84
    , m_qmakeProcess(NULL)
53
85
{
54
86
    m_longName = _("Qt's QMake integration with CodeLite");
55
87
    m_shortName = wxT("QMakePlugin");
56
88
 
57
 
    m_conf = new QmakeConf(clStandardPaths::Get().GetUserDataDir() + wxFileName::GetPathSeparator() + wxT("config/qmake.ini"));
58
 
 
59
 
    //Connect items
60
 
    EventNotifier::Get()->Connect(wxEVT_CMD_PROJ_SETTINGS_SAVED,  wxCommandEventHandler(QMakePlugin::OnSaveConfig     ),     NULL, this);
61
 
    EventNotifier::Get()->Connect(wxEVT_BUILD_STARTING,           clBuildEventHandler(QMakePlugin::OnBuildStarting  ),     NULL, this);
62
 
    EventNotifier::Get()->Connect(wxEVT_GET_PROJECT_BUILD_CMD,    clBuildEventHandler(QMakePlugin::OnGetBuildCommand),     NULL, this);
63
 
    EventNotifier::Get()->Connect(wxEVT_GET_PROJECT_CLEAN_CMD,    clBuildEventHandler(QMakePlugin::OnGetCleanCommand),     NULL, this);
64
 
    EventNotifier::Get()->Connect(wxEVT_GET_IS_PLUGIN_MAKEFILE,   clBuildEventHandler(QMakePlugin::OnGetIsPluginMakefile), NULL, this);
65
 
    EventNotifier::Get()->Connect(wxEVT_TREE_ITEM_FILE_ACTIVATED, wxCommandEventHandler(QMakePlugin::OnOpenFile),            NULL, this);
66
 
    EventNotifier::Get()->Connect(wxEVT_PLUGIN_EXPORT_MAKEFILE,   clBuildEventHandler(QMakePlugin::OnExportMakefile),      NULL, this);
67
 
}
68
 
 
69
 
QMakePlugin::~QMakePlugin()
70
 
{
71
 
    delete m_conf;
72
 
}
73
 
 
74
 
clToolBar *QMakePlugin::CreateToolBar(wxWindow *parent)
 
89
    m_conf = new QmakeConf(clStandardPaths::Get().GetUserDataDir() + wxFileName::GetPathSeparator() +
 
90
                           wxT("config/qmake.ini"));
 
91
 
 
92
    // Connect items
 
93
    EventNotifier::Get()->Connect(
 
94
        wxEVT_CMD_PROJ_SETTINGS_SAVED, wxCommandEventHandler(QMakePlugin::OnSaveConfig), NULL, this);
 
95
    EventNotifier::Get()->Connect(wxEVT_BUILD_STARTING, clBuildEventHandler(QMakePlugin::OnBuildStarting), NULL, this);
 
96
    EventNotifier::Get()->Connect(
 
97
        wxEVT_GET_PROJECT_BUILD_CMD, clBuildEventHandler(QMakePlugin::OnGetBuildCommand), NULL, this);
 
98
    EventNotifier::Get()->Connect(
 
99
        wxEVT_GET_PROJECT_CLEAN_CMD, clBuildEventHandler(QMakePlugin::OnGetCleanCommand), NULL, this);
 
100
    EventNotifier::Get()->Connect(
 
101
        wxEVT_GET_IS_PLUGIN_MAKEFILE, clBuildEventHandler(QMakePlugin::OnGetIsPluginMakefile), NULL, this);
 
102
    EventNotifier::Get()->Connect(
 
103
        wxEVT_TREE_ITEM_FILE_ACTIVATED, wxCommandEventHandler(QMakePlugin::OnOpenFile), NULL, this);
 
104
}
 
105
 
 
106
QMakePlugin::~QMakePlugin() { delete m_conf; }
 
107
 
 
108
clToolBar* QMakePlugin::CreateToolBar(wxWindow* parent)
75
109
{
76
110
    // Create the toolbar to be used by the plugin
77
 
    clToolBar *tb(NULL);
 
111
    clToolBar* tb(NULL);
78
112
 
79
113
    // You can use the below code a snippet:
80
114
    // First, check that CodeLite allows plugin to register plugins
81
 
    if (m_mgr->AllowToolbar()) {
 
115
    if(m_mgr->AllowToolbar()) {
82
116
        // Support both toolbars icon size
83
117
        int size = m_mgr->GetToolbarIconSize();
84
118
 
89
123
        tb->SetToolBitmapSize(wxSize(size, size));
90
124
 
91
125
        // Add tools to the plugins toolbar. You must provide 2 sets of icons: 24x24 and 16x16
92
 
        if (size == 24) {
93
 
            tb->AddTool(XRCID("qmake_settings"), _("Configure qmake"), LoadBitmapFile(wxT("qt24_preferences.png")), _("Configure qmake"));
94
 
            tb->AddTool(XRCID("new_qmake_project"), _("Create new qmake based project"), LoadBitmapFile(wxT("qt24_new.png")), _("Create new qmake based project"));
 
126
        if(size == 24) {
 
127
            tb->AddTool(XRCID("qmake_settings"),
 
128
                        _("Configure qmake"),
 
129
                        LoadBitmapFile(wxT("qt24_preferences.png")),
 
130
                        _("Configure qmake"));
 
131
            tb->AddTool(XRCID("new_qmake_project"),
 
132
                        _("Create new qmake based project"),
 
133
                        LoadBitmapFile(wxT("qt24_new.png")),
 
134
                        _("Create new qmake based project"));
95
135
        } else {
96
 
            tb->AddTool(XRCID("qmake_settings"), _("Configure qmake"), LoadBitmapFile(wxT("qt16_preferences.png")), _("Configure qmake"));
97
 
            tb->AddTool(XRCID("new_qmake_project"), _("Create new qmake based project"), LoadBitmapFile(wxT("qt16_new.png")), _("Create new qmake based project"));
 
136
            tb->AddTool(XRCID("qmake_settings"),
 
137
                        _("Configure qmake"),
 
138
                        LoadBitmapFile(wxT("qt16_preferences.png")),
 
139
                        _("Configure qmake"));
 
140
            tb->AddTool(XRCID("new_qmake_project"),
 
141
                        _("Create new qmake based project"),
 
142
                        LoadBitmapFile(wxT("qt16_new.png")),
 
143
                        _("Create new qmake based project"));
98
144
        }
99
145
        // And finally, we must call 'Realize()'
100
146
        tb->Realize();
106
152
    return tb;
107
153
}
108
154
 
109
 
void QMakePlugin::CreatePluginMenu(wxMenu *pluginsMenu)
 
155
void QMakePlugin::CreatePluginMenu(wxMenu* pluginsMenu)
110
156
{
111
157
    // You can use the below code a snippet:
112
 
    wxMenu *menu = new wxMenu();
113
 
    wxMenuItem *item(NULL);
114
 
    item = new wxMenuItem(menu, XRCID("new_qmake_project"), _("New qmake based project..."), wxEmptyString, wxITEM_NORMAL);
 
158
    wxMenu* menu = new wxMenu();
 
159
    wxMenuItem* item(NULL);
 
160
    item =
 
161
        new wxMenuItem(menu, XRCID("new_qmake_project"), _("New qmake based project..."), wxEmptyString, wxITEM_NORMAL);
115
162
    menu->Append(item);
116
163
 
117
164
    item = new wxMenuItem(menu, XRCID("qmake_settings"), _("Settings..."), wxEmptyString, wxITEM_NORMAL);
119
166
 
120
167
    pluginsMenu->Append(wxID_ANY, wxT("QMake"), menu);
121
168
 
122
 
    m_mgr->GetTheApp()->Connect(XRCID("new_qmake_project"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QMakePlugin::OnNewQmakeBasedProject), NULL, (wxEvtHandler*)this);
123
 
    m_mgr->GetTheApp()->Connect(XRCID("qmake_settings"), wxEVT_COMMAND_MENU_SELECTED,    wxCommandEventHandler(QMakePlugin::OnSettings), NULL, (wxEvtHandler*)this);
 
169
    wxTheApp->Connect(XRCID("new_qmake_project"),
 
170
                      wxEVT_COMMAND_MENU_SELECTED,
 
171
                      wxCommandEventHandler(QMakePlugin::OnNewQmakeBasedProject),
 
172
                      NULL,
 
173
                      (wxEvtHandler*)this);
 
174
    wxTheApp->Connect(XRCID("qmake_settings"),
 
175
                      wxEVT_COMMAND_MENU_SELECTED,
 
176
                      wxCommandEventHandler(QMakePlugin::OnSettings),
 
177
                      NULL,
 
178
                      (wxEvtHandler*)this);
 
179
    wxTheApp->Connect(XRCID("qmake_run_qmake"),
 
180
                      wxEVT_COMMAND_MENU_SELECTED,
 
181
                      wxCommandEventHandler(QMakePlugin::OnExportMakefile),
 
182
                      NULL,
 
183
                      this);
124
184
}
125
185
 
126
 
void QMakePlugin::HookPopupMenu(wxMenu *menu, MenuType type)
 
186
void QMakePlugin::HookPopupMenu(wxMenu* menu, MenuType type)
127
187
{
128
 
    wxUnusedVar( menu );
129
 
    wxUnusedVar( type );
 
188
    if(type == MenuTypeFileView_Project) {
 
189
        if(!menu->FindItem(XRCID("qmake_run_qmake"))) {
 
190
            menu->PrependSeparator();
 
191
            menu->Prepend(XRCID("qmake_run_qmake"), _("Run qmake..."), _("Run qmake..."));
 
192
        }
 
193
    }
130
194
}
131
195
 
132
196
void QMakePlugin::UnPlug()
133
197
{
134
 
    EventNotifier::Get()->Disconnect(wxEVT_CMD_PROJ_SETTINGS_SAVED,  wxCommandEventHandler(QMakePlugin::OnSaveConfig     ),     NULL, this);
135
 
    EventNotifier::Get()->Disconnect(wxEVT_BUILD_STARTING,           clBuildEventHandler(QMakePlugin::OnBuildStarting  ),     NULL, this);
136
 
    EventNotifier::Get()->Disconnect(wxEVT_GET_PROJECT_BUILD_CMD,    clBuildEventHandler(QMakePlugin::OnGetBuildCommand),     NULL, this);
137
 
    EventNotifier::Get()->Disconnect(wxEVT_GET_PROJECT_CLEAN_CMD,    clBuildEventHandler(QMakePlugin::OnGetCleanCommand),     NULL, this);
138
 
    EventNotifier::Get()->Disconnect(wxEVT_GET_IS_PLUGIN_MAKEFILE,   clBuildEventHandler(QMakePlugin::OnGetIsPluginMakefile), NULL, this);
139
 
    EventNotifier::Get()->Disconnect(wxEVT_TREE_ITEM_FILE_ACTIVATED, wxCommandEventHandler(QMakePlugin::OnOpenFile),            NULL, this);
140
 
    EventNotifier::Get()->Disconnect(wxEVT_PLUGIN_EXPORT_MAKEFILE,   clBuildEventHandler(QMakePlugin::OnExportMakefile),      NULL, this);
141
 
    wxTheApp->Disconnect(XRCID("new_qmake_project"), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(QMakePlugin::OnNewQmakeBasedProject), NULL, (wxEvtHandler*)this);
142
 
    wxTheApp->Disconnect(XRCID("qmake_settings"), wxEVT_COMMAND_MENU_SELECTED,    wxCommandEventHandler(QMakePlugin::OnSettings), NULL, (wxEvtHandler*)this);
 
198
    EventNotifier::Get()->Disconnect(
 
199
        wxEVT_CMD_PROJ_SETTINGS_SAVED, wxCommandEventHandler(QMakePlugin::OnSaveConfig), NULL, this);
 
200
    EventNotifier::Get()->Disconnect(
 
201
        wxEVT_BUILD_STARTING, clBuildEventHandler(QMakePlugin::OnBuildStarting), NULL, this);
 
202
    EventNotifier::Get()->Disconnect(
 
203
        wxEVT_GET_PROJECT_BUILD_CMD, clBuildEventHandler(QMakePlugin::OnGetBuildCommand), NULL, this);
 
204
    EventNotifier::Get()->Disconnect(
 
205
        wxEVT_GET_PROJECT_CLEAN_CMD, clBuildEventHandler(QMakePlugin::OnGetCleanCommand), NULL, this);
 
206
    EventNotifier::Get()->Disconnect(
 
207
        wxEVT_GET_IS_PLUGIN_MAKEFILE, clBuildEventHandler(QMakePlugin::OnGetIsPluginMakefile), NULL, this);
 
208
    EventNotifier::Get()->Disconnect(
 
209
        wxEVT_TREE_ITEM_FILE_ACTIVATED, wxCommandEventHandler(QMakePlugin::OnOpenFile), NULL, this);
 
210
    wxTheApp->Disconnect(XRCID("new_qmake_project"),
 
211
                         wxEVT_COMMAND_MENU_SELECTED,
 
212
                         wxCommandEventHandler(QMakePlugin::OnNewQmakeBasedProject),
 
213
                         NULL,
 
214
                         (wxEvtHandler*)this);
 
215
    wxTheApp->Disconnect(XRCID("qmake_settings"),
 
216
                         wxEVT_COMMAND_MENU_SELECTED,
 
217
                         wxCommandEventHandler(QMakePlugin::OnSettings),
 
218
                         NULL,
 
219
                         (wxEvtHandler*)this);
 
220
    wxTheApp->Disconnect(XRCID("qmake_run_qmake"),
 
221
                         wxEVT_COMMAND_MENU_SELECTED,
 
222
                         wxCommandEventHandler(QMakePlugin::OnExportMakefile),
 
223
                         NULL,
 
224
                         this);
143
225
}
144
226
 
145
 
void QMakePlugin::HookProjectSettingsTab(wxBookCtrlBase* book, const wxString &projectName, const wxString &configName)
 
227
void QMakePlugin::HookProjectSettingsTab(wxBookCtrlBase* book, const wxString& projectName, const wxString& configName)
146
228
{
147
 
    if ( !book ) return;
 
229
    if(!book)
 
230
        return;
148
231
 
149
232
    DoUnHookAllTabs(book);
150
233
 
151
 
    QMakeTab *page = DoGetQmakeTab(configName);
152
 
    if (! page ) {
 
234
    QMakeTab* page = DoGetQmakeTab(configName);
 
235
    if(!page) {
153
236
        page = new QMakeTab(book, m_conf);
154
237
        page->Load(m_mgr, projectName, configName);
155
238
        m_pages[configName] = page;
157
240
    book->AddPage(page, wxT("QMake"), true, wxNOT_FOUND);
158
241
}
159
242
 
160
 
void QMakePlugin::UnHookProjectSettingsTab(wxBookCtrlBase* book, const wxString &projectName, const wxString &configName)
 
243
void
 
244
    QMakePlugin::UnHookProjectSettingsTab(wxBookCtrlBase* book, const wxString& projectName, const wxString& configName)
161
245
{
162
 
    wxUnusedVar( configName );
 
246
    wxUnusedVar(configName);
163
247
    DoUnHookAllTabs(book);
164
248
}
165
249
 
167
251
{
168
252
    event.Skip();
169
253
 
170
 
    wxString *proj = (wxString *)event.GetClientData();
 
254
    wxString* proj = (wxString*)event.GetClientData();
171
255
 
172
256
    wxString conf, project;
173
257
    project = *proj;
174
 
    conf    = event.GetString();
 
258
    conf = event.GetString();
175
259
 
176
 
    QMakeTab *tab = DoGetQmakeTab( conf );
177
 
    if ( !tab ) {
 
260
    QMakeTab* tab = DoGetQmakeTab(conf);
 
261
    if(!tab) {
178
262
        return;
179
263
    }
180
264
    tab->Save(m_mgr, project, conf);
183
267
QMakeTab* QMakePlugin::DoGetQmakeTab(const wxString& config)
184
268
{
185
269
    std::map<wxString, QMakeTab*>::iterator iter = m_pages.find(config);
186
 
    if (iter == m_pages.end()) {
 
270
    if(iter == m_pages.end()) {
187
271
        return NULL;
188
272
    }
189
273
    return iter->second;
191
275
 
192
276
void QMakePlugin::DoUnHookAllTabs(wxBookCtrlBase* book)
193
277
{
194
 
    if ( !book ) {
 
278
    if(!book) {
195
279
        return;
196
280
    }
197
281
 
198
 
    for (size_t i=0 ; i<book->GetPageCount(); i++) {
 
282
    for(size_t i = 0; i < book->GetPageCount(); i++) {
199
283
        std::map<wxString, QMakeTab*>::iterator iter = m_pages.begin();
200
 
        for (; iter != m_pages.end(); iter++) {
201
 
            if (book->GetPage(i) == iter->second) {
 
284
        for(; iter != m_pages.end(); iter++) {
 
285
            if(book->GetPage(i) == iter->second) {
202
286
                book->RemovePage(i);
203
287
                iter->second->Destroy();
204
288
                m_pages.erase(iter);
221
305
    event.Skip();
222
306
 
223
307
    QmakePluginData::BuildConfPluginData bcpd;
224
 
    wxString  project = event.GetProjectName();
225
 
    wxString  config  = event.GetConfigurationName();
226
 
 
227
 
    if ( !DoGetData(project, config, bcpd) ) {
228
 
        return;
229
 
    }
230
 
 
231
 
    if ( !bcpd.m_enabled ) {
232
 
        return;
233
 
    }
 
308
    wxString project = event.GetProjectName();
 
309
    wxString config = event.GetConfigurationName();
 
310
 
 
311
    if(!DoGetData(project, config, bcpd)) {
 
312
        return;
 
313
    }
 
314
 
 
315
    if(!bcpd.m_enabled) {
 
316
        return;
 
317
    }
 
318
 
 
319
    // OK this is a qmake project
 
320
    event.Skip(false);
234
321
 
235
322
    wxString errMsg;
236
323
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
237
 
    if ( !p ) {
 
324
    if(!p) {
238
325
        return;
239
326
    }
240
327
    QMakeProFileGenerator generator(m_mgr, project, config);
241
 
 
242
 
    // regenrate the .pro file
243
 
    bool needRegeneration = generator.Generate();
244
 
 
245
 
    wxString qmake_exe = m_conf->Read(wxString::Format(wxT("%s/qmake"),     bcpd.m_qmakeConfig.c_str()));
246
 
    wxString qmakespec = m_conf->Read(wxString::Format(wxT("%s/qmakespec"), bcpd.m_qmakeConfig.c_str()));
247
 
    wxString qtdir     = m_conf->Read(wxString::Format(wxT("%s/qtdir"),     bcpd.m_qmakeConfig.c_str()));
248
 
 
249
 
    // Create qmake comand
250
 
    wxString qmake_exe_line;
251
 
    qmake_exe.Trim().Trim(false);
252
 
    qmakespec.Trim().Trim(false);
253
 
 
254
 
    // Set QTDIR
255
 
    DirSaver ds;
256
 
    {
257
 
 
258
 
        wxSetWorkingDirectory ( p->GetFileName().GetPath(wxPATH_GET_SEPARATOR|wxPATH_GET_VOLUME) );
259
 
        wxSetEnv(wxT("QTDIR"), qtdir);
260
 
        qmake_exe_line << wxT("\"") << qmake_exe << wxT("\" -spec ") << qmakespec << wxT(" ") << generator.GetProFileName();
261
 
 
262
 
        if ( needRegeneration ) {
263
 
            wxArrayString output;
264
 
            ProcUtils::SafeExecuteCommand(qmake_exe_line, output);
265
 
        }
266
 
 
 
328
    if(!wxFileName::Exists(generator.GetProFileName())) {
 
329
        // alert and return
 
330
        ::wxMessageBox(_("Could not locate pro file.\nDid you remember to run qmake? (right click on the project"),
 
331
                       "QMake",
 
332
                       wxICON_WARNING | wxCENTER);
 
333
        return;
 
334
    } else {
 
335
        event.Skip();
267
336
    }
268
337
}
269
338
 
270
 
bool QMakePlugin::DoGetData(const wxString& project, const wxString& conf, QmakePluginData::BuildConfPluginData &bcpd)
 
339
bool QMakePlugin::DoGetData(const wxString& project, const wxString& conf, QmakePluginData::BuildConfPluginData& bcpd)
271
340
{
272
341
    wxString errMsg;
273
342
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
274
 
    if ( p ) {
 
343
    if(p) {
275
344
        wxString rawData = p->GetPluginData(wxT("qmake"));
276
 
        QmakePluginData pd( rawData );
 
345
        QmakePluginData pd(rawData);
277
346
        return pd.GetDataForBuildConf(conf, bcpd);
278
347
    }
279
348
    return false;
283
352
{
284
353
    QmakePluginData::BuildConfPluginData bcpd;
285
354
 
286
 
    wxString  project = event.GetProjectName();
287
 
    wxString  config  = event.GetConfigurationName();
288
 
 
289
 
    if ( !DoGetData(project, config, bcpd) ) {
290
 
        event.Skip();
291
 
        return;
292
 
    }
293
 
 
294
 
    if ( !bcpd.m_enabled ) {
295
 
        event.Skip();
296
 
        return;
297
 
    }
298
 
 
299
 
    event.SetCommand( DoGetBuildCommand(project, config, event.IsProjectOnly()) + wxT(" clean") );
 
355
    wxString project = event.GetProjectName();
 
356
    wxString config = event.GetConfigurationName();
 
357
 
 
358
    if(!DoGetData(project, config, bcpd)) {
 
359
        event.Skip();
 
360
        return;
 
361
    }
 
362
 
 
363
    if(!bcpd.m_enabled) {
 
364
        event.Skip();
 
365
        return;
 
366
    }
 
367
 
 
368
    event.SetCommand(DoGetBuildCommand(project, config, event.IsProjectOnly()) + wxT(" clean"));
300
369
}
301
370
 
302
371
void QMakePlugin::OnGetBuildCommand(clBuildEvent& event)
303
372
{
304
373
    QmakePluginData::BuildConfPluginData bcpd;
305
374
 
306
 
    wxString  project = event.GetProjectName();
307
 
    wxString  config  = event.GetConfigurationName();
 
375
    wxString project = event.GetProjectName();
 
376
    wxString config = event.GetConfigurationName();
308
377
 
309
 
    if ( !DoGetData(project, config, bcpd) ) {
 
378
    if(!DoGetData(project, config, bcpd)) {
310
379
        event.Skip();
311
380
        return;
312
381
    }
313
382
 
314
 
    if ( !bcpd.m_enabled ) {
 
383
    if(!bcpd.m_enabled) {
315
384
        event.Skip();
316
385
        return;
317
386
    }
318
387
 
319
388
    // we avoid calling event.Skip() to override the default build system by this one
320
 
    event.SetCommand( DoGetBuildCommand(project, config, event.IsProjectOnly()) );
 
389
    event.SetCommand(DoGetBuildCommand(project, config, event.IsProjectOnly()));
321
390
}
322
391
 
323
392
void QMakePlugin::OnGetIsPluginMakefile(clBuildEvent& event)
325
394
    QmakePluginData::BuildConfPluginData bcpd;
326
395
 
327
396
    wxString project = event.GetProjectName();
328
 
    wxString config  = event.GetConfigurationName();
 
397
    wxString config = event.GetConfigurationName();
329
398
 
330
 
    if ( !DoGetData(project, config, bcpd) ) {
 
399
    if(!DoGetData(project, config, bcpd)) {
331
400
        event.Skip();
332
401
        return;
333
402
    }
334
403
 
335
 
    if ( bcpd.m_enabled ) {
 
404
    if(bcpd.m_enabled) {
336
405
        // return without calling event.Skip()
337
406
        return;
338
407
    }
339
408
    event.Skip();
340
409
}
341
410
 
342
 
wxString QMakePlugin::DoGetBuildCommand(const wxString &project, const wxString &config, bool projectOnly)
 
411
wxString QMakePlugin::DoGetBuildCommand(const wxString& project, const wxString& config, bool projectOnly)
343
412
{
344
 
    wxUnusedVar ( config );
 
413
    wxUnusedVar(config);
345
414
 
346
415
    wxString errMsg;
347
416
    ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
348
 
    if ( !p ) {
 
417
    if(!p) {
349
418
        return wxEmptyString;
350
419
    }
351
 
    
 
420
 
352
421
    BuildConfigPtr bldConf = WorkspaceST::Get()->GetProjBuildConf(project, config);
353
 
    
354
422
 
355
423
    wxString cmd;
356
424
 
357
 
    if ( !projectOnly ) {
 
425
    wxString projectMakefile;
 
426
    projectMakefile << p->GetName() << ".mk";
 
427
    ::WrapWithQuotes(projectMakefile);
 
428
    projectMakefile.Replace("\\", "/");
 
429
 
 
430
    if(!projectOnly) {
 
431
        // part of a greater makefile, use $(MAKE)
358
432
        cmd << wxT("@cd \"") << p->GetFileName().GetPath() << wxT("\" && ");
 
433
        cmd << "$(MAKE) -f " << projectMakefile;
 
434
    } else {
 
435
        // project only
 
436
        cmd = bldConf->GetCompiler()->GetTool("MAKE");
 
437
        if(!cmd.Contains("-f")) {
 
438
            cmd << " -f ";
 
439
        }
 
440
        cmd << " " << projectMakefile;
359
441
    }
360
 
    
361
 
    // fix: replace all Windows like slashes to POSIX
362
 
    wxString command = bldConf->GetCompiler()->GetTool("MAKE");
363
 
    command.Replace(wxT("\\"), wxT("/"));
364
 
    
365
 
    cmd << command << wxT(" \"") << p->GetName() << wxT(".mk\"");
366
442
    return cmd;
367
443
}
368
444
 
369
445
void QMakePlugin::OnNewQmakeBasedProject(wxCommandEvent& event)
370
446
{
371
 
    wxUnusedVar ( event );
372
 
    if (m_conf->GetAllConfigurations().IsEmpty()) {
373
 
        wxMessageBox(_("There is no qmake defined, please define one from 'Plugins -> Qmake -> Settings'"), _("CodeLite"), wxOK|wxICON_WARNING|wxCENTER, m_mgr->GetTheApp()->GetTopWindow());
 
447
    wxUnusedVar(event);
 
448
    if(m_conf->GetAllConfigurations().IsEmpty()) {
 
449
        wxMessageBox(_("There is no qmake defined, please define one from 'Plugins -> Qmake -> Settings'"),
 
450
                     _("CodeLite"),
 
451
                     wxOK | wxICON_WARNING | wxCENTER,
 
452
                     m_mgr->GetTheApp()->GetTopWindow());
374
453
        return;
375
454
    }
376
455
 
377
456
    NewQtProjDlg dlg(m_mgr->GetTheApp()->GetTopWindow(), m_conf, m_mgr);
378
 
    if (dlg.ShowModal() == wxID_OK) {
379
 
        wxString kind         = dlg.GetProjectKind();
380
 
        wxString name         = dlg.GetProjectName();
381
 
        wxString path         = dlg.GetProjectPath();
382
 
        wxString configRelease= wxT("0000");
383
 
        wxString config       = wxT("0000");
 
457
    if(dlg.ShowModal() == wxID_OK) {
 
458
        wxString kind = dlg.GetProjectKind();
 
459
        wxString name = dlg.GetProjectName();
 
460
        wxString path = dlg.GetProjectPath();
 
461
        wxString configRelease = wxT("0000");
 
462
        wxString config = wxT("0000");
384
463
        wxString templateFile = m_mgr->GetStartupDirectory();
385
 
        wxString type         = wxEmptyString;
386
 
        wxString qmakeSettings= dlg.GetQmake();
 
464
        wxString type = wxEmptyString;
 
465
        wxString qmakeSettings = dlg.GetQmake();
387
466
        wxString qmake;
388
467
        wxString content;
389
468
 
390
 
        if ( kind == wxT("Static Library") ) {
 
469
        if(kind == wxT("Static Library")) {
391
470
 
392
471
            type = Project::STATIC_LIBRARY;
393
472
 
394
 
        } else if ( kind == wxT("Dynamic Library") ) {
 
473
        } else if(kind == wxT("Dynamic Library")) {
395
474
 
396
475
            type = Project::DYNAMIC_LIBRARY;
397
476
 
398
 
        } else if ( kind == wxT("Console") ) {
 
477
        } else if(kind == wxT("Console")) {
399
478
 
400
479
            type = Project::EXECUTABLE;
401
480
            configRelease = wxT("0017CONFIG += console");
402
 
            config        = wxT("0023CONFIG += console debug");
 
481
            config = wxT("0023CONFIG += console debug");
403
482
 
404
483
        } else {
405
484
 
406
485
            type = Project::EXECUTABLE;
407
 
            config        = wxT("0015CONFIG += debug");
 
486
            config = wxT("0015CONFIG += debug");
408
487
            configRelease = wxT("0000");
409
488
        }
410
489
 
411
490
        wxString filename(m_mgr->GetStartupDirectory() + wxT("/templates/qmake/qmake.project"));
412
 
        if (!ReadFileWithConversion(filename, content)) {
 
491
        if(!ReadFileWithConversion(filename, content)) {
413
492
            return;
414
493
        }
415
494
 
416
495
        // prepend the string lenght
417
496
        qmake = wxString::Format(wxT("%04d%s"), qmakeSettings.Length(), qmakeSettings.c_str());
418
497
 
419
 
 
420
 
        content.Replace(wxT("$(TYPE)")  ,         type);
421
 
        content.Replace(wxT("$(NAME)")  ,         name);
422
 
        content.Replace(wxT("$(CONFIG)"),         config);
 
498
        content.Replace(wxT("$(TYPE)"), type);
 
499
        content.Replace(wxT("$(NAME)"), name);
 
500
        content.Replace(wxT("$(CONFIG)"), config);
423
501
        content.Replace(wxT("$(RELEASE_CONFIG)"), configRelease);
424
 
        content.Replace(wxT("$(QMAKE)"),          qmake);
 
502
        content.Replace(wxT("$(QMAKE)"), qmake);
425
503
 
426
 
        //save the file to the disk
 
504
        // save the file to the disk
427
505
        {
428
506
            DirSaver ds;
429
 
            if ( !wxSetWorkingDirectory(path) ) {
430
 
                wxMessageBox(_("Invalid project path!"), _("CodeLite"), wxOK|wxCENTER|wxICON_WARNING);
 
507
            if(!wxSetWorkingDirectory(path)) {
 
508
                wxMessageBox(_("Invalid project path!"), _("CodeLite"), wxOK | wxCENTER | wxICON_WARNING);
431
509
                return;
432
510
            }
433
511
 
434
 
            if ( dlg.GetCreateDirectory() ) {
 
512
            if(dlg.GetCreateDirectory()) {
435
513
                wxMkdir(name);
436
514
                wxSetWorkingDirectory(name);
437
515
            }
438
516
 
439
 
            if ( !WriteFileWithBackup(name + wxT(".project"), content, false) ) {
440
 
                wxMessageBox(wxString::Format(_("Failed to create .project file '%s'"), wxString(name + wxT(".project")).c_str()),
441
 
                             _("CodeLite"), wxOK|wxCENTER|wxICON_WARNING);
 
517
            if(!WriteFileWithBackup(name + wxT(".project"), content, false)) {
 
518
                wxMessageBox(wxString::Format(_("Failed to create .project file '%s'"),
 
519
                                              wxString(name + wxT(".project")).c_str()),
 
520
                             _("CodeLite"),
 
521
                             wxOK | wxCENTER | wxICON_WARNING);
442
522
                return;
443
523
            }
444
524
 
450
530
    }
451
531
}
452
532
 
453
 
void QMakePlugin::OnOpenFile(wxCommandEvent &event)
 
533
void QMakePlugin::OnOpenFile(wxCommandEvent& event)
454
534
{
455
 
    wxString *fn = (wxString*)event.GetClientData();
456
 
    if ( fn ) {
 
535
    wxString* fn = (wxString*)event.GetClientData();
 
536
    if(fn) {
457
537
        // launch it with the default application
458
 
        wxFileName fullpath ( *fn );
459
 
        if ( fullpath.GetExt().MakeLower() != wxT("ui") ) {
 
538
        wxFileName fullpath(*fn);
 
539
        if(fullpath.GetExt().MakeLower() != wxT("ui")) {
460
540
            event.Skip();
461
541
            return;
462
542
        }
463
543
 
464
 
        wxMimeTypesManager *mgr = wxTheMimeTypesManager;
465
 
        wxFileType *type = mgr->GetFileTypeFromExtension(fullpath.GetExt());
466
 
        if ( type ) {
 
544
        wxMimeTypesManager* mgr = wxTheMimeTypesManager;
 
545
        wxFileType* type = mgr->GetFileTypeFromExtension(fullpath.GetExt());
 
546
        if(type) {
467
547
            wxString cmd = type->GetOpenCommand(fullpath.GetFullPath());
468
548
            delete type;
469
549
 
470
 
            if ( cmd.IsEmpty() == false ) {
 
550
            if(cmd.IsEmpty() == false) {
471
551
                wxExecute(cmd);
472
552
                return;
473
553
            }
477
557
    event.Skip();
478
558
}
479
559
 
480
 
void QMakePlugin::OnExportMakefile(clBuildEvent& event)
 
560
void QMakePlugin::OnExportMakefile(wxCommandEvent& event)
481
561
{
 
562
    if(m_qmakeProcess)
 
563
        return;
 
564
 
482
565
    QmakePluginData::BuildConfPluginData bcpd;
483
566
 
484
 
    wxString  project = event.GetProjectName();
485
 
    wxString  config  = event.GetConfigurationName();
486
 
 
487
 
    if ( !DoGetData(project, config, bcpd) ) {
 
567
    ProjectPtr pProj = m_mgr->GetSelectedProject();
 
568
    CHECK_PTR_RET(pProj);
 
569
 
 
570
    BuildConfigPtr bldConf = pProj->GetBuildConfiguration();
 
571
    CHECK_PTR_RET(bldConf);
 
572
 
 
573
    wxString project = pProj->GetName();
 
574
    wxString config = bldConf->GetName();
 
575
 
 
576
    if(!DoGetData(project, config, bcpd)) {
488
577
        event.Skip();
489
578
        return;
490
579
    }
491
580
 
492
 
    if ( bcpd.m_enabled ) {
 
581
    if(bcpd.m_enabled) {
493
582
        // This project/configuration is qmake project
494
583
        QMakeProFileGenerator generator(m_mgr, project, config);
495
584
 
497
586
        generator.Generate();
498
587
 
499
588
        // run qmake
500
 
        wxString qmake_exe = m_conf->Read(wxString::Format(wxT("%s/qmake"),     bcpd.m_qmakeConfig.c_str()));
 
589
        wxString qmake_exe = m_conf->Read(wxString::Format(wxT("%s/qmake"), bcpd.m_qmakeConfig.c_str()));
501
590
        wxString qmakespec = m_conf->Read(wxString::Format(wxT("%s/qmakespec"), bcpd.m_qmakeConfig.c_str()));
502
 
        wxString qtdir     = m_conf->Read(wxString::Format(wxT("%s/qtdir"),     bcpd.m_qmakeConfig.c_str()));
 
591
        wxString qtdir = m_conf->Read(wxString::Format(wxT("%s/qtdir"), bcpd.m_qmakeConfig.c_str()));
503
592
 
504
593
        // Create qmake comand
505
594
        wxString qmake_exe_line;
512
601
 
513
602
            wxString errMsg;
514
603
            ProjectPtr p = m_mgr->GetWorkspace()->FindProjectByName(project, errMsg);
515
 
            if ( !p ) {
 
604
            if(!p) {
516
605
                return;
517
606
            }
518
607
 
519
 
            wxSetWorkingDirectory ( p->GetFileName().GetPath(wxPATH_GET_SEPARATOR|wxPATH_GET_VOLUME) );
520
 
            wxSetEnv(wxT("QTDIR"), qtdir);
521
 
            qmake_exe_line << wxT("\"") << qmake_exe << wxT("\" -spec ") << qmakespec << wxT(" ") << generator.GetProFileName();
522
 
 
523
 
            wxArrayString output;
524
 
            ProcUtils::SafeExecuteCommand(qmake_exe_line, output);
 
608
            qmake_exe_line << wxT("\"") << qmake_exe << wxT("\" -spec ") << qmakespec << wxT(" ")
 
609
                           << generator.GetProFileName();
 
610
            wxStringMap_t om;
 
611
            om.insert(std::make_pair("QTDIR", qtdir));
 
612
            EnvSetter envGuard(NULL, &om, project);
 
613
            m_mgr->ClearOutputTab(kOutputTab_Build);
 
614
            m_mgr->AppendOutputTabText(kOutputTab_Build, wxString() << "-- " << qmake_exe_line << "\n");
 
615
            m_qmakeProcess =
 
616
                ::CreateAsyncProcess(this, qmake_exe_line, IProcessCreateDefault, p->GetFileName().GetPath());
525
617
        }
526
618
    }
527
619
    event.Skip();
528
620
}
 
621
 
 
622
void QMakePlugin::OnQmakeOutput(wxCommandEvent& event)
 
623
{
 
624
    ProcessEventData* ped = static_cast<ProcessEventData*>(event.GetClientData());
 
625
    m_mgr->AppendOutputTabText(kOutputTab_Build, ped->GetData());
 
626
    wxDELETE(ped);
 
627
}
 
628
 
 
629
void QMakePlugin::OnQmakeTerminated(wxCommandEvent& event)
 
630
{
 
631
    ProcessEventData* ped = static_cast<ProcessEventData*>(event.GetClientData());
 
632
    wxDELETE(ped);
 
633
    wxDELETE(m_qmakeProcess);
 
634
    m_mgr->AppendOutputTabText(kOutputTab_Build, "-- done\n");
 
635
}