Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
cf1bc696
Commit
cf1bc696
authored
Jul 26, 2022
by
Pablo Rauzy
Committed by
Christoph Cullmann
Aug 14, 2022
Browse files
[WIP] allow to record once run multiple time
parent
16eaade1
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/keyboardmacro/plugin_katekeyboardmacro.cpp
View file @
cf1bc696
...
...
@@ -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
(
"Capture
d
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
;
...
...
addons/keyboardmacro/plugin_katekeyboardmacro.h
View file @
cf1bc696
...
...
@@ -7,7 +7,7 @@
#define PLUGIN_KATEKEYBOARDMACRO_H
#include
<QKeyEvent>
#include
<Q
Queue
>
#include
<Q
List
>
#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
;
Q
Queue
<
QKeyEvent
*>
m_keyEvents
;
Q
List
<
QKeyEvent
*>
m_keyEvents
;
PluginKateKeyboardMacroRecordCommand
*
m_recCommand
;
PluginKateKeyboardMacroRunCommand
*
m_runCommand
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment