Skip to content

Commit

Permalink
Preselect sub menus and patch items in PatchSelector (surge-synthesiz…
Browse files Browse the repository at this point in the history
…er#6859)

* Preselect sub menus and patch items in PatchSelector

* "static constexpr int" instead of "#define" for the id for preselected menu items.

---------

Co-authored-by: Alexandr Zyurkalov <[email protected]>
  • Loading branch information
Alexander-Zyurkalov and Alexandr Zyurkalov authored Feb 27, 2023
1 parent e46dbfc commit 0189187
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ Vincent Zauhar <[email protected]>
Marty Lake <[email protected]>
David Carlier <[email protected]>
Xenakios <[email protected]>
Alexandr Zyurkalov <[email protected]>
2 changes: 1 addition & 1 deletion doc/Developer Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ If your IDE is set to auto-format cmake files make sure to configure it accordin

### Naming

* `#define` constants are `UPPERCASE_VARIABLES`
* used to `#define` constants as `UPPERCASE_VARIABLES`, but prefer `static constexpr <type> UPPERCASE_VARIABLES`.
* `class HaveCamelCaseNames`
* `void functionsAreCamelCaseWithLowerFirst`
* We are not using `s_` or `m_` or equivalent notations for members or statics
Expand Down
19 changes: 17 additions & 2 deletions src/surge-xt/gui/widgets/PatchSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
#include "AccessibleHelpers.h"
#include "SurgeJUCEHelpers.h"

/*
* It is an arbitrary number that we set as an ID for patch menu items.
* It is not necessarily to be unique among all menu items, only among a sub menu, so it can
* be a constant.
*/
static constexpr int ID_TO_PRESELECT_MENU_ITEMS = 636133;

namespace Surge
{
namespace Widgets
Expand Down Expand Up @@ -743,7 +750,8 @@ void PatchSelector::showClassicMenu(bool single_category)

if (sge)
{
o = sge->popupMenuOptions(getBounds().getBottomLeft());
o = sge->popupMenuOptions(getBounds().getBottomLeft())
.withInitiallySelectedItem(ID_TO_PRESELECT_MENU_ITEMS);
}

contextMenu.showMenuAsync(o, [that = juce::Component::SafePointer(this)](int) {
Expand Down Expand Up @@ -1006,6 +1014,9 @@ bool PatchSelector::populatePatchMenuForCategory(int c, juce::PopupMenu &context
auto item = juce::PopupMenu::Item(name).setEnabled(true).setTicked(thisCheck).setAction(
[this, p]() { this->loadPatch(p); });

if (thisCheck)
item.setID(ID_TO_PRESELECT_MENU_ITEMS);

if (isFav && associatedBitmapStore)
{
auto img = associatedBitmapStore->getImage(IDB_FAVORITE_MENU_ICON);
Expand Down Expand Up @@ -1068,7 +1079,11 @@ bool PatchSelector::populatePatchMenuForCategory(int c, juce::PopupMenu &context

if (!single_category)
{
contextMenu.addSubMenu(name, *subMenu, true, nullptr, amIChecked);
if (amIChecked)
contextMenu.addSubMenu(name, *subMenu, true, nullptr, amIChecked,
ID_TO_PRESELECT_MENU_ITEMS);
else
contextMenu.addSubMenu(name, *subMenu, true, nullptr, amIChecked);
}

main_e++;
Expand Down

0 comments on commit 0189187

Please sign in to comment.