projectexplorer.cpp 125 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 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 "customwizard/customwizard.h"
34
#include "deployablefile.h"
Tobias Hunger's avatar
Tobias Hunger committed
35
#include "deployconfiguration.h"
36
#include "gcctoolchainfactories.h"
37
#include "project.h"
38
#include "projectexplorersettings.h"
39
#include "projectmacroexpander.h"
40
#include "removetaskhandler.h"
41
#include "unconfiguredprojectpanel.h"
Tobias Hunger's avatar
Tobias Hunger committed
42
43
#include "kitmanager.h"
#include "kitoptionspage.h"
Tobias Hunger's avatar
Tobias Hunger committed
44
#include "target.h"
45
46
#include "toolchainmanager.h"
#include "toolchainoptionspage.h"
47
#include "copytaskhandler.h"
48
#include "showineditortaskhandler.h"
49
#include "vcsannotatetaskhandler.h"
50
#include "localapplicationruncontrol.h"
con's avatar
con committed
51
52
53
54
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
55
#include "currentprojectfind.h"
con's avatar
con committed
56
#include "currentprojectfilter.h"
57
#include "editorsettingspropertiespage.h"
58
#include "codestylesettingspropertiespage.h"
59
#include "dependenciespanel.h"
con's avatar
con committed
60
61
62
#include "foldernavigationwidget.h"
#include "iprojectmanager.h"
#include "nodesvisitor.h"
63
#include "appoutputpane.h"
con's avatar
con committed
64
65
#include "pluginfilefactory.h"
#include "processstep.h"
Tobias Hunger's avatar
Tobias Hunger committed
66
#include "kitinformation.h"
con's avatar
con committed
67
68
69
70
71
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "runsettingspropertiespage.h"
#include "session.h"
72
#include "projectnodes.h"
con's avatar
con committed
73
#include "sessiondialog.h"
74
#include "projectexplorersettingspage.h"
75
#include "corelistenercheckingforrunningbuild.h"
76
#include "buildconfiguration.h"
77
#include "miniprojecttargetselector.h"
dt's avatar
dt committed
78
#include "taskhub.h"
79
#include "customtoolchain.h"
Christian Kandeler's avatar
Christian Kandeler committed
80
#include "selectablefilesmodel.h"
81
#include <projectexplorer/customwizard/customwizard.h>
Tobias Hunger's avatar
Tobias Hunger committed
82
83
84
#include "devicesupport/desktopdevice.h"
#include "devicesupport/desktopdevicefactory.h"
#include "devicesupport/devicemanager.h"
85
#include "devicesupport/devicesettingspage.h"
con's avatar
con committed
86

87
#ifdef Q_OS_WIN
88
#    include "windebuginterface.h"
89
#    include "msvctoolchain.h"
SteveKing's avatar
SteveKing committed
90
#    include "wincetoolchain.h"
91
92
#endif

93
94
95
#define HAS_WELCOME_PAGE (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))

#if HAS_WELCOME_PAGE
96
97
98
#include "projectwelcomepage.h"
#endif

99
#include <extensionsystem/pluginspec.h>
100
#include <extensionsystem/pluginmanager.h>
101
#include <coreplugin/icore.h>
102
#include <coreplugin/editormanager/ieditor.h>
103
#include <coreplugin/id.h>
con's avatar
con committed
104
#include <coreplugin/coreconstants.h>
105
#include <coreplugin/documentmanager.h>
106
#include <coreplugin/imode.h>
con's avatar
con committed
107
108
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
109
#include <coreplugin/actionmanager/actionmanager.h>
110
#include <coreplugin/actionmanager/actioncontainer.h>
111
#include <coreplugin/infobar.h>
con's avatar
con committed
112
113
114
115
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.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 <texteditor/findinfiles.h>
120
#include <utils/fileutils.h>
121
#include <utils/parameteraction.h>
122
#include <utils/qtcassert.h>
con's avatar
con committed
123

124
125
#include <QtPlugin>
#include <QDebug>
126
#include <QFileInfo>
127
#include <QSettings>
Morten Johan Sorvig's avatar
Morten Johan Sorvig committed
128

129
130
131
132
133
#include <QAction>
#include <QApplication>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
134
#include <QTimer>
135
#include <QWizard>
con's avatar
con committed
136

137
138
/*!
    \namespace ProjectExplorer
139
    The ProjectExplorer namespace contains the classes to explore projects.
140
141
142
143
*/

