projectexplorer.cpp 91 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

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

32
#include "project.h"
33
#include "projectexplorersettings.h"
Tobias Hunger's avatar
Tobias Hunger committed
34
35
#include "target.h"
#include "targetsettingspanel.h"
36
#include "copytaskhandler.h"
37
#include "showineditortaskhandler.h"
38
#include "vcsannotatetaskhandler.h"
con's avatar
con committed
39
40
41
42
43
#include "applicationrunconfiguration.h"
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
44
#include "currentprojectfind.h"
con's avatar
con committed
45
46
#include "currentprojectfilter.h"
#include "customexecutablerunconfiguration.h"
47
48
#include "editorsettingspropertiespage.h"
#include "dependenciespanel.h"
con's avatar
con committed
49
50
51
52
53
54
55
56
57
#include "foldernavigationwidget.h"
#include "iprojectmanager.h"
#include "metatypedeclarations.h"
#include "nodesvisitor.h"
#include "outputwindow.h"
#include "persistentsettings.h"
#include "pluginfilefactory.h"
#include "processstep.h"
#include "projectexplorerconstants.h"
58
#include "customwizard.h"
con's avatar
con committed
59
60
61
62
63
64
65
66
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "removefiledialog.h"
#include "runsettingspropertiespage.h"
#include "scriptwrappers.h"
#include "session.h"
#include "sessiondialog.h"
Tobias Hunger's avatar
Tobias Hunger committed
67
#include "target.h"
68
#include "projectexplorersettingspage.h"
69
70
#include "projectwelcomepage.h"
#include "projectwelcomepagewidget.h"
71
#include "corelistenercheckingforrunningbuild.h"
72
#include "buildconfiguration.h"
73
#include "buildconfigdialog.h"
74
#include "miniprojecttargetselector.h"
dt's avatar
dt committed
75
#include "taskhub.h"
con's avatar
con committed
76
77
78

#include <coreplugin/basemode.h>
#include <coreplugin/coreconstants.h>
79
80
#include <coreplugin/filemanager.h>
#include <coreplugin/icore.h>
con's avatar
con committed
81
82
83
#include <coreplugin/mainwindow.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
84
#include <coreplugin/actionmanager/actionmanager.h>
85
86
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
con's avatar
con committed
87
88
89
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
90
#include <coreplugin/editormanager/iexternaleditor.h>
con's avatar
con committed
91
92
93
94
#include <coreplugin/findplaceholder.h>
#include <coreplugin/basefilewizard.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
95
#include <welcome/welcomemode.h>
96
#include <extensionsystem/pluginmanager.h>
97
#include <utils/consoleprocess.h>
hjk's avatar
hjk committed
98
#include <utils/qtcassert.h>
99
#include <utils/parameteraction.h>
con's avatar
con committed
100

101
#include <QtCore/QtPlugin>
hjk's avatar
hjk committed
102
#include <QtCore/QDateTime>
con's avatar
con committed
103
104
#include <QtCore/QDebug>
#include <QtCore/QSettings>
hjk's avatar
hjk committed
105

con's avatar
con committed
106
107
#include <QtGui/QAction>
#include <QtGui/QApplication>
hjk's avatar
hjk committed
108
109
110
#include <QtGui/QFileDialog>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
con's avatar
con committed
111

112
113
Q_DECLARE_METATYPE(Core::IEditorFactory*);
Q_DECLARE_METATYPE(Core::IExternalEditor*);
con's avatar
con committed
114
115
116
117
118

namespace {
bool debug = false;
}

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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;
#if 0
    QAction *m_loadAction;
#endif
138
    Utils::ParameterAction *m_unloadAction;
139
140
    QAction *m_clearSession;
    QAction *m_buildProjectOnlyAction;
141
    Utils::ParameterAction *m_buildAction;
142
    Utils::ParameterAction *m_buildActionContextMenu;
143
144
    QAction *m_buildSessionAction;
    QAction *m_rebuildProjectOnlyAction;
145
    Utils::ParameterAction *m_rebuildAction;
146
    Utils::ParameterAction *m_rebuildActionContextMenu;
147
148
    QAction *m_rebuildSessionAction;
    QAction *m_cleanProjectOnlyAction;
Tobias Hunger's avatar
Tobias Hunger committed
149
150
151
152
    QAction *m_deployProjectOnlyAction;
    Utils::ParameterAction *m_deployAction;
    Utils::ParameterAction *m_deployActionContextMenu;
    QAction *m_deploySessionAction;
153
    Utils::ParameterAction *m_cleanAction;
154
    Utils::ParameterAction *m_cleanActionContextMenu;
155
156
157
158
159
160
161
162
163
    QAction *m_cleanSessionAction;
    QAction *m_runAction;
    QAction *m_runActionContextMenu;
    QAction *m_cancelBuildAction;
    QAction *m_debugAction;
    QAction *m_addNewFileAction;
    QAction *m_addExistingFilesAction;
    QAction *m_openFileAction;
    QAction *m_showInGraphicalShell;
164
    QAction *m_openTerminalHere;
165
166
    QAction *m_removeFileAction;
    QAction *m_renameFileAction;
167
    QAction *m_projectSelectorAction;
168
    QAction *m_projectSelectorActionMenu;
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

    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;
    Internal::OutputPane *m_outputPane;

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

    QString m_lastOpenDirectory;
187
    RunConfiguration *m_delayedRunConfiguration; // TODO this is not right
188
189
190
    RunControl *m_debuggingRunControl;
    QString m_runMode;
    QString m_projectFilterString;
191
    Internal::MiniProjectTargetSelector * m_targetSelector;
192
    Internal::ProjectExplorerSettings m_projectExplorerSettings;
193
    Internal::ProjectWelcomePage *m_welcomePage;
194
195

    Core::BaseMode * m_projectsMode;
