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

[WIP] allow to record once run multiple time

parent 16eaade1
......@@ -7,7 +7,10 @@
#include <QAction>
#include <QCoreApplication>
#include <QKeyEvent>
#include <QList>
#include <QString>
#include <QtAlgorithms>
#include <KTextEditor/Editor>
#include <KTextEditor/Message>
......@@ -34,6 +37,7 @@ PluginKateKeyboardMacro::~PluginKateKeyboardMacro()
{
delete m_recCommand;
delete m_runCommand;
reset();
}
QObject *PluginKateKeyboardMacro::createView(KTextEditor::MainWindow *mainWindow)
......@@ -54,14 +58,20 @@ bool PluginKateKeyboardMacro::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = new QKeyEvent(*static_cast<QKeyEvent *>(event));
m_keyEvents.enqueue(keyEvent);
qDebug("Capture key press: %s", keyEvent->text().toUtf8().data());
m_keyEvents.append(keyEvent);
qDebug("Captured key press: %s", keyEvent->text().toUtf8().data());
return true;
} else {
return QObject::eventFilter(obj, event);
}
}
void PluginKateKeyboardMacro::reset()
{
qDeleteAll(m_keyEvents.begin(), m_keyEvents.end());
m_keyEvents.clear();
}
bool PluginKateKeyboardMacro::record(KTextEditor::View *)
{
if (m_recording) { // end recording
......@@ -72,7 +82,10 @@ bool PluginKateKeyboardMacro::record(KTextEditor::View *)
return true; // if success
}
// start recording
// first reset ...
reset();
// ... then start recording
std::cerr << "start recording" << std::endl;
QCoreApplication::instance()->installEventFilter(this);
m_recording = true;
......@@ -86,11 +99,12 @@ bool PluginKateKeyboardMacro::run(KTextEditor::View *view)
record(view);
}
while (!m_keyEvents.isEmpty()) {
QKeyEvent *keyEvent = m_keyEvents.dequeue();
qDebug("Emit key press: %s", keyEvent->text().toUtf8().data());
QCoreApplication::sendEvent(QCoreApplication::instance(), keyEvent);
delete keyEvent;
if (!m_keyEvents.isEmpty()) {
QList<QKeyEvent *>::ConstIterator keyEvent;
for (keyEvent = m_keyEvents.constBegin(); keyEvent != m_keyEvents.constEnd(); keyEvent++) {
qDebug("Emitting key press: %s", (*keyEvent)->text().toUtf8().data());
QCoreApplication::sendEvent(QCoreApplication::instance(), *keyEvent);
}
}
return true;
......
......@@ -7,7 +7,7 @@
#define PLUGIN_KATEKEYBOARDMACRO_H
#include <QKeyEvent>
#include <QQueue>
#include <QList>
#include <KTextEditor/Application>
#include <KTextEditor/Command>
......@@ -31,6 +31,7 @@ public:
bool eventFilter(QObject *obj, QEvent *event) override;
void reset();
bool record(KTextEditor::View *view);
bool run(KTextEditor::View *view);
bool isRecording();
......@@ -39,7 +40,7 @@ private:
KTextEditor::MainWindow *m_mainWindow;
bool m_recording = false;
QQueue<QKeyEvent *> m_keyEvents;
QList<QKeyEvent *> m_keyEvents;
PluginKateKeyboardMacroRecordCommand *m_recCommand;
PluginKateKeyboardMacroRunCommand *m_runCommand;
......
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