projectexplorer.cpp 131 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
Eike Ziller's avatar
Eike Ziller committed
3
4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
Eike Ziller's avatar
Eike Ziller committed
12
13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18
19
20
21
22
23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25
26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27
28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
hjk's avatar
hjk committed
30

31
#include "projectexplorer.h"
Tobias Hunger's avatar
Tobias Hunger committed
32

Tobias Hunger's avatar
Tobias Hunger committed
33
#include "buildsteplist.h"
34
#include "configtaskhandler.h"
35
#include "customwizard/customwizard.h"
36
#include "deployablefile.h"
Tobias Hunger's avatar
Tobias Hunger committed
37
#include "deployconfiguration.h"
38
#include "gcctoolchainfactories.h"
Tobias Hunger's avatar
Tobias Hunger committed
39
40
41
#ifdef WITH_JOURNALD
#include "journaldwatcher.h"
#endif
Tobias Hunger's avatar
Tobias Hunger committed
42
#include "jsonwizard/jsonwizardfactory.h"
Tobias Hunger's avatar
Tobias Hunger committed
43
#include "jsonwizard/jsonwizardgeneratorfactory.h"
44
#include "jsonwizard/jsonwizardpagefactory_p.h"
45
#include "project.h"
46
#include "projectexplorersettings.h"
47
#include "removetaskhandler.h"
48
#include "unconfiguredprojectpanel.h"
49
#include "kitfeatureprovider.h"
Tobias Hunger's avatar
Tobias Hunger committed
50
51
#include "kitmanager.h"
#include "kitoptionspage.h"
Tobias Hunger's avatar
Tobias Hunger committed
52
#include "target.h"
53
54
#include "toolchainmanager.h"
#include "toolchainoptionspage.h"
55
#include "copytaskhandler.h"
56
#include "showineditortaskhandler.h"
57
#include "vcsannotatetaskhandler.h"
58
#include "localapplicationruncontrol.h"
con's avatar
con committed
59
60
61
62
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
63
#include "currentprojectfind.h"
con's avatar
con committed
64
#include "currentprojectfilter.h"
65
#include "editorsettingspropertiespage.h"
66
#include "codestylesettingspropertiespage.h"
67
#include "dependenciespanel.h"
con's avatar
con committed
68
69
70
#include "foldernavigationwidget.h"
#include "iprojectmanager.h"
#include "nodesvisitor.h"
71
#include "appoutputpane.h"
con's avatar
con committed
72
#include "processstep.h"
Tobias Hunger's avatar
Tobias Hunger committed
73
#include "kitinformation.h"
con's avatar
con committed
74
75
76
77
78
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "runsettingspropertiespage.h"
#include "session.h"
79
#include "projectnodes.h"
con's avatar
con committed
80
#include "sessiondialog.h"
81
#include "projectexplorersettingspage.h"
82
#include "corelistenercheckingforrunningbuild.h"
83
#include "buildconfiguration.h"
84
#include "miniprojecttargetselector.h"
dt's avatar
dt committed
85
#include "taskhub.h"
86
#include "customtoolchain.h"
Christian Kandeler's avatar
Christian Kandeler committed
87
#include "selectablefilesmodel.h"
88
#include <projectexplorer/customwizard/customwizard.h>
Tobias Hunger's avatar
Tobias Hunger committed
89
90
91
#include "devicesupport/desktopdevice.h"
#include "devicesupport/desktopdevicefactory.h"
#include "devicesupport/devicemanager.h"
92
#include "devicesupport/devicesettingspage.h"
93
#include "targetsettingspanel.h"
94
#include "projectpanelfactory.h"
con's avatar
con committed
95

96
#ifdef Q_OS_WIN
97
#    include "windebuginterface.h"
98
#    include "msvctoolchain.h"
SteveKing's avatar
SteveKing committed
99
#    include "wincetoolchain.h"
100
101
#endif

102
#include "projecttree.h"
103
104
#include "projectwelcomepage.h"

105
#include <extensionsystem/pluginspec.h>
106
#include <extensionsystem/pluginmanager.h>
107
#include <coreplugin/icore.h>
108
#include <coreplugin/editormanager/ieditor.h>
109
#include <coreplugin/id.h>
110
#include <coreplugin/idocumentfactory.h>
111
#include <coreplugin/idocument.h>
con's avatar
con committed
112
#include <coreplugin/coreconstants.h>
113
#include <coreplugin/documentmanager.h>
114
#include <coreplugin/imode.h>
con's avatar
con committed
115
#include <coreplugin/modemanager.h>
116
#include <coreplugin/actionmanager/actionmanager.h>
117
#include <coreplugin/actionmanager/actioncontainer.h>
118
#include <coreplugin/actionmanager/command.h>
119
#include <coreplugin/infobar.h>
con's avatar
con committed
120
121
122
123
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
Robert Loehning's avatar
Robert Loehning committed
124
#include <coreplugin/fileutils.h>
125
#include <coreplugin/removefiledialog.h>
126
#include <texteditor/findinfiles.h>
127
#include <ssh/sshconnection.h>
hjk's avatar
hjk committed
128

