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))]
27extern_conformance!(
28 unsafe impl NSAccessibility for NSSavePanel {}
29);
30
31#[cfg(all(
32 feature = "NSAccessibilityProtocols",
33 feature = "NSPanel",
34 feature = "NSResponder",
35 feature = "NSWindow"
36))]
37extern_conformance!(
38 unsafe impl NSAccessibilityElementProtocol for NSSavePanel {}
39);
40
41#[cfg(all(
42 feature = "NSAnimation",
43 feature = "NSPanel",
44 feature = "NSResponder",
45 feature = "NSWindow"
46))]
47extern_conformance!(
48 unsafe impl NSAnimatablePropertyContainer for NSSavePanel {}
49);
50
51#[cfg(all(
52 feature = "NSAppearance",
53 feature = "NSPanel",
54 feature = "NSResponder",
55 feature = "NSWindow"
56))]
57extern_conformance!(
58 unsafe impl NSAppearanceCustomization for NSSavePanel {}
59);
60
61#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
62extern_conformance!(
63 unsafe impl NSCoding for NSSavePanel {}
64);
65
66#[cfg(all(
67 feature = "NSMenu",
68 feature = "NSPanel",
69 feature = "NSResponder",
70 feature = "NSWindow"
71))]
72extern_conformance!(
73 unsafe impl NSMenuItemValidation for NSSavePanel {}
74);
75
76#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
77extern_conformance!(
78 unsafe impl NSObjectProtocol for NSSavePanel {}
79);
80
81#[cfg(all(
82 feature = "NSPanel",
83 feature = "NSResponder",
84 feature = "NSUserInterfaceItemIdentification",
85 feature = "NSWindow"
86))]
87extern_conformance!(
88 unsafe impl NSUserInterfaceItemIdentification for NSSavePanel {}
89);
90
91#[cfg(all(
92 feature = "NSPanel",
93 feature = "NSResponder",
94 feature = "NSUserInterfaceValidation",
95 feature = "NSWindow"
96))]
97extern_conformance!(
98 unsafe impl NSUserInterfaceValidations for NSSavePanel {}
99);
100
101#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
102impl NSSavePanel {
103 extern_methods!(
104 /// Creates a new instance of the NSSavePanel. This class is not a singleton.
105 #[unsafe(method(savePanel))]
106 #[unsafe(method_family = none)]
107 pub unsafe fn savePanel(mtm: MainThreadMarker) -> Retained<NSSavePanel>;
108
109 /// `NSSavePanel`: Returns the URL to save the file at. A file may already exist at `url` if the user choose to overwrite it.
110 /// `NSOpenPanel`: Returns the single filename selected by the user. Note: if -allowsMultipleSelection is set, you should use the -URLs on NSOpenPanel instead.
111 #[unsafe(method(URL))]
112 #[unsafe(method_family = none)]
113 pub unsafe fn URL(&self) -> Option<Retained<NSURL>>;
114
115 #[cfg(feature = "NSUserInterfaceItemIdentification")]
116 /// Sets and returns the identifier.
117 ///
118 /// The panel's current state such as the root directory and the current directory are saved and restored relative to the identifier.
119 /// - 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).
120 /// - Note: Can only be set during the configuration phase.
121 #[unsafe(method(identifier))]
122 #[unsafe(method_family = none)]
123 pub unsafe fn identifier(&self) -> Option<Retained<NSUserInterfaceItemIdentifier>>;
124
125 #[cfg(feature = "NSUserInterfaceItemIdentification")]
126 /// Setter for [`identifier`][Self::identifier].
127 #[unsafe(method(setIdentifier:))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn setIdentifier(&self, identifier: Option<&NSUserInterfaceItemIdentifier>);
130
131 /// `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.
132 /// - Note: Can only be set during the configuration phase.
133 #[unsafe(method(directoryURL))]
134 #[unsafe(method_family = none)]
135 pub unsafe fn directoryURL(&self) -> Option<Retained<NSURL>>;
136
137 /// Setter for [`directoryURL`][Self::directoryURL].
138 #[unsafe(method(setDirectoryURL:))]
139 #[unsafe(method_family = none)]
140 pub unsafe fn setDirectoryURL(&self, directory_url: Option<&NSURL>);
141
142 #[cfg(feature = "objc2-uniform-type-identifiers")]
143 #[cfg(target_vendor = "apple")]
144 /// `NSSavePanel`: An array of UTTypes specifying the file types the user can save the file as. Set to `
145 /// @
146 /// []` 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.
147 /// `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 `
148 /// @
149 /// []` to specify that all files should be enabled.
150 #[unsafe(method(allowedContentTypes))]
151 #[unsafe(method_family = none)]
152 pub unsafe fn allowedContentTypes(&self) -> Retained<NSArray<UTType>>;
153
154 #[cfg(feature = "objc2-uniform-type-identifiers")]
155 #[cfg(target_vendor = "apple")]
156 /// Setter for [`allowedContentTypes`][Self::allowedContentTypes].
157 #[unsafe(method(setAllowedContentTypes:))]
158 #[unsafe(method_family = none)]
159 pub unsafe fn setAllowedContentTypes(&self, allowed_content_types: &NSArray<UTType>);
160
161 /// `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`.
162 /// `NSOpenPanel`: Not used.
163 #[unsafe(method(allowsOtherFileTypes))]
164 #[unsafe(method_family = none)]
165 pub unsafe fn allowsOtherFileTypes(&self) -> bool;
166
167 /// Setter for [`allowsOtherFileTypes`][Self::allowsOtherFileTypes].
168 #[unsafe(method(setAllowsOtherFileTypes:))]
169 #[unsafe(method_family = none)]
170 pub unsafe fn setAllowsOtherFileTypes(&self, allows_other_file_types: bool);
171
172 #[cfg(feature = "objc2-uniform-type-identifiers")]
173 #[cfg(target_vendor = "apple")]
174 /// `NSSavePanel`:The current type. If set to `nil`, resets to the first allowed content type. Returns `nil` if `allowedContentTypes` is empty.
175 /// `NSOpenPanel`: Not used.
176 /// - Note: Asserts that `currentContentType` conforms to `UTTypeData` or `UTTypeDirectory`.
177 #[unsafe(method(currentContentType))]
178 #[unsafe(method_family = none)]
179 pub unsafe fn currentContentType(&self) -> Option<Retained<UTType>>;
180
181 #[cfg(feature = "objc2-uniform-type-identifiers")]
182 #[cfg(target_vendor = "apple")]
183 /// Setter for [`currentContentType`][Self::currentContentType].
184 #[unsafe(method(setCurrentContentType:))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn setCurrentContentType(&self, current_content_type: Option<&UTType>);
187
188 #[cfg(feature = "NSView")]
189 /// 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).
190 #[unsafe(method(accessoryView))]
191 #[unsafe(method_family = none)]
192 pub unsafe fn accessoryView(&self) -> Option<Retained<NSView>>;
193
194 #[cfg(feature = "NSView")]
195 /// Setter for [`accessoryView`][Self::accessoryView].
196 #[unsafe(method(setAccessoryView:))]
197 #[unsafe(method_family = none)]
198 pub unsafe fn setAccessoryView(&self, accessory_view: Option<&NSView>);
199
200 /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the delegate.
201 #[unsafe(method(delegate))]
202 #[unsafe(method_family = none)]
203 pub unsafe fn delegate(
204 &self,
205 ) -> Option<Retained<ProtocolObject<dyn NSOpenSavePanelDelegate>>>;
206
207 /// This is a [weak property][objc2::topics::weak_property].
208 /// Setter for [`delegate`][Self::delegate].
209 #[unsafe(method(setDelegate:))]
210 #[unsafe(method_family = none)]
211 pub unsafe fn setDelegate(
212 &self,
213 delegate: Option<&ProtocolObject<dyn NSOpenSavePanelDelegate>>,
214 );
215
216 /// `NSSavePanel`: Returns `YES` if the panel is expanded. Defaults to `NO`. Persists in the user defaults.
217 /// - Note: Can only be set during the configuration phase.
218 /// `NSOpenPanel`: Not used.
219 #[unsafe(method(isExpanded))]
220 #[unsafe(method_family = none)]
221 pub unsafe fn isExpanded(&self) -> bool;
222
223 /// `NSSavePanel`/`NSOpenPanel`: Set to `YES` to show the "New Folder" button. Default is `YES`.
224 #[unsafe(method(canCreateDirectories))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn canCreateDirectories(&self) -> bool;
227
228 /// Setter for [`canCreateDirectories`][Self::canCreateDirectories].
229 #[unsafe(method(setCanCreateDirectories:))]
230 #[unsafe(method_family = none)]
231 pub unsafe fn setCanCreateDirectories(&self, can_create_directories: bool);
232
233 /// `NSSavePanel`: Set to `YES` to show the "Hide Extension" menu item.
234 /// `NSOpenPanel`: Not used.
235 #[unsafe(method(canSelectHiddenExtension))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn canSelectHiddenExtension(&self) -> bool;
238
239 /// Setter for [`canSelectHiddenExtension`][Self::canSelectHiddenExtension].
240 #[unsafe(method(setCanSelectHiddenExtension:))]
241 #[unsafe(method_family = none)]
242 pub unsafe fn setCanSelectHiddenExtension(&self, can_select_hidden_extension: bool);
243
244 /// `NSSavePanel`: Set to `YES` if the filename extension should be hidden. Otherwise, `NO` if the filename extension should be shown. Default is `YES`.
245 /// - Note: Can only be set during the configuration phase.
246 /// `NSOpenPanel`: Not used.
247 #[unsafe(method(isExtensionHidden))]
248 #[unsafe(method_family = none)]
249 pub unsafe fn isExtensionHidden(&self) -> bool;
250
251 /// Setter for [`isExtensionHidden`][Self::isExtensionHidden].
252 #[unsafe(method(setExtensionHidden:))]
253 #[unsafe(method_family = none)]
254 pub unsafe fn setExtensionHidden(&self, extension_hidden: bool);
255
256 /// `NSSavePanel`/`NSOpenPanel`: If set to `YES`, the user can navigate into file packages as if they were directories. Default is `NO`.
257 #[unsafe(method(treatsFilePackagesAsDirectories))]
258 #[unsafe(method_family = none)]
259 pub unsafe fn treatsFilePackagesAsDirectories(&self) -> bool;
260
261 /// Setter for [`treatsFilePackagesAsDirectories`][Self::treatsFilePackagesAsDirectories].
262 #[unsafe(method(setTreatsFilePackagesAsDirectories:))]
263 #[unsafe(method_family = none)]
264 pub unsafe fn setTreatsFilePackagesAsDirectories(
265 &self,
266 treats_file_packages_as_directories: bool,
267 );
268
269 /// `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.
270 #[unsafe(method(prompt))]
271 #[unsafe(method_family = none)]
272 pub unsafe fn prompt(&self) -> Retained<NSString>;
273
274 /// Setter for [`prompt`][Self::prompt].
275 #[unsafe(method(setPrompt:))]
276 #[unsafe(method_family = none)]
277 pub unsafe fn setPrompt(&self, prompt: Option<&NSString>);
278
279 /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the title for the panel shown at the top of the window.
280 /// - Note: The open and save panel does not currently have a titlebar. So the title is not displayed.
281 #[unsafe(method(title))]
282 #[unsafe(method_family = none)]
283 pub unsafe fn title(&self) -> Retained<NSString>;
284
285 /// Setter for [`title`][Self::title].
286 #[unsafe(method(setTitle:))]
287 #[unsafe(method_family = none)]
288 pub unsafe fn setTitle(&self, title: Option<&NSString>);
289
290 /// `NSSavePanel`: Sets and returns the text shown to the left of the "name field". Default value is a localized "Save As:" string.
291 /// `NSOpenPanel`: Not used.
292 #[unsafe(method(nameFieldLabel))]
293 #[unsafe(method_family = none)]
294 pub unsafe fn nameFieldLabel(&self) -> Retained<NSString>;
295
296 /// Setter for [`nameFieldLabel`][Self::nameFieldLabel].
297 #[unsafe(method(setNameFieldLabel:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn setNameFieldLabel(&self, name_field_label: Option<&NSString>);
300
301 /// `NSSavePanel`: Sets and returns the user-editable file name shown in the name field.
302 /// - Note: Calling the deprecated methods that take a "name:" parameter will overwrite any values set before the panel is shown.
303 /// - Note: If `[panel isExtensionHidden]` is set to `YES`, the extension will be hidden.
304 /// - Note: Can only be set during the configuration phase.
305 /// `NSOpenPanel`: Not used.
306 #[unsafe(method(nameFieldStringValue))]
307 #[unsafe(method_family = none)]
308 pub unsafe fn nameFieldStringValue(&self) -> Retained<NSString>;
309
310 /// Setter for [`nameFieldStringValue`][Self::nameFieldStringValue].
311 #[unsafe(method(setNameFieldStringValue:))]
312 #[unsafe(method_family = none)]
313 pub unsafe fn setNameFieldStringValue(&self, name_field_string_value: &NSString);
314
315 /// `NSSavePanel`/`NSOpenPanel`: Sets and returns the message shown under title of the panel.
316 #[unsafe(method(message))]
317 #[unsafe(method_family = none)]
318 pub unsafe fn message(&self) -> Retained<NSString>;
319
320 /// Setter for [`message`][Self::message].
321 #[unsafe(method(setMessage:))]
322 #[unsafe(method_family = none)]
323 pub unsafe fn setMessage(&self, message: Option<&NSString>);
324
325 /// `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`.
326 #[unsafe(method(showsHiddenFiles))]
327 #[unsafe(method_family = none)]
328 pub unsafe fn showsHiddenFiles(&self) -> bool;
329
330 /// Setter for [`showsHiddenFiles`][Self::showsHiddenFiles].
331 #[unsafe(method(setShowsHiddenFiles:))]
332 #[unsafe(method_family = none)]
333 pub unsafe fn setShowsHiddenFiles(&self, shows_hidden_files: bool);
334
335 /// `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`.
336 /// `NSOpenPanel`: Not used.
337 #[unsafe(method(showsTagField))]
338 #[unsafe(method_family = none)]
339 pub unsafe fn showsTagField(&self) -> bool;
340
341 /// Setter for [`showsTagField`][Self::showsTagField].
342 #[unsafe(method(setShowsTagField:))]
343 #[unsafe(method_family = none)]
344 pub unsafe fn setShowsTagField(&self, shows_tag_field: bool);
345
346 /// `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`.
347 /// `NSOpenPanel`: Not used.
348 #[unsafe(method(tagNames))]
349 #[unsafe(method_family = none)]
350 pub unsafe fn tagNames(&self) -> Option<Retained<NSArray<NSString>>>;
351
352 /// Setter for [`tagNames`][Self::tagNames].
353 #[unsafe(method(setTagNames:))]
354 #[unsafe(method_family = none)]
355 pub unsafe fn setTagNames(&self, tag_names: Option<&NSArray<NSString>>);
356
357 /// `NSSavePanel`: Whether or not to show a control for selecting the type of the saved file.
358 /// The control shows the types in `allowedContentTypes`. Default is `NO`.
359 /// - Note: If
360 /// `allowedContentTypes`is empty, the control is not displayed.
361 /// `NSOpenPanel`: Not used.
362 #[unsafe(method(showsContentTypes))]
363 #[unsafe(method_family = none)]
364 pub unsafe fn showsContentTypes(&self) -> bool;
365
366 /// Setter for [`showsContentTypes`][Self::showsContentTypes].
367 #[unsafe(method(setShowsContentTypes:))]
368 #[unsafe(method_family = none)]
369 pub unsafe fn setShowsContentTypes(&self, shows_content_types: bool);
370
371 /// Refreshes the open or save panel's contents.
372 #[unsafe(method(validateVisibleColumns))]
373 #[unsafe(method_family = none)]
374 pub unsafe fn validateVisibleColumns(&self);
375
376 #[unsafe(method(ok:))]
377 #[unsafe(method_family = none)]
378 pub unsafe fn ok(&self, sender: Option<&AnyObject>);
379
380 #[unsafe(method(cancel:))]
381 #[unsafe(method_family = none)]
382 pub unsafe fn cancel(&self, sender: Option<&AnyObject>);
383
384 #[cfg(all(feature = "NSApplication", feature = "block2"))]
385 /// `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`.
386 #[unsafe(method(beginSheetModalForWindow:completionHandler:))]
387 #[unsafe(method_family = none)]
388 pub unsafe fn beginSheetModalForWindow_completionHandler(
389 &self,
390 window: &NSWindow,
391 handler: &block2::DynBlock<dyn Fn(NSModalResponse)>,
392 );
393
394 #[cfg(all(feature = "NSApplication", feature = "block2"))]
395 /// `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`.
396 #[unsafe(method(beginWithCompletionHandler:))]
397 #[unsafe(method_family = none)]
398 pub unsafe fn beginWithCompletionHandler(
399 &self,
400 handler: &block2::DynBlock<dyn Fn(NSModalResponse)>,
401 );
402
403 #[cfg(feature = "NSApplication")]
404 /// `NSSavePanel`/`NSOpenPanel`: Presents the panel as an application modal window. Returns after the user has closed the panel.
405 /// - Returns: `NSModalResponseOK`, `NSModalResponseCancel` or if the panel fails to display, `NSModalResponseAbort`.
406 #[unsafe(method(runModal))]
407 #[unsafe(method_family = none)]
408 pub unsafe fn runModal(&self) -> NSModalResponse;
409 );
410}
411
412/// Methods declared on superclass `NSWindow`.
413#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
414impl NSSavePanel {
415 extern_methods!(
416 #[cfg(feature = "NSGraphics")]
417 #[unsafe(method(initWithContentRect:styleMask:backing:defer:))]
418 #[unsafe(method_family = init)]
419 pub unsafe fn initWithContentRect_styleMask_backing_defer(
420 this: Allocated<Self>,
421 content_rect: NSRect,
422 style: NSWindowStyleMask,
423 backing_store_type: NSBackingStoreType,
424 flag: bool,
425 ) -> Retained<Self>;
426
427 #[cfg(all(feature = "NSGraphics", feature = "NSScreen"))]
428 #[unsafe(method(initWithContentRect:styleMask:backing:defer:screen:))]
429 #[unsafe(method_family = init)]
430 pub unsafe fn initWithContentRect_styleMask_backing_defer_screen(
431 this: Allocated<Self>,
432 content_rect: NSRect,
433 style: NSWindowStyleMask,
434 backing_store_type: NSBackingStoreType,
435 flag: bool,
436 screen: Option<&NSScreen>,
437 ) -> Retained<Self>;
438
439 #[unsafe(method(initWithCoder:))]
440 #[unsafe(method_family = init)]
441 pub unsafe fn initWithCoder(this: Allocated<Self>, coder: &NSCoder) -> Retained<Self>;
442
443 #[cfg(feature = "NSViewController")]
444 /// 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].
445 #[unsafe(method(windowWithContentViewController:))]
446 #[unsafe(method_family = none)]
447 pub unsafe fn windowWithContentViewController(
448 content_view_controller: &NSViewController,
449 ) -> Retained<Self>;
450 );
451}
452
453/// Methods declared on superclass `NSResponder`.
454#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
455impl NSSavePanel {
456 extern_methods!(
457 #[unsafe(method(init))]
458 #[unsafe(method_family = init)]
459 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
460 );
461}
462
463/// Methods declared on superclass `NSObject`.
464#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
465impl NSSavePanel {
466 extern_methods!(
467 #[unsafe(method(new))]
468 #[unsafe(method_family = new)]
469 pub unsafe fn new(mtm: MainThreadMarker) -> Retained<Self>;
470 );
471}
472
473extern_protocol!(
474 /// [Apple's documentation](https://developer.apple.com/documentation/appkit/nsopensavepaneldelegate?language=objc)
475 pub unsafe trait NSOpenSavePanelDelegate: NSObjectProtocol + MainThreadOnly {
476 /// Optional — Enabling URLs.
477 /// `NSSavePanel`: This method is not sent. All urls are always disabled.
478 /// `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.
479 #[optional]
480 #[unsafe(method(panel:shouldEnableURL:))]
481 #[unsafe(method_family = none)]
482 unsafe fn panel_shouldEnableURL(&self, sender: &AnyObject, url: &NSURL) -> bool;
483
484 /// Optional — URL validation for saving and opening files.
485 /// `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.
486 /// - Note: An item at `url` may not physically exist yet, unless the user decided to overwrite an existing item.
487 /// `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.
488 /// - Note: Implement this delegate method instead of `panel:shouldEnableURL:` if the processing of the selected item takes a long time.
489 #[optional]
490 #[unsafe(method(panel:validateURL:error:_))]
491 #[unsafe(method_family = none)]
492 unsafe fn panel_validateURL_error(
493 &self,
494 sender: &AnyObject,
495 url: &NSURL,
496 ) -> Result<(), Retained<NSError>>;
497
498 /// 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").
499 #[optional]
500 #[unsafe(method(panel:didChangeToDirectoryURL:))]
501 #[unsafe(method_family = none)]
502 unsafe fn panel_didChangeToDirectoryURL(&self, sender: &AnyObject, url: Option<&NSURL>);
503
504 /// 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.
505 #[optional]
506 #[unsafe(method(panel:userEnteredFilename:confirmed:))]
507 #[unsafe(method_family = none)]
508 unsafe fn panel_userEnteredFilename_confirmed(
509 &self,
510 sender: &AnyObject,
511 filename: &NSString,
512 ok_flag: bool,
513 ) -> Option<Retained<NSString>>;
514
515 /// Optional — Sent when the user clicks the disclosure triangle to expand or collapse the file browser while in NSOpenPanel.
516 #[optional]
517 #[unsafe(method(panel:willExpand:))]
518 #[unsafe(method_family = none)]
519 unsafe fn panel_willExpand(&self, sender: &AnyObject, expanding: bool);
520
521 /// Optional — Sent when the user has changed the selection.
522 #[optional]
523 #[unsafe(method(panelSelectionDidChange:))]
524 #[unsafe(method_family = none)]
525 unsafe fn panelSelectionDidChange(&self, sender: Option<&AnyObject>);
526
527 #[cfg(feature = "objc2-uniform-type-identifiers")]
528 #[cfg(target_vendor = "apple")]
529 /// `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`.
530 /// `NSOpenPanel`: Not sent.
531 #[optional]
532 #[unsafe(method(panel:displayNameForType:))]
533 #[unsafe(method_family = none)]
534 unsafe fn panel_displayNameForType(
535 &self,
536 sender: &AnyObject,
537 r#type: &UTType,
538 ) -> Option<Retained<NSString>>;
539
540 #[cfg(feature = "objc2-uniform-type-identifiers")]
541 #[cfg(target_vendor = "apple")]
542 /// `NSSavePanel`: Optional — Sent when the user changes the current type.
543 /// `NSOpenPanel`: Not sent.
544 #[optional]
545 #[unsafe(method(panel:didSelectType:))]
546 #[unsafe(method_family = none)]
547 unsafe fn panel_didSelectType(&self, sender: &AnyObject, r#type: Option<&UTType>);
548 }
549);
550
551/// NSDeprecated.
552#[cfg(all(feature = "NSPanel", feature = "NSResponder", feature = "NSWindow"))]
553impl NSSavePanel {
554 extern_methods!(
555 #[deprecated = "Use -URL instead"]
556 #[unsafe(method(filename))]
557 #[unsafe(method_family = none)]
558 pub unsafe fn filename(&self) -> Retained<NSString>;
559
560 #[deprecated = "Use -directoryURL instead"]
561 #[unsafe(method(directory))]
562 #[unsafe(method_family = none)]
563 pub unsafe fn directory(&self) -> Retained<NSString>;
564
565 #[deprecated = "Use -setDirectoryURL: instead"]
566 #[unsafe(method(setDirectory:))]
567 #[unsafe(method_family = none)]
568 pub unsafe fn setDirectory(&self, path: Option<&NSString>);
569
570 #[deprecated = "Use -allowedContentTypes instead"]
571 #[unsafe(method(requiredFileType))]
572 #[unsafe(method_family = none)]
573 pub unsafe fn requiredFileType(&self) -> Option<Retained<NSString>>;
574
575 #[deprecated = "Use -allowedContentTypes: instead"]
576 #[unsafe(method(setRequiredFileType:))]
577 #[unsafe(method_family = none)]
578 pub unsafe fn setRequiredFileType(&self, r#type: Option<&NSString>);
579
580 #[deprecated = "Use beginSheetModalForWindow:completionHandler: instead. The following parameters are replaced by properties: 'path' is replaced by 'directoryURL' and 'name' by 'nameFieldStringValue'."]
581 #[unsafe(method(beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:))]
582 #[unsafe(method_family = none)]
583 pub unsafe fn beginSheetForDirectory_file_modalForWindow_modalDelegate_didEndSelector_contextInfo(
584 &self,
585 path: Option<&NSString>,
586 name: Option<&NSString>,
587 doc_window: Option<&NSWindow>,
588 delegate: Option<&AnyObject>,
589 did_end_selector: Option<Sel>,
590 context_info: *mut c_void,
591 );
592
593 #[deprecated = "Use -runModal instead. The following parameters are replaced by properties: 'path' is replaced by 'directoryURL' and 'name' by 'nameFieldStringValue'."]
594 #[unsafe(method(runModalForDirectory:file:))]
595 #[unsafe(method_family = none)]
596 pub unsafe fn runModalForDirectory_file(
597 &self,
598 path: Option<&NSString>,
599 name: Option<&NSString>,
600 ) -> NSInteger;
601
602 #[deprecated = "Default implementation does nothing."]
603 #[unsafe(method(selectText:))]
604 #[unsafe(method_family = none)]
605 pub unsafe fn selectText(&self, sender: Option<&AnyObject>);
606
607 /// `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'.
608 /// `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.
609 #[deprecated = "Use -allowedContentTypes instead"]
610 #[unsafe(method(allowedFileTypes))]
611 #[unsafe(method_family = none)]
612 pub unsafe fn allowedFileTypes(&self) -> Option<Retained<NSArray<NSString>>>;
613
614 /// Setter for [`allowedFileTypes`][Self::allowedFileTypes].
615 #[deprecated = "Use -allowedContentTypes instead"]
616 #[unsafe(method(setAllowedFileTypes:))]
617 #[unsafe(method_family = none)]
618 pub unsafe fn setAllowedFileTypes(&self, allowed_file_types: Option<&NSArray<NSString>>);
619 );
620}