objc2_app_kit/generated/
NSSavePanel.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6use objc2_foundation::*;
7#[cfg(feature = "objc2-uniform-type-identifiers")]
8#[cfg(target_vendor = "apple")]
9use objc2_uniform_type_identifiers::*;
10
11use crate::*;
12
13extern_class!(
14    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nssavepanel?language=objc)
15    #[unsafe(super(NSPanel, NSWindow, NSResponder, NSObject))]
16    #[derive(Debug, PartialEq, Eq, Hash)]
17    #[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
18    pub struct NSSavePanel;
19);
20
21#[cfg(all(
22    feature = "NSAccessibilityProtocols",
23    feature = "NSPanel",
24    feature = "NSResponder",
25    feature = "NSWindow"
26))]
27unsafe impl NSAccessibility for NSSavePanel {}
28
29#[cfg(all(
30    feature = "NSAccessibilityProtocols",
31    feature = "NSPanel",
32    feature = "NSResponder",
33    feature = "NSWindow"
34))]
35unsafe impl NSAccessibilityElementProtocol for NSSavePanel {}
36
37#[cfg(all(
38    feature = "NSAnimation",
39    feature = "NSPanel",
40    feature = "NSResponder",
41    feature = "NSWindow"
42))]
43unsafe impl NSAnimatablePropertyContainer for NSSavePanel {}
44
45#[cfg(all(
46    feature = "NSAppearance",
47    feature = "NSPanel",
48    feature = "NSResponder",
49    feature = "NSWindow"
50))]
51unsafe impl NSAppearanceCustomization for NSSavePanel {}
52
53#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
54unsafe impl NSCoding for NSSavePanel {}
55
56#[cfg(all(
57    feature = "NSMenu",
58    feature = "NSPanel",
59    feature = "NSResponder",
60    feature = "NSWindow"
61))]
62unsafe impl NSMenuItemValidation for NSSavePanel {}
63
64#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
65unsafe impl NSObjectProtocol for NSSavePanel {}
66
67#[cfg(all(
68    feature = "NSPanel",
69    feature = "NSResponder",
70    feature = "NSUserInterfaceItemIdentification",
71    feature = "NSWindow"
72))]
73unsafe impl NSUserInterfaceItemIdentification for NSSavePanel {}
74
75#[cfg(all(
76    feature = "NSPanel",
77    feature = "NSResponder",
78    feature = "NSUserInterfaceValidation",
79    feature = "NSWindow"
80))]
81unsafe impl NSUserInterfaceValidations for NSSavePanel {}
82
83#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
84impl NSSavePanel {
85    extern_methods!(
86        /// Creates a new instance of the NSSavePanel. This class is not a singleton.
87        #[unsafe(method(savePanel))]
88        #[unsafe(method_family = none)]
89        pub unsafe fn savePanel(mtm: MainThreadMarker) -> Retained<NSSavePanel>;
90
91        /// `NSSavePanel`: Returns the URL to save the file at. A file may already exist at `url` if the user choose to overwrite it.
92        /// `NSOpenPanel`: Returns the single filename selected by the user. Note: if -allowsMultipleSelection is set, you should use the -URLs on NSOpenPanel instead.
93        #[unsafe(method(URL))]
94        #[unsafe(method_family = none)]
95        pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
96
97        #[cfg(feature = "NSUserInterfaceItemIdentification")]
98        /// Sets and returns the identifier.
99        ///
100        /// The panel's current state such as the root directory and the current directory are saved and restored relative to the identifier.
101        /// - Note: When the identifier is changed, the properties that depend on the identifier are updated from user defaults. Properties that have a null value in user defaults are not changed (and keep their existing value).
102        /// - Note: Can only be set during the configuration phase.
103        #[unsafe(method(identifier))]
104        #[unsafe(method_family = none)]
105        pub unsafe fn identifier(&self) -> Option<Retained<NSUserInterfaceItemIdentifier>>;
106
107        #[cfg(feature = "NSUserInterfaceItemIdentification")]
108        /// Setter for [`identifier`][Self::identifier].
109        #[unsafe(method(setIdentifier:))]
110        #[unsafe(method_family = none)]
111        pub unsafe fn setIdentifier(&self, identifier: Option<&NSUserInterfaceItemIdentifier>);
112
113        /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the directory that is displayed. Set to `nil` to display the default directory. This method will not block to resolve the URL, and the directory will asyncronously be set, if required.
114        /// - Note: Can only be set during the configuration phase.
115        #[unsafe(method(directoryURL))]
116        #[unsafe(method_family = none)]
117        pub unsafe fn directoryURL(&self) -> Option<Retained<NSURL>>;
118
119        /// Setter for [`directoryURL`][Self::directoryURL].
120        #[unsafe(method(setDirectoryURL:))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn setDirectoryURL(&self, directory_url: Option<&NSURL>);
123
124        #[cfg(feature = "objc2-uniform-type-identifiers")]
125        #[cfg(target_vendor = "apple")]
126        /// `NSSavePanel`: An array of UTTypes specifying the file types the user can save the file as. Set to `
127        /// @
128        /// []` to specify that any file type can be used. If no extension is given by the user, the first preferred extension from the array will be used as the extension for the save panel. If the user specifies a type not in the array, and `allowsOtherFileTypes` is `YES`, they will be presented with another dialog when prompted to save. The default value is the empty array.
129        /// `NSOpenPanel`: This property determines which files should be enabled in the open panel. Using the deprecated methods to show the open panel (the ones that take a "types:" parameter) will overwrite this value, and should not be used. `allowedContentTypes` can be changed while the panel is running (ie: from an accessory view). This is also known as the "enabled file types". Set to `
130        /// @
131        /// []` to specify that all files should be enabled.
132        #[unsafe(method(allowedContentTypes))]
133        #[unsafe(method_family = none)]
134        pub unsafe fn allowedContentTypes(&self) -> Retained<NSArray<UTType>>;
135
136        #[cfg(feature = "objc2-uniform-type-identifiers")]
137        #[cfg(target_vendor = "apple")]
138        /// Setter for [`allowedContentTypes`][Self::allowedContentTypes].
139        #[unsafe(method(setAllowedContentTypes:))]
140        #[unsafe(method_family = none)]
141        pub unsafe fn setAllowedContentTypes(&self, allowed_content_types: &NSArray<UTType>);
142
143        /// `NSSavePanel`: Returns a BOOL value that indicates whether the panel allows the user to save files with an extension that is not in the list of `allowedFileTypes`.
144        /// `NSOpenPanel`: Not used.
145        #[unsafe(method(allowsOtherFileTypes))]
146        #[unsafe(method_family = none)]
147        pub unsafe fn allowsOtherFileTypes(&self) -> bool;
148
149        /// Setter for [`allowsOtherFileTypes`][Self::allowsOtherFileTypes].
150        #[unsafe(method(setAllowsOtherFileTypes:))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn setAllowsOtherFileTypes(&self, allows_other_file_types: bool);
153
154        #[cfg(feature = "objc2-uniform-type-identifiers")]
155        #[cfg(target_vendor = "apple")]
156        /// `NSSavePanel`:The current type. If set to `nil`, resets to the first allowed content type. Returns `nil` if `allowedContentTypes` is empty.
157        /// `NSOpenPanel`: Not used.
158        /// - Note: Asserts that `currentContentType` conforms to `UTTypeData` or `UTTypeDirectory`.
159        #[unsafe(method(currentContentType))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn currentContentType(&self) -> Option<Retained<UTType>>;
162
163        #[cfg(feature = "objc2-uniform-type-identifiers")]
164        #[cfg(target_vendor = "apple")]
165        /// Setter for [`currentContentType`][Self::currentContentType].
166        #[unsafe(method(setCurrentContentType:))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn setCurrentContentType(&self, current_content_type: Option<&UTType>);
169
170        #[cfg(feature = "NSView")]
171        /// Sets and returns the accessory view shown in the panel. For applications that link on SnowLeopard and higher, the accessoryView's frame will be observed, and any changes the programmer makes to the frame will automatically be reflected in the panel (including animated changes to the frame height).
172        #[unsafe(method(accessoryView))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn accessoryView(&self) -> Option<Retained<NSView>>;
175
176        #[cfg(feature = "NSView")]
177        /// Setter for [`accessoryView`][Self::accessoryView].
178        #[unsafe(method(setAccessoryView:))]
179        #[unsafe(method_family = none)]
180        pub unsafe fn setAccessoryView(&self, accessory_view: Option<&NSView>);
181
182        /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the delegate.
183        #[unsafe(method(delegate))]
184        #[unsafe(method_family = none)]
185        pub unsafe fn delegate(
186            &self,
187        ) -> Option<Retained<ProtocolObject<dyn NSOpenSavePanelDelegate>>>;
188
189        /// This is a [weak property][objc2::topics::weak_property].
190        /// Setter for [`delegate`][Self::delegate].
191        #[unsafe(method(setDelegate:))]
192        #[unsafe(method_family = none)]
193        pub unsafe fn setDelegate(
194            &self,
195            delegate: Option<&ProtocolObject<dyn NSOpenSavePanelDelegate>>,
196        );
197
198        /// `NSSavePanel`: Returns `YES` if the panel is expanded. Defaults to `NO`. Persists in the user defaults.
199        /// - Note: Can only be set during the configuration phase.
200        /// `NSOpenPanel`: Not used.
201        #[unsafe(method(isExpanded))]
202        #[unsafe(method_family = none)]
203        pub unsafe fn isExpanded(&self) -> bool;
204
205        /// `NSSavePanel`/`NSOpenPanel`: Set to `YES` to show the "New Folder" button. Default is `YES`.
206        #[unsafe(method(canCreateDirectories))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn canCreateDirectories(&self) -> bool;
209
210        /// Setter for [`canCreateDirectories`][Self::canCreateDirectories].
211        #[unsafe(method(setCanCreateDirectories:))]
212        #[unsafe(method_family = none)]
213        pub unsafe fn setCanCreateDirectories(&self, can_create_directories: bool);
214
215        /// `NSSavePanel`: Set to `YES` to show the "Hide Extension" menu item.
216        /// `NSOpenPanel`: Not used.
217        #[unsafe(method(canSelectHiddenExtension))]
218        #[unsafe(method_family = none)]
219        pub unsafe fn canSelectHiddenExtension(&self) -> bool;
220
221        /// Setter for [`canSelectHiddenExtension`][Self::canSelectHiddenExtension].
222        #[unsafe(method(setCanSelectHiddenExtension:))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn setCanSelectHiddenExtension(&self, can_select_hidden_extension: bool);
225
226        /// `NSSavePanel`: Set to `YES` if the filename extension should be hidden. Otherwise, `NO` if the filename extension should be shown. Default is `YES`.
227        /// - Note: Can only be set during the configuration phase.
228        /// `NSOpenPanel`: Not used.
229        #[unsafe(method(isExtensionHidden))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn isExtensionHidden(&self) -> bool;
232
233        /// Setter for [`isExtensionHidden`][Self::isExtensionHidden].
234        #[unsafe(method(setExtensionHidden:))]
235        #[unsafe(method_family = none)]
236        pub unsafe fn setExtensionHidden(&self, extension_hidden: bool);
237
238        /// `NSSavePanel`/`NSOpenPanel`: If set to `YES`, the user can navigate into file packages as if they were directories. Default is `NO`.
239        #[unsafe(method(treatsFilePackagesAsDirectories))]
240        #[unsafe(method_family = none)]
241        pub unsafe fn treatsFilePackagesAsDirectories(&self) -> bool;
242
243        /// Setter for [`treatsFilePackagesAsDirectories`][Self::treatsFilePackagesAsDirectories].
244        #[unsafe(method(setTreatsFilePackagesAsDirectories:))]
245        #[unsafe(method_family = none)]
246        pub unsafe fn setTreatsFilePackagesAsDirectories(
247            &self,
248            treats_file_packages_as_directories: bool,
249        );
250
251        /// `NSSavePanel`/`NSOpenPanel`: Sets the text shown on the Open or Save button. If set to an empty string, it will show a localized "Open" for the NSOpenPanel and "Save" for the NSSavePanel. The default value will be the correct localized prompt for the open or save panel, as appropriate.
252        #[unsafe(method(prompt))]
253        #[unsafe(method_family = none)]
254        pub unsafe fn prompt(&self) -> Retained<NSString>;
255
256        /// Setter for [`prompt`][Self::prompt].
257        #[unsafe(method(setPrompt:))]
258        #[unsafe(method_family = none)]
259        pub unsafe fn setPrompt(&self, prompt: Option<&NSString>);
260
261        /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the title for the panel shown at the top of the window.
262        /// - Note: The open and save panel does not currently have a titlebar. So the title is not displayed.
263        #[unsafe(method(title))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn title(&self) -> Retained<NSString>;
266
267        /// Setter for [`title`][Self::title].
268        #[unsafe(method(setTitle:))]
269        #[unsafe(method_family = none)]
270        pub unsafe fn setTitle(&self, title: Option<&NSString>);
271
272        /// `NSSavePanel`: Sets and returns the text shown to the left of the "name field". Default value is a localized "Save As:" string.
273        /// `NSOpenPanel`: Not used.
274        #[unsafe(method(nameFieldLabel))]
275        #[unsafe(method_family = none)]
276        pub unsafe fn nameFieldLabel(&self) -> Retained<NSString>;
277
278        /// Setter for [`nameFieldLabel`][Self::nameFieldLabel].
279        #[unsafe(method(setNameFieldLabel:))]
280        #[unsafe(method_family = none)]
281        pub unsafe fn setNameFieldLabel(&self, name_field_label: Option<&NSString>);
282
283        /// `NSSavePanel`: Sets and returns the user-editable file name shown in the name field.
284        /// - Note: Calling the deprecated methods that take a "name:" parameter will overwrite any values set before the panel is shown.
285        /// - Note: If `[panel isExtensionHidden]` is set to `YES`, the extension will be hidden.
286        /// - Note: Can only be set during the configuration phase.
287        /// `NSOpenPanel`: Not used.
288        #[unsafe(method(nameFieldStringValue))]
289        #[unsafe(method_family = none)]
290        pub unsafe fn nameFieldStringValue(&self) -> Retained<NSString>;
291
292        /// Setter for [`nameFieldStringValue`][Self::nameFieldStringValue].
293        #[unsafe(method(setNameFieldStringValue:))]
294        #[unsafe(method_family = none)]
295        pub unsafe fn setNameFieldStringValue(&self, name_field_string_value: &NSString);
296
297        /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the message shown under title of the panel.
298        #[unsafe(method(message))]
299        #[unsafe(method_family = none)]
300        pub unsafe fn message(&self) -> Retained<NSString>;
301
302        /// Setter for [`message`][Self::message].
303        #[unsafe(method(setMessage:))]
304        #[unsafe(method_family = none)]
305        pub unsafe fn setMessage(&self, message: Option<&NSString>);
306
307        /// `NSSavePanel`/`NSOpenPanel`: If `showsHiddenFiles` is set to `YES`, files that are normally hidden from the user are displayed. This method was published in Mac OS 10.6, but has existed since Mac OS 10.4. This property is KVO compliant. The user may invoke the keyboard shortcut (cmd-shift-.) to show or hide hidden files. Any user interface shown in an an accessory view should be updated by using key value observing (KVO) to watch for changes of this property. Alternatively, the user interface can be directly bound to this property. The default value is `NO`.
308        #[unsafe(method(showsHiddenFiles))]
309        #[unsafe(method_family = none)]
310        pub unsafe fn showsHiddenFiles(&self) -> bool;
311
312        /// Setter for [`showsHiddenFiles`][Self::showsHiddenFiles].
313        #[unsafe(method(setShowsHiddenFiles:))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn setShowsHiddenFiles(&self, shows_hidden_files: bool);
316
317        /// `NSSavePanel`: Shows or hides the "Tags" field in the receiver. By passing `YES`, you become responsible for setting Tag names on the resulting file after saving is complete. Default is `YES`.
318        /// `NSOpenPanel`: Not used.
319        #[unsafe(method(showsTagField))]
320        #[unsafe(method_family = none)]
321        pub unsafe fn showsTagField(&self) -> bool;
322
323        /// Setter for [`showsTagField`][Self::showsTagField].
324        #[unsafe(method(setShowsTagField:))]
325        #[unsafe(method_family = none)]
326        pub unsafe fn setShowsTagField(&self, shows_tag_field: bool);
327
328        /// `NSSavePanel`: When -showsTagField returns YES, set any initial Tag names to be displayed, if necessary, prior to displaying the receiver. Also, if the user clicks "Save", take the result of -tagNames, and set them on the resulting file after saving is complete. Tag names are NSStrings, arrays of which can be used directly with the NSURLTagNamesKey API for getting and setting tags on files. Passing `nil` or an empty array to -setTagNames: will result in no initial Tag names appearing in the receiver. When -showsTagField returns YES, -tagNames always returns a non-nil array, and when NO, -tagNames always returns `nil`.
329        /// `NSOpenPanel`: Not used.
330        #[unsafe(method(tagNames))]
331        #[unsafe(method_family = none)]
332        pub unsafe fn tagNames(&self) -> Option<Retained<NSArray<NSString>>>;
333
334        /// Setter for [`tagNames`][Self::tagNames].
335        #[unsafe(method(setTagNames:))]
336        #[unsafe(method_family = none)]
337        pub unsafe fn setTagNames(&self, tag_names: Option<&NSArray<NSString>>);
338
339        /// `NSSavePanel`: Whether or not to show a control for selecting the type of the saved file.
340        /// The control shows the types in `allowedContentTypes`. Default is `NO`.
341        /// - Note: If
342        /// `allowedContentTypes`is empty, the control is not displayed.
343        /// `NSOpenPanel`: Not used.
344        #[unsafe(method(showsContentTypes))]
345        #[unsafe(method_family = none)]
346        pub unsafe fn showsContentTypes(&self) -> bool;
347
348        /// Setter for [`showsContentTypes`][Self::showsContentTypes].
349        #[unsafe(method(setShowsContentTypes:))]
350        #[unsafe(method_family = none)]
351        pub unsafe fn setShowsContentTypes(&self, shows_content_types: bool);
352
353        /// Refreshes the open or save panel's contents.
354        #[unsafe(method(validateVisibleColumns))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn validateVisibleColumns(&self);
357
358        #[unsafe(method(ok:))]
359        #[unsafe(method_family = none)]
360        pub unsafe fn ok(&self, sender: Option<&AnyObject>);
361
362        #[unsafe(method(cancel:))]
363        #[unsafe(method_family = none)]
364        pub unsafe fn cancel(&self, sender: Option<&AnyObject>);
365
366        #[cfg(all(feature = "NSApplication", feature = "block2"))]
367        /// `NSSavePanel`/`NSOpenPanel`: Presents the panel as a sheet modal to `window` and returns immediately. Configure the panel before calling this method. The completion handler block will be called after the user has closed the panel, however, the open/save panel sheet may still be on screen. If you require the sheet to be offscreen (for example, to show an alert), first call `[savePanel orderOut:nil]` to close it. The `result` will be `NSModalResponseOK`, `NSModalResponseCancel`, or if the panel fails to display, `NSModalResponseAbort`.
368        #[unsafe(method(beginSheetModalForWindow:completionHandler:))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn beginSheetModalForWindow_completionHandler(
371            &self,
372            window: &NSWindow,
373            handler: &block2::Block<dyn Fn(NSModalResponse)>,
374        );
375
376        #[cfg(all(feature = "NSApplication", feature = "block2"))]
377        /// `NSSavePanel`/`NSOpenPanel`: Presents the panel as a modeless window and returns immediately. Configure the panel before calling this method. The completion handler block will be called after the user has closed the panel. The `result` will be `NSModalResponseOK`, `NSModalResponseCancel`, or if the panel fails to display, `NSModalResponseAbort`.
378        #[unsafe(method(beginWithCompletionHandler:))]
379        #[unsafe(method_family = none)]
380        pub unsafe fn beginWithCompletionHandler(
381            &self,
382            handler: &block2::Block<dyn Fn(NSModalResponse)>,
383        );
384
385        #[cfg(feature = "NSApplication")]
386        /// `NSSavePanel`/`NSOpenPanel`: Presents the panel as an application modal window. Returns after the user has closed the panel.
387        /// - Returns: `NSModalResponseOK`, `NSModalResponseCancel` or if the panel fails to display, `NSModalResponseAbort`.
388        #[unsafe(method(runModal))]
389        #[unsafe(method_family = none)]
390        pub unsafe fn runModal(&self) -> NSModalResponse;
391    );
392}
393
394/// Methods declared on superclass `NSWindow`.
395#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
396impl NSSavePanel {
397    extern_methods!(
398        #[cfg(feature = "NSGraphics")]
399        #[unsafe(method(initWithContentRect:styleMask:backing:defer:))]
400        #[unsafe(method_family = init)]
401        pub unsafe fn initWithContentRect_styleMask_backing_defer(
402            this: Allocated<Self>,
403            content_rect: NSRect,
404            style: NSWindowStyleMask,
405            backing_store_type: NSBackingStoreType,
406            flag: bool,
407        ) -> Retained<Self>;
408
409        #[cfg(all(feature = "NSGraphics", feature = "NSScreen"))]
410        #[unsafe(method(initWithContentRect:styleMask:backing:defer:screen:))]
411        #[unsafe(method_family = init)]
412        pub unsafe fn initWithContentRect_styleMask_backing_defer_screen(
413            this: Allocated<Self>,
414            content_rect: NSRect,
415            style: NSWindowStyleMask,
416            backing_store_type: NSBackingStoreType,
417            flag: bool,
418            screen: Option<&NSScreen>,
419        ) -> Retained<Self>;
420
421        #[unsafe(method(initWithCoder:))]
422        #[unsafe(method_family = init)]
423        pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Retained<Self>;
424
425        #[cfg(feature = "NSViewController")]
426        /// Convenience method for creating an autoreleased titled window with the given contentViewController. A basic NSWindow with the following attributes is made: titled, closable, resizable, miniaturizable. The window's title is automatically bound to the contentViewController's title. The size of the window can easily be controlled by utilizing autolayout and applying size constraints to the view (or its subviews). The window has isReleasedWhenClosed set to NO, and it must be explicitly retained to keep the window instance alive. To have it automatically be freed when it is closed, do the following: [window retain] and [window setReleasedWhenClosed:YES].
427        #[unsafe(method(windowWithContentViewController:))]
428        #[unsafe(method_family = none)]
429        pub unsafe fn windowWithContentViewController(
430            content_view_controller: &NSViewController,
431        ) -> Retained<Self>;
432    );
433}
434
435/// Methods declared on superclass `NSResponder`.
436#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
437impl NSSavePanel {
438    extern_methods!(
439        #[unsafe(method(init))]
440        #[unsafe(method_family = init)]
441        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
442    );
443}
444
445/// Methods declared on superclass `NSObject`.
446#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
447impl NSSavePanel {
448    extern_methods!(
449        #[unsafe(method(new))]
450        #[unsafe(method_family = new)]
451        pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
452    );
453}
454
455extern_protocol!(
456    /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsopensavepaneldelegate?language=objc)
457    pub unsafe trait NSOpenSavePanelDelegate: NSObjectProtocol + MainThreadOnly {
458        /// Optional — Enabling URLs.
459        /// `NSSavePanel`: This method is not sent. All urls are always disabled.
460        /// `NSOpenPanel`: Return `YES` to allow the `url` to be enabled in the panel. Delegate implementations should be fast to avoid stalling the UI. Applications linked on Mac OS 10.7 and later should be prepared to handle non-file URL schemes.
461        #[optional]
462        #[unsafe(method(panel:shouldEnableURL:))]
463        #[unsafe(method_family = none)]
464        unsafe fn panel_shouldEnableURL(&self, sender: &AnyObject, url: &NSURL) -> bool;
465
466        /// Optional — URL validation for saving and opening files.
467        /// `NSSavePanel`: Sent once by the save panel when the user clicks the Save button. The user is intending to save a file at `url`. Return `YES` if the `url` is a valid location to save to. Return `NO` and return by reference `outError` with a user displayable error message for why the `url` is not valid. If a recovery option is provided by the error, and recovery succeeded, the panel will attempt to close again.
468        /// - Note: An item at `url` may not physically exist yet, unless the user decided to overwrite an existing item.
469        /// `NSOpenPanel`: Sent once for each selected filename (or directory) when the user chooses the Open button. Return `YES` if the `url` is acceptable to open. Return `NO` and return by reference `outError` with a user displayable message for why the `url` is not valid for opening. If a recovery option is provided by the error, and recovery succeeded, the panel will attempt to close again.
470        /// - Note: Implement this delegate method instead of  `panel:shouldEnableURL:` if the processing of the selected item takes a long time.
471        #[optional]
472        #[unsafe(method(panel:validateURL:error:_))]
473        #[unsafe(method_family = none)]
474        unsafe fn panel_validateURL_error(
475            &self,
476            sender: &AnyObject,
477            url: &NSURL,
478        ) -> Result<(), Retained<NSError>>;
479
480        /// Optional — Sent when the user selected the directory located at `url`. `url` may be `nil`. if the current directory can't be represented by an NSURL object (ie: the media sidebar directory, or the "Computer").
481        #[optional]
482        #[unsafe(method(panel:didChangeToDirectoryURL:))]
483        #[unsafe(method_family = none)]
484        unsafe fn panel_didChangeToDirectoryURL(&self, sender: &AnyObject, url: Option<&NSURL>);
485
486        /// Optional — Filename customization for the NSSavePanel. Allows the delegate to customize the filename entered by the user, before the extension is appended, and before the user is potentially asked to replace a file.
487        #[optional]
488        #[unsafe(method(panel:userEnteredFilename:confirmed:))]
489        #[unsafe(method_family = none)]
490        unsafe fn panel_userEnteredFilename_confirmed(
491            &self,
492            sender: &AnyObject,
493            filename: &NSString,
494            ok_flag: bool,
495        ) -> Option<Retained<NSString>>;
496
497        /// Optional — Sent when the user clicks the disclosure triangle to expand or collapse the file browser while in NSOpenPanel.
498        #[optional]
499        #[unsafe(method(panel:willExpand:))]
500        #[unsafe(method_family = none)]
501        unsafe fn panel_willExpand(&self, sender: &AnyObject, expanding: bool);
502
503        /// Optional — Sent when the user has changed the selection.
504        #[optional]
505        #[unsafe(method(panelSelectionDidChange:))]
506        #[unsafe(method_family = none)]
507        unsafe fn panelSelectionDidChange(&self, sender: Option<&AnyObject>);
508
509        #[cfg(feature = "objc2-uniform-type-identifiers")]
510        #[cfg(target_vendor = "apple")]
511        /// `NSSavePanel`: Optional — Sent when the content type popup is displayed and the save panel needs the display name for a type. If `nil` is returned, the save panel will display type's `localizedDescription`.
512        /// `NSOpenPanel`: Not sent.
513        #[optional]
514        #[unsafe(method(panel:displayNameForType:))]
515        #[unsafe(method_family = none)]
516        unsafe fn panel_displayNameForType(
517            &self,
518            sender: &AnyObject,
519            r#type: &UTType,
520        ) -> Option<Retained<NSString>>;
521
522        #[cfg(feature = "objc2-uniform-type-identifiers")]
523        #[cfg(target_vendor = "apple")]
524        /// `NSSavePanel`: Optional — Sent when the user changes the current type.
525        /// `NSOpenPanel`: Not sent.
526        #[optional]
527        #[unsafe(method(panel:didSelectType:))]
528        #[unsafe(method_family = none)]
529        unsafe fn panel_didSelectType(&self, sender: &AnyObject, r#type: Option<&UTType>);
530    }
531);
532
533/// NSDeprecated.
534#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
535impl NSSavePanel {
536    extern_methods!(
537        #[deprecated = "Use -URL instead"]
538        #[unsafe(method(filename))]
539        #[unsafe(method_family = none)]
540        pub unsafe fn filename(&self) -> Retained<NSString>;
541
542        #[deprecated = "Use -directoryURL instead"]
543        #[unsafe(method(directory))]
544        #[unsafe(method_family = none)]
545        pub unsafe fn directory(&self) -> Retained<NSString>;
546
547        #[deprecated = "Use -setDirectoryURL: instead"]
548        #[unsafe(method(setDirectory:))]
549        #[unsafe(method_family = none)]
550        pub unsafe fn setDirectory(&self, path: Option<&NSString>);
551
552        #[deprecated = "Use -allowedContentTypes instead"]
553        #[unsafe(method(requiredFileType))]
554        #[unsafe(method_family = none)]
555        pub unsafe fn requiredFileType(&self) -> Option<Retained<NSString>>;
556
557        #[deprecated = "Use -allowedContentTypes: instead"]
558        #[unsafe(method(setRequiredFileType:))]
559        #[unsafe(method_family = none)]
560        pub unsafe fn setRequiredFileType(&self, r#type: Option<&NSString>);
561
562        #[deprecated = "Use beginSheetModalForWindow:completionHandler: instead. The following parameters are replaced by properties: 'path' is replaced by 'directoryURL' and 'name' by 'nameFieldStringValue'."]
563        #[unsafe(method(beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:))]
564        #[unsafe(method_family = none)]
565        pub unsafe fn beginSheetForDirectory_file_modalForWindow_modalDelegate_didEndSelector_contextInfo(
566            &self,
567            path: Option<&NSString>,
568            name: Option<&NSString>,
569            doc_window: Option<&NSWindow>,
570            delegate: Option<&AnyObject>,
571            did_end_selector: Option<Sel>,
572            context_info: *mut c_void,
573        );
574
575        #[deprecated = "Use -runModal instead. The following parameters are replaced by properties: 'path' is replaced by 'directoryURL' and 'name' by 'nameFieldStringValue'."]
576        #[unsafe(method(runModalForDirectory:file:))]
577        #[unsafe(method_family = none)]
578        pub unsafe fn runModalForDirectory_file(
579            &self,
580            path: Option<&NSString>,
581            name: Option<&NSString>,
582        ) -> NSInteger;
583
584        #[deprecated = "Default implementation does nothing."]
585        #[unsafe(method(selectText:))]
586        #[unsafe(method_family = none)]
587        pub unsafe fn selectText(&self, sender: Option<&AnyObject>);
588
589        /// `NSSavePanel`: An array of NSStrings specifying the file types the user can save the file as. The file type can be a common file extension, or a UTI. A nil value indicates that any file type can be used. If the array is not nil and the array contains no items, an exception will be raised. If no extension is given by the user, the first item in the allowedFileTypes will be used as the extension for the save panel. If the user specifies a type not in the array, and 'allowsOtherFileTypes' is YES, they will be presented with another dialog when prompted to save. The default value is 'nil'.
590        /// `NSOpenPanel`: On versions less than 10.6, this property is ignored. For applications that link against 10.6 and higher, this property will determine which files should be enabled in the open panel. Using the deprecated methods to show the open panel (the ones that take a "types:" parameter) will overwrite this value, and should not be used. The allowedFileTypes can be changed while the panel is running (ie: from an accessory view). The file type can be a common file extension, or a UTI. This is also known as the "enabled file types". A nil value indicates that all files should be enabled.
591        #[deprecated = "Use -allowedContentTypes instead"]
592        #[unsafe(method(allowedFileTypes))]
593        #[unsafe(method_family = none)]
594        pub unsafe fn allowedFileTypes(&self) -> Option<Retained<NSArray<NSString>>>;
595
596        /// Setter for [`allowedFileTypes`][Self::allowedFileTypes].
597        #[deprecated = "Use -allowedContentTypes instead"]
598        #[unsafe(method(setAllowedFileTypes:))]
599        #[unsafe(method_family = none)]
600        pub unsafe fn setAllowedFileTypes(&self, allowed_file_types: Option<&NSArray<NSString>>);
601    );
602}