projectexplorer.cpp 122 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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
12
13
14
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

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

Tobias Hunger's avatar
Tobias Hunger committed
32
#include "buildsteplist.h"
33
#include "deployablefile.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
#include "deployconfiguration.h"
35
#include "gcctoolchainfactories.h"
36
#include "project.h"
37
#include "projectexplorersettings.h"
38
#include "projectmacroexpander.h"
39
#include "removetaskhandler.h"
Tobias Hunger's avatar
Tobias Hunger committed
40
41
#include "kitmanager.h"
#include "kitoptionspage.h"
Tobias Hunger's avatar
Tobias Hunger committed
42
43
#include "target.h"
#include "targetsettingspanel.h"
44
45
#include "toolchainmanager.h"
#include "toolchainoptionspage.h"
46
#include "copytaskhandler.h"
47
#include "showineditortaskhandler.h"
48
#include "vcsannotatetaskhandler.h"
49
#include "localapplicationruncontrol.h"
con's avatar
con committed
50
51
52
53
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
54
#include "currentprojectfind.h"
con's avatar
con committed
55
#include "currentprojectfilter.h"
56
#include "editorsettingspropertiespage.h"
57
#include "codestylesettingspropertiespage.h"
58
#include "dependenciespanel.h"
con's avatar
con committed
59
60
61
62
#include "foldernavigationwidget.h"
#include "iprojectmanager.h"
#include "metatypedeclarations.h"
#include "nodesvisitor.h"
63
#include "appoutputpane.h"
con's avatar
con committed
64
65
66
#include "pluginfilefactory.h"
#include "processstep.h"
#include "projectexplorerconstants.h"
67
#include "customwizard.h"
Tobias Hunger's avatar
Tobias Hunger committed
68
#include "kitinformation.h"
con's avatar
con committed
69
70
71
72
73
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "runsettingspropertiespage.h"
#include "session.h"
74
#include "projectnodes.h"
con's avatar
con committed
75
#include "sessiondialog.h"
Tobias Hunger's avatar
Tobias Hunger committed
76
#include "target.h"
77
#include "projectexplorersettingspage.h"
78
#include "projectwelcomepage.h"
79
#include "corelistenercheckingforrunningbuild.h"
80
#include "buildconfiguration.h"
81
#include "miniprojecttargetselector.h"
dt's avatar
dt committed
82
#include "taskhub.h"
83
#include "customtoolchain.h"
Tobias Hunger's avatar
Tobias Hunger committed
84
85
86
#include "devicesupport/desktopdevice.h"
#include "devicesupport/desktopdevicefactory.h"
#include "devicesupport/devicemanager.h"
87
#include "devicesupport/devicesettingspage.h"
88
89
#include "publishing/ipublishingwizardfactory.h"
#include "publishing/publishingwizardselectiondialog.h"
con's avatar
con committed
90

91
#ifdef Q_OS_WIN
92
#    include "windebuginterface.h"
93
#    include "msvctoolchain.h"
SteveKing's avatar
SteveKing committed
94
#    include "wincetoolchain.h"
95
96
#endif

97
#include <extensionsystem/pluginspec.h>
con's avatar
con committed
98
#include <coreplugin/coreconstants.h>
99
#include <coreplugin/documentmanager.h>
100
#include <coreplugin/icore.h>
101
#include <coreplugin/idocument.h>
102
#include <coreplugin/imode.h>
con's avatar
con committed
103
104
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
105
#include <coreplugin/actionmanager/actionmanager.h>
106
107
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
108
#include <coreplugin/id.h>
109
#include <coreplugin/infobar.h>
con's avatar
con committed
110
111
112
113
114
115
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/basefilewizard.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
116
#include <coreplugin/variablemanager.h>
Robert Loehning's avatar
Robert Loehning committed
117
#include <coreplugin/fileutils.h>
118
#include <coreplugin/removefiledialog.h>
119
#include <extensionsystem/pluginmanager.h>
120
#include <find/searchresultwindow.h>
121
#include <utils/consoleprocess.h>
hjk's avatar
hjk committed
122
#include <utils/qtcassert.h>
123
#include <utils/parameteraction.h>
124
#include <utils/stringutils.h>
Jarek Kobus's avatar
Jarek Kobus committed
125
#include <utils/persistentsettings.h>
con's avatar
con committed
126

127
128
129
#include <QtPlugin>
#include <QDateTime>
#include <QDebug>
130
#include <QFileInfo>
131
#include <QSettings>
Morten Johan Sorvig's avatar
Morten Johan Sorvig committed
132

133
134
135
136
137
#include <QAction>
#include <QApplication>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
138
#include <QTimer>
139
#include <QWizard>
con's avatar
con committed
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*!
    \namespace ProjectExplorer
    ProjectExplorer plugin namespace
*/

/*!
    \namespace ProjectExplorer::Internal
    Internal namespace of the ProjectExplorer plugin
    \internal
*/

/*!
    \class ProjectExplorer::ProjectExplorerPlugin

    \brief ProjectExplorerPlugin with static accessor and utility functions to obtain
    current project, open projects, etc.
*/

