projectexplorer.cpp 83.2 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 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"
31
#include "project.h"
32
#include "projectexplorersettings.h"
con's avatar
con committed
33
34
35
36
37
#include "applicationrunconfiguration.h"
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
38
#include "currentprojectfind.h"
con's avatar
con committed
39
40
#include "currentprojectfilter.h"
#include "customexecutablerunconfiguration.h"
41
42
#include "editorsettingspropertiespage.h"
#include "dependenciespanel.h"
con's avatar
con committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#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"
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "removefiledialog.h"
#include "runsettingspropertiespage.h"
#include "scriptwrappers.h"
#include "session.h"
#include "sessiondialog.h"
60
#include "projectexplorersettingspage.h"
61
62
#include "projectwelcomepage.h"
#include "projectwelcomepagewidget.h"
63
#include "corelistenercheckingforrunningbuild.h"
64
#include "buildconfiguration.h"
65
#include "miniprojecttargetselector.h"
con's avatar
con committed
66
67
68

#include <coreplugin/basemode.h>
#include <coreplugin/coreconstants.h>
69
70
#include <coreplugin/filemanager.h>
#include <coreplugin/icore.h>
con's avatar
con committed
71
72
73
74
#include <coreplugin/mainwindow.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/uniqueidmanager.h>
75
#include <coreplugin/actionmanager/actionmanager.h>
con's avatar
con committed
76
77
78
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/editormanager/ieditorfactory.h>
79
#include <coreplugin/editormanager/iexternaleditor.h>
con's avatar
con committed
80
81
82
83
#include <coreplugin/findplaceholder.h>
#include <coreplugin/basefilewizard.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
84
#include <welcome/welcomemode.h>
85
#include <extensionsystem/pluginmanager.h>
86
#include <utils/consoleprocess.h>
hjk's avatar
hjk committed
87
#include <utils/qtcassert.h>
88
#include <utils/parameteraction.h>
con's avatar
con committed
89

90
#include <QtCore/QtPlugin>
hjk's avatar
hjk committed
91
#include <QtCore/QDateTime>
con's avatar
con committed
92
93
#include <QtCore/QDebug>
#include <QtCore/QSettings>
hjk's avatar
hjk committed
94

con's avatar
con committed
95
96
#include <QtGui/QAction>
#include <QtGui/QApplication>
hjk's avatar
hjk committed
97
98
99
#include <QtGui/QFileDialog>
#include <QtGui/QMenu>
#include <QtGui/QMessageBox>
100
#include <QtGui/QVBoxLayout>
con's avatar
con committed
101

102
103
Q_DECLARE_METATYPE(Core::IEditorFactory*);
Q_DECLARE_METATYPE(Core::IExternalEditor*);
con's avatar
con committed
104
105
106
107
108

namespace {
bool debug = false;
}

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
128
    Utils::ParameterAction *m_unloadAction;
129
130
    QAction *m_clearSession;
    QAction *m_buildProjectOnlyAction;
131
    Utils::ParameterAction *m_buildAction;
132
133
    QAction *m_buildSessionAction;
    QAction *m_rebuildProjectOnlyAction;
134
    Utils::ParameterAction *m_rebuildAction;
135
136
    QAction *m_rebuildSessionAction;
    QAction *m_cleanProjectOnlyAction;
137
    Utils::ParameterAction *m_cleanAction;
138
139
140
141
142
143
144
145
146
    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;
147
    QAction *m_openTerminalHere;
148
149
    QAction *m_removeFileAction;
    QAction *m_renameFileAction;
150
    QAction *m_projectSelectorAction;
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

    QMenu *m_buildConfigurationMenu;
    QActionGroup *m_buildConfigurationActionGroup;
    QMenu *m_runConfigurationMenu;
    QActionGroup *m_runConfigurationActionGroup;

    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;
174
    RunConfiguration *m_delayedRunConfiguration; // TODO this is not right
175
176
177
    RunControl *m_debuggingRunControl;
    QString m_runMode;
    QString m_projectFilterString;
178
    Internal::MiniProjectTargetSelector * m_targetSelector;
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
    Internal::ProjectExplorerSettings m_projectExplorerSettings;
    Internal::ProjectWelcomePage *m_welcomePlugin;
    Internal::ProjectWelcomePageWidget *m_welcomePage;
};

ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
    m_buildConfigurationActionGroup(0),
    m_runConfigurationActionGroup(0),
    m_currentProject(0),
    m_currentNode(0),
    m_delayedRunConfiguration(0),
    m_debuggingRunControl(0)
{
}

}  // namespace ProjectExplorer

con's avatar
con committed
196
197
198
199
200
201
202
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;


ProjectExplorerPlugin *ProjectExplorerPlugin::m_instance = 0;

ProjectExplorerPlugin::ProjectExplorerPlugin()
203
    : d(new ProjectExplorerPluginPrivate)
