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
d141cf93
Commit
d141cf93
authored
Aug 03, 2022
by
Pablo Rauzy
Committed by
Christoph Cullmann
Aug 14, 2022
Browse files
new kmplay command to play a named keyboard macro without loading it
parent
a592691c
Changes
2
Hide whitespace changes
Inline
Side-by-side
addons/keyboardmacros/keyboardmacrosplugin.cpp
View file @
d141cf93
...
...
@@ -147,14 +147,20 @@ void KeyboardMacrosPlugin::cancel()
stop
(
false
);
}
bool
KeyboardMacrosPlugin
::
play
()
bool
KeyboardMacrosPlugin
::
play
(
QString
name
)
{
qDebug
()
<<
"[KeyboardMacrosPlugin] playing macro!"
;
if
(
m_macro
.
isEmpty
())
{
Macro
m
;
if
(
!
name
.
isEmpty
()
&&
m_namedMacros
.
contains
(
name
))
{
m
=
m_namedMacros
.
value
(
name
);
qDebug
()
<<
"[KeyboardMacrosPlugin] playing macro:"
<<
name
;
}
else
if
(
!
m_macro
.
isEmpty
())
{
m
=
m_macro
;
qDebug
()
<<
"[KeyboardMacrosPlugin] playing macro!"
;
}
else
{
return
false
;
}
Macro
::
Iterator
it
;
for
(
it
=
m
_macro
.
begin
();
it
!=
m
_macro
.
end
();
it
++
)
{
for
(
it
=
m
.
begin
();
it
!=
m
.
end
();
it
++
)
{
QKeyEvent
*
keyEvent
;
// send key press
keyEvent
=
(
*
it
).
keyPress
();
...
...
@@ -351,12 +357,13 @@ KeyboardMacrosPluginView::~KeyboardMacrosPluginView()
// BEGIN Plugin commands to manage named keyboard macros
KeyboardMacrosPluginCommands
::
KeyboardMacrosPluginCommands
(
KeyboardMacrosPlugin
*
plugin
)
:
KTextEditor
::
Command
(
QStringList
()
<<
QStringLiteral
(
"kmsave"
)
<<
QStringLiteral
(
"kmload"
)
<<
QStringLiteral
(
"kmremove"
),
plugin
)
:
KTextEditor
::
Command
(
QStringList
()
<<
QStringLiteral
(
"kmsave"
)
<<
QStringLiteral
(
"kmload"
)
<<
QStringLiteral
(
"kmremove"
)
<<
QStringLiteral
(
"kmplay"
),
plugin
)
,
m_plugin
(
plugin
)
{
}
bool
KeyboardMacrosPluginCommands
::
exec
(
KTextEditor
::
View
*
,
const
QString
&
cmd
,
QString
&
msg
,
const
KTextEditor
::
Range
&
)
bool
KeyboardMacrosPluginCommands
::
exec
(
KTextEditor
::
View
*
view
,
const
QString
&
cmd
,
QString
&
msg
,
const
KTextEditor
::
Range
&
)
{
QStringList
actionAndName
=
cmd
.
split
(
QRegExp
(
QStringLiteral
(
"
\\
s+"
)));
if
(
actionAndName
.
length
()
!=
2
)
{
...
...
@@ -383,6 +390,15 @@ bool KeyboardMacrosPluginCommands::exec(KTextEditor::View *, const QString &cmd,
return
false
;
}
return
true
;
}
else
if
(
action
==
QStringLiteral
(
"kmplay"
))
{
// set focus on the view otherwise the macro is played with focus on the command line
view
->
setFocus
();
// then attempt to play the given macro
if
(
!
m_plugin
->
play
(
name
))
{
msg
=
i18n
(
"No keyboard macro named '%1' found."
,
name
);
return
false
;
}
return
true
;
}
return
false
;
}
...
...
@@ -398,6 +414,9 @@ bool KeyboardMacrosPluginCommands::help(KTextEditor::View *, const QString &cmd,
}
else
if
(
cmd
==
QStringLiteral
(
"kmremove"
))
{
msg
=
i18n
(
"<qt><p>Usage: <code>kmremove <name></code></p><p>Remove saved keyboard macro <code><name></code>.</p></qt>"
);
return
true
;
}
else
if
(
cmd
==
QStringLiteral
(
"kmplay"
))
{
msg
=
i18n
(
"<qt><p>Usage: <code>kmplay <name></code></p><p>Play saved keyboard macro <code><name></code> without loading it.</p></qt>"
);
return
true
;
}
return
false
;
}
...
...
addons/keyboardmacros/keyboardmacrosplugin.h
View file @
d141cf93
...
...
@@ -60,7 +60,7 @@ private:
void
record
();
void
stop
(
bool
save
);
void
cancel
();
bool
play
();
bool
play
(
QString
name
=
QString
()
);
bool
save
(
QString
name
);
bool
load
(
QString
name
);
...
...
@@ -108,7 +108,7 @@ class KeyboardMacrosPluginCommands : public KTextEditor::Command
public:
KeyboardMacrosPluginCommands
(
KeyboardMacrosPlugin
*
plugin
);
bool
exec
(
KTextEditor
::
View
*
,
const
QString
&
cmd
,
QString
&
msg
,
const
KTextEditor
::
Range
&
=
KTextEditor
::
Range
::
invalid
())
override
;
bool
exec
(
KTextEditor
::
View
*
view
,
const
QString
&
cmd
,
QString
&
msg
,
const
KTextEditor
::
Range
&
=
KTextEditor
::
Range
::
invalid
())
override
;
bool
help
(
KTextEditor
::
View
*
,
const
QString
&
cmd
,
QString
&
msg
)
override
;
private:
...
...
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