con's avatar
con committed
159
160
namespace {
bool debug = false;
161
const char EXTERNAL_FILE_WARNING[] = "ExternalFile";
con's avatar
con committed
162
163
}

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
namespace ProjectExplorer {

struct ProjectExplorerPluginPrivate {
    ProjectExplorerPluginPrivate();

    QMenu *m_sessionContextMenu;
    QMenu *m_sessionMenu;
    QMenu *m_projectMenu;
    QMenu *m_subProjectMenu;
    QMenu *m_folderMenu;
    QMenu *m_fileMenu;
    QMenu *m_openWithMenu;

    QMultiMap<int, QObject*> m_actionMap;
    QAction *m_sessionManagerAction;
    QAction *m_newAction;
    QAction *m_loadAction;
181
    Utils::ParameterAction *m_unloadAction;
182
    QAction *m_closeAllProjects;
183
    QAction *m_buildProjectOnlyAction;
184
    Utils::ParameterAction *m_buildAction;
185
    QAction *m_buildActionContextMenu;
186
187
    QAction *m_buildSessionAction;
    QAction *m_rebuildProjectOnlyAction;
188
    Utils::ParameterAction *m_rebuildAction;
189
    QAction *m_rebuildActionContextMenu;
190
191
    QAction *m_rebuildSessionAction;
    QAction *m_cleanProjectOnlyAction;
Tobias Hunger's avatar
Tobias Hunger committed
192
193
    QAction *m_deployProjectOnlyAction;
    Utils::ParameterAction *m_deployAction;
194
    QAction *m_deployActionContextMenu;
Tobias Hunger's avatar
Tobias Hunger committed
195
    QAction *m_deploySessionAction;
196
    Utils::ParameterAction *m_publishAction;
197
    Utils::ParameterAction *m_cleanAction;
198
    QAction *m_cleanActionContextMenu;
199
200
201
    QAction *m_cleanSessionAction;
    QAction *m_runAction;
    QAction *m_runActionContextMenu;
202
    QAction *m_runWithoutDeployAction;
203
204
205
    QAction *m_cancelBuildAction;
    QAction *m_addNewFileAction;
    QAction *m_addExistingFilesAction;
206
    QAction *m_addNewSubprojectAction;
207
    QAction *m_removeFileAction;
208
    QAction *m_removeProjectAction;
209
    QAction *m_deleteFileAction;
210
    QAction *m_renameFileAction;
dt's avatar
dt committed
211
    QAction *m_openFileAction;
212
    QAction *m_projectTreeCollapseAllAction;
213
    QAction *m_searchOnFileSystem;
dt's avatar
dt committed
214
215
    QAction *m_showInGraphicalShell;
    QAction *m_openTerminalHere;
216
    Utils::ParameterAction *m_setStartupProjectAction;
217
    QAction *m_projectSelectorAction;
218
    QAction *m_projectSelectorActionMenu;
Daniel Teske's avatar
Daniel Teske committed
219
    QAction *m_projectSelectorActionQuick;
dt's avatar
dt committed
220
    QAction *m_runSubProject;
221
222
223
224
225
226
227
228
229
230
231
232

    Internal::ProjectWindow *m_proWindow;
    SessionManager *m_session;
    QString m_sessionToRestoreAtStartup;

    Project *m_currentProject;
    Node *m_currentNode;

    BuildManager *m_buildManager;

    QList<Internal::ProjectFileFactory*> m_fileFactories;
    QStringList m_profileMimeTypes;
233
    Internal::AppOutputPane *m_outputPane;
234
235
236
237
238

    QList<QPair<QString, QString> > m_recentProjects; // pair of filename, displayname
    static const int m_maxRecentProjects = 7;

    QString m_lastOpenDirectory;
Daniel Teske's avatar
Daniel Teske committed
239
    RunConfiguration *m_delayedRunConfiguration;
240
    RunMode m_runMode;
241
    QString m_projectFilterString;
242
    Internal::MiniProjectTargetSelector * m_targetSelector;
243
    Internal::ProjectExplorerSettings m_projectExplorerSettings;
244
    Internal::ProjectWelcomePage *m_welcomePage;
245

246
    Core::IMode *m_projectsMode;
247

248
    TaskHub *m_taskHub;
Tobias Hunger's avatar
Tobias Hunger committed
249
    KitManager *m_kitManager;
Tobias Hunger's avatar
Tobias Hunger committed
250
    ToolChainManager *m_toolChainManager;
251
    bool m_shuttingDown;
252
    QStringList m_arguments;
253
254
255
256
257
258
};

ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
    m_currentProject(0),
    m_currentNode(0),
    m_delayedRunConfiguration(0),
259
    m_runMode(NoRunMode),
260
    m_projectsMode(0),
Tobias Hunger's avatar
Tobias Hunger committed
261
    m_kitManager(0),
Tobias Hunger's avatar
Tobias Hunger committed
262
    m_toolChainManager(0),
263
    m_shuttingDown(false)
264
265
266
{
}

267
268
269
class ProjectsMode : public Core::IMode
{
public:
270
271
272
273
    ProjectsMode(QWidget *proWindow)
    {
        setWidget(proWindow);
        setContext(Core::Context(Constants::C_PROJECTEXPLORER));
274
275
276
        setDisplayName(QCoreApplication::translate("ProjectExplorer::ProjectsMode", "Projects"));
        setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Project.png")));
        setPriority(Constants::P_MODE_SESSION);
277
278
        setId(Constants::MODE_SESSION);
        setType(Core::Id());
279
        setContextHelpId(QLatin1String("Managing Projects"));
280
    }
281
282
};

283
284
}  // namespace ProjectExplorer

