discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: custom options during save in a document app


From: Wolfgang Lux
Subject: Re: custom options during save in a document app
Date: Fri, 5 Oct 2012 12:05:37 +0200

Hi Riccardo,

> Hi Fred & Nikolaus,
> 
> thank you for your suggestions, they were mostly overlapping, so I was 
> confident it was the best way!
> 
> Fred Kiefer wrote:
>> You best options here is to override the method -prepareSavePanel in our 
>> NSDocument subclass, which is the Apple recommended way of doing this. You 
>> will also have to override shouldRunSavePanelWithAccessoryView to return NO, 
>> otherwise the standard accessory view will still be displayed.
>> 
>> From there on down you will have to replace all the standard NSDocument 
>> methods to handle your additional parameters. There is no way around that.
> by searching on the web I found another important method to override:
> - (NSString *)fileTypeFromLastRunSavePanel
> 
> which is very important if the new accessory view changes the filetype. I 
> found no other way to "set it", since setFileType doesn't work.
> 
> I have one problem though: the file extension.
> 
> Previously, i was running this in saveDocumentAs (thus "before")
>    filepath = [[filepath stringByDeletingPathExtension] 
> stringByAppendingString: @".tiff"];
>    [self setFileName:filepath];
>    [self setFileType: @"tiff"];
> 
> that's easy, since I only have one filetype, I could preset the extension and 
> normalize it before opening the panel. I may have many extensions, because 
> PRICE is "editor" of only TIFF files (or, in the future JPEG and a few 
> others) but "opens" all file types supported by GUI.
> 
> The best would be that on the change of the filetype popup (don't try that on 
> GNUstep yet or, if, substitute PRWindow.gorm file with PRWindow.nib, there is 
> a strange bug affecting only gorm).
> 
> How can I set the filename with the filepanel running? The filetype is not a 
> problem since it gets "set" later cleanly with the method mentioned above.

I think you are on a completely wrong track here. If you want to add a JPEG 
file type to PRICE, you should declare that in the NSTypes (or 
CFBundleDocumentTypes) section of the Info.plist file as a separate type, but 
using the same NSDocumentClass as for TIFF files. Then, the NSDocument 
framework will automatically handle the file type and file extension for you 
and you shouldn't override saveDocumentAs: (it will not work in the way you'd 
expect on OS X anyway thanks to document modal sheets anyway).

To add options for the JPEG type you must add an accessory view to the save 
panel in -prepareSavePanel:, as Fred and Nikolaus suggested. Make sure you save 
the values selected by the user in attributes of your document class, so you 
have them available in -dataRepresentationOfType:

Wolfgang




reply via email to

[Prev in Thread] Current Thread [Next in Thread]