-
Notifications
You must be signed in to change notification settings - Fork 0
/
goto_next_filtered_note.groovy
53 lines (50 loc) · 1.5 KB
/
goto_next_filtered_note.groovy
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
/*:name = GoTo - Filtered note / next :description=Jump to next segment with a note matching the filter
*
* @author: Kos Ivantsov
* @date: 2024-08-19
* @version: 0.2
*/
import static javax.swing.JOptionPane.*
import static org.omegat.util.Platform.*
prop = project.projectProperties
filtered_note = new File(prop.getProjectRoot() + "filtered_note.txt")
if (!filtered_note.exists()) {
regex = 'XYZZZ'
} else {
regex = filtered_note.text.trim()
}
exit = false
if (!prop) {
final def title = 'Next filtered note'
final def msg = 'Please try again after you open a project.'
showMessageDialog null, msg, title, INFORMATION_MESSAGE
exit = true
return
}
lastSegmentNumber = project.allEntries.size()
jump = false
def gui() {
if (exit)
return
ste = editor.getCurrentEntry()
currentSegmentNumber = startingSegmentNumber = ste.entryNum()
while (!jump) {
nextSegmentNumber = currentSegmentNumber == lastSegmentNumber ? 1 : currentSegmentNumber + 1
stn = project.allEntries[nextSegmentNumber - 1]
info = project.getTranslationInfo(stn)
note = info.note ? info.note.toString() : ""
if (nextSegmentNumber == startingSegmentNumber) {
return
}
found_note = note.find(regex)
if (found_note) {
jump = true
editor.gotoEntry(nextSegmentNumber)
return
} else {
jump = false
currentSegmentNumber = nextSegmentNumber
}
}
}
return