nsdocument

Where do you put cleanup code for NSDocument sub-classes?

I have a document-based application and I have sub-classed NSDocument and provided the required methods, but my document needs some extensive clean-up (needs to run external tasks etc). Where is the best place to put this? I have tried a few different methods such as: close close: canCloseDocumentWithDelegate:shouldCloseSelector:contex...

Enabling Save for an NSDocument

Hello, I am using an NSDocumentController subclass to do some custom stuff when I create my NSDocuments. The strange thing is that when the document is created, the Save option in the menu is disabled. The problem is that I use the save function to save something manually out from the document so it's decoupled from the main NSDocument ...

Multiple Documents in a Single Window in Cocoa

I want to write an application which may have multiple documents in a single window via a tabbed interface. Should I avoid the NSDocument architecture (the Cocoa Document-based Application template)? As far as I can tell, it supports only one or more window per document but not vice versa. I have been wrestling with this question for ...

Validate before opening a document in NSDocument architecture

I have an document based application which formats an XML file. Writing and reading of document is done in my NSDocument subclass - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError but if the fil...

NSDocument architecture pros and cons

Does anybody have any NSDocument pros and cons they'd like to share? In particular: Once you depend on the NSDocument architecture, is it difficult to refactor it out if you need to? Are there performance implications? Does it limit you in certain/many ways? ...

Problem with NSDocument and writeToURL:ofType:error:

I'm working on a document-based application, and I want to use a document package as my file format. To do that, it seems that the NSDocument method I need to override is -writeToURL:ofType:error:. It sometimes works, but only under certain conditions. For example, this code works: - (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSStri...

How to associate an action to a keyboard shortcut?

Hi all, I've an IBAction that calls up a panel. I want to invoke that action with a keyboard shortcut but I'm at a loss on how to do it. I guess one way of doing it would be to create a menu item, associate the action to the item and then assign the shortcut to that item, but I haven't done my menus yet. Any ideas or suggestions? ...

How do I define a writable type for an application with a "Viewer" role?

I have an application that has the Viewer role for PDF files. Although my application does not edit the PDF files, it does allow the user to save the PDF file (if it is too large or complex for the workflow that my application handles). When the SaveDocumentAs: method is called, I get the following warning: Trying to save a document...

How can I create a document-based application that cannot create a new document?

I have a document-based application that is designed to process existing documents, not to create new documents. How do I prevent the application from creating a new, blank document when launched by opening it from the Finder? ...

Use ZIP-archives to store NSDocument data

I noticed that Apple started using zip archives to replace document packages (folders appearing as a single file in Finder) in the iWork applications. I'm considering doing the same as I keep getting support emails related to my document packages getting corrupted when copying them to a windows fileserver. My questions is what would be ...

WebView Cocoa control crashing on window close.

I get a crash in WebEditorClient::clearUndoRedoOperations which is trying to access -[WebView(WebViewEditing) undoManager] when I close the main window of an NSDocument that contains a webview with a text editor in it. It only happens when there is an undo-able state. Seems like a bug in Cocoa, but I might be doing something wrong. Any i...

Changing file extension for a 'save as' in NSDocument?

Hi, I want to give my app, which currently simply saves out folders, the option of giving these folders file extensions (for saving packages). At the moment, when I do 'saveDocumentAs:', I get the save sheet with 'Untitled' as the suggested filename, how can I optionaly make it say (for example) 'Untitled.myext'? Cheers MT ...

Closing a document's window and opening a new one, without closing the document

My app is document-based, but the “document” consists of two folders, not one file. The document's initial window contains a couple of file pickers and a button; the action closes that window and opens a new one showing the results of the operation between the two folder hierarchies. (The two windows are significantly different in size; ...

NSImage readFromData problem

I am trying to make a simple document-based cocoa application that can save and load images in pdf files. For the save part, I am using - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { return [imageView dataWithPDFInsideRect:[imageView bounds]]; } And this works, the image could be saved to a PDF file. Fo...

Cleanest way to create multiple NSDocuments from NSData

Hi, I am writing a document based application on OS X. One feature oft this application will be an "import" function. This function will read data files from the disk which contain data as raw BLOBs and can be parsed into one oder more documents. For this function I will have to create documents programatically. The main problem is, th...

Saving a file when using NSDocument

Hi, I am creating an application using NSDocument. MyDocument.xib just has an NSTextView in an NSScrollView. When I do a ⌘S to save it, I get an error message ( 'The document “Untitled” could not be saved as “Untitled.rubytext”. '). How can I make my application save it as an RTF file? I mean using NSDocument (I guess dataRepresentation...

Specify a File Name and Path for an NSPersistentDocument

In Cocoa, when the user wants the document they're working on saved I need to have the file saved with a specific file name and path. The functionality I'd like is after the sheet comes up that says "Do you want to save the changes..." and the user presses "Save", I provide the file name and path and the file saves (for new documents of...

Hacking the NSDocument architecture

I'm working on creating an NSDocument-based app with tabs for documents. I have found that it wasn't really designed for this. Apple designed the architechture to allow multiple windows for a single document but not the other way around. I have it basically working but I have started to run into weird issues. For example, when a window i...

Saving image to Documents directory and retrieving for email attachment

THANKS..This Works now. I having trouble figuring out NSBundle & DocumentDirectory data, I have a Camera Picture "imageView" that I'm saving to the NSDocumentDirectoy and then want to retrieve it for attaching to an email, Here the saving code: - (IBAction)saveImage { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentD...

Create subfolder in NSDocumentDirectory

hello, I just wanted to know is it's possible to create a subfolder in the NSDocumentDirectory and write data into that created folder, like: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *dirPath =[[paths objectAtIndex:0] stringAppendingPathComponent:@"TestFolder"]; NSS...