mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Bit of tidying-up in KeyPressMappingSet and related classes.
This commit is contained in:
parent
06e2a667fb
commit
d0fa359f72
5 changed files with 92 additions and 117 deletions
|
|
@ -26,20 +26,18 @@
|
|||
class KeyMappingEditorComponent::ChangeKeyButton : public Button
|
||||
{
|
||||
public:
|
||||
ChangeKeyButton (KeyMappingEditorComponent& owner_,
|
||||
const CommandID commandID_,
|
||||
const String& keyName,
|
||||
const int keyNum_)
|
||||
ChangeKeyButton (KeyMappingEditorComponent& kec, const CommandID command,
|
||||
const String& keyName, const int keyIndex)
|
||||
: Button (keyName),
|
||||
owner (owner_),
|
||||
commandID (commandID_),
|
||||
keyNum (keyNum_)
|
||||
owner (kec),
|
||||
commandID (command),
|
||||
keyNum (keyIndex)
|
||||
{
|
||||
setWantsKeyboardFocus (false);
|
||||
setTriggeredOnMouseDown (keyNum >= 0);
|
||||
|
||||
setTooltip (keyNum_ < 0 ? TRANS("adds a new key-mapping")
|
||||
: TRANS("click to change this key-mapping"));
|
||||
setTooltip (keyIndex < 0 ? TRANS("adds a new key-mapping")
|
||||
: TRANS("click to change this key-mapping"));
|
||||
}
|
||||
|
||||
void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
|
||||
|
|
@ -83,25 +81,20 @@ public:
|
|||
void fitToContent (const int h) noexcept
|
||||
{
|
||||
if (keyNum < 0)
|
||||
{
|
||||
setSize (h, h);
|
||||
}
|
||||
else
|
||||
{
|
||||
Font f (h * 0.6f);
|
||||
setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
|
||||
}
|
||||
setSize (jlimit (h * 4, h * 8, 6 + Font (h * 0.6f).getStringWidth (getName())), h);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
class KeyEntryWindow : public AlertWindow
|
||||
{
|
||||
public:
|
||||
KeyEntryWindow (KeyMappingEditorComponent& owner_)
|
||||
KeyEntryWindow (KeyMappingEditorComponent& kec)
|
||||
: AlertWindow (TRANS("New key-mapping"),
|
||||
TRANS("Please press a key combination now..."),
|
||||
AlertWindow::NoIcon),
|
||||
owner (owner_)
|
||||
owner (kec)
|
||||
{
|
||||
addButton (TRANS("Ok"), 1);
|
||||
addButton (TRANS("Cancel"), 0);
|
||||
|
|
@ -123,7 +116,7 @@ public:
|
|||
|
||||
if (previousCommand != 0)
|
||||
message << "\n\n" << TRANS("(Currently assigned to \"")
|
||||
<< owner.getMappings().getCommandManager()->getNameOfCommand (previousCommand) << "\")";
|
||||
<< owner.getCommandManager().getNameOfCommand (previousCommand) << "\")";
|
||||
|
||||
setMessage (message);
|
||||
return true;
|
||||
|
|
@ -168,7 +161,7 @@ public:
|
|||
AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
|
||||
TRANS("Change key-mapping"),
|
||||
TRANS("This key is already assigned to the command \"")
|
||||
+ owner.getMappings().getCommandManager()->getNameOfCommand (previousCommand)
|
||||
+ owner.getCommandManager().getNameOfCommand (previousCommand)
|
||||
+ TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
|
||||
TRANS("Re-assign"),
|
||||
TRANS("Cancel"),
|
||||
|
|
@ -209,8 +202,8 @@ private:
|
|||
class KeyMappingEditorComponent::ItemComponent : public Component
|
||||
{
|
||||
public:
|
||||
ItemComponent (KeyMappingEditorComponent& owner_, const CommandID commandID_)
|
||||
: owner (owner_), commandID (commandID_)
|
||||
ItemComponent (KeyMappingEditorComponent& kec, const CommandID command)
|
||||
: owner (kec), commandID (command)
|
||||
{
|
||||
setInterceptsMouseClicks (false, true);
|
||||
|
||||
|
|
@ -239,7 +232,7 @@ public:
|
|||
g.setFont (getHeight() * 0.7f);
|
||||
g.setColour (findColour (KeyMappingEditorComponent::textColourId));
|
||||
|
||||
g.drawFittedText (owner.getMappings().getCommandManager()->getNameOfCommand (commandID),
|
||||
g.drawFittedText (owner.getCommandManager().getNameOfCommand (commandID),
|
||||
4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
|
||||
Justification::centredLeft, true);
|
||||
}
|
||||
|
|
@ -272,19 +265,14 @@ private:
|
|||
class KeyMappingEditorComponent::MappingItem : public TreeViewItem
|
||||
{
|
||||
public:
|
||||
MappingItem (KeyMappingEditorComponent& owner_, const CommandID commandID_)
|
||||
: owner (owner_), commandID (commandID_)
|
||||
{
|
||||
}
|
||||
MappingItem (KeyMappingEditorComponent& kec, const CommandID command)
|
||||
: owner (kec), commandID (command)
|
||||
{}
|
||||
|
||||
String getUniqueName() const { return String ((int) commandID) + "_id"; }
|
||||
bool mightContainSubItems() { return false; }
|
||||
int getItemHeight() const { return 20; }
|
||||
|
||||
Component* createItemComponent()
|
||||
{
|
||||
return new ItemComponent (owner, commandID);
|
||||
}
|
||||
String getUniqueName() const { return String ((int) commandID) + "_id"; }
|
||||
bool mightContainSubItems() { return false; }
|
||||
int getItemHeight() const { return 20; }
|
||||
Component* createItemComponent() { return new ItemComponent (owner, commandID); }
|
||||
|
||||
private:
|
||||
KeyMappingEditorComponent& owner;
|
||||
|
|
@ -298,10 +286,9 @@ private:
|
|||
class KeyMappingEditorComponent::CategoryItem : public TreeViewItem
|
||||
{
|
||||
public:
|
||||
CategoryItem (KeyMappingEditorComponent& owner_, const String& name)
|
||||
: owner (owner_), categoryName (name)
|
||||
{
|
||||
}
|
||||
CategoryItem (KeyMappingEditorComponent& kec, const String& name)
|
||||
: owner (kec), categoryName (name)
|
||||
{}
|
||||
|
||||
String getUniqueName() const { return categoryName + "_cat"; }
|
||||
bool mightContainSubItems() { return true; }
|
||||
|
|
@ -323,13 +310,11 @@ public:
|
|||
{
|
||||
if (getNumSubItems() == 0)
|
||||
{
|
||||
Array <CommandID> commands (owner.getMappings().getCommandManager()->getCommandsInCategory (categoryName));
|
||||
const Array <CommandID> commands (owner.getCommandManager().getCommandsInCategory (categoryName));
|
||||
|
||||
for (int i = 0; i < commands.size(); ++i)
|
||||
{
|
||||
if (owner.shouldCommandBeIncluded (commands[i]))
|
||||
addSubItem (new MappingItem (owner, commands[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -351,8 +336,8 @@ class KeyMappingEditorComponent::TopLevelItem : public TreeViewItem,
|
|||
private ChangeListener
|
||||
{
|
||||
public:
|
||||
TopLevelItem (KeyMappingEditorComponent& owner_)
|
||||
: owner (owner_)
|
||||
TopLevelItem (KeyMappingEditorComponent& kec)
|
||||
: owner (kec)
|
||||
{
|
||||
setLinesDrawnForSubItems (false);
|
||||
owner.getMappings().addChangeListener (this);
|
||||
|
|
@ -371,11 +356,11 @@ public:
|
|||
const OpennessRestorer opennessRestorer (*this);
|
||||
clearSubItems();
|
||||
|
||||
const StringArray categories (owner.getMappings().getCommandManager()->getCommandCategories());
|
||||
const StringArray categories (owner.getCommandManager().getCommandCategories());
|
||||
|
||||
for (int i = 0; i < categories.size(); ++i)
|
||||
{
|
||||
const Array <CommandID> commands (owner.getMappings().getCommandManager()->getCommandsInCategory (categories[i]));
|
||||
const Array <CommandID> commands (owner.getCommandManager().getCommandsInCategory (categories[i]));
|
||||
int count = 0;
|
||||
|
||||
for (int j = 0; j < commands.size(); ++j)
|
||||
|
|
@ -469,14 +454,14 @@ void KeyMappingEditorComponent::resized()
|
|||
//==============================================================================
|
||||
bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
|
||||
{
|
||||
const ApplicationCommandInfo* const ci = mappings.getCommandManager()->getCommandForID (commandID);
|
||||
const ApplicationCommandInfo* const ci = mappings.getCommandManager().getCommandForID (commandID);
|
||||
|
||||
return ci != nullptr && (ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0;
|
||||
}
|
||||
|
||||
bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
|
||||
{
|
||||
const ApplicationCommandInfo* const ci = mappings.getCommandManager()->getCommandForID (commandID);
|
||||
const ApplicationCommandInfo* const ci = mappings.getCommandManager().getCommandForID (commandID);
|
||||
|
||||
return ci != nullptr && (ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue