Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

A "preview" checkbox with JavaScript

$
0
0

Hi friends.

 

I´m writting a JavaScript that sends the active document in an appropriated way to print. Before calling the print command, I wanna display a dialog box asking the number of copies to print. So I thought I could also use this box to show some "auto" adjustments options (for example "auto levels"). If the user active "Apply auto-levels" then image refreshes to show the result (like a live preview). If user disables this box, then auto levels must be retired from image.

 

Well..hope you do not laught on my solution. The way I found to do it is..apply auto levels and refresh when user enables the field, and return in the history and refresh if the user disables this field. It get the expected result. BUT, if I have more checkboxes in the same dialog box, then this solution will not work so well (sure).

 

Do you have any other consistent solution to have previews of commands, but retire if the user disables the field?? Would like to learn a little about it.

 

Well..what I do (the solution I´ve mentioned above) is:

 

 

var doc = app.activeDocument;

var c = doc.activeLayer;

 

 

var dial = new Window ("dialog", "Print", undefined, {closeButton:false});

dial.orientation = "column";

dial.alignChildren = "fill";

dial.margins = 20;

 

 

var dPanel = dial.add ("panel", undefined, "Print options:");

dPanel.orientation = "column";

dPanel.alignChildren = "left";

dPanel.margins = 15;

 

 

var aLevels = dPanel.add ("checkbox", undefined, "Apply auto levels");

 

 

var dGroup = dial.add ("group", undefined);

dGroup.orientation = "row";

dGroup.alignChildren = "left";

 

 

var st = dGroup.add ("statictext", undefined, "Copies:");

 

 

var nField = dGroup.add ("edittext", undefined, "1");

nField.characters = 10;

 

 

var gButtons = dial.add ("group", undefined);

gButtons.orientation = "row";

gButtons.alignChildren = ["right", "right"];

 

 

var exe = gButtons.add ("button", undefined, "Execute", {name:"ok"});

 

 

var canc = gButtons.add ("button", undefined, "Cancel", {name:"cancel"});

 

 

 

aLevels.onClick = function (){

   

    if (aLevels.value){

        c.autoLevels();

        app.refresh();

    };

    else

    if (! aLevels.value){

        doc.activeHistoryState = doc.historyStates[doc.historyStates.length-2];

        app.refresh();

    };   

};

   

dial.show();

 

 

Any idea to forget all of this and make a real "preview" checkbox?


Viewing all articles
Browse latest Browse all 12244

Trending Articles