basevcseditorfactory.cpp 3.64 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
34
#include "basevcseditorfactory.h"
#include "vcsbaseeditor.h"

#include <texteditor/texteditoractionhandler.h>

jkobus's avatar
jkobus committed
35
#include <diffeditor/diffeditorconstants.h>
36
37
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
jkobus's avatar
jkobus committed
38

39
#include <QCoreApplication>
40
#include <QStringList>
41

42
43
using namespace TextEditor;

44
/*!
hjk's avatar
hjk committed
45
    \class VcsBase::BaseVCSEditorFactory
46

47
48
    \brief The BaseVCSEditorFactory class is the base class for editor
    factories creating instances of VcsBaseEditor subclasses.
49

hjk's avatar
hjk committed
50
    \sa VcsBase::VcsBaseEditorWidget
51
52
*/

hjk's avatar
hjk committed
53
namespace VcsBase {
54

55
VcsEditorFactory::VcsEditorFactory(const VcsBaseEditorParameters *parameters,
56
                                   const EditorWidgetCreator &editorWidgetCreator,
57
                                   QObject *describeReceiver, const char *describeSlot)
con's avatar
con committed
58
{
59
    setProperty("VcsEditorFactoryName", QByteArray(parameters->id));
60
61
62
63
    setId(parameters->id);
    setDisplayName(QCoreApplication::translate("VCS", parameters->displayName));
    if (QLatin1String(parameters->mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE))
        addMimeType(parameters->mimeType);
con's avatar
con committed
64

65
66
    setEditorActionHandlers(parameters->context, TextEditorActionHandler::None);

67
    setDocumentCreator([=]() -> BaseTextDocument* {
68
69
70
71
72
73
        auto document = new BaseTextDocument(parameters->id);
 //  if (QLatin1String(parameters->mimeType) != QLatin1String(DiffEditor::Constants::DIFF_EDITOR_MIMETYPE))
        document->setMimeType(QLatin1String(parameters->mimeType));
        return document;
    });

74
    setEditorWidgetCreator([=]() -> BaseTextEditorWidget* {
75
76
77
78
79
80
81
82
83
        auto widget = qobject_cast<VcsBaseEditorWidget *>(editorWidgetCreator());
        widget->setDescribeSlot(describeReceiver, describeSlot);
        widget->setParameters(parameters);
        return widget;
    });

    setEditorCreator([=]() {
        return new VcsBaseEditor(parameters);
    });
con's avatar
con committed
84
85
}

86
VcsBaseEditor *VcsEditorFactory::createEditorById(const char *id)
con's avatar
con committed
87
{
88
89
90
91
    auto factory =  ExtensionSystem::PluginManager::getObject<VcsEditorFactory>(
        [id](QObject *ob) { return ob->property("VcsEditorFactoryName").toByteArray() == id; });
    QTC_ASSERT(factory, return 0);
    return qobject_cast<VcsBaseEditor *>(factory->createEditor());
con's avatar
con committed
92
93
}

hjk's avatar
hjk committed
94
} // namespace VcsBase