196
197
198
199
200
201
};

ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
    m_currentProject(0),
    m_currentNode(0),
    m_delayedRunConfiguration(0),
202
203
    m_debuggingRunControl(0),
    m_projectsMode(0)
204
205
206
207
208
{
}

}  // namespace ProjectExplorer

con's avatar
con committed
209
210
211
212
213
214
215
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;


ProjectExplorerPlugin *ProjectExplorerPlugin::m_instance = 0;

ProjectExplorerPlugin::ProjectExplorerPlugin()
216
    : d(new ProjectExplorerPluginPrivate)
con's avatar
con committed
217
218
219
220
221
222
{
    m_instance = this;
}

ProjectExplorerPlugin::~ProjectExplorerPlugin()
{
223
224
    removeObject(d->m_welcomePage);
    delete d->m_welcomePage;
con's avatar
con committed
225
    removeObject(this);
226
    delete d;
con's avatar
con committed
227
228
229
230
231
232
233
}

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

234
235
236
237
238
239
bool ProjectExplorerPlugin::parseArguments(const QStringList &arguments, QString * /* error */)
{
    CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
    return true;
}

240
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
241
{
242
243
    if (!parseArguments(arguments, error))
        return false;
dt's avatar
dt committed
244
245
246
    addObject(this);

    addAutoReleasedObject(new TaskHub);
247

248
249
    Core::ICore *core = Core::ICore::instance();
    Core::ActionManager *am = core->actionManager();
con's avatar
con committed
250

251
    d->m_welcomePage = new ProjectWelcomePage;
252
    connect(d->m_welcomePage, SIGNAL(manageSessions()), this, SLOT(showSessionManager()));
253
    addObject(d->m_welcomePage);
con's avatar
con committed
254

hjk's avatar
hjk committed
255
256
    connect(core->fileManager(), SIGNAL(currentFileChanged(QString)),
            this, SLOT(setCurrentFile(QString)));
con's avatar
con committed
257

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

260
    connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project *)),
con's avatar
con committed
261
            this, SIGNAL(fileListChanged()));
262
    connect(d->m_session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project *)),
con's avatar
con committed
263
            this, SLOT(invalidateProject(ProjectExplorer::Project *)));
264
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project *)),
con's avatar
con committed
265
            this, SIGNAL(fileListChanged()));
266
    connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
con's avatar
con committed
267
            this, SLOT(startupProjectChanged()));
268
269
    connect(d->m_session, SIGNAL(dependencyChanged(ProjectExplorer::Project*,ProjectExplorer::Project*)),
            this, SLOT(updateActions()));
con's avatar
con committed
270

271
    d->m_proWindow = new ProjectWindow;
con's avatar
con committed
272

273
    Core::Context globalcontext(Core::Constants::C_GLOBAL);
274
    Core::Context pecontext(Constants::C_PROJECTEXPLORER);
con's avatar
con committed
275

276
277
278
279
280
281
    d->m_projectsMode = new Core::BaseMode;
    d->m_projectsMode->setDisplayName(tr("Projects"));
    d->m_projectsMode->setId(QLatin1String(Constants::MODE_SESSION));
    d->m_projectsMode->setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Project.png")));
    d->m_projectsMode->setPriority(Constants::P_MODE_SESSION);
    d->m_projectsMode->setWidget(d->m_proWindow);
282
    d->m_projectsMode->setContext(pecontext);
283
    d->m_projectsMode->setEnabled(session()->startupProject());
Daniel Molkentin's avatar
Daniel Molkentin committed
284
    d->m_projectsMode->setContextHelpId(QLatin1String("Managing Projects"));
285
    addAutoReleasedObject(d->m_projectsMode);
286
    d->m_proWindow->layout()->addWidget(new Core::FindToolBarPlaceHolder(d->m_proWindow));
con's avatar
con committed
287

288
    addAutoReleasedObject(new CopyTaskHandler);
289
    addAutoReleasedObject(new ShowInEditorTaskHandler);
290
    addAutoReleasedObject(new VcsAnnotateTaskHandler);
291

292
293
    d->m_buildManager = new BuildManager(this);
    connect(d->m_buildManager, SIGNAL(buildStateChanged(ProjectExplorer::Project *)),
con's avatar
con committed
294
            this, SLOT(buildStateChanged(ProjectExplorer::Project *)));
295
    connect(d->m_buildManager, SIGNAL(buildQueueFinished(bool)),
con's avatar
con committed
296
297
            this, SLOT(buildQueueFinished(bool)));

298
    addAutoReleasedObject(new CoreListenerCheckingForRunningBuild(d->m_buildManager));
con's avatar
con committed
299

300
301
302
303
    d->m_outputPane = new OutputPane;
    addAutoReleasedObject(d->m_outputPane);
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project *)),
            d->m_outputPane, SLOT(projectRemoved()));
con's avatar
con committed
304

305
    AllProjectsFilter *allProjectsFilter = new AllProjectsFilter(this);
con's avatar
con committed
306
307
    addAutoReleasedObject(allProjectsFilter);

308
    CurrentProjectFilter *currentProjectFilter = new CurrentProjectFilter(this);
con's avatar
con committed
309
310
311
312
313
    addAutoReleasedObject(currentProjectFilter);

    addAutoReleasedObject(new BuildSettingsPanelFactory);
    addAutoReleasedObject(new RunSettingsPanelFactory);
    addAutoReleasedObject(new EditorSettingsPanelFactory);
314
    addAutoReleasedObject(new DependenciesPanelFactory(d->m_session));
con's avatar
con committed
315
316
317
318

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

319
320
321
    ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
    AllProjectsFind *allProjectsFind = new AllProjectsFind(this,
        pm->getObject<Find::SearchResultWindow>());
