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