/*!
    \namespace ProjectExplorer::Internal
144
145
    The ProjectExplorer::Internal namespace is the internal namespace of the
    ProjectExplorer plugin.
146
147
148
149
150
151
    \internal
*/

/*!
    \class ProjectExplorer::ProjectExplorerPlugin

152
153
    \brief The ProjectExplorerPlugin class contains static accessor and utility
    functions to obtain the current project, open projects, and so on.
154
155
*/

con's avatar
con committed
156
157
namespace {
bool debug = false;
158
const char EXTERNAL_FILE_WARNING[] = "ExternalFile";
con's avatar
con committed
159
160
}

161
162
using namespace Core;

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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;
180
    Utils::ParameterAction *m_unloadAction;
181
    QAction *m_closeAllProjects;
182
    QAction *m_buildProjectOnlyAction;
183
    Utils::ParameterAction *m_buildAction;
184
    QAction *m_buildActionContextMenu;
185
186
    QAction *m_buildSessionAction;
    QAction *m_rebuildProjectOnlyAction;
187
    Utils::ParameterAction *m_rebuildAction;
188
    QAction *m_rebuildActionContextMenu;
189
190
    QAction *m_rebuildSessionAction;
    QAction *m_cleanProjectOnlyAction;
Tobias Hunger's avatar
Tobias Hunger committed
191
192
    QAction *m_deployProjectOnlyAction;
    Utils::ParameterAction *m_deployAction;
193
    QAction *m_deployActionContextMenu;
Tobias Hunger's avatar
Tobias Hunger committed
194
    QAction *m_deploySessionAction;
195
    Utils::ParameterAction *m_cleanAction;
196
    QAction *m_cleanActionContextMenu;
197
198
199
    QAction *m_cleanSessionAction;
    QAction *m_runAction;
    QAction *m_runActionContextMenu;
200
    QAction *m_runWithoutDeployAction;
201
202
203
    QAction *m_cancelBuildAction;
    QAction *m_addNewFileAction;
    QAction *m_addExistingFilesAction;
204
    QAction *m_addExistingDirectoryAction;
205
    QAction *m_addNewSubprojectAction;
206
    QAction *m_removeFileAction;
207
    QAction *m_removeProjectAction;
208
    QAction *m_deleteFileAction;
209
    QAction *m_renameFileAction;
dt's avatar
dt committed
210
    QAction *m_openFileAction;
211
    QAction *m_projectTreeCollapseAllAction;
212
    QAction *m_searchOnFileSystem;
dt's avatar
dt committed
213
214
    QAction *m_showInGraphicalShell;
    QAction *m_openTerminalHere;
215
    Utils::ParameterAction *m_setStartupProjectAction;
216
    QAction *m_projectSelectorAction;
217
    QAction *m_projectSelectorActionMenu;
Daniel Teske's avatar
Daniel Teske committed
218
    QAction *m_projectSelectorActionQuick;
dt's avatar
dt committed
219
    QAction *m_runSubProject;
220
221
222
223
224

    Internal::ProjectWindow *m_proWindow;
    QString m_sessionToRestoreAtStartup;

    Project *m_currentProject;
225
    Context m_lastProjectContext;
226
227
228
229
    Node *m_currentNode;

    QList<Internal::ProjectFileFactory*> m_fileFactories;
    QStringList m_profileMimeTypes;
230
    Internal::AppOutputPane *m_outputPane;
231
232

    QList<QPair<QString, QString> > m_recentProjects; // pair of filename, displayname
233
    static const int m_maxRecentProjects = 25;
234
235

    QString m_lastOpenDirectory;
236
237
    QPointer<RunConfiguration> m_delayedRunConfiguration;
    bool m_shouldHaveRunConfiguration;
238
    RunMode m_runMode;
239
    QString m_projectFilterString;
240
    Internal::MiniProjectTargetSelector * m_targetSelector;
241
    Internal::ProjectExplorerSettings m_projectExplorerSettings;
242

243

244
#if HAS_WELCOME_PAGE
245
246
    Internal::ProjectWelcomePage *m_welcomePage;
#endif
247
    IMode *m_projectsMode;
248

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

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

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

285
286
}  // namespace ProjectExplorer

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


ProjectExplorerPlugin *ProjectExplorerPlugin::m_instance = 0;

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

