45 keyMappings->clearAllKeyPresses();
57 if (
auto* command = getMutableCommandForID (newCommand.
commandID))
68 *command = newCommand;
74 commands.add (newInfo);
76 keyMappings->resetToDefaultMapping (newCommand.
commandID);
84 if (target !=
nullptr)
89 for (
int i = 0; i < commandIDs.
size(); ++i)
101 for (
int i = commands.size(); --i >= 0;)
103 if (commands.getUnchecked (i)->commandID == commandID)
108 const Array<KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
110 for (
int j = keys.
size(); --j >= 0;)
124 for (
int i = commands.size(); --i >= 0;)
125 if (commands.getUnchecked (i)->commandID == commandID)
126 return commands.getUnchecked (i);
133 return getMutableCommandForID (commandID);
138 if (
auto* ci = getCommandForID (commandID))
139 return ci->shortName;
146 if (
auto* ci = getCommandForID (commandID))
147 return ci->description.
isNotEmpty() ? ci->description
157 for (
int i = 0; i < commands.size(); ++i)
167 for (
int i = 0; i < commands.size(); ++i)
168 if (commands.getUnchecked (i)->categoryName == categoryName)
169 results.
add (commands.getUnchecked (i)->commandID);
180 return invoke (info, asynchronously);
197 sendListenerInvokeCallback (info);
198 ok = target->invoke (info, asynchronously);
208 return firstTarget !=
nullptr ? firstTarget
214 firstTarget = newTarget;
222 if (target ==
nullptr)
225 if (target !=
nullptr)
226 target = target->getTargetForCommand (commandID);
228 if (target !=
nullptr)
231 target->getCommandInfo (commandID, upToDateInfo);
242 if (target ==
nullptr && c !=
nullptr)
256 if (
auto* peer = activeWindow->getPeer())
258 c = peer->getLastFocusedSubcomponent();
271 for (
int i = desktop.getNumComponents(); --i >= 0;)
272 if (
auto* component = desktop.getComponent (i))
273 if (detail::WindowingHelpers::isForegroundOrEmbeddedProcess (component))
274 if (
auto* peer = component->getPeer())
286 if (
auto* content = resizableWindow->getContentComponent())
299 listeners.add (listener);
304 listeners.remove (listener);
312void ApplicationCommandManager::handleAsyncUpdate()
314 listeners.call ([] (ApplicationCommandManagerListener& l) { l.applicationCommandListChanged(); });
317void ApplicationCommandManager::globalFocusChanged (Component*)
A listener that receives callbacks from an ApplicationCommandManager when commands are invoked or the...
virtual void applicationCommandInvoked(const ApplicationCommandTarget::InvocationInfo &)=0
Called when an app command is about to be invoked.
void addListener(ApplicationCommandManagerListener *listener)
Registers a listener that will be called when various events occur.
ApplicationCommandTarget * getTargetForCommand(CommandID commandID, ApplicationCommandInfo &upToDateInfo)
Tries to find the best target to use to perform a given command.
static ApplicationCommandTarget * findTargetForComponent(Component *)
Examines this component and all its parents in turn, looking for the first one which is an Applicatio...
Array< CommandID > getCommandsInCategory(const String &categoryName) const
Returns a list of all the command UIDs in a particular category.
String getNameOfCommand(CommandID commandID) const noexcept
Returns the name field for a command.
static ApplicationCommandTarget * findDefaultComponentTarget()
Looks for a suitable command target based on which Components have the keyboard focus.
StringArray getCommandCategories() const
Returns the list of categories.
void setFirstCommandTarget(ApplicationCommandTarget *newTarget) noexcept
Sets a target to be returned by getFirstCommandTarget().
void registerCommand(const ApplicationCommandInfo &newCommand)
Adds a command to the list of registered commands.
ApplicationCommandManager()
Creates an ApplicationCommandManager.
bool invokeDirectly(CommandID commandID, bool asynchronously)
Invokes the given command directly, sending it to the default target.
void removeCommand(CommandID commandID)
Removes the command with a specified ID.
~ApplicationCommandManager() override
Destructor.
const ApplicationCommandInfo * getCommandForID(CommandID commandID) const noexcept
Returns the details about a given command ID.
bool invoke(const ApplicationCommandTarget::InvocationInfo &invocationInfo, bool asynchronously)
Sends a command to the default target.
void commandStatusChanged()
This should be called to tell the manager that one of its registered commands may have changed its ac...
void clearCommands()
Clears the current list of all commands.
virtual ApplicationCommandTarget * getFirstCommandTarget(CommandID commandID)
Chooses the ApplicationCommandTarget to which a command should be sent.
void removeListener(ApplicationCommandManagerListener *listener)
Deregisters a previously-added listener.
void registerAllCommandsForTarget(ApplicationCommandTarget *target)
Adds all the commands that this target publishes to the manager's list.
String getDescriptionOfCommand(CommandID commandID) const noexcept
Returns the description field for a command.
A command target publishes a list of command IDs that it can perform.
virtual void getCommandInfo(CommandID commandID, ApplicationCommandInfo &result)=0
This must provide details about one of the commands that this target can perform.
virtual void getAllCommands(Array< CommandID > &commands)=0
This must return a complete list of commands that this target can handle.
Holds a resizable array of primitive or copy-by-value objects.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
int size() const noexcept
Returns the current number of elements in the array.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
The base class for all JUCE user-interface objects.
static Component *JUCE_CALLTYPE getCurrentlyFocusedComponent() noexcept
Returns the component that currently has the keyboard focus.
TargetClass * findParentComponentOfClass() const
Searches the parent components for a component of a specified class.
void removeFocusChangeListener(FocusChangeListener *listener)
Unregisters a FocusChangeListener that was added with addFocusChangeListener().
void addFocusChangeListener(FocusChangeListener *listener)
Registers a FocusChangeListener that will receive a callback whenever the focused component changes.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
static JUCEApplication *JUCE_CALLTYPE getInstance() noexcept
Returns the global instance of the application object being run.
Manages and edits a list of keypresses, which it uses to invoke the appropriate command in an Applica...
A base class for top-level windows that can be dragged around and resized.
A special array for holding a list of strings.
bool addIfNotAlreadyThere(const String &stringToAdd, bool ignoreCase=false)
Adds a string to the array as long as it's not already in there.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
static TopLevelWindow * getActiveTopLevelWindow() noexcept
Returns the currently-active top level window.
#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
This macro is used to catch unsafe use of functions which expect to only be called on the message thr...
int CommandID
A type used to hold the unique ID for an application command.
Holds information describing an application command.
int flags
A bitwise-OR of the values specified in the CommandFlags enum.
Array< KeyPress > defaultKeypresses
A list of zero or more keypresses that should be used as the default keys for this command.
CommandID commandID
The command's unique ID number.
String categoryName
A named category that the command fits into.
@ wantsKeyUpDownCallbacks
If this flag is present, then when a KeyPressMappingSet invokes the command, it will call the command...
@ readOnlyInKeyEditor
If this flag is present, then a KeyMappingEditorComponent will display the command in its list,...
@ hiddenFromKeyEditor
If this flag is present, then a KeyMappingEditorComponent will not display the command in its list.
String shortName
A short name to describe the command.
Contains contextual details about the invocation of a command.
InvocationMethod invocationMethod
The type of event that triggered this command.
@ direct
The command is being invoked directly by a piece of code.
int commandFlags
The command's flags.
CommandID commandID
The UID of the command that should be performed.