projectexplorer.cpp 120 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
#include "target.h"
43 44
#include "toolchainmanager.h"
#include "toolchainoptionspage.h"
45
#include "copytaskhandler.h"
46
#include "showineditortaskhandler.h"
47
#include "vcsannotatetaskhandler.h"
48
#include "localapplicationruncontrol.h"
con's avatar
con committed
49 50 51 52
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
53
#include "currentprojectfind.h"
con's avatar
con committed
54
#include "currentprojectfilter.h"
55
#include "editorsettingspropertiespage.h"
56
#include "codestylesettingspropertiespage.h"
57
#include "dependenciespanel.h"
con's avatar
con committed
58 59 60
#include "foldernavigationwidget.h"
#include "iprojectmanager.h"
#include "nodesvisitor.h"
61
#include "appoutputpane.h"
con's avatar
con committed
62 63
#include "pluginfilefactory.h"
#include "processstep.h"
Tobias Hunger's avatar
Tobias Hunger committed
64
#include "kitinformation.h"
con's avatar
con committed
65 66 67 68 69
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "runsettingspropertiespage.h"
#include "session.h"
70
#include "projectnodes.h"
con's avatar
con committed
71
#include "sessiondialog.h"
72
#include "projectexplorersettingspage.h"
73
#include "corelistenercheckingforrunningbuild.h"
74
#include "buildconfiguration.h"
75
#include "miniprojecttargetselector.h"
dt's avatar
dt committed
76
#include "taskhub.h"
77
#include "customtoolchain.h"
78
#include <projectexplorer/customwizard/customwizard.h>
Tobias Hunger's avatar
Tobias Hunger committed
79 80 81
#include "devicesupport/desktopdevice.h"
#include "devicesupport/desktopdevicefactory.h"
#include "devicesupport/devicemanager.h"
82
#include "devicesupport/devicesettingspage.h"
83 84
#include "publishing/ipublishingwizardfactory.h"
#include "publishing/publishingwizardselectiondialog.h"
con's avatar
con committed
85

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

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

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

98
#include <extensionsystem/pluginspec.h>
99
#include <coreplugin/icore.h>
100
#include <coreplugin/editormanager/ieditor.h>
101
#include <coreplugin/id.h>
con's avatar
con committed
102
#include <coreplugin/coreconstants.h>
103
#include <coreplugin/documentmanager.h>
104
#include <coreplugin/imode.h>
con's avatar
con committed
105 106
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
107
#include <coreplugin/actionmanager/actionmanager.h>
108
#include <coreplugin/actionmanager/actioncontainer.h>
109
#include <coreplugin/infobar.h>
con's avatar
con committed
110 111 112 113
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
114
#include <coreplugin/variablemanager.h>
Robert Loehning's avatar
Robert Loehning committed
115
#include <coreplugin/fileutils.h>
116
#include <coreplugin/removefiledialog.h>
117
#include <texteditor/findinfiles.h>
hjk's avatar
hjk committed
118
#include <utils/qtcassert.h>
119
#include <utils/parameteraction.h>
con's avatar
con committed
120

121 122
#include <QtPlugin>
#include <QDebug>
123
#include <QFileInfo>
124
#include <QSettings>
Morten Johan Sorvig's avatar
Morten Johan Sorvig committed
125

126 127 128 129 130
#include <QAction>
#include <QApplication>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
131
#include <QTimer>
132
#include <QWizard>
con's avatar
con committed
133

134 135 136 137 138 139 140 141 142 143 144 145 146 147
/*!
    \namespace ProjectExplorer
    ProjectExplorer plugin namespace
*/

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

/*!
    \class ProjectExplorer::ProjectExplorerPlugin

148 149
    \brief The ProjectExplorerPlugin class contains static accessor and utility
    functions to obtain the current project, open projects, and so on.
150 151
*/

con's avatar
con committed
152 153
namespace {
bool debug = false;
154
const char EXTERNAL_FILE_WARNING[] = "ExternalFile";
con's avatar
con committed
155 156
}

