1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "plaintexteditor.h"
34 #include "plaintexteditorfactory.h"
35 #include "texteditorconstants.h"
36 #include "texteditorplugin.h"
37 #include "texteditoractionhandler.h"
38 #include "texteditorsettings.h"
40 #include "highlightersettings.h"
42 #include <coreplugin/coreconstants.h>
43 #include <coreplugin/editormanager/editormanager.h>
45 #include <QtCore/QDebug>
47 using namespace TextEditor;
48 using namespace TextEditor::Internal;
50 PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
51 : Core::IEditorFactory(parent)
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);
60 connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
61 this, SLOT(updateEditorInfoBar(Core::IEditor*)));
64 PlainTextEditorFactory::~PlainTextEditorFactory()
66 delete m_actionHandler;
69 QString PlainTextEditorFactory::id() const
71 return QLatin1String(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
74 QString PlainTextEditorFactory::displayName() const
76 return tr(Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME);
79 Core::IFile *PlainTextEditorFactory::open(const QString &fileName)
81 Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
82 return iface ? iface->file() : 0;
85 Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent)
87 PlainTextEditorWidget *rc = new PlainTextEditorWidget(parent);
88 TextEditorPlugin::instance()->initializeEditor(rc);
89 connect(rc, SIGNAL(configured(Core::IEditor*)),
90 this, SLOT(updateEditorInfoBar(Core::IEditor*)));
94 void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
96 PlainTextEditor *editorEditable = qobject_cast<PlainTextEditor *>(editor);
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"),
108 SLOT(acceptMissingSyntaxDefinitionInfo()),
109 SLOT(ignoreMissingSyntaxDefinitionInfo()));
113 Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_SYNTAX_DEFINITION);
116 void PlainTextEditorFactory::addMimeType(const QString &type)
118 m_mimeTypes.append(type);
121 QStringList PlainTextEditorFactory::mimeTypes() const