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