con's avatar
con committed
285
286
287
288
289
290
291
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;


ProjectExplorerPlugin *ProjectExplorerPlugin::m_instance = 0;

ProjectExplorerPlugin::ProjectExplorerPlugin()
292
    : d(new ProjectExplorerPluginPrivate)
con's avatar
con committed
293
294
295
296
297
298
{
    m_instance = this;
}

ProjectExplorerPlugin::~ProjectExplorerPlugin()
{
299
300
    removeObject(d->m_welcomePage);
    delete d->m_welcomePage;
con's avatar
con committed
301
    removeObject(this);
Tobias Hunger's avatar
Tobias Hunger committed
302
    // Force sequence of deletion:
Tobias Hunger's avatar
Tobias Hunger committed
303
    delete d->m_kitManager; // remove all the profile informations
Tobias Hunger's avatar
Tobias Hunger committed
304
305
    delete d->m_toolChainManager;

306
    delete d;
con's avatar
con committed
307
308
309
310
311
312
313
}

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

314
315
316
317
318
319
bool ProjectExplorerPlugin::parseArguments(const QStringList &arguments, QString * /* error */)
{
    CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
    return true;
}

320
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
321
{
Friedemann Kleint's avatar
Friedemann Kleint committed
322
    qRegisterMetaType<ProjectExplorer::RunControl *>();
323
    qRegisterMetaType<ProjectExplorer::DeployableFile>("ProjectExplorer::DeployableFile");
Friedemann Kleint's avatar
Friedemann Kleint committed
324

325
326
    if (!parseArguments(arguments, error))
        return false;
dt's avatar
dt committed
327
328
    addObject(this);

329
    // Add ToolChainFactories:
330
#ifdef Q_OS_WIN
331
332
    addAutoReleasedObject(new WinDebugInterface);

333
    addAutoReleasedObject(new Internal::MsvcToolChainFactory);
SteveKing's avatar
SteveKing committed
334
    addAutoReleasedObject(new Internal::WinCEToolChainFactory);
335
336
#else
    addAutoReleasedObject(new Internal::LinuxIccToolChainFactory);
Tobias Hunger's avatar
Tobias Hunger committed
337
338
339
#endif
#ifndef Q_OS_MAC
    addAutoReleasedObject(new Internal::MingwToolChainFactory); // Mingw offers cross-compiling to windows
340
#endif
341
    addAutoReleasedObject(new Internal::GccToolChainFactory);
Tobias Hunger's avatar
Tobias Hunger committed
342
    addAutoReleasedObject(new Internal::ClangToolChainFactory);
343
    addAutoReleasedObject(new Internal::CustomToolChainFactory);
344

Tobias Hunger's avatar
Tobias Hunger committed
345
346
    addAutoReleasedObject(new Internal::DesktopDeviceFactory);

Tobias Hunger's avatar
Tobias Hunger committed
347
    d->m_kitManager = new KitManager; // register before ToolChainManager
348
    new DeviceManager; // Create DeviceManager singleton
Tobias Hunger's avatar
Tobias Hunger committed
349
    d->m_toolChainManager = new ToolChainManager;
350
351
352
353

    // Register KitInformation:
    KitManager::instance()->registerKitInformation(new DeviceTypeKitInformation);
    KitManager::instance()->registerKitInformation(new DeviceKitInformation);
354
    KitManager::instance()->registerKitInformation(new ToolChainKitInformation);
355
356
    KitManager::instance()->registerKitInformation(new SysRootKitInformation);

357
    addAutoReleasedObject(new Internal::ToolChainOptionsPage);
Tobias Hunger's avatar
Tobias Hunger committed
358
    addAutoReleasedObject(new KitOptionsPage);
359

360
361
    d->m_taskHub = new TaskHub;
    addAutoReleasedObject(d->m_taskHub);
362

hjk's avatar
hjk committed
363
    connect(Core::ICore::instance(), SIGNAL(newItemsDialogRequested()), this, SLOT(loadCustomWizards()));
con's avatar
con committed
364

365
    d->m_welcomePage = new ProjectWelcomePage;
366
    connect(d->m_welcomePage, SIGNAL(manageSessions()), this, SLOT(showSessionManager()));
367
    addObject(d->m_welcomePage);
con's avatar
con committed
368

369
    connect(Core::DocumentManager::instance(), SIGNAL(currentFileChanged(QString)),
hjk's avatar
hjk committed
370
            this, SLOT(setCurrentFile(QString)));
con's avatar
con committed
371

372
    d->m_session = new SessionManager(this);
con's avatar
con committed
373

Robert Loehning's avatar
Robert Loehning committed
374
    connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
con's avatar
con committed
375
            this, SIGNAL(fileListChanged()));