con's avatar
con committed
204
205
206
207
208
209
{
    m_instance = this;
}

ProjectExplorerPlugin::~ProjectExplorerPlugin()
{
210
    removeObject(d->m_welcomePlugin);
211
    delete d->m_welcomePlugin;
con's avatar
con committed
212
    removeObject(this);
213
    delete d;
con's avatar
con committed
214
215
216
217
218
219
220
}

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

221
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
con's avatar
con committed
222
{
223
224
    Q_UNUSED(arguments)
    Q_UNUSED(error)
225

226
227
    Core::ICore *core = Core::ICore::instance();
    Core::ActionManager *am = core->actionManager();
con's avatar
con committed
228

229
230
231
232
233
    d->m_welcomePlugin = new ProjectWelcomePage;
    d->m_welcomePage = qobject_cast<Internal::ProjectWelcomePageWidget*>(d->m_welcomePlugin->page());
    Q_ASSERT(d->m_welcomePage);
    connect(d->m_welcomePage, SIGNAL(manageSessions()), this, SLOT(showSessionManager()));
    addObject(d->m_welcomePlugin);
con's avatar
con committed
234
235
    addObject(this);

hjk's avatar
hjk committed
236
237
    connect(core->fileManager(), SIGNAL(currentFileChanged(QString)),
            this, SLOT(setCurrentFile(QString)));
con's avatar
con committed
238

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

241
    connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project *)),
con's avatar
con committed
242
            this, SIGNAL(fileListChanged()));
243
    connect(d->m_session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project *)),
con's avatar
con committed
244
            this, SLOT(invalidateProject(ProjectExplorer::Project *)));
245
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project *)),
con's avatar
con committed
246
            this, SIGNAL(fileListChanged()));
247
    connect(d->m_session, SIGNAL(startupProjectChanged(ProjectExplorer::Project *)),
con's avatar
con committed
248
            this, SLOT(startupProjectChanged()));
249
250
251
252
    connect(d->m_session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
            this, SLOT(updatePreferredWizardKinds()));
    connect(d->m_session, SIGNAL(projectRemoved(ProjectExplorer::Project*)),
            this, SLOT(updatePreferredWizardKinds()));
con's avatar
con committed
253

254
    d->m_proWindow = new ProjectWindow;
con's avatar
con committed
255
256
257
258
259

    QList<int> globalcontext;
    globalcontext.append(Core::Constants::C_GLOBAL_ID);

    QList<int> pecontext;
260
    pecontext << core->uniqueIDManager()->uniqueIdentifier(Constants::C_PROJECTEXPLORER);
con's avatar
con committed
261

hjk's avatar
hjk committed
262
    Core::BaseMode *mode = new Core::BaseMode;
263
264
    mode->setDisplayName(tr("Projects"));
    mode->setId(QLatin1String(Constants::MODE_SESSION));
hjk's avatar
hjk committed
265
266
    mode->setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Project.png")));
    mode->setPriority(Constants::P_MODE_SESSION);
267
    mode->setWidget(d->m_proWindow);
con's avatar
con committed
268
269
    mode->setContext(QList<int>() << pecontext);
    addAutoReleasedObject(mode);
270
    d->m_proWindow->layout()->addWidget(new Core::FindToolBarPlaceHolder(d->m_proWindow));
con's avatar
con committed
271

272
273
    d->m_buildManager = new BuildManager(this);
    connect(d->m_buildManager, SIGNAL(buildStateChanged(ProjectExplorer::Project *)),
con's avatar
con committed
274
            this, SLOT(buildStateChanged(ProjectExplorer::Project *)));
275
    connect(d->m_buildManager, SIGNAL(buildQueueFinished(bool)),
con's avatar
con committed
276
277
            this, SLOT(buildQueueFinished(bool)));

278
    addAutoReleasedObject(new CoreListenerCheckingForRunningBuild(d->m_buildManager));
con's avatar
con committed
279

280
281
282
283
    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
284

285
    AllProjectsFilter *allProjectsFilter = new AllProjectsFilter(this);
con's avatar
con committed
286
287
    addAutoReleasedObject(allProjectsFilter);

288
    CurrentProjectFilter *currentProjectFilter = new CurrentProjectFilter(this);
con's avatar
con committed
289
290
291
292
293
    addAutoReleasedObject(currentProjectFilter);

    addAutoReleasedObject(new BuildSettingsPanelFactory);
    addAutoReleasedObject(new RunSettingsPanelFactory);
    addAutoReleasedObject(new EditorSettingsPanelFactory);
294
    addAutoReleasedObject(new DependenciesPanelFactory(d->m_session));
con's avatar
con committed
295
296
297
298

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

299
300
301
    ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
    AllProjectsFind *allProjectsFind = new AllProjectsFind(this,
        pm->getObject<Find::SearchResultWindow>());