ProjectExplorerPlugin::~ProjectExplorerPlugin()
{
301
#if HAS_WELCOME_PAGE
302
303
    removeObject(d->m_welcomePage);
    delete d->m_welcomePage;
304
#endif
con's avatar
con committed
305
    removeObject(this);
Tobias Hunger's avatar
Tobias Hunger committed
306
    // Force sequence of deletion:
Tobias Hunger's avatar
Tobias Hunger committed
307
    delete d->m_kitManager; // remove all the profile informations
Tobias Hunger's avatar
Tobias Hunger committed
308
309
    delete d->m_toolChainManager;

310
    delete d;
con's avatar
con committed
311
312
313
314
315
316
317
}

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

318
319
320
321
322
323
bool ProjectExplorerPlugin::parseArguments(const QStringList &arguments, QString * /* error */)
{
    CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
    return true;
}

324
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
325
{
Friedemann Kleint's avatar
Friedemann Kleint committed
326
    qRegisterMetaType<ProjectExplorer::RunControl *>();
327
    qRegisterMetaType<ProjectExplorer::DeployableFile>("ProjectExplorer::DeployableFile");
Friedemann Kleint's avatar
Friedemann Kleint committed
328

329
330
    if (!parseArguments(arguments, error))
        return false;
dt's avatar
dt committed
331
332
    addObject(this);

333
    // Add ToolChainFactories:
334
#ifdef Q_OS_WIN
335
336
    addAutoReleasedObject(new WinDebugInterface);

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

Tobias Hunger's avatar
Tobias Hunger committed
349
350
    addAutoReleasedObject(new Internal::DesktopDeviceFactory);

Tobias Hunger's avatar
Tobias Hunger committed
351
    d->m_kitManager = new KitManager; // register before ToolChainManager
Tobias Hunger's avatar
Tobias Hunger committed
352
    d->m_toolChainManager = new ToolChainManager;
353
354

    // Register KitInformation:
355
356
357
358
    KitManager::registerKitInformation(new DeviceTypeKitInformation);
    KitManager::registerKitInformation(new DeviceKitInformation);
    KitManager::registerKitInformation(new ToolChainKitInformation);
    KitManager::registerKitInformation(new SysRootKitInformation);
359

360
    addAutoReleasedObject(new Internal::ToolChainOptionsPage);
Tobias Hunger's avatar
Tobias Hunger committed
361
    addAutoReleasedObject(new KitOptionsPage);
362

363
    addAutoReleasedObject(new TaskHub);
364

365
    connect(ICore::instance(), SIGNAL(newItemsDialogRequested()), this, SLOT(loadCustomWizards()));
con's avatar
con committed
366

367
#if HAS_WELCOME_PAGE
368
    d->m_welcomePage = new ProjectWelcomePage;
369
    connect(d->m_welcomePage, SIGNAL(manageSessions()), this, SLOT(showSessionManager()));
370
    addObject(d->m_welcomePage);
371
#endif
con's avatar
con committed
372

373
    connect(DocumentManager::instance(), SIGNAL(currentFileChanged(QString)),
hjk's avatar
hjk committed
374
            this, SLOT(setCurrentFile(QString)));
con's avatar
con committed
375

376
    QObject *sessionManager = new SessionManager(this);
con's avatar
con committed
377

378
    connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
con's avatar
con committed
379
            this, SIGNAL(fileListChanged()));
380
    connect(sessionManager, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
Robert Loehning's avatar
Robert Loehning committed
381
            this, SLOT(invalidateProject(ProjectExplorer::Project*)));
382
    connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
con's avatar
con committed
383
            this, SIGNAL(fileListChanged()));
384
    connect(sessionManager, SIGNAL(projectAdded(ProjectExplorer::Project*)),
385
            this, SLOT(projectAdded(ProjectExplorer::Project*)));
386
    connect(sessionManager, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
387
            this, SLOT(projectRemoved(ProjectExplorer::Project*)));
388
    connect(sessionManager, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
con's avatar
con committed
389
            this, SLOT(startupProjectChanged()));
390
    connect(sessionManager, SIGNAL(projectDisplayNameChanged(ProjectExplorer::Project*)),
391
            this, SLOT(projectDisplayNameChanged(ProjectExplorer::Project*)));
392
    connect(sessionManager, SIGNAL(dependencyChanged(ProjectExplorer::Project*,ProjectExplorer::Project*)),
393
            this, SLOT(updateActions()));
394
    connect(sessionManager, SIGNAL(sessionLoaded(QString)),
395
            this, SLOT(updateActions()));