129
#include <utils/algorithm.h>
130
#include <utils/fileutils.h>
hjk's avatar
hjk committed
131
#include <utils/macroexpander.h>
Eike Ziller's avatar
Eike Ziller committed
132
#include <utils/mimetypes/mimedatabase.h>
133
#include <utils/parameteraction.h>
134
#include <utils/qtcassert.h>
135
#include <utils/stringutils.h>
con's avatar
con committed
136

137
138
#include <QtPlugin>
#include <QDebug>
139
#include <QFileInfo>
140
#include <QSettings>
Morten Johan Sorvig's avatar
Morten Johan Sorvig committed
141

142
143
144
145
146
#include <QAction>
#include <QApplication>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
147
#include <QTimer>
148
#include <QWizard>
con's avatar
con committed
149

150
151
/*!
    \namespace ProjectExplorer
152
    The ProjectExplorer namespace contains the classes to explore projects.
153
154
155
156
*/

/*!
    \namespace ProjectExplorer::Internal
157
158
    The ProjectExplorer::Internal namespace is the internal namespace of the
    ProjectExplorer plugin.
159
160
161
162
163
164
    \internal
*/

/*!
    \class ProjectExplorer::ProjectExplorerPlugin

165
166
    \brief The ProjectExplorerPlugin class contains static accessor and utility
    functions to obtain the current project, open projects, and so on.
167
168
*/

con's avatar
con committed
169
170
171
172
namespace {
bool debug = false;
}

173
using namespace Core;
174
using namespace ProjectExplorer::Internal;
175

176
177
namespace ProjectExplorer {

178
179
static Target *activeTarget()
{
180
    Project *project = ProjectTree::currentProject();
181
182
183
184
185
186
187
188
189
    return project ? project->activeTarget() : 0;
}

static BuildConfiguration *activeBuildConfiguration()
{
    Target *target = activeTarget();
    return target ? target->activeBuildConfiguration() : 0;
}

190
191
192
193
194
195
static Kit *currentKit()
{
    Target *target = activeTarget();
    return target ? target->kit() : 0;
}

196
197
class ProjectExplorerPluginPrivate : public QObject
{
198
199
    Q_DECLARE_TR_FUNCTIONS(ProjectExplorer::ProjectExplorerPlugin)

200
public:
201
202
    ProjectExplorerPluginPrivate();

203
    void deploy(QList<Project *>);
204
    int queue(QList<Project *>, QList<Id> stepIds);
205
206
207
208
209
210
211
212
213
214
215
216
217
    void updateContextMenuActions();
    void executeRunConfiguration(RunConfiguration *, RunMode mode);
    QPair<bool, QString> buildSettingsEnabledForSession();
    QPair<bool, QString> buildSettingsEnabled(Project *pro);

    void addToRecentProjects(const QString &fileName, const QString &displayName);
    void startRunControl(RunControl *runControl, RunMode runMode);

    void updateActions();
    void updateContext();
    void updateDeployActions();
    void updateRunWithoutDeployMenu();

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
    void buildQueueFinished(bool success);

    void buildStateChanged(ProjectExplorer::Project * pro);
    void buildProjectOnly();
    void handleBuildProject();
    void buildProjectContextMenu();
    void buildSession();
    void rebuildProjectOnly();
    void rebuildProject();
    void rebuildProjectContextMenu();
    void rebuildSession();
    void deployProjectOnly();
    void deployProject();
    void deployProjectContextMenu();
    void deploySession();
    void cleanProjectOnly();
    void cleanProject();
    void cleanProjectContextMenu();
    void cleanSession();
    void cancelBuild();
    void loadAction();
    void handleUnloadProject();
    void unloadProjectContextMenu();
    void closeAllProjects();
    void newProject();
    void showSessionManager();
    void updateSessionMenu();
    void setSession(QAction *action);

    void determineSessionToRestoreAtStartup();
    void restoreSession();
    void loadSession(const QString &session);
    void handleRunProject();
    void runProjectContextMenu();
    void runProjectWithoutDeploy();
    void savePersistentSettings();

    void addNewFile();
    void handleAddExistingFiles();
    void addExistingDirectory();
    void addNewSubproject();
    void removeProject();
    void openFile();
    void searchOnFileSystem();
    void showInGraphicalShell();
    void removeFile();
    void deleteFile();
    void handleRenameFile();
    void handleSetStartupProject();
    void setStartupProject(ProjectExplorer::Project *project);

    void updateRecentProjectMenu();
    void clearRecentProjects();
271
    void openRecentProject(const QString &fileName);
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
    void updateUnloadProjectMenu();
    void openTerminalHere();

    void invalidateProject(ProjectExplorer::Project *project);

    void projectAdded(ProjectExplorer::Project *pro);
    void projectRemoved(ProjectExplorer::Project *pro);
    void projectDisplayNameChanged(ProjectExplorer::Project *pro);
    void startupProjectChanged(); // Calls updateRunAction
    void activeTargetChanged();
    void activeRunConfigurationChanged();

    void slotUpdateRunActions();

    void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);

    void updateWelcomePage();

    void runConfigurationConfigurationFinished();

public:
293
294
295
296
297
298
299
    QMenu *m_sessionMenu;
    QMenu *m_openWithMenu;