con's avatar
con committed
302
303
    addAutoReleasedObject(allProjectsFind);

304
305
    CurrentProjectFind *currentProjectFind = new CurrentProjectFind(this,
        pm->getObject<Find::SearchResultWindow>());
con's avatar
con committed
306
307
    addAutoReleasedObject(currentProjectFind);

308
    addAutoReleasedObject(new LocalApplicationRunControlFactory);
con's avatar
con committed
309
310
    addAutoReleasedObject(new CustomExecutableRunConfigurationFactory);

311
    addAutoReleasedObject(new ProjectFileWizardExtension);
con's avatar
con committed
312

313
314
315
    // Settings page
    addAutoReleasedObject(new ProjectExplorerSettingsPage);

con's avatar
con committed
316
    // context menus
317
    Core::ActionContainer *msessionContextMenu =
con's avatar
con committed
318
        am->createMenu(Constants::M_SESSIONCONTEXT);
319
    Core::ActionContainer *mproject =
con's avatar
con committed
320
        am->createMenu(Constants::M_PROJECTCONTEXT);
321
    Core::ActionContainer *msubProject =
con's avatar
con committed
322
        am->createMenu(Constants::M_SUBPROJECTCONTEXT);
323
    Core::ActionContainer *mfolder =
con's avatar
con committed
324
        am->createMenu(Constants::M_FOLDERCONTEXT);
325
    Core::ActionContainer *mfilec =
con's avatar
con committed
326
327
        am->createMenu(Constants::M_FILECONTEXT);

328
329
330
331
332
    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
333

334
    Core::ActionContainer *mfile =
con's avatar
con committed
335
        am->actionContainer(Core::Constants::M_FILE);
336
    Core::ActionContainer *menubar =
con's avatar
con committed
337
338
339
        am->actionContainer(Core::Constants::MENU_BAR);

    // mode manager (for fancy actions)
340
    Core::ModeManager *modeManager = core->modeManager();
con's avatar
con committed
341
342

    // build menu
343
    Core::ActionContainer *mbuild =
con's avatar
con committed
344
        am->createMenu(Constants::M_BUILDPROJECT);
345
    mbuild->menu()->setTitle(tr("&Build"));
con's avatar
con committed
346
347
348
    menubar->addMenu(mbuild, Core::Constants::G_VIEW);

    // debug menu
349
    Core::ActionContainer *mdebug =
con's avatar
con committed
350
        am->createMenu(Constants::M_DEBUG);
351
    mdebug->menu()->setTitle(tr("&Debug"));
con's avatar
con committed
352
353
    menubar->addMenu(mdebug, Core::Constants::G_VIEW);

354
355
356
357
    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
358
359
360
361
362
363
364
365
366

    //
    // 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
367
    mbuild->appendGroup(Constants::G_BUILD_RUN);
con's avatar
con committed
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382

    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);
383
    msubProject->appendGroup(Constants::G_PROJECT_BUILD);
con's avatar
con committed
384
385
386
387
388
389
390
391
392
393
394
395
396
    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
397
    Core::ActionContainer * const openWith =
con's avatar
con committed
398
            am->createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
399
400
    d->m_openWithMenu = openWith->menu();
    d->m_openWithMenu->setTitle(tr("Open With"));
con's avatar
con committed
401
402

    connect(mfilec->menu(), SIGNAL(aboutToShow()), this, SLOT(populateOpenWithMenu()));
403
    connect(d->m_openWithMenu, SIGNAL(triggered(QAction *)),
con's avatar
con committed
404
405
406
407
408
409
            this, SLOT(openWithMenuTriggered(QAction *)));

    //
    // Separators
    //

con's avatar
con committed
410
    Core::Command *cmd;
con's avatar
con committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
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
    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
466
467
    d->m_sessionManagerAction = new QAction(tr("Session Manager..."), this);
    cmd = am->registerAction(d->m_sessionManagerAction, Constants::NEWSESSION, globalcontext);
con's avatar
con committed
468
469
470
    cmd->setDefaultKeySequence(QKeySequence());

    // new action
471
472
    d->m_newAction = new QAction(tr("New Project..."), this);
    cmd = am->registerAction(d->m_newAction, Constants::NEWPROJECT, globalcontext);
con's avatar
con committed
473
474
475
476
477
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+N")));
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

#if 0
    // open action
478
479
    d->m_loadAction = new QAction(tr("Load Project..."), this);
    cmd = am->registerAction(d->m_loadAction, Constants::LOAD, globalcontext);
con's avatar
con committed
480
481
482
483
484
485
    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
486
487
    d->m_openFileAction = new QAction(tr("Open File"), this);
    cmd = am->registerAction(d->m_openFileAction, ProjectExplorer::Constants::OPENFILE,
con's avatar
con committed
488
489
490
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OPEN);