396
    connect(sessionManager, SIGNAL(sessionLoaded(QString)),
397
            this, SLOT(updateWelcomePage()));
con's avatar
con committed
398

399
400
401
402
    addAutoReleasedObject(new CustomWizardFactory<CustomProjectWizard>(Core::IWizard::ProjectWizard));
    addAutoReleasedObject(new CustomWizardFactory<CustomWizard>(Core::IWizard::FileWizard));
    addAutoReleasedObject(new CustomWizardFactory<CustomWizard>(Core::IWizard::ClassWizard));

403
    d->m_proWindow = new ProjectWindow;
Orgad Shaneh's avatar
Orgad Shaneh committed
404
    addAutoReleasedObject(d->m_proWindow);
con's avatar
con committed
405

406
407
    Context globalcontext(Core::Constants::C_GLOBAL);
    Context projecTreeContext(Constants::C_PROJECT_TREE);
con's avatar
con committed
408

409
    d->m_projectsMode = new ProjectsMode(d->m_proWindow);
410
    d->m_projectsMode->setEnabled(false);
411
    addAutoReleasedObject(d->m_projectsMode);
412
    d->m_proWindow->layout()->addWidget(new FindToolBarPlaceHolder(d->m_proWindow));
con's avatar
con committed
413

414
    addAutoReleasedObject(new CopyTaskHandler);
415
    addAutoReleasedObject(new ShowInEditorTaskHandler);
416
    addAutoReleasedObject(new VcsAnnotateTaskHandler);
417
    addAutoReleasedObject(new RemoveTaskHandler);
418
    addAutoReleasedObject(new CoreListener);
con's avatar
con committed
419

420
    d->m_outputPane = new AppOutputPane;
421
    addAutoReleasedObject(d->m_outputPane);
422
    connect(SessionManager::instance(), SIGNAL(projectRemoved(ProjectExplorer::Project*)),
423
            d->m_outputPane, SLOT(projectRemoved()));
con's avatar
con committed
424

425
426
427
428
429
    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*)));

hjk's avatar
hjk committed
430
431
    addAutoReleasedObject(new AllProjectsFilter);
    addAutoReleasedObject(new CurrentProjectFilter);
con's avatar
con committed
432
433
434
435

    addAutoReleasedObject(new BuildSettingsPanelFactory);
    addAutoReleasedObject(new RunSettingsPanelFactory);
    addAutoReleasedObject(new EditorSettingsPanelFactory);
436
    addAutoReleasedObject(new CodeStyleSettingsPanelFactory);
437
    addAutoReleasedObject(new DependenciesPanelFactory);
con's avatar
con committed
438

hjk's avatar
hjk committed
439
    addAutoReleasedObject(new ProcessStepFactory);
440
    addAutoReleasedObject(new UnconfiguredProjectPanel);
con's avatar
con committed
441

hjk's avatar
hjk committed
442
443
    addAutoReleasedObject(new AllProjectsFind);
    addAutoReleasedObject(new CurrentProjectFind);
con's avatar
con committed
444

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

447
    addAutoReleasedObject(new ProjectFileWizardExtension);
con's avatar
con committed
448

449
    // Settings pages
450
    addAutoReleasedObject(new ProjectExplorerSettingsPage);
451
    addAutoReleasedObject(new DeviceSettingsPage);
452

con's avatar
con committed
453
    // context menus
454
455
456
457
458
459
460
461
462
463
    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
464

465
    d->m_sessionContextMenu = msessionContextMenu->menu();
dt's avatar
dt committed
466
467
468
469
    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
470

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

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

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

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

    //
    // Groups
    //

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

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

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

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

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

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

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

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

    //
    // Separators
    //

556
    Command *cmd;
con's avatar
con committed
557

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

560
561
562
563
564
565
566
567
568
    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
569
570
571
572
573
574

    //
    // Actions
    //

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

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

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

594
    d->m_searchOnFileSystem = new QAction(FileUtils::msgFindInDirectory(), this);
595
    cmd = ActionManager::registerAction(d->m_searchOnFileSystem, ProjectExplorer::Constants::SEARCHONFILESYSTEM, projecTreeContext);
596
597

    mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
598
599
600
601
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_CONFIG);
    msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);

602
603
    d->m_showInGraphicalShell = new QAction(FileUtils::msgGraphicalShellAction(), this);
    cmd = ActionManager::registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
dt's avatar
dt committed
604
605
606
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
607

