Add keyboard shortcut in plugin

Stefan Ziegler <[email protected]> Mon, 28 Jul 2025 16:00:44 +0200
Newsgroups gmane.editors.jedit.user
Message-ID <CAJvo+1-7WpF_qyybs7CNNvdQraNWOc0=ps8MQRUpGqw05+5mNA@mail.gmail.com>
--===============2302278979310067042==
Content-Type: multipart/alternative; boundary="0000000000008a11fd063afdb821"

--0000000000008a11fd063afdb821
Content-Type: text/plain; charset="UTF-8"

Hi

I'm trying to add a keyboard shortcut for a plugin action. My props file:

plugin.ch.so.agi.jedit.InterlisPlugin.menu=compileCurrentFile
compileCurrentFile.label=Compile current file
compileCurrentFile.shortcut=CS+c

This alone does not work. I can add some code in the start() method of my
plugin:

ActionSet actionSet = this.getPluginJAR().getActionSet();EditAction[] ea =
actionSet.getActions();
for (int i = 0; i < ea.length; ++i) {
    String shortcut1 = jEdit.getProperty(ea[i].getName() + ".shortcut");
    if (shortcut1 != null) {
        Edit.getInputHandler().addKeyBinding(shortcut1, ea[i]);
    String shortcut2 = jEdit.getProperty(ea[i].getName() + ".shortcut2");
    if (shortcut2 != null)
        jEdit.getInputHandler().addKeyBinding(shortcut2, ea[i]);
}

After that the shortcut works (or at least after on restart of jEdit). Is
it actually even possible to add a shortcut from a plugin. Is this the way
to do it?

regards
Stefan

--0000000000008a11fd063afdb821
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi</div><div><br></div><div>I&#39;m trying to add a k=
eyboard shortcut for a plugin action. My props file:</div><div><br></div><d=
iv>plugin.ch.so.agi.jedit.InterlisPlugin.menu=3DcompileCurrentFile</div><di=
v>compileCurrentFile.label=3DCompile current file <br></div><div>compileCur=
rentFile.shortcut=3DCS+c</div><div><br></div><div>This alone does not work.=
 I can add some code in the start() method of my plugin:</div><div><br></di=
v><div>ActionSet actionSet =3D this.getPluginJAR().getActionSet();EditActio=
n[] ea =3D actionSet.getActions();</div><div>for (int i =3D 0; i &lt; ea.le=
ngth; ++i) {</div><div>=C2=A0=C2=A0=C2=A0 String shortcut1 =3D jEdit.getPro=
perty(ea[i].getName() + &quot;.shortcut&quot;);</div><div>=C2=A0=C2=A0=C2=
=A0 if (shortcut1 !=3D null) {</div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 Edit.getInputHandler().addKeyBinding(shortcut1, ea[i]);</div><div=
>=C2=A0=C2=A0=C2=A0 String shortcut2 =3D jEdit.getProperty(ea[i].getName() =
+ &quot;.shortcut2&quot;);</div><div>=C2=A0=C2=A0=C2=A0 if (shortcut2 !=3D =
null)</div><div>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 jEdit.getInputHa=
ndler().addKeyBinding(shortcut2, ea[i]);</div><div>}</div><div><br></div><d=
iv>After that the shortcut works (or at least after on restart of jEdit). I=
s it actually even possible to add a shortcut from a plugin. Is this the wa=
y to do it?</div><div><br></div><div>regards</div><div>Stefan=C2=A0</div><d=
iv><br></div></div>

--0000000000008a11fd063afdb821--


--===============2302278979310067042==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============2302278979310067042==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-- 
-----------------------------------------------
jEdit Users' List
[email protected]
https://lists.sourceforge.net/lists/listinfo/jedit-users

--===============2302278979310067042==--