491
    d->m_showInGraphicalShell = new QAction(FolderNavigationWidget::msgGraphicalShellAction(), this);
492
    cmd = am->registerAction(d->m_showInGraphicalShell, ProjectExplorer::Constants::SHOWINGRAPHICALSHELL,
con's avatar
con committed
493
494
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OPEN);
495
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
496

497
    d->m_openTerminalHere = new QAction(FolderNavigationWidget::msgTerminalAction(), this);
498
499
500
501
502
    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
503
504
505
    // Open With menu
    mfilec->addMenu(openWith, ProjectExplorer::Constants::G_FILE_OPEN);

mae's avatar
mae committed
506
    // recent projects menu
507
    Core::ActionContainer *mrecent =
mae's avatar
mae committed
508
        am->createMenu(Constants::M_RECENTPROJECTS);
509
    mrecent->menu()->setTitle(tr("Recent P&rojects"));
mae's avatar
mae committed
510
511
512
513
    mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
    connect(mfile->menu(), SIGNAL(aboutToShow()),
        this, SLOT(updateRecentProjectMenu()));

con's avatar
con committed
514
    // unload action
515
516
    d->m_unloadAction = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
                                                      Utils::ParameterAction::EnabledWithParameter, this);
517
    cmd = am->registerAction(d->m_unloadAction, Constants::UNLOAD, globalcontext);
con's avatar
con committed
518
    cmd->setAttribute(Core::Command::CA_UpdateText);
519
    cmd->setDefaultText(d->m_unloadAction->text());
con's avatar
con committed
520
521
522
523
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);

    // unload session action
524
525
    d->m_clearSession = new QAction(tr("Close All Projects"), this);
    cmd = am->registerAction(d->m_clearSession, Constants::CLEARSESSION, globalcontext);
con's avatar
con committed
526
527
528
529
    mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);

    // session menu
530
    Core::ActionContainer *msession = am->createMenu(Constants::M_SESSION);
531
    msession->menu()->setTitle(tr("Session"));
con's avatar
con committed
532
    mfile->addMenu(msession, Core::Constants::G_FILE_PROJECT);
533
    d->m_sessionMenu = msession->menu();
con's avatar
con committed
534
535
536
537
    connect(mfile->menu(), SIGNAL(aboutToShow()),
            this, SLOT(updateSessionMenu()));

    // build menu
538
    Core::ActionContainer *mbc =
con's avatar
con committed
539
        am->createMenu(Constants::BUILDCONFIGURATIONMENU);
540
541
    d->m_buildConfigurationMenu = mbc->menu();
    d->m_buildConfigurationMenu->setTitle(tr("Set Build Configuration"));
con's avatar
con committed
542
543
544
    //TODO this means it is build twice, rrr
    connect(mproject->menu(), SIGNAL(aboutToShow()), this, SLOT(populateBuildConfigurationMenu()));
    connect(mbuild->menu(), SIGNAL(aboutToShow()), this, SLOT(populateBuildConfigurationMenu()));
545
546
    connect(d->m_buildConfigurationMenu, SIGNAL(aboutToShow()), this, SLOT(populateBuildConfigurationMenu()));
    connect(d->m_buildConfigurationMenu, SIGNAL(triggered(QAction *)), this, SLOT(buildConfigurationMenuTriggered(QAction *)));
con's avatar
con committed
547
548
549
550

    // build session action
    QIcon buildIcon(Constants::ICON_BUILD);
    buildIcon.addFile(Constants::ICON_BUILD_SMALL);
551
552
    d->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
    cmd = am->registerAction(d->m_buildSessionAction, Constants::BUILDSESSION, globalcontext);
con's avatar
con committed
553
554
555
556
    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
557
    modeManager->addAction(cmd, Constants::P_ACTION_BUILDSESSION);
con's avatar
con committed
558
559
560
561

    // rebuild session action
    QIcon rebuildIcon(Constants::ICON_REBUILD);
    rebuildIcon.addFile(Constants::ICON_REBUILD_SMALL);
562
563
    d->m_rebuildSessionAction = new QAction(rebuildIcon, tr("Rebuild All"), this);
    cmd = am->registerAction(d->m_rebuildSessionAction, Constants::REBUILDSESSION, globalcontext);
con's avatar
con committed
564
565
566
567
568
569
    mbuild->addAction(cmd, Constants::G_BUILD_SESSION);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // clean session
    QIcon cleanIcon(Constants::ICON_CLEAN);
    cleanIcon.addFile(Constants::ICON_CLEAN_SMALL);
570
571
    d->m_cleanSessionAction = new QAction(cleanIcon, tr("Clean All"), this);
    cmd = am->registerAction(d->m_cleanSessionAction, Constants::CLEANSESSION, globalcontext);
con's avatar
con committed
572
573
574
575
    mbuild->addAction(cmd, Constants::G_BUILD_SESSION);
    msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);

    // build action
