Adding touchbar support with a new action group

Answered

Hi guys, I am developing Mac Touchbar support for some actions that we already use in a plugin. However I can't see how to add them. I guess the changes could be made in plugin.xml. So I have tried the following way of including my new action group TouchBarMyAction_alt_r in the Debug Actions available on the touchbar, but it didn't work. (My intention was to have an action group that appears on the touchbar when alt+r are pressed.)

<group id="TouchBar">
<separator text="type.flexible"/>
<group id="TouchBarMyAction_alt_r">
<reference ref="MyAction1"/>
<reference ref="MyAction2"/>
<reference ref="MyAction3"/>
<separator text="type.flexible"/>
</group>
</group>
How can I achieve this? Is there either a declarative or programmatic way of doing it?
0
3 comments

So I've made a bit of progress: I added an `ActionGroup` class that has the same id as the one I added to `plugin.xml`. In that class, I defined the actions to be displayed. This resulted in the group's action buttons showing up and they were usable with some qualifications.

  1. There were no icons.
  2. They were in the TouchBarDebug_alt action group not in their own group.
  3. I couldn't find out how to configure a special key combination to display the custom action group.

Any suggestions to help me move forward with this?

The custom ActionGroup class I wrote was:

package my.code.intellij.actions;

import com.intellij.openapi.actionSystem.*;
import java.awt.event.InputEvent;
import javax.swing.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class TouchBarMyActionGroup extends DefaultActionGroup {
private static final ShortcutSet shortcutSet =
() ->
new Shortcut[] {
new KeyboardShortcut(
KeyStroke.getKeyStroke('r',
InputEvent.ALT_DOWN_MASK), null)
};

public TouchBarMyActionGroup() {}

public TouchBarMyActionGroup(String dirPath) {
super("TouchBarMyAction_alt_r", false);
this.registerCustomShortcutSet(shortcutSet, null);
}

@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
return new AnAction[] {
new MyAction1(),
new MyAction2(),
new MyAction3()
};
}

/**
* This method can be called in popup menus if {@link
* #canBePerformed(DataContext)} is {@code
* true}.
*/
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
System.out.println();
}

/** @return {@code true} if {@link
* #actionPerformed(AnActionEvent)} should be called.
*/
public boolean canBePerformed(@NotNull DataContext context)
{
return true;
}
}

 

0

Along with the above code snippet, I revised the plugin.xml which now has:

<group id="TouchBarMyAction_alt_r"         class="my.code.intellij.actions.TouchBarMyActionGroup" text="My Operations"
        popup="false" icon="myicon.png">
    <separator/>
    <add-to-group group-id="TouchBarDebug_alt" anchor="last"/>
    <separator/>
</group>

But as I said it still doesn't work in the ways I described.

0

Unfortunately, touchbar doesn't support custom shortcuts (like alt+r) now, it supports only simple modifier keys (ctlr, alt, shift, meta and combinations of them). Such shortcuts will be added in nearest EAP 20.3.

In current version you can define 'default' or 'debugger' action groups (and corresponding subgroups for modifier keys), example:


<group id="TouchBarDefault">
<reference ref="Stop"/>
<group id="TouchBarDefault_ctrl">
<separator/>
</group>
<group id="TouchBarDefault_alt">
<reference ref="SelectInProjectView"/>
<separator text="type.flexible"/>
</group>
<group id="TouchBarDefault_cmd">
<reference ref="ToggleBookmark"/>
<reference ref="ToggleLineBreakpoint"/>
</group>
<group id="TouchBarDefault_cmd.alt">
<separator text="type.flexible"/>
<reference ref="FindUsages"/>
</group>
<group id="TouchBarDefault_shift">
<reference ref="Move"/>
</group>
</group>
<group id="TouchBarDebug">
<reference ref="Rerun"/>
<reference ref="Resume"/>
<reference ref="Pause"/>
<group id="TouchBarDebug_alt">
<reference ref="ViewBreakpoints"/>
</group>
</group>

 

0

Please sign in to leave a comment.