diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-01-16 12:01:32 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-01-16 14:11:11 +0100 |
| commit | 783d379bfaabe8a0eb6fe368bb0ba47c905b1a80 (patch) | |
| tree | 4cbb8d1df7f0451db06d46b20c1b5dd57026c7f2 /src/file_registry.rs | |
| parent | 81cd06b3334f2f91f6a1ab62a28e11c7d0c677eb (diff) | |
Allow for custom stages
Diffstat (limited to 'src/file_registry.rs')
| -rw-r--r-- | src/file_registry.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/file_registry.rs b/src/file_registry.rs index 6ebf986..7f062c8 100644 --- a/src/file_registry.rs +++ b/src/file_registry.rs @@ -5,11 +5,11 @@ use std::cell::RefCell; use std::path::PathBuf; -use relm4::ComponentController; use relm4::component::Controller; use relm4::gtk; use crate::AppModel; +use crate::actions::Action; thread_local! { /// Keeps window controllers alive for the lifetime of each window. @@ -17,6 +17,9 @@ thread_local! { /// Tracks which files are currently open to prevent duplicate windows. static OPEN_FILES: RefCell<Vec<(PathBuf, gtk::Window)>> = const { RefCell::new(Vec::new()) }; + + /// Stores senders for all windows (including main window) to enable broadcasting. + static WINDOW_SENDERS: RefCell<Vec<relm4::Sender<Action>>> = const { RefCell::new(Vec::new()) }; } /// Stores a window controller to keep it alive. @@ -52,11 +55,18 @@ pub fn unregister_file(path: &PathBuf) { }); } -/// Broadcasts a message to all windows. -pub fn broadcast_to_all_windows(message: crate::actions::Action) { - WINDOW_CONTROLLERS.with_borrow(|controllers| { - for controller in controllers { - controller.sender().emit(message.clone()); +/// Registers a window's sender for broadcasting. +pub fn register_sender(sender: relm4::Sender<Action>) { + WINDOW_SENDERS.with_borrow_mut(|senders| { + senders.push(sender); + }); +} + +/// Broadcasts a message to all windows via their registered senders. +pub fn broadcast_to_all_windows(message: Action) { + WINDOW_SENDERS.with_borrow(|senders| { + for sender in senders { + sender.emit(message.clone()); } }); } |