Robert Loehning's avatar
Robert Loehning committed
376
377
378
    connect(d->m_session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
            this, SLOT(invalidateProject(ProjectExplorer::Project*)));
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
con's avatar
con committed
379
            this, SIGNAL(fileListChanged()));
380
381
382
383
    connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
            this, SLOT(projectAdded(ProjectExplorer::Project*)));
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
            this, SLOT(projectRemoved(ProjectExplorer::Project*)));
Robert Loehning's avatar
Robert Loehning committed
384
    connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
con's avatar
con committed
385
            this, SLOT(startupProjectChanged()));
386
387
    connect(d->m_session, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
            this, SLOT(projectDisplayNameChanged(ProjectExplorer::Project*)));
388
389
    connect(d->m_session, SIGNAL(dependencyChanged(ProjectExplorer::Project*,ProjectExplorer::Project*)),
            this, SLOT(updateActions()));
390
    connect(d->m_session, SIGNAL(sessionLoaded(QString)),
391
            this, SLOT(updateActions()));
392
    connect(d->m_session, SIGNAL(sessionLoaded(QString)),
393
            this, SLOT(updateWelcomePage()));
con's avatar
con committed
394

395
    d->m_proWindow = new ProjectWindow;
Orgad Shaneh's avatar
Orgad Shaneh committed
396
    addAutoReleasedObject(d->m_proWindow);
con's avatar
con committed
397

398
    Core::Context globalcontext(Core::Constants::C_GLOBAL);
dt's avatar
dt committed
399
    Core::Context projecTreeContext(Constants::C_PROJECT_TREE);
con's avatar
con committed
400

401
    d->m_projectsMode = new ProjectsMode(d->m_proWindow);
402
    d->m_projectsMode->setEnabled(false);
403
    addAutoReleasedObject(d->m_projectsMode);
404
    d->m_proWindow->layout()->addWidget(new Core::FindToolBarPlaceHolder(d->m_proWindow));
con's avatar
con committed
405

406
    addAutoReleasedObject(new CopyTaskHandler);
407
    addAutoReleasedObject(new ShowInEditorTaskHandler);
408
    addAutoReleasedObject(new VcsAnnotateTaskHandler);
409
    addAutoReleasedObject(new RemoveTaskHandler);
410
    addAutoReleasedObject(new CoreListener);
con's avatar
con committed
411

412
    d->m_outputPane = new AppOutputPane;
413
    addAutoReleasedObject(d->m_outputPane);
Robert Loehning's avatar
Robert Loehning committed
414
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
415
            d->m_outputPane, SLOT(projectRemoved()));
con's avatar
con committed
416

417
418
419
420
421
    connect(d->m_outputPane, SIGNAL(runControlStarted(ProjectExplorer::RunControl*)),
            this, SIGNAL(runControlStarted(ProjectExplorer::RunControl*)));
    connect(d->m_outputPane, SIGNAL(runControlFinished(ProjectExplorer::RunControl*)),
            this, SIGNAL(runControlFinished(ProjectExplorer::RunControl*)));

422
    AllProjectsFilter *allProjectsFilter = new AllProjectsFilter(this);
con's avatar
con committed
423
424
    addAutoReleasedObject(allProjectsFilter);

425
    CurrentProjectFilter *currentProjectFilter = new CurrentProjectFilter(this);
con's avatar
con committed
426
427
428
429
430
    addAutoReleasedObject(currentProjectFilter);

    addAutoReleasedObject(new BuildSettingsPanelFactory);
    addAutoReleasedObject(new RunSettingsPanelFactory);
    addAutoReleasedObject(new EditorSettingsPanelFactory);
431
    addAutoReleasedObject(new CodeStyleSettingsPanelFactory);
432
    addAutoReleasedObject(new DependenciesPanelFactory(d->m_session));
con's avatar
con committed
433
434
435
436

    ProcessStepFactory *processStepFactory = new ProcessStepFactory;
    addAutoReleasedObject(processStepFactory);

437
    AllProjectsFind *allProjectsFind = new AllProjectsFind(this);
con's avatar
con committed
438
439
    addAutoReleasedObject(allProjectsFind);

440
    CurrentProjectFind *currentProjectFind = new CurrentProjectFind(this);
con's avatar
con committed
441
442
    addAutoReleasedObject(currentProjectFind);

443
    addAutoReleasedObject(new LocalApplicationRunControlFactory);
con's avatar
con committed
444

445
    addAutoReleasedObject(new ProjectFileWizardExtension);
con's avatar
con committed
446

447
    // Settings pages
