objc2_finder_sync/generated/
mod.rs

1// This file has been automatically generated by `objc2`'s `header-translator`.
2// DO NOT EDIT
3
4#![allow(unused_imports)]
5#![allow(deprecated)]
6#![allow(non_snake_case)]
7#![allow(non_camel_case_types)]
8#![allow(non_upper_case_globals)]
9#![allow(missing_docs)]
10#![allow(clippy::too_many_arguments)]
11#![allow(clippy::type_complexity)]
12#![allow(clippy::upper_case_acronyms)]
13#![allow(clippy::identity_op)]
14#![allow(clippy::missing_safety_doc)]
15#![allow(clippy::doc_lazy_continuation)]
16#![allow(rustdoc::broken_intra_doc_links)]
17#![allow(rustdoc::bare_urls)]
18#![allow(rustdoc::invalid_html_tags)]
19
20#[link(name = "FinderSync", kind = "framework")]
21extern "C" {}
22
23use core::ffi::*;
24use core::ptr::NonNull;
25use objc2::__framework_prelude::*;
26#[cfg(feature = "objc2-app-kit")]
27use objc2_app_kit::*;
28use objc2_foundation::*;
29
30use crate::*;
31
32extern_class!(
33    /// A controller that acts as a bridge between your Finder Sync extension and the Finder itself.
34    ///
35    /// Use the Finder Sync controller to configure your extension, to set badges
36    /// on items in the Finder’s window, and to get a list of selected and targeted
37    /// items.
38    ///
39    /// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fifindersynccontroller?language=objc)
40    #[unsafe(super(NSExtensionContext, NSObject))]
41    #[derive(Debug, PartialEq, Eq, Hash)]
42    pub struct FIFinderSyncController;
43);
44
45extern_conformance!(
46    unsafe impl NSObjectProtocol for FIFinderSyncController {}
47);
48
49impl FIFinderSyncController {
50    extern_methods!(
51        /// Returns the shared Finder Sync controller object.
52        ///
53        /// - Returns: The default Finder Sync controller object for this extension.
54        #[unsafe(method(defaultController))]
55        #[unsafe(method_family = none)]
56        pub unsafe fn defaultController() -> Retained<Self>;
57
58        /// The directories managed by this extension.
59        ///
60        /// The extension receives
61        /// ``FIFinderSync/beginObservingDirectoryAtURL:`` and
62        /// ``FIFinderSync/endObservingDirectoryAtURL:`` messages for every
63        /// directory in this set and for all of their subdirectories.
64        ///
65        /// Always set `directoryURLs` when the extension starts. If there are no
66        /// directories to watch, set `directoryURLs` to an empty set.
67        #[unsafe(method(directoryURLs))]
68        #[unsafe(method_family = none)]
69        pub unsafe fn directoryURLs(&self) -> Retained<NSSet<NSURL>>;
70
71        /// Setter for [`directoryURLs`][Self::directoryURLs].
72        ///
73        /// This is [copied][objc2_foundation::NSCopying::copy] when set.
74        #[unsafe(method(setDirectoryURLs:))]
75        #[unsafe(method_family = none)]
76        pub unsafe fn setDirectoryURLs(&self, directory_ur_ls: Option<&NSSet<NSURL>>);
77
78        #[cfg(feature = "objc2-app-kit")]
79        /// Sets the badge image and label for the given ID.
80        ///
81        /// Use this method to configure your badges. Finder may display the image, the
82        /// label or both. Your Finder Sync extension typically sets up a fixed number
83        /// of badges during its `init` method.
84        ///
85        /// - Parameters:
86        /// - image: An
87        /// <doc
88        /// ://com.apple.documentation/documentation/appkit/nsimage>
89        /// object. The system may or may not draw this image on top of the item’s
90        /// icon; when it does, the system determines the overlay position. Don't
91        /// add any padding to the image to adjust this positioning. The image draws
92        /// at up to 320 x 320 points.
93        /// - label: A label describing the sync state represented by this badge.
94        /// Each label should be a short localized string, such as "Waiting."
95        /// - badgeID: A unique ID, identifying this badge.
96        #[unsafe(method(setBadgeImage:label:forBadgeIdentifier:))]
97        #[unsafe(method_family = none)]
98        pub unsafe fn setBadgeImage_label_forBadgeIdentifier(
99            &self,
100            image: &NSImage,
101            label: Option<&NSString>,
102            badge_id: &NSString,
103        );
104
105        /// Sets the badge for a file or directory.
106        ///
107        /// Adds the specified badge to the given file or directory. Setting the
108        /// identifier to an empty string (`
109        /// "
110        /// "`) removes the badge.
111        ///
112        /// Avoid adding badges to items that the Finder hasn't displayed yet.
113        /// When setting the initial badge, call this method from your Finder Sync
114        /// extension’s ``FIFinderSync/requestBadgeIdentifierForURL:``
115        /// method. When updating badges, call this method only for items that have
116        /// already received a badge.
117        ///
118        /// - Parameters:
119        /// - badgeID: A unique ID, identifying the badge.
120        /// - url: The URL of the file or directory.
121        ///
122        /// ## See Also
123        /// - ``FIFinderSync/requestBadgeIdentifierForURL:``
124        #[unsafe(method(setBadgeIdentifier:forURL:))]
125        #[unsafe(method_family = none)]
126        pub unsafe fn setBadgeIdentifier_forURL(&self, badge_id: &NSString, url: &NSURL);
127
128        /// Returns the URL of the Finder’s current target.
129        ///
130        /// Use this method when creating a custom shortcut menu for the Finder. This
131        /// returns the URL of the item that the user Control-clicked, letting you
132        /// customize the menu for that item.
133        ///
134        /// This method returns valid values only from the Finder Sync extension’s
135        /// ``FIFinderSync/menuForMenuKind:`` method or from one of the menu
136        /// actions created in this method. If the selected items are outside the
137        /// extension’s managed directories (for example, when the user clicks on the
138        /// toolbar button), this method returns `nil`.
139        ///
140        /// - Returns: The URL of the Finder’s current target.
141        #[unsafe(method(targetedURL))]
142        #[unsafe(method_family = none)]
143        pub unsafe fn targetedURL(&self) -> Option<Retained<NSURL>>;
144
145        /// Returns an array of selected items.
146        ///
147        /// Use this method when creating a shortcut menu or a menu for the extension’s
148        /// toolbar button. You can then modify the menu’s content based on the items
149        /// currently selected.
150        ///
151        /// This method returns valid values only from the Finder Sync extension’s
152        /// ``FIFinderSync/menuForMenuKind:`` method or from one of the menu
153        /// actions created in this method. If the selected items are outside the
154        /// extension’s managed directories (for example, when the user clicks on the
155        /// toolbar button), this method returns `nil`.
156        ///
157        /// - Returns: An array of items currently selected in the Finder window.
158        #[unsafe(method(selectedItemURLs))]
159        #[unsafe(method_family = none)]
160        pub unsafe fn selectedItemURLs(&self) -> Option<Retained<NSArray<NSURL>>>;
161
162        #[unsafe(method(lastUsedDateForItemWithURL:))]
163        #[unsafe(method_family = none)]
164        pub unsafe fn lastUsedDateForItemWithURL(
165            &self,
166            item_url: &NSURL,
167        ) -> Option<Retained<NSDate>>;
168
169        #[cfg(feature = "block2")]
170        #[unsafe(method(setLastUsedDate:forItemWithURL:completion:))]
171        #[unsafe(method_family = none)]
172        pub unsafe fn setLastUsedDate_forItemWithURL_completion(
173            &self,
174            last_used_date: &NSDate,
175            item_url: &NSURL,
176            completion: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
177        );
178
179        #[unsafe(method(tagDataForItemWithURL:))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn tagDataForItemWithURL(&self, item_url: &NSURL) -> Option<Retained<NSData>>;
182
183        #[cfg(feature = "block2")]
184        #[unsafe(method(setTagData:forItemWithURL:completion:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn setTagData_forItemWithURL_completion(
187            &self,
188            tag_data: Option<&NSData>,
189            item_url: &NSURL,
190            completion: &block2::DynBlock<dyn Fn(NonNull<NSError>)>,
191        );
192
193        #[unsafe(method(isExtensionEnabled))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn isExtensionEnabled() -> bool;
196
197        #[unsafe(method(showExtensionManagementInterface))]
198        #[unsafe(method_family = none)]
199        pub unsafe fn showExtensionManagementInterface();
200    );
201}
202
203/// Methods declared on superclass `NSObject`.
204impl FIFinderSyncController {
205    extern_methods!(
206        #[unsafe(method(init))]
207        #[unsafe(method_family = init)]
208        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
209
210        #[unsafe(method(new))]
211        #[unsafe(method_family = new)]
212        pub unsafe fn new() -> Retained<Self>;
213    );
214}
215
216/// The different kinds of custom menus that the Finder Sync extension can
217/// provide.
218///
219/// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fimenukind?language=objc)
220// NS_ENUM
221#[repr(transparent)]
222#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
223pub struct FIMenuKind(pub NSUInteger);
224impl FIMenuKind {
225    /// A shortcut menu created when the user control-clicks on an item or a
226    /// group of selected items inside the Finder window.
227    #[doc(alias = "FIMenuKindContextualMenuForItems")]
228    pub const ContextualMenuForItems: Self = Self(0);
229    /// A shortcut menu created when the user control-clicks on the Finder
230    /// window’s background.
231    #[doc(alias = "FIMenuKindContextualMenuForContainer")]
232    pub const ContextualMenuForContainer: Self = Self(1);
233    /// A shortcut menu created when the user control-clicks on an item in the
234    /// sidebar.
235    #[doc(alias = "FIMenuKindContextualMenuForSidebar")]
236    pub const ContextualMenuForSidebar: Self = Self(2);
237    /// A menu created when the user clicks on the extension’s toolbar button.
238    #[doc(alias = "FIMenuKindToolbarItemMenu")]
239    pub const ToolbarItemMenu: Self = Self(3);
240}
241
242unsafe impl Encode for FIMenuKind {
243    const ENCODING: Encoding = NSUInteger::ENCODING;
244}
245
246unsafe impl RefEncode for FIMenuKind {
247    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
248}
249
250extern_protocol!(
251    /// The group of methods to implement for modifying the Finder user interface to express file synchronization status and control.
252    ///
253    /// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fifindersyncprotocol?language=objc)
254    #[doc(alias = "FIFinderSync")]
255    #[name = "FIFinderSync"]
256    pub unsafe trait FIFinderSyncProtocol {
257        #[cfg(feature = "objc2-app-kit")]
258        /// Requests a custom menu from the extension.
259        ///
260        /// Override this method to provide custom menus in the Finder. You can
261        /// customize this menu based both on the menu’s kind and on the selected and
262        /// targeted items (if any). You can get the selected and targeted items from
263        /// the extension’s ``FIFinderSyncController``.
264        ///
265        /// If `kind` is ``FIMenuKindToolbarItemMenu``, the system always calls this
266        /// method even if the target and selection are not related to the extension.
267        ///
268        /// The extension's principal object provides a method for each menu item's
269        /// assigned action.
270        ///
271        /// - Parameters:
272        /// - menu: The type of menu being displayed. For a list of possible values, see ``FinderSync/FIMenuKind``.
273        ///
274        /// - Returns: A custom menu.
275        ///
276        /// ## See Also
277        /// - ``FinderSync/FIFinderSyncController/targetedURL``
278        /// - ``FinderSync/FIFinderSyncController/selectedItemURLs``
279        #[optional]
280        #[unsafe(method(menuForMenuKind:))]
281        #[unsafe(method_family = none)]
282        unsafe fn menuForMenuKind(
283            &self,
284            menu: FIMenuKind,
285            mtm: MainThreadMarker,
286        ) -> Option<Retained<NSMenu>>;
287
288        /// Tells the extension that the user is looking at a monitored directory or at
289        /// one of its subdirectories.
290        ///
291        /// Override this method to receive notifications when the user opens the
292        /// contents of a monitored directory or one of its subdirectories in the
293        /// Finder. The system calls `beginObservingDirectoryAtURL:` only once for each
294        /// unique URL. As long as the content remains visible in at least one Finder
295        /// window, any additional Finder windows that open to the same URL are ignored.
296        ///
297        /// - Note: The system creates additional instances of your extension for any
298        /// Open and Save dialogs. These extensions receive their own calls to
299        /// `beginObservingDirectoryAtURL:`, even if the directory is already open in a
300        /// Finder window.
301        ///
302        /// - Parameters:
303        /// - url: The URL of the directory.
304        #[optional]
305        #[unsafe(method(beginObservingDirectoryAtURL:))]
306        #[unsafe(method_family = none)]
307        unsafe fn beginObservingDirectoryAtURL(&self, url: &NSURL);
308
309        /// Tells the extension that the user has stopped looking at a monitored
310        /// directory or at one of its subdirectories.
311        ///
312        /// Override this method to receive notifications when the user is no longer
313        /// looking at the contents of the given URL. As with
314        /// ``FIFinderSync/beginObservingDirectoryAtURL:``, the Open and Save
315        /// dialogs are tracked separately from the Finder.
316        ///
317        /// - Parameters:
318        /// - url: The URL of the directory.
319        #[optional]
320        #[unsafe(method(endObservingDirectoryAtURL:))]
321        #[unsafe(method_family = none)]
322        unsafe fn endObservingDirectoryAtURL(&self, url: &NSURL);
323
324        /// Requests a badge for the given file or directory.
325        ///
326        /// Override this method to receive notifications whenever a new item becomes
327        /// visible in the Finder. Check the item’s state, and call
328        /// ``FIFinderSyncController/setBadgeIdentifier:forURL:`` to set an appropriate
329        /// badge.
330        ///
331        /// - Parameters:
332        /// - url: The URL of a file or directory inside the extension’s monitored
333        /// directories.
334        ///
335        /// ## See Also
336        /// - ``FinderSync/FIFinderSyncController/setBadgeIdentifier:forURL:``
337        #[optional]
338        #[unsafe(method(requestBadgeIdentifierForURL:))]
339        #[unsafe(method_family = none)]
340        unsafe fn requestBadgeIdentifierForURL(&self, url: &NSURL);
341
342        /// The name of the extension’s toolbar button.
343        ///
344        /// To add a toolbar item to the Finder, override the getter method for the
345        /// toolbar image, name, and tooltip properties.
346        #[optional]
347        #[unsafe(method(toolbarItemName))]
348        #[unsafe(method_family = none)]
349        unsafe fn toolbarItemName(&self) -> Retained<NSString>;
350
351        #[cfg(feature = "objc2-app-kit")]
352        /// The image for the extension’s toolbar button.
353        ///
354        /// To add a toolbar item to the Finder, override the getter method for the
355        /// toolbar image, name, and tooltip properties.
356        #[optional]
357        #[unsafe(method(toolbarItemImage))]
358        #[unsafe(method_family = none)]
359        unsafe fn toolbarItemImage(&self) -> Retained<NSImage>;
360
361        /// The tooltip text for the extension’s toolbar button.
362        ///
363        /// To add a toolbar item to the Finder, override the getter method for the
364        /// toolbar image, name, and tooltip properties.
365        #[optional]
366        #[unsafe(method(toolbarItemToolTip))]
367        #[unsafe(method_family = none)]
368        unsafe fn toolbarItemToolTip(&self) -> Retained<NSString>;
369
370        #[optional]
371        #[unsafe(method(supportedServiceNamesForItemWithURL:))]
372        #[unsafe(method_family = none)]
373        unsafe fn supportedServiceNamesForItemWithURL(
374            &self,
375            item_url: &NSURL,
376        ) -> Retained<NSArray<NSFileProviderServiceName>>;
377
378        #[optional]
379        #[unsafe(method(makeListenerEndpointForServiceName:itemURL:andReturnError:_))]
380        #[unsafe(method_family = none)]
381        unsafe fn makeListenerEndpointForServiceName_itemURL_andReturnError(
382            &self,
383            service_name: &NSFileProviderServiceName,
384            item_url: &NSURL,
385        ) -> Result<Retained<NSXPCListenerEndpoint>, Retained<NSError>>;
386
387        #[cfg(feature = "block2")]
388        #[optional]
389        #[unsafe(method(valuesForAttributes:forItemWithURL:completion:))]
390        #[unsafe(method_family = none)]
391        unsafe fn valuesForAttributes_forItemWithURL_completion(
392            &self,
393            attributes: &NSArray<NSURLResourceKey>,
394            item_url: &NSURL,
395            completion: &block2::DynBlock<
396                dyn Fn(NonNull<NSDictionary<NSURLResourceKey, AnyObject>>, *mut NSError),
397            >,
398        );
399    }
400);
401
402extern_class!(
403    /// A type to subclass to add badges, custom shortcut menus, and toolbar buttons to the Finder.
404    ///
405    /// Subclass the FIFinderSync class when you want to customize the appearance of
406    /// the Finder. Although the FIFinderSync class doesn’t provide any developer
407    /// accessible API, it does adopt the ``FIFinderSyncProtocol``
408    /// protocol. This protocol declares methods you can implement to modify the
409    /// appearance of the Finder. For more information on these methods, see
410    /// ``FIFinderSyncProtocol``. To learn more about creating a Finder Sync
411    /// extension, see [Finder
412    /// Sync](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Finder.html#//apple_ref/doc/uid/TP40014214-CH15)
413    /// in [App Extension Programming
414    /// Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214).
415    ///
416    /// ## See Also
417    /// - ``FinderSync/FIFinderSyncProtocol``
418    ///
419    /// See also [Apple's documentation](https://developer.apple.com/documentation/findersync/fifindersync?language=objc)
420    #[unsafe(super(NSObject))]
421    #[derive(Debug, PartialEq, Eq, Hash)]
422    pub struct FIFinderSync;
423);
424
425extern_conformance!(
426    unsafe impl FIFinderSyncProtocol for FIFinderSync {}
427);
428
429extern_conformance!(
430    unsafe impl NSExtensionRequestHandling for FIFinderSync {}
431);
432
433extern_conformance!(
434    unsafe impl NSObjectProtocol for FIFinderSync {}
435);
436
437impl FIFinderSync {
438    extern_methods!();
439}
440
441/// Methods declared on superclass `NSObject`.
442impl FIFinderSync {
443    extern_methods!(
444        #[unsafe(method(init))]
445        #[unsafe(method_family = init)]
446        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
447
448        #[unsafe(method(new))]
449        #[unsafe(method_family = new)]
450        pub unsafe fn new() -> Retained<Self>;
451    );
452}