    QMultiMap<int, QObject*> m_actionMap;
    QAction *m_sessionManagerAction;
    QAction *m_newAction;
    QAction *m_loadAction;
300
    Utils::ParameterAction *m_unloadAction;
301
    Utils::ParameterAction *m_unloadActionContextMenu;
302
    QAction *m_closeAllProjects;
303
    QAction *m_buildProjectOnlyAction;
304
    Utils::ParameterAction *m_buildAction;
305
    QAction *m_buildActionContextMenu;
306
307
    QAction *m_buildSessionAction;
    QAction *m_rebuildProjectOnlyAction;
308
    Utils::ParameterAction *m_rebuildAction;
309
    QAction *m_rebuildActionContextMenu;
310
311
    QAction *m_rebuildSessionAction;
    QAction *m_cleanProjectOnlyAction;
Tobias Hunger's avatar
Tobias Hunger committed
312
313
    QAction *m_deployProjectOnlyAction;
    Utils::ParameterAction *m_deployAction;
314
    QAction *m_deployActionContextMenu;
Tobias Hunger's avatar
Tobias Hunger committed
315
    QAction *m_deploySessionAction;
316
    Utils::ParameterAction *m_cleanAction;
317
    QAction *m_cleanActionContextMenu;
318
319
320
    QAction *m_cleanSessionAction;
    QAction *m_runAction;
    QAction *m_runActionContextMenu;
321
    QAction *m_runWithoutDeployAction;
322
323
324
    QAction *m_cancelBuildAction;
    QAction *m_addNewFileAction;
    QAction *m_addExistingFilesAction;
325
    QAction *m_addExistingDirectoryAction;
326
    QAction *m_addNewSubprojectAction;
327
    QAction *m_removeFileAction;
328
    QAction *m_removeProjectAction;
329
    QAction *m_deleteFileAction;
330
    QAction *m_renameFileAction;
dt's avatar
dt committed
331
    QAction *m_openFileAction;
332
    QAction *m_projectTreeCollapseAllAction;
333
    QAction *m_searchOnFileSystem;
dt's avatar
dt committed
334
335
    QAction *m_showInGraphicalShell;
    QAction *m_openTerminalHere;
336
    Utils::ParameterAction *m_setStartupProjectAction;
337
    QAction *m_projectSelectorAction;
338
    QAction *m_projectSelectorActionMenu;
Daniel Teske's avatar
Daniel Teske committed
339
    QAction *m_projectSelectorActionQuick;
dt's avatar
dt committed
340
    QAction *m_runSubProject;
341

342
    ProjectWindow *m_proWindow;
343
344
345
    QString m_sessionToRestoreAtStartup;

    QStringList m_profileMimeTypes;
346
    AppOutputPane *m_outputPane;
347
348

    QList<QPair<QString, QString> > m_recentProjects; // pair of filename, displayname
349
    static const int m_maxRecentProjects = 25;
350
351

    QString m_lastOpenDirectory;
352
    QPointer<RunConfiguration> m_delayedRunConfiguration;
353
    QList<QPair<RunConfiguration *, RunMode>> m_delayedRunConfigurationForRun;
354
    bool m_shouldHaveRunConfiguration;
355
    RunMode m_runMode;
356
    QString m_projectFilterString;
357
358
359
    MiniProjectTargetSelector * m_targetSelector;
    ProjectExplorerSettings m_projectExplorerSettings;
    ProjectWelcomePage *m_welcomePage;
360
    IMode *m_projectsMode;
361

362
    TaskHub *m_taskHub;
Tobias Hunger's avatar
Tobias Hunger committed
363
    KitManager *m_kitManager;
Tobias Hunger's avatar
Tobias Hunger committed
364
    ToolChainManager *m_toolChainManager;
365
    bool m_shuttingDown;
366
    QStringList m_arguments;
367
    QList<ProjectPanelFactory *> m_panelFactories;
368
    QString m_renameFileError;
Tobias Hunger's avatar
Tobias Hunger committed
369
370
371
#ifdef WITH_JOURNALD
    JournaldWatcher *m_journalWatcher;
#endif
372
373
374
};

ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
375
    m_shouldHaveRunConfiguration(false),
376
    m_runMode(NoRunMode),
377
    m_projectsMode(0),
Tobias Hunger's avatar
Tobias Hunger committed
378
    m_kitManager(0),
Tobias Hunger's avatar
Tobias Hunger committed
379
    m_toolChainManager(0),
380
    m_shuttingDown(false)
Tobias Hunger's avatar
Tobias Hunger committed
381
382
383
#ifdef WITH_JOURNALD
    , m_journalWatcher(0)
#endif
384
385
386
{
}

387
class ProjectsMode : public IMode
388
389
{
public:
390
391
392
    ProjectsMode(QWidget *proWindow)
    {
        setWidget(proWindow);
393
        setContext(Context(Constants::C_PROJECTEXPLORER));
394
        setDisplayName(QCoreApplication::translate("ProjectExplorer::ProjectsMode", "Projects"));
395
        setIcon(QIcon(QLatin1String(":/projectexplorer/images/mode_project.png")));
396
        setPriority(Constants::P_MODE_SESSION);
397
        setId(Constants::MODE_SESSION);
398
        setContextHelpId(QLatin1String("Managing Projects"));
399
    }
400
401
};