448
    addAutoReleasedObject(new ProjectExplorerSettingsPage);
449
    addAutoReleasedObject(new DeviceSettingsPage);
450

con's avatar
con committed
451
    // context menus
452
    Core::ActionContainer *msessionContextMenu =
Eike Ziller's avatar
Eike Ziller committed
453
        Core::ActionManager::createMenu(Constants::M_SESSIONCONTEXT);
dt's avatar
dt committed
454
    Core::ActionContainer *mprojectContextMenu =
Eike Ziller's avatar
Eike Ziller committed
455
        Core::ActionManager::createMenu(Constants::M_PROJECTCONTEXT);
dt's avatar
dt committed
456
    Core::ActionContainer *msubProjectContextMenu =
Eike Ziller's avatar
Eike Ziller committed
457
        Core::ActionManager::createMenu(Constants::M_SUBPROJECTCONTEXT);
dt's avatar
dt committed
458
    Core::ActionContainer *mfolderContextMenu =
Eike Ziller's avatar
Eike Ziller committed
459
        Core::ActionManager::createMenu(Constants::M_FOLDERCONTEXT);
dt's avatar
dt committed
460
    Core::ActionContainer *mfileContextMenu =
Eike Ziller's avatar
Eike Ziller committed
461
        Core::ActionManager::createMenu(Constants::M_FILECONTEXT);
con's avatar
con committed
462

463
    d->m_sessionContextMenu = msessionContextMenu->menu();
dt's avatar
dt committed
464
465
466
467
    d->m_projectMenu = mprojectContextMenu->menu();
    d->m_subProjectMenu = msubProjectContextMenu->menu();
    d->m_folderMenu = mfolderContextMenu->menu();
    d->m_fileMenu = mfileContextMenu->menu();
con's avatar
con committed
468

469
    Core::ActionContainer *mfile =
Eike Ziller's avatar
Eike Ziller committed
470
        Core::ActionManager::actionContainer(Core::Constants::M_FILE);
471
    Core::ActionContainer *menubar =
Eike Ziller's avatar
Eike Ziller committed
472
        Core::ActionManager::actionContainer(Core::Constants::MENU_BAR);
con's avatar
con committed
473
474

    // build menu
475
    Core::ActionContainer *mbuild =
Eike Ziller's avatar
Eike Ziller committed
476
        Core::ActionManager::createMenu(Constants::M_BUILDPROJECT);
477
    mbuild->menu()->setTitle(tr("&Build"));
con's avatar
con committed
478
479
480
    menubar->addMenu(mbuild, Core::Constants::G_VIEW);

    // debug menu
481
    Core::ActionContainer *mdebug =
Eike Ziller's avatar
Eike Ziller committed
482
        Core::ActionManager::createMenu(Constants::M_DEBUG);
483
    mdebug->menu()->setTitle(tr("&Debug"));
con's avatar
con committed
484
485
    menubar->addMenu(mdebug, Core::Constants::G_VIEW);

486
    Core::ActionContainer *mstartdebugging =
Eike Ziller's avatar
Eike Ziller committed
487
        Core::ActionManager::createMenu(Constants::M_DEBUG_STARTDEBUGGING);
488
489
    mstartdebugging->menu()->setTitle(tr("&Start Debugging"));
    mdebug->addMenu(mstartdebugging, Core::Constants::G_DEFAULT_ONE);
con's avatar
con committed
490
491
492
493
494

    //
    // Groups
    //

495
496
497
498
    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
499
    mbuild->appendGroup(Constants::G_BUILD_CANCEL);
dt's avatar
dt committed
500
    mbuild->appendGroup(Constants::G_BUILD_RUN);
con's avatar
con committed
501
502

    msessionContextMenu->appendGroup(Constants::G_SESSION_BUILD);
503
    msessionContextMenu->appendGroup(Constants::G_SESSION_REBUILD);
con's avatar
con committed
504
505
    msessionContextMenu->appendGroup(Constants::G_SESSION_FILES);
    msessionContextMenu->appendGroup(Constants::G_SESSION_OTHER);
506
    msessionContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
507

dt's avatar
dt committed
508
509
510
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
511
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_REBUILD);
dt's avatar
dt committed
512
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
513
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
514
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
515

dt's avatar
dt committed
516
517
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
dt's avatar
dt committed
518
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
dt's avatar
dt committed
519
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
520
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
521
    msubProjectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
522

Eike Ziller's avatar
Eike Ziller committed
523
    Core::ActionContainer *runMenu = Core::ActionManager::createMenu(Constants::RUNMENUCONTEXTMENU);
dt's avatar
dt committed
524
    runMenu->setOnAllDisabledBehavior(Core::ActionContainer::Hide);
Friedemann Kleint's avatar
Friedemann Kleint committed
525
    QIcon runIcon = QIcon(QLatin1String(Constants::ICON_RUN));
526
    runIcon.addFile(QLatin1String(Constants::ICON_RUN_SMALL));
dt's avatar
dt committed
527
    runMenu->menu()->setIcon(runIcon);
