/*すべての線幅を変更_CS3.jsx　2016.03.09（z-）
http//ajabon.catfood.jp/
下記オリジナル作品の下位バージョン対応版。
　オリジナルとの相違点は、
    ・設定が保存されない
    ・複数オブジェクトには対応しない 
    ・修飾キーによるプレビュー未対応　など。*/

/*
すべての線幅を変更.jsx
Copyright (c) 2016 Toshiyuki Takahashi
Released under the MIT license
http://opensource.org/licenses/mit-license.php
http://www.graphicartsunit.com/
*/

var dlg = new Window("dialog{text:'すべての線幅を変更_cs3', \
G1:Group{orientation:'row', \
S:StaticText{text:'比率'}, \
E:EditText{text:'50', characters:8}, \
S:StaticText{text:'%'} \
}, \
G2:Group{orientation:'row', \
C:Checkbox{value:true, text:'プレビュー　'}, \
CB:Button{text:'キャンセル'}, \
OB:Button{text:'実行'}\
}\
}");
var defScale = 100;
var flag = false;
dlg.G1.E.onChange = function(){
    if(dlg.G2.C.value){
        resizeStrokeWeight();
        }
    }

dlg.G2.OB.onClick = function(){
    if(flag == false){
        resizeStrokeWeight();
        }
    dlg.close();
    }

dlg.G2.CB.onClick = function(){
    if(flag == true){
        app.undo();
        }
    dlg.close();
    }

dlg.G2.C.onClick = function(){
    if(this.value == true){
        dlg.G1.E.notify("onChange");
        flag = true;
        }
    else{
        if(flag == true){
            app.undo();
            app.redraw();
            }
        flag = false;
        }
    }

dlg.show();

function resizeStrokeWeight(){
    if(flag == true){
        app.undo();
        flag = false;
        }
    try{
        app.activeDocument.selection[0].resize(100, 100, true, false, false, false, (dlg.G1.E.text - 0) < 1000? dlg.G1.E.text - 0 : 1000, undefined);
        //app.activeDocument.selection[0].resize(100, 100, true, false, false, false, 200, undefined);
        app.redraw();
        flag = true;
        } catch(e) {}
    }