402
403
static ProjectExplorerPlugin *m_instance = 0;
static ProjectExplorerPluginPrivate *dd = 0;
con's avatar
con committed
404
405
406
407

ProjectExplorerPlugin::ProjectExplorerPlugin()
{
    m_instance = this;
408
    dd = new ProjectExplorerPluginPrivate;
con's avatar
con committed
409
410
411
412
}

ProjectExplorerPlugin::~ProjectExplorerPlugin()
{
Tobias Hunger's avatar
Tobias Hunger committed
413
414
    JsonWizardFactory::destroyAllFactories();

415
416
417
    removeObject(dd->m_welcomePage);
    delete dd->m_welcomePage;

con's avatar
con committed
418
    removeObject(this);
Tobias Hunger's avatar
Tobias Hunger committed
419
    // Force sequence of deletion:
420
421
    delete dd->m_kitManager; // remove all the profile information
    delete dd->m_toolChainManager;
Tobias Hunger's avatar
Tobias Hunger committed
422
423
424
#ifdef WITH_JOURNALD
    delete dd->m_journalWatcher;
#endif
425
    ProjectPanelFactory::destroyFactories();
426
    delete dd;
con's avatar
con committed
427
428
429
430
431
432
433
}

ProjectExplorerPlugin *ProjectExplorerPlugin::instance()
{
    return m_instance;
}

434
435
436
437
438
static void updateActions()
{
    dd->updateActions();
}

439
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
440
{
441
442
    Q_UNUSED(error);

Friedemann Kleint's avatar
Friedemann Kleint committed
443
    qRegisterMetaType<ProjectExplorer::RunControl *>();
444
    qRegisterMetaType<ProjectExplorer::DeployableFile>("ProjectExplorer::DeployableFile");
Friedemann Kleint's avatar
Friedemann Kleint committed
445

446
447
448
    CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
    JsonWizardFactory::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));

dt's avatar
dt committed
449
450
    addObject(this);

Tobias Hunger's avatar
Tobias Hunger committed
451
452
    addAutoReleasedObject(new DeviceManager);

Tobias Hunger's avatar
Tobias Hunger committed
453
454
455
456
#ifdef WITH_JOURNALD
    dd->m_journalWatcher = new JournaldWatcher;
#endif

457
    // Add ToolChainFactories:
458
#ifdef Q_OS_WIN
459
460
    addAutoReleasedObject(new WinDebugInterface);

461
462
    addAutoReleasedObject(new MsvcToolChainFactory);
    addAutoReleasedObject(new WinCEToolChainFactory);
463
#else
464
    addAutoReleasedObject(new LinuxIccToolChainFactory);
Tobias Hunger's avatar
Tobias Hunger committed
465
466
#endif
#ifndef Q_OS_MAC
467
    addAutoReleasedObject(new MingwToolChainFactory); // Mingw offers cross-compiling to windows
468
#endif
469
470
471
    addAutoReleasedObject(new GccToolChainFactory);
    addAutoReleasedObject(new ClangToolChainFactory);
    addAutoReleasedObject(new CustomToolChainFactory);
472

473
    addAutoReleasedObject(new DesktopDeviceFactory);
Tobias Hunger's avatar
Tobias Hunger committed
474

475
476
    dd->m_kitManager = new KitManager; // register before ToolChainManager
    dd->m_toolChainManager = new ToolChainManager;
477

478
    IWizardFactory::registerFeatureProvider(new KitFeatureProvider);
479

480
    // Register KitInformation:
481
482
483
484
    KitManager::registerKitInformation(new DeviceTypeKitInformation);
    KitManager::registerKitInformation(new DeviceKitInformation);
    KitManager::registerKitInformation(new ToolChainKitInformation);
    KitManager::registerKitInformation(new SysRootKitInformation);
485
    KitManager::registerKitInformation(new EnvironmentKitInformation);
486

487
    addAutoReleasedObject(new ToolChainOptionsPage);
Tobias Hunger's avatar
Tobias Hunger committed
488
    addAutoReleasedObject(new KitOptionsPage);
489

490
    addAutoReleasedObject(new TaskHub);
491

492
493
494
495
496
497
    IWizardFactory::registerFactoryCreator([]() -> QList<IWizardFactory *> {
        QList<IWizardFactory *> result;
        result << CustomWizard::createWizards();
        result << JsonWizardFactory::createWizardFactories();
        return result;
    });
con's avatar
con committed
498

499
    dd->m_welcomePage = new ProjectWelcomePage;
500
    connect(dd->m_welcomePage, &ProjectWelcomePage::manageSessions,
501
            dd, &ProjectExplorerPluginPrivate::showSessionManager);
502
    addObject(dd->m_welcomePage);
con's avatar
con committed
503

504
505
506
507
508
    auto sessionManager = new SessionManager(this);

    connect(sessionManager, &SessionManager::projectAdded,
            this, &ProjectExplorerPlugin::fileListChanged);
    connect(sessionManager, &SessionManager::aboutToRemoveProject,
509
            dd, &ProjectExplorerPluginPrivate::invalidateProject);
