49 for (
int i = 0; i < mappings.
size(); ++i)
67 for (
int i = mappings.
size(); --i >= 0;)
80 CommandMapping*
const cm =
new CommandMapping();
81 cm->commandID = commandID;
100 for (
int j = 0;
j <
ci->defaultKeypresses.size(); ++
j)
119 addKeyPresses (*
this,
ci);
124 if (mappings.
size() > 0)
133 for (
int i = mappings.
size(); --i >= 0;)
147 for (
int i = mappings.
size(); --i >= 0;)
151 for (
int j =
cm.keypresses.size(); --
j >= 0;)
155 cm.keypresses.remove (
j);
165 for (
int i = mappings.
size(); --i >= 0;)
179 for (
int i = 0; i < mappings.size(); ++i)
180 if (mappings.getUnchecked (i)->keypresses.contains (keyPress))
181 return mappings.getUnchecked (i)->commandID;
188 for (
int i = mappings.size(); --i >= 0;)
189 if (mappings.getUnchecked (i)->commandID == commandID)
190 return mappings.getUnchecked (i)->keypresses.contains (keyPress);
195void KeyPressMappingSet::invokeCommand (
const CommandID commandID,
197 const bool isKeyDown,
198 const int millisecsSinceKeyPressed,
199 Component*
const originatingComponent)
const
204 info.isKeyDown = isKeyDown;
206 info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
207 info.originatingComponent = originatingComponent;
209 commandManager.
invoke (info,
false);
217 if (
xmlVersion.getBoolAttribute (
"basedOnDefaults",
true))
230 for (
auto* map :
xmlVersion.getChildIterator())
238 if (map->hasTagName (
"MAPPING"))
242 else if (map->hasTagName (
"UNMAPPING"))
244 for (
auto& m : mappings)
246 m->keypresses.removeAllInstancesOf (key);
263 defaultSet = std::make_unique<KeyPressMappingSet> (commandManager);
267 auto doc = std::make_unique<XmlElement> (
"KEYMAPPINGS");
271 for (
int i = 0; i < mappings.
size(); ++i)
275 for (
int j = 0;
j <
cm.keypresses.size(); ++
j)
278 || !
defaultSet->containsMapping (
cm.commandID,
cm.keypresses.getReference (
j)))
280 auto map =
doc->createNewChildElement (
"MAPPING");
284 map->setAttribute (
"key",
cm.keypresses.getReference (
j).getTextDescription());
291 for (
int i = 0; i <
defaultSet->mappings.size(); ++i)
295 for (
int j = 0;
j <
cm.keypresses.size(); ++
j)
299 auto map =
doc->createNewChildElement (
"UNMAPPING");
303 map->setAttribute (
"key",
cm.keypresses.getReference (
j).getTextDescription());
317 for (
int i = 0; i < mappings.
size(); ++i)
321 if (
cm.keypresses.contains (key))
333 invokeCommand (
cm.commandID, key,
true, 0, originatingComponent);
355 for (
int i = mappings.
size(); --i >= 0;)
359 if (
cm.wantsKeyUpDownCallbacks)
361 for (
int j =
cm.keypresses.size(); --
j >= 0;)
363 const KeyPress key (
cm.keypresses.getReference (
j));
369 for (
int k = keysDown.
size(); --k >= 0;)
386 KeyPressTime*
const k =
new KeyPressTime();
388 k->timeWhenPressed = now;
402 invokeCommand (
cm.commandID, key, isDown,
millisecs, originatingComponent);
One of these objects holds a list of all the commands your app can perform, and despatches these comm...
ApplicationCommandTarget * getTargetForCommand(CommandID commandID, ApplicationCommandInfo &upToDateInfo)
Tries to find the best target to use to perform a given command.
int getNumCommands() const noexcept
Returns the number of commands that have been registered.
const ApplicationCommandInfo * getCommandForID(CommandID commandID) const noexcept
Returns the details about a given command ID.
const ApplicationCommandInfo * getCommandForIndex(int index) const noexcept
Returns the details about one of the registered commands.
bool invoke(const ApplicationCommandTarget::InvocationInfo &invocationInfo, bool asynchronously)
Sends a command to the default target.
String getDescriptionOfCommand(CommandID commandID) const noexcept
Returns the description field for a command.
Holds a resizable array of primitive or copy-by-value objects.
Holds a list of ChangeListeners, and sends messages to them when instructed.
void sendChangeMessage()
Causes an asynchronous change message to be sent to all the registered listeners.
static bool isUpperCase(juce_wchar character) noexcept
Checks whether a unicode character is upper-case.
The base class for all JUCE user-interface objects.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
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.
Classes can implement this interface and register themselves with the Desktop class to receive callba...
Receives callbacks when keys are pressed.
Manages and edits a list of keypresses, which it uses to invoke the appropriate command in an Applica...
void addKeyPress(CommandID commandID, const KeyPress &newKeyPress, int insertIndex=-1)
Assigns a keypress to a command.
void resetToDefaultMapping(CommandID commandID)
Resets all key-mappings to the defaults for a particular command.
Array< KeyPress > getKeyPressesAssignedToCommand(CommandID commandID) const
Returns a list of keypresses that are assigned to a particular command.
bool containsMapping(CommandID commandID, const KeyPress &keyPress) const noexcept
Returns true if the given command is linked to this key.
void removeKeyPress(CommandID commandID, int keyPressIndex)
Removes one of the keypresses that are assigned to a command.
~KeyPressMappingSet() override
Destructor.
void globalFocusChanged(Component *) override
Callback to indicate that the currently focused component has changed.
void clearAllKeyPresses()
Removes all keypresses that are assigned to any commands.
void resetToDefaultMappings()
Reset all mappings to the defaults, as dictated by the ApplicationCommandManager.
CommandID findCommandForKeyPress(const KeyPress &keyPress) const noexcept
Looks for a command that corresponds to a keypress.
bool keyPressed(const KeyPress &, Component *) override
Called to indicate that a key has been pressed.
KeyPressMappingSet(ApplicationCommandManager &)
Creates a KeyPressMappingSet for a given command manager.
bool keyStateChanged(bool isKeyDown, Component *) override
Called when any key is pressed or released.
bool restoreFromXml(const XmlElement &xmlVersion)
Tries to recreate the mappings from a previously stored state.
std::unique_ptr< XmlElement > createXml(bool saveDifferencesFromDefaultSet) const
Creates an XML representation of the current mappings.
Represents a key press, including any modifier keys that are needed.
bool isCurrentlyDown() const
Checks whether the user is currently holding down the keys that make up this KeyPress.
static KeyPress createFromDescription(const String &textVersion)
Converts a textual key description to a KeyPress.
virtual void playAlertSound()
Plays the system's default 'beep' noise, to alert the user about something very important.
int size() const noexcept
Returns the number of items currently in the array.
ObjectClass * getUnchecked(int index) const noexcept
Returns a pointer to the object at this index in the array, without checking whether the index is in-...
void remove(int indexToRemove, bool deleteObject=true)
Removes an object from the array.
void clear(bool deleteObjects=true)
Clears the array, optionally deleting the objects inside it first.
ObjectClass * add(ObjectClass *newObject)
Appends a new object to the end of the array.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
static uint32 getMillisecondCounter() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
Used to build a tree of elements representing an XML document.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
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.
@ wantsKeyUpDownCallbacks
If this flag is present, then when a KeyPressMappingSet invokes the command, it will call the command...
@ isDisabled
Indicates that the command can't currently be performed.
Contains contextual details about the invocation of a command.
@ fromKeyPress
The command is being invoked by a key-press.