con's avatar
con committed
322
323
    addAutoReleasedObject(allProjectsFind);

324
325
    CurrentProjectFind *currentProjectFind = new CurrentProjectFind(this,
        pm->getObject<Find::SearchResultWindow>());
con's avatar
con committed
326
327
    addAutoReleasedObject(currentProjectFind);

328
    addAutoReleasedObject(new LocalApplicationRunControlFactory);
con's avatar
con committed
329
330
    addAutoReleasedObject(new CustomExecutableRunConfigurationFactory);

331
    addAutoReleasedObject(new ProjectFileWizardExtension);
con's avatar
con committed
332

333
334
335
    // Settings page
    addAutoReleasedObject(new ProjectExplorerSettingsPage);

con's avatar
con committed
336
    // context menus
337
    Core::ActionContainer *msessionContextMenu =
con's avatar
con committed
338
        am->createMenu(Constants::M_SESSIONCONTEXT);
339
    Core::ActionContainer *mproject =
con's avatar
con committed
340
        am->createMenu(Constants::M_PROJECTCONTEXT);
341
    Core::ActionContainer *msubProject =
con's avatar
con committed
342
        am->createMenu(Constants::M_SUBPROJECTCONTEXT);
343
    Core::ActionContainer *mfolder =
con's avatar
con committed
344
        am->createMenu(Constants::M_FOLDERCONTEXT);
345
    Core::ActionContainer *mfilec =
con's avatar
con committed
346
347
        am->createMenu(Constants::M_FILECONTEXT);

348
349
350
351
352
    d->m_sessionContextMenu = msessionContextMenu->menu();
    d->m_projectMenu = mproject->menu();
    d->m_subProjectMenu = msubProject->menu();
    d->m_folderMenu = mfolder->menu();
    d->m_fileMenu = mfilec->menu();
con's avatar
con committed
353

354
    Core::ActionContainer *mfile =
con's avatar
con committed
355
        am->actionContainer(Core::Constants::M_FILE);
356
    Core::ActionContainer *menubar =
con's avatar
con committed
357
358
359
        am->actionContainer(Core::Constants::MENU_BAR);

    // mode manager (for fancy actions)
360
    Core::ModeManager *modeManager = core->modeManager();
con's avatar
con committed
361
362

    // build menu
363
    Core::ActionContainer *mbuild =
con's avatar
con committed
364
        am->createMenu(Constants::M_BUILDPROJECT);
365
    mbuild->menu()->setTitle(tr("&Build"));
con's avatar
con committed
366
367
368
    menubar->addMenu(mbuild, Core::Constants::G_VIEW);

    // debug menu
369
    Core::ActionContainer *mdebug =
con's avatar
con committed
370
        am->createMenu(Constants::M_DEBUG);
371
    mdebug->menu()->setTitle(tr("&Debug"));
con's avatar
con committed
372
373
    menubar->addMenu(mdebug, Core::Constants::G_VIEW);

374
375
376
377
    Core::ActionContainer *mstartdebugging =
        am->createMenu(Constants::M_DEBUG_STARTDEBUGGING);
    mstartdebugging->menu()->setTitle(tr("&Start Debugging"));
    mdebug->addMenu(mstartdebugging, Core::Constants::G_DEFAULT_ONE);
con's avatar
con committed
378
379
380
381
382
383
384
385
386

    //
    // Groups
    //

    mbuild->appendGroup(Constants::G_BUILD_SESSION);
    mbuild->appendGroup(Constants::G_BUILD_PROJECT);
    mbuild->appendGroup(Constants::G_BUILD_OTHER);
    mbuild->appendGroup(Constants::G_BUILD_CANCEL);
dt's avatar
dt committed
387
    mbuild->appendGroup(Constants::G_BUILD_RUN);
con's avatar
con committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

    msessionContextMenu->appendGroup(Constants::G_SESSION_BUILD);
    msessionContextMenu->appendGroup(Constants::G_SESSION_FILES);
    msessionContextMenu->appendGroup(Constants::G_SESSION_OTHER);
    msessionContextMenu->appendGroup(Constants::G_SESSION_CONFIG);

    mproject->appendGroup(Constants::G_PROJECT_OPEN);
    mproject->appendGroup(Constants::G_PROJECT_NEW);
    mproject->appendGroup(Constants::G_PROJECT_BUILD);
    mproject->appendGroup(Constants::G_PROJECT_RUN);
    mproject->appendGroup(Constants::G_PROJECT_FILES);
    mproject->appendGroup(Constants::G_PROJECT_OTHER);
    mproject->appendGroup(Constants::G_PROJECT_CONFIG);

    msubProject->appendGroup(Constants::G_PROJECT_OPEN);
403
    msubProject->appendGroup(Constants::G_PROJECT_BUILD);
con's avatar
con committed
404
405
406
407
408
409
410
411
412
413
414
415
416
    msubProject->appendGroup(Constants::G_PROJECT_FILES);
    msubProject->appendGroup(Constants::G_PROJECT_OTHER);
    msubProject->appendGroup(Constants::G_PROJECT_CONFIG);

    mfolder->appendGroup(Constants::G_FOLDER_FILES);
    mfolder->appendGroup(Constants::G_FOLDER_OTHER);
    mfolder->appendGroup(Constants::G_FOLDER_CONFIG);

    mfilec->appendGroup(Constants::G_FILE_OPEN);
    mfilec->appendGroup(Constants::G_FILE_OTHER);
    mfilec->appendGroup(Constants::G_FILE_CONFIG);

    // "open with" submenu
417
    Core::ActionContainer * const openWith =
con's avatar
con committed
418
            am->createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
419
    openWith->setEmptyAction(Core::ActionContainer::EA_None);
420
421
    d->m_openWithMenu = openWith->menu();
    d->m_openWithMenu->setTitle(tr("Open With"));
