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
03900b7e
Commit
03900b7e
authored
Aug 01, 2022
by
Pablo Rauzy
Committed by
Christoph Cullmann
Aug 14, 2022
Browse files
better macro storage
parent
7821e7ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/keyboardmacros/keyboardmacrosplugin.cpp
View file @
03900b7e
...
...
@@ -31,10 +31,6 @@ KeyboardMacrosPlugin::KeyboardMacrosPlugin(QObject *parent, const QList<QVariant
KeyboardMacrosPlugin
::~
KeyboardMacrosPlugin
()
{
qDeleteAll
(
m_tape
.
begin
(),
m_tape
.
end
());
m_tape
.
clear
();
qDeleteAll
(
m_macro
.
begin
(),
m_macro
.
end
());
m_macro
.
clear
();
}
QObject
*
KeyboardMacrosPlugin
::
createView
(
KTextEditor
::
MainWindow
*
mainWindow
)
...
...
@@ -77,8 +73,7 @@ bool KeyboardMacrosPlugin::eventFilter(QObject *obj, QEvent *event)
return
false
;
}
// otherwise we add the keyboard event to the macro
m_tape
.
append
(
new
QKeyEvent
(
QEvent
::
KeyPress
,
keyEvent
->
key
(),
keyEvent
->
modifiers
(),
keyEvent
->
text
()));
m_tape
.
append
(
new
QKeyEvent
(
QEvent
::
KeyRelease
,
keyEvent
->
key
(),
keyEvent
->
modifiers
(),
keyEvent
->
text
()));
m_tape
.
append
(
KeyCombination
(
keyEvent
));
return
false
;
}
else
{
return
QObject
::
eventFilter
(
obj
,
event
);
...
...
@@ -108,7 +103,6 @@ void KeyboardMacrosPlugin::stop(bool save)
m_recording
=
false
;
if
(
save
)
{
// delete current macro
qDeleteAll
(
m_macro
.
begin
(),
m_macro
.
end
());
m_macro
.
clear
();
// replace it with the tape
m_macro
.
swap
(
m_tape
);
...
...
@@ -117,7 +111,6 @@ void KeyboardMacrosPlugin::stop(bool save)
m_playAction
->
setEnabled
(
!
m_macro
.
isEmpty
());
}
else
{
// cancel
// delete tape
qDeleteAll
(
m_tape
.
begin
(),
m_tape
.
end
());
m_tape
.
clear
();
}
m_recordAction
->
setText
(
i18n
(
"&Record Macro..."
));
...
...
@@ -134,10 +127,15 @@ bool KeyboardMacrosPlugin::play()
if
(
m_macro
.
isEmpty
())
{
return
false
;
}
QKeyEvent
*
keyEvent
;
Macro
::
Iterator
it
;
for
(
it
=
m_macro
.
begin
();
it
!=
m_macro
.
end
();
it
++
)
{
QKeyEvent
*
keyEvent
=
*
it
;
keyEvent
=
(
*
it
).
keyPress
()
;
qApp
->
sendEvent
(
qApp
->
focusWidget
(),
keyEvent
);
delete
keyEvent
;
keyEvent
=
(
*
it
).
keyRelease
();
qApp
->
sendEvent
(
qApp
->
focusWidget
(),
keyEvent
);
delete
keyEvent
;
}
return
true
;
}
...
...
addons/keyboardmacros/keyboardmacrosplugin.h
View file @
03900b7e
...
...
@@ -15,7 +15,29 @@
#include
<KTextEditor/Plugin>
#include
<KTextEditor/View>
typedef
QList
<
QKeyEvent
*>
Macro
;
class
KeyCombination
{
private:
int
key
;
Qt
::
KeyboardModifiers
modifiers
;
QString
text
;
public:
KeyCombination
(
QKeyEvent
*
keyEvent
)
:
key
(
keyEvent
->
key
())
,
modifiers
(
keyEvent
->
modifiers
())
,
text
(
keyEvent
->
text
()){};
QKeyEvent
*
keyPress
()
{
return
new
QKeyEvent
(
QEvent
::
KeyPress
,
key
,
modifiers
,
text
);
};
QKeyEvent
*
keyRelease
()
{
return
new
QKeyEvent
(
QEvent
::
KeyRelease
,
key
,
modifiers
,
text
);
};
};
typedef
QList
<
KeyCombination
>
Macro
;
class
KeyboardMacrosPlugin
:
public
KTextEditor
::
Plugin
{
...
...
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