157 158
using namespace Core;

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

    Internal::ProjectWindow *m_proWindow;
    QString m_sessionToRestoreAtStartup;

    Project *m_currentProject;
221
    Context m_lastProjectContext;
222 223 224 225
    Node *m_currentNode;

    QList<Internal::ProjectFileFactory*> m_fileFactories;
    QStringList m_profileMimeTypes;
226
    Internal::AppOutputPane *m_outputPane;
227 228 229 230 231

    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
232
    RunConfiguration *m_delayedRunConfiguration;
233
    RunMode m_runMode;
234
    QString m_projectFilterString;
235
    Internal::MiniProjectTargetSelector * m_targetSelector;
236
    Internal::ProjectExplorerSettings m_projectExplorerSettings;
237

238

239
#if HAS_WELCOME_PAGE
240 241
    Internal::ProjectWelcomePage *m_welcomePage;
#endif
242
    IMode *m_projectsMode;
243

244
    TaskHub *m_taskHub;
Tobias Hunger's avatar
Tobias Hunger committed
245
    KitManager *m_kitManager;
Tobias Hunger's avatar
Tobias Hunger committed
246
    ToolChainManager *m_toolChainManager;
247
    bool m_shuttingDown;
248
    bool m_ignoreDocumentManagerChangedFile;
249
    QStringList m_arguments;
250 251 252 253 254 255
};

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

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

280 281
}  // namespace ProjectExplorer

con's avatar
con committed
282 283 284 285 286 287 288
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;


ProjectExplorerPlugin *ProjectExplorerPlugin::m_instance = 0;

ProjectExplorerPlugin::ProjectExplorerPlugin()
289
    : d(new ProjectExplorerPluginPrivate)
con's avatar
con committed
290 291 292 293 294 295
{
    m_instance = this;
}

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

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

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

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

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

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

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

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

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

Tobias Hunger's avatar
Tobias Hunger committed
346
    d->m_kitManager = new KitManager; // register before ToolChainManager
Tobias Hunger's avatar
Tobias Hunger committed
347
    d->m_toolChainManager = new ToolChainManager;
348 349

    // Register KitInformation:
350 351 352 353
    KitManager::registerKitInformation(new DeviceTypeKitInformation);
    KitManager::registerKitInformation(new DeviceKitInformation);
    KitManager::registerKitInformation(new ToolChainKitInformation);
    KitManager::registerKitInformation(new SysRootKitInformation);
354

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

358
    addAutoReleasedObject(new TaskHub);
359

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

362
#if HAS_WELCOME_PAGE
363
    d->m_welcomePage = new ProjectWelcomePage;
364
    connect(d->m_welcomePage, SIGNAL(manageSessions()), this, SLOT(showSessionManager()));
365
    addObject(d->m_welcomePage);
366
#endif
con's avatar
con committed
367

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

371
    QObject *sessionManager = new SessionManager(this);
con's avatar
con committed
372

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

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

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

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

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

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

416 417 418 419 420
    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
421 422
    addAutoReleasedObject(new AllProjectsFilter);
    addAutoReleasedObject(new CurrentProjectFilter);
con's avatar
con committed
423 424 425 426

    addAutoReleasedObject(new BuildSettingsPanelFactory);
    addAutoReleasedObject(new RunSettingsPanelFactory);
    addAutoReleasedObject(new EditorSettingsPanelFactory);
427
    addAutoReleasedObject(new CodeStyleSettingsPanelFactory);
428
    addAutoReleasedObject(new DependenciesPanelFactory);
con's avatar
con committed
429

hjk's avatar
hjk committed
430
    addAutoReleasedObject(new ProcessStepFactory);
con's avatar
con committed
431

hjk's avatar
hjk committed
432 433
    addAutoReleasedObject(new AllProjectsFind);
    addAutoReleasedObject(new CurrentProjectFind);
con's avatar
con committed
434

