use of org.omegat.core.matching.NearString in project omegat by omegat-org.
the class MainWindow method doInsertTrans.
/**
* insert current fuzzy match or selection at cursor position
*/
public void doInsertTrans() {
if (!Core.getProject().isProjectLoaded()) {
return;
}
String text = getSelectedTextInMatcher();
boolean fromMT = false;
if (StringUtil.isEmpty(text)) {
NearString near = Core.getMatcher().getActiveMatch();
if (near != null) {
text = near.translation;
if (near.comesFrom == NearString.MATCH_SOURCE.TM && FileUtil.isInPath(new File(Core.getProject().getProjectProperties().getTMRoot(), "mt"), new File(near.projs[0]))) {
fromMT = true;
}
}
}
if (!StringUtil.isEmpty(text)) {
if (fromMT) {
Core.getEditor().insertTextAndMark(text);
} else {
Core.getEditor().insertText(text);
}
Core.getEditor().requestFocus();
}
}
use of org.omegat.core.matching.NearString in project omegat by omegat-org.
the class MatchesTextArea method setFoundResult.
/**
* Sets the list of fuzzy matches to show in the pane. Each element of the
* list should be an instance of {@link NearString}.
*/
@Override
protected void setFoundResult(final SourceTextEntry se, List<NearString> newMatches) {
UIThreadsUtil.mustBeSwingThread();
clear();
if (newMatches == null) {
return;
}
if (!newMatches.isEmpty() && Preferences.isPreference(Preferences.NOTIFY_FUZZY_MATCHES)) {
scrollPane.notify(true);
}
NearString.SORT_KEY key = Preferences.getPreferenceEnumDefault(Preferences.EXT_TMX_SORT_KEY, SORT_KEY.SCORE);
newMatches.sort(Comparator.comparing(ns -> ns.scores[0], new ScoresComparator(key).reversed()));
matches.addAll(newMatches);
delimiters.add(0);
StringBuilder displayBuffer = new StringBuilder();
MatchesVarExpansion template = new MatchesVarExpansion(Preferences.getPreferenceDefault(Preferences.EXT_TMX_MATCH_TEMPLATE, MatchesVarExpansion.DEFAULT_TEMPLATE));
for (int i = 0; i < newMatches.size(); i++) {
NearString match = newMatches.get(i);
MatchesVarExpansion.Result result = template.apply(match, i + 1);
displayBuffer.append(result.text);
sourcePos.add(result.sourcePos);
diffInfos.add(result.diffInfo);
if (i < (newMatches.size() - 1)) {
displayBuffer.append("\n\n");
}
delimiters.add(displayBuffer.length());
}
setText(displayBuffer.toString());
setActiveMatch(0);
checkForReplaceTranslation();
}
Aggregations