2009-03-20 14:57:12 +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).
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
** Commercial Usage
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
|
|
|
** 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.
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-03-16 11:08:07 +01:00
|
|
|
#include "genericprojectfileseditor.h"
|
|
|
|
#include "genericprojectmanager.h"
|
|
|
|
#include "genericprojectconstants.h"
|
|
|
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2009-03-16 15:22:05 +01:00
|
|
|
#include <texteditor/fontsettings.h>
|
2009-03-16 16:14:34 +01:00
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
2009-03-16 15:22:05 +01:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
using namespace GenericProjectManager;
|
|
|
|
using namespace GenericProjectManager::Internal;
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-03-16 16:14:34 +01:00
|
|
|
// ProjectFilesFactory
|
2009-03-16 11:08:07 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-03-16 15:14:13 +01:00
|
|
|
|
2009-03-16 11:08:07 +01:00
|
|
|
ProjectFilesFactory::ProjectFilesFactory(Manager *manager,
|
|
|
|
TextEditor::TextEditorActionHandler *handler)
|
|
|
|
: Core::IEditorFactory(manager),
|
2009-03-18 12:18:59 +01:00
|
|
|
m_manager(manager),
|
|
|
|
m_actionHandler(handler)
|
2009-03-16 11:08:07 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
m_mimeTypes.append(QLatin1String(Constants::FILES_MIMETYPE));
|
|
|
|
m_mimeTypes.append(QLatin1String(Constants::INCLUDES_MIMETYPE));
|
|
|
|
m_mimeTypes.append(QLatin1String(Constants::CONFIG_MIMETYPE));
|
2009-03-16 11:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFilesFactory::~ProjectFilesFactory()
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
Manager *ProjectFilesFactory::manager() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_manager;
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
Core::IEditor *ProjectFilesFactory::createEditor(QWidget *parent)
|
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
ProjectFilesEditor *ed = new ProjectFilesEditor(parent, this, m_actionHandler);
|
2009-03-17 18:17:51 +01:00
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(ed);
|
2009-03-16 11:08:07 +01:00
|
|
|
return ed->editableInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList ProjectFilesFactory::mimeTypes() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_mimeTypes;
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString ProjectFilesFactory::id() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
return QLatin1String(Constants::FILES_EDITOR_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ProjectFilesFactory::displayName() const
|
|
|
|
{
|
|
|
|
return tr(Constants::FILES_EDITOR_DISPLAY_NAME);
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
Core::IFile *ProjectFilesFactory::open(const QString &fileName)
|
|
|
|
{
|
|
|
|
Core::EditorManager *editorManager = Core::EditorManager::instance();
|
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
if (Core::IEditor *editor = editorManager->openEditor(fileName, id()))
|
2009-03-16 11:08:07 +01:00
|
|
|
return editor->file();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ProjectFilesEditable
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-03-16 15:14:13 +01:00
|
|
|
|
2009-03-16 11:08:07 +01:00
|
|
|
ProjectFilesEditable::ProjectFilesEditable(ProjectFilesEditor *editor)
|
2010-06-25 17:37:59 +02:00
|
|
|
: TextEditor::BaseTextEditorEditable(editor),
|
|
|
|
m_context(Constants::C_FILESEDITOR)
|
|
|
|
{ }
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
ProjectFilesEditable::~ProjectFilesEditable()
|
|
|
|
{ }
|
|
|
|
|
2010-06-25 12:56:16 +02:00
|
|
|
Core::Context ProjectFilesEditable::context() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_context;
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString ProjectFilesEditable::id() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2010-01-07 18:17:24 +01:00
|
|
|
return QLatin1String(Constants::FILES_EDITOR_ID);
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
bool ProjectFilesEditable::duplicateSupported() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
Core::IEditor *ProjectFilesEditable::duplicate(QWidget *parent)
|
|
|
|
{
|
|
|
|
ProjectFilesEditor *parentEditor = qobject_cast<ProjectFilesEditor *>(editor());
|
|
|
|
ProjectFilesEditor *editor = new ProjectFilesEditor(parent,
|
|
|
|
parentEditor->factory(),
|
|
|
|
parentEditor->actionHandler());
|
2009-03-17 18:17:51 +01:00
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
2009-03-16 11:08:07 +01:00
|
|
|
return editor->editableInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ProjectFilesEditor
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-03-16 15:14:13 +01:00
|
|
|
|
2009-03-16 11:08:07 +01:00
|
|
|
ProjectFilesEditor::ProjectFilesEditor(QWidget *parent, ProjectFilesFactory *factory,
|
|
|
|
TextEditor::TextEditorActionHandler *handler)
|
|
|
|
: TextEditor::BaseTextEditor(parent),
|
2009-03-18 12:18:59 +01:00
|
|
|
m_factory(factory),
|
|
|
|
m_actionHandler(handler)
|
2009-03-16 11:08:07 +01:00
|
|
|
{
|
|
|
|
Manager *manager = factory->manager();
|
|
|
|
ProjectFilesDocument *doc = new ProjectFilesDocument(manager);
|
|
|
|
setBaseTextDocument(doc);
|
2009-03-16 16:14:34 +01:00
|
|
|
|
|
|
|
handler->setupActions(this);
|
2009-03-16 11:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFilesEditor::~ProjectFilesEditor()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
ProjectFilesFactory *ProjectFilesEditor::factory() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_factory;
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
TextEditor::TextEditorActionHandler *ProjectFilesEditor::actionHandler() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2009-03-18 12:18:59 +01:00
|
|
|
return m_actionHandler;
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
TextEditor::BaseTextEditorEditable *ProjectFilesEditor::createEditableInterface()
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
|
|
|
return new ProjectFilesEditable(this);
|
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ProjectFilesDocument
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-03-16 15:14:13 +01:00
|
|
|
|
2009-03-16 11:08:07 +01:00
|
|
|
ProjectFilesDocument::ProjectFilesDocument(Manager *manager)
|
2009-03-18 12:18:59 +01:00
|
|
|
: m_manager(manager)
|
2009-03-16 11:08:07 +01:00
|
|
|
{
|
|
|
|
setMimeType(QLatin1String(Constants::FILES_MIMETYPE));
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFilesDocument::~ProjectFilesDocument()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
bool ProjectFilesDocument::save(const QString &name)
|
|
|
|
{
|
|
|
|
if (! BaseTextDocument::save(name))
|
|
|
|
return false;
|
|
|
|
|
2009-03-18 12:18:59 +01:00
|
|
|
m_manager->notifyChanged(name);
|
2009-03-16 11:08:07 +01:00
|
|
|
return true;
|
|
|
|
}
|