576
577
    d->m_buildAction = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
                                                     Utils::ParameterAction::EnabledWithParameter, this);
578
    cmd = am->registerAction(d->m_buildAction, Constants::BUILD, globalcontext);
579
    cmd->setAttribute(Core::Command::CA_UpdateText);
580
    cmd->setDefaultText(d->m_buildAction->text());
con's avatar
con committed
581
582
583
584
585
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

    // rebuild action
586
587
    d->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
                                                       Utils::ParameterAction::EnabledWithParameter, this);
588
    cmd = am->registerAction(d->m_rebuildAction, Constants::REBUILD, globalcontext);
589
    cmd->setAttribute(Core::Command::CA_UpdateText);
590
    cmd->setDefaultText(d->m_rebuildAction->text());
con's avatar
con committed
591
592
593
594
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

    // clean action
595
596
    d->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
                                                     Utils::ParameterAction::EnabledWithParameter, this);
597
    cmd = am->registerAction(d->m_cleanAction, Constants::CLEAN, globalcontext);
598
    cmd->setAttribute(Core::Command::CA_UpdateText);
599
    cmd->setDefaultText(d->m_cleanAction->text());
con's avatar
con committed
600
601
602
    mbuild->addAction(cmd, Constants::G_BUILD_PROJECT);
    mproject->addAction(cmd, Constants::G_PROJECT_BUILD);

603
    // build without dependencies action
604
605
    d->m_buildProjectOnlyAction = new QAction(tr("Build Without Dependencies"), this);
    cmd = am->registerAction(d->m_buildProjectOnlyAction, Constants::BUILDPROJECTONLY, globalcontext);
606

607
    // rebuild without dependencies action
608
609
    d->m_rebuildProjectOnlyAction = new QAction(tr("Rebuild Without Dependencies"), this);
    cmd = am->registerAction(d->m_rebuildProjectOnlyAction, Constants::REBUILDPROJECTONLY, globalcontext);
610

611
    // clean without dependencies action
612
613
    d->m_cleanProjectOnlyAction = new QAction(tr("Clean Without Dependencies"), this);
    cmd = am->registerAction(d->m_cleanProjectOnlyAction, Constants::CLEANPROJECTONLY, globalcontext);
614

con's avatar
con committed
615
    // Add Set Build Configuration to menu
dt's avatar
dt committed
616
    mbuild->addMenu(mbc, Constants::G_BUILD_OTHER);
con's avatar
con committed
617
618
619
620
621
    mproject->addMenu(mbc, Constants::G_PROJECT_CONFIG);

    // run action
    QIcon runIcon(Constants::ICON_RUN);
    runIcon.addFile(Constants::ICON_RUN_SMALL);
622
623
    d->m_runAction = new QAction(runIcon, tr("Run"), this);
    cmd = am->registerAction(d->m_runAction, Constants::RUN, globalcontext);
con's avatar
con committed
624
625
    cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R")));
    mbuild->addAction(cmd, Constants::G_BUILD_RUN);
626

627
    Core::ActionContainer *mrc = am->createMenu(Constants::RUNCONFIGURATIONMENU);
628
629
    d->m_runConfigurationMenu = mrc->menu();
    d->m_runConfigurationMenu->setTitle(tr("Set Run Configuration"));
con's avatar
con committed
630
631
632
    mbuild->addMenu(mrc, Constants::G_BUILD_RUN);
    mproject->addMenu(mrc, Constants::G_PROJECT_CONFIG);
    // TODO this recreates the menu twice if shown in the Build or context menu
633
    connect(d->m_runConfigurationMenu, SIGNAL(aboutToShow()), this, SLOT(populateRunConfigurationMenu()));
con's avatar
con committed
634
635
    connect(mproject->menu(), SIGNAL(aboutToShow()), this, SLOT(populateRunConfigurationMenu()));
    connect(mbuild->menu(), SIGNAL(aboutToShow()), this, SLOT(populateRunConfigurationMenu()));
636
    connect(d->m_runConfigurationMenu, SIGNAL(triggered(QAction *)), this, SLOT(runConfigurationMenuTriggered(QAction *)));
con's avatar
con committed
637

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

640
641
    d->m_runActionContextMenu = new QAction(runIcon, tr("Run"), this);
    cmd = am->registerAction(d->m_runActionContextMenu, Constants::RUNCONTEXTMENU, globalcontext);
642
643
    mproject->addAction(cmd, Constants::G_PROJECT_RUN);

con's avatar
con committed
644
    // cancel build action
645
646
    d->m_cancelBuildAction = new QAction(tr("Cancel Build"), this);
    cmd = am->registerAction(d->m_cancelBuildAction, Constants::CANCELBUILD, globalcontext);
