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