1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
8
** Commercial License Usage
9
** Licensees holding valid commercial Qt licenses may use this file in
10
** accordance with the commercial license agreement provided with the
11
** Software or, alternatively, in accordance with the terms contained in
12
** a written agreement between you and Digia. For licensing terms and
13
** conditions see http://qt.digia.com/licensing. For further information
14
** use the contact form at http://qt.digia.com/contact-us.
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Digia gives you certain additional
25
** rights. These rights are described in the Digia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
****************************************************************************/
30
#include "qt4projectmanagerplugin.h"
32
#include "qt4projectmanager.h"
34
#include "qmakestep.h"
36
#include "qt4buildconfiguration.h"
37
#include "wizards/consoleappwizard.h"
38
#include "wizards/guiappwizard.h"
39
#include "wizards/librarywizard.h"
40
#include "wizards/testwizard.h"
41
#include "wizards/emptyprojectwizard.h"
42
#include "wizards/subdirsprojectwizard.h"
43
#include "wizards/qtquickappwizard.h"
44
#include "wizards/html5appwizard.h"
45
#include "customwidgetwizard/customwidgetwizard.h"
46
#include "profileeditorfactory.h"
47
#include "profilehoverhandler.h"
48
#include "qt4projectmanagerconstants.h"
49
#include "qt4project.h"
50
#include "externaleditors.h"
51
#include "profilecompletionassist.h"
52
#include "qt-desktop/qt4runconfiguration.h"
53
#include "qt-desktop/desktopqtversionfactory.h"
54
#include "qt-desktop/simulatorqtversionfactory.h"
55
#include "winceqtversionfactory.h"
56
#include "unconfiguredprojectpanel.h"
57
#include "qmakekitinformation.h"
59
#include <coreplugin/icore.h>
60
#include <projectexplorer/buildmanager.h>
61
#include <projectexplorer/session.h>
62
#include <projectexplorer/projectexplorer.h>
63
#include <projectexplorer/target.h>
64
#include <coreplugin/mimedatabase.h>
65
#include <coreplugin/coreconstants.h>
66
#include <coreplugin/actionmanager/actionmanager.h>
67
#include <coreplugin/actionmanager/actioncontainer.h>
68
#include <coreplugin/editormanager/editormanager.h>
69
#include <coreplugin/editormanager/ieditor.h>
70
#include <texteditor/texteditoractionhandler.h>
71
#include <texteditor/texteditorconstants.h>
72
#include <utils/hostosinfo.h>
73
#include <utils/parameteraction.h>
81
using namespace Qt4ProjectManager::Internal;
82
using namespace Qt4ProjectManager;
83
using ProjectExplorer::Project;
85
Qt4ProjectManagerPlugin::Qt4ProjectManagerPlugin()
86
: m_previousStartupProject(0), m_previousTarget(0)
91
Qt4ProjectManagerPlugin::~Qt4ProjectManagerPlugin()
93
//removeObject(m_embeddedPropertiesPage);
94
//delete m_embeddedPropertiesPage;
96
removeObject(m_proFileEditorFactory);
97
delete m_proFileEditorFactory;
98
removeObject(m_qt4ProjectManager);
99
delete m_qt4ProjectManager;
102
bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
105
const Core::Context projectContext(Qt4ProjectManager::Constants::PROJECT_ID);
106
Core::Context projecTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE);
108
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":qt4projectmanager/Qt4ProjectManager.mimetypes.xml"), errorMessage))
111
m_projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
113
//create and register objects
114
m_qt4ProjectManager = new Qt4Manager(this);
115
addObject(m_qt4ProjectManager);
117
TextEditor::TextEditorActionHandler *editorHandler
118
= new TextEditor::TextEditorActionHandler(Constants::C_PROFILEEDITOR,
119
TextEditor::TextEditorActionHandler::UnCommentSelection
120
| TextEditor::TextEditorActionHandler::JumpToFileUnderCursor);
122
m_proFileEditorFactory = new ProFileEditorFactory(m_qt4ProjectManager, editorHandler);
124
ProjectExplorer::KitManager::instance()->registerKitInformation(new QmakeKitInformation);
126
addObject(m_proFileEditorFactory);
128
addAutoReleasedObject(new EmptyProjectWizard);
129
addAutoReleasedObject(new SubdirsProjectWizard);
130
addAutoReleasedObject(new GuiAppWizard);
131
addAutoReleasedObject(new ConsoleAppWizard);
132
QtQuickAppWizard::createInstances(this); //creates several instances with different options
133
addAutoReleasedObject(new Html5AppWizard);
134
addAutoReleasedObject(new LibraryWizard);
135
addAutoReleasedObject(new TestWizard);
136
addAutoReleasedObject(new CustomWidgetWizard);
138
CustomQt4ProjectWizard::registerSelf();
140
addAutoReleasedObject(new QMakeStepFactory);
141
addAutoReleasedObject(new MakeStepFactory);
143
addAutoReleasedObject(new Qt4BuildConfigurationFactory);
144
addAutoReleasedObject(new Qt4RunConfigurationFactory);
146
if (Utils::HostOsInfo::isMacHost())
147
addAutoReleasedObject(new MacDesignerExternalEditor);
149
addAutoReleasedObject(new DesignerExternalEditor);
150
addAutoReleasedObject(new LinguistExternalEditor);
152
addAutoReleasedObject(new DesktopQtVersionFactory);
153
addAutoReleasedObject(new SimulatorQtVersionFactory);
154
addAutoReleasedObject(new WinCeQtVersionFactory);
156
addAutoReleasedObject(new ProFileCompletionAssistProvider);
157
addAutoReleasedObject(new ProFileHoverHandler(this));
158
addAutoReleasedObject(new UnconfiguredProjectPanel);
161
Core::ActionContainer *mbuild =
162
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT);
163
Core::ActionContainer *mproject =
164
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
165
Core::ActionContainer *msubproject =
166
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
167
Core::ActionContainer *mfile =
168
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
171
Core::Command *command;
173
m_buildSubProjectContextMenu = new Utils::ParameterAction(tr("Build"), tr("Build \"%1\""),
174
Utils::ParameterAction::AlwaysEnabled/*handled manually*/,
176
command = Core::ActionManager::registerAction(m_buildSubProjectContextMenu, Constants::BUILDSUBDIRCONTEXTMENU, projectContext);
177
command->setAttribute(Core::Command::CA_Hide);
178
command->setAttribute(Core::Command::CA_UpdateText);
179
command->setDescription(m_buildSubProjectContextMenu->text());
180
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
181
connect(m_buildSubProjectContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildSubDirContextMenu()));
183
m_runQMakeActionContextMenu = new QAction(tr("Run qmake"), this);
184
command = Core::ActionManager::registerAction(m_runQMakeActionContextMenu, Constants::RUNQMAKECONTEXTMENU, projectContext);
185
command->setAttribute(Core::Command::CA_Hide);
186
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
187
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
188
connect(m_runQMakeActionContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(runQMakeContextMenu()));
190
command = msubproject->addSeparator(projectContext, ProjectExplorer::Constants::G_PROJECT_BUILD,
191
&m_subProjectRebuildSeparator);
192
command->setAttribute(Core::Command::CA_Hide);
194
m_rebuildSubProjectContextMenu = new QAction(tr("Rebuild"), this);
195
command = Core::ActionManager::registerAction(
196
m_rebuildSubProjectContextMenu, Constants::REBUILDSUBDIRCONTEXTMENU, projectContext);
197
command->setAttribute(Core::Command::CA_Hide);
198
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
199
connect(m_rebuildSubProjectContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(rebuildSubDirContextMenu()));
201
m_cleanSubProjectContextMenu = new QAction(tr("Clean"), this);
202
command = Core::ActionManager::registerAction(
203
m_cleanSubProjectContextMenu, Constants::CLEANSUBDIRCONTEXTMENU, projectContext);
204
command->setAttribute(Core::Command::CA_Hide);
205
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
206
connect(m_cleanSubProjectContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(cleanSubDirContextMenu()));
208
m_buildFileContextMenu = new QAction(tr("Build"), this);
209
command = Core::ActionManager::registerAction(m_buildFileContextMenu, Constants::BUILDFILECONTEXTMENU, projectContext);
210
command->setAttribute(Core::Command::CA_Hide);
211
mfile->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER);
212
connect(m_buildFileContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildFileContextMenu()));
214
m_buildSubProjectAction = new Utils::ParameterAction(tr("Build Subproject"), tr("Build Subproject \"%1\""),
215
Utils::ParameterAction::AlwaysEnabled, this);
216
command = Core::ActionManager::registerAction(m_buildSubProjectAction, Constants::BUILDSUBDIR, projectContext);
217
command->setAttribute(Core::Command::CA_Hide);
218
command->setAttribute(Core::Command::CA_UpdateText);
219
command->setDescription(m_buildSubProjectAction->text());
220
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
221
connect(m_buildSubProjectAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildSubDirContextMenu()));
223
m_runQMakeAction = new QAction(tr("Run qmake"), this);
224
command = Core::ActionManager::registerAction(m_runQMakeAction, Constants::RUNQMAKE, projectContext);
225
command->setAttribute(Core::Command::CA_Hide);
226
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
227
connect(m_runQMakeAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(runQMake()));
229
m_rebuildSubProjectAction = new Utils::ParameterAction(tr("Rebuild Subproject"), tr("Rebuild Subproject \"%1\""),
230
Utils::ParameterAction::AlwaysEnabled, this);
231
command = Core::ActionManager::registerAction(m_rebuildSubProjectAction, Constants::REBUILDSUBDIR, projectContext);
232
command->setAttribute(Core::Command::CA_Hide);
233
command->setAttribute(Core::Command::CA_UpdateText);
234
command->setDescription(m_rebuildSubProjectAction->text());
235
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_REBUILD);
236
connect(m_rebuildSubProjectAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(rebuildSubDirContextMenu()));
238
m_cleanSubProjectAction = new Utils::ParameterAction(tr("Clean Subproject"), tr("Clean Subproject \"%1\""),
239
Utils::ParameterAction::AlwaysEnabled, this);
240
command = Core::ActionManager::registerAction(m_cleanSubProjectAction, Constants::CLEANSUBDIR, projectContext);
241
command->setAttribute(Core::Command::CA_Hide);
242
command->setAttribute(Core::Command::CA_UpdateText);
243
command->setDescription(m_cleanSubProjectAction->text());
244
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_CLEAN);
245
connect(m_cleanSubProjectAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(cleanSubDirContextMenu()));
247
const Core::Context globalcontext(Core::Constants::C_GLOBAL);
248
m_buildFileAction = new Utils::ParameterAction(tr("Build File"), tr("Build File \"%1\""),
249
Utils::ParameterAction::AlwaysEnabled, this);
250
command = Core::ActionManager::registerAction(m_buildFileAction, Constants::BUILDFILE, globalcontext);
251
command->setAttribute(Core::Command::CA_Hide);
252
command->setAttribute(Core::Command::CA_UpdateText);
253
command->setDescription(m_buildFileAction->text());
254
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+B")));
255
mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_BUILD);
256
connect(m_buildFileAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildFile()));
258
connect(m_projectExplorer->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)),
259
this, SLOT(buildStateChanged(ProjectExplorer::Project*)));
260
connect(m_projectExplorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
261
this, SLOT(startupProjectChanged()));
262
connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
263
this, SLOT(updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*)));
265
Core::ActionContainer *contextMenu = Core::ActionManager::createMenu(Qt4ProjectManager::Constants::M_CONTEXT);
267
Core::Context proFileEditorContext = Core::Context(Qt4ProjectManager::Constants::C_PROFILEEDITOR);
269
command = Core::ActionManager::command(TextEditor::Constants::JUMP_TO_FILE_UNDER_CURSOR);
270
contextMenu->addAction(command);
272
m_addLibraryAction = new QAction(tr("Add Library..."), this);
273
command = Core::ActionManager::registerAction(m_addLibraryAction,
274
Constants::ADDLIBRARY, proFileEditorContext);
275
connect(m_addLibraryAction, SIGNAL(triggered()),
276
m_qt4ProjectManager, SLOT(addLibrary()));
277
contextMenu->addAction(command);
279
m_addLibraryActionContextMenu = new QAction(tr("Add Library..."), this);
280
command = Core::ActionManager::registerAction(m_addLibraryActionContextMenu,
281
Constants::ADDLIBRARY, projecTreeContext);
282
connect(m_addLibraryActionContextMenu, SIGNAL(triggered()),
283
m_qt4ProjectManager, SLOT(addLibraryContextMenu()));
284
mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
285
msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
287
contextMenu->addSeparator(proFileEditorContext);
289
command = Core::ActionManager::command(TextEditor::Constants::UN_COMMENT_SELECTION);
290
contextMenu->addAction(command);
292
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
293
this, SLOT(updateBuildFileAction()));
298
void Qt4ProjectManagerPlugin::extensionsInitialized()
300
m_qt4ProjectManager->init();
303
void Qt4ProjectManagerPlugin::startupProjectChanged()
305
if (m_previousStartupProject)
306
disconnect(m_previousStartupProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
307
this, SLOT(activeTargetChanged()));
309
m_previousStartupProject = qobject_cast<Qt4Project *>(m_projectExplorer->session()->startupProject());
311
if (m_previousStartupProject)
312
connect(m_previousStartupProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
313
this, SLOT(activeTargetChanged()));
315
activeTargetChanged();
318
void Qt4ProjectManagerPlugin::activeTargetChanged()
320
if (m_previousTarget)
321
disconnect(m_previousTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
322
this, SLOT(updateRunQMakeAction()));
324
m_previousTarget = m_previousStartupProject ? m_previousStartupProject->activeTarget() : 0;
326
if (m_previousTarget)
327
connect(m_previousTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
328
this, SLOT(updateRunQMakeAction()));
330
updateRunQMakeAction();
333
void Qt4ProjectManagerPlugin::updateRunQMakeAction()
336
if (m_projectExplorer->buildManager()->isBuilding(m_projectExplorer->currentProject()))
338
Qt4Project *pro = qobject_cast<Qt4Project *>(m_projectExplorer->currentProject());
340
|| !pro->activeTarget()
341
|| !pro->activeTarget()->activeBuildConfiguration())
344
m_runQMakeAction->setEnabled(enable);
347
void Qt4ProjectManagerPlugin::updateContextActions(ProjectExplorer::Node *node, ProjectExplorer::Project *project)
349
m_addLibraryActionContextMenu->setEnabled(qobject_cast<Qt4ProFileNode *>(node));
351
Qt4ProFileNode *proFileNode = qobject_cast<Qt4ProFileNode *>(node);
352
Qt4Project *qt4Project = qobject_cast<Qt4Project *>(project);
353
Qt4ProFileNode *subProjectNode = node ? qobject_cast<Qt4ProFileNode *>(node->projectNode()) : 0;
354
ProjectExplorer::FileNode *fileNode = qobject_cast<ProjectExplorer::FileNode *>(node);
355
bool buildFilePossible = subProjectNode && fileNode
356
&& (fileNode->fileType() == ProjectExplorer::SourceType);
358
m_qt4ProjectManager->setContextNode(subProjectNode);
359
m_qt4ProjectManager->setContextProject(qt4Project);
360
m_qt4ProjectManager->setContextFile(buildFilePossible ? fileNode : 0);
362
bool subProjectActionsVisible = qt4Project && subProjectNode && (subProjectNode != qt4Project->rootProjectNode());
364
QString subProjectName;
365
if (subProjectActionsVisible)
366
subProjectName = subProjectNode->displayName();
368
m_buildSubProjectAction->setParameter(subProjectName);
369
m_rebuildSubProjectAction->setParameter(subProjectName);
370
m_cleanSubProjectAction->setParameter(subProjectName);
371
m_buildSubProjectContextMenu->setParameter(subProjectName);
372
m_buildFileAction->setParameter(buildFilePossible ? QFileInfo(fileNode->path()).fileName() : QString());
374
Qt4BuildConfiguration *buildConfiguration = (qt4Project && qt4Project->activeTarget()) ?
375
static_cast<Qt4BuildConfiguration *>(qt4Project->activeTarget()->activeBuildConfiguration()) : 0;
376
bool isProjectNode = qt4Project && proFileNode && buildConfiguration;
377
bool isBuilding = m_projectExplorer->buildManager()->isBuilding(project);
378
bool enabled = subProjectActionsVisible && !isBuilding;
380
m_buildSubProjectAction->setVisible(subProjectActionsVisible);
381
m_rebuildSubProjectAction->setVisible(subProjectActionsVisible);
382
m_cleanSubProjectAction->setVisible(subProjectActionsVisible);
383
m_buildSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
384
m_subProjectRebuildSeparator->setVisible(subProjectActionsVisible && isProjectNode);
385
m_rebuildSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
386
m_cleanSubProjectContextMenu->setVisible(subProjectActionsVisible && isProjectNode);
387
m_runQMakeActionContextMenu->setVisible(isProjectNode && buildConfiguration->qmakeStep());
388
m_buildFileAction->setVisible(buildFilePossible);
389
m_buildFileContextMenu->setVisible(buildFilePossible);
391
m_buildSubProjectAction->setEnabled(enabled);
392
m_rebuildSubProjectAction->setEnabled(enabled);
393
m_cleanSubProjectAction->setEnabled(enabled);
394
m_buildSubProjectContextMenu->setEnabled(enabled && isProjectNode);
395
m_rebuildSubProjectContextMenu->setEnabled(enabled && isProjectNode);
396
m_cleanSubProjectContextMenu->setEnabled(enabled && isProjectNode);
397
m_runQMakeActionContextMenu->setEnabled(isProjectNode && !isBuilding
398
&& buildConfiguration->qmakeStep());
399
m_buildFileAction->setEnabled(buildFilePossible && !isBuilding);
400
m_buildFileContextMenu->setEnabled(buildFilePossible && !isBuilding);
403
void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
405
ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject();
406
if (pro == currentProject) {
407
updateRunQMakeAction();
408
updateContextActions(m_projectExplorer->currentNode(), pro);
409
updateBuildFileAction();
413
void Qt4ProjectManagerPlugin::updateBuildFileAction()
415
bool visible = false;
416
bool enabled = false;
419
if (Core::IEditor *currentEditor = Core::EditorManager::currentEditor()) {
420
file = currentEditor->document()->fileName();
421
ProjectExplorer::SessionManager *session = m_projectExplorer->session();
422
ProjectExplorer::Node *node = session->nodeForFile(file);
423
ProjectExplorer::Project *project = session->projectForFile(file);
424
m_buildFileAction->setParameter(QFileInfo(file).fileName());
425
visible = qobject_cast<Qt4Project *>(project)
427
&& qobject_cast<Qt4ProFileNode *>(node->projectNode());
429
enabled = !m_projectExplorer->buildManager()->isBuilding(project);
431
m_buildFileAction->setVisible(visible);
432
m_buildFileAction->setEnabled(enabled);
435
Q_EXPORT_PLUGIN(Qt4ProjectManagerPlugin)