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

--demo targets for tutorial batch 3 (options and settings): text: and row: (labels, tabs, combo boxes, search fields by their English text or its translation; the control on a Settings label's row), settings / window:<id>, panelmenu:<panel>, devices (the Device View, window-button cells), the Playlist's automation-lane cells (+A, lane points), ui.click peer dx / dy; --demo190qxcheck (src/Demo190qxCheck.inc)

Ka1-S 1 неделя назад
Родитель
Сommit
47e483f08f
4 измененных файлов с 335 добавлено и 2 удалено
  1. 24 0
      docs/DEMO_MODE.md
  2. 165 0
      src/Demo190qxCheck.inc
  3. 9 0
      src/Main.cpp
  4. 137 2
      src/ui/DemoMode.cpp

+ 24 - 0
docs/DEMO_MODE.md

@@ -134,6 +134,30 @@ Also new in round 190pl:
 `LYNX --demo190plcheck <prefix>` runs these against a real window (on a private X server) and writes
 `<prefix>-checks.txt` (files in `<prefix>-files/`); run it with `--lang pt-BR` too.
 
+### Targets of tutorial batch 3 (round 190qx)
+
+No new operation: these are new kinds of **target** for `ui.find`, `ui.click`, `ui.hover` and `ui.drag`, so the videos about
+options and settings record every language from one script.
+
+| Target | What it finds |
+|---|---|
+| `text:<English text>` | A showing label, button (a Settings tab too), combo box or text field whose own text is that English text or its translation (as `menu:` targets: without a trailing `...`). A search field also matches by its hint ("Search an action or a key..."), before and after something is typed in it. LYNX's other windows are searched first (the newest on top), then the main window |
+| `row:<English text>` | The control on that label's row: the nearest combo box, slider, switch or field to the label's right whose height covers the label's middle (a Settings page's rows: `row:Buffer size`, `row:Text size`). A click on a combo box opens its menu, whose items are `menu:` targets |
+| `settings`, `window:<id>` | The Settings window, or another tool window by its key (as `findToolWindow`) |
+| `panelmenu:<panel>` | `playlist`, `channelRack`, `pianoRoll`, `mixer` or `browser`: the panel's Window options button (the arrow at its title: detach, maximize, close, the panel's own options, How to use this...) |
+| `devices` | The Clip-launch layout's detail view (its Device View page). Cells: row 0, column *n* = device card *n*'s window button (card 0 = the chain's first) |
+
+Also:
+
+- **Playlist cells** (with Playlist › Automation lanes on): row `1000 + t` = track *t*'s first automation lane at the 16th
+  *column* (its whole height: `at` y picks the value, top = the highest; a click adds a point); row `2000 + t` = the "+A"
+  button on track *t*'s header (left of its LED; it shows while the pointer is over the header), which opens the add-lane menu.
+- **`ui.click` with `peer: true`** takes `dx` / `dy` (pixels from the `at` point): a list's row below a search field that
+  has no ID.
+
+`LYNX --demo190qxcheck <prefix>` runs these against a real window (on a private X server) and writes
+`<prefix>-checks.txt`; run it with `--lang pt-BR` too.
+
 ### Useful component IDs
 
 | Where | IDs |

+ 165 - 0
src/Demo190qxCheck.inc

@@ -0,0 +1,165 @@
+    // --demo190qxcheck <prefix> (round 190qx): the --demo targets tutorial batch 3 (options and settings) added
+    // (docs/DEMO_MODE.md), run against a real main window on the desktop (a private X server): "text:" (a Settings tab, a
+    // label, a search field by its hint, also once something is typed in it), "row:" (the control on a Settings label's
+    // row), "settings" / "window:<id>" (a tool window), "panelmenu:<panel>" (a panel's Window options button and its menu),
+    // the Playlist's automation-lane cells (row 2000 + t: the "+A" button, row 1000 + t: the lane), "devices" (the Clip-launch
+    // Device View) with its window-button cells, and ui.click "peer" with dx / dy. <prefix>-checks.txt lists the checks;
+    // run it with --lang pt-BR too. Included in the app class of Main.cpp.
+    bool runDemoCheck190qx (const juce::String& prefix)
+    {
+        using namespace lynx;
+        juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
+        juce::String checks;
+        bool allOk = true;
+        const auto check = [&checks, &allOk, &prefix] (const juce::String& what, bool ok) {
+            checks << (ok ? "ok   " : "FAIL ") << what << "\n";
+            allOk = allOk && ok;
+            juce::File (prefix + "-checks.txt").replaceWithText (checks);
+        };
+
+        demo::setActive (true);
+        AudioEngine offline (false);
+        MainComponent ui (offline, false);
+        ui.setSize (1600, 960);
+        ui.addToDesktop (juce::ComponentPeer::windowAppearsOnTaskbar);
+        ui.setTopLeftPosition (0, 0);
+        ui.setVisible (true);
+        const auto settle = [&offline] {
+            for (int round = 0; round < 6; ++round)
+            {
+                for (int k = 0; k < 4; ++k)
+                    offline.dispatchPendingMessages();
+#if JUCE_LINUX || JUCE_WINDOWS
+                for (int i = 0; i < 256 && juce::detail::dispatchNextMessageOnSystemQueue (true); ++i) {}
+#endif
+                juce::Thread::sleep (20);
+            }
+        };
+        const auto settleFor = [&settle] (int ms) {
+            const auto end = juce::Time::getMillisecondCounter() + (juce::uint32) ms;
+            while (juce::Time::getMillisecondCounter() < end)
+                settle();
+        };
+        const auto op = [&ui] (const char* name, juce::var args) -> juce::var {
+            try
+            {
+                return ui.handleDemoOp (name, args);
+            }
+            catch (const std::exception& e)
+            {
+                auto* o = new juce::DynamicObject();
+                o->setProperty ("error", juce::String (e.what()));
+                return o;
+            }
+        };
+        const auto json = [] (const juce::String& text) { return juce::JSON::parse (text); };
+        const auto ok = [] (const juce::var& r) { return ! r.hasProperty ("error"); };
+        const auto why = [] (const juce::var& r) { return r.hasProperty ("error") ? " (" + r["error"].toString() + ")" : juce::String(); };
+        const auto find = [&op, &json] (const juce::String& args) { return op ("ui.find", json (args)); };
+        const auto found = [&find] (const juce::String& target) { return (bool) find ("{\"target\":" + juce::JSON::toString (target) + "}")["found"]; };
+
+        op ("ui.welcome", json (R"({"choice":"fl"})"));
+        offline.setSong (makeNewProject());
+        settle();
+
+        // --- Settings: the window, tabs, labels and rows by their English text ------------------------------------------
+        op ("ui.action", json (R"({"id":"view.settings"})"));
+        settleFor (400);
+        check ("\"settings\" is the Settings window", found ("settings"));
+        check ("\"window:settings\" too", found ("window:settings"));
+        auto r = op ("ui.click", json (R"({"target":"text:Audio"})"));
+        settleFor (300);
+        check ("text:Audio clicks the Audio tab" + why (r), ok (r) && found ("text:Buffer size"));
+        auto f = find (R"({"target":"row:Buffer size"})");
+        check ("row:Buffer size is the combo box on that label's row", (bool) f["found"] && f["control"]["kind"] == "combo");
+        auto label = find (R"({"target":"text:Buffer size"})");
+        check ("and sits to the right of the label, on the same line",
+               (bool) label["found"] && (int) f["control"]["screen"]["x"] > (int) label["control"]["screen"]["x"]
+                   && std::abs ((int) f["control"]["screen"]["y"] - (int) label["control"]["screen"]["y"]) < 12);
+        r = op ("ui.click", json (R"({"target":"text:General"})"));
+        settleFor (300);
+        check ("text:General switches the page" + why (r), ok (r) && found ("row:Text size") && ! found ("text:Buffer size"));
+        r = op ("ui.click", json (R"({"target":"row:Text size"})"));
+        settleFor (300);
+        check ("a click on a row's combo box opens its menu (125 % listed)" + why (r), ok (r) && found ("menu:125 %"));
+        juce::PopupMenu::dismissAllActiveMenus();
+        settle();
+        check ("an unknown text is not found", ! found ("text:No such setting anywhere"));
+        r = op ("ui.type", json (R"({"target":"settings.find","text":"metronome","interval":10})"));
+        settleFor (600);
+        check ("the find box takes typing (ui.type)" + why (r), ok (r));
+        op ("ui.action", json (R"({"id":"view.settings"})"));
+        settleFor (300);
+        check ("Settings closes again", ! found ("settings"));
+
+        // --- a search field by its hint, typed into, and a list row below it (peer click with dy) -------------------------
+        {
+            const juce::String search = "text:Search an action or a key (e.g. \\\"Ctrl+L\\\")";
+            op ("ui.click", json (R"({"target":"menu:Options"})"));
+            settle();
+            op ("ui.click", json (R"({"target":"menu:Manage shortcuts..."})"));
+            settleFor (500);
+            check ("Manage shortcuts: the search field is found by its hint", found (search.replace ("\\\"", "\"")));
+            r = op ("ui.type", json ("{\"target\":\"" + search + "\",\"text\":\"metronome\",\"interval\":10}"));
+            settleFor (500);
+            check ("and still after typing into it" + why (r), ok (r) && found (search.replace ("\\\"", "\"")));
+            check ("the Change button is disabled before a row is selected", ! (bool) find (R"({"target":"text:Change"})")["control"]["enabled"]);
+            r = op ("ui.click", json ("{\"target\":\"" + search + "\",\"peer\":true,\"at\":{\"x\":0.3,\"y\":0.5},\"dy\":40}"));
+            settleFor (400);
+            check ("a peer click 40 px under the field selects the first row (Change enabled)" + why (r),
+                   ok (r) && (bool) find (R"({"target":"text:Change"})")["control"]["enabled"]);
+            op ("ui.action", json (R"({"id":"view.closeWindows"})"));
+            settleFor (300);
+        }
+
+        // --- a panel's Window options button and the Playlist's automation lanes ------------------------------------------
+        op ("ui.show", json (R"({"panel":"playlist"})"));
+        settle();
+        f = find (R"({"target":"panelmenu:playlist"})");
+        check ("panelmenu:playlist is the Playlist's Window options button", (bool) f["found"] && f["control"]["kind"] == "button");
+        r = op ("ui.click", json (R"({"target":"panelmenu:playlist"})"));
+        settleFor (300);
+        check ("its menu holds Automation lanes" + why (r), ok (r) && found ("menu:Automation lanes"));
+        r = op ("ui.click", json (R"({"target":"menu:Automation lanes"})"));
+        settleFor (300);
+        check ("which turns the lanes on" + why (r), ok (r) && autolanes::shown());
+        f = find (R"({"target":"playlist","cell":{"row":2000,"column":0}})");
+        check ("cell row 2000 = track 1's +A button (left of its LED)", (bool) f["found"]);
+        offline.editSong ([] (Song& s) { autolanes::addLane (s, 0, { AutomationTargetKind::tempo, 0, 0, 0 }, "Tempo", 0.5f); });
+        settleFor (300);
+        r = op ("ui.click", json (R"({"target":"playlist","cell":{"row":1000,"column":8},"at":{"x":0.5,"y":0.2}})"));
+        settleFor (300);
+        {
+            const auto& song = offline.getSong();
+            const auto a = song.playlistTracks.empty() || song.playlistTracks[0].lanes.empty() ? -1 : song.playlistTracks[0].lanes[0].automation;
+            const auto points = a >= 0 && a < (int) song.automations.size() ? song.automations[(std::size_t) a].points.size() : 0;
+            check ("a click on cell row 1000 adds a point to track 1's lane (" + juce::String ((int) points) + " points)" + why (r), ok (r) && points >= 1);
+        }
+        if (autolanes::shown())
+            autolanes::setShown (false);
+
+        // --- the Clip-launch layout's Device View ------------------------------------------------------------------------
+        op ("ui.layout", json (R"({"style":"clipLaunch"})"));
+        settleFor (500);
+        op ("ui.action", json (R"({"id":"view.detailDevices"})"));
+        settleFor (300);
+        check ("\"devices\" is the Device View", found ("devices"));
+        op ("ui.click", json (R"({"target":"clipGrid","cell":{"row":-2,"column":0}})"));
+        settleFor (300);
+        if (auto* detail = ui.getDetailViewForSnapshot(); detail != nullptr && detail->cardCountForCheck() > 0)
+        {
+            f = find (R"({"target":"devices","cell":{"row":0,"column":0}})");
+            check ("cell row 0 = a device card's window button", (bool) f["found"] && (int) f["control"]["screen"]["width"] > 4);
+        }
+        else
+            check ("(the first track shows no device card: the window-button cell is not checked)", true);
+        op ("ui.layout", json (R"({"style":"pattern"})"));
+        settle();
+
+        check ("the batch 3 targets need no new operation (ui.find / ui.click)", demo::operations().contains ("ui.find"));
+        ui.removeFromDesktop();
+        demo::setActive (false);
+        checks << (allOk ? "ALL OK\n" : "FAILURES\n");
+        juce::File (prefix + "-checks.txt").replaceWithText (checks);
+        return allOk;
+    }

+ 9 - 0
src/Main.cpp

@@ -3157,6 +3157,14 @@ public:
             return;
         }
 
