NSTextStorage, Core Data and NSUndoManager - How to track changes? - objective-c

Imagine a managed object that has got a transient attribute of type NSTextStorage. This gets archived into a binary NSData object on save. On edit I swap the textStorage of the NSTextView so all the changes go directly into the text storage. This way I can update other managed objects that are related to certain text locations without leaving the context in an inconsistent state and other UI elements using the same text storage get updated immediately.
The trouble is that the managed object context's undoManager doesn't know what to do with the text storage on undo/redo. I think it's because the undo actions are handled by the text view.
So I was thinking I could just serialise/archive the text storage on every change and replace the text storage contents with its unarchived contents. I've tested it even with longer text documents and it's not a real bottleneck on a Mac. But how do I get the undo manager to use it ? Or is there a totally different way to get it to work.
I've put a sample project up on http://cl.ly/3B1P0r2P1i0m

Related

QlikView Text Object Formatting

I am unable to format the text in a text object. For example, I need headers in bold, while the body of the text could be normal. Can I get any hints on this?
I know this can be achieved via extension objects, but I do not have any experience creating them.
This is not currently possible in QlikView 11. It has been an open development request for quite some time.
You have two options:
Use multiple text objects and lay them over each other (i.e. make the topmost one bold and its background transparent).
Use an extension object, however, this then restricts you to AJAX/WebView for your document. There is an existing extension (written by Stefan Walther) that has this capability here (git repo).

How to show document preview in iCloud conflicts sheet in Mac App using NSDocument