528
    runMenu->menu()->setTitle(tr("Run"));
dt's avatar
dt committed
529
530
    msubProjectContextMenu->addMenu(runMenu, ProjectExplorer::Constants::G_PROJECT_RUN);

dt's avatar
dt committed
531
532
533
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_FILES);
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_OTHER);
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_CONFIG);
534
    mfolderContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
535

dt's avatar
dt committed
536
537
538
    mfileContextMenu->appendGroup(Constants::G_FILE_OPEN);
    mfileContextMenu->appendGroup(Constants::G_FILE_OTHER);
    mfileContextMenu->appendGroup(Constants::G_FILE_CONFIG);
539
    mfileContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
540
    // "open with" submenu
541
    Core::ActionContainer * const openWith =
Eike Ziller's avatar
Eike Ziller committed
542
            Core::ActionManager::createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
543
    openWith->setOnAllDisabledBehavior(Core::ActionContainer::Show);
544
545
    d->m_openWithMenu = openWith->menu();
    d->m_openWithMenu->setTitle(tr("Open With"));
con's avatar
con committed
546

Robert Loehning's avatar
Robert Loehning committed
547
    connect(d->m_openWithMenu, SIGNAL(triggered(QAction*)),
548
            Core::DocumentManager::instance(), SLOT(slotExecuteOpenWithMenuAction(QAction*)));
con's avatar
con committed
549
550
551
552
553

    //
    // Separators
    //

con's avatar
con committed
554
    Core::Command *cmd;
con's avatar
con committed
555

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

558
559
560
561
562
563
564
565
566
    msessionContextMenu->addSeparator(projecTreeContext, Constants::G_SESSION_FILES);
    mprojectContextMenu->addSeparator(projecTreeContext, Constants::G_PROJECT_FILES);
    msubProjectContextMenu->addSeparator(projecTreeContext, Constants::G_PROJECT_FILES);
    mfile->addSeparator(globalcontext, Core::Constants::G_FILE_PROJECT);
    mbuild->addSeparator(globalcontext, Constants::G_BUILD_REBUILD);
    msessionContextMenu->addSeparator(globalcontext, Constants::G_SESSION_OTHER);
    mbuild->addSeparator(globalcontext, Constants::G_BUILD_CANCEL);
    mbuild->addSeparator(globalcontext, Constants::G_BUILD_RUN);
    mprojectContextMenu->addSeparator(globalcontext, Constants::G_PROJECT_REBUILD);
con's avatar
con committed
567
568
569
570
571
572

    //
    // Actions
    //

    // new action
573
    d->m_newAction = new QAction(tr("New Project..."), this);
Eike Ziller's avatar
Eike Ziller committed
574
    cmd = Core::ActionManager::registerAction(d->m_newAction, Constants::NEWPROJECT, globalcontext);
con's avatar
con committed
575
576
577
578
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+N")));
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // open action
579
    d->m_loadAction = new QAction(tr("Load Project..."), this);
Eike Ziller's avatar
Eike Ziller committed
580
    cmd = Core::ActionManager::registerAction(d->m_loadAction, Constants::LOAD, globalcontext);
581
#ifndef Q_OS_MAC
con's avatar
con committed
582
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+O")));
583
#endif
con's avatar
con committed
584
585
586
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // Default open action
587
    d->m_openFileAction = new QAction(tr("Open File"), this);
Eike Ziller's avatar
Eike Ziller committed
588
    cmd = Core::ActionManager::registerAction(d->m_openFileAction, ProjectExplorer::Constants::OPENFILE,
dt's avatar
dt committed
589
590
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
con's avatar
con committed
591

592
    d->m_searchOnFileSystem = new QAction(FolderNavigationWidget::msgFindOnFileSystem(), this);
Eike Ziller's avatar
Eike Ziller committed
593
    cmd = Core::ActionManager::registerAction(d->m_searchOnFileSystem, ProjectExplorer::Constants::SEARCHONFILESYSTEM, projecTreeContext);
594
595
596
597
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_CONFIG);
    msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);

598
    d->m_showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), this);
Eike Ziller's avatar
Eike Ziller committed
599
    cmd = Core::ActionManager::registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
dt's avatar
dt committed
600
601
602
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
603

604
    d->m_openTerminalHere = new QAction(Core::FileUtils::msgTerminalAction(), this);
Eike Ziller's avatar
Eike Ziller committed
605
    cmd = Core::ActionManager::registerAction(d->m_openTerminalHere, ProjectExplorer::Constants::OPENTERMIANLHERE,
dt's avatar
dt committed
606
607
608
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
609

con's avatar
con committed
610
    // Open With menu
dt's avatar
dt committed
611
    mfileContextMenu->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN);
con's avatar
con committed
612

mae's avatar
mae committed
613
    // recent projects menu
614
    Core::ActionContainer *mrecent =
Eike Ziller's avatar
Eike Ziller committed
615
        Core::ActionManager::createMenu(Constants::M_RECENTPROJECTS);
616
    mrecent->menu()->setTitle(tr("Recent P&rojects"));
