bigtext 0.19.1

Free editor for huge text and log files (1-50+ GB): opens them without loading them into memory, 4 GB/s search, atomic save
Documentation
//! The system's file dialogs (rfd), owned by BigText's window.
//!
//! A dialog without an owner is a window of its own: a click on BigText put it behind, while
//! BigText waited for it and looked hung (discussion #20). An owned dialog stays in front of
//! BigText, and BigText's window stays out of the way until it is closed.

use std::cell::RefCell;

thread_local! {
    /// A dialog with the window set as its owner, copied for each dialog. rfd keeps the raw
    /// window handle, and the window lives as long as the app.
    static OWNED: RefCell<Option<rfd::FileDialog>> = const { RefCell::new(None) };
}

/// Notes the window that file dialogs belong to (each frame; only the first one counts).
pub fn remember(frame: &eframe::Frame) {
    OWNED.with(|o| {
        let mut o = o.borrow_mut();
        if o.is_none() {
            *o = Some(rfd::FileDialog::new().set_parent(frame));
        }
    });
}

/// A file dialog owned by BigText's window (on another thread, or before the first frame, one
/// of its own, as before).
pub fn file() -> rfd::FileDialog {
    OWNED.with(|o| o.borrow().clone()).unwrap_or_default()
}