use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.
the class EditorTextArea3 method selectTag.
/**
* Try to select full tag on specified position, in the source and
* translation part of segment.
*
* @param pos
* position
* @return true if selected
*/
boolean selectTag(int pos) {
int s = controller.getSegmentIndexAtLocation(pos);
if (s < 0) {
return false;
}
SegmentBuilder segment = controller.m_docSegList[s];
if (pos < segment.getStartPosition() || pos >= segment.getEndPosition()) {
return false;
}
SourceTextEntry ste = getOmDocument().controller.getCurrentEntry();
if (ste != null) {
try {
String text = getOmDocument().getText(segment.getStartPosition(), segment.getEndPosition() - segment.getStartPosition());
int off = pos - segment.getStartPosition();
if (off < 0 || off >= text.length()) {
return false;
}
for (ProtectedPart pp : ste.getProtectedParts()) {
int p = -1;
while ((p = text.indexOf(pp.getTextInSourceSegment(), p + 1)) >= 0) {
if (p <= off && off < p + pp.getTextInSourceSegment().length()) {
p += segment.getStartPosition();
select(p, p + pp.getTextInSourceSegment().length());
return true;
}
}
}
} catch (BadLocationException ex) {
}
}
return false;
}
use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.
the class ReplaceFilter method replaceAll.
/**
* Replace all occurrences in all entries.
*/
public void replaceAll() {
for (SourceTextEntry ste : entries.values()) {
TMXEntry en = Core.getProject().getTranslationInfo(ste);
String trans = getEntryText(ste, en);
if (trans == null) {
continue;
}
// Avoid to replace more than once with variables when entries have duplicates
if ((en.defaultTranslation) && (ste.getDuplicate() == SourceTextEntry.DUPLICATE.NEXT)) {
// Already replaced when we parsed the first entry
continue;
}
List<SearchMatch> found = getReplacementsForEntry(trans);
if (found != null) {
int off = 0;
StringBuilder o = new StringBuilder(trans);
for (SearchMatch m : found) {
o.replace(m.getStart() + off, m.getEnd() + off, m.getReplacement());
off += m.getReplacement().length() - m.getLength();
}
PrepareTMXEntry prepare = new PrepareTMXEntry(en);
prepare.translation = o.toString();
Core.getProject().setTranslation(ste, prepare, en.defaultTranslation, null);
}
}
EditorController ec = (EditorController) Core.getEditor();
ec.refreshEntries(entries.keySet());
}
Aggregations