Search in sources :

Example 31 with SourceTextEntry

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;
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 32 with SourceTextEntry

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());
}
Also used : SearchMatch(org.omegat.core.search.SearchMatch) EditorController(org.omegat.gui.editor.EditorController) SourceTextEntry(org.omegat.core.data.SourceTextEntry) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry)

Aggregations

SourceTextEntry (org.omegat.core.data.SourceTextEntry)32 Point (java.awt.Point)14 TMXEntry (org.omegat.core.data.TMXEntry)12 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)9 ArrayList (java.util.ArrayList)8 IProject (org.omegat.core.data.IProject)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 EntryKey (org.omegat.core.data.EntryKey)5 FileInfo (org.omegat.core.data.IProject.FileInfo)5 Language (org.omegat.util.Language)5 List (java.util.List)4 Before (org.junit.Before)4 ProtectedPart (org.omegat.core.data.ProtectedPart)4 NearString (org.omegat.core.matching.NearString)4 Cursor (java.awt.Cursor)3 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2