510
511
512
    connect(sessionManager, &SessionManager::projectRemoved,
            this, &ProjectExplorerPlugin::fileListChanged);
    connect(sessionManager, &SessionManager::projectAdded,
513
            dd, &ProjectExplorerPluginPrivate::projectAdded);
514
    connect(sessionManager, &SessionManager::projectRemoved,
515
            dd, &ProjectExplorerPluginPrivate::projectRemoved);
516
    connect(sessionManager, &SessionManager::startupProjectChanged,
517
            dd, &ProjectExplorerPluginPrivate::startupProjectChanged);
518
    connect(sessionManager, &SessionManager::projectDisplayNameChanged,
519
520
521
            dd, &ProjectExplorerPluginPrivate::projectDisplayNameChanged);
    connect(sessionManager, &SessionManager::dependencyChanged, updateActions);
    connect(sessionManager, &SessionManager::sessionLoaded, updateActions);
522
    connect(sessionManager, &SessionManager::sessionLoaded,
523
            dd, &ProjectExplorerPluginPrivate::updateWelcomePage);
con's avatar
con committed
524

525
526
527
528
529
    ProjectTree *tree = new ProjectTree(this);
    connect(tree, &ProjectTree::currentProjectChanged,
            dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
    connect(tree, &ProjectTree::currentNodeChanged,
            dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
530
    connect(tree, &ProjectTree::currentProjectChanged, updateActions);
531

532
533
    addAutoReleasedObject(new CustomWizardMetaFactory<CustomProjectWizard>(IWizardFactory::ProjectWizard));
    addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(IWizardFactory::FileWizard));
534

Tobias Hunger's avatar
Tobias Hunger committed
535
    // For JsonWizard:
536
    JsonWizardFactory::registerPageFactory(new FieldPageFactory);
537
    JsonWizardFactory::registerPageFactory(new FilePageFactory);
538
    JsonWizardFactory::registerPageFactory(new KitsPageFactory);
539
    JsonWizardFactory::registerPageFactory(new ProjectPageFactory);
540
541
    JsonWizardFactory::registerPageFactory(new SummaryPageFactory);

Tobias Hunger's avatar
Tobias Hunger committed
542
    JsonWizardFactory::registerGeneratorFactory(new FileGeneratorFactory);
543
    JsonWizardFactory::registerGeneratorFactory(new ScannerGeneratorFactory);
Tobias Hunger's avatar
Tobias Hunger committed
544

545
546
    dd->m_proWindow = new ProjectWindow;
    addAutoReleasedObject(dd->m_proWindow);
con's avatar
con committed
547

548
    Context projecTreeContext(Constants::C_PROJECT_TREE);
con's avatar
con committed
549

550
551
552
553
    dd->m_projectsMode = new ProjectsMode(dd->m_proWindow);
    dd->m_projectsMode->setEnabled(false);
    addAutoReleasedObject(dd->m_projectsMode);
    dd->m_proWindow->layout()->addWidget(new FindToolBarPlaceHolder(dd->m_proWindow));
con's avatar
con committed
554

555
    addAutoReleasedObject(new CopyTaskHandler);
556
    addAutoReleasedObject(new ShowInEditorTaskHandler);
557
    addAutoReleasedObject(new VcsAnnotateTaskHandler);
558
    addAutoReleasedObject(new RemoveTaskHandler);
559
560
    addAutoReleasedObject(new ConfigTaskHandler(Task::compilerMissingTask(),
                                                Constants::KITS_SETTINGS_PAGE_ID));
561
    addAutoReleasedObject(new CoreListener);
con's avatar
con committed
562

563
564
    dd->m_outputPane = new AppOutputPane;
    addAutoReleasedObject(dd->m_outputPane);
565
566
    connect(SessionManager::instance(), &SessionManager::projectRemoved,
            dd->m_outputPane, &AppOutputPane::projectRemoved);
con's avatar
con committed
567

568
569
570
    connect(dd->m_outputPane, &AppOutputPane::runControlStarted,
            this, &ProjectExplorerPlugin::runControlStarted);
    connect(dd->m_outputPane, &AppOutputPane::runControlFinished,
571
            this, &ProjectExplorerPlugin::runControlFinished);
572
    connect(dd->m_outputPane, &AppOutputPane::runControlFinished,
573
            this, &ProjectExplorerPlugin::updateRunActions);
574

hjk's avatar
hjk committed
575
576
    addAutoReleasedObject(new AllProjectsFilter);
    addAutoReleasedObject(new CurrentProjectFilter);
con's avatar
con committed
577

578
    // ProjectPanelFactories
579
    auto editorSettingsPanelFactory = new ProjectPanelFactory;
580
581
582
583
    editorSettingsPanelFactory->setPriority(30);
    QString displayName = QCoreApplication::translate("EditorSettingsPanelFactory", "Editor");
    editorSettingsPanelFactory->setDisplayName(displayName);
    QIcon icon = QIcon(QLatin1String(":/projectexplorer/images/EditorSettings.png"));
584
    editorSettingsPanelFactory->setSimpleCreateWidgetFunction<EditorSettingsWidget>(icon);
585
    ProjectPanelFactory::registerFactory(editorSettingsPanelFactory);
586

587
    auto codeStyleSettingsPanelFactory = new ProjectPanelFactory;
588
589
590
591
    codeStyleSettingsPanelFactory->setPriority(40);
    displayName = QCoreApplication::translate("CodeStyleSettingsPanelFactory", "Code Style");
    codeStyleSettingsPanelFactory->setDisplayName(displayName);
    icon = QIcon(QLatin1String(":/projectexplorer/images/CodeStyleSettings.png"));
592
    codeStyleSettingsPanelFactory->setSimpleCreateWidgetFunction<CodeStyleSettingsWidget>(icon);
593
    ProjectPanelFactory::registerFactory(codeStyleSettingsPanelFactory);
594

595
    auto dependenciesPanelFactory = new ProjectPanelFactory;
596
597
598
599
    dependenciesPanelFactory->setPriority(50);
    displayName = QCoreApplication::translate("DependenciesPanelFactory", "Dependencies");
    dependenciesPanelFactory->setDisplayName(displayName);
    icon = QIcon(QLatin1String(":/projectexplorer/images/ProjectDependencies.png"));
600
    dependenciesPanelFactory->setSimpleCreateWidgetFunction<DependenciesWidget>(icon);
601
    ProjectPanelFactory::registerFactory(dependenciesPanelFactory);
602

603
    auto unconfiguredProjectPanel = new ProjectPanelFactory;
604
605
606
607
608
609
    unconfiguredProjectPanel->setPriority(-10);
    unconfiguredProjectPanel->setDisplayName(tr("Configure Project"));
    unconfiguredProjectPanel->setSupportsFunction([](Project *project){
        return project->targets().isEmpty() && !project->requiresTargetPanel();
    });
    icon = QIcon(QLatin1String(":/projectexplorer/images/unconfigured.png"));
610
    unconfiguredProjectPanel->setSimpleCreateWidgetFunction<TargetSetupPageWrapper>(icon);
611
    ProjectPanelFactory::registerFactory(unconfiguredProjectPanel);
con's avatar
con committed
612

613
    auto targetSettingsPanelFactory = new ProjectPanelFactory;
614
615
616
617
618
619
620
621
622
623
    targetSettingsPanelFactory->setPriority(-10);
    displayName = QCoreApplication::translate("TargetSettingsPanelFactory", "Build & Run");
    targetSettingsPanelFactory->setDisplayName(displayName);
    targetSettingsPanelFactory->setSupportsFunction([](Project *project) {
        return !project->targets().isEmpty()
                || project->requiresTargetPanel();
    });
    targetSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
        return new TargetSettingsPanelWidget(project);
    });
