From e07ba1883989411db42455fbf048f103a15a9547 Mon Sep 17 00:00:00 2001 From: Alexander Iljin Date: Sat, 26 Aug 2017 10:23:18 +0300 Subject: [PATCH] ui: add find-windows to find multiple worlds matching a predicate --- basis/ui/ui-docs.factor | 4 ++++ basis/ui/ui.factor | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/basis/ui/ui-docs.factor b/basis/ui/ui-docs.factor index 29078d5206..4b78687345 100644 --- a/basis/ui/ui-docs.factor +++ b/basis/ui/ui-docs.factor @@ -53,6 +53,10 @@ HELP: fullscreen? { fullscreen? set-fullscreen } related-words +HELP: find-windows +{ $values { "quot" { $quotation ( world -- ? ) } } { "seq" sequence } } +{ $description "Finds all native windows such that the gadget passed to " { $link open-window } " satisfies the quotation, outputting an empty sequence if no such gadget could be found. The front-most native window is the last in the " { $snippet "seq" } "." } ; + HELP: find-window { $values { "quot" { $quotation ( world -- ? ) } } { "world/f" { $maybe world } } } { $description "Finds a native window such that the gadget passed to " { $link open-window } " satisfies the quotation, outputting " { $link f } " if no such gadget could be found. The front-most native window is checked first." } ; diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 6d2739970f..1f1d052a94 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -140,10 +140,13 @@ SYMBOL: ui-running PRIVATE> -: find-window ( quot: ( world -- ? ) -- world/f ) +: find-windows ( quot: ( world -- ? ) -- seq ) [ ui-windows get-global values ] dip '[ dup children>> [ ] [ nip first ] if-empty @ ] - find-last nip ; inline + filter ; inline + +: find-window ( quot: ( world -- ? ) -- world/f ) + find-windows ?last ; inline : ui-running? ( -- ? ) ui-running get-global ;