con's avatar
con committed
422

423
    connect(d->m_openWithMenu, SIGNAL(triggered(QAction *)),
con's avatar
con committed
424
425
426
427
428
429
            this, SLOT(openWithMenuTriggered(QAction *)));

    //
    // Separators
    //

con's avatar
con committed
430
    Core::Command *cmd;
con's avatar
con committed
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
    QAction *sep;

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.Build.Sep"), globalcontext);
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.Files.Sep"), globalcontext);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
    msubProject->addAction(cmd, Constants::G_PROJECT_FILES);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.New.Sep"), globalcontext);
    mproject->addAction(cmd, Constants::G_PROJECT_NEW);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.Config.Sep"), globalcontext);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_CONFIG);
    mproject->addAction(cmd, Constants::G_PROJECT_CONFIG);
    msubProject->addAction(cmd, Constants::G_PROJECT_CONFIG);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.Projects.Sep"), globalcontext);
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.Other.Sep"), globalcontext);
    mbuild->addAction(cmd, Constants::G_BUILD_OTHER);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_OTHER);
    mproject->addAction(cmd, Constants::G_PROJECT_OTHER);
    msubProject->addAction(cmd, Constants::G_PROJECT_OTHER);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.Run.Sep"), globalcontext);
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
    mproject->addAction(cmd, Constants::G_PROJECT_RUN);

    sep = new QAction(this);
    sep->setSeparator(true);
    cmd = am->registerAction(sep, QLatin1String("ProjectExplorer.CancelBuild.Sep"), globalcontext);
    mbuild->addAction(cmd, Constants::G_BUILD_CANCEL);

    //
    // Actions
    //

    // new session action
486
487
    d->m_sessionManagerAction = new QAction(tr("Session Manager..."), this);
    cmd = am->registerAction(d->m_sessionManagerAction, Constants::NEWSESSION, globalcontext);
con's avatar
con committed
488
489
490
    cmd->setDefaultKeySequence(QKeySequence());

    // new action
491
492
    d->m_newAction = new QAction(tr("New Project..."), this);
    cmd = am->registerAction(d->m_newAction, Constants::NEWPROJECT, globalcontext);
con's avatar
con committed
493
494
495
496
497
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+N")));
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

#if 0
    // open action
498
499
    d->m_loadAction = new QAction(tr("Load Project..."), this);
    cmd = am->registerAction(d->m_loadAction, Constants::LOAD, globalcontext);
con's avatar
con committed
500
501
502
503
504
505
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+O")));
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);
#endif

    // Default open action
506
507
    d->m_openFileAction = new QAction(tr("Open File"), this);
    cmd = am->registerAction(d->m_openFileAction, ProjectExplorer::Constants::OPENFILE,
con's avatar
con committed
508
509
510
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OPEN);

511
    d->m_showInGraphicalShell = new QAction(FolderNavigationWidget::msgGraphicalShellAction(), this);
512
    cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
con's avatar
con committed
513
514
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OPEN);
515
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
516

517
    d->m_openTerminalHere = new QAction(FolderNavigationWidget::msgTerminalAction(), this);
518
519
520
521
522
    cmd = am->registerAction(d->m_openTerminalHere, ProjectExplorer::Constants::OPENTERMIANLHERE,
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OPEN);
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);

con's avatar
con committed
523
524
525
    // Open With menu
    mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN);

mae's avatar
mae committed
526
    // recent projects menu
527
    Core::ActionContainer *mrecent =
mae's avatar
mae committed
528
        am->createMenu(Constants::M_RECENTPROJECTS);
529
    mrecent->menu()->setTitle(tr("Recent P&rojects"));
mae's avatar
mae committed
530
531
532
533
    mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
    connect(mfile->menu(), SIGNAL(aboutToShow()),
        this, SLOT(updateRecentProjectMenu()));

con's avatar
con committed
534
    // unload action
535
536
    d->m_unloadAction = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
                                                      Utils::ParameterAction::EnabledWithParameter, this);
537
    cmd = am->registerAction(d->m_unloadAction, Constants::UNLOAD, globalcontext);
con's avatar
con committed
538
    cmd->setAttribute(Core::Command::CA_UpdateText);
539
    cmd->setDefaultText(d->m_unloadAction->text());
con's avatar
con committed
540
541
542
543
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);

    // unload session action
544
545
    d->m_clearSession = new QAction(tr("Close All Projects"), this);
    cmd = am->registerAction(d->m_clearSession, Constants::CLEARSESSION, globalcontext);
con's avatar
con committed
546
547
548
549
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // session menu
550
    Core::ActionContainer *msession = am->createMenu(Constants::M_SESSION);
551
    msession->menu()->setTitle(tr("Session"));
con's avatar
con committed
552
    mfile->addMenu(msession, Core::Constants::G_FILE_PROJECT);
553
    d->m_sessionMenu = msession->menu();
con's avatar
con committed
554
555
556
557
558
559
    connect(mfile->menu(), SIGNAL(aboutToShow()),
            this, SLOT(updateSessionMenu()));

    // build session action
    QIcon buildIcon(Constants::ICON_BUILD);
    buildIcon.addFile(Constants::ICON_BUILD_SMALL);
560
561
    d->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
    cmd = am->registerAction(d->m_buildSessionAction, Constants::BUILDSESSION, globalcontext);
con's avatar
con committed
562
563
564
565
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+B")));
    mbuild->addAction(cmd, Constants::G_BUILD_SESSION);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);
    // Add to mode bar
566
    modeManager->addAction(cmd, Constants::P_ACTION_BUILDSESSION);
con's avatar
con committed
567
568
569
570

    // rebuild session action
    QIcon rebuildIcon(Constants::ICON_REBUILD);
    rebuildIcon.addFile(Constants::ICON_REBUILD_SMALL);
