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