435
    addAutoReleasedObject(new LocalApplicationRunControlFactory);
con's avatar
con committed
436

437
    addAutoReleasedObject(new ProjectFileWizardExtension);
con's avatar
con committed
438

439
    // Settings pages
440
    addAutoReleasedObject(new ProjectExplorerSettingsPage);
441
    addAutoReleasedObject(new DeviceSettingsPage);
442

con's avatar
con committed
443
    // context menus
444 445 446 447 448 449 450 451 452 453
    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
454

455
    d->m_sessionContextMenu = msessionContextMenu->menu();
dt's avatar
dt committed
456 457 458 459
    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
460

461 462 463 464
    ActionContainer *mfile =
        ActionManager::actionContainer(Core::Constants::M_FILE);
    ActionContainer *menubar =
        ActionManager::actionContainer(Core::Constants::MENU_BAR);
con's avatar
con committed
465 466

    // build menu
467 468
    ActionContainer *mbuild =
        ActionManager::createMenu(Constants::M_BUILDPROJECT);
469
    mbuild->menu()->setTitle(tr("&Build"));
con's avatar
con committed
470 471 472
    menubar->addMenu(mbuild, Core::Constants::G_VIEW);

    // debug menu
473 474
    ActionContainer *mdebug =
        ActionManager::createMenu(Constants::M_DEBUG);
475
    mdebug->menu()->setTitle(tr("&Debug"));
con's avatar
con committed
476 477
    menubar->addMenu(mdebug, Core::Constants::G_VIEW);

478 479
    ActionContainer *mstartdebugging =
        ActionManager::createMenu(Constants::M_DEBUG_STARTDEBUGGING);
480 481
    mstartdebugging->menu()->setTitle(tr("&Start Debugging"));
    mdebug->addMenu(mstartdebugging, Core::Constants::G_DEFAULT_ONE);
con's avatar
con committed
482 483 484 485 486

    //
    // Groups
    //

487 488 489 490
    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
491
    mbuild->appendGroup(Constants::G_BUILD_CANCEL);
dt's avatar
dt committed
492
    mbuild->appendGroup(Constants::G_BUILD_RUN);
con's avatar
con committed
493 494

    msessionContextMenu->appendGroup(Constants::G_SESSION_BUILD);
495
    msessionContextMenu->appendGroup(Constants::G_SESSION_REBUILD);
con's avatar
con committed
496 497
    msessionContextMenu->appendGroup(Constants::G_SESSION_FILES);
    msessionContextMenu->appendGroup(Constants::G_SESSION_OTHER);
498
    msessionContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
499

dt's avatar
dt committed
500 501 502
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
503
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_REBUILD);
dt's avatar
dt committed
504
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
505
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
506
    mprojectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
507

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

515 516
    ActionContainer *runMenu = ActionManager::createMenu(Constants::RUNMENUCONTEXTMENU);
    runMenu->setOnAllDisabledBehavior(ActionContainer::Hide);
Friedemann Kleint's avatar
Friedemann Kleint committed
517
    QIcon runIcon = QIcon(QLatin1String(Constants::ICON_RUN));
518
    runIcon.addFile(QLatin1String(Constants::ICON_RUN_SMALL));
dt's avatar
dt committed
519
    runMenu->menu()->setIcon(runIcon);
520
    runMenu->menu()->setTitle(tr("Run"));
dt's avatar
dt committed
521 522
    msubProjectContextMenu->addMenu(runMenu, ProjectExplorer::Constants::G_PROJECT_RUN);

dt's avatar
dt committed
523 524 525
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_FILES);
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_OTHER);
    mfolderContextMenu->appendGroup(Constants::G_FOLDER_CONFIG);
526
    mfolderContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
527

dt's avatar
dt committed
528 529 530
    mfileContextMenu->appendGroup(Constants::G_FILE_OPEN);
    mfileContextMenu->appendGroup(Constants::G_FILE_OTHER);
    mfileContextMenu->appendGroup(Constants::G_FILE_CONFIG);
