qt4projectmanagerplugin.cpp 15.8 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2 3 4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
**
10
** GNU Lesser General Public License Usage
11
**
hjk's avatar
hjk committed
12 13 14 15 16 17
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18
**
con's avatar
con committed
19
** In addition, as a special exception, Nokia gives you certain additional
hjk's avatar
hjk committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
con's avatar
con committed
21 22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
23 24 25 26 27
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
con's avatar
con committed
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
con's avatar
con committed
30
**
31
**************************************************************************/
hjk's avatar
hjk committed
32

con's avatar
con committed
33
#include "qt4projectmanagerplugin.h"
hjk's avatar
hjk committed
34

con's avatar
con committed
35
#include "qt4projectmanager.h"
36
#include "qt4nodes.h"
37 38
#include "qmakestep.h"
#include "makestep.h"
39 40
#include "qt4target.h"
#include "qt4buildconfiguration.h"
con's avatar
con committed
41 42
#include "wizards/consoleappwizard.h"
#include "wizards/guiappwizard.h"
43
#include "wizards/mobileappwizard.h"
con's avatar
con committed
44
#include "wizards/librarywizard.h"
45
#include "wizards/testwizard.h"
46
#include "wizards/emptyprojectwizard.h"
47
#include "wizards/subdirsprojectwizard.h"
48
#include "wizards/qtquickappwizard.h"
49
#include "wizards/html5appwizard.h"
50
#include "customwidgetwizard/customwidgetwizard.h"
con's avatar
con committed
51
#include "profileeditorfactory.h"
52
#include "profilehoverhandler.h"
con's avatar
con committed
53 54
#include "qt4projectmanagerconstants.h"
#include "qt4project.h"
55
#include "profileeditor.h"
56
#include "externaleditors.h"
Leandro Melo's avatar
Leandro Melo committed
57
#include "profilecompletionassist.h"
58
#include "qt-s60/s60manager.h"
59 60 61
#include "qt-desktop/qt4desktoptargetfactory.h"
#include "qt-desktop/qt4simulatortargetfactory.h"
#include "qt-desktop/qt4runconfiguration.h"
dt's avatar
dt committed
62 63 64
#include "qt-desktop/desktopqtversionfactory.h"
#include "qt-desktop/simulatorqtversionfactory.h"
#include "winceqtversionfactory.h"
65 66
#include "unconfiguredprojectpanel.h"
#include "unconfiguredsettingsoptionpage.h"
con's avatar
con committed
67

68
#include <coreplugin/id.h>
69
#include <coreplugin/icore.h>
70
#include <extensionsystem/pluginmanager.h>
71
#include <projectexplorer/buildmanager.h>
con's avatar
con committed
72
#include <projectexplorer/project.h>
73
#include <projectexplorer/session.h>
74 75
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/projectexplorerconstants.h>
con's avatar
con committed
76 77
#include <projectexplorer/projectnodes.h>
#include <coreplugin/mimedatabase.h>
78
#include <coreplugin/actionmanager/actionmanager.h>
79 80
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
81
#include <coreplugin/editormanager/editormanager.h>
con's avatar
con committed
82
#include <texteditor/texteditoractionhandler.h>
83
#include <texteditor/texteditorconstants.h>
84
#include <texteditor/texteditorsettings.h>
con's avatar
con committed
85 86

#ifdef WITH_TESTS
Tobias Hunger's avatar
Tobias Hunger committed
87
#    include <QTest>
con's avatar
con committed
88 89
#endif

Tobias Hunger's avatar
Tobias Hunger committed
90
#include <QtCore/QtPlugin>
dt's avatar
dt committed
91
#include <QtGui/QMenu>
Tobias Hunger's avatar
Tobias Hunger committed
92

con's avatar
con committed
93 94 95 96
using namespace Qt4ProjectManager::Internal;
using namespace Qt4ProjectManager;
using ProjectExplorer::Project;

