2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "qt4projectmanager.h"
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "qt4projectmanagerconstants.h"
|
|
|
|
|
#include "qt4projectmanagerplugin.h"
|
|
|
|
|
#include "qt4nodes.h"
|
|
|
|
|
#include "qt4project.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "qt4target.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "profilereader.h"
|
|
|
|
|
#include "qmakestep.h"
|
2009-12-08 13:09:16 +01:00
|
|
|
#include "qt4buildconfiguration.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/basefilewizard.h>
|
|
|
|
|
#include <coreplugin/messagemanager.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-01-14 15:08:46 +01:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2009-09-25 11:35:44 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2009-01-14 15:08:46 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2009-12-08 12:48:43 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2010-03-10 10:21:52 +01:00
|
|
|
#include <designer/formwindoweditor.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QCoreApplication>
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QVariant>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
|
|
|
|
|
|
using namespace Qt4ProjectManager;
|
|
|
|
|
using namespace Qt4ProjectManager::Internal;
|
|
|
|
|
|
|
|
|
|
using ProjectExplorer::BuildStep;
|
|
|
|
|
using ProjectExplorer::FileType;
|
|
|
|
|
using ProjectExplorer::HeaderType;
|
|
|
|
|
using ProjectExplorer::SourceType;
|
|
|
|
|
using ProjectExplorer::FormType;
|
|
|
|
|
using ProjectExplorer::ResourceType;
|
|
|
|
|
using ProjectExplorer::UnknownFileType;
|
|
|
|
|
|
|
|
|
|
// Known file types of a Qt 4 project
|
2009-01-16 16:30:22 +01:00
|
|
|
static const char* qt4FileTypes[] = {
|
|
|
|
|
"CppHeaderFiles",
|
|
|
|
|
"CppSourceFiles",
|
|
|
|
|
"Qt4FormFiles",
|
|
|
|
|
"Qt4ResourceFiles"
|
|
|
|
|
};
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
Qt4Manager::Qt4Manager(Qt4ProjectManagerPlugin *plugin)
|
2009-12-08 12:48:43 +01:00
|
|
|
: m_plugin(plugin),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_contextProject(0),
|
2009-05-12 14:12:20 +02:00
|
|
|
m_lastEditor(0),
|
|
|
|
|
m_dirty(false)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt4Manager::~Qt4Manager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 18:14:06 +01:00
|
|
|
void Qt4Manager::registerProject(Qt4Project *project)
|
|
|
|
|
{
|
|
|
|
|
m_projects.append(project);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::unregisterProject(Qt4Project *project)
|
|
|
|
|
{
|
|
|
|
|
m_projects.removeOne(project);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::notifyChanged(const QString &name)
|
|
|
|
|
{
|
2008-12-09 11:07:24 +01:00
|
|
|
foreach (Qt4Project *pro, m_projects)
|
2008-12-02 18:14:06 +01:00
|
|
|
pro->notifyChanged(name);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void Qt4Manager::init()
|
|
|
|
|
{
|
2009-05-12 14:12:20 +02:00
|
|
|
connect(Core::EditorManager::instance(), SIGNAL(editorAboutToClose(Core::IEditor*)),
|
|
|
|
|
this, SLOT(editorAboutToClose(Core::IEditor*)));
|
|
|
|
|
|
|
|
|
|
connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
|
|
|
|
|
this, SLOT(editorChanged(Core::IEditor*)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::editorChanged(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
// Handle old editor
|
2010-03-10 10:21:52 +01:00
|
|
|
Designer::FormWindowEditor *lastFormEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
|
2010-02-26 14:55:25 +01:00
|
|
|
if (lastFormEditor) {
|
|
|
|
|
disconnect(lastFormEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
|
2009-05-12 14:12:20 +02:00
|
|
|
|
|
|
|
|
if (m_dirty) {
|
2010-02-26 14:55:25 +01:00
|
|
|
const QString contents = lastFormEditor->contents();
|
2009-05-12 14:12:20 +02:00
|
|
|
foreach(Qt4Project *project, m_projects)
|
2010-02-26 14:55:25 +01:00
|
|
|
project->rootProjectNode()->updateCodeModelSupportFromEditor(lastFormEditor->file()->fileName(), contents);
|
2009-05-12 14:12:20 +02:00
|
|
|
m_dirty = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_lastEditor = editor;
|
|
|
|
|
|
|
|
|
|
// Handle new editor
|
2010-03-10 10:21:52 +01:00
|
|
|
if (Designer::FormWindowEditor *fw = qobject_cast<Designer::FormWindowEditor *>(editor))
|
2009-05-12 14:12:20 +02:00
|
|
|
connect(fw, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (m_lastEditor == editor) {
|
|
|
|
|
// Oh no our editor is going to be closed
|
|
|
|
|
// get the content first
|
2010-03-10 10:21:52 +01:00
|
|
|
Designer::FormWindowEditor *lastEditor = qobject_cast<Designer::FormWindowEditor *>(m_lastEditor);
|
2009-05-12 14:12:20 +02:00
|
|
|
if (lastEditor) {
|
|
|
|
|
disconnect(lastEditor, SIGNAL(changed()), this, SLOT(uiEditorContentsChanged()));
|
|
|
|
|
if (m_dirty) {
|
2010-02-26 14:55:25 +01:00
|
|
|
const QString contents = lastEditor->contents();
|
2009-05-12 14:12:20 +02:00
|
|
|
foreach(Qt4Project *project, m_projects)
|
2010-02-26 14:55:25 +01:00
|
|
|
project->rootProjectNode()->updateCodeModelSupportFromEditor(lastEditor->file()->fileName(), contents);
|
2009-05-12 14:12:20 +02:00
|
|
|
m_dirty = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_lastEditor = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::uiEditorContentsChanged()
|
|
|
|
|
{
|
|
|
|
|
// cast sender, get filename
|
|
|
|
|
if (m_dirty)
|
|
|
|
|
return;
|
2010-03-10 10:21:52 +01:00
|
|
|
Designer::FormWindowEditor *fw = qobject_cast<Designer::FormWindowEditor *>(sender());
|
2009-05-12 14:12:20 +02:00
|
|
|
if (!fw)
|
|
|
|
|
return;
|
|
|
|
|
m_dirty = true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Qt4Manager::projectContext() const
|
|
|
|
|
{
|
|
|
|
|
return m_plugin->projectContext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Qt4Manager::projectLanguage() const
|
|
|
|
|
{
|
2009-12-08 12:48:43 +01:00
|
|
|
return Core::UniqueIDManager::instance()->
|
|
|
|
|
uniqueIdentifier(QLatin1String(ProjectExplorer::Constants::LANG_CXX));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Qt4Manager::mimeType() const
|
|
|
|
|
{
|
2009-12-08 12:48:43 +01:00
|
|
|
return QLatin1String(Qt4ProjectManager::Constants::PROFILE_MIMETYPE);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Project* Qt4Manager::openProject(const QString &fileName)
|
|
|
|
|
{
|
2009-01-20 15:31:33 +01:00
|
|
|
Core::MessageManager *messageManager = Core::ICore::instance()->messageManager();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// TODO Make all file paths relative & remove this hack
|
|
|
|
|
// We convert the path to an absolute one here because qt4project.cpp
|
|
|
|
|
// && profileevaluator use absolute/canonical file paths all over the place
|
|
|
|
|
// Correct fix would be to remove these calls ...
|
|
|
|
|
QString canonicalFilePath = QFileInfo(fileName).canonicalFilePath();
|
|
|
|
|
|
|
|
|
|
if (canonicalFilePath.isEmpty()) {
|
2009-04-15 17:19:15 +02:00
|
|
|
messageManager->printToOutputPane(tr("Failed opening project '%1': Project file does not exist").arg(QDir::toNativeSeparators(canonicalFilePath)));
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (ProjectExplorer::Project *pi, projectExplorer()->session()->projects()) {
|
|
|
|
|
if (canonicalFilePath == pi->file()->fileName()) {
|
2009-04-15 17:19:15 +02:00
|
|
|
messageManager->printToOutputPane(tr("Failed opening project '%1': Project already open").arg(QDir::toNativeSeparators(canonicalFilePath)));
|
2008-12-02 12:01:29 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt4Project *pro = new Qt4Project(this, canonicalFilePath);
|
|
|
|
|
return pro;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::ProjectExplorerPlugin *Qt4Manager::projectExplorer() const
|
|
|
|
|
{
|
2009-12-08 12:48:43 +01:00
|
|
|
return ProjectExplorer::ProjectExplorerPlugin::instance();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Node *Qt4Manager::contextNode() const
|
|
|
|
|
{
|
|
|
|
|
return m_contextNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::setContextNode(ProjectExplorer::Node *node)
|
|
|
|
|
{
|
|
|
|
|
m_contextNode = node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::setContextProject(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
m_contextProject = project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::Project *Qt4Manager::contextProject() const
|
|
|
|
|
{
|
|
|
|
|
return m_contextProject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::runQMake()
|
|
|
|
|
{
|
2010-01-13 18:00:02 +01:00
|
|
|
runQMake(projectExplorer()->currentProject(), 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::runQMakeContextMenu()
|
|
|
|
|
{
|
2010-01-13 18:00:02 +01:00
|
|
|
runQMake(m_contextProject, m_contextNode);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-13 18:00:02 +01:00
|
|
|
void Qt4Manager::runQMake(ProjectExplorer::Project *p, ProjectExplorer::Node *node)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-12-08 13:09:16 +01:00
|
|
|
Qt4Project *qt4pro = qobject_cast<Qt4Project *>(p);
|
|
|
|
|
QTC_ASSERT(qt4pro, return);
|
2010-01-13 18:00:02 +01:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!qt4pro->activeTarget() ||
|
|
|
|
|
!qt4pro->activeTarget()->activeBuildConfiguration())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Qt4BuildConfiguration *bc = qt4pro->activeTarget()->activeBuildConfiguration();
|
2009-12-08 13:09:16 +01:00
|
|
|
QMakeStep *qs = bc->qmakeStep();
|
2009-10-27 14:16:28 +01:00
|
|
|
|
2009-07-21 15:01:16 +02:00
|
|
|
if (!qs)
|
|
|
|
|
return;
|
2008-12-02 12:01:29 +01:00
|
|
|
//found qmakeStep, now use it
|
2009-07-21 15:01:16 +02:00
|
|
|
qs->setForced(true);
|
2010-01-13 18:00:02 +01:00
|
|
|
|
|
|
|
|
if (node != 0 && node != qt4pro->rootProjectNode())
|
|
|
|
|
if (Qt4ProFileNode *profile = qobject_cast<Qt4ProFileNode *>(node))
|
|
|
|
|
bc->setSubNodeBuild(profile);
|
|
|
|
|
|
2009-12-08 12:48:43 +01:00
|
|
|
projectExplorer()->buildManager()->appendStep(qs);
|
2010-01-13 18:00:02 +01:00
|
|
|
bc->setSubNodeBuild(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Qt4Manager::buildSubDirContextMenu()
|
|
|
|
|
{
|
|
|
|
|
Qt4Project *qt4pro = qobject_cast<Qt4Project *>(m_contextProject);
|
|
|
|
|
QTC_ASSERT(qt4pro, return);
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!qt4pro->activeTarget() ||
|
|
|
|
|
!qt4pro->activeTarget()->activeBuildConfiguration())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Qt4BuildConfiguration *bc = qt4pro->activeTarget()->activeBuildConfiguration();
|
2010-01-13 18:00:02 +01:00
|
|
|
if (m_contextNode != 0 && m_contextNode != qt4pro->rootProjectNode())
|
|
|
|
|
if (Qt4ProFileNode *profile = qobject_cast<Qt4ProFileNode *>(m_contextNode))
|
|
|
|
|
bc->setSubNodeBuild(profile);
|
|
|
|
|
|
2010-03-01 17:28:46 +01:00
|
|
|
if (projectExplorer()->saveModifiedFiles())
|
|
|
|
|
projectExplorer()->buildManager()->buildProject(bc);
|
2010-01-13 18:00:02 +01:00
|
|
|
|
|
|
|
|
bc->setSubNodeBuild(0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Qt4Manager::fileTypeId(ProjectExplorer::FileType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case HeaderType:
|
|
|
|
|
return QLatin1String(qt4FileTypes[0]);
|
|
|
|
|
case SourceType:
|
|
|
|
|
return QLatin1String(qt4FileTypes[1]);
|
|
|
|
|
case FormType:
|
|
|
|
|
return QLatin1String(qt4FileTypes[2]);
|
|
|
|
|
case ResourceType:
|
|
|
|
|
return QLatin1String(qt4FileTypes[3]);
|
|
|
|
|
case UnknownFileType:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return QString();
|
|
|
|
|
}
|