Skip to content

Add bindings for NSOpenPanel #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2021
Merged

Conversation

maxbrunsfeld
Copy link
Contributor

This PR adds bindings for the main NSOpenPanel APIs, which let you present a modal for selecting files or directories. Usage:

let panel = NSOpenPanel::openPanel(nil);
panel.setCanChooseDirectories_(YES);
panel.setCanChooseFiles_(NO);
panel.setAllowsMultipleSelection_(YES);

let response = panel.runModal();
if response == NSModalResponse::NSModalResponseOk {
    let urls = panel.URLs();
    for i in 0..urls.count() {
        let url_ptr = urls.objectAtIndex(i).absoluteString().UTF8String();
        let url = CStr::from_ptr(url_ptr).to_string_lossy();
        eprintln!("You picked URL {}", url);
    }
}

@jdm
Copy link
Member

jdm commented Apr 9, 2021

@bors-servo r+
Thanks!

@bors-servo
Copy link
Contributor

📌 Commit 52b7bc0 has been approved by jdm

@bors-servo
Copy link
Contributor

⌛ Testing commit 52b7bc0 with merge e9a65bb...

@bors-servo
Copy link
Contributor

☀️ Test successful - checks-travis
Approved by: jdm
Pushing e9a65bb to master...

@bors-servo bors-servo merged commit e9a65bb into servo:master Apr 9, 2021
@maxbrunsfeld maxbrunsfeld deleted the nsopenpanel branch May 5, 2021 01:54
bors-servo added a commit that referenced this pull request May 5, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
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);
}

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants