forked from qt-creator/qt-creator
EmacsKeys: Hide plugin class in .cpp
Change-Id: I5b2bb608743fad30505898bbbf0699db84866c3c Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -2,7 +2,8 @@ add_qtc_plugin(EmacsKeys
|
||||
PLUGIN_DEPENDS Core TextEditor
|
||||
SOURCES
|
||||
emacskeysconstants.h
|
||||
emacskeysplugin.cpp emacskeysplugin.h
|
||||
emacskeysstate.cpp emacskeysstate.h
|
||||
emacskeysplugin.cpp
|
||||
emacskeysstate.cpp
|
||||
emacskeysstate.h
|
||||
emacskeystr.h
|
||||
)
|
||||
|
||||
@@ -11,7 +11,6 @@ QtcPlugin {
|
||||
files: [
|
||||
"emacskeysconstants.h",
|
||||
"emacskeysplugin.cpp",
|
||||
"emacskeysplugin.h",
|
||||
"emacskeysstate.cpp",
|
||||
"emacskeysstate.h",
|
||||
"emacskeystr.h",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
|
||||
#include <utils/id.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QPlainTextEdit;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core {
|
||||
class IEditor;
|
||||
}
|
||||
namespace TextEditor {
|
||||
class TextEditorWidget;
|
||||
}
|
||||
|
||||
namespace EmacsKeys {
|
||||
namespace Internal {
|
||||
|
||||
class EmacsKeysState;
|
||||
|
||||
class EmacsKeysPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "EmacsKeys.json")
|
||||
|
||||
public:
|
||||
EmacsKeysPlugin();
|
||||
~EmacsKeysPlugin() override;
|
||||
|
||||
void initialize() override;
|
||||
void extensionsInitialized() override;
|
||||
|
||||
private:
|
||||
void editorAboutToClose(Core::IEditor *editor);
|
||||
void currentEditorChanged(Core::IEditor *editor);
|
||||
|
||||
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(Utils::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;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace EmacsKeys
|
||||
Reference in New Issue
Block a user