Commit 32ac14c2 authored by Kai Koehne's avatar Kai Koehne
Browse files

Wire up new project file format in Project Manager

Old format is still available as a fallback.
parent 47155f85
......@@ -32,12 +32,12 @@ SUBDIRS = plugin_coreplugin \
plugin_resourceeditor \
plugin_genericprojectmanager \
plugin_qmljseditor \
plugin_qmlprojectmanager \
plugin_mercurial \
debugger/dumper.pro
contains(QT_CONFIG, declarative) {
SUBDIRS += plugin_qmlinspector \
SUBDIRS += plugin_qmlprojectmanager \
plugin_qmlinspector \
plugin_qmldesigner
}
......
......@@ -59,11 +59,16 @@
#include <QtGui/QLabel>
#include <QtGui/QSpinBox>
#include <QtDeclarative/QmlComponent>
using namespace QmlProjectManager;
using namespace QmlProjectManager::Internal;
using namespace ProjectExplorer;
enum {
debug = false
};
////////////////////////////////////////////////////////////////////////////////////
// QmlProject
////////////////////////////////////////////////////////////////////////////////////
......@@ -121,13 +126,26 @@ static QStringList readLines(const QString &absoluteFileName)
return lines;
}
void QmlProject::parseProject(RefreshOptions options)
{
if (options & Files) {
m_files = convertToAbsoluteFiles(readLines(filesFileName()));
m_files.removeDuplicates();
m_modelManager->updateSourceFiles(m_files);
if (!m_projectItem) {
QmlComponent *component = new QmlComponent(&m_engine, m_fileName, this);
if (component->isReady()
&& qobject_cast<QmlProjectItem*>(component->create())) {
m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
} else {
qWarning() << m_fileName << "is not valid qml file, falling back to old format ...";
m_files = convertToAbsoluteFiles(readLines(filesFileName()));
m_files.removeDuplicates();
m_modelManager->updateSourceFiles(m_files);
}
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(projectDir().path());
m_modelManager->updateSourceFiles(m_projectItem.data()->qmlFiles());
}
m_rootNode->refresh();
}
if (options & Configuration) {
......@@ -163,7 +181,15 @@ QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const
}
QStringList QmlProject::files() const
{ return m_files; }
{
QStringList files;
if (m_projectItem) {
files = m_projectItem.data()->qmlFiles();
} else {
files = m_files;
}
return files;
}
QString QmlProject::displayName() const
{
......@@ -217,7 +243,7 @@ QmlProjectNode *QmlProject::rootProjectNode() const
QStringList QmlProject::files(FilesMode) const
{
return m_files;
return files();
}
bool QmlProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader)
......
......@@ -33,6 +33,7 @@
#include "qmlprojectmanager.h"
#include "qmlprojectnodes.h"
#include "qmlprojectmanager_global.h"
#include "fileformat/qmlprojectitem.h"
#include <projectexplorer/project.h>
#include <projectexplorer/projectnodes.h>
......@@ -41,6 +42,7 @@
#include <coreplugin/ifile.h>
#include <QtCore/QDir>
#include <QtDeclarative/QmlEngine>
namespace QmlJSEditor {
class QmlModelManagerInterface;
......@@ -184,18 +186,23 @@ protected:
virtual bool restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);
private:
// plain format
void parseProject(RefreshOptions options);
QStringList convertToAbsoluteFiles(const QStringList &paths) const;
Internal::Manager *m_manager;
QString m_fileName;
QString m_filesFileName;
Internal::QmlProjectFile *m_file;
QString m_projectName;
QmlJSEditor::QmlModelManagerInterface *m_modelManager;
// plain format
QStringList m_files;
// qml based, new format
QmlEngine m_engine;
QWeakPointer<QmlProjectItem> m_projectItem;
Internal::QmlProjectNode *m_rootNode;
};
......
TEMPLATE = lib
TARGET = QmlProjectManager
QT += declarative
include(../../qtcreatorplugin.pri)
include(qmlprojectmanager_dependencies.pri)
include(fileformat/fileformat.pri)
DEFINES += QMLPROJECTMANAGER_LIBRARY
HEADERS = qmlproject.h \
HEADERS += qmlproject.h \
qmlprojectplugin.h \
qmlprojectmanager.h \
qmlprojectconstants.h \
......@@ -13,7 +18,7 @@ HEADERS = qmlproject.h \
qmltaskmanager.h \
qmlprojectfileseditor.h \
qmlprojectmanager_global.h
SOURCES = qmlproject.cpp \
SOURCES += qmlproject.cpp \
qmlprojectplugin.cpp \
qmlprojectmanager.cpp \
qmlprojectnodes.cpp \
......
......@@ -78,29 +78,33 @@ void QmlProjectNode::refresh()
<< projectFilesNode,
this);
QStringList filePaths;
QHash<QString, QStringList> filesInPath;
QHash<QString, QStringList> filesInDirectory;
foreach (const QString &absoluteFileName, files) {
QFileInfo fileInfo(absoluteFileName);
const QString absoluteFilePath = fileInfo.path();
foreach (const QString &fileName, files) {
QFileInfo fileInfo(fileName);
if (! absoluteFilePath.startsWith(path()))
continue; // `file' is not part of the project.
QString absoluteFilePath;
QString relativeDirectory;
const QString relativeFilePath = absoluteFilePath.mid(path().length() + 1);
if (! filePaths.contains(relativeFilePath))
filePaths.append(relativeFilePath);
if (fileInfo.isAbsolute()) {
// plain old file format
absoluteFilePath = fileInfo.filePath();
relativeDirectory = m_project->projectDir().relativeFilePath(fileInfo.path());
} else {
absoluteFilePath = m_project->projectDir().absoluteFilePath(fileInfo.filePath());
relativeDirectory = fileInfo.path();
if (relativeDirectory == ".")
relativeDirectory.clear();
}
filesInPath[relativeFilePath].append(absoluteFileName);
filesInDirectory[relativeDirectory].append(absoluteFilePath);
}
foreach (const QString &filePath, filePaths) {
FolderNode *folder = findOrCreateFolderByName(filePath);
foreach (const QString &directory, filesInDirectory.keys()) {
FolderNode *folder = findOrCreateFolderByName(directory);
QList<FileNode *> fileNodes;
foreach (const QString &file, filesInPath.value(filePath)) {
foreach (const QString &file, filesInDirectory.value(directory)) {
FileType fileType = SourceType; // ### FIXME
FileNode *fileNode = new FileNode(file, fileType, /*generated = */ false);
fileNodes.append(fileNode);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment