EmacsKeys: Hide plugin class in .cpp

Change-Id: I5b2bb608743fad30505898bbbf0699db84866c3c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-15 10:31:21 +01:00
parent 02be4ac613
commit 4434b09d49
4 changed files with 56 additions and 104 deletions

View File

@@ -1,8 +1,6 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "emacskeysplugin.h"
#include "emacskeysconstants.h"
#include "emacskeysstate.h"
#include "emacskeystr.h"
@@ -13,16 +11,21 @@
#include <coreplugin/icontext.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/iplugin.h>
#include <utils/qtcassert.h>
#include <texteditor/texteditor.h>
#include <texteditor/textdocument.h>
#include <QAction>
#include <QPlainTextEdit>
#include <QApplication>
#include <QClipboard>
#include <QPlainTextEdit>
#include <QScrollBar>
#include <QTextCursor>
QT_BEGIN_NAMESPACE
extern void qt_set_sequence_auto_mnemonic(bool enable);
@@ -31,24 +34,58 @@ QT_END_NAMESPACE
using namespace Core;
using namespace Utils;
namespace {
QString plainSelectedText(const QTextCursor &cursor)
namespace EmacsKeys::Internal {
static QString plainSelectedText(const QTextCursor &cursor)
{
// selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline
return cursor.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n'));
}
}
namespace EmacsKeys {
namespace Internal {
class EmacsKeysPlugin final : public ExtensionSystem::IPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "EmacsKeys.json")
//---------------------------------------------------------------------------
// EmacsKeysPlugin
//---------------------------------------------------------------------------
void initialize() final;
EmacsKeysPlugin::EmacsKeysPlugin() = default;
void editorAboutToClose(Core::IEditor *editor);
void currentEditorChanged(Core::IEditor *editor);
EmacsKeysPlugin::~EmacsKeysPlugin() = default;
void deleteCharacter(); // C-d
void killWord(); // M-d
void killLine(); // C-k
void insertLineAndIndent(); // C-j
void gotoFileStart(); // M-<
void gotoFileEnd(); // M->
void gotoLineStart(); // C-a
void gotoLineEnd(); // C-e
void gotoNextLine(); // C-n
void gotoPreviousLine(); // C-p
void gotoNextCharacter(); // C-f
void gotoPreviousCharacter(); // C-b
void gotoNextWord(); // M-f
void gotoPreviousWord(); // M-b
void mark(); // C-SPC
void exchangeCursorAndMark(); // C-x C-x
void copy(); // M-w
void cut(); // C-w
void yank(); // C-y
void scrollHalfDown(); // C-v
void scrollHalfUp(); // M-v
QAction *registerAction(Id id, void (EmacsKeysPlugin::*callback)(), const QString &title);
void genericGoto(QTextCursor::MoveOperation op, bool abortAssist = true);
void genericVScroll(int direction);
QHash<QPlainTextEdit *, EmacsKeysState *> m_stateMap;
QPlainTextEdit *m_currentEditorWidget = nullptr;
EmacsKeysState *m_currentState = nullptr;
TextEditor::TextEditorWidget *m_currentBaseTextEditorWidget = nullptr;
};
void EmacsKeysPlugin::initialize()
{
@@ -110,10 +147,6 @@ void EmacsKeysPlugin::initialize()
&EmacsKeysPlugin::scrollHalfUp, Tr::tr("Scroll Half Screen Up"));
}
void EmacsKeysPlugin::extensionsInitialized()
{
}
void EmacsKeysPlugin::editorAboutToClose(IEditor *editor)
{
auto w = qobject_cast<QPlainTextEdit*>(editor->widget());
@@ -353,5 +386,6 @@ void EmacsKeysPlugin::genericVScroll(int direction)
m_currentState->endOwnAction(KeysActionOther);
}
} // namespace Internal
} // namespace EmacsKeys
} // EmacsKeys::Internal
#include "emacskeysplugin.moc"