97 98 99 100 101 102
Qt4ProjectManagerPlugin::Qt4ProjectManagerPlugin()
    : m_previousStartupProject(0), m_previousTarget(0)
{

}

con's avatar
con committed
103 104 105 106 107 108 109 110 111 112
Qt4ProjectManagerPlugin::~Qt4ProjectManagerPlugin()
{
    //removeObject(m_embeddedPropertiesPage);
    //delete m_embeddedPropertiesPage;

    removeObject(m_proFileEditorFactory);
    delete m_proFileEditorFactory;
    removeObject(m_qt4ProjectManager);
    delete m_qt4ProjectManager;
}
113 114

bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *errorMessage)
con's avatar
con committed
115
{
116
    Q_UNUSED(arguments)
117
    const Core::Context projectContext(Qt4ProjectManager::Constants::PROJECT_ID);
118
    Core::Context projecTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE);
119

hjk's avatar
hjk committed
120
    if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":qt4projectmanager/Qt4ProjectManager.mimetypes.xml"), errorMessage))
con's avatar
con committed
121 122
        return false;

123
    m_projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();
hjk's avatar
hjk committed
124
    Core::ActionManager *am = Core::ICore::actionManager();
con's avatar
con committed
125 126

    //create and register objects
127
    m_qt4ProjectManager = new Qt4Manager(this);
con's avatar
con committed
128 129 130
    addObject(m_qt4ProjectManager);

    TextEditor::TextEditorActionHandler *editorHandler
131 132
            = new TextEditor::TextEditorActionHandler(Constants::C_PROFILEEDITOR,
                  TextEditor::TextEditorActionHandler::UnCommentSelection);
con's avatar
con committed
133 134 135 136

    m_proFileEditorFactory = new ProFileEditorFactory(m_qt4ProjectManager, editorHandler);
    addObject(m_proFileEditorFactory);

137
    addAutoReleasedObject(new EmptyProjectWizard);
138 139 140 141
    addAutoReleasedObject(new SubdirsProjectWizard);
    addAutoReleasedObject(new GuiAppWizard);
    addAutoReleasedObject(new ConsoleAppWizard);
    addAutoReleasedObject(new MobileAppWizard);
142
    QtQuickAppWizard::createInstances(this); //creates several instances with different options
143
    addAutoReleasedObject(new Html5AppWizard);
144
    addAutoReleasedObject(new LibraryWizard);
145
    addAutoReleasedObject(new TestWizard);
146
    addAutoReleasedObject(new CustomWidgetWizard);
con's avatar
con committed
147

148 149
    CustomQt4ProjectWizard::registerSelf();

dt's avatar
dt committed
150 151
    addAutoReleasedObject(new QMakeStepFactory);
    addAutoReleasedObject(new MakeStepFactory);
con's avatar
con committed
152 153

    addAutoReleasedObject(new Qt4RunConfigurationFactory);
154
    addAutoReleasedObject(new UnConfiguredSettingsOptionPage);
con's avatar
con committed
155

156 157 158 159 160 161 162
#ifdef Q_OS_MAC
    addAutoReleasedObject(new MacDesignerExternalEditor);
#else
    addAutoReleasedObject(new DesignerExternalEditor);
#endif
    addAutoReleasedObject(new LinguistExternalEditor);

con's avatar
con committed
163
    addAutoReleasedObject(new S60Manager);
ck's avatar
ck committed
164

165 166 167
    addAutoReleasedObject(new Qt4DesktopTargetFactory);
    addAutoReleasedObject(new Qt4SimulatorTargetFactory);

dt's avatar
dt committed
168 169 170 171
    addAutoReleasedObject(new DesktopQtVersionFactory);
    addAutoReleasedObject(new SimulatorQtVersionFactory);
    addAutoReleasedObject(new WinCeQtVersionFactory);

