-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNC_FindAndReplace.js
92 lines (80 loc) · 2.64 KB
/
NC_FindAndReplace.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
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
89
90
91
92
/* ---------------------------------------------------------------------------------
* NC_Find_And_Replace.js
*
* Jason Schleifer / 26 October 2018
* Latest Revision: v2.0 - 25 Nov 2018, 10:04 AM
* License: GPL v3
*
* Description:
* -----------
* Finds and replaces text in the selected nodes.
*
* Usage:
* ------
* Select a series of nodes you want to replace the text of. Choose the function NC_FindAndReplace.
*
* Requirements:
* -------------
* NC_Utils.js
*
* Updates:
* --------
* v2.0 - added use of NC_Utils.js
*
* Installation:
* -------------
* https://docs.toonboom.com/help/harmony-16/premium/scripting/import-script.html
*
* Acknowledgement:
* ----------------
* This script wouldn't have been possible without the help from eAthis
* https://forums.toonboom.com/harmony/support-and-troubleshooting/how-set-focus-lineedit-qtscript
*/
include("NC_Utils.js");
/**
*
* @return {void}
*/
function NC_FindAndReplace() {
var myUi = NC_CreateWidget()
var findLE = new QLineEdit();
var replaceLE = new QLineEdit();
var findLELabel = new QLabel();
findLELabel.text = "Find:";
findLE.text = "asdf";
var replaceLELabel = new QLabel();
replaceLELabel.text = "Replace:";
var submit = new QPushButton();
submit.text = "OK";
var cancel = new QPushButton();
cancel.text = "CANCEL";
myUi.gridLayout.addWidget(findLELabel, 0, 0);
myUi.gridLayout.addWidget(replaceLELabel, 1, 0);
myUi.gridLayout.addWidget(findLE, 0, 1);
myUi.gridLayout.addWidget(replaceLE, 1, 1);
myUi.gridLayout.addWidget(submit, 2, 0);
myUi.gridLayout.addWidget(cancel, 2, 1);
//myUi.setWindowFlags(Qt.FramelessWindowHint);
myUi.show();
replaceLE.setFocus(true); // here is the line you need !
var findAndReplace = function() {
var _find = findLE.text;
var _replace = replaceLE.text;
var n = selection.numberOfNodesSelected();
for (i = 0; i < n; ++i) {
var selNode = selection.selectedNode(i);
var nodeNamePath = selNode.split("/");
var nodeName = nodeNamePath[nodeNamePath.length - 1];
var newNodeName = nodeName.replace(_find, _replace);
var columnId = node.linkedColumn(selNode, "DRAWING.ELEMENT");
var elementKey = column.getElementIdOfDrawing(columnId);
var newColumnName = newNodeName;
node.rename(selNode, newNodeName);
column.rename(columnId, newNodeName);
element.renameById(elementKey, newNodeName);
}
myUi.close();
}
submit.clicked.connect(myUi, findAndReplace);
cancel.clicked.connect(myUi, myUi.close);
}