use of org.omegat.core.search.SearchMatch in project omegat by omegat-org.
the class ReplaceFilter method skip.
private void skip() {
EditorController ec = (EditorController) Core.getEditor();
// try to find in current entry
int pos = ec.getCurrentPositionInEntryTranslation();
String str = ec.getCurrentTranslation();
List<SearchMatch> found = getReplacementsForEntry(str);
if (found != null) {
for (SearchMatch m : found) {
if (m.getStart() >= pos) {
ec.setCaretPosition(new IEditor.CaretPosition(m.getStart(), m.getEnd()));
ec.requestFocus();
return;
}
}
}
// not found in current entry - find next entry
int currentEntryNumber = ec.getCurrentEntryNumber();
ec.commitAndDeactivate();
// find to the end of project
for (int i = currentEntryNumber + 1; i <= maxEntryNum; i++) {
SourceTextEntry ste = entries.get(i);
if (ste == null) {
// entry not filtered
continue;
}
TMXEntry en = Core.getProject().getTranslationInfo(ste);
String trans = getEntryText(ste, en);
if (trans == null) {
continue;
}
found = getReplacementsForEntry(trans);
if (found == null) {
// no replacements
continue;
}
for (SearchMatch m : found) {
ec.gotoEntry(i, new CaretPosition(m.getStart(), m.getEnd()));
ec.requestFocus();
return;
}
}
// find from the beginning of project
for (int i = minEntryNum; i < currentEntryNumber; i++) {
SourceTextEntry ste = entries.get(i);
if (ste == null) {
// entry not filtered
continue;
}
TMXEntry en = Core.getProject().getTranslationInfo(ste);
String trans = getEntryText(ste, en);
if (trans == null) {
continue;
}
found = getReplacementsForEntry(trans);
if (found == null) {
// no replacements
continue;
}
for (SearchMatch m : found) {
ec.gotoEntry(i, new CaretPosition(m.getStart(), m.getEnd()));
ec.requestFocus();
return;
}
}
// not found
ec.activateEntry();
}
use of org.omegat.core.search.SearchMatch 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());
}
use of org.omegat.core.search.SearchMatch in project omegat by omegat-org.
the class ReplaceFilter method replace.
private void replace() {
EditorController ec = (EditorController) Core.getEditor();
// is caret inside match ?
int pos = ec.getCurrentPositionInEntryTranslation();
String str = ec.getCurrentTranslation();
List<SearchMatch> found = getReplacementsForEntry(str);
if (found != null) {
for (SearchMatch m : found) {
if (m.getStart() <= pos && pos <= m.getEnd()) {
// yes - replace
ec.replacePartOfText(m.getReplacement(), m.getStart(), m.getEnd());
break;
}
}
}
// skip to next
skip();
}
use of org.omegat.core.search.SearchMatch in project omegat by omegat-org.
the class ReplaceMarker method getMarksForEntry.
@Override
public List<Mark> getMarksForEntry(SourceTextEntry ste, String sourceText, String translationText, boolean isActive) throws Exception {
IEditorFilter filter = Core.getEditor().getFilter();
if (filter == null || !(filter instanceof ReplaceFilter)) {
return Collections.emptyList();
}
ReplaceFilter replaceFilter = (ReplaceFilter) filter;
List<SearchMatch> matches = replaceFilter.getReplacementsForEntry(translationText);
if (matches == null) {
return Collections.emptyList();
}
List<Mark> r = new ArrayList<Mark>(matches.size());
for (SearchMatch s : matches) {
Mark m = new Mark(Mark.ENTRY_PART.TRANSLATION, s.getStart(), s.getEnd());
m.painter = PAINTER;
r.add(m);
}
return r;
}
Aggregations