2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "plaintexteditorfactory.h"
|
2013-03-12 12:06:15 +01:00
|
|
|
#include "plaintexteditor.h"
|
2011-05-20 11:27:07 +02:00
|
|
|
#include "basetextdocument.h"
|
2013-12-10 15:54:20 +01:00
|
|
|
#include "texteditoractionhandler.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "texteditorconstants.h"
|
|
|
|
#include "texteditorplugin.h"
|
2013-12-10 15:54:20 +01:00
|
|
|
#include "texteditorsettings.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2011-05-06 12:48:44 +02:00
|
|
|
#include <coreplugin/infobar.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-05-06 12:30:23 +04:00
|
|
|
#include <QCoreApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2010-05-28 14:37:25 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace TextEditor;
|
|
|
|
using namespace TextEditor::Internal;
|
|
|
|
|
2009-01-20 15:31:33 +01:00
|
|
|
PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
|
2010-01-07 18:17:24 +01:00
|
|
|
: Core::IEditorFactory(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-05-31 19:35:37 +02:00
|
|
|
setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
|
|
|
setDisplayName(qApp->translate("OpenWith::Editors", Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME));
|
|
|
|
addMimeType(QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
|
|
|
|
|
2013-12-10 17:13:21 +01:00
|
|
|
new TextEditorActionHandler(this,
|
2010-06-25 17:37:59 +02:00
|
|
|
TextEditor::Constants::C_TEXTEDITOR,
|
2010-05-20 13:56:11 +02:00
|
|
|
TextEditorActionHandler::Format |
|
2010-06-18 16:30:56 +02:00
|
|
|
TextEditorActionHandler::UnCommentSelection |
|
|
|
|
TextEditorActionHandler::UnCollapseAll);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2014-01-07 14:41:57 +01:00
|
|
|
Core::IEditor *PlainTextEditorFactory::createEditor()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-01-07 14:41:57 +01:00
|
|
|
PlainTextEditorWidget *rc = new PlainTextEditorWidget();
|
2013-12-10 15:54:20 +01:00
|
|
|
TextEditorSettings::initializeEditor(rc);
|
2010-09-20 11:47:01 +02:00
|
|
|
connect(rc, SIGNAL(configured(Core::IEditor*)),
|
|
|
|
this, SLOT(updateEditorInfoBar(Core::IEditor*)));
|
2011-05-06 12:48:44 +02:00
|
|
|
updateEditorInfoBar(rc->editor());
|
2011-02-21 16:02:26 +01:00
|
|
|
return rc->editor();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
2012-11-13 23:19:26 +02:00
|
|
|
/*!
|
|
|
|
* Test if syntax highlighter is available (or unneeded) for \a editor.
|
|
|
|
* If not found, show a warning with a link to the relevant settings page.
|
|
|
|
*/
|
2010-05-28 14:37:25 +02:00
|
|
|
void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
|
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
PlainTextEditor *editorEditable = qobject_cast<PlainTextEditor *>(editor);
|
2010-05-28 14:37:25 +02:00
|
|
|
if (editorEditable) {
|
2012-02-14 16:43:51 +01:00
|
|
|
BaseTextDocument *file = qobject_cast<BaseTextDocument *>(editor->document());
|
2011-05-20 11:27:07 +02:00
|
|
|
if (!file)
|
|
|
|
return;
|
2011-02-21 16:02:26 +01:00
|
|
|
PlainTextEditorWidget *textEditor = static_cast<PlainTextEditorWidget *>(editorEditable->editorWidget());
|
2012-11-08 21:12:56 +02:00
|
|
|
Core::Id infoSyntaxDefinition(Constants::INFO_SYNTAX_DEFINITION);
|
2012-11-13 23:19:26 +02:00
|
|
|
Core::InfoBar *infoBar = file->infoBar();
|
|
|
|
if (!textEditor->isMissingSyntaxDefinition()) {
|
|
|
|
infoBar->removeInfo(infoSyntaxDefinition);
|
|
|
|
} else if (infoBar->canInfoBeAdded(infoSyntaxDefinition)) {
|
2012-01-05 11:05:28 +01:00
|
|
|
Core::InfoBarEntry info(infoSyntaxDefinition,
|
2011-05-06 12:48:44 +02:00
|
|
|
tr("A highlight definition was not found for this file. "
|
2012-11-13 23:19:26 +02:00
|
|
|
"Would you like to try to find one?"),
|
|
|
|
Core::InfoBarEntry::GlobalSuppressionEnabled);
|
2011-10-05 20:13:49 +02:00
|
|
|
info.setCustomButtonInfo(tr("Show highlighter options..."),
|
2011-05-06 12:48:44 +02:00
|
|
|
textEditor, SLOT(acceptMissingSyntaxDefinitionInfo()));
|
2012-11-13 23:19:26 +02:00
|
|
|
infoBar->addInfo(info);
|
2010-05-28 14:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|