GenericUI - FileSave

Discussion of the xtools Toolkit

Moderators:xbytor, DavideBarranca, Paul MR

Post Reply
undavide
GenericUI - FileSave

Post by undavide » Wed Jun 16, 2010 12:50 pm

Hello,
I'm studying the GenericUI and SampleUI code, I'm particularly interested in the FileSave part.
In the SampleUI script, the GUI contains the Save Options section, but the call for the file saving within the SampleUI.prototype.process function isn't linked to the panel file saving options - so the result is always a PSD file even if I switch to, say, JPG.
Is there any code sample with the the file saving options actually enabled?
Thanks in advance,

Davide

xbytor

GenericUI - FileSave

Post by xbytor » Wed Jun 16, 2010 4:39 pm

There is some code missing.

In validatePanel, you need a line like this:

Code: Select all    self.validateFileSavePanel(pnl.filesave, opts);

That will populate 'opts' with whatever the settings are in the FileSave panel.

Later on, when you are in your 'process' function, you can retrieve an appropriate type of *SaveOptions object by a call like

Code: Select all    var saveOpts = FileSaveOptions.convert(opts);

This can then be used like this

Code: Select all   doc.saveAs(file, saveOpts);


There are other subtleties that you may or may not have to worry about. For instance, if the file type is jpg and the doc is 16bit, you should probably convert to 8bit before the save.

CSX uses the FileSave panel if you want a real-world example of how to use the FileSave panel. But I will add code to the SampleUI script so that it does the use the save options that you specify in the UI.

-X

undavide

GenericUI - FileSave

Post by undavide » Wed Jun 16, 2010 4:53 pm


Works like a charm, thank you so much.
I definitely have to study some more object oriented javascript...
Thanks again,

Davide

Post Reply