Commit ec38c829 authored by Konstantin Tokarev's avatar Konstantin Tokarev Committed by Eike Ziller

Added default implementation for IEditorFactory::open().

This change allows to avoid massive code duplication along editors.

Change-Id: Ifdc6ae4b44ab399d34193ab8dddfa1f76d65ad11
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 6630857d
......@@ -426,13 +426,6 @@ QString BinEditorFactory::displayName() const
return tr(Constants::C_BINEDITOR_DISPLAY_NAME);
}
Core::IDocument *BinEditorFactory::open(const QString &fileName)
{
Core::EditorManager *em = Core::EditorManager::instance();
Core::IEditor *iface = em->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
Core::IEditor *BinEditorFactory::createEditor(QWidget *parent)
{
BinEditor *editor = new BinEditor(parent);
......
......@@ -109,7 +109,6 @@ public:
Core::IEditor *createEditor(QWidget *parent);
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
private:
const QStringList m_mimeTypes;
......
......@@ -84,12 +84,6 @@ QString CMakeEditorFactory::displayName() const
return tr(CMakeProjectManager::Constants::CMAKE_EDITOR_DISPLAY_NAME);
}
Core::IDocument *CMakeEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
Core::IEditor *CMakeEditorFactory::createEditor(QWidget *parent)
{
CMakeEditorWidget *rc = new CMakeEditorWidget(parent, this, m_actionHandler);
......
......@@ -57,7 +57,6 @@ public:
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
private:
......
......@@ -94,7 +94,8 @@ SOURCES += mainwindow.cpp \
featureprovider.cpp \
idocument.cpp \
textdocument.cpp \
documentmanager.cpp
documentmanager.cpp \
ieditorfactory.cpp
HEADERS += mainwindow.h \
editmode.h \
......
......@@ -47,6 +47,7 @@ public:
IEditorFactory(QObject *parent = 0) : IDocumentFactory(parent) {}
virtual IEditor *createEditor(QWidget *parent) = 0;
virtual IDocument *open(const QString &fileName);
};
} // namespace Core
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** 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.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "ieditorfactory.h"
#include "ieditor.h"
#include "editormanager.h"
Core::IDocument *Core::IEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
......@@ -108,12 +108,6 @@ QString CppEditorFactory::displayName() const
return tr(CppEditor::Constants::CPPEDITOR_DISPLAY_NAME);
}
Core::IDocument *CppEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
Core::IEditor *CppEditorFactory::createEditor(QWidget *parent)
{
CPPEditorWidget *editor = new CPPEditorWidget(parent);
......
......@@ -121,7 +121,6 @@ public:
Core::IEditor *createEditor(QWidget *parent);
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
private:
CppPlugin *m_owner;
......
......@@ -79,16 +79,6 @@ QString ProjectFilesFactory::displayName() const
return tr(Constants::FILES_EDITOR_DISPLAY_NAME);
}
Core::IDocument *ProjectFilesFactory::open(const QString &fileName)
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
if (Core::IEditor *editor = editorManager->openEditor(fileName, id()))
return editor->document();
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// ProjectFilesEditable
////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -62,7 +62,6 @@ public:
virtual QStringList mimeTypes() const;
virtual Core::Id id() const;
virtual QString displayName() const;
virtual Core::IDocument *open(const QString &fileName);
private:
TextEditor::TextEditorActionHandler *m_actionHandler;
......
......@@ -75,16 +75,6 @@ QString GLSLEditorFactory::displayName() const
return tr(C_GLSLEDITOR_DISPLAY_NAME);
}
Core::IDocument *GLSLEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
if (!iface) {
qWarning() << "QmlEditorFactory::open: openEditor failed for " << fileName;
return 0;
}
return iface->document();
}
Core::IEditor *GLSLEditorFactory::createEditor(QWidget *parent)
{
GLSLEditor::GLSLTextEditorWidget *rc = new GLSLEditor::GLSLTextEditorWidget(parent);
......
......@@ -51,7 +51,6 @@ public:
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
private slots:
......
......@@ -77,17 +77,6 @@ QString QmlJSEditorFactory::displayName() const
return tr(C_QMLJSEDITOR_DISPLAY_NAME);
}
Core::IDocument *QmlJSEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
if (!iface) {
qWarning() << "QmlEditorFactory::open: openEditor failed for " << fileName;
return 0;
}
return iface->document();
}
Core::IEditor *QmlJSEditorFactory::createEditor(QWidget *parent)
{
QmlJSEditor::QmlJSTextEditorWidget *rc = new QmlJSEditor::QmlJSTextEditorWidget(parent);
......
......@@ -51,7 +51,6 @@ public:
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
private:
......
......@@ -78,12 +78,6 @@ QString ProFileEditorFactory::displayName() const
return tr(Qt4ProjectManager::Constants::PROFILE_EDITOR_DISPLAY_NAME);
}
Core::IDocument *ProFileEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
Core::IEditor *ProFileEditorFactory::createEditor(QWidget *parent)
{
ProFileEditorWidget *editor = new ProFileEditorWidget(parent, this, m_actionHandler);
......
......@@ -59,7 +59,6 @@ public:
QStringList mimeTypes() const;
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
Qt4Manager *qt4ProjectManager() const { return m_manager; }
......
......@@ -64,16 +64,6 @@ QString ResourceEditorFactory::displayName() const
return tr(C_RESOURCEEDITOR_DISPLAY_NAME);
}
Core::IDocument *ResourceEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
if (!iface) {
qWarning() << "ResourceEditorFactory::open: openEditor failed for " << fileName;
return 0;
}
return iface->document();
}
Core::IEditor *ResourceEditorFactory::createEditor(QWidget *parent)
{
Core::Context context(ResourceEditor::Constants::C_RESOURCEEDITOR);
......
......@@ -55,7 +55,6 @@ public:
// IEditorFactory
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
private:
......
......@@ -75,12 +75,6 @@ QString PlainTextEditorFactory::displayName() const
return tr(Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME);
}
Core::IDocument *PlainTextEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent)
{
PlainTextEditorWidget *rc = new PlainTextEditorWidget(parent);
......
......@@ -54,8 +54,6 @@ public:
//Core::IEditorFactory
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
TextEditor::TextEditorActionHandler *actionHandler() const { return m_actionHandler; }
......
......@@ -99,12 +99,6 @@ QString BaseVcsEditorFactory::displayName() const
return d->m_displayName;
}
Core::IDocument *BaseVcsEditorFactory::open(const QString &fileName)
{
Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
return iface ? iface->document() : 0;
}
Core::IEditor *BaseVcsEditorFactory::createEditor(QWidget *parent)
{
VcsBaseEditorWidget *vcsEditor = createVcsBaseEditor(d->m_type, parent);
......
......@@ -57,8 +57,6 @@ public:
Core::Id id() const;
QString displayName() const;
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
private:
......
......@@ -91,11 +91,4 @@ QStringList BaseVcsSubmitEditorFactory::mimeTypes() const
return d->m_mimeTypes;
}
Core::IDocument *BaseVcsSubmitEditorFactory::open(const QString &fileName)
{
if (Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id()))
return iface->document();
return 0;
}
} // namespace VcsBase
......@@ -62,7 +62,6 @@ public:
Core::Id id() const;
QString displayName() const;
QStringList mimeTypes() const;
Core::IDocument *open(const QString &fileName);
private:
virtual VcsBaseSubmitEditor
......
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