571
572
    d->m_rebuildSessionAction = new QAction(rebuildIcon, tr("Rebuild All"), this);
    cmd = am->registerAction(d->m_rebuildSessionAction, Constants::REBUILDSESSION, globalcontext);
con's avatar
con committed
573
574
575
    mbuild->addAction(cmd, Constants::G_BUILD_SESSION);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

Tobias Hunger's avatar
Tobias Hunger committed
576
577
578
579
580
581
    // deploy session
    d->m_deploySessionAction = new QAction(tr("Deploy All"), this);
    cmd = am->registerAction(d->m_deploySessionAction, Constants::DEPLOYSESSION, globalcontext);
    mbuild->addAction(cmd, Constants::G_BUILD_SESSION);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

con's avatar
con committed
582
583
584
    // clean session
    QIcon cleanIcon(Constants::ICON_CLEAN);
    cleanIcon.addFile(Constants::ICON_CLEAN_SMALL);
585
586
    d->m_cleanSessionAction = new QAction(cleanIcon, tr("Clean All"), this);
    cmd = am->registerAction(d->m_cleanSessionAction, Constants::CLEANSESSION, globalcontext);
con's avatar
con committed
587
588
589
590
    mbuild->addAction(cmd, Constants::G_BUILD_SESSION);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // build action
591
    d->m_buildAction = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
592
                                                     Utils::ParameterAction::AlwaysEnabled, this);
593
    cmd = am->registerAction(d->m_buildAction, Constants::BUILD, globalcontext);
594
    cmd->setAttribute(Core::Command::CA_UpdateText);
595
    cmd->setDefaultText(d->m_buildAction->text());
con's avatar
con committed
596
597
598
599
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);

    // rebuild action
600
    d->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
601
                                                       Utils::ParameterAction::AlwaysEnabled, this);
602
    cmd = am->registerAction(d->m_rebuildAction, Constants::REBUILD, globalcontext);
603
    cmd->setAttribute(Core::Command::CA_UpdateText);
604
    cmd->setDefaultText(d->m_rebuildAction->text());
con's avatar
con committed
605
606
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);

Tobias Hunger's avatar
Tobias Hunger committed
607
608
609
610
611
612
613
614
    // deploy action
    d->m_deployAction = new Utils::ParameterAction(tr("Deploy Project"), tr("Deploy Project \"%1\""),
                                                     Utils::ParameterAction::AlwaysEnabled, this);
    cmd = am->registerAction(d->m_deployAction, Constants::DEPLOY, globalcontext);
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setDefaultText(d->m_deployAction->text());
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);

con's avatar
con committed
615
    // clean action
616
    d->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
617
                                                     Utils::ParameterAction::AlwaysEnabled, this);
618
    cmd = am->registerAction(d->m_cleanAction, Constants::CLEAN, globalcontext);
619
    cmd->setAttribute(Core::Command::CA_UpdateText);
620
    cmd->setDefaultText(d->m_cleanAction->text());
con's avatar
con committed
621
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638

    // build action (context menu)
    d->m_buildActionContextMenu = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
                                                             Utils::ParameterAction::AlwaysEnabled, this);
    cmd = am->registerAction(d->m_buildActionContextMenu, Constants::BUILDCM, globalcontext);
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setDefaultText(d->m_buildActionContextMenu->text());
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

    // rebuild action (context menu)
    d->m_rebuildActionContextMenu = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
                                                               Utils::ParameterAction::AlwaysEnabled, this);
    cmd = am->registerAction(d->m_rebuildActionContextMenu, Constants::REBUILDCM, globalcontext);
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setDefaultText(d->m_rebuildActionContextMenu->text());
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

Tobias Hunger's avatar
Tobias Hunger committed
639
640
641
642
643
644
645
646
    // deploy action (context menu)
    d->m_deployActionContextMenu = new Utils::ParameterAction(tr("Deploy Project"), tr("Deploy Project \"%1\""),
                                                              Utils::ParameterAction::AlwaysEnabled, this);
    cmd = am->registerAction(d->m_rebuildActionContextMenu, Constants::DEPLOYCM, globalcontext);
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setDefaultText(d->m_deployActionContextMenu->text());
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

647
648
649
650
651
652
    // clean action (context menu)
    d->m_cleanActionContextMenu = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
                                                             Utils::ParameterAction::AlwaysEnabled, this);
    cmd = am->registerAction(d->m_cleanActionContextMenu, Constants::CLEANCM, globalcontext);
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setDefaultText(d->m_cleanActionContextMenu->text());
con's avatar
con committed
653
654
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

655
    // build without dependencies action
656
657
    d->m_buildProjectOnlyAction = new QAction(tr("Build Without Dependencies"), this);
    cmd = am->registerAction(d->m_buildProjectOnlyAction, Constants::BUILDPROJECTONLY, globalcontext);
658

659
    // rebuild without dependencies action
660
661
    d->m_rebuildProjectOnlyAction = new QAction(tr("Rebuild Without Dependencies"), this);
    cmd = am->registerAction(d->m_rebuildProjectOnlyAction, Constants::REBUILDPROJECTONLY, globalcontext);
662

Tobias Hunger's avatar
Tobias Hunger committed
663
664
665
666
    // deploy without dependencies action
    d->m_deployProjectOnlyAction = new QAction(tr("Deploy Without Dependencies"), this);
    cmd = am->registerAction(d->m_deployProjectOnlyAction, Constants::DEPLOYPROJECTONLY, globalcontext);

667
    // clean without dependencies action
668
669
    d->m_cleanProjectOnlyAction = new QAction(tr("Clean Without Dependencies"), this);
    cmd = am->registerAction(d->m_cleanProjectOnlyAction, Constants::CLEANPROJECTONLY, globalcontext);
670