con's avatar
con committed
647
648
649
650
    mbuild->addAction(cmd, Constants::G_BUILD_CANCEL);

    // debug action
    QIcon debuggerIcon(":/projectexplorer/images/debugger_start_small.png");
651
    debuggerIcon.addFile(":/projectexplorer/images/debugger_start.png");
652
653
    d->m_debugAction = new QAction(debuggerIcon, tr("Start Debugging"), this);
    cmd = am->registerAction(d->m_debugAction, Constants::DEBUG, globalcontext);
con's avatar
con committed
654
655
    cmd->setAttribute(Core::Command::CA_UpdateText);
    cmd->setAttribute(Core::Command::CA_UpdateIcon);
con's avatar
con committed
656
657
    cmd->setDefaultText(tr("Start Debugging"));
    cmd->setDefaultKeySequence(QKeySequence(tr("F5")));
658
    mstartdebugging->addAction(cmd, Core::Constants::G_DEFAULT_ONE);
659
    modeManager->addAction(cmd, Constants::P_ACTION_DEBUG);
con's avatar
con committed
660
661

    // add new file action
662
663
    d->m_addNewFileAction = new QAction(tr("Add New..."), this);
    cmd = am->registerAction(d->m_addNewFileAction, ProjectExplorer::Constants::ADDNEWFILE,
con's avatar
con committed
664
665
666
                       globalcontext);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
    msubProject->addAction(cmd, Constants::G_PROJECT_FILES);
667
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
668
669

    // add existing file action
670
671
    d->m_addExistingFilesAction = new QAction(tr("Add Existing Files..."), this);
    cmd = am->registerAction(d->m_addExistingFilesAction, ProjectExplorer::Constants::ADDEXISTINGFILES,
con's avatar
con committed
672
673
674
                       globalcontext);
    mproject->addAction(cmd, Constants::G_PROJECT_FILES);
    msubProject->addAction(cmd, Constants::G_PROJECT_FILES);
675
    mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
con's avatar
con committed
676
677

    // remove file action
678
679
    d->m_removeFileAction = new QAction(tr("Remove File..."), this);
    cmd = am->registerAction(d->m_removeFileAction, ProjectExplorer::Constants::REMOVEFILE,
con's avatar
con committed
680
681
682
683
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OTHER);

    // renamefile action (TODO: Not supported yet)
684
685
    d->m_renameFileAction = new QAction(tr("Rename"), this);
    cmd = am->registerAction(d->m_renameFileAction, ProjectExplorer::Constants::RENAMEFILE,
con's avatar
con committed
686
687
                       globalcontext);
    mfilec->addAction(cmd, Constants::G_FILE_OTHER);
688
689
    d->m_renameFileAction->setEnabled(false);
    d->m_renameFileAction->setVisible(false);
con's avatar
con committed
690

691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
    // target selector
    d->m_projectSelectorAction = new QAction(this);
    d->m_projectSelectorAction->setEnabled(false);
    QWidget *mainWindow = Core::ICore::instance()->mainWindow();
    d->m_targetSelector = new Internal::MiniProjectTargetSelector(d->m_projectSelectorAction, mainWindow);
    connect(d->m_projectSelectorAction, SIGNAL(triggered()), d->m_targetSelector, SLOT(show()));
    modeManager->addProjectSelector(d->m_projectSelectorAction);


    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*)));

709
    connect(core, SIGNAL(saveSettingsRequested()),
con's avatar
con committed
710
711
        this, SLOT(savePersistentSettings()));

hjk's avatar
hjk committed
712
713
    addAutoReleasedObject(new ProjectTreeWidgetFactory);
    addAutoReleasedObject(new FolderNavigationWidgetFactory);
con's avatar
con committed
714

715
    // > -- Creator 1.0 compatibility code
716
    QStringList oldRecentProjects;
717
    if (QSettings *s = core->settings())
718
719
        oldRecentProjects = s->value("ProjectExplorer/RecentProjects/Files", QStringList()).toStringList();
    for (QStringList::iterator it = oldRecentProjects.begin(); it != oldRecentProjects.end(); ) {
con's avatar
con committed
720
721
722
        if (QFileInfo(*it).isFile()) {
            ++it;
        } else {
723
            it = oldRecentProjects.erase(it);
con's avatar
con committed
724
725
726
        }
    }

727
    foreach(const QString &s, oldRecentProjects) {
728
        d->m_recentProjects.append(qMakePair(s, QFileInfo(s).fileName()));
729
    }
730
    // < -- Creator 1.0 compatibility code
731
732
733
734
735
736

    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) {
737
                if (QFileInfo(fileNames.at(i)).isFile())
738
                    d->m_recentProjects.append(qMakePair(fileNames.at(i), displayNames.at(i)));
739
740
741
742
            }
        }
    }

