nsundomanager

Invocation-based Undo Manager in Swift [duplicate]

穿精又带淫゛_ 提交于 2019-12-25 03:09:35
问题 This question already has answers here : NSUndoManager casting NSUndoManagerProxy crash in Swift code (2 answers) Closed 2 years ago . I'm having trouble adopting the more complex invocation-based approach to undo registration in Swift (based on NSHipster article here. Apple's docs still have all sample code in Objective-C, and the semantics are very different for the invocation setup). My NSDocument subclass Document has the following method that operates on the model objects, which I wish

undo all changes made in a view controller

99封情书 提交于 2019-12-25 00:23:20
问题 Is it possible to undo all changes made in a view controller without affecting the changes made in its parent view controller? btw. They are with the same managedObjectContext. ps. I have two entities A and B. A has an to-many relationships to B. View controller VCA is used to perform some changes in A. View controller VCB is used to perform some changes in B. VCA is the parent view controller of VCB. 回答1: No need to create a new context. When you leave the child view controller, you have the

Removing undo actions for a WebView's NSUndoManager

此生再无相见时 提交于 2019-12-23 12:28:04
问题 I have several WebViews that I swap in and out of my view hierarchy. Some of these WebViews contain form fields, so I implement the editingDelegate to provide the NSUndoManager for my document. The problem is that any typing done in the WebView generates actions that are placed on the undo stack. After the view is removed from the hierarchy, the actions are still in the undo stack. At that point, if a user uses Cmd-Z to "Undo Typing", an exception is thrown because -undoEditing: is being sent

Undo action names for Core Data changes

末鹿安然 提交于 2019-12-21 17:28:56
问题 I'm looking for a built-in (or easy-to-implement) way to get Core Data undo/redo action names to read like "Undo edit First Name", rather than simply "Undo" or "Redo" as they do by default. I have a Core Data application, and am using its NSUndoManager as my window's undo manager. It works great, but when a user makes a change to a field (inline from an NSTableView ), the Undo menu item's title doesn't reflect which field changed. Initial searching led me to the same question posted on Apple

NSUndoManager, Core Data and selective undo/redo

核能气质少年 提交于 2019-12-21 10:46:11
问题 I'm working on a core data application that has a rather large hierarchy of managed objects similar to a tree. When a base object is created, it creates a few child objects which in turn create their own child objects and so on. Each of these child objects may gather information using NSURLConnections. Now, I'd like to support undo/redo with the undoManager in the managedObjectContext. The problem is, if a user creates a base object, then tries to undo that action, the base object is not

Nested undo group with CoreData

穿精又带淫゛_ 提交于 2019-12-21 01:59:16
问题 I want to add a undo manager to a coredata backed iphone application. When the user tries to add a new object (by tapping on + button) I load a new modal viewcontroller and start a new undo group in viewDidLoad. When the user presses Cancel button, I want to rollback the changes in cancelAction callback. Queries: Is it possible to start a nested Undo group and persist it through event loop and collate all the changes done in one single undo group? Right now, when I call beginUndoGrouping in

Using NSUndoManager and .prepare(withInvocationTarget:) in Swift 3

老子叫甜甜 提交于 2019-12-19 06:17:08
问题 I am migrating an Xcode 7 / Swift 2.2 mac OS X project to Xcode 8 / Swift 3, and I have run into a problem using undoManager in my view controller class, MyViewController, which has a function undo. In Xcode 7 / Swift 2.2, this worked fine: undoManager?.prepareWithInvocationTarget(self).undo(data, moreData: moreData) undoManager?.setActionName("Change Data) In Xcode 8 / Swift 3, using the recommended pattern from https://developer.apple.com/library/content/documentation/Swift/Conceptual

Using NSUndoManager and .prepare(withInvocationTarget:) in Swift 3

别等时光非礼了梦想. 提交于 2019-12-19 06:17:03
问题 I am migrating an Xcode 7 / Swift 2.2 mac OS X project to Xcode 8 / Swift 3, and I have run into a problem using undoManager in my view controller class, MyViewController, which has a function undo. In Xcode 7 / Swift 2.2, this worked fine: undoManager?.prepareWithInvocationTarget(self).undo(data, moreData: moreData) undoManager?.setActionName("Change Data) In Xcode 8 / Swift 3, using the recommended pattern from https://developer.apple.com/library/content/documentation/Swift/Conceptual

Cocoa: looking for a general strategy for programmatic manipulation of NSTextView storage without messing up undo

梦想与她 提交于 2019-12-18 11:08:24
问题 I am writing a special-purpose text editor in cocoa that does things like automatic text substitution, inline text completions (ala Xcode ), etc. I need to be able to programmatically manipulate the NSTextView ’s NSTextStorage in response to 1) user typing, 2) user pasting, 3) user dropping text. I have tried two different general approaches and both of them have caused the NSTextView ’s native undo manager to get out of sync in different ways. In each case, I am only using NSTextView

How do I register UndoManager in Swift?

送分小仙女□ 提交于 2019-12-17 18:55:17
问题 How do I use UndoManager (previously NSUndoManager ) in Swift? Here's an Objective-C example I've tried to replicate: [[undoManager prepareWithInvocationTarget:self] myArgumentlessMethod]; Swift, however, seems to not have NSInvocation , which (seemingly) means I can't call methods on the undoManager that it doesn't implement. I've tried the object-based version in Swift, but it seems to crash my Playground: undoManager.registerUndoWithTarget(self, selector: Selector("myMethod"), object: nil)