2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/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
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company 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"
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "texteditor.h"
|
|
|
|
|
#include "textdocument.h"
|
2014-07-30 10:41:06 +02:00
|
|
|
#include "normalindenter.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>
|
2014-08-22 19:14:48 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-05-06 12:30:23 +04:00
|
|
|
#include <QCoreApplication>
|
2010-05-28 14:37:25 +02:00
|
|
|
|
2014-08-22 19:14:48 +02:00
|
|
|
namespace TextEditor {
|
2014-08-27 11:19:04 +02:00
|
|
|
|
|
|
|
|
static PlainTextEditorFactory *m_instance = 0;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
class PlainTextEditorWidget : public TextEditorWidget
|
2014-08-22 19:14:48 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PlainTextEditorWidget() {}
|
2015-06-01 17:55:31 +02:00
|
|
|
void finalizeInitialization() override
|
2015-02-03 09:18:57 +01:00
|
|
|
{
|
|
|
|
|
textDocument()->setMimeType(QLatin1String(Constants::C_TEXTEDITOR_MIMETYPE_TEXT));
|
|
|
|
|
}
|
2014-08-22 19:14:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PlainTextEditorFactory::PlainTextEditorFactory()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-08-27 11:19:04 +02:00
|
|
|
QTC_CHECK(!m_instance);
|
|
|
|
|
m_instance = this;
|
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));
|
2015-04-24 10:53:21 +02:00
|
|
|
addMimeType(QLatin1String("text/css")); // for some reason freedesktop thinks css is text/x-csrc
|
2013-05-31 19:35:37 +02:00
|
|
|
|
2014-09-22 18:43:31 +02:00
|
|
|
setDocumentCreator([]() { return new TextDocument(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); });
|
2014-08-22 19:14:48 +02:00
|
|
|
setEditorWidgetCreator([]() { return new PlainTextEditorWidget; });
|
|
|
|
|
setIndenterCreator([]() { return new NormalIndenter; });
|
2015-02-03 09:18:57 +01:00
|
|
|
setUseGenericHighlighter(true);
|
2014-08-22 19:14:48 +02:00
|
|
|
|
2014-09-02 12:25:20 +02:00
|
|
|
setEditorActionHandlers(TextEditorActionHandler::Format |
|
2010-06-18 16:30:56 +02:00
|
|
|
TextEditorActionHandler::UnCommentSelection |
|
|
|
|
|
TextEditorActionHandler::UnCollapseAll);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-27 11:19:04 +02:00
|
|
|
PlainTextEditorFactory *PlainTextEditorFactory::instance()
|
|
|
|
|
{
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseTextEditor *PlainTextEditorFactory::createPlainTextEditor()
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<BaseTextEditor *>(m_instance->createEditor());
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-22 19:14:48 +02:00
|
|
|
} // namespace TextEditor
|