REBOL [ Title: "Face searches" Author: "Brett Handley" Purpose: "Functions that search for faces according to a condition." Date: 24-Jan-2002 Version: 1.0.0 Comment: "Inspired by the find-key-face function." ] find-face: func [ "Search faces - returns first face that satisfies the condition." condition [block! function!] {A function or a function body block - "face" is argument.} /from "Start search at specified face - default is screen-face." face [object!] /local w f result ] [ if not from [face: system/view/screen-face] if block? :condition [condition: func [face] condition] either condition face [face] [ w: in face 'pane either block? w: get w [ result: none foreach f w [if all [object? f f: find-face/from :condition f] [result: f break]] result ] [ if object? :w [find-face/from :condition w] ] ] ] find-faces: func [ "Search faces - returns those that satisfy the condition." condition [block! function!] {A function or a function body block - "face" is argument.} /from "Start search at specified face - default is screen-face." face [object!] /local w f result ] [ if not from [face: system/view/screen-face] if block? :condition [condition: func [face] condition] result: copy [] if condition face [append result face] w: in face 'pane either block? w: get w [ foreach f w [if object? f [append result find-faces/from :condition f]] ] [ if object? :w [append result find-faces/from :condition w] ] result ] find-parent-face: function [ "Search faces - returns first parent where a child face satisfies the condition." condition [block! function!] {A function or a function body block - "face" is argument.} /from "Start search at specified face - default is screen-face." face [object!] ][app-window child w][ if not from [face: system/view/screen-face] child: find-face/from :condition face find-face/from [ all [ face/pane either object? face/pane [face/pane = child][find face/pane child] ] ] face ]