con's avatar
con committed
671
672
673
    // run action
    QIcon runIcon(Constants::ICON_RUN);
    runIcon.addFile(Constants::ICON_RUN_SMALL);
674
675
    d->m_runAction = new QAction(runIcon, tr("Run"), this);
    cmd = am->registerAction(d->m_runAction, Constants::RUN, globalcontext);
676
677
    cmd->setAttribute(Core::Command::CA_UpdateText);

con's avatar
con committed
678
679
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R")));
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
680

681
    modeManager->addAction(cmd, Constants::P_ACTION_RUN);
con's avatar
con committed
682

683
684
    d->m_runActionContextMenu = new QAction(runIcon, tr("Run"), this);
    cmd = am->registerAction(d->m_runActionContextMenu, Constants::RUNCONTEXTMENU, globalcontext);
685
686
    mproject->addAction(cmd, Constants::G_PROJECT_RUN);

con's avatar
con committed
687
    // cancel build action
688
689
    d->m_cancelBuildAction = new QAction(tr("Cancel Build"), this);
    cmd = am->registerAction(d->m_cancelBuildAction, Constants::CANCELBUILD, globalcontext);
con's avatar
con committed
690
691
692
693
    mbuild->addAction(cmd, Constants::G_BUILD_CANCEL);

    // debug action
    QIcon debuggerIcon(":/projectexplorer/images/debugger_start_small.png");
694
    debuggerIcon.addFile(":/projectexplorer/images/debugger_start.png");
695
696
    d->m_debugAction = new QAction(debuggerIcon, tr("Start Debugging"), this);
    cmd = am->registerAction(d->m_debugAction, Constants::DEBUG, globalcontext);
con's avatar
con committed
697
698
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setAttribute(Core::Command::CA_UpdateIcon);
con's avatar
con committed
699
700
    cmd->setDefaultText(tr("Start Debugging"));
    cmd->setDefaultKeySequence(QKeySequence(tr("F5")));
701
    mstartdebugging->addAction(cmd, Core::Constants::G_DEFAULT_ONE);
702
    modeManager->addAction(cmd, Constants::P_ACTION_DEBUG);
con's avatar
con committed
703
704

    // add new file action
705
706
    d->m_addNewFileAction = new QAction(tr("Add New..."), this);
    cmd = am->registerAction(d->m_addNewFileAction, ProjectExplorer::Constants::ADDNEWFILE,
con's avatar
con committed
707
708
709
                       globalcontext);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
    msubProject->addAction(cmd, Constants::G_PROJECT_FILES);
710
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
711
712

    // add existing file action
713
714
    d->m_addExistingFilesAction = new QAction(tr("Add Existing Files..."), this);
    cmd = am->registerAction(d->m_addExistingFilesAction, ProjectExplorer::Constants::ADDEXISTINGFILES,
con's avatar
con committed
715
716
717
                       globalcontext);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
    msubProject->addAction(cmd, Constants::G_PROJECT_FILES);
718
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
719
720

    // remove file action
721
722
    d->m_removeFileAction = new QAction(tr("Remove File..."), this);
    cmd = am->registerAction(d->m_removeFileAction, ProjectExplorer::Constants::REMOVEFILE,
con's avatar
con committed
723
724
725
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OTHER);

dt's avatar
dt committed
726
    // renamefile action
727
728
    d->m_renameFileAction = new QAction(tr("Rename"), this);
    cmd = am->registerAction(d->m_renameFileAction, ProjectExplorer::Constants::RENAMEFILE,
con's avatar
con committed
729
730
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OTHER);
dt's avatar
dt committed
731
732
733
734
    // Not yet used by anyone, so hide for now
//    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
//    msubProject->addAction(cmd, Constants::G_FOLDER_FILES);
//    mproject->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
735

736
737
    // target selector
    d->m_projectSelectorAction = new QAction(this);
738
    d->m_projectSelectorAction->setCheckable(true);
739
740
741
    d->m_projectSelectorAction->setEnabled(false);
    QWidget *mainWindow = Core::ICore::instance()->mainWindow();
    d->m_targetSelector = new Internal::MiniProjectTargetSelector(d->m_projectSelectorAction, mainWindow);
742
    connect(d->m_projectSelectorAction, SIGNAL(triggered()), d->m_targetSelector, SLOT(show()));
743
    modeManager->addProjectSelector(d->m_projectSelectorAction);
744
745
746
747
748
749

    d->m_projectSelectorActionMenu = new QAction(this);
    d->m_projectSelectorActionMenu->setEnabled(false);
    d->m_projectSelectorActionMenu->setText(tr("Open Build/Run Target Selector..."));
    connect(d->m_projectSelectorActionMenu, SIGNAL(triggered()), d->m_targetSelector, SLOT(show()));
    cmd = am->registerAction(d->m_projectSelectorActionMenu, ProjectExplorer::Constants::SELECTTARGET,
Tobias Hunger's avatar
Tobias Hunger committed
750
751
                       globalcontext);
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+T")));
752
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
753
754
755
756
757
758
759
760
761
762

    connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
            d->m_targetSelector, SLOT(addProject(ProjectExplorer::Project*)));
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
            d->m_targetSelector, SLOT(removeProject(ProjectExplorer::Project*)));
    connect(d->m_targetSelector, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
            this, SLOT(setStartupProject(ProjectExplorer::Project*)));
    connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
            d->m_targetSelector, SLOT(changeStartupProject(ProjectExplorer::Project*)));

763
    connect(core, SIGNAL(saveSettingsRequested()),
con's avatar
con committed
764
765
        this, SLOT(savePersistentSettings()));

hjk's avatar
hjk committed
766
767
    addAutoReleasedObject(new ProjectTreeWidgetFactory);
    addAutoReleasedObject(new FolderNavigationWidgetFactory);
