2009-03-20 14:57:12 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 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
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** 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.
|
2009-03-20 14:57:12 +01:00
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** 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.
|
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)
|
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesEditorWidget *ed = new ProjectFilesEditorWidget(parent, this, m_actionHandler);
|
2009-03-17 18:17:51 +01:00
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(ed);
|
2011-02-21 16:02:26 +01:00
|
|
|
return ed->editor();
|
2009-03-16 11:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
|
|
|
|
: TextEditor::BaseTextEditor(editor),
|
2010-06-25 17:37:59 +02:00
|
|
|
m_context(Constants::C_FILESEDITOR)
|
|
|
|
{ }
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesEditor::~ProjectFilesEditor()
|
2009-03-16 11:08:07 +01:00
|
|
|
{ }
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
Core::Context ProjectFilesEditor::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
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
QString ProjectFilesEditor::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
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
bool ProjectFilesEditor::duplicateSupported() const
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
Core::IEditor *ProjectFilesEditor::duplicate(QWidget *parent)
|
2009-03-16 11:08:07 +01:00
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesEditorWidget *parentEditor = qobject_cast<ProjectFilesEditorWidget *>(editorWidget());
|
|
|
|
ProjectFilesEditorWidget *editor = new ProjectFilesEditorWidget(parent,
|
2009-03-16 11:08:07 +01:00
|
|
|
parentEditor->factory(),
|
|
|
|
parentEditor->actionHandler());
|
2009-03-17 18:17:51 +01:00
|
|
|
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
2011-02-21 16:02:26 +01:00
|
|
|
return editor->editor();
|
2009-03-16 11:08:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ProjectFilesEditor
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
2009-03-16 15:14:13 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent, ProjectFilesFactory *factory,
|
2009-03-16 11:08:07 +01:00
|
|
|
TextEditor::TextEditorActionHandler *handler)
|
2011-02-21 16:02:26 +01:00
|
|
|
: TextEditor::BaseTextEditorWidget(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
|
|
|
}
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesEditorWidget::~ProjectFilesEditorWidget()
|
2009-03-16 11:08:07 +01:00
|
|
|
{ }
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
ProjectFilesFactory *ProjectFilesEditorWidget::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
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
TextEditor::TextEditorActionHandler *ProjectFilesEditorWidget::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
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
TextEditor::BaseTextEditor *ProjectFilesEditorWidget::createEditor()
|
2009-03-16 15:14:13 +01:00
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
return new ProjectFilesEditor(this);
|
2009-03-16 15:14:13 +01:00
|
|
|
}
|
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;
|
|
|
|
}
|