531
    mfileContextMenu->appendGroup(Constants::G_PROJECT_TREE);
con's avatar
con committed
532
    // "open with" submenu
533 534 535
    ActionContainer * const openWith =
            ActionManager::createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
    openWith->setOnAllDisabledBehavior(ActionContainer::Show);
536 537
    d->m_openWithMenu = openWith->menu();
    d->m_openWithMenu->setTitle(tr("Open With"));
con's avatar
con committed
538

Robert Loehning's avatar
Robert Loehning committed
539
    connect(d->m_openWithMenu, SIGNAL(triggered(QAction*)),
540
            DocumentManager::instance(), SLOT(slotExecuteOpenWithMenuAction(QAction*)));
con's avatar
con committed
541 542 543 544 545

    //
    // Separators
    //

546
    Command *cmd;
con's avatar
con committed
547

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

550 551 552 553 554 555 556 557 558
    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
559 560 561 562 563 564

    //
    // Actions
    //

    // new action
565
    d->m_newAction = new QAction(tr("New Project..."), this);
566
    cmd = ActionManager::registerAction(d->m_newAction, Constants::NEWPROJECT, globalcontext);
con's avatar
con committed
567 568 569 570
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+N")));
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // open action
571
    d->m_loadAction = new QAction(tr("Load Project..."), this);
572
    cmd = ActionManager::registerAction(d->m_loadAction, Constants::LOAD, globalcontext);
573
#ifndef Q_OS_MAC
con's avatar
con committed
574
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+O")));
575
#endif
con's avatar
con committed
576 577 578
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // Default open action
579
    d->m_openFileAction = new QAction(tr("Open File"), this);
580
    cmd = ActionManager::registerAction(d->m_openFileAction, ProjectExplorer::Constants::OPENFILE,
dt's avatar
dt committed
581 582
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
con's avatar
con committed
583

584
    d->m_searchOnFileSystem = new QAction(FolderNavigationWidget::msgFindOnFileSystem(), this);
585
    cmd = ActionManager::registerAction(d->m_searchOnFileSystem, ProjectExplorer::Constants::SEARCHONFILESYSTEM, projecTreeContext);
586 587 588 589
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_CONFIG);
    msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
    mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);

590 591
    d->m_showInGraphicalShell = new QAction(FileUtils::msgGraphicalShellAction(), this);
    cmd = ActionManager::registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
dt's avatar
dt committed
592 593 594
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
595

596 597
    d->m_openTerminalHere = new QAction(FileUtils::msgTerminalAction(), this);
    cmd = ActionManager::registerAction(d->m_openTerminalHere, ProjectExplorer::Constants::OPENTERMIANLHERE,
dt's avatar
dt committed
598 599 600
                       projecTreeContext);
    mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
    mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
601

con's avatar
con committed
602
    // Open With menu
dt's avatar
dt committed
603
    mfileContextMenu->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN);
con's avatar
con committed
604

mae's avatar
mae committed
605
    // recent projects menu
606 607
    ActionContainer *mrecent =
        ActionManager::createMenu(Constants::M_RECENTPROJECTS);
608
    mrecent->menu()->setTitle(tr("Recent P&rojects"));
609
    mrecent->setOnAllDisabledBehavior(ActionContainer::Show);
mae's avatar
mae committed
610 611 612 613
    mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
    connect(mfile->menu(), SIGNAL(aboutToShow()),
        this, SLOT(updateRecentProjectMenu()));

614
    // session menu
615
    ActionContainer *msession = ActionManager::createMenu(Constants::M_SESSION);
616
    msession->menu()->setTitle(tr("Sessions"));
617
    msession->setOnAllDisabledBehavior(ActionContainer::Show);
618 619 620 621 622 623 624
    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);
625
    cmd = ActionManager::registerAction(d->m_sessionManagerAction, Constants::NEWSESSION, globalcontext);
