-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApplyActionToOpenDocuments.js
57 lines (46 loc) · 1.93 KB
/
ApplyActionToOpenDocuments.js
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
/* Apply Action script by eishiya, last updated 23 Oct 2022
This script adds an action to the Edit menu that lets you choose any action
registered in Tiled (native or scripted) and apply it to all open documents.
This script does not and cannot verify that the actions *make sense* being
applied to all documents, so exercise caution.
*/
var applyActionState = {
dialogOpen: false,
chosenAction: null,
chosenIndex: null
}
applyActionState.applyActionDialog = tiled.registerAction("ApplyActionDialog", function(action) {
if(applyActionState.dialogOpen) return;
applyActionState.dialogOpen = true;
let dialog = new Dialog("Apply Action to Documents");
let actionsDropdown = dialog.addComboBox("Action:", tiled.actions);
actionsDropdown.toolTip = "Which action should be applied? To find actions faster, you can start typing their name.";
actionsDropdown.currentTextChanged.connect(function(newText) {
applyActionState.chosenIndex = actionsDropdown.currentIndex;
applyActionState.chosenAction = newText;
});
if(applyActionState.chosenIndex != null) {
actionsDropdown.currentIndex = applyActionState.chosenIndex;
}
let applyButton = dialog.addButton("Apply");
applyButton.clicked.connect(function() {
dialog.done(Dialog.Accepted);
//Do the chosen action:
let lastAsset = tiled.activeAsset;
for(asset of tiled.openAssets) {
tiled.activeAsset = asset;
tiled.trigger(applyActionState.chosenAction);
}
tiled.activeAsset = lastAsset;
});
dialog.addNewRow();
let closeButton = dialog.addButton("Cancel");
closeButton.clicked.connect(function() { dialog.done(Dialog.Rejected);} );
dialog.finished.connect(function() { applyActionState.dialogOpen = false; });
dialog.show();
});
applyActionState.applyActionDialog.text = "Apply Action to Documents...";
tiled.extendMenu("Edit", [
{ action: "ApplyActionDialog", before: "Preferences" },
{separator: true}
]);