624
    ProjectPanelFactory::registerFactory(targetSettingsPanelFactory);
625

hjk's avatar
hjk committed
626
    addAutoReleasedObject(new ProcessStepFactory);
con's avatar
con committed
627

hjk's avatar
hjk committed
628
629
    addAutoReleasedObject(new AllProjectsFind);
    addAutoReleasedObject(new CurrentProjectFind);
con's avatar
con committed
630

631
    addAutoReleasedObject(new LocalApplicationRunControlFactory);
con's avatar
con committed
632

633
    addAutoReleasedObject(new ProjectFileWizardExtension);
con's avatar
con committed
634

635
    // Settings pages
636
    addAutoReleasedObject(new ProjectExplorerSettingsPage);
637
    addAutoReleasedObject(new DeviceSettingsPage);
638

con's avatar
con committed
639
    // context menus
640
641
642
643
644
645
646
647
648
649
    ActionContainer *msessionContextMenu =
        ActionManager::createMenu(Constants::M_SESSIONCONTEXT);
    ActionContainer *mprojectContextMenu =
        ActionManager::createMenu(Constants::M_PROJECTCONTEXT);
    ActionContainer *msubProjectContextMenu =
        ActionManager::createMenu(Constants::M_SUBPROJECTCONTEXT);
    ActionContainer *mfolderContextMenu =
        ActionManager::createMenu(Constants::M_FOLDERCONTEXT);
    ActionContainer *mfileContextMenu =
        ActionManager::createMenu(Constants::M_FILECONTEXT);
con's avatar
con committed
650

651
652
653
654
    ActionContainer *mfile =
        ActionManager::actionContainer(Core::Constants::M_FILE);
    ActionContainer *menubar =
        ActionManager::actionContainer(Core::Constants::MENU_BAR);
con's avatar
con committed
655
656

    // build menu
657
658
    ActionContainer *mbuild =
        ActionManager::createMenu(Constants::M_BUILDPROJECT);
659
    mbuild->menu()->setTitle(tr("&Build"));
con's avatar
con committed
660
661
662
    menubar->addMenu(mbuild, Core::Constants::G_VIEW);

    // debug menu
663
664
    ActionContainer *mdebug =
        ActionManager::createMenu(Constants::M_DEBUG);
665
    mdebug->menu()->setTitle(tr("&Debug"));
con's avatar
con committed
666
667
    menubar->addMenu(mdebug, Core::Constants::G_VIEW);

668
669
    ActionContainer *mstartdebugging =
        ActionManager::createMenu(Constants::M_DEBUG_STARTDEBUGGING);
