-
Notifications
You must be signed in to change notification settings - Fork 4
/
progressbar.jsx
64 lines (64 loc) · 1.73 KB
/
progressbar.jsx
1
//构建progressbar核心逻辑,非public方法,仅jsx内部调用function createProgressWindow(title, message, total, hasCancelButton) { this.winRef = null; var win; if (title == null) { title = "Work in progress"; } if (message == null) { message = "Please wait..."; } if (hasCancelButton == null) { hasCancelButton = false; } win = new Window("palette", title, undefined); this.winRef = win; win.bar = win.add("progressbar", { x: 20, y: 12, width: 300, height: 20 }, 0, total); win.stMessage = win.add("statictext", { x: 10, y: 36, width: 320, height: 20 }, "" + message); win.stMessage.justify = 'center'; this.reset = function(message) { win.bar.value = 0; win.stMessage.text = message; return win.update(); }; this.updateProgress = function(perc, message) { if (perc != null) { win.bar.value = perc; } if (message != null) { win.stMessage.text = message; } app.refresh();//这句话非常关键 if (perc == win.bar.maxvalue) { this.close(); } return; }; this.close = function() { win.close(); win=null;//该句是必须的,否则win关闭后,切换到其他应用再回到ps后,win又会出现 this.winRef = null; }; if (hasCancelButton) { win.cancelButton = win.add('button', undefined, 'Cancel'); win.cancelButton.onClick = function() { this.winRef.close(); this.winRef = null; //win = null;//执行该句会导致崩溃 //throw new Error('User canceled the pre-processing!'); }; } win.center(win.parent); win.show(); return this;};