617
    mrecent->setOnAllDisabledBehavior(Core::ActionContainer::Show);
mae's avatar
mae committed
618
619
620
621
    mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
    connect(mfile->menu(), SIGNAL(aboutToShow()),
        this, SLOT(updateRecentProjectMenu()));

622
    // session menu
Eike Ziller's avatar
Eike Ziller committed
623
    Core::ActionContainer *msession = Core::ActionManager::createMenu(Constants::M_SESSION);
624
    msession->menu()->setTitle(tr("Sessions"));
625
626
627
628
629
630
631
632
    msession->setOnAllDisabledBehavior(Core::ActionContainer::Show);
    mfile->addMenu(msession, Core::Constants::G_FILE_OPEN);
    d->m_sessionMenu = msession->menu();
    connect(mfile->menu(), SIGNAL(aboutToShow()),
            this, SLOT(updateSessionMenu()));

    // session manager action
    d->m_sessionManagerAction = new QAction(tr("Session Manager..."), this);
Eike Ziller's avatar
Eike Ziller committed
633
    cmd = Core::ActionManager::registerAction(d->m_sessionManagerAction, Constants::NEWSESSION, globalcontext);
634
635
636
637
    mfile->addAction(cmd, Core::Constants::G_FILE_OPEN);
    cmd->setDefaultKeySequence(QKeySequence());


dt's avatar
dt committed
638
    // XXX same action?
con's avatar
con committed
639
    // unload action
640
641
    d->m_unloadAction = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
                                                      Utils::ParameterAction::EnabledWithParameter, this);
Eike Ziller's avatar
Eike Ziller committed
642
    cmd = Core::ActionManager::registerAction(d->m_unloadAction, Constants::UNLOAD, globalcontext);
con's avatar
con committed
643
    cmd->setAttribute(Core::Command::CA_UpdateText);
644
    cmd->setDescription(d->m_unloadAction->text());
con's avatar
con committed
645
646
647
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);

    // unload session action
648
    d->m_closeAllProjects = new QAction(tr("Close All Projects and Editors"), this);
Eike Ziller's avatar
Eike Ziller committed
649
    cmd = Core::ActionManager::registerAction(d->m_closeAllProjects, Constants::CLEARSESSION, globalcontext);
con's avatar
con committed
650
651
652
653
    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
654
    QIcon buildIcon = QIcon(QLatin1String(Constants::ICON_BUILD));
655
    buildIcon.addFile(QLatin1String(Constants::ICON_BUILD_SMALL));
656
    d->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
Eike Ziller's avatar
Eike Ziller committed
657
    cmd = Core::ActionManager::registerAction(d->m_buildSessionAction, Constants::BUILDSESSION, globalcontext);
con's avatar
con committed
658
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+B")));
659
660
661
662
663
    mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // deploy session
    d->m_deploySessionAction = new QAction(tr("Deploy All"), this);
Eike Ziller's avatar
Eike Ziller committed
664
    cmd = Core::ActionManager::registerAction(d->m_deploySessionAction, Constants::DEPLOYSESSION, globalcontext);
665
    mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);
con's avatar
con committed
666
667
668
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // rebuild session action
Friedemann Kleint's avatar
Friedemann Kleint committed
669
    QIcon rebuildIcon = QIcon(QLatin1String(Constants::ICON_REBUILD));
670
    rebuildIcon.addFile(QLatin1String(Constants::ICON_REBUILD_SMALL));
671
    d->m_rebuildSessionAction = new QAction(rebuildIcon, tr("Rebuild All"), this);
Eike Ziller's avatar
Eike Ziller committed
672
    cmd = Core::ActionManager::registerAction(d->m_rebuildSessionAction, Constants::REBUILDSESSION, globalcontext);
673
674
    mbuild->addAction(cmd, Constants::G_BUILD_REBUILD);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_REBUILD);
Tobias Hunger's avatar
Tobias Hunger committed
675

con's avatar
con committed
676
    // clean session
Friedemann Kleint's avatar
Friedemann Kleint committed
677
    QIcon cleanIcon = QIcon(QLatin1String(Constants::ICON_CLEAN));
678
    cleanIcon.addFile(QLatin1String(Constants::ICON_CLEAN_SMALL));
679
    d->m_cleanSessionAction = new QAction(cleanIcon, tr("Clean All"), this);
Eike Ziller's avatar
Eike Ziller committed
680
    cmd = Core::ActionManager::registerAction(d->m_cleanSessionAction, Constants::CLEANSESSION, globalcontext);
681
682
    mbuild->addAction(cmd, Constants::G_BUILD_CLEAN);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_REBUILD);
con's avatar
con committed
683
684

    // build action
685
    d->m_buildAction = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
686
                                                     Utils::ParameterAction::AlwaysEnabled, this);
dt's avatar
dt committed
687
    d->m_buildAction->setIcon(buildIcon);
Eike Ziller's avatar
Eike Ziller committed
688
    cmd = Core::ActionManager::registerAction(d->m_buildAction, Constants::BUILD, globalcontext);
