Struct gpui2::ModelContext
source · pub struct ModelContext<'a, T> { /* private fields */ }
Implementations§
source§impl<'a, T: 'static> ModelContext<'a, T>
impl<'a, T: 'static> ModelContext<'a, T>
pub fn entity_id(&self) -> EntityId
pub fn handle(&self) -> Model<T>
pub fn weak_model(&self) -> WeakModel<T>
pub fn observe<W, E>( &mut self, entity: &E, on_notify: impl FnMut(&mut T, E, &mut ModelContext<'_, T>) + 'static ) -> Subscriptionwhere T: 'static, W: 'static, E: Entity<W>,
pub fn subscribe<T2, E, Evt>( &mut self, entity: &E, on_event: impl FnMut(&mut T, E, &Evt, &mut ModelContext<'_, T>) + 'static ) -> Subscriptionwhere T: 'static, T2: 'static + EventEmitter<Evt>, E: Entity<T2>, Evt: 'static,
pub fn on_release( &mut self, on_release: impl FnOnce(&mut T, &mut AppContext) + 'static ) -> Subscriptionwhere T: 'static,
pub fn observe_release<T2, E>( &mut self, entity: &E, on_release: impl FnOnce(&mut T, &mut T2, &mut ModelContext<'_, T>) + 'static ) -> Subscriptionwhere T: Any, T2: 'static, E: Entity<T2>,
pub fn observe_global<G: 'static>( &mut self, f: impl FnMut(&mut T, &mut ModelContext<'_, T>) + 'static ) -> Subscriptionwhere T: 'static,
pub fn on_app_quit<Fut>( &mut self, on_quit: impl FnMut(&mut T, &mut ModelContext<'_, T>) -> Fut + 'static ) -> Subscriptionwhere Fut: 'static + Future<Output = ()>, T: 'static,
pub fn notify(&mut self)
pub fn update_global<G, R>( &mut self, f: impl FnOnce(&mut G, &mut Self) -> R ) -> Rwhere G: 'static,
pub fn spawn<Fut, R>( &self, f: impl FnOnce(WeakModel<T>, AsyncAppContext) -> Fut ) -> Task<R> ⓘwhere T: 'static, Fut: Future<Output = R> + 'static, R: 'static,
source§impl<'a, T> ModelContext<'a, T>
impl<'a, T> ModelContext<'a, T>
pub fn emit<Evt>(&mut self, event: Evt)where T: EventEmitter<Evt>, Evt: 'static,
Methods from Deref<Target = &'a mut AppContext>§
sourcepub fn shutdown(&mut self)
pub fn shutdown(&mut self)
Quit the application gracefully. Handlers registered with ModelContext::on_app_quit
will be given 100ms to complete before exiting.
pub fn quit(&mut self)
pub fn app_metadata(&self) -> AppMetadata
sourcepub fn refresh(&mut self)
pub fn refresh(&mut self)
Schedules all windows in the application to be redrawn. This can be called multiple times in an update cycle and still result in a single redraw.
pub fn observe<W, E>( &mut self, entity: &E, on_notify: impl FnMut(E, &mut AppContext) + 'static ) -> Subscriptionwhere W: 'static, E: Entity<W>,
pub fn observe_internal<W, E>( &mut self, entity: &E, on_notify: impl FnMut(E, &mut AppContext) -> bool + 'static ) -> Subscriptionwhere W: 'static, E: Entity<W>,
pub fn subscribe<T, E, Evt>( &mut self, entity: &E, on_event: impl FnMut(E, &Evt, &mut AppContext) + 'static ) -> Subscriptionwhere T: 'static + EventEmitter<Evt>, E: Entity<T>, Evt: 'static,
pub fn windows(&self) -> Vec<AnyWindowHandle>
sourcepub fn open_window<V: 'static + Render>(
&mut self,
options: WindowOptions,
build_root_view: impl FnOnce(&mut WindowContext<'_>) -> View<V>
) -> WindowHandle<V>
pub fn open_window<V: 'static + Render>( &mut self, options: WindowOptions, build_root_view: impl FnOnce(&mut WindowContext<'_>) -> View<V> ) -> WindowHandle<V>
Opens a new window with the given option and the root view returned by the given function.
The function is invoked with a WindowContext
, which can be used to interact with window-specific
functionality.
sourcepub fn activate(&self, ignoring_other_apps: bool)
pub fn activate(&self, ignoring_other_apps: bool)
Instructs the platform to activate the application by bringing it to the foreground.
pub fn hide(&self)
pub fn hide_other_apps(&self)
pub fn unhide_other_apps(&self)
sourcepub fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>
pub fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>
Returns the list of currently active displays.
sourcepub fn write_to_clipboard(&self, item: ClipboardItem)
pub fn write_to_clipboard(&self, item: ClipboardItem)
Writes data to the platform clipboard.
sourcepub fn read_from_clipboard(&self) -> Option<ClipboardItem>
pub fn read_from_clipboard(&self) -> Option<ClipboardItem>
Reads data from the platform clipboard.
sourcepub fn write_credentials(
&self,
url: &str,
username: &str,
password: &[u8]
) -> Result<()>
pub fn write_credentials( &self, url: &str, username: &str, password: &[u8] ) -> Result<()>
Writes credentials to the platform keychain.
sourcepub fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>>
pub fn read_credentials(&self, url: &str) -> Result<Option<(String, Vec<u8>)>>
Reads credentials from the platform keychain.
sourcepub fn delete_credentials(&self, url: &str) -> Result<()>
pub fn delete_credentials(&self, url: &str) -> Result<()>
Deletes credentials from the platform keychain.
sourcepub fn open_url(&self, url: &str)
pub fn open_url(&self, url: &str)
Directs the platform’s default browser to open the given URL.
pub fn app_path(&self) -> Result<PathBuf>
pub fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf>
pub fn prompt_for_paths( &self, options: PathPromptOptions ) -> Receiver<Option<Vec<PathBuf>>>
pub fn prompt_for_new_path(&self, directory: &Path) -> Receiver<Option<PathBuf>>
pub fn reveal_path(&self, path: &Path)
pub fn should_auto_hide_scrollbars(&self) -> bool
sourcepub fn to_async(&self) -> AsyncAppContext
pub fn to_async(&self) -> AsyncAppContext
Creates an AsyncAppContext
, which can be cloned and has a static lifetime
so it can be held across await
points.
sourcepub fn background_executor(&self) -> &BackgroundExecutor
pub fn background_executor(&self) -> &BackgroundExecutor
Obtains a reference to the executor, which can be used to spawn futures.
sourcepub fn foreground_executor(&self) -> &ForegroundExecutor
pub fn foreground_executor(&self) -> &ForegroundExecutor
Obtains a reference to the executor, which can be used to spawn futures.
sourcepub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R> ⓘwhere
Fut: Future<Output = R> + 'static,
R: 'static,
pub fn spawn<Fut, R>(&self, f: impl FnOnce(AsyncAppContext) -> Fut) -> Task<R> ⓘwhere Fut: Future<Output = R> + 'static, R: 'static,
Spawns the future returned by the given function on the thread pool. The closure will be invoked with AsyncAppContext, which allows the application state to be accessed across await points.
sourcepub fn defer(&mut self, f: impl FnOnce(&mut AppContext) + 'static)
pub fn defer(&mut self, f: impl FnOnce(&mut AppContext) + 'static)
Schedules the given function to be run at the end of the current effect cycle, allowing entities that are currently on the stack to be returned to the app.
sourcepub fn asset_source(&self) -> &Arc<dyn AssetSource>
pub fn asset_source(&self) -> &Arc<dyn AssetSource>
Accessor for the application’s asset source, which is provided when constructing the App
.
sourcepub fn text_system(&self) -> &Arc<TextSystem>
pub fn text_system(&self) -> &Arc<TextSystem>
Accessor for the text system.
sourcepub fn text_style(&self) -> TextStyle
pub fn text_style(&self) -> TextStyle
The current text style. Which is composed of all the style refinements provided to with_text_style
.
sourcepub fn has_global<G: 'static>(&self) -> bool
pub fn has_global<G: 'static>(&self) -> bool
Check whether a global of the given type has been assigned.
sourcepub fn global<G: 'static>(&self) -> &G
pub fn global<G: 'static>(&self) -> &G
Access the global of the given type. Panics if a global for that type has not been assigned.
sourcepub fn try_global<G: 'static>(&self) -> Option<&G>
pub fn try_global<G: 'static>(&self) -> Option<&G>
Access the global of the given type if a value has been assigned.
sourcepub fn global_mut<G: 'static>(&mut self) -> &mut G
pub fn global_mut<G: 'static>(&mut self) -> &mut G
Access the global of the given type mutably. Panics if a global for that type has not been assigned.
sourcepub fn default_global<G: 'static + Default>(&mut self) -> &mut G
pub fn default_global<G: 'static + Default>(&mut self) -> &mut G
Access the global of the given type mutably. A default value is assigned if a global of this type has not yet been assigned.
sourcepub fn set_global<G: Any>(&mut self, global: G)
pub fn set_global<G: Any>(&mut self, global: G)
Set the value of the global of the given type.
sourcepub fn update_global<G: 'static, R>(
&mut self,
f: impl FnOnce(&mut G, &mut Self) -> R
) -> R
pub fn update_global<G: 'static, R>( &mut self, f: impl FnOnce(&mut G, &mut Self) -> R ) -> R
Update the global of the given type with a closure. Unlike global_mut
, this method provides
your closure with mutable access to the AppContext
and the global simultaneously.
sourcepub fn observe_global<G: 'static>(
&mut self,
f: impl FnMut(&mut Self) + 'static
) -> Subscription
pub fn observe_global<G: 'static>( &mut self, f: impl FnMut(&mut Self) + 'static ) -> Subscription
Register a callback to be invoked when a global of the given type is updated.
pub fn observe_new_views<V: 'static>( &mut self, on_new: impl 'static + Fn(&mut V, &mut ViewContext<'_, V>) ) -> Subscription
pub fn observe_release<E, T>( &mut self, handle: &E, on_release: impl FnOnce(&mut T, &mut AppContext) + 'static ) -> Subscriptionwhere E: Entity<T>, T: 'static,
sourcepub fn bind_keys(&mut self, bindings: impl IntoIterator<Item = KeyBinding>)
pub fn bind_keys(&mut self, bindings: impl IntoIterator<Item = KeyBinding>)
Register key bindings.
sourcepub fn on_action<A: Action>(
&mut self,
listener: impl Fn(&A, &mut Self) + 'static
)
pub fn on_action<A: Action>( &mut self, listener: impl Fn(&A, &mut Self) + 'static )
Register a global listener for actions invoked via the keyboard.
sourcepub fn stop_propagation(&mut self)
pub fn stop_propagation(&mut self)
Event handlers propagate events by default. Call this method to stop dispatching to event handlers with a lower z-index (mouse) or higher in the tree (keyboard). This is the opposite of [propagate]. It’s also possible to cancel a call to [propagate] by calling this method before effects are flushed.
sourcepub fn propagate(&mut self)
pub fn propagate(&mut self)
Action handlers stop propagation by default during the bubble phase of action dispatch dispatching to action handlers higher in the element tree. This is the opposite of [stop_propagation]. It’s also possible to cancel a call to [stop_propagate] by calling this method before effects are flushed.