con's avatar
con committed
768

769
770
771
772
773
    if (QSettings *s = core->settings()) {
        const QStringList fileNames = s->value("ProjectExplorer/RecentProjects/FileNames").toStringList();
        const QStringList displayNames = s->value("ProjectExplorer/RecentProjects/DisplayNames").toStringList();
        if (fileNames.size() == displayNames.size()) {
            for (int i = 0; i < fileNames.size(); ++i) {
774
                if (QFileInfo(fileNames.at(i)).isFile())
775
                    d->m_recentProjects.append(qMakePair(fileNames.at(i), displayNames.at(i)));
776
777
778
779
            }
        }
    }

780
    if (QSettings *s = core->settings()) {
Tobias Hunger's avatar
Tobias Hunger committed
781
782
        d->m_projectExplorerSettings.buildBeforeDeploy = s->value("ProjectExplorer/Settings/BuildBeforeDeploy", true).toBool();
        d->m_projectExplorerSettings.deployBeforeRun = s->value("ProjectExplorer/Settings/DeployBeforeRun", true).toBool();
783
784
        d->m_projectExplorerSettings.saveBeforeBuild = s->value("ProjectExplorer/Settings/SaveBeforeBuild", false).toBool();
        d->m_projectExplorerSettings.showCompilerOutput = s->value("ProjectExplorer/Settings/ShowCompilerOutput", false).toBool();
785
        d->m_projectExplorerSettings.cleanOldAppOutput = s->value("ProjectExplorer/Settings/CleanOldAppOutput", false).toBool();
786
        d->m_projectExplorerSettings.useJom = s->value("ProjectExplorer/Settings/UseJom", true).toBool();
787
788
789
        d->m_projectExplorerSettings.environmentId = QUuid(s->value("ProjectExplorer/Settings/EnvironmentId").toString());
        if (d->m_projectExplorerSettings.environmentId.isNull())
            d->m_projectExplorerSettings.environmentId = QUuid::createUuid();
790
    }
791

792
793
    connect(d->m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(showSessionManager()));
    connect(d->m_newAction, SIGNAL(triggered()), this, SLOT(newProject()));
con's avatar
con committed
794
#if 0
795
    connect(d->m_loadAction, SIGNAL(triggered()), this, SLOT(loadAction()));
con's avatar
con committed
796
#endif
797
798
    connect(d->m_buildProjectOnlyAction, SIGNAL(triggered()), this, SLOT(buildProjectOnly()));
    connect(d->m_buildAction, SIGNAL(triggered()), this, SLOT(buildProject()));
799
    connect(d->m_buildActionContextMenu, SIGNAL(triggered()), this, SLOT(buildProjectContextMenu()));
800
801
802
    connect(d->m_buildSessionAction, SIGNAL(triggered()), this, SLOT(buildSession()));
    connect(d->m_rebuildProjectOnlyAction, SIGNAL(triggered()), this, SLOT(rebuildProjectOnly()));
    connect(d->m_rebuildAction, SIGNAL(triggered()), this, SLOT(rebuildProject()));
803
    connect(d->m_rebuildActionContextMenu, SIGNAL(triggered()), this, SLOT(rebuildProjectContextMenu()));
804
    connect(d->m_rebuildSessionAction, SIGNAL(triggered()), this, SLOT(rebuildSession()));
Tobias Hunger's avatar
Tobias Hunger committed
805
806
807
808
    connect(d->m_deployProjectOnlyAction, SIGNAL(triggered()), this, SLOT(deployProjectOnly()));
    connect(d->m_deployAction, SIGNAL(triggered()), this, SLOT(deployProject()));
    connect(d->m_deployActionContextMenu, SIGNAL(triggered()), this, SLOT(deployProjectContextMenu()));
    connect(d->m_deploySessionAction, SIGNAL(triggered()), this, SLOT(deploySession()));
809
810
    connect(d->m_cleanProjectOnlyAction, SIGNAL(triggered()), this, SLOT(cleanProjectOnly()));
    connect(d->m_cleanAction, SIGNAL(triggered()), this, SLOT(cleanProject()));
811
    connect(d->m_cleanActionContextMenu, SIGNAL(triggered()), this, SLOT(cleanProjectContextMenu()));
812
813
814
815
816
817
818
819
820
821
822
    connect(d->m_cleanSessionAction, SIGNAL(triggered()), this, SLOT(cleanSession()));
    connect(d->m_runAction, SIGNAL(triggered()), this, SLOT(runProject()));
    connect(d->m_runActionContextMenu, SIGNAL(triggered()), this, SLOT(runProjectContextMenu()));
    connect(d->m_cancelBuildAction, SIGNAL(triggered()), this, SLOT(cancelBuild()));
    connect(d->m_debugAction, SIGNAL(triggered()), this, SLOT(debugProject()));
    connect(d->m_unloadAction, SIGNAL(triggered()), this, SLOT(unloadProject()));
    connect(d->m_clearSession, SIGNAL(triggered()), this, SLOT(clearSession()));
    connect(d->m_addNewFileAction, SIGNAL(triggered()), this, SLOT(addNewFile()));
    connect(d->m_addExistingFilesAction, SIGNAL(triggered()), this, SLOT(addExistingFiles()));
    connect(d->m_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
    connect(d->m_showInGraphicalShell, SIGNAL(triggered()), this, SLOT(showInGraphicalShell()));
823
    connect(d->m_openTerminalHere, SIGNAL(triggered()), this, SLOT(openTerminalHere()));
824
825
    connect(d->m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile()));
    connect(d->m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile()));
con's avatar
con committed
826
827
828

    updateActions();

829
830
    connect(Core::ICore::instance(), SIGNAL(coreAboutToOpen()),
            this, SLOT(determineSessionToRestoreAtStartup()));
