mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
On macOS, add documentEdited APIs (#2550)
* On macOS, add documentEdited APIs
Port of 33fdeab629
* Update src/platform/macos.rs
Co-authored-by: Mads Marquart <mads@marquart.dk>
* typo
Co-authored-by: Mads Marquart <mads@marquart.dk>
This commit is contained in:
parent
6d0cf6a275
commit
f77f858e9b
|
@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
|||
|
||||
# Unreleased
|
||||
|
||||
- On macOS, add `WindowExtMacOS::is_document_edited` and `WindowExtMacOS::set_document_edited` APIs.
|
||||
- **Breaking:** Removed `WindowBuilderExtIOS::with_root_view_class`; instead, you should use `[[view layer] addSublayer: ...]` to add an instance of the desired layer class (e.g. `CAEAGLLayer` or `CAMetalLayer`). See `vulkano-win` or `wgpu` for examples of this.
|
||||
- On MacOS and Windows, add `Window::set_content_protected`.
|
||||
- On MacOS, add `EventLoopBuilderExtMacOS::with_activate_ignoring_other_apps`.
|
||||
|
|
|
@ -36,6 +36,25 @@ pub trait WindowExtMacOS {
|
|||
|
||||
/// Sets whether or not the window has shadow.
|
||||
fn set_has_shadow(&self, has_shadow: bool);
|
||||
|
||||
/// Get the window's edit state.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// WindowEvent::CloseRequested => {
|
||||
/// if window.is_document_edited() {
|
||||
/// // Show the user a save pop-up or similar
|
||||
/// } else {
|
||||
/// // Close the window
|
||||
/// drop(window);
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
fn is_document_edited(&self) -> bool;
|
||||
|
||||
/// Put the window in a state which indicates a file save is required.
|
||||
fn set_document_edited(&self, edited: bool);
|
||||
}
|
||||
|
||||
impl WindowExtMacOS for Window {
|
||||
|
@ -68,6 +87,16 @@ impl WindowExtMacOS for Window {
|
|||
fn set_has_shadow(&self, has_shadow: bool) {
|
||||
self.window.set_has_shadow(has_shadow)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_document_edited(&self) -> bool {
|
||||
self.window.is_document_edited()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_document_edited(&self, edited: bool) {
|
||||
self.window.set_document_edited(edited)
|
||||
}
|
||||
}
|
||||
|
||||
/// Corresponds to `NSApplicationActivationPolicy`.
|
||||
|
|
|
@ -168,6 +168,9 @@ extern_methods!(
|
|||
#[sel(setLevel:)]
|
||||
pub fn setLevel(&self, level: NSWindowLevel);
|
||||
|
||||
#[sel(setDocumentEdited:)]
|
||||
pub fn setDocumentEdited(&self, val: bool);
|
||||
|
||||
#[sel(occlusionState)]
|
||||
pub fn occlusionState(&self) -> NSWindowOcclusionState;
|
||||
|
||||
|
@ -186,6 +189,9 @@ extern_methods!(
|
|||
#[sel(isZoomed)]
|
||||
pub fn isZoomed(&self) -> bool;
|
||||
|
||||
#[sel(isDocumentEdited)]
|
||||
pub fn isDocumentEdited(&self) -> bool;
|
||||
|
||||
#[sel(close)]
|
||||
pub fn close(&self);
|
||||
|
||||
|
|
|
@ -1229,6 +1229,14 @@ impl WindowExtMacOS for WinitWindow {
|
|||
fn set_has_shadow(&self, has_shadow: bool) {
|
||||
self.setHasShadow(has_shadow)
|
||||
}
|
||||
|
||||
fn is_document_edited(&self) -> bool {
|
||||
self.isDocumentEdited()
|
||||
}
|
||||
|
||||
fn set_document_edited(&self, edited: bool) {
|
||||
self.setDocumentEdited(edited)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn get_ns_theme() -> Theme {
|
||||
|
|
Loading…
Reference in a new issue