+        if (args.contains ("--demo190qxcheck"))
+        {
+            // LYNX --demo190qxcheck prefix: round 190qx, the --demo targets of tutorial batch 3 (src/Demo190qxCheck.inc)
+            const auto i = args.indexOf ("--demo190qxcheck");
+            setApplicationReturnValue (runDemoCheck190qx (args[i + 1].unquoted()) ? 0 : 1);
+            quit();
+            return;
+        }
         if (args.contains ("--demo190plcheck"))
         {
             // LYNX --demo190plcheck prefix: round 190pl, the --demo operations of tutorial batch 2 (src/Demo190plCheck.inc)
@@ -21416,6 +21424,7 @@ private:
 #include "OnboardShot190np.inc" // round 190np
 #include "Demo190pgCheck.inc" // round 190pg
 #include "Demo190plCheck.inc" // round 190pl
+#include "Demo190qxCheck.inc" // round 190qx
 #include "AutoLinks190ovCheck.inc" // round 190ov (FL automation clips linked to several controls)
     // --trackautoshot190gz (round 190gz): see the dispatch above
     bool runTrackAutoShot190gz (const juce::String& prefix)

+ 137 - 2
src/ui/DemoMode.cpp

@@ -26,6 +26,7 @@
 #include "ui/MainComponent.h"
 #include "ui/MixerComponent.h"
 #include "ui/PolyEditor.h"
+#include "ui/ToolWindow.h"
 
 namespace lynx
 {
@@ -232,6 +233,96 @@ juce::Component* findInOtherWindows (juce::Component& window, const juce::String
     return nullptr;
 }
 
+// Round 190qx: "text:<English text>" is a showing label, button (a Settings tab too) or combo box whose own text is that
+// English text or its translation (so one script records every language, as menu: targets); "row:<English text>" is the
+// control on that label's row (the combo box, slider, switch or field to its right, as a Settings page lays them out).
+// LYNX's other windows are searched first (the newest on top: Settings, dialogs), then the main window.
+juce::String ownText (juce::Component& c)
+{
+    if (auto* label = dynamic_cast<juce::Label*> (&c))
+        return label->getText();
+    if (auto* button = dynamic_cast<juce::Button*> (&c))
+        return button->getButtonText();
+    if (auto* box = dynamic_cast<juce::ComboBox*> (&c))
+        return box->getText();
+    if (auto* field = dynamic_cast<juce::TextEditor*> (&c)) // (an empty search field by the hint it shows)
+        return field->isEmpty() ? field->getTextToShowWhenEmpty() : field->getText();
+    return {};
+}
+
+juce::Component* findTextIn (juce::Component& root, const juce::String& english, const juce::String& translated)
+{
+    for (auto* c : root.getChildren())
+    {
+        if (! c->isVisible() || c->getLocalBounds().isEmpty())
+            continue;
+        if (const auto t = menuText (ownText (*c)); t.isNotEmpty() && (t == translated || t == english))
+            return c;
+        if (auto* field = dynamic_cast<juce::TextEditor*> (c)) // (a search field by its hint, also once something is typed in it)
+            if (const auto hint = menuText (field->getTextToShowWhenEmpty()); hint.isNotEmpty() && (hint == translated || hint == english))
+                return c;
+        if (auto* inner = findTextIn (*c, english, translated))
+            return inner;
+    }
+    return nullptr;
+}
+
+juce::Component* findByText (juce::Component& window, const juce::String& englishText, bool row)
+{
+    const auto raw = englishText.trim();
+    const auto english = menuText (raw), translated = menuText (tr (raw));
+    juce::Component* found = nullptr;
+    auto& desktop = juce::Desktop::getInstance();
+    for (int i = desktop.getNumComponents(); --i >= 0 && found == nullptr;)
+        if (auto* top = desktop.getComponent (i); top != nullptr && top != window.getTopLevelComponent() && top->isShowing())
+            found = findTextIn (*top, english, translated);
+    if (found == nullptr)
+        found = findTextIn (window, english, translated);
+    if (found == nullptr || ! row)
+        return found;
+    // the row: the nearest control to the label's right whose height covers the label's middle
+    auto* parent = found->getParentComponent();
+    if (parent == nullptr)
+        return nullptr;
+    const auto from = found->getBounds();
+    juce::Component* best = nullptr;
+    for (auto* c : parent->getChildren())
+    {
+        if (c == found || ! c->isVisible() || dynamic_cast<juce::Label*> (c) != nullptr || c->getBounds().isEmpty())
+            continue;
+        const auto b = c->getBounds();
+        if (b.getX() >= from.getX() + 4 && b.getY() <= from.getCentreY() && b.getBottom() >= from.getCentreY()
+            && (best == nullptr || b.getX() < best->getX()))
+            best = c;
+    }
+    return best;
+}
+
+// Round 190qx: a panel's "Window options" button (the menu at its title: detach, maximize, close, the panel's own options,
+// How to use this...), found from the panel upwards by the button's tooltip
+juce::Component* findWithTooltip (juce::Component& root, const juce::String& tip)
+{
+    for (auto* c : root.getChildren())
+    {
+        if (! c->isVisible())
+            continue;
+        if (auto* b = dynamic_cast<juce::Button*> (c); b != nullptr && b->getTooltip() == tip)
+            return c;
+        if (auto* inner = findWithTooltip (*c, tip))
+            return inner;
+    }
+    return nullptr;
+}
+
+juce::Component* panelMenuButton (juce::Component* panel)
+{
+    const auto tip = tr ("Window options: detach, maximize, close and this panel's own settings");
+    for (auto* up = panel != nullptr ? panel->getParentComponent() : nullptr; up != nullptr; up = up->getParentComponent())
+        if (auto* b = findWithTooltip (*up, tip))
+            return b;
+    return nullptr;
+}
+
 // Round 190pl: a press, moves and a release delivered through a LYNX window's peer, as the system's mouse events arrive
 // (ComponentPeer::handleMouseEvent; nothing reaches the operating system): what is on top at each point gets them, a
 // drag that starts a drag-and-drop (a loop onto the timeline, a plugin onto a slot) drops on what is under its end, a
@@ -445,6 +536,26 @@ juce::var MainComponent::handleDemoOp (const juce::String& op, const juce::var&
     const auto locate = [&window] (const juce::String& target) -> juce::Component* {
         if (target.startsWith ("menu:"))
             return findMenuItem (window, target.substring (5));
+        if (target.startsWith ("text:") || target.startsWith ("row:")) // (round 190qx)
+            return findByText (window, target.fromFirstOccurrenceOf (":", false, false), target.startsWith ("row:"));
+        if (target.startsWith ("panelmenu:")) // (round 190qx: playlist, channelRack, pianoRoll, mixer, browser)
+        {
+            const auto p = target.substring (10);
+            juce::Component* panel = p == "playlist" ? (juce::Component*) &window.playlist : p == "channelRack" ? (juce::Component*) &window.rack
+                                   : p == "pianoRoll" ? (juce::Component*) &window.pianoRoll : p == "mixer" ? (juce::Component*) &window.mixer
+                                   : p == "browser" ? (juce::Component*) &window.browser : nullptr;
+            return panel != nullptr && panel->isShowing() ? panelMenuButton (panel) : nullptr;
+        }
+        if (target == "settings" || target.startsWith ("window:")) // (round 190qx: a tool window by its ID, "settings" for Settings)
+        {
+            auto* w = findToolWindow (target == "settings" ? juce::String ("settings") : target.substring (7));
+            return w != nullptr && w->isShowing() ? w : nullptr;
+        }
+        if (target == "devices") // (round 190qx: the Clip-launch layout's detail view, its Device View page)
+        {
+            auto* detail = window.getDetailViewForSnapshot();
+            return detail != nullptr && detail->isShowing() ? detail : nullptr;
+        }
         if (auto* c = onboardui::findShowing (window, target))
             return c;
         return findInOtherWindows (window, target);
@@ -541,7 +652,24 @@ juce::var MainComponent::handleDemoOp (const juce::String& op, const juce::var&
         }
         else if (&c == &playlist)
         {
-            if (row >= 0 && row < 1000 && column >= 0) // (a new project's Playlist draws its tracks before any of them is stored)
+            // round 190qx (Playlist › Automation lanes): row 1000 + t = track t's first lane at the 16th `column` (its whole
+            // height: "at" y picks the value, top = the highest); row 2000 + t = the "+A" button on t's header (left of its
+            // LED, shown while the pointer is over the header), which opens the add-lane menu
+            if (row >= 1000 && row < 2000 && column >= 0)
+            {
+                const auto body = playlist.laneBodyForSnapshot (row - 1000, 0).toNearestInt();
+                const auto x0 = (int) playlist.xOfTickForSnapshot ((double) column * ticksPerStep);
+                const auto x1 = (int) playlist.xOfTickForSnapshot ((double) (column + 1) * ticksPerStep);
+                if (! body.isEmpty())
+                    r = { x0, body.getY(), juce::jmax (2, x1 - x0), body.getHeight() };
+            }
+            else if (row >= 2000 && row < 3000)
+            {
+                const auto led = playlist.trackLedForSnapshot (row - 2000);
+                if (! led.isEmpty())
+                    r = { led.getX() - 22, led.getCentreY() - 7, 20, 14 };
+            }
+            else if (row >= 0 && row < 1000 && column >= 0) // (a new project's Playlist draws its tracks before any of them is stored)
             {
                 const auto band = playlist.trackRowForSnapshot (row);
                 const auto x0 = (int) playlist.xOfTickForSnapshot ((double) column * ticksPerStep);
@@ -557,6 +685,12 @@ juce::var MainComponent::handleDemoOp (const juce::String& op, const juce::var&
               : row == 3 ? strips.routeArrowForSnapshot (column) : row == 4 ? strips.faderCapForSnapshot (column) : row == 5 ? strips.panAreaForSnapshot (column)
               : row == 6 ? strips.soloAreaForSnapshot (column) : row == 7 ? strips.headerAreaForSnapshot (column) : juce::Rectangle<int>();
         }
+        else if (detailView != nullptr && &c == detailView.get())
+        {
+            // round 190qx: row 0 = device card `column`'s window button (in its title bar; the chain's first card is 0)
+            if (row == 0 && column >= 0 && column < detailView->cardCountForCheck())
+                r = detailView->windowButtonForCheck (column);
+        }
         else if (clipGridView != nullptr && &c == clipGridView.get())
         {
             if (row == -2 && column >= 0) // (the column's title, above its first slot: its right-click menu has Deactivate Track)
@@ -690,7 +824,8 @@ juce::var MainComponent::handleDemoOp (const juce::String& op, const juce::var&
         {
             const auto cell = cellOf (c);
             const auto local = cell ? pointIn (*cell) : pointIn (c.getLocalBounds());
-            const auto screen = c.localPointToGlobal (local);
+            // (round 190qx: "dx" / "dy", pixels from that point: a list's row below a search field that has no ID)
+            const auto screen = c.localPointToGlobal (local) + juce::Point<float> ((float) (double) args["dx"], (float) (double) args["dy"]);
             PeerGesture::click (*c.getTopLevelComponent(), screen, clicks, keysOf (args["mods"]), right);
             return object ({ { "clicked", true }, { "control", described } });
         }