I am creating a Mac App, using NSDocument, that stores a custom class of documents to iCloud.
I was able to get the program to store documents to iCloud quite easily by just Code Signing it, Sandboxing it, and adding iCloud entitlements; however, I'm still encountering a problem where when I trigger an iCloud conflict and the program drops down the sheet allowing the user to resolve the conflict the rows in the sheet do not show the small image of the document (like Preview and TextEdit do).
Additionally, when I click on the area where the image should be (it's blank) it opens up a Quick Look window that just displays an image of the Document Icon together with some other information as opposed to a snap shot of the actual file like Preview and TextEdit do.
I have not found any information in Apple's documentation that explains what I need to do to implement the same behaviour as Preview and TextEdit.
So far I've been surprised by how easily I've been able to get all of the functionability of not only the Auto Saves and the Versions browser, but also saving to the Cloud. NSDocument seems to do all of this for the developer (resolving iCloud Conflicts, etc.), as Apple's documents says it does, but again I'm not getting this other behaviour and I don't want to reinvent the wheel by writing code that is not needed.
I'm thinking that the answer might lie somewhere with implementing a Quick Look thumbnail (for the small image in the table in the sheet) and a Quick Look preview for the larger preview of the document when that in the sheet is clicked on, but this seems like a lot of work and I'm afraid of losing some of the other build-in functions of NSDocument if I start "trapping" NSDocument routines up the food chain so to speak.
Has anyone else encountered this problem and found the easiest solution?
Update: Dec. 25/12
I've finally figured out that the problem is I need a QuickLook generator to display both a QL Thumbnail (which shows up in the table in the conflicts sheet) and a QL Preview (which is displayed when a user clicks on the Thumbnail)
I ended up creating the QL generator project, and afterwards creating a workspace which I added my main project and the QL generator project to. After that I added a Copy Files Build Phase to the main project to copy the QL generator into the main Application bundle.

Storing NSFont to document

Our picture editing cocoa application allows the user to add a string to a photo. This string has an associated NSFont object. We want to store this NSFont object in the saved document. Is using archiving NSFont using NSCoding the best way around?
I would have thought you would be better off storing an NSFontDescriptor, since that way you have more control over exactly which font you use when your editing app finds itself opening a file on a machine that doesn’t have the font that was used when the file was saved.

Graphic image saving in text editor?

I am making a basic text editor from this tutorial here:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextArchitecture/Tasks/TextEditor.html
My text editor can save, write, and open documents in RTF and TXT format, but cannot save graphics along with any text. Formatted text is saved, and the graphic does display when the window is open, but does not get saved.
You're almost there, you just need to implement a bit more in your app's Info.plist.
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSData *data;
[self setString:[textView textStorage]];
NSMutableDictionary *dict =
[NSDictionary dictionaryWithObject:NSRTFTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
Notice that in the method which asks for the data to be saved to file, no matter what, it's set up to use NSRTFTextDocumentType rather than NSRTF*D*TextDocumentType. RTFD means RTF with attachments, which saves an .rtfd document which is actually a package/bundle (a folder that is presented to the user as if it were a single file). Saving as NSRTFTextDocumentType will effectively discard the stuff that can't fit into an RTF document, like the images.
After step 12 is the following:
At this stage of its development, your editor opens and saves documents only with an extension of ????. To enable your application to save and open documents with a recognized file type, you need to use Xcode to configure the document types settings in the application’s property list file in the Resources folder in Xcode. (The Xcode template names the file with your project name followed by -Info.plist.) You can edit this file in Xcode by selecting the file in the Groups & Files list and using the built-in editor. Click the disclosure triangles to edit the value of the first item under CFBundleTypeExtensions to the preferred extension for your document files.
For more information about property list files, see “Storing Document Types Information in the Application's Property List” in Document-Based Applications Overview. For complete details about application property lists, see Runtime Configuration Guidelines.
Basically, right now, you're being passed in a generic DocumentType in that data method shown above. Once you claim in your Info.plist that you can handle RTF and RTFD data (as 2 separate entries), you will be passed in a different value in that method, depending on what the user has chosen in the Format popup button in the NSSavePanel. You can check the value of the passed in type and then specify NSRTFTextDocumentType or NSRTFDTextDocumentType accordingly.
You can probably look at TextEdit's Info.plist to use as the basis of your Document types, though be sure to change the NSDocument subclass name to your own so the NSDocumentController knows what class to use.
maybe your images are not saved in the same directory?
for example if I create a rtf document with TextEdit it creates an folder called something.rtfd and contains the TXT.rtf and all the images.

Is it possible to reference a photoshop file or layer comp from within another photoshop file?

Creating all the art for a large website often involves a couple dozen 50+mb photoshop files. Frequently, a given module may appear in more than one file.
Is there a way to reference an oft-used module from another file?
For instance -
"site-section-2.psd" references "common-module-h.psd", and "site-section-6.psd" also references "common-module-h.psd", so that any time updates are made to "common-module-h.psd", the updates appear in both files which reference it.
Possible?
(maybe with photoshop javascript?)
I've checked the JSX Photoshop Object Model, and you can access LayerComps, but there is no magic function to save from one file to another. Something like this could be written to disk, from file1.psd for example, then loaded into file2.psd.
It's a bit of a long shot and I don't know if it's worth the trouble.
For web prototyping I use Fireworks and and I'm pretty happy. You can easily create symbols (much like in Flash and Illustrator) and even save them to a Common Library, which means it will be easy peasy to keep your navigation items for example up to date, for all the files using it. You can even import PSD files into Fireworks, only not all the filters will be supported.
Don't know if you can keep most of the eye-candy in Photoshop and then assemble reamble versions with ease using Fireworks.
You can try converting all the layers into one smart object and then drag the smart object layer into the new .psd file.
Go to the Layers palette: Window > Layers(F7).
LMB SINGLE CLICK the top layer.
Scroll down Layer palette until you get to the bottom.
SHIFT + LMB SINGLE CLICK. At this point all the layers should be hilighted.
RMB SINGLE CLICK any of Layer "Titles".
You should see a menu pop up so use the mouse to scroll until you find "Convert to Smart Object". LMB SINGLE CLICK to convert all the layers into one smart object. The smart object can be edited by double clicking it in the Layers palette. You can also drag a smart object from one .PSD into another .PSD. I usually just open both .PSD files and drag the smart object form one Layers palette to the other Layers palette.