Leandro Melo's avatar
Leandro Melo committed
172
    addAutoReleasedObject(new ProFileCompletionAssistProvider);
173
    addAutoReleasedObject(new ProFileHoverHandler(this));
174
    addAutoReleasedObject(new UnconfiguredProjectPanel);
175

con's avatar
con committed
176
    //menus
177
    Core::ActionContainer *mbuild =
178
            am->actionContainer(ProjectExplorer::Constants::M_BUILDPROJECT);
179
    Core::ActionContainer *mproject =
180 181 182
            am->actionContainer(ProjectExplorer::Constants::M_PROJECTCONTEXT);
    Core::ActionContainer *msubproject =
            am->actionContainer(ProjectExplorer::Constants::M_SUBPROJECTCONTEXT);
con's avatar
con committed
183 184

    //register actions
con's avatar
con committed
185
    Core::Command *command;
con's avatar
con committed
186 187 188 189

    QIcon qmakeIcon(QLatin1String(":/qt4projectmanager/images/run_qmake.png"));
    qmakeIcon.addFile(QLatin1String(":/qt4projectmanager/images/run_qmake_small.png"));
    m_runQMakeAction = new QAction(qmakeIcon, tr("Run qmake"), this);
190
    command = am->registerAction(m_runQMakeAction, Constants::RUNQMAKE, projectContext);
191
    command->setAttribute(Core::Command::CA_Hide);
dt's avatar
dt committed
192
    mbuild->addAction(command, ProjectExplorer::Constants::G_BUILD_PROJECT);
con's avatar
con committed
193 194 195
    connect(m_runQMakeAction, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(runQMake()));

    m_runQMakeActionContextMenu = new QAction(qmakeIcon, tr("Run qmake"), this);
196
    command = am->registerAction(m_runQMakeActionContextMenu, Constants::RUNQMAKECONTEXTMENU, projectContext);
197
    command->setAttribute(Core::Command::CA_Hide);
con's avatar
con committed
198
    mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
199
    msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
con's avatar
con committed
200 201
    connect(m_runQMakeActionContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(runQMakeContextMenu()));

202 203
    QIcon buildIcon = QIcon(QLatin1String(ProjectExplorer::Constants::ICON_BUILD));
    buildIcon.addFile(QLatin1String(ProjectExplorer::Constants::ICON_BUILD_SMALL));
204
    m_buildSubProjectContextMenu = new QAction(buildIcon, tr("Build"), this);
205
    command = am->registerAction(m_buildSubProjectContextMenu, Constants::BUILDSUBDIR, projectContext);
206 207 208 209
    command->setAttribute(Core::Command::CA_Hide);
    msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
    connect(m_buildSubProjectContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(buildSubDirContextMenu()));

210 211
    QIcon rebuildIcon = QIcon(QLatin1String(ProjectExplorer::Constants::ICON_REBUILD));
    rebuildIcon.addFile(QLatin1String(ProjectExplorer::Constants::ICON_REBUILD_SMALL));
dt's avatar
dt committed
212
    m_rebuildSubProjectContextMenu = new QAction(rebuildIcon, tr("Rebuild"), this);
213
    command = am->registerAction(m_rebuildSubProjectContextMenu, Constants::REBUILDSUBDIR, projectContext);
dt's avatar
dt committed
214 215 216 217
    command->setAttribute(Core::Command::CA_Hide);
    msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
    connect(m_rebuildSubProjectContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(rebuildSubDirContextMenu()));

218 219
    QIcon cleanIcon = QIcon(QLatin1String(ProjectExplorer::Constants::ICON_CLEAN));
    cleanIcon.addFile(QLatin1String(ProjectExplorer::Constants::ICON_CLEAN_SMALL));
dt's avatar
dt committed
220
    m_cleanSubProjectContextMenu = new QAction(cleanIcon, tr("Clean"), this);
221
    command = am->registerAction(m_cleanSubProjectContextMenu, Constants::CLEANSUBDIR, projectContext);