743
    if (QSettings *s = core->settings()) {
744
745
746
747
        d->m_projectExplorerSettings.buildBeforeRun = s->value("ProjectExplorer/Settings/BuildBeforeRun", true).toBool();
        d->m_projectExplorerSettings.saveBeforeBuild = s->value("ProjectExplorer/Settings/SaveBeforeBuild", false).toBool();
        d->m_projectExplorerSettings.showCompilerOutput = s->value("ProjectExplorer/Settings/ShowCompilerOutput", false).toBool();
        d->m_projectExplorerSettings.useJom = s->value("ProjectExplorer/Settings/UseJom", true).toBool();
748
    }
749

750
751
    connect(d->m_sessionManagerAction, SIGNAL(triggered()), this, SLOT(showSessionManager()));
    connect(d->m_newAction, SIGNAL(triggered()), this, SLOT(newProject()));
con's avatar
con committed
752
#if 0
753
    connect(d->m_loadAction, SIGNAL(triggered()), this, SLOT(loadAction()));
con's avatar
con committed
754
#endif
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
    connect(d->m_buildProjectOnlyAction, SIGNAL(triggered()), this, SLOT(buildProjectOnly()));
    connect(d->m_buildAction, SIGNAL(triggered()), this, SLOT(buildProject()));
    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()));
    connect(d->m_rebuildSessionAction, SIGNAL(triggered()), this, SLOT(rebuildSession()));
    connect(d->m_cleanProjectOnlyAction, SIGNAL(triggered()), this, SLOT(cleanProjectOnly()));
    connect(d->m_cleanAction, SIGNAL(triggered()), this, SLOT(cleanProject()));
    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()));
774
    connect(d->m_openTerminalHere, SIGNAL(triggered()), this, SLOT(openTerminalHere()));
775
776
    connect(d->m_removeFileAction, SIGNAL(triggered()), this, SLOT(removeFile()));
    connect(d->m_renameFileAction, SIGNAL(triggered()), this, SLOT(renameFile()));
con's avatar
con committed
777
778
779

    updateActions();

780
781
    connect(Core::ICore::instance(), SIGNAL(coreAboutToOpen()),
            this, SLOT(determineSessionToRestoreAtStartup()));
782
    connect(Core::ICore::instance(), SIGNAL(coreOpened()), this, SLOT(restoreSession()));
con's avatar
con committed
783

784
785
    updateWelcomePage();

con's avatar
con committed
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
    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
804
    if (const Core::MimeType mt = Core::ICore::instance()->mimeDatabase()->findByFile(QFileInfo(filename)))
805
        if (ProjectFileFactory *pf = findFactory<ProjectFileFactory>(mt.type(), d->m_fileFactories.constBegin(), d->m_fileFactories.constEnd()))
con's avatar
con committed
806
807
808
809
810
811
812
813
814
815
816
            return pf;
    qWarning("Unable to find project file factory for '%s'", filename.toUtf8().constData());
    return 0;
}

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


817
    QString dir = d->m_lastOpenDirectory;
con's avatar
con committed
818
819
820
821
822
823

    // 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();
824
            const bool isProject = d->m_profileMimeTypes.contains(file->mimeType());
con's avatar
con committed
825
826
827
828
829
830
            dir = isProject ? fn : QFileInfo(fn).absolutePath();
        }
    }

    QString filename = QFileDialog::getOpenFileName(0, tr("Load Project"),
                                                    dir,
831
                                                    d->m_projectFilterString);
con's avatar
con committed
832
833
834
835
836
837
838
    if (filename.isEmpty())
        return;
    if (ProjectFileFactory *pf = findProjectFileFactory(filename))
        pf->open(filename);
    updateActions();
}

839
void ProjectExplorerPlugin::unloadProject()
con's avatar
con committed
840
841
{
    if (debug)
842
        qDebug() << "ProjectExplorerPlugin::unloadProject";
con's avatar
con committed
843

844
    Core::IFile *fi = d->m_currentProject->file();
con's avatar
con committed
845
846

    if (!fi || fi->fileName().isEmpty()) //nothing to save?
847
        return;
con's avatar
con committed
848
849
850
851
852
853
854
855
856
857
858
859
860

    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)
861
        success = Core::ICore::instance()->fileManager()->saveModifiedFiles(filesToSave).isEmpty();
con's avatar
con committed
862
    else
863
        success = Core::ICore::instance()->fileManager()->saveModifiedFilesSilently(filesToSave).isEmpty();
con's avatar
con committed
864

865
    if (!success)
con's avatar
con committed
866
867
        return;

868
    addToRecentProjects(fi->fileName(), d->m_currentProject->displayName());
869
    d->m_session->removeProject(d->m_currentProject);
con's avatar
con committed
870
871
872
873
874
875
876
877
    updateActions();
}

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

878
    if (!d->m_session->clear())
con's avatar
con committed
879
880
881
882
883
884
        return; // Action has been cancelled
    updateActions();
}

