Commit 7c537a81 authored by Roberto Raggi's avatar Roberto Raggi

Introduced editors for .files and .includes files.

parent 8c83a8f7
......@@ -75,7 +75,7 @@ Q_DECLARE_METATYPE(Core::IEditor*)
using namespace Core;
using namespace Core::Internal;
enum { debugEditorManager=0 };
enum { debugEditorManager=1 };
static inline ExtensionSystem::PluginManager *pluginManager()
{
......
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-generic-project">
<sub-class-of type="text/plain"/>
<comment>Generic Qt Creator Project file</comment>
<glob pattern="*.creator"/>
</mime-type>
<mime-type type="application/vnd.nokia.qt.generic.files">
<sub-class-of type="text/plain"/>
<comment>Generic Project Files</comment>
<glob pattern="*.files"/>
</mime-type>
<mime-type type="application/vnd.nokia.qt.generic.includes">
<sub-class-of type="text/plain"/>
<comment>Generic Project Include Paths</comment>
<glob pattern="*.includes"/>
</mime-type>
<mime-type type="application/vnd.nokia.qt.generic.config">
<sub-class-of type="text/plain"/>
<comment>Generic Project Configuration File</comment>
<glob pattern="*.config"/>
</mime-type>
</mime-info>
......@@ -113,32 +113,72 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
_file = new GenericProjectFile(this, fileName);
_rootNode = new GenericProjectNode(this, _file);
_manager->registerProject(this);
}
GenericProject::~GenericProject()
{
qDebug() << Q_FUNC_INFO;
_manager->unregisterProject(this);
delete _rootNode;
delete _toolChain;
}
QStringList GenericProject::readLines(const QString &absoluteFileName) const
{
QStringList lines;
QFile file(absoluteFileName);
if (file.open(QFile::ReadOnly)) {
QTextStream stream(&file);
forever {
QString line = stream.readLine();
if (line.isNull())
break;
line = line.trimmed();
if (line.isEmpty())
continue;
lines.append(line);
}
}
return lines;
}
void GenericProject::parseProject()
{
const QFileInfo projectFileInfo(_fileName);
const QDir projectDir = projectFileInfo.dir();
const QString projectName = projectFileInfo.baseName();
const QFileInfo projectFiles(projectDir, projectName + QLatin1String(".files"));
const QFileInfo projectIncludes(projectDir, projectName + QLatin1String(".includes"));
const QFileInfo projectConfig(projectDir, projectName + QLatin1String(".config"));
QSettings projectInfo(_fileName, QSettings::IniFormat);
_files = convertToAbsoluteFiles(projectInfo.value(QLatin1String("files")).toStringList());
_files = convertToAbsoluteFiles(readLines(projectFiles.absoluteFilePath()));
_projectIncludePaths = readLines(projectIncludes.absoluteFilePath());
_generated = convertToAbsoluteFiles(projectInfo.value(QLatin1String("generated")).toStringList());
_defines = projectInfo.value(QLatin1String("defines")).toStringList();
_projectIncludePaths = projectInfo.value(QLatin1String("includePaths")).toStringList();
qDebug() << "project include paths:" << _projectIncludePaths;
emit fileListChanged();
}
void GenericProject::refresh()
{
qDebug() << Q_FUNC_INFO;
parseProject();
_rootNode->refresh();
CppTools::CppModelManagerInterface *modelManager =
......
......@@ -106,6 +106,8 @@ protected:
private:
void parseProject();
QStringList readLines(const QString &absoluteFileName) const;
Manager *_manager;
QString _fileName;
GenericProjectFile *_file;
......
......@@ -33,10 +33,24 @@
namespace GenericProjectManager {
namespace Constants {
const char *const PROJECTCONTEXT = "GenericProject.ProjectContext";
const char *const GENERICMIMETYPE = "text/x-generic-project";
const char *const MAKESTEP = "GenericProjectManager.MakeStep";
const char *const PROJECTCONTEXT = "GenericProject.ProjectContext";
const char *const GENERICMIMETYPE = "text/x-generic-project"; // ### FIXME
const char *const MAKESTEP = "GenericProjectManager.MakeStep";
// contexts
const char *const C_FILESEDITOR = ".files Editor";
// kinds
const char *const PROJECT_KIND = "Generic";
const char *const FILES_EDITOR = ".files Editor";
const char *const FILES_MIMETYPE = "application/vnd.nokia.qt.generic.files";
const char *const INCLUDES_EDITOR = ".includes Editor";
const char *const INCLUDES_MIMETYPE = "application/vnd.nokia.qt.generic.includes";
const char *const CONFIG_EDITOR = ".includes Editor";
const char *const CONFIG_MIMETYPE = "application/vnd.nokia.qt.generic.config";
} // namespace Constants
} // namespace GenericProjectManager
......
#include "genericprojectfileseditor.h"
#include "genericprojectmanager.h"
#include "genericprojectconstants.h"
#include <coreplugin/uniqueidmanager.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QtDebug>
using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditable
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesFactory::ProjectFilesFactory(Manager *manager,
TextEditor::TextEditorActionHandler *handler)
: Core::IEditorFactory(manager),
_manager(manager),
_actionHandler(handler)
{
_mimeTypes.append(QLatin1String(Constants::FILES_MIMETYPE));
_mimeTypes.append(QLatin1String(Constants::INCLUDES_MIMETYPE));
}
ProjectFilesFactory::~ProjectFilesFactory()
{ }
Manager *ProjectFilesFactory::manager() const
{ return _manager; }
Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
{
ProjectFilesEditor *ed = new ProjectFilesEditor(parent, this, _actionHandler);
// ### initialize
return ed->editableInterface();
}
QStringList ProjectFilesFactory::mimeTypes() const
{ return _mimeTypes; }
QString ProjectFilesFactory::kind() const
{ return QLatin1String(Constants::FILES_EDITOR); }
Core::IFile *ProjectFilesFactory::open(const QString &fileName)
{
qDebug() << Q_FUNC_INFO << fileName;
Core::EditorManager *editorManager = Core::EditorManager::instance();
if (Core::IEditor *editor = editorManager->openEditor(fileName, kind()))
return editor->file();
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditable
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditable::ProjectFilesEditable(ProjectFilesEditor *editor)
: TextEditor::BaseTextEditorEditable(editor)
{
Core::UniqueIDManager *uidm = Core::UniqueIDManager::instance();
_context << uidm->uniqueIdentifier(Constants::C_FILESEDITOR);
}
ProjectFilesEditable::~ProjectFilesEditable()
{ }
QList<int> ProjectFilesEditable::context() const
{ return _context; }
const char *ProjectFilesEditable::kind() const
{ return Constants::FILES_EDITOR; }
bool ProjectFilesEditable::duplicateSupported() const
{ return true; }
Core::IEditor *ProjectFilesEditable::duplicate(QWidget *parent)
{
ProjectFilesEditor *parentEditor = qobject_cast<ProjectFilesEditor *>(editor());
ProjectFilesEditor *editor = new ProjectFilesEditor(parent,
parentEditor->factory(),
parentEditor->actionHandler());
return editor->editableInterface();
}
////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditor
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditor::ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *factory,
TextEditor::TextEditorActionHandler *handler)
: TextEditor::BaseTextEditor(parent),
_factory(factory),
_actionHandler(handler)
{
Manager *manager = factory->manager();
ProjectFilesDocument *doc = new ProjectFilesDocument(manager);
setBaseTextDocument(doc);
}
ProjectFilesEditor::~ProjectFilesEditor()
{ }
ProjectFilesFactory *ProjectFilesEditor::factory() const
{ return _factory; }
TextEditor::TextEditorActionHandler *ProjectFilesEditor::actionHandler() const
{ return _actionHandler; }
TextEditor::BaseTextEditorEditable *ProjectFilesEditor::createEditableInterface()
{ return new ProjectFilesEditable(this); }
////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesDocument
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesDocument::ProjectFilesDocument(Manager *manager)
: _manager(manager)
{
setMimeType(QLatin1String(Constants::FILES_MIMETYPE));
}
ProjectFilesDocument::~ProjectFilesDocument()
{ }
bool ProjectFilesDocument::save(const QString &name)
{
if (! BaseTextDocument::save(name))
return false;
_manager->notifyChanged(name);
return true;
}
#ifndef GENERICPROJECTFILESEDITOR_H
#define GENERICPROJECTFILESEDITOR_H
#include <texteditor/basetexteditor.h>
#include <texteditor/basetextdocument.h>
#include <coreplugin/editormanager/ieditorfactory.h>
namespace GenericProjectManager {
namespace Internal {
class Manager;
class ProjectFilesEditable;
class ProjectFilesEditor;
class ProjectFilesDocument;
class ProjectFilesFactory;
class ProjectFilesFactory: public Core::IEditorFactory
{
Q_OBJECT
public:
ProjectFilesFactory(Manager *manager, TextEditor::TextEditorActionHandler *handler);
virtual ~ProjectFilesFactory();
Manager *manager() const;
virtual Core::IEditor *createEditor(QWidget *parent);
virtual QStringList mimeTypes() const;
virtual QString kind() const;
virtual Core::IFile *open(const QString &fileName);
private:
Manager *_manager;
TextEditor::TextEditorActionHandler *_actionHandler;
QStringList _mimeTypes;
};
class ProjectFilesEditable: public TextEditor::BaseTextEditorEditable
{
Q_OBJECT
public:
ProjectFilesEditable(ProjectFilesEditor *editor);
virtual ~ProjectFilesEditable();
virtual QList<int> context() const;
virtual const char *kind() const;
virtual bool duplicateSupported() const;
virtual Core::IEditor *duplicate(QWidget *parent);
private:
QList<int> _context;
};
class ProjectFilesEditor: public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *factory,
TextEditor::TextEditorActionHandler *handler);
virtual ~ProjectFilesEditor();
ProjectFilesFactory *factory() const;
TextEditor::TextEditorActionHandler *actionHandler() const;
virtual TextEditor::BaseTextEditorEditable *createEditableInterface();
private:
ProjectFilesFactory *_factory;
TextEditor::TextEditorActionHandler *_actionHandler;
};
class ProjectFilesDocument: public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
ProjectFilesDocument(Manager *manager);
virtual ~ProjectFilesDocument();
virtual bool save(const QString &name);
private:
Manager *_manager;
};
} // end of namespace Internal
} // end of namespace GenericProjectManager
#endif // GENERICPROJECTFILESEDITOR_H
......@@ -35,6 +35,8 @@
#include <coreplugin/uniqueidmanager.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <QtDebug>
using namespace GenericProjectManager::Internal;
Manager::Manager()
......@@ -60,9 +62,24 @@ ProjectExplorer::Project *Manager::openProject(const QString &fileName)
{
QFileInfo fileInfo(fileName);
if (fileInfo.isFile())
return new GenericProject(this, fileName);
if (fileInfo.isFile()) {
GenericProject *project = new GenericProject(this, fileName);
return project;
}
return 0;
}
void Manager::registerProject(GenericProject *project)
{ _projects.append(project); }
void Manager::unregisterProject(GenericProject *project)
{ _projects.removeAll(project); }
void Manager::notifyChanged(const QString &fileName)
{
foreach (GenericProject *project, _projects) {
project->refresh();
}
}
......@@ -35,6 +35,8 @@
namespace GenericProjectManager {
namespace Internal {
class GenericProject;
class Manager: public ProjectExplorer::IProjectManager
{
Q_OBJECT
......@@ -49,9 +51,15 @@ public:
virtual QString mimeType() const;
virtual ProjectExplorer::Project *openProject(const QString &fileName);
void notifyChanged(const QString &fileName);
void registerProject(GenericProject *project);
void unregisterProject(GenericProject *project);
private:
int _projectContext;
int _projectLanguage;
QList<GenericProject *> _projects;
};
} // namespace Internal
......
......@@ -8,6 +8,7 @@ HEADERS = genericproject.h \
genericprojectconstants.h \
genericprojectnodes.h \
genericprojectwizard.h \
genericprojectfileseditor.h \
pkgconfigtool.h \
makestep.h
SOURCES = genericproject.cpp \
......@@ -15,6 +16,7 @@ SOURCES = genericproject.cpp \
genericprojectmanager.cpp \
genericprojectnodes.cpp \
genericprojectwizard.cpp \
genericprojectfileseditor.cpp \
pkgconfigtool.cpp \
makestep.cpp
RESOURCES += genericproject.qrc
......@@ -30,21 +30,30 @@
#include "genericprojectplugin.h"
#include "genericprojectmanager.h"
#include "genericprojectwizard.h"
#include "genericprojectconstants.h"
#include "genericprojectfileseditor.h"
#include "makestep.h"
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <texteditor/texteditoractionhandler.h>
#include <QtCore/QtPlugin>
#include <QtCore/QDebug>
using namespace GenericProjectManager;
using namespace GenericProjectManager::Internal;
GenericProjectPlugin::GenericProjectPlugin()
: _projectFilesEditorFactory(0)
{ }
GenericProjectPlugin::~GenericProjectPlugin()
{ }
{
removeObject(_projectFilesEditorFactory);
delete _projectFilesEditorFactory;
}
bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage)
{
......@@ -58,7 +67,15 @@ bool GenericProjectPlugin::initialize(const QStringList &, QString *errorMessage
if (! mimeDB->addMimeTypes(mimetypesXml, errorMessage))
return false;
addAutoReleasedObject(new Manager);
Manager *manager = new Manager;
TextEditor::TextEditorActionHandler *actionHandler =
new TextEditor::TextEditorActionHandler(Constants::C_FILESEDITOR);
_projectFilesEditorFactory = new ProjectFilesFactory(manager, actionHandler);
addObject(_projectFilesEditorFactory);
addAutoReleasedObject(manager);
addAutoReleasedObject(new MakeBuildStepFactory);
addAutoReleasedObject(new GenericProjectWizard);
......
......@@ -37,6 +37,8 @@
namespace GenericProjectManager {
namespace Internal {
class ProjectFilesFactory;
class GenericProjectPlugin: public ExtensionSystem::IPlugin
{
Q_OBJECT
......@@ -47,6 +49,9 @@ public:
virtual bool initialize(const QStringList &arguments, QString *errorString);
virtual void extensionsInitialized();
private:
ProjectFilesFactory *_projectFilesEditorFactory;
};
} // namespace Internal
......
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