dt's avatar
dt committed
222 223 224 225
    command->setAttribute(Core::Command::CA_Hide);
    msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_BUILD);
    connect(m_cleanSubProjectContextMenu, SIGNAL(triggered()), m_qt4ProjectManager, SLOT(cleanSubDirContextMenu()));

con's avatar
con committed
226 227 228 229 230 231
    connect(m_projectExplorer,
            SIGNAL(aboutToShowContextMenu(ProjectExplorer::Project*, ProjectExplorer::Node*)),
            this, SLOT(updateContextMenu(ProjectExplorer::Project*, ProjectExplorer::Node*)));

    connect(m_projectExplorer->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project *)),
            this, SLOT(buildStateChanged(ProjectExplorer::Project *)));
232 233
    connect(m_projectExplorer->session(), SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
            this, SLOT(startupProjectChanged()));
234 235
    connect(m_projectExplorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*,ProjectExplorer::Project*)),
            this, SLOT(currentNodeChanged(ProjectExplorer::Node*)));
con's avatar
con committed
236

237
    Core::ActionContainer *contextMenu = am->createMenu(Qt4ProjectManager::Constants::M_CONTEXT);
238

239
    Core::Context proFileEditorContext = Core::Context(Qt4ProjectManager::Constants::C_PROFILEEDITOR);
240

241
    QAction *jumpToFile = new QAction(tr("Jump to File Under Cursor"), this);
242
    command = am->registerAction(jumpToFile,
243
        Constants::JUMP_TO_FILE, proFileEditorContext);
244
    command->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
245 246
    connect(jumpToFile, SIGNAL(triggered()),
            this, SLOT(jumpToFile()));
247
    contextMenu->addAction(command);
248

249 250
    m_addLibraryAction = new QAction(tr("Add Library..."), this);
    command = am->registerAction(m_addLibraryAction,
251
        Constants::ADDLIBRARY, proFileEditorContext);
252 253 254 255 256 257 258 259 260 261 262
    connect(m_addLibraryAction, SIGNAL(triggered()),
            m_qt4ProjectManager, SLOT(addLibrary()));
    contextMenu->addAction(command);

    m_addLibraryActionContextMenu = new QAction(tr("Add Library..."), this);
    command = am->registerAction(m_addLibraryActionContextMenu,
        Constants::ADDLIBRARY, projecTreeContext);
    connect(m_addLibraryActionContextMenu, SIGNAL(triggered()),
            m_qt4ProjectManager, SLOT(addLibraryContextMenu()));
    mproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
    msubproject->addAction(command, ProjectExplorer::Constants::G_PROJECT_FILES);
263

264 265 266 267 268
    QAction *separator = new QAction(this);
    separator->setSeparator(true);
    contextMenu->addAction(am->registerAction(separator,
                  Core::Id(Constants::SEPARATOR), proFileEditorContext));

269 270
    command = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
    contextMenu->addAction(command);
271

con's avatar
con committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285
    return true;
}

void Qt4ProjectManagerPlugin::extensionsInitialized()
{
    m_qt4ProjectManager->init();
}

void Qt4ProjectManagerPlugin::updateContextMenu(Project *project,
                                                ProjectExplorer::Node *node)
{
    m_qt4ProjectManager->setContextProject(project);
    m_qt4ProjectManager->setContextNode(node);
    m_runQMakeActionContextMenu->setEnabled(false);
286
    m_buildSubProjectContextMenu->setEnabled(false);
dt's avatar
dt committed
287 288
    m_rebuildSubProjectContextMenu->setEnabled(false);
    m_cleanSubProjectContextMenu->setEnabled(false);
con's avatar
con committed
289

290
    Qt4ProFileNode *proFileNode = qobject_cast<Qt4ProFileNode *>(node);
291 292 293 294
    Qt4Project *qt4Project = qobject_cast<Qt4Project *>(project);
    if (qt4Project && proFileNode
            && qt4Project->activeTarget()
            && qt4Project->activeTarget()->activeQt4BuildConfiguration()) {
dt's avatar
dt committed
295
        m_runQMakeActionContextMenu->setVisible(true);
296
        m_buildSubProjectContextMenu->setVisible(true);
dt's avatar
dt committed
297 298
        m_rebuildSubProjectContextMenu->setVisible(true);
        m_cleanSubProjectContextMenu->setVisible(true);
299 300

        if (!m_projectExplorer->buildManager()->isBuilding(project)) {
301 302
            if (qt4Project->activeTarget()->activeQt4BuildConfiguration()->qmakeStep())
                m_runQMakeActionContextMenu->setEnabled(true);
303
            m_buildSubProjectContextMenu->setEnabled(true);
dt's avatar
dt committed
304 305
            m_rebuildSubProjectContextMenu->setEnabled(true);
            m_cleanSubProjectContextMenu->setEnabled(true);
306
        }
307 308
    } else {
        m_runQMakeActionContextMenu->setVisible(false);
309
        m_buildSubProjectContextMenu->setVisible(false);
dt's avatar
dt committed
310 311
        m_rebuildSubProjectContextMenu->setVisible(false);
        m_cleanSubProjectContextMenu->setVisible(false);
con's avatar
con committed
312 313 314
    }
}

315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

void Qt4ProjectManagerPlugin::startupProjectChanged()
{
    if (m_previousStartupProject)
        disconnect(m_previousStartupProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
                   this, SLOT(activeTargetChanged()));

    m_previousStartupProject = qobject_cast<Qt4Project *>(m_projectExplorer->session()->startupProject());

    if (m_previousStartupProject)
        connect(m_previousStartupProject, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
                           this, SLOT(activeTargetChanged()));

    activeTargetChanged();
}

void Qt4ProjectManagerPlugin::activeTargetChanged()
{
    if (m_previousTarget)
        disconnect(m_previousTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
                   this, SLOT(updateRunQMakeAction()));

    m_previousTarget = m_previousStartupProject ? m_previousStartupProject->activeTarget() : 0;

    if (m_previousTarget)
        connect(m_previousTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
                this, SLOT(updateRunQMakeAction()));

    updateRunQMakeAction();
}

void Qt4ProjectManagerPlugin::updateRunQMakeAction()
con's avatar
con committed
347
{
348 349 350 351 352 353 354 355 356 357
    bool enable = true;
    if (m_projectExplorer->buildManager()->isBuilding(m_projectExplorer->currentProject()))
        enable = false;
    Qt4Project *pro = qobject_cast<Qt4Project *>(m_projectExplorer->currentProject());
    if (!pro
            || !pro->activeTarget()
            || !pro->activeTarget()->activeBuildConfiguration())
        enable = false;

    m_runQMakeAction->setEnabled(enable);
con's avatar
con committed
358 359
}

360 361 362 363 364
void Qt4ProjectManagerPlugin::currentNodeChanged(ProjectExplorer::Node *node)
{
    m_addLibraryActionContextMenu->setEnabled(qobject_cast<Qt4ProFileNode *>(node));
}

con's avatar
con committed
365 366 367 368
void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
{
    ProjectExplorer::Project *currentProject = m_projectExplorer->currentProject();
    if (pro == currentProject)
369
        updateRunQMakeAction();
con's avatar
con committed
370 371
}

372 373 374
void Qt4ProjectManagerPlugin::jumpToFile()
{
    Core::EditorManager *em = Core::EditorManager::instance();
375
    ProFileEditorWidget *editor = qobject_cast<ProFileEditorWidget*>(em->currentEditor()->widget());
376 377 378 379
    if (editor)
        editor->jumpToFile();
}

con's avatar
con committed
380
Q_EXPORT_PLUGIN(Qt4ProjectManagerPlugin)