Skip to content
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

Useobjc2 v0.6 #236

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## Unreleased
- Update `objc2` to v0.6.

## 0.15.1
- Update `ashpd` to 0.10.
Expand Down
112 changes: 25 additions & 87 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ raw-window-handle = "0.6"
log = "0.4"

[target.'cfg(target_os = "macos")'.dependencies]
block2 = "0.5.0"
objc2 = "0.5.1"
objc2-foundation = { version = "0.2.0", features = [
"dispatch",
block2 = "0.6.0"
dispatch2 = "0.2.0"
objc2 = "0.6.0"
objc2-foundation = { version = "0.3.0", default-features = false, features = [
"std",
"NSArray",
"NSEnumerator",
"NSString",
"NSThread",
"NSURL",
] }
objc2-app-kit = { version = "0.2.0", features = [
objc2-app-kit = { version = "0.3.0", default-features = false, features = [
"std",
"block2",
"NSAlert",
"NSApplication",
Expand All @@ -53,8 +55,14 @@ objc2-app-kit = { version = "0.2.0", features = [
"NSView",
"NSWindow",
] }
core-foundation = "0.10.0"
core-foundation-sys = "0.8.7"
objc2-core-foundation = { version = "0.3.0", default-features = false, features = [
"std",
"CFBase",
"CFDate",
"CFString",
"CFURL",
"CFUserNotification",
] }

[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { version = "0.59", features = [
Expand All @@ -67,7 +75,9 @@ windows-sys = { version = "0.59", features = [

[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
# XDG Desktop Portal
ashpd = { version = "0.10", optional = true, default-features = false, features = ["raw_handle"] }
ashpd = { version = "0.10", optional = true, default-features = false, features = [
"raw_handle",
] }
urlencoding = { version = "2.1.0", optional = true }
pollster = { version = "0.4", optional = true }
# GTK
Expand Down
37 changes: 15 additions & 22 deletions src/backend/macos/file_dialog/panel_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::path::Path;
use std::path::PathBuf;

use block2::Block;
use objc2::rc::Id;

use objc2::rc::Retained;
use objc2::MainThreadMarker;
use objc2_app_kit::{NSModalResponse, NSOpenPanel, NSSavePanel, NSWindow, NSWindowLevel};
use objc2_foundation::{MainThreadMarker, NSArray, NSObjectProtocol, NSString, NSURL};
use objc2_foundation::{NSArray, NSString, NSURL};
use raw_window_handle::RawWindowHandle;

use super::super::{
Expand All @@ -22,14 +22,14 @@ extern "C" {

pub struct Panel {
// Either `NSSavePanel` or the subclass `NSOpenPanel`
pub(crate) panel: Id<NSSavePanel>,
parent: Option<Id<NSWindow>>,
pub(crate) panel: Retained<NSSavePanel>,
parent: Option<Retained<NSWindow>>,
_focus_manager: FocusManager,
_policy_manager: PolicyManager,
}

impl AsModal for Panel {
fn inner_modal(&self) -> &NSSavePanel {
fn inner_modal(&self) -> &(impl InnerModal + 'static) {
&*self.panel
}
}
Expand All @@ -46,17 +46,10 @@ impl InnerModal for NSSavePanel {

impl Panel {
fn as_open_panel(&self) -> Option<&NSOpenPanel> {
if self.panel.is_kind_of::<NSOpenPanel>() {
let ptr: *const NSSavePanel = &*self.panel;
let ptr: *const NSOpenPanel = ptr.cast();
// SAFETY: Just checked that the panel is an `NSOpenPanel`
Some(unsafe { &*ptr })
} else {
None
}
self.panel.downcast_ref::<NSOpenPanel>()
}

pub fn new(panel: Id<NSSavePanel>, parent: Option<&RawWindowHandle>) -> Self {
pub fn new(panel: Retained<NSSavePanel>, parent: Option<&RawWindowHandle>) -> Self {
let _policy_manager = PolicyManager::new(MainThreadMarker::from(&*panel));

let _focus_manager = FocusManager::new(MainThreadMarker::from(&*panel));
Expand Down Expand Up @@ -119,7 +112,7 @@ trait PanelExt {
}

let f_raw: Vec<_> = exts.iter().map(|ext| NSString::from_str(ext)).collect();
let array = NSArray::from_vec(f_raw);
let array = NSArray::from_retained_slice(&f_raw);

unsafe {
#[allow(deprecated)]
Expand Down Expand Up @@ -158,13 +151,13 @@ trait PanelExt {
}
}

impl PanelExt for Id<NSSavePanel> {
impl PanelExt for Retained<NSSavePanel> {
fn panel(&self) -> &NSSavePanel {
&self
}
}

impl PanelExt for Id<NSOpenPanel> {
impl PanelExt for Retained<NSOpenPanel> {
fn panel(&self) -> &NSSavePanel {
&self
}
Expand Down Expand Up @@ -197,7 +190,7 @@ impl Panel {
unsafe { panel.setCanChooseDirectories(false) };
unsafe { panel.setCanChooseFiles(true) };

Self::new(Id::into_super(panel), opt.parent.as_ref())
Self::new(Retained::into_super(panel), opt.parent.as_ref())
}

pub fn build_save_file(opt: &FileDialog, mtm: MainThreadMarker) -> Self {
Expand Down Expand Up @@ -243,7 +236,7 @@ impl Panel {
unsafe { panel.setCanChooseDirectories(true) };
unsafe { panel.setCanChooseFiles(false) };

Self::new(Id::into_super(panel), opt.parent.as_ref())
Self::new(Retained::into_super(panel), opt.parent.as_ref())
}

pub fn build_pick_folders(opt: &FileDialog, mtm: MainThreadMarker) -> Self {
Expand All @@ -264,7 +257,7 @@ impl Panel {
unsafe { panel.setCanChooseFiles(false) };
unsafe { panel.setAllowsMultipleSelection(true) };

Self::new(Id::into_super(panel), opt.parent.as_ref())
Self::new(Retained::into_super(panel), opt.parent.as_ref())
}

pub fn build_pick_files(opt: &FileDialog, mtm: MainThreadMarker) -> Self {
Expand All @@ -290,6 +283,6 @@ impl Panel {
unsafe { panel.setCanChooseFiles(true) };
unsafe { panel.setAllowsMultipleSelection(true) };

Self::new(Id::into_super(panel), opt.parent.as_ref())
Self::new(Retained::into_super(panel), opt.parent.as_ref())
}
}
Loading
Loading