Просмотр исходного кода

Piano roll: the scale box opens its menu again after the first click

The FL layout's scale box shows FL's Scale highlighting menu itself (issue #203), so ComboBox's own "menu closed" callback never ran: its menuActive flag stayed set and showPopupIfNotActive() ignored every later click. onPopup now returns the menu and showPopup() shows it with a result callback that calls hidePopup(), as ComboBox does. A core test guards the wiring; a two-click probe on macOS showed the second click did not open the menu before the fix and does after it.
LYNX SHARE contributor 1 неделя назад
Родитель
Сommit
b9546f848e
3 измененных файлов с 29 добавлено и 25 удалено
  1. 2 6
      src/ui/PianoRollComponent.cpp
  2. 9 19
      src/ui/PianoRollComponent.h
  3. 18 0
      tests/Issues190llTests.inc

+ 2 - 6
src/ui/PianoRollComponent.cpp

@@ -417,9 +417,7 @@ PianoRollComponent::PianoRollComponent (AudioEngine& e)
             chordBox.addItem (tr ("Scale degree chord"), degreeStampId);
     }
     chordBox.setSelectedId (1, juce::dontSendNotification);
-    chordBox.onPopup = [this] { // (round 190nu: FL's stamp button opens the Stamp menu; the options of the degree chord on top)
-        stampMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&chordBox).withMinimumWidth (chordBox.getWidth()));
-    };
+    chordBox.onPopup = [this] { return stampMenu(); }; // (round 190nu: FL's stamp button opens the Stamp menu; the options of the degree chord on top)
     chordBox.setTooltip (tr ("Clicking creates this chord (the clicked note is the root)"));
 
     // scale: root x type
@@ -440,9 +438,7 @@ PianoRollComponent::PianoRollComponent (AudioEngine& e)
     scaleSnapButton.setEnabled (false); // until a scale is chosen
     scaleBox.setTooltip (tr ("Highlights the notes of a scale"));
     // issue #203 (round 190ll): the FL layout's click opens FL's Scale highlighting menu (root and scale apart)
-    scaleBox.onPopup = [this] {
-        scaleHighlightMenu().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&scaleBox).withMinimumWidth (scaleBox.getWidth()));
-    };
+    scaleBox.onPopup = [this] { return scaleHighlightMenu(); };
     // docked (Clip-launch: Live's Clip View Scale; Simple: BandLab's Smart View): a root box and a scale box
     for (int root = 0; root < 12; ++root)
         scaleRootBox.addItem (juce::String (notenames::pitchName (root)), root + 1);

+ 9 - 19
src/ui/PianoRollComponent.h

@@ -572,31 +572,21 @@ private:
     {
     public:
         using IconComboBox::IconComboBox;
-        std::function<void()> onPopup;
+        // The menu a click opens instead of the box's item list (issue #203, FL's View › Scale highlighting menu). The box
+        // shows it itself, so it also has to close it: ComboBox::showPopupIfNotActive() marks the box as having a menu
+        // open before showPopup(), and ComboBox clears that mark from the result callback of the menu *it* shows. With a
+        // menu of our own, a click after the first one did nothing (the mark stayed set).
+        std::function<juce::PopupMenu()> onPopup;
         void showPopup() override
         {
-            if (! onPopup)
+            if (onPopup == nullptr)
             {
                 IconComboBox::showPopup();
                 return;
             }
-            onPopup();
-            // issue #242 (round 190od): juce::ComboBox marks its popup active before showPopup() and clears the mark only
-            // in its own menu's callback, so a box whose click opens another menu stayed "active" after that menu
-            // closed and never opened again. The menu onPopup() showed is the modal component now: its end clears it.
-            if (auto* menu = juce::Component::getCurrentlyModalComponent())
-                juce::ModalComponentManager::getInstance()->attachCallback (
-                    menu, juce::ModalCallbackFunction::create ([box = juce::Component::SafePointer<ScaleBox> (this)] (int) {
-                        if (box != nullptr)
-                            box->popupClosed();
-                    }));
-            else
-                popupClosed();
-        }
-        void popupClosed()
-        {
-            if (isPopupActive())
-                hidePopup();
+            const juce::Component::SafePointer<ScaleBox> box (this);
+            onPopup().showMenuAsync (juce::PopupMenu::Options().withTargetComponent (this).withMinimumWidth (getWidth()),
+                                     [box] (int) { if (box != nullptr) box->hidePopup(); });
         }
     };
     // chord created on each click (like FL's "stamp"); round 190nu: a click opens the Stamp menu (FL's stamp button opens

+ 18 - 0
tests/Issues190llTests.inc

@@ -156,3 +156,21 @@ TEST (issues190od_199_blocks_after_the_pattern_wrap_report_its_start)
     w = lynx::hostPositionWrap (s, s.songLength());
     CHECK (! s.loopPlays() || (w.at == (double) (3 * bar) && w.to == (double) bar));
 }
+
+// #203 (round 190ll, follow-up): the FL layout's scale box opens FL's View › Scale highlighting menu itself, not the
+// box's own item list. ComboBox marks the box as having a menu open before showPopup() and clears that mark from the
+// result callback of the menu it shows -- for the box's own menu that callback never ran, so the box ignored every click
+// after the first one (the menu did not open again). The box now closes its own menu through ComboBox::hidePopup().
+// (A real click needs the message loop and the GUI, so this guards the wiring in the source.)
+TEST (issues190ll_203_scale_box_opens_its_menu_again)
+{
+    using namespace i18ntest;
+    const auto header = readFile ("src/ui/PianoRollComponent.h");
+    const auto box = header.find ("class ScaleBox final : public IconComboBox");
+    CHECK (box != std::string::npos);
+    CHECK (header.find ("std::function<juce::PopupMenu()> onPopup;", box) != std::string::npos); // (the menu to open)
+    CHECK (header.find ("onPopup().showMenuAsync", box) != std::string::npos);                   // (the box shows it)
+    CHECK (header.find ("[box] (int) { if (box != nullptr) box->hidePopup(); }", box) != std::string::npos); // (and closes it)
+    CHECK (readFile ("src/ui/PianoRollComponent.cpp")
+               .find ("scaleBox.onPopup = [this] { return scaleHighlightMenu(); };") != std::string::npos);
+}