Skip to content

Commit

Permalink
feat(macos): add document edited apis, closes #268 (#287)
Browse files Browse the repository at this point in the history
* Add API for MacOS NSWindow::isDocumentEdited()

This fixes #268 and therefore tauri-apps/tauri#3125

The setter API is added upstream in the cocoa crate
(servo/core-foundation-rs PR #493)

* use objc directly

* fmt

* cast to i8

* Update src/platform/macos.rs
  • Loading branch information
joshchngs authored and amrbashir committed Oct 3, 2022
1 parent e42ff07 commit 33fdeab
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/macos-decoumen-edited.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": patch
---

Add `WindowExtMacOS::is_doucmented_edited` and `WindowExtMacOS::set_is_doucmented_edited` on macOS.
18 changes: 18 additions & 0 deletions src/platform/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ pub trait WindowExtMacOS {

/// Sets whether or not the window has shadow.
fn set_has_shadow(&self, has_shadow: bool);

/// Put the window in a state which indicates a file save is required.
///
/// <https://developer.apple.com/documentation/appkit/nswindow/1419311-isdocumentedited>
fn set_is_document_edited(&self, edited: bool);

/// Get the window's edit state
fn is_document_edited(&self) -> bool;
}

impl WindowExtMacOS for Window {
Expand Down Expand Up @@ -87,6 +95,16 @@ impl WindowExtMacOS for Window {
fn set_has_shadow(&self, has_shadow: bool) {
self.window.set_has_shadow(has_shadow)
}

#[inline]
fn set_is_document_edited(&self, edited: bool) {
self.window.set_is_document_edited(edited)
}

#[inline]
fn is_document_edited(&self) -> bool {
self.window.is_document_edited()
}
}

/// Corresponds to `NSApplicationActivationPolicy`.
Expand Down
13 changes: 13 additions & 0 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,19 @@ impl WindowExtMacOS for UnownedWindow {
.setHasShadow_(if has_shadow { YES } else { NO })
}
}

#[inline]
fn set_is_document_edited(&self, edited: bool) {
unsafe { self.ns_window.setDocumentEdited_(edited as i8) }
}

#[inline]
fn is_document_edited(&self) -> bool {
unsafe {
let is_document_edited: BOOL = msg_send![*self.ns_window, isDocumentEdited];
is_document_edited == YES
}
}
}

impl Drop for UnownedWindow {
Expand Down

0 comments on commit 33fdeab

Please sign in to comment.