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