2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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"
|
2016-01-22 11:48:22 +01:00
|
|
|
#include "basehoverhandler.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
|
2016-01-22 11:48:22 +01:00
|
|
|
addHoverHandler(new BaseHoverHandler);
|
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
|