670
671
    mstartdebugging->menu()->setTitle(tr("&Start Debugging"));
    mdebug->addMenu(mstartdebugging, Core::Constants::G_DEFAULT_ONE);
con's avatar
con committed
672
673
674
675
676

    //
    // Groups
    //

677
678
679
680
    mbuild->appendGroup(Constants::G_BUILD_BUILD);
    mbuild->appendGroup(Constants::G_BUILD_DEPLOY);
    mbuild->appendGroup(Constants::G_BUILD_REBUILD);
    mbuild->appendGroup(Constants::G_BUILD_CLEAN);
con's avatar
con committed
681
    mbuild->appendGroup(Constants::G_BUILD_CANCEL);
dt's avatar
dt committed
682
    mbuild->appendGroup(Constants::G_BUILD_RUN);
con's avatar
con committed
683
684

    msessionContextMenu->appendGroup(Constants::G_SESSION_BUILD);
685
    msessionContextMenu->appendGroup(Constants::G_SESSION_REBUILD);
con's avatar
con committed
686
687
    msessionContextMenu->appendGroup(Constants::G_SESSION_FILES);
    msessionContextMenu->appendGroup(Constants::G_SESSION_OTHER);
688
    msessionContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
689

dt's avatar
dt committed
690
691
692
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
693
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_REBUILD);
dt's avatar
dt committed
694
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
695
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
696
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
697

dt's avatar
dt committed
698
699
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
dt's avatar
dt committed
700
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
dt's avatar
dt committed
701
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
702
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
703
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
704

705
706
    ActionContainer *runMenu = ActionManager::createMenu(Constants::RUNMENUCONTEXTMENU);
    runMenu->setOnAllDisabledBehavior(ActionContainer::Hide);
Friedemann Kleint's avatar
Friedemann Kleint committed
707
    QIcon runIcon = QIcon(QLatin1String(Constants::ICON_RUN));
708
    runIcon.addFile(QLatin1String(Constants::ICON_RUN_SMALL));
dt's avatar
dt committed
709
    runMenu->menu()->setIcon(runIcon);
710
    runMenu->menu()->setTitle(tr("Run"));
dt's avatar
dt committed
711
712
    msubProjectContextMenu->addMenu(runMenu, ProjectExplorer::Constants::G_PROJECT_RUN);

dt's avatar
dt committed
713
714
715
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_FILES);
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_OTHER);
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_CONFIG);
716
    mfolderContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
717

dt's avatar
dt committed
718
719
720
    mfileContextMenu->appendGroup(Constants::G_FILE_OPEN);
    mfileContextMenu->appendGroup(Constants::G_FILE_OTHER);
    mfileContextMenu->appendGroup(Constants::G_FILE_CONFIG);
721
    mfileContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
722
    // "open with" submenu
723
724
725
    ActionContainer * const openWith =
            ActionManager::createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
    openWith->setOnAllDisabledBehavior(ActionContainer::Show);
726
727
    dd->m_openWithMenu = openWith->menu();
    dd->m_openWithMenu->setTitle(tr("Open With"));
con's avatar
con committed
728

729
730
    connect(dd->m_openWithMenu, &QMenu::triggered,
            DocumentManager::instance(), &DocumentManager::executeOpenWithMenuAction);
con's avatar
con committed
731
732
733
734
735

    //
    // Separators
    //

736
    Command *cmd;
con's avatar
con committed
737

738
    msessionContextMenu->addSeparator(projecTreeContext, Constants::G_SESSION_REBUILD);
con's avatar
con committed
739

740
741
742
    msessionContextMenu->addSeparator(projecTreeContext, Constants::G_SESSION_FILES);
    mprojectContextMenu->addSeparator(projecTreeContext, Constants::G_PROJECT_FILES);
    msubProjectContextMenu->addSeparator(projecTreeContext, Constants::G_PROJECT_FILES);
743
744
745
746
747
748
    mfile->addSeparator(Core::Constants::G_FILE_PROJECT);
    mbuild->addSeparator(Constants::G_BUILD_REBUILD);
    msessionContextMenu->addSeparator(Constants::G_SESSION_OTHER);
    mbuild->addSeparator(Constants::G_BUILD_CANCEL);
    mbuild->addSeparator(Constants::G_BUILD_RUN);
    mprojectContextMenu->addSeparator(Constants::G_PROJECT_REBUILD);
con's avatar
con committed
749
750
751
752
753
754

    //
    // Actions
    //

    // new action
755
    dd->m_newAction = new QAction(tr("New Project..."), this);
756
    cmd = ActionManager::registerAction(dd->m_newAction, Constants::NEWPROJECT);
con's avatar
con committed
757
758
759
760
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+N")));
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // open action
761
    dd->m_loadAction = new QAction(tr("Load Project..."), this);
762
    cmd = ActionManager::registerAction(dd->m_loadAction, Constants::LOAD);
763
#ifndef Q_OS_MAC
con's avatar
con committed
764
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+O")));
765
#endif
con's avatar
con committed
766
767
768
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // Default open action
769
    dd->m_openFileAction = new QAction(tr("Open File"), this);
