objc2_foundation/generated/
NSUndoManager.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::*;
6
7use crate::*;
8
9/// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundoclosegroupingrunloopordering?language=objc)
10pub static NSUndoCloseGroupingRunLoopOrdering: NSUInteger = 350000;
11
12/// A key used to set and get user info for undo and redo actions
13///
14/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanageruserinfokey?language=objc)
15// NS_TYPED_EXTENSIBLE_ENUM
16#[cfg(feature = "NSString")]
17pub type NSUndoManagerUserInfoKey = NSString;
18
19extern "C" {
20    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagergroupisdiscardablekey?language=objc)
21    #[cfg(feature = "NSString")]
22    pub static NSUndoManagerGroupIsDiscardableKey: &'static NSString;
23}
24
25extern_class!(
26    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanager?language=objc)
27    #[unsafe(super(NSObject))]
28    #[derive(Debug, PartialEq, Eq, Hash)]
29    pub struct NSUndoManager;
30);
31
32unsafe impl NSObjectProtocol for NSUndoManager {}
33
34impl NSUndoManager {
35    extern_methods!(
36        /// Marks the beginning of an undo group.
37        ///
38        /// All individual undo operations before a subsequent ``endUndoGrouping`` message are grouped together and reversed by a later ``undo`` message. By default undo groups are begun automatically at the start of the event loop, but you can begin your own undo groups with this method, and nest them within other groups.
39        ///
40        /// This method posts an ``NSUndoManagerCheckpointNotification`` unless a top-level undo is in progress. It posts an ``NSUndoManagerDidOpenUndoGroupNotification`` if a new group was successfully created.
41        #[unsafe(method(beginUndoGrouping))]
42        #[unsafe(method_family = none)]
43        pub unsafe fn beginUndoGrouping(&self);
44
45        /// Marks the end of an undo group.
46        ///
47        /// All individual undo operations back to the matching ``beginUndoGrouping`` message are grouped together and reversed by a later ``undo`` or ``undoNestedGroup`` message. Undo groups can be nested, thus providing functionality similar to nested transactions. Raises an ``NSInternalInconsistencyException`` if there’s no ``beginUndoGrouping`` message in effect.
48        ///
49        /// This method posts an ``NSUndoManagerCheckpointNotification`` and an ``NSUndoManagerDidCloseUndoGroupNotification`` just before the group is closed.
50        #[unsafe(method(endUndoGrouping))]
51        #[unsafe(method_family = none)]
52        pub unsafe fn endUndoGrouping(&self);
53
54        /// The number of nested undo groups (or redo groups, if Redo was invoked last) in the current event loop.
55        ///
56        /// An integer indicating the number of nested groups. If `0` is returned, there is no open undo or redo group.
57        #[unsafe(method(groupingLevel))]
58        #[unsafe(method_family = none)]
59        pub unsafe fn groupingLevel(&self) -> NSInteger;
60
61        /// Disables the recording of undo operations, whether by ``registerUndoWithTarget:selector:object:`` or by invocation-based undo.
62        ///
63        /// This method can be invoked multiple times by multiple clients. The ``enableUndoRegistration`` method must be invoked an equal number of times to re-enable undo registration.
64        #[unsafe(method(disableUndoRegistration))]
65        #[unsafe(method_family = none)]
66        pub unsafe fn disableUndoRegistration(&self);
67
68        /// Enables the recording of undo operations.
69        ///
70        /// Because undo registration is enabled by default, this is used to balance a prior ``disableUndoRegistration``. Undo registration isn’t actually re-enabled until an enable message balances the last disable message in effect.
71        /// Raises an NSInternalInconsistencyException if invoked while no disableUndoRegistration() message is in effect.
72        #[unsafe(method(enableUndoRegistration))]
73        #[unsafe(method_family = none)]
74        pub unsafe fn enableUndoRegistration(&self);
75
76        /// Whether the recording of undo operations is enabled.
77        #[unsafe(method(isUndoRegistrationEnabled))]
78        #[unsafe(method_family = none)]
79        pub unsafe fn isUndoRegistrationEnabled(&self) -> bool;
80
81        /// A Boolean value that indicates whether the receiver automatically creates undo groups around each pass of the run loop.
82        ///
83        /// If `true`, the receiver automatically creates undo groups around each pass of the run loop.
84        /// The default is `true`. If you turn automatic grouping off, you must close groups explicitly before invoking either ``undo`` or ``undoNestedGroup``.
85        #[unsafe(method(groupsByEvent))]
86        #[unsafe(method_family = none)]
87        pub unsafe fn groupsByEvent(&self) -> bool;
88
89        /// Setter for [`groupsByEvent`][Self::groupsByEvent].
90        #[unsafe(method(setGroupsByEvent:))]
91        #[unsafe(method_family = none)]
92        pub unsafe fn setGroupsByEvent(&self, groups_by_event: bool);
93
94        /// The maximum number of top-level undo groups the receiver holds.
95        ///
96        /// An integer specifying the number of undo groups. A limit of 0 indicates no limit, so old undo groups are never dropped.
97        /// When ending an undo group results in the number of groups exceeding this limit, the oldest groups are dropped from the stack. The default is 0.
98        /// If you change the limit to a level below the prior limit, old undo groups are immediately dropped.
99        #[unsafe(method(levelsOfUndo))]
100        #[unsafe(method_family = none)]
101        pub unsafe fn levelsOfUndo(&self) -> NSUInteger;
102
103        /// Setter for [`levelsOfUndo`][Self::levelsOfUndo].
104        #[unsafe(method(setLevelsOfUndo:))]
105        #[unsafe(method_family = none)]
106        pub unsafe fn setLevelsOfUndo(&self, levels_of_undo: NSUInteger);
107
108        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "NSString"))]
109        /// The modes governing the types of input handled during a cycle of the run loop.
110        ///
111        /// An array of string constants specifying the current run-loop modes.
112        /// By default, the sole run-loop mode is ``NSDefaultRunLoopMode`` (which excludes data from ``NSConnection`` objects). Some examples of other uses are to limit the input to data received during a mouse-tracking session by setting the mode to ``NSEventTrackingRunLoopMode``, or limit it to data received from a modal panel with ``NSModalPanelRunLoopMode``.
113        #[unsafe(method(runLoopModes))]
114        #[unsafe(method_family = none)]
115        pub unsafe fn runLoopModes(&self) -> Retained<NSArray<NSRunLoopMode>>;
116
117        #[cfg(all(feature = "NSArray", feature = "NSObjCRuntime", feature = "NSString"))]
118        /// Setter for [`runLoopModes`][Self::runLoopModes].
119        #[unsafe(method(setRunLoopModes:))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn setRunLoopModes(&self, run_loop_modes: &NSArray<NSRunLoopMode>);
122
123        /// Closes the top-level undo group if necessary and invokes ``undoNestedGroup``.
124        ///
125        /// This method also invokes ``endUndoGrouping`` if the nesting level is 1. Raises an ``NSInternalInconsistencyException`` if more than one undo group is open (that is, if the last group isn’t at the top level).
126        /// This method posts an ``NSUndoManagerCheckpointNotification``.
127        #[unsafe(method(undo))]
128        #[unsafe(method_family = none)]
129        pub unsafe fn undo(&self);
130
131        /// Performs the operations in the last group on the redo stack, if there are any, recording them on the undo stack as a single group.
132        ///
133        /// Raises an ``NSInternalInconsistencyException`` if the method is invoked during an undo operation.
134        /// This method posts an ``NSUndoManagerCheckpointNotification`` and ``NSUndoManagerWillRedoChangeNotification`` before it performs the redo operation, and it posts the ``NSUndoManagerDidRedoChangeNotification`` after it performs the redo operation.
135        #[unsafe(method(redo))]
136        #[unsafe(method_family = none)]
137        pub unsafe fn redo(&self);
138
139        /// Performs the undo operations in the last undo group (whether top-level or nested), recording the operations on the redo stack as a single group.
140        ///
141        /// Raises an ``NSInternalInconsistencyException`` if any undo operations have been registered since the last ``enableUndoRegistration`` message.
142        /// This method posts an ``NSUndoManagerCheckpointNotification`` and ``NSUndoManagerWillUndoChangeNotification`` before it performs the undo operation, and it posts an ``NSUndoManagerDidUndoChangeNotification`` after it performs the undo operation.
143        #[unsafe(method(undoNestedGroup))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn undoNestedGroup(&self);
146
147        /// Whether the receiver has any actions to undo.
148        ///
149        /// The return value does not mean you can safely invoke ``undo`` or ``undoNestedGroup`` — you may have to close open undo groups first.
150        #[unsafe(method(canUndo))]
151        #[unsafe(method_family = none)]
152        pub unsafe fn canUndo(&self) -> bool;
153
154        /// Whether the receiver has any actions to redo.
155        ///
156        /// Because any undo operation registered clears the redo stack, this method posts an NSUndoManagerCheckpointNotification to allow clients to apply their pending operations before testing the redo stack.
157        #[unsafe(method(canRedo))]
158        #[unsafe(method_family = none)]
159        pub unsafe fn canRedo(&self) -> bool;
160
161        /// How many times `undo` can be invoked before there are no more actions left to
162        /// be undone
163        #[unsafe(method(undoCount))]
164        #[unsafe(method_family = none)]
165        pub unsafe fn undoCount(&self) -> NSUInteger;
166
167        /// How many times `redo` can be invoked before there are no more actions left to
168        /// be redone
169        #[unsafe(method(redoCount))]
170        #[unsafe(method_family = none)]
171        pub unsafe fn redoCount(&self) -> NSUInteger;
172
173        /// Whether the receiver is in the process of performing its ``undo`` or ``undoNestedGroup`` method.
174        #[unsafe(method(isUndoing))]
175        #[unsafe(method_family = none)]
176        pub unsafe fn isUndoing(&self) -> bool;
177
178        /// Whether the receiver is in the process of performing its ``redo`` method.
179        #[unsafe(method(isRedoing))]
180        #[unsafe(method_family = none)]
181        pub unsafe fn isRedoing(&self) -> bool;
182
183        /// Clears the undo and redo stacks and re-enables the receiver.
184        #[unsafe(method(removeAllActions))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn removeAllActions(&self);
187
188        /// Clears the undo and redo stacks of all operations involving the specified target as the recipient of the undo message.
189        ///
190        /// Doesn't re-enable the receiver if it's disabled.
191        ///
192        /// - Parameter target: The recepient of the undo mesages to be removed.
193        #[unsafe(method(removeAllActionsWithTarget:))]
194        #[unsafe(method_family = none)]
195        pub unsafe fn removeAllActionsWithTarget(&self, target: &AnyObject);
196
197        /// Registers the selector of the specified target to implement a single undo operation that the target receives.
198        ///
199        /// - Parameter target: The target of the undo operation. The undo manager maintains an unowned reference to `target` to prevent retain cycles.
200        /// - Parameter selector: The selector for the undo operation.
201        /// - Parameter object: The argument sent with the selector. The undo manager maintains a strong reference to `object`
202        #[unsafe(method(registerUndoWithTarget:selector:object:))]
203        #[unsafe(method_family = none)]
204        pub unsafe fn registerUndoWithTarget_selector_object(
205            &self,
206            target: &AnyObject,
207            selector: Sel,
208            object: Option<&AnyObject>,
209        );
210
211        /// Prepares the undo manager for invocation-based undo with the given target as the subject of the next undo operation.
212        ///
213        /// For example, when called as:
214        ///
215        /// [[undoManager prepareWithInvocationTarget:target] setFont:oldFont color:oldColor]
216        ///
217        /// When undo is called, the specified target will be called with
218        ///
219        /// [target setFont:oldFont color:oldColor]
220        ///
221        /// - Parameter target: The target of the undo operation. The undo manager maintains a weak reference to `target`.
222        /// - Returns:  A proxy object that forwards messages to the undo manager for recording as undo actions.
223        #[unsafe(method(prepareWithInvocationTarget:))]
224        #[unsafe(method_family = none)]
225        pub unsafe fn prepareWithInvocationTarget(&self, target: &AnyObject)
226            -> Retained<AnyObject>;
227
228        #[cfg(feature = "block2")]
229        /// Records a single undo operation for a given target so that when an undo is performed, it executes the specified block.
230        ///
231        /// As with other undo operations, this does not strongly retain target. Care should be taken to avoid introducing retain cycles by other references captured by the block.
232        ///
233        /// - Parameter target: The target of the undo operation.
234        /// - Parameter undoHandler: The block to be executed when an operation is undone. The block takes a single argument, the target of the undo operation.
235        #[unsafe(method(registerUndoWithTarget:handler:))]
236        #[unsafe(method_family = none)]
237        pub unsafe fn registerUndoWithTarget_handler(
238            &self,
239            target: &AnyObject,
240            undo_handler: &block2::Block<dyn Fn(NonNull<AnyObject>)>,
241        );
242
243        /// Sets whether the next undo or redo action is discardable.
244        ///
245        /// Specifies that the latest undo action may be safely discarded when a document can not be saved for any reason.
246        /// An example might be an undo action that changes the viewable area of a document.
247        /// To find out if an undo group contains only discardable actions, look for the ``NSUndoManagerGroupIsDiscardableKey`` in the `userInfo` dictionary of the ``NSUndoManagerWillCloseUndoGroupNotification``.
248        ///
249        /// - Parameter discardable: Specifies if the action is discardable. YES if the next undo or redo action can be discarded; NO otherwise.
250        #[unsafe(method(setActionIsDiscardable:))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn setActionIsDiscardable(&self, discardable: bool);
253
254        /// Whether the next undo action is discardable.
255        ///
256        /// Specifies that the latest undo action may be safely discarded when a document can not be saved for any reason. These are typically actions that don’t affect persistent state.
257        /// An example might be an undo action that changes the viewable area of a document.
258        #[unsafe(method(undoActionIsDiscardable))]
259        #[unsafe(method_family = none)]
260        pub unsafe fn undoActionIsDiscardable(&self) -> bool;
261
262        /// Whether the next redo action is discardable.
263        ///
264        /// Specifies that the latest redo action may be safely discarded when a document can not be saved for any reason. These are typically actions that don’t affect persistent state.
265        /// An example might be an redo action that changes the viewable area of a document.
266        #[unsafe(method(redoActionIsDiscardable))]
267        #[unsafe(method_family = none)]
268        pub unsafe fn redoActionIsDiscardable(&self) -> bool;
269
270        #[cfg(feature = "NSString")]
271        /// The name identifying the undo action.
272        ///
273        /// The undo action name. Returns an empty string if no action name has been assigned or if there is nothing to undo.
274        /// For example, if the menu title is “Undo Delete,” the string returned is “Delete.”
275        #[unsafe(method(undoActionName))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn undoActionName(&self) -> Retained<NSString>;
278
279        #[cfg(feature = "NSString")]
280        /// The name identifying the redo action.
281        ///
282        /// The redo action name. Returns an empty string if no action name has been assigned or if there is nothing to redo.
283        /// For example, if the menu title is “Redo Delete,” the string returned is “Delete.”
284        #[unsafe(method(redoActionName))]
285        #[unsafe(method_family = none)]
286        pub unsafe fn redoActionName(&self) -> Retained<NSString>;
287
288        #[cfg(feature = "NSString")]
289        /// Sets the name of the action associated with the Undo or Redo command.
290        ///
291        /// If actionName is an empty string, the action name currently associated with the menu command is removed. There is no effect if actionName is nil.
292        ///
293        /// - Parameter actionName: The name of the action.
294        #[unsafe(method(setActionName:))]
295        #[unsafe(method_family = none)]
296        pub unsafe fn setActionName(&self, action_name: &NSString);
297
298        #[cfg(feature = "NSString")]
299        /// Get a value from the undo action's user info
300        ///
301        /// - Parameter key: Which value should be retrieved
302        #[unsafe(method(undoActionUserInfoValueForKey:))]
303        #[unsafe(method_family = none)]
304        pub unsafe fn undoActionUserInfoValueForKey(
305            &self,
306            key: &NSUndoManagerUserInfoKey,
307        ) -> Option<Retained<AnyObject>>;
308
309        #[cfg(feature = "NSString")]
310        /// Get a value from the redo action's user info
311        ///
312        /// - Parameter key: Which value should be retrieved
313        #[unsafe(method(redoActionUserInfoValueForKey:))]
314        #[unsafe(method_family = none)]
315        pub unsafe fn redoActionUserInfoValueForKey(
316            &self,
317            key: &NSUndoManagerUserInfoKey,
318        ) -> Option<Retained<AnyObject>>;
319
320        #[cfg(feature = "NSString")]
321        /// Set user info for the Undo or Redo command.
322        /// - Parameter info: Value to be saved in the user info
323        /// - Parameter key: Key at which the object should be saved
324        #[unsafe(method(setActionUserInfoValue:forKey:))]
325        #[unsafe(method_family = none)]
326        pub unsafe fn setActionUserInfoValue_forKey(
327            &self,
328            info: Option<&AnyObject>,
329            key: &NSUndoManagerUserInfoKey,
330        );
331
332        #[cfg(feature = "NSString")]
333        /// The complete title of the Undo menu command, for example, “Undo Paste.”
334        ///
335        /// Returns “Undo” if no action name has been assigned or nil if there is nothing to undo.
336        #[unsafe(method(undoMenuItemTitle))]
337        #[unsafe(method_family = none)]
338        pub unsafe fn undoMenuItemTitle(&self) -> Retained<NSString>;
339
340        #[cfg(feature = "NSString")]
341        /// The complete title of the Redo menu command, for example, “Redo Paste.”
342        ///
343        /// Returns “Redo” if no action name has been assigned or nil if there is nothing to redo.
344        #[unsafe(method(redoMenuItemTitle))]
345        #[unsafe(method_family = none)]
346        pub unsafe fn redoMenuItemTitle(&self) -> Retained<NSString>;
347
348        #[cfg(feature = "NSString")]
349        /// Returns the complete, localized title of the Undo menu command for the action identified by the given name.
350        ///
351        /// Override this method if you want to customize the localization behaviour. This method is invoked by ``undoMenuItemTitle``.
352        ///
353        /// - Parameter actionName: The name of the undo action.
354        /// - Returns: The localized title of the undo menu item.
355        #[unsafe(method(undoMenuTitleForUndoActionName:))]
356        #[unsafe(method_family = none)]
357        pub unsafe fn undoMenuTitleForUndoActionName(
358            &self,
359            action_name: &NSString,
360        ) -> Retained<NSString>;
361
362        #[cfg(feature = "NSString")]
363        /// Returns the complete, localized title of the Redo menu command for the action identified by the given name.
364        ///
365        /// Override this method if you want to customize the localization behaviour. This method is invoked by ``redoMenuItemTitle``.
366        ///
367        /// - Parameter actionName: The name of the redo action.
368        /// - Returns: The localized title of the redo menu item.
369        #[unsafe(method(redoMenuTitleForUndoActionName:))]
370        #[unsafe(method_family = none)]
371        pub unsafe fn redoMenuTitleForUndoActionName(
372            &self,
373            action_name: &NSString,
374        ) -> Retained<NSString>;
375    );
376}
377
378/// Methods declared on superclass `NSObject`.
379impl NSUndoManager {
380    extern_methods!(
381        #[unsafe(method(init))]
382        #[unsafe(method_family = init)]
383        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
384
385        #[unsafe(method(new))]
386        #[unsafe(method_family = new)]
387        pub unsafe fn new() -> Retained<Self>;
388    );
389}
390
391extern "C" {
392    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagercheckpointnotification?language=objc)
393    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
394    pub static NSUndoManagerCheckpointNotification: &'static NSNotificationName;
395}
396
397extern "C" {
398    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerwillundochangenotification?language=objc)
399    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
400    pub static NSUndoManagerWillUndoChangeNotification: &'static NSNotificationName;
401}
402
403extern "C" {
404    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerwillredochangenotification?language=objc)
405    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
406    pub static NSUndoManagerWillRedoChangeNotification: &'static NSNotificationName;
407}
408
409extern "C" {
410    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerdidundochangenotification?language=objc)
411    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
412    pub static NSUndoManagerDidUndoChangeNotification: &'static NSNotificationName;
413}
414
415extern "C" {
416    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerdidredochangenotification?language=objc)
417    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
418    pub static NSUndoManagerDidRedoChangeNotification: &'static NSNotificationName;
419}
420
421extern "C" {
422    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerdidopenundogroupnotification?language=objc)
423    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
424    pub static NSUndoManagerDidOpenUndoGroupNotification: &'static NSNotificationName;
425}
426
427extern "C" {
428    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerwillcloseundogroupnotification?language=objc)
429    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
430    pub static NSUndoManagerWillCloseUndoGroupNotification: &'static NSNotificationName;
431}
432
433extern "C" {
434    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsundomanagerdidcloseundogroupnotification?language=objc)
435    #[cfg(all(feature = "NSNotification", feature = "NSString"))]
436    pub static NSUndoManagerDidCloseUndoGroupNotification: &'static NSNotificationName;
437}