-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revise 'Apply Expression to Selection' UI, resolve #3
- Loading branch information
Showing
1 changed file
with
68 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,46 +2,85 @@ | |
* Prompts user for an expression, and applies it to selected properties | ||
* | ||
* @author Zack Lovatt <[email protected]> | ||
* @version 0.1.0 | ||
* @version 0.2.0 | ||
*/ | ||
(function applyExpressionToSelection () { | ||
var DEFAULT_EXPRESSION = "loopIn() + loopOut() - value"; | ||
var comp = app.project.activeItem; | ||
(function applyExpressionToSelection() { | ||
var DEFAULT_EXPRESSION = "loopIn() + loopOut() - value;"; | ||
_getUserExpression(DEFAULT_EXPRESSION); | ||
|
||
if (!(comp && comp instanceof CompItem)) { | ||
alert("Open a comp!"); | ||
return; | ||
} | ||
/** | ||
* Applies an expression to selected prop(s) | ||
* | ||
* @param {string} expression Expression to apply | ||
*/ | ||
function applyExpression(expression) { | ||
var comp = app.project.activeItem; | ||
|
||
if (!(comp && comp instanceof CompItem)) { | ||
alert("Open a comp!"); | ||
return; | ||
} | ||
|
||
var props = comp.selectedProperties; | ||
var props = comp.selectedProperties; | ||
|
||
if (props.length === 0) { | ||
alert("Select properties to apply expression to!"); | ||
return; | ||
} | ||
if (props.length === 0) { | ||
alert("Select properties to apply expression to!"); | ||
return; | ||
} | ||
|
||
if (!expression || expression == "") { | ||
alert("Enter an expression"); | ||
return; | ||
} | ||
|
||
app.beginUndoGroup("Apply Expression to Selected Properties"); | ||
|
||
var userExpression = prompt("Enter an expression!", DEFAULT_EXPRESSION); | ||
try { | ||
for (var ii = 0, il = props.length; ii < il; ii++) { | ||
var prop = props[ii]; | ||
|
||
if (!userExpression) { | ||
alert("Enter an expression"); | ||
return; | ||
if (!prop.canSetExpression) { | ||
continue; | ||
} | ||
|
||
prop.expression = expression; | ||
} | ||
} catch (e) { | ||
alert(e); | ||
} finally { | ||
app.endUndoGroup(); | ||
} | ||
} | ||
|
||
app.beginUndoGroup("Apply Expression to Selected Properties"); | ||
function _getUserExpression(defaultExpression) { | ||
var win = new Window("palette", "Apply Expression to Selection", undefined, { | ||
resizeable: true | ||
}); | ||
win.alignChildren = "fill"; | ||
|
||
win.add("statictext", undefined, "Expression to apply:"); | ||
|
||
try { | ||
for (var ii = 0, il = props.length; ii < il; ii++) { | ||
var prop = props[ii]; | ||
var editText = win.add("edittext", undefined, defaultExpression, { | ||
multiline: true | ||
}); | ||
editText.characters = 50; | ||
editText.size = [500, 200]; | ||
editText.alignment = "fill"; | ||
|
||
if (!prop.canSetExpression) { | ||
continue; | ||
var btnOk = win.add("button", undefined, "Apply"); | ||
btnOk.onClick = function () { | ||
var userExpression = editText.text; | ||
|
||
if (userExpression == "") { | ||
alert("No expression to apply!"); | ||
return; | ||
} | ||
|
||
prop.expression = userExpression; | ||
} | ||
} catch (e) { | ||
alert(e); | ||
} finally { | ||
app.endUndoGroup(); | ||
win.close(); | ||
applyExpression(userExpression); | ||
}; | ||
btnOk.alignment = "right"; | ||
|
||
win.show(); | ||
} | ||
})(); |