# ApplicationCommandTarget in tracktion engine?

**URL:** <https://forum.juce.com/t/applicationcommandtarget-in-tracktion-engine/35823>\
**Category:** Tracktion Engine\
**Created:** [October 23, 2019, 1:09am UTC](https://forum.juce.com/t/applicationcommandtarget-in-tracktion-engine/35823 "2019-10-23T01:09:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [October 23, 2019, 1:09am UTC](https://forum.juce.com/t/applicationcommandtarget-in-tracktion-engine/35823/1 "2019-10-23T01:09:01Z")

</div>

Hi, I implemented my own UIBehaviour overriding methods:

```
juce::ApplicationCommandManager* getApplicationCommandManager() override { return &commandManager; }
void getAllCommands (juce::Array<juce::CommandID>& commands) override;
void getCommandInfo (juce::CommandID commandID, juce::ApplicationCommandInfo& result) override;
bool perform (const juce::ApplicationCommandTarget::InvocationInfo& info) override;

```

but on my mainComponent if I implement this method:

```
PopupMenu MainComponent::getMenuForIndex (int topLevelMenuIndex, const String& menuName);

```

nothing is displayed in menu selected, so I asked me if I need to inherit My UIBehaviour class with ApplicationCommandTarget and in the init of this class call `commandManager.registerAllCommandsForTarget( **this** );`

in Main component if I also try to print the number of command registered it prints me 0:

```
ApplicationCommandManager* commandManager = engine.getUIBehaviour().getApplicationCommandManager();

DBG(commandManager->getNumCommands());

```

how do you thought this in tracktion?

Thank you in advice!

---

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [October 23, 2019, 9:32am UTC](https://forum.juce.com/t/applicationcommandtarget-in-tracktion-engine/35823/2 "2019-10-23T09:32:30Z")

</div>

Solved I do in this way, I inherited My UIBehaviour class with ApplicationCommandTarget and in the init of this class call `commandManager.registerAllCommandsForTarget( **this** );` 🙂

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [October 23, 2019, 11:44am UTC](https://forum.juce.com/t/applicationcommandtarget-in-tracktion-engine/35823/3 "2019-10-23T11:44:03Z")

</div>

I think you probably want to keep your `UIBehaviour` subclass and `ApplicationCommandTarget` subclass separate.

The only reason `UIBehaviour` needs to return `ApplicationCommandTarget` is so:

1. The `AlphaTrackControlSurface` can send key presses to it
2. You _may_ want to access your command manager via the UIBehaviour class in your UI e.g. plugins windows.

But for most cases, you won’t need to implement these if you can get direct access to your `ApplicationControlManager`.

---

<div class="post-metadata">

**Author:** ![Ayra](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ayra/32/5775_2.png) [@Ayra](https://forum.juce.com/u/Ayra)\
**Post date:** [October 23, 2019, 12:00pm UTC](https://forum.juce.com/t/applicationcommandtarget-in-tracktion-engine/35823/4 "2019-10-23T12:00:32Z")

</div>

Ok Thank You! this could be the reason of this topic?

> [@Can't select MenuItems](https://forum.juce.com/t/cant-select-menuitems/35831):
>
> Hi, I created my own menuBar, I implemented MenubarModel, ApplicationCommandTarget ecc. and all works. My problem is that when I open a menu all items inside are not selectable and also if I press my key combination to invoke command nothing happens.