void ProjectExplorerPlugin::extensionsInitialized()
{
885
886
887
    d->m_fileFactories = ProjectFileFactory::createFactories(&d->m_projectFilterString);
    foreach (ProjectFileFactory *pf, d->m_fileFactories) {
        d->m_profileMimeTypes += pf->mimeTypes();
con's avatar
con committed
888
889
890
891
892
893
        addAutoReleasedObject(pf);
    }
}

void ProjectExplorerPlugin::shutdown()
{
con's avatar
con committed
894
    d->m_proWindow->shutdown(); // disconnect from session
895
896
    d->m_session->clear();
//    d->m_proWindow->saveConfigChanges();
con's avatar
con committed
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
}

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

    QString defaultLocation;
    if (currentProject()) {
        const QFileInfo file(currentProject()->file()->fileName());
        QDir dir = file.dir();
        dir.cdUp();
        defaultLocation = dir.absolutePath();
    }

912
    Core::ICore::instance()->showNewItemDialog(tr("New Project", "Title of dialog"),
913
                              Core::IWizard::wizardsOfKind(Core::IWizard::ProjectWizard),
con's avatar
con committed
914
915
916
917
                              defaultLocation);
    updateActions();
}

918
void ProjectExplorerPlugin::showSessionManager()
con's avatar
con committed
919
920
{
    if (debug)
921
        qDebug() << "ProjectExplorerPlugin::showSessionManager";
con's avatar
con committed
922

923
    if (d->m_session->isDefaultVirgin()) {
con's avatar
con committed
924
925
        // do not save new virgin default sessions
    } else {
926
        d->m_session->save();
con's avatar
con committed
927
    }
928
    SessionDialog sessionDialog(d->m_session, d->m_session->activeSession(), false);
con's avatar
con committed
929
930
931
    sessionDialog.exec();

    updateActions();
932
933
934
935

    Core::ModeManager *modeManager = Core::ModeManager::instance();
    Core::IMode *welcomeMode = modeManager->mode(Core::Constants::MODE_WELCOME);
    if (modeManager->currentMode() == welcomeMode)
936
        updateWelcomePage();
con's avatar
con committed
937
938
939
940
941
942
943
944
}

void ProjectExplorerPlugin::setStartupProject(Project *project)
{
    if (debug)
        qDebug() << "ProjectExplorerPlugin::setStartupProject";

    if (!project)
945
        project = d->m_currentProject;
dt's avatar
dt committed
946
947
    if (!project)
        return;
948
    d->m_session->setStartupProject(project);
con's avatar
con committed
949
950
951
952
953
954
955
956
957
    // NPE: Visually mark startup project
    updateActions();
}

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

958
    foreach (Project *pro, d->m_session->projects())
con's avatar
con committed
959
960
        pro->saveSettings();

961
    if (d->m_session->isDefaultVirgin()) {
con's avatar
con committed
962
963
        // do not save new virgin default sessions
    } else {
964
        d->m_session->save();
con's avatar
con committed
965
966
    }

967
    QSettings *s = Core::ICore::instance()->settings();
con's avatar
con committed
968
    if (s) {
969
        s->setValue("ProjectExplorer/StartupSession", d->m_session->file()->fileName());
970
971
972
973
974
        s->remove("ProjectExplorer/RecentProjects/Files");

        QStringList fileNames;
        QStringList displayNames;
        QList<QPair<QString, QString> >::const_iterator it, end;
975
976
        end = d->m_recentProjects.constEnd();
        for (it = d->m_recentProjects.constBegin(); it != end; ++it) {
977
978
979
980
981
982
            fileNames << (*it).first;
            displayNames << (*it).second;
        }

        s->setValue("ProjectExplorer/RecentProjects/FileNames", fileNames);
        s->setValue("ProjectExplorer/RecentProjects/DisplayNames", displayNames);
983

984
985
986
987
        s->setValue("ProjectExplorer/Settings/BuildBeforeRun", d->m_projectExplorerSettings.buildBeforeRun);
        s->setValue("ProjectExplorer/Settings/SaveBeforeBuild", d->m_projectExplorerSettings.saveBeforeBuild);
        s->setValue("ProjectExplorer/Settings/ShowCompilerOutput", d->m_projectExplorerSettings.showCompilerOutput);
        s->setValue("ProjectExplorer/Settings/UseJom", d->m_projectExplorerSettings.useJom);
con's avatar
con committed
988
989
990
991
992
993
994
995
    }
}

bool ProjectExplorerPlugin::openProject(const QString &fileName)
{
    if (debug)
        qDebug() << "ProjectExplorerPlugin::openProject";

996
997
    QList<Project *> list = openProjects(QStringList() << fileName);
    if (!list.isEmpty()) {
998
        addToRecentProjects(fileName, list.first()->displayName());
con's avatar
con committed
999
1000
        return true;
    }