Commit 6bb0e485 authored by Pablo Rauzy's avatar Pablo Rauzy Committed by Christoph Cullmann
Browse files

[WIP] renaming plugin to Keyboard Macros (plural)

parent 7963a630
......@@ -33,4 +33,4 @@ ecm_optional_add_subdirectory(textfilter) # Pipe text through some external comm
ecm_optional_add_subdirectory(xmlcheck) # XML Validation plugin
ecm_optional_add_subdirectory(xmltools) # XML completion
ecm_optional_add_subdirectory(cmake-tools)
ecm_optional_add_subdirectory(keyboardmacro)
ecm_optional_add_subdirectory(keyboardmacros)
kate_add_plugin(keyboardmacroplugin)
target_compile_definitions(keyboardmacroplugin PRIVATE TRANSLATION_DOMAIN="katekeyboardmacro")
target_link_libraries(keyboardmacroplugin PRIVATE KF5::I18n KF5::TextEditor)
target_sources(
keyboardmacroplugin
PRIVATE
plugin_katekeyboardmacro.cpp
plugin.qrc
)
kate_add_plugin(keyboardmacrosplugin)
target_compile_definitions(keyboardmacrosplugin PRIVATE TRANSLATION_DOMAIN="katekeyboardmacros")
target_link_libraries(keyboardmacrosplugin PRIVATE KF5::I18n KF5::TextEditor)
target_sources(
keyboardmacrosplugin
PRIVATE
keyboardmacrosplugin.cpp
plugin.qrc
)
#! /bin/sh
$EXTRACTRC *.rc *.ui >> rc.cpp
$XGETTEXT *.cpp -o $podir/katekeyboardmacro.pot
$XGETTEXT *.cpp -o $podir/katekeyboardmacros.pot
......@@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "plugin_katekeyboardmacro.h"
#include "keyboardmacrosplugin.h"
#include <QAction>
#include <QCoreApplication>
......@@ -15,35 +15,35 @@
#include <KTextEditor/Editor>
#include <KTextEditor/Message>
#include <KLocalizedString>
#include <KActionCollection>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KXMLGUIFactory>
#include <iostream>
#include <qevent.h>
K_PLUGIN_FACTORY_WITH_JSON(KeyboardMacroPluginFactory, "keyboardmacroplugin.json", registerPlugin<PluginKateKeyboardMacro>();)
K_PLUGIN_FACTORY_WITH_JSON(KeyboardMacrosPluginFactory, "keyboardmacrosplugin.json", registerPlugin<KeyboardMacrosPlugin>();)
PluginKateKeyboardMacro::PluginKateKeyboardMacro(QObject *parent, const QList<QVariant> &)
KeyboardMacrosPlugin::KeyboardMacrosPlugin(QObject *parent, const QList<QVariant> &)
: KTextEditor::Plugin(parent)
{
// register "recmac" and "runmac" commands
m_recCommand = new PluginKateKeyboardMacroRecordCommand(this);
m_runCommand = new PluginKateKeyboardMacroRunCommand(this);
m_recCommand = new KeyboardMacrosPluginRecordCommand(this);
m_runCommand = new KeyboardMacrosPluginRunCommand(this);
}
PluginKateKeyboardMacro::~PluginKateKeyboardMacro()
KeyboardMacrosPlugin::~KeyboardMacrosPlugin()
{
delete m_recCommand;
delete m_runCommand;
reset();
}
QObject *PluginKateKeyboardMacro::createView(KTextEditor::MainWindow *mainWindow)
QObject *KeyboardMacrosPlugin::createView(KTextEditor::MainWindow *mainWindow)
{
m_mainWindow = mainWindow;
return new PluginViewKateKeyboardMacro(this, mainWindow);
return new KeyboardMacrosPluginView(this, mainWindow);
}
// https://doc.qt.io/qt-6/eventsandfilters.html
......@@ -54,7 +54,7 @@ QObject *PluginKateKeyboardMacro::createView(KTextEditor::MainWindow *mainWindow
// file:///usr/share/qt5/doc/qtcore/qcoreapplication.html#sendEvent
// also see postEvent, sendPostedEvents, etc
bool PluginKateKeyboardMacro::eventFilter(QObject *obj, QEvent *event)
bool KeyboardMacrosPlugin::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = new QKeyEvent(*static_cast<QKeyEvent *>(event));
......@@ -69,13 +69,13 @@ bool PluginKateKeyboardMacro::eventFilter(QObject *obj, QEvent *event)
}
}
void PluginKateKeyboardMacro::reset()
void KeyboardMacrosPlugin::reset()
{
qDeleteAll(m_keyEvents.begin(), m_keyEvents.end());
m_keyEvents.clear();
}
bool PluginKateKeyboardMacro::record(KTextEditor::View *)
bool KeyboardMacrosPlugin::record(KTextEditor::View *)
{
if (m_recording) { // end recording
// KTextEditor::Editor::instance()->application()->activeMainWindow()->window()->removeEventFilter(this);
......@@ -99,7 +99,7 @@ bool PluginKateKeyboardMacro::record(KTextEditor::View *)
return true;
}
bool PluginKateKeyboardMacro::run(KTextEditor::View *view)
bool KeyboardMacrosPlugin::run(KTextEditor::View *view)
{
if (m_recording) {
// end recording before running macro
......@@ -118,12 +118,12 @@ bool PluginKateKeyboardMacro::run(KTextEditor::View *view)
return true;
}
bool PluginKateKeyboardMacro::isRecording()
bool KeyboardMacrosPlugin::isRecording()
{
return m_recording;
}
void PluginKateKeyboardMacro::slotRecord()
void KeyboardMacrosPlugin::slotRecord()
{
if (!KTextEditor::Editor::instance()->application()->activeMainWindow()) {
return;
......@@ -137,7 +137,7 @@ void PluginKateKeyboardMacro::slotRecord()
record(view);
}
void PluginKateKeyboardMacro::slotRun()
void KeyboardMacrosPlugin::slotRun()
{
if (!KTextEditor::Editor::instance()->application()->activeMainWindow()) {
return;
......@@ -153,25 +153,25 @@ void PluginKateKeyboardMacro::slotRun()
// BEGIN Plugin view to add our actions to the gui
PluginViewKateKeyboardMacro::PluginViewKateKeyboardMacro(PluginKateKeyboardMacro *plugin, KTextEditor::MainWindow *mainwindow)
KeyboardMacrosPluginView::KeyboardMacrosPluginView(KeyboardMacrosPlugin *plugin, KTextEditor::MainWindow *mainwindow)
: QObject(mainwindow)
, m_mainWindow(mainwindow)
{
// setup xml gui
KXMLGUIClient::setComponentName(QStringLiteral("keyboardmacro"), i18n("Keyboard Macro"));
KXMLGUIClient::setComponentName(QStringLiteral("keyboardmacros"), i18n("Keyboard Macros"));
setXMLFile(QStringLiteral("ui.rc"));
// create record action
QAction *rec = actionCollection()->addAction(QStringLiteral("record_macro"));
rec->setText(i18n("Record &Macro..."));
actionCollection()->setDefaultShortcut(rec, Qt::CTRL | Qt::SHIFT | Qt::Key_K);
connect(rec, &QAction::triggered, plugin, &PluginKateKeyboardMacro::slotRecord);
connect(rec, &QAction::triggered, plugin, &KeyboardMacrosPlugin::slotRecord);
// create run action
QAction *run = actionCollection()->addAction(QStringLiteral("run_macro"));
run->setText(i18n("&Run Macro"));
actionCollection()->setDefaultShortcut(run, Qt::CTRL | Qt::ALT | Qt::Key_K);
connect(run, &QAction::triggered, plugin, &PluginKateKeyboardMacro::slotRun);
connect(run, &QAction::triggered, plugin, &KeyboardMacrosPlugin::slotRun);
// TODO: make an entire "Keyboard Macros" submenu with "record", "run", "save as", "run saved"
......@@ -179,7 +179,7 @@ PluginViewKateKeyboardMacro::PluginViewKateKeyboardMacro(PluginKateKeyboardMacro
mainwindow->guiFactory()->addClient(this);
}
PluginViewKateKeyboardMacro::~PluginViewKateKeyboardMacro()
KeyboardMacrosPluginView::~KeyboardMacrosPluginView()
{
// remove us from the gui
m_mainWindow->guiFactory()->removeClient(this);
......@@ -189,13 +189,13 @@ PluginViewKateKeyboardMacro::~PluginViewKateKeyboardMacro()
// BEGIN commands
PluginKateKeyboardMacroRecordCommand::PluginKateKeyboardMacroRecordCommand(PluginKateKeyboardMacro *plugin)
KeyboardMacrosPluginRecordCommand::KeyboardMacrosPluginRecordCommand(KeyboardMacrosPlugin *plugin)
: KTextEditor::Command(QStringList() << QStringLiteral("recmac"), plugin)
, m_plugin(plugin)
{
}
bool PluginKateKeyboardMacroRecordCommand::exec(KTextEditor::View *view, const QString &, QString &, const KTextEditor::Range &)
bool KeyboardMacrosPluginRecordCommand::exec(KTextEditor::View *view, const QString &, QString &, const KTextEditor::Range &)
{
if (m_plugin->isRecording()) {
// remove from the recording the call to this command…
......@@ -206,19 +206,19 @@ bool PluginKateKeyboardMacroRecordCommand::exec(KTextEditor::View *view, const Q
return true;
}
bool PluginKateKeyboardMacroRecordCommand::help(KTextEditor::View *, const QString &, QString &msg)
bool KeyboardMacrosPluginRecordCommand::help(KTextEditor::View *, const QString &, QString &msg)
{
msg = i18n("<qt><p>Usage: <code>recmac</code></p><p>Start/stop recording a keyboard macro.</p></qt>");
return true;
}
PluginKateKeyboardMacroRunCommand::PluginKateKeyboardMacroRunCommand(PluginKateKeyboardMacro *plugin)
KeyboardMacrosPluginRunCommand::KeyboardMacrosPluginRunCommand(KeyboardMacrosPlugin *plugin)
: KTextEditor::Command(QStringList() << QStringLiteral("runmac"), plugin)
, m_plugin(plugin)
{
}
bool PluginKateKeyboardMacroRunCommand::exec(KTextEditor::View *view, const QString &, QString &, const KTextEditor::Range &)
bool KeyboardMacrosPluginRunCommand::exec(KTextEditor::View *view, const QString &, QString &, const KTextEditor::Range &)
{
if (!m_plugin->run(view)) {
// display fail in toolview
......@@ -227,7 +227,7 @@ bool PluginKateKeyboardMacroRunCommand::exec(KTextEditor::View *view, const QStr
// TODO: allow the command to take a name as an argument to run a saved macro (default to the last recorded one)
}
bool PluginKateKeyboardMacroRunCommand::help(KTextEditor::View *, const QString &, QString &msg)
bool KeyboardMacrosPluginRunCommand::help(KTextEditor::View *, const QString &, QString &msg)
{
msg = i18n("<qt><p>Usage: <code>runmac</code></p><p>Run recorded keyboard macro.</p></qt>");
return true;
......@@ -237,5 +237,5 @@ bool PluginKateKeyboardMacroRunCommand::help(KTextEditor::View *, const QString
// END
// required for KeyboardMacroPluginFactory vtable
#include "plugin_katekeyboardmacro.moc"
// required for KeyboardMacrosPluginFactory vtable
#include "keyboardmacrosplugin.moc"
......@@ -15,17 +15,17 @@
#include <KTextEditor/Plugin>
#include <KTextEditor/View>
class PluginKateKeyboardMacroRecordCommand;
class PluginKateKeyboardMacroRunCommand;
class KeyboardMacrosPluginRecordCommand;
class KeyboardMacrosPluginRunCommand;
class PluginKateKeyboardMacro : public KTextEditor::Plugin
class KeyboardMacrosPlugin : public KTextEditor::Plugin
{
Q_OBJECT
public:
explicit PluginKateKeyboardMacro(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
explicit KeyboardMacrosPlugin(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
~PluginKateKeyboardMacro() override;
~KeyboardMacrosPlugin() override;
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
......@@ -42,8 +42,8 @@ private:
bool m_recording = false;
QList<QKeyEvent *> m_keyEvents;
PluginKateKeyboardMacroRecordCommand *m_recCommand;
PluginKateKeyboardMacroRunCommand *m_runCommand;
KeyboardMacrosPluginRecordCommand *m_recCommand;
KeyboardMacrosPluginRunCommand *m_runCommand;
public Q_SLOTS:
void slotRecord();
......@@ -53,13 +53,13 @@ public Q_SLOTS:
/**
* Plugin view to add our actions to the gui
*/
class PluginViewKateKeyboardMacro : public QObject, public KXMLGUIClient
class KeyboardMacrosPluginView : public QObject, public KXMLGUIClient
{
Q_OBJECT
public:
explicit PluginViewKateKeyboardMacro(PluginKateKeyboardMacro *plugin, KTextEditor::MainWindow *mainwindow);
~PluginViewKateKeyboardMacro() override;
explicit KeyboardMacrosPluginView(KeyboardMacrosPlugin *plugin, KTextEditor::MainWindow *mainwindow);
~KeyboardMacrosPluginView() override;
private:
KTextEditor::MainWindow *m_mainWindow;
......@@ -68,33 +68,33 @@ private:
/**
* recmac command
*/
class PluginKateKeyboardMacroRecordCommand : public KTextEditor::Command
class KeyboardMacrosPluginRecordCommand : public KTextEditor::Command
{
Q_OBJECT
public:
PluginKateKeyboardMacroRecordCommand(PluginKateKeyboardMacro *plugin);
KeyboardMacrosPluginRecordCommand(KeyboardMacrosPlugin *plugin);
bool exec(KTextEditor::View *view, const QString &, QString &, const KTextEditor::Range & = KTextEditor::Range::invalid()) override;
bool help(KTextEditor::View *view, const QString &, QString &msg) override;
private:
PluginKateKeyboardMacro *m_plugin;
KeyboardMacrosPlugin *m_plugin;
};
/**
* runmac command
*/
class PluginKateKeyboardMacroRunCommand : public KTextEditor::Command
class KeyboardMacrosPluginRunCommand : public KTextEditor::Command
{
Q_OBJECT
public:
PluginKateKeyboardMacroRunCommand(PluginKateKeyboardMacro *plugin);
KeyboardMacrosPluginRunCommand(KeyboardMacrosPlugin *plugin);
bool exec(KTextEditor::View *view, const QString &, QString &, const KTextEditor::Range & = KTextEditor::Range::invalid()) override;
bool help(KTextEditor::View *view, const QString &, QString &msg) override;
private:
PluginKateKeyboardMacro *m_plugin;
KeyboardMacrosPlugin *m_plugin;
};
#endif
{
"KPlugin": {
"Description": "Record and run any keyboard action sequence",
"Name": "Keyboard Macro",
"Description": "Record and run keyboard action sequences",
"Name": "Keyboard Macros",
"ServiceTypes": [
"KTextEditor/Plugin"
]
......
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="/kxmlgui5/keyboardmacro">
<qresource prefix="/kxmlgui5/keyboardmacros">
<file>ui.rc</file>
</qresource>
</RCC>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="katekeyboardmacro" library="libkatekeyboardmacroplugin" version="5" translationDomain="katekeyboardmacro">
<gui name="keyboardmacrosplugin" library="libkeyboardmacrosplugin" version="5" translationDomain="katekeyboardmacros">
<MenuBar>
<Menu name="tools">
<text>&amp;Tools</text>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment