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 15:17:14 +0200

Riccardo Mottola wrote:

> Hi Wolfgang,
> 
> Wolfgang Lux wrote:
>> Hi Riccardo,
>> 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:
>> 
> Exactly, I added an accessory view, however as far as I understand, the 
> document types are now my burden. I do not want to override saveDocumentAs 
> anymore, at least not for this need. I can read back what was selected with 
> fileTypeFromLastRunSavePanel, however in the "standard" view which these the 
> type selection generated by the NSDocumentClass are handled automatically. In 
> the standard panel, selection them does change the extension of the file 
> directly (and perhaps does other things too and I want to emulate this).
> 
> Your suggestion would be then to populate the popup dynamically by the 
> supported NSDocumentClass types? That would be a further plus that adds some 
> burden, since some have certain options other others, but could be cool.

What I meant (and I guess I wasn't clear about that) is that you should not try 
to reimplement any functionality provided by NSDocument. NSDocument has already 
created the pop up with the document types at the time -prepareSavePanel: is 
called. So in your implementation of that method just ask the save panel for 
its current accessory view and add your own elements to that view (you may 
eventually need to resize the existing view for that). Or make the existing 
accessory view a subview of your own accessory view. If you want to dynamically 
change the save panel options depending on the document type currently chosen 
by the user, you can do so by overriding the (undocumented) NSDocument method 
-changeSaveType:. However, if you do so, be sure to call the super class 
implementation in your own method.

Wolfgang




reply via email to

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