608
609
    d->m_openTerminalHere = new QAction(FileUtils::msgTerminalAction(), this);
    cmd = ActionManager::registerAction(d->m_openTerminalHere, ProjectExplorer::Constants::OPENTERMIANLHERE,
dt's avatar
dt committed
610
611
612
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
613

con's avatar
con committed
614
    // Open With menu
dt's avatar
dt committed
615
    mfileContextMenu->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN);
con's avatar
con committed
616

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

626
    // session menu
627
    ActionContainer *msession = ActionManager::createMenu(Constants::M_SESSION);
628
    msession->menu()->setTitle(tr("Sessions"));
629
    msession->setOnAllDisabledBehavior(ActionContainer::Show);
630
631
632
633
634
635
636
    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);
637
    cmd = ActionManager::registerAction(d->m_sessionManagerAction, Constants::NEWSESSION, globalcontext);
638
639
640
641
    mfile->addAction(cmd, Core::Constants::G_FILE_OPEN);
    cmd->setDefaultKeySequence(QKeySequence());


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

    // unload session action
652
    d->m_closeAllProjects = new QAction(tr("Close All Projects and Editors"), this);
653
    cmd = ActionManager::registerAction(d->m_closeAllProjects, Constants::CLEARSESSION, globalcontext);
con's avatar
con committed
654
655
656
657
    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
658
    QIcon buildIcon = QIcon(QLatin1String(Constants::ICON_BUILD));
659
    buildIcon.addFile(QLatin1String(Constants::ICON_BUILD_SMALL));
660
    d->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
661
    cmd = ActionManager::registerAction(d->m_buildSessionAction, Constants::BUILDSESSION, globalcontext);
con's avatar
con committed
662
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+B")));
663
664
665
666
667
    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);
668
    cmd = ActionManager::registerAction(d->m_deploySessionAction, Constants::DEPLOYSESSION, globalcontext);
669
    mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);
con's avatar
con committed
670
671
672
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

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

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

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

698
    // Add to mode bar
699
    ModeManager::addAction(cmd->action(), Constants::P_ACTION_BUILDPROJECT);
700

701
702
703
    // deploy action
    d->m_deployAction = new Utils::ParameterAction(tr("Deploy Project"), tr("Deploy Project \"%1\""),
                                                     Utils::ParameterAction::AlwaysEnabled, this);
704
705
    cmd = ActionManager::registerAction(d->m_deployAction, Constants::DEPLOY, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
706
707
708
    cmd->setDescription(d->m_deployAction->text());
    mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);

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

717
718
    // clean action
    d->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
Tobias Hunger's avatar
Tobias Hunger committed
719
                                                     Utils::ParameterAction::AlwaysEnabled, this);
720
721
    cmd = ActionManager::registerAction(d->m_cleanAction, Constants::CLEAN, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
722
723
724
725
726
727
728
    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);
729
    cmd = ActionManager::registerAction(d->m_cancelBuildAction, Constants::CANCELBUILD, globalcontext);
730
731
732
733
    mbuild->addAction(cmd, Constants::G_BUILD_CANCEL);

    // run action
    d->m_runAction = new QAction(runIcon, tr("Run"), this);
734
735
    cmd = ActionManager::registerAction(d->m_runAction, Constants::RUN, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
736
737
738
739

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

740
    ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN);
741
742
743

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

747
    // build action (context menu)
748
    d->m_buildActionContextMenu = new QAction(tr("Build"), this);
749
750
    cmd = ActionManager::registerAction(d->m_buildActionContextMenu, Constants::BUILDCM, projecTreeContext);
    cmd->setAttribute(Command::CA_UpdateText);
dt's avatar
dt committed
751
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
752
753

    // rebuild action (context menu)
754
    d->m_rebuildActionContextMenu = new QAction(tr("Rebuild"), this);
755
756
    cmd = ActionManager::registerAction(d->m_rebuildActionContextMenu, Constants::REBUILDCM, projecTreeContext);
    cmd->setAttribute(Command::CA_UpdateText);
757
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
Tobias Hunger's avatar
Tobias Hunger committed
758

759
    // clean action (context menu)
760
    d->m_cleanActionContextMenu = new QAction(tr("Clean"), this);
761
762
    cmd = ActionManager::registerAction(d->m_cleanActionContextMenu, Constants::CLEANCM, projecTreeContext);
    cmd->setAttribute(Command::CA_UpdateText);
763
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
con's avatar
con committed
764