forked from runegan/refresher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefresher.jsx
88 lines (69 loc) · 2.15 KB
/
refresher.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
Refresher
Refresh ScriptUIs in a panel, without closing it.
To use: Place this file in the ScriptUI folder.
Press the "..." button to select a script file to run.
Press the "R" button to refresh the scriptFile
Made by Rune Gangsø
Email: runegan@gmail.com
Github: github.com/runegan/refresher
*/
( function( thisObj ) {
if ( !( thisObj instanceof Panel ) ) {
alert( "Must be run from ScriptUI folder", "Error", true );
return;
}
// Create Refresher UI
var refreshGroup = thisObj.add(
"group { alignment: ['fill', 'top'], alignChildren: 'fill', spacing: 0, margins: 0}"
);
var refreshButton = refreshGroup.add( "button { text: 'r', maximumSize: [20, 20] }" );
var changeButton = refreshGroup.add( "button { text: '...', maximumSize: [20, 20] }" );
var theScriptFile;
refreshButton.onClick = refreshCall;
changeButton.onClick = change;
// =========================================== Functions ===========================================
// Change script file
function change() {
var file = File.openDialog( "Open jsx file" );
// Make sure user did not cancel
if ( file ) {
theScriptFile = file;
// Save script file location in a setting
app.settings.saveSetting( "refresher", "scriptFilePath", theScriptFile.fsName );
refreshCall();
}
}
function refreshCall() {
refresh.call( thisObj );
}
function refresh() {
// Remove everything except RefreshGroup from the panel
for ( var i = thisObj.children.length - 1; i >= 0; i-- ) {
if ( thisObj.children[ i ] !== refreshGroup ) {
thisObj.remove( thisObj.children[ i ] );
}
}
// Run the scriptFile
try {
$.evalFile( theScriptFile );
// Alert any errors
} catch ( err ) {
alert( err.fileName + "\n" + err.message + " on line " + err.line );
}
// Recalculate UI
thisObj.layout.layout( true );
}
// Check if a script file is stored in the settings
if ( app.settings.haveSetting( "refresher", "scriptFilePath" ) ) {
theScriptFile = new File( app.settings.getSetting( "refresher", "scriptFilePath" ) );
if ( !theScriptFile.exists ) {
theScriptFile = null;
}
}
// Prompt user for a script file if none was found
if ( !theScriptFile ) {
change();
}
thisObj.layout.layout( true );
}( this ) );