qmlprojectmanager.cpp 3.04 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
8
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
15 16 17 18 19 20 21 22 23 24
**
** GNU Lesser General Public License Usage
**
** 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.
**
con's avatar
con committed
25 26 27 28 29 30
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
31 32 33 34 35 36 37 38
**
**************************************************************************/

#include "qmlprojectmanager.h"
#include "qmlprojectconstants.h"
#include "qmlproject.h"

#include <coreplugin/icore.h>
Kai Koehne's avatar
Kai Koehne committed
39
#include <coreplugin/ifile.h>
40
#include <coreplugin/messagemanager.h>
41
#include <projectexplorer/projectexplorerconstants.h>
42 43
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
44 45 46

#include <QtDebug>

Kai Koehne's avatar
Kai Koehne committed
47 48
namespace QmlProjectManager {
namespace Internal {
49 50 51 52 53 54 55 56 57 58

Manager::Manager()
{
}

QString Manager::mimeType() const
{ return QLatin1String(Constants::QMLMIMETYPE); }

ProjectExplorer::Project *Manager::openProject(const QString &fileName)
{
59 60
    Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();

61
    QFileInfo fileInfo(fileName);
62 63 64 65
    ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ProjectExplorer::ProjectExplorerPlugin::instance();

    foreach (ProjectExplorer::Project *pi, projectExplorer->session()->projects()) {
        if (fileName == pi->file()->fileName()) {
66 67
            messageManager->printToOutputPanePopup(tr("Failed opening project '%1': Project already open")
                                                   .arg(QDir::toNativeSeparators(fileName)));
68 69 70
            return 0;
        }
    }
71

Erik Verbruggen's avatar
Erik Verbruggen committed
72 73
    if (fileInfo.isFile())
        return new QmlProject(this, fileName);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    return 0;
}

void Manager::registerProject(QmlProject *project)
{ m_projects.append(project); }

void Manager::unregisterProject(QmlProject *project)
{ m_projects.removeAll(project); }

void Manager::notifyChanged(const QString &fileName)
{
    foreach (QmlProject *project, m_projects) {
        if (fileName == project->filesFileName()) {
            project->refresh(QmlProject::Files);
        }
    }
}
Kai Koehne's avatar
Kai Koehne committed
92 93 94

} // namespace Internal
} // namespace QmlProjectManager