770
    cmd = ActionManager::registerAction(dd->m_openFileAction, Constants::OPENFILE,
dt's avatar
dt committed
771
772
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
con's avatar
con committed
773

774
    dd->m_searchOnFileSystem = new QAction(FileUtils::msgFindInDirectory(), this);
775
    cmd = ActionManager::registerAction(dd->m_searchOnFileSystem, Constants::SEARCHONFILESYSTEM, projecTreeContext);
776
777

    mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
778
779
780
781
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_CONFIG);
    msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);

782
    dd->m_showInGraphicalShell = new QAction(FileUtils::msgGraphicalShellAction(), this);
783
    cmd = ActionManager::registerAction(dd->m_showInGraphicalShell, Constants::SHOWINGRAPHICALSHELL,
dt's avatar
dt committed
784
785
786
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
787

788
    dd->m_openTerminalHere = new QAction(FileUtils::msgTerminalAction(), this);
789
    cmd = ActionManager::registerAction(dd->m_openTerminalHere, Constants::OPENTERMIANLHERE,
dt's avatar
dt committed
790
791
792
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
793

con's avatar
con committed
794
    // Open With menu
795
    mfileContextMenu->addMenu(openWith, Constants::G_FILE_OPEN);
con's avatar
con committed
796

mae's avatar
mae committed
797
    // recent projects menu
798
799
    ActionContainer *mrecent =
        ActionManager::createMenu(Constants::M_RECENTPROJECTS);
800
    mrecent->menu()->setTitle(tr("Recent P&rojects"));
801
    mrecent->setOnAllDisabledBehavior(ActionContainer::Show);
mae's avatar
mae committed
802
    mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
803
    connect(mfile->menu(), &QMenu::aboutToShow,
804
            dd, &ProjectExplorerPluginPrivate::updateRecentProjectMenu);
mae's avatar
mae committed
805

806
    // session menu
807
    ActionContainer *msession = ActionManager::createMenu(Constants::M_SESSION);
808
    msession->menu()->setTitle(tr("Sessions"));
809
    msession->setOnAllDisabledBehavior(ActionContainer::Show);
810
    mfile->addMenu(msession, Core::Constants::G_FILE_OPEN);
811
    dd->m_sessionMenu = msession->menu();
812
    connect(mfile->menu(), &QMenu::aboutToShow,
813
            dd, &ProjectExplorerPluginPrivate::updateSessionMenu);
814
815

    // session manager action
816
    dd->m_sessionManagerAction = new QAction(tr("Session Manager..."), this);
817
    cmd = ActionManager::registerAction(dd->m_sessionManagerAction, Constants::NEWSESSION);
818
819
820
821
    mfile->addAction(cmd, Core::Constants::G_FILE_OPEN);
    cmd->setDefaultKeySequence(QKeySequence());


con's avatar
con committed
822
    // unload action
823
    dd->m_unloadAction = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
824
                                                      Utils::ParameterAction::AlwaysEnabled, this);
825
    cmd = ActionManager::registerAction(dd->m_unloadAction, Constants::UNLOAD);
826
    cmd->setAttribute(Command::CA_UpdateText);
827
    cmd->setDescription(dd->m_unloadAction->text());
con's avatar
con committed
828
829
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);

830
831
832
833
834
    ActionContainer *munload =
        ActionManager::createMenu(Constants::M_UNLOADPROJECTS);
    munload->menu()->setTitle(tr("Close Project"));
    munload->setOnAllDisabledBehavior(ActionContainer::Show);
    mfile->addMenu(munload, Core::Constants::G_FILE_PROJECT);
835
    connect(mfile->menu(), &QMenu::aboutToShow,
836
            dd, &ProjectExplorerPluginPrivate::updateUnloadProjectMenu);
837

con's avatar
con committed
838
    // unload session action
839
    dd->m_closeAllProjects = new QAction(tr("Close All Projects and Editors"), this);
840
    cmd = ActionManager::registerAction(dd->m_closeAllProjects, Constants::CLEARSESSION);
con's avatar
con committed
841
842
843
844
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // build session action
Friedemann Kleint's avatar
Friedemann Kleint committed
845
    QIcon buildIcon = QIcon(QLatin1String(Constants::ICON_BUILD));
846
    buildIcon.addFile(QLatin1String(Constants::ICON_BUILD_SMALL));
847
    dd->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
848
    cmd = ActionManager::registerAction(dd->m_buildSessionAction, Constants::BUILDSESSION);
con's avatar
con committed
849
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+B")));
850
851
852
853
    mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // deploy session
854
    dd->m_deploySessionAction = new QAction(tr("Deploy All"), this);
855
    cmd = ActionManager::registerAction(dd->m_deploySessionAction, Constants::DEPLOYSESSION);
856
    mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);
con's avatar
con committed
857
858
859
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // rebuild session action
Friedemann Kleint's avatar
Friedemann Kleint committed
860
    QIcon rebuildIcon = QIcon(QLatin1String(Constants::ICON_REBUILD));
861
    rebuildIcon.addFile(QLatin1String(Constants::ICON_REBUILD_SMALL));
862
    dd->m_rebuildSessionAction = new QAction(rebuildIcon, tr("Rebuild All"), this);