831
    connect(Core::ICore::instance(), SIGNAL(coreOpened()), this, SLOT(restoreSession()));
con's avatar
con committed
832

833
834
    updateWelcomePage();

con's avatar
con committed
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
    return true;
}

// Find a factory by file mime type in a sequence of factories
template <class Factory, class Iterator>
    Factory *findFactory(const QString &mimeType, Iterator i1, Iterator i2)
{
    for ( ; i1 != i2; ++i2) {
        Factory *f = *i1;
        if (f->mimeTypes().contains(mimeType))
            return f;
    }
    return 0;
}

ProjectFileFactory * ProjectExplorerPlugin::findProjectFileFactory(const QString &filename) const
{
    // Find factory
853
    if (const Core::MimeType mt = Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(filename)))
854
        if (ProjectFileFactory *pf = findFactory<ProjectFileFactory>(mt.type(), d->m_fileFactories.constBegin(), d->m_fileFactories.constEnd()))
con's avatar
con committed
855
856
857
858
859
860
861
862
863
864
865
            return pf;
    qWarning("Unable to find project file factory for '%s'", filename.toUtf8().constData());
    return 0;
}

void ProjectExplorerPlugin::loadAction()
{
    if (debug)
        qDebug() << "ProjectExplorerPlugin::loadAction";


866
    QString dir = d->m_lastOpenDirectory;
con's avatar
con committed
867
868
869
870
871
872

    // for your special convenience, we preselect a pro file if it is
    // the current file
    if (Core::IEditor *editor = Core::EditorManager::instance()->currentEditor()) {
        if (const Core::IFile *file = editor->file()) {
            const QString fn = file->fileName();
873
            const bool isProject = d->m_profileMimeTypes.contains(file->mimeType());
con's avatar
con committed
874
875
876
877
878
879
            dir = isProject ? fn : QFileInfo(fn).absolutePath();
        }
    }

    QString filename = QFileDialog::getOpenFileName(0, tr("Load Project"),
                                                    dir,
880
                                                    d->m_projectFilterString);
con's avatar
con committed
881
882
883
884
885
886
887
    if (filename.isEmpty())
        return;
    if (ProjectFileFactory *pf = findProjectFileFactory(filename))
        pf->open(filename);
    updateActions();
}

888
void ProjectExplorerPlugin::unloadProject()
con's avatar
con committed
889
890
{
    if (debug)
891
        qDebug() << "ProjectExplorerPlugin::unloadProject";
con's avatar
con committed
892

893
    Core::IFile *fi = d->m_currentProject->file();
con's avatar
con committed
894
895

    if (!fi || fi->fileName().isEmpty()) //nothing to save?
896
        return;
con's avatar
con committed
897
898
899
900
901
902
903
904
905
906
907
908
909

    QList<Core::IFile*> filesToSave;
    filesToSave << fi;

    // check the number of modified files
    int readonlycount = 0;
    foreach (const Core::IFile *file, filesToSave) {
        if (file->isReadOnly())
            ++readonlycount;
    }

    bool success = false;
    if (readonlycount > 0)
910
        success = Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave).isEmpty();
con's avatar
con committed
911
    else
912
        success = Core::ICore::instance()->fileManager()->saveModifiedFilesSilently(filesToSave).isEmpty();
con's avatar
con committed
913

914
    if (!success)
con's avatar
con committed
915
916
        return;

917
    addToRecentProjects(fi->fileName(), d->m_currentProject->displayName());
918
    d->m_session->removeProject(d->m_currentProject);
con's avatar
con committed
919
920
921
922
923
924
925
926
    updateActions();
}

void ProjectExplorerPlugin::clearSession()
{
    if (debug)
        qDebug() << "ProjectExplorerPlugin::clearSession";

927
    if (!d->m_session->clear())
con's avatar
con committed
928
929
930
931
932
933
        return; // Action has been cancelled
    updateActions();
}

void ProjectExplorerPlugin::extensionsInitialized()
{
934
935
936
    d->m_fileFactories = ProjectFileFactory::createFactories(&d->m_projectFilterString);
    foreach (ProjectFileFactory *pf, d->m_fileFactories) {
        d->m_profileMimeTypes += pf->mimeTypes();
con's avatar
con committed
937
938
        addAutoReleasedObject(pf);
    }
939
940
941
942
    // Add custom wizards, for which other plugins might have registered
    // class factories
    foreach(Core::IWizard *cpw, ProjectExplorer::CustomWizard::createWizards())
        addAutoReleasedObject(cpw);
dt's avatar
dt committed
943
944

    d->m_buildManager->extensionsInitialized();
con's avatar
con committed
945
946
}

947
void ProjectExplorerPlugin::aboutToShutdown()
con's avatar
con committed
948
{
949
    d->m_proWindow->aboutToShutdown(); // disconnect from session
950
    d->m_session->clear();
951
    d->m_projectsMode = 0;
952
//    d->m_proWindow->saveConfigChanges();
con's avatar
con committed
953
954
955
956
957
958
959
960
961
}

void ProjectExplorerPlugin::newProject()
{
    if (debug)
        qDebug() << "ProjectExplorerPlugin::newProject";

    QString defaultLocation;
    if (currentProject()) {
962
        QDir dir(currentProject()->projectDirectory());
con's avatar
con committed
963
964
965
966
        dir.cdUp();
        defaultLocation = dir.absolutePath();
    }

967
    Core::ICore::instance()->showNewItemDialog(tr("New Project", "Title of dialog"),
968
                              Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard),
con's avatar
con committed
969
970
971
972
                              defaultLocation);
    updateActions();
}

973
void ProjectExplorerPlugin::showSessionManager()
con's avatar
con committed
974
975
{
    if (debug)
976
        qDebug() << "ProjectExplorerPlugin::showSessionManager";
con's avatar
con committed
977