Skip to content

Commit 025dcb3

Browse files
authored
Auto merge of #457 - zed-industries:ns-save-panel, r=jrmuizel
Add NSSavePanel binding This PR adds bindings to some basic `NSSavePanel` APIs. In Cocoa, `NSSavePanel` is a superclass of `NSOpenPanel`, which I added bindings for in #454. Example: ```rust let panel = NSSavePanel::savePanel(nil); panel.setDirectoryURL(the_url); let response = panel.runModal(); if response == NSModalResponse::NSModalResponseOk { let url_ptr = panel.URL().absoluteString().UTF8String(); let url = CStr::from_ptr(url_ptr).to_string_lossy(); eprintln!("You picked URL {}", url); } ```
2 parents 3557404 + 39e1e0e commit 025dcb3

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

cocoa/src/appkit.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,36 @@ pub enum NSModalResponse {
17861786
NSModalResponseCancel = 0,
17871787
}
17881788

1789-
pub trait NSOpenPanel: Sized {
1789+
pub trait NSSavePanel: Sized {
1790+
unsafe fn savePanel(_: Self) -> id {
1791+
msg_send![class!(NSSavePanel), savePanel]
1792+
}
1793+
1794+
unsafe fn setDirectoryURL(self, url: id);
1795+
unsafe fn setCanCreateDirectories(self, canCreateDirectories: BOOL);
1796+
unsafe fn URL(self) -> id;
1797+
unsafe fn runModal(self) -> NSModalResponse;
1798+
}
1799+
1800+
impl NSSavePanel for id {
1801+
unsafe fn setDirectoryURL(self, url: id) {
1802+
msg_send![self, setDirectoryURL: url]
1803+
}
1804+
1805+
unsafe fn setCanCreateDirectories(self, canCreateDirectories: BOOL) {
1806+
msg_send![self, setCanCreateDirectories: canCreateDirectories]
1807+
}
1808+
1809+
unsafe fn URL(self) -> id {
1810+
msg_send![self, URL]
1811+
}
1812+
1813+
unsafe fn runModal(self) -> NSModalResponse {
1814+
msg_send![self, runModal]
1815+
}
1816+
}
1817+
1818+
pub trait NSOpenPanel: NSSavePanel {
17901819
unsafe fn openPanel(_: Self) -> id {
17911820
msg_send![class!(NSOpenPanel), openPanel]
17921821
}
@@ -1796,7 +1825,6 @@ pub trait NSOpenPanel: Sized {
17961825
unsafe fn setResolvesAliases_(self, resolvesAliases: BOOL);
17971826
unsafe fn setAllowsMultipleSelection_(self, allowsMultipleSelection: BOOL);
17981827
unsafe fn URLs(self) -> id;
1799-
unsafe fn runModal(self) -> NSModalResponse;
18001828
}
18011829

18021830
impl NSOpenPanel for id {
@@ -1819,10 +1847,6 @@ impl NSOpenPanel for id {
18191847
unsafe fn URLs(self) -> id {
18201848
msg_send![self, URLs]
18211849
}
1822-
1823-
unsafe fn runModal(self) -> NSModalResponse {
1824-
msg_send![self, runModal]
1825-
}
18261850
}
18271851

18281852
#[repr(usize)]

0 commit comments

Comments
 (0)