Skip to content

Commit

Permalink
Merge pull request #1940 from alcomposer/command-dismiss-fix
Browse files Browse the repository at this point in the history
Use the commandID to dismiss the callout box also, no need for a dism…
  • Loading branch information
timothyschoen authored Nov 14, 2024
2 parents 8119967 + cc2a300 commit 92cd84c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ void PluginEditor::getCommandInfo(CommandID const commandID, ApplicationCommandI
}
case CommandIDs::ShowCommandInput: {
result.setInfo("Toggle Command Input", "Enables or disables the command input", "View", 0);
result.addDefaultKeypress(KeyPress::F3Key, ModifierKeys::noModifiers);
result.addDefaultKeypress(77, ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier);
result.setActive(true);
break;
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Sidebar/CommandInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ class CommandInput final
public:
CommandInput(PluginEditor* editor) : editor(editor)
{
// We need to set the target for the command manager, otherwise it will default to PlugDataApp and fail to find CommandID
editor->commandManager.setFirstCommandTarget(editor);
// Get the application command id key to toggle show/hide of the command prompt
// We need to know this as the command prompt gets keyboard focus
// So the command prompt needs to dismiss itself when the CommandID key is pressed
// And we want to make sure the user can set this shortcut
auto* keyMappings = editor->commandManager.getKeyMappings();
auto keyPresses = keyMappings->getKeyPressesAssignedToCommand(CommandIDs::ShowCommandInput);
commandIDToggleShowKey = keyPresses.getFirst();
Expand Down Expand Up @@ -732,8 +733,8 @@ class CommandInput final
return true;
}
else if (key.getKeyCode() == commandIDToggleShowKey.getKeyCode()) {
dismiss();
return true;
editor->commandManager.invokeDirectly(CommandIDs::ShowCommandInput, false);
return true;
}
return false;
}
Expand Down Expand Up @@ -829,7 +830,6 @@ class CommandInput final

public:

std::function<void()> dismiss = [](){};
std::function<void()> onDismiss = [](){};

static inline const UnorderedSet<String> allAtoms = { "floatbox", "symbolbox", "listbox", "gatom" };
Expand Down
14 changes: 6 additions & 8 deletions Source/Statusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,23 +1260,21 @@ Statusbar::~Statusbar()

void Statusbar::showCommandInput()
{
if (commandInputCallout)
if (commandInputCallout) {
commandInputCallout->dismiss();
return;
}

auto commandInput = std::make_unique<CommandInput>(editor);
auto rawCommandInput = commandInput.get();
auto& callout = editor->showCalloutBox(std::move(commandInput), commandInputButton->getScreenBounds().removeFromRight(22));

commandInputCallout = (&callout);

rawCommandInput->dismiss = [callout_ = SafePointer(&callout)](){
if (callout_) {
callout_->dismiss();
}
};
commandInputCallout = &callout;

rawCommandInput->onDismiss = [this](){
// If the mouse is not over the button when callout is closed, the button doesn't know it needs to repaint
// This can cause paint glitches on the button if the cursor is not over the button when callout is closed
// So we call repaint on the button when the callout is destroyed
commandInputButton->repaint();
};
}
Expand Down

0 comments on commit 92cd84c

Please sign in to comment.