OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / texteditor / plaintexteditorfactory.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "plaintexteditor.h"
34 #include "plaintexteditorfactory.h"
35 #include "texteditorconstants.h"
36 #include "texteditorplugin.h"
37 #include "texteditoractionhandler.h"
38 #include "texteditorsettings.h"
39 #include "manager.h"
40 #include "highlightersettings.h"
41
42 #include <coreplugin/coreconstants.h>
43 #include <coreplugin/editormanager/editormanager.h>
44
45 #include <QtCore/QDebug>
46
47 using namespace TextEditor;
48 using namespace TextEditor::Internal;
49
50 PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
51   : Core::IEditorFactory(parent)
52 {
53     m_actionHandler = new TextEditorActionHandler(
54         TextEditor::Constants::C_TEXTEDITOR,
55         TextEditorActionHandler::Format |
56         TextEditorActionHandler::UnCommentSelection |
57         TextEditorActionHandler::UnCollapseAll);
58     m_mimeTypes << QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT);
59
60     connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
61             this, SLOT(updateEditorInfoBar(Core::IEditor*)));
62 }
63
64 PlainTextEditorFactory::~PlainTextEditorFactory()
65 {
66     delete m_actionHandler;
67 }
68
69 QString PlainTextEditorFactory::id() const
70 {
71     return QLatin1String(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
72 }
73
74 QString PlainTextEditorFactory::displayName() const
75 {
76     return tr(Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME);
77 }
78
79 Core::IFile *PlainTextEditorFactory::open(const QString &fileName)
80 {
81     Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
82     return iface ? iface->file() : 0;
83 }
84
85 Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent)
86 {
87     PlainTextEditorWidget *rc = new PlainTextEditorWidget(parent);
88     TextEditorPlugin::instance()->initializeEditor(rc);
89     connect(rc, SIGNAL(configured(Core::IEditor*)),
90             this, SLOT(updateEditorInfoBar(Core::IEditor*)));
91     return rc->editor();
92 }
93
94 void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
95 {
96     PlainTextEditor *editorEditable = qobject_cast<PlainTextEditor *>(editor);
97     if (editorEditable) {
98         PlainTextEditorWidget *textEditor = static_cast<PlainTextEditorWidget *>(editorEditable->editorWidget());
99         if (textEditor->isMissingSyntaxDefinition() &&
100             !textEditor->ignoreMissingSyntaxDefinition() &&
101             TextEditorSettings::instance()->highlighterSettings().alertWhenNoDefinition()) {
102             Core::EditorManager::instance()->showEditorInfoBar(
103                 Constants::INFO_SYNTAX_DEFINITION,
104                 tr("A highlight definition was not found for this file. "
105                    "Would you like to try to find one?"),
106                 tr("Show highlighter options"),
107                 textEditor,
108                 SLOT(acceptMissingSyntaxDefinitionInfo()),
109                 SLOT(ignoreMissingSyntaxDefinitionInfo()));
110             return;
111         }
112     }
113     Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_SYNTAX_DEFINITION);
114 }
115
116 void PlainTextEditorFactory::addMimeType(const QString &type)
117 {
118     m_mimeTypes.append(type);
119 }
120
121 QStringList PlainTextEditorFactory::mimeTypes() const
122 {
123     return m_mimeTypes;
124 }