689
    cmd->setAttribute(Core::Command::CA_UpdateText);
690
    cmd->setDescription(d->m_buildAction->text());
con's avatar
con committed
691
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
692
    mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
con's avatar
con committed
693

694
    // Add to mode bar
695
    Core::ModeManager::addAction(cmd->action(), Constants::P_ACTION_BUILDPROJECT);
696

697
698
699
    // deploy action
    d->m_deployAction = new Utils::ParameterAction(tr("Deploy Project"), tr("Deploy Project \"%1\""),
                                                     Utils::ParameterAction::AlwaysEnabled, this);
Eike Ziller's avatar
Eike Ziller committed
700
    cmd = Core::ActionManager::registerAction(d->m_deployAction, Constants::DEPLOY, globalcontext);
701
702
703
704
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setDescription(d->m_deployAction->text());
    mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);

con's avatar
con committed
705
    // rebuild action
706
    d->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
707
                                                       Utils::ParameterAction::AlwaysEnabled, this);
Eike Ziller's avatar
Eike Ziller committed
708
    cmd = Core::ActionManager::registerAction(d->m_rebuildAction, Constants::REBUILD, globalcontext);
709
    cmd->setAttribute(Core::Command::CA_UpdateText);
710
    cmd->setDescription(d->m_rebuildAction->text());
711
    mbuild->addAction(cmd, Constants::G_BUILD_REBUILD);
con's avatar
con committed
712

713
714
    // clean action
    d->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
Tobias Hunger's avatar
Tobias Hunger committed
715
                                                     Utils::ParameterAction::AlwaysEnabled, this);
Eike Ziller's avatar
Eike Ziller committed
716
    cmd = Core::ActionManager::registerAction(d->m_cleanAction, Constants::CLEAN, globalcontext);
Tobias Hunger's avatar
Tobias Hunger committed
717
    cmd->setAttribute(Core::Command::CA_UpdateText);
718
719
720
721
722
723
724
    cmd->setDescription(d->m_cleanAction->text());
    mbuild->addAction(cmd, Constants::G_BUILD_CLEAN);

    // cancel build action
    QIcon stopIcon = QIcon(QLatin1String(Constants::ICON_STOP));
    stopIcon.addFile(QLatin1String(Constants::ICON_STOP_SMALL));
    d->m_cancelBuildAction = new QAction(stopIcon, tr("Cancel Build"), this);
Eike Ziller's avatar
Eike Ziller committed
725
    cmd = Core::ActionManager::registerAction(d->m_cancelBuildAction, Constants::CANCELBUILD, globalcontext);
726
727
728
729
    mbuild->addAction(cmd, Constants::G_BUILD_CANCEL);

    // run action
    d->m_runAction = new QAction(runIcon, tr("Run"), this);
Eike Ziller's avatar
Eike Ziller committed
730
    cmd = Core::ActionManager::registerAction(d->m_runAction, Constants::RUN, globalcontext);
731
732
733
734
735
736
737
738
739
    cmd->setAttribute(Core::Command::CA_UpdateText);

    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R")));
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);

    Core::ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN);

    // Run without deployment action
    d->m_runWithoutDeployAction = new QAction(tr("Run Without Deployment"), this);
Eike Ziller's avatar
Eike Ziller committed
740
    cmd = Core::ActionManager::registerAction(d->m_runWithoutDeployAction, Constants::RUNWITHOUTDEPLOY, globalcontext);
741
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
Tobias Hunger's avatar
Tobias Hunger committed
742

743
744
745
    // Publish action
    d->m_publishAction = new Utils::ParameterAction(tr("Publish Project..."), tr("Publish Project \"%1\"..."),
                                                    Utils::ParameterAction::AlwaysEnabled, this);
Eike Ziller's avatar
Eike Ziller committed
746
    cmd = Core::ActionManager::registerAction(d->m_publishAction, Constants::PUBLISH, globalcontext);
747
    cmd->setAttribute(Core::Command::CA_UpdateText);
748
    cmd->setDescription(d->m_publishAction->text());
749
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
750
751

    // build action (context menu)
752
    d->m_buildActionContextMenu = new QAction(tr("Build"), this);
Eike Ziller's avatar
Eike Ziller committed
753
    cmd = Core::ActionManager::registerAction(d->m_buildActionContextMenu, Constants::BUILDCM, projecTreeContext);
754
    cmd->setAttribute(Core::Command::CA_UpdateText);
dt's avatar
dt committed
755
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
756
757

    // rebuild action (context menu)
758
    d->m_rebuildActionContextMenu = new QAction(tr("Rebuild"), this);
Eike Ziller's avatar
Eike Ziller committed
759
    cmd = Core::ActionManager::registerAction(d->m_rebuildActionContextMenu, Constants::REBUILDCM, projecTreeContext);
760
    cmd->setAttribute(Core::Command::CA_UpdateText);
761
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
Tobias Hunger's avatar
Tobias Hunger committed
762

763
    // clean action (context menu)