2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "plaintexteditorfactory.h"
|
2020-02-28 13:17:08 +01:00
|
|
|
#include "basehoverhandler.h"
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "textdocument.h"
|
2020-02-28 13:17:08 +01:00
|
|
|
#include "texteditor.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"
|
2020-02-28 13:17:08 +01:00
|
|
|
#include "textindenter.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
2020-06-17 12:23:44 +02:00
|
|
|
#include <utils/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
|
|
|
|
2018-09-20 01:16:01 +03:00
|
|
|
static PlainTextEditorFactory *m_instance = nullptr;
|
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:
|
2018-11-25 18:52:41 +01:00
|
|
|
PlainTextEditorWidget() = default;
|
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);
|
2017-04-24 17:01:10 +02:00
|
|
|
setDisplayName(QCoreApplication::translate("OpenWith::Editors", Core::Constants::K_DEFAULT_TEXT_EDITOR_DISPLAY_NAME));
|
2013-05-31 19:35:37 +02:00
|
|
|
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; });
|
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 |
|
2018-07-13 12:33:46 +02:00
|
|
|
TextEditorActionHandler::UnCommentSelection |
|
|
|
|
|
TextEditorActionHandler::UnCollapseAll |
|
|
|
|
|
TextEditorActionHandler::FollowSymbolUnderCursor);
|
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
|