626 627 628 629
    mfile->addAction(cmd, Core::Constants::G_FILE_OPEN);
    cmd->setDefaultKeySequence(QKeySequence());


dt's avatar
dt committed
630
    // XXX same action?
con's avatar
con committed
631
    // unload action
632 633
    d->m_unloadAction = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
                                                      Utils::ParameterAction::EnabledWithParameter, this);
634 635
    cmd = ActionManager::registerAction(d->m_unloadAction, Constants::UNLOAD, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
636
    cmd->setDescription(d->m_unloadAction->text());
con's avatar
con committed
637 638 639
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);

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

    // rebuild session action
Friedemann Kleint's avatar
Friedemann Kleint committed
661
    QIcon rebuildIcon = QIcon(QLatin1String(Constants::ICON_REBUILD));
662
    rebuildIcon.addFile(QLatin1String(Constants::ICON_REBUILD_SMALL));
663
    d->m_rebuildSessionAction = new QAction(rebuildIcon, tr("Rebuild All"), this);
664
    cmd = ActionManager::registerAction(d->m_rebuildSessionAction, Constants::REBUILDSESSION, globalcontext);
665 666
    mbuild->addAction(cmd, Constants::G_BUILD_REBUILD);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_REBUILD);
Tobias Hunger's avatar
Tobias Hunger committed
667

con's avatar
con committed
668
    // clean session
Friedemann Kleint's avatar
Friedemann Kleint committed
669
    QIcon cleanIcon = QIcon(QLatin1String(Constants::ICON_CLEAN));
670
    cleanIcon.addFile(QLatin1String(Constants::ICON_CLEAN_SMALL));
671
    d->m_cleanSessionAction = new QAction(cleanIcon, tr("Clean All"), this);
672
    cmd = ActionManager::registerAction(d->m_cleanSessionAction, Constants::CLEANSESSION, globalcontext);
673 674
    mbuild->addAction(cmd, Constants::G_BUILD_CLEAN);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_REBUILD);
con's avatar
con committed
675 676

    // build action
677
    d->m_buildAction = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
678
                                                     Utils::ParameterAction::AlwaysEnabled, this);
dt's avatar
dt committed
679
    d->m_buildAction->setIcon(buildIcon);
680 681
    cmd = ActionManager::registerAction(d->m_buildAction, Constants::BUILD, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
682
    cmd->setDescription(d->m_buildAction->text());
con's avatar
con committed
683
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
684
    mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
con's avatar
con committed
685

686
    // Add to mode bar
687
    ModeManager::addAction(cmd->action(), Constants::P_ACTION_BUILDPROJECT);
688

689 690 691
    // deploy action
    d->m_deployAction = new Utils::ParameterAction(tr("Deploy Project"), tr("Deploy Project \"%1\""),
                                                     Utils::ParameterAction::AlwaysEnabled, this);
692 693
    cmd = ActionManager::registerAction(d->m_deployAction, Constants::DEPLOY, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
694 695 696
    cmd->setDescription(d->m_deployAction->text());
    mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);

con's avatar
con committed
697
    // rebuild action
698
    d->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
699
                                                       Utils::ParameterAction::AlwaysEnabled, this);
700 701
    cmd = ActionManager::registerAction(d->m_rebuildAction, Constants::REBUILD, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
702
    cmd->setDescription(d->m_rebuildAction->text());
703
    mbuild->addAction(cmd, Constants::G_BUILD_REBUILD);
con's avatar
con committed
704

705 706
    // clean action
    d->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
Tobias Hunger's avatar
Tobias Hunger committed
707
                                                     Utils::ParameterAction::AlwaysEnabled, this);
708 709
    cmd = ActionManager::registerAction(d->m_cleanAction, Constants::CLEAN, globalcontext);
    cmd->setAttribute(Command::CA_UpdateText);
710 711 712 713 714 715 716
    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);
717
    cmd = ActionManager::registerAction(d->m_cancelBuildAction, Constants::CANCELBUILD, globalcontext);