Search in sources :

Example 21 with SourceTextEntry

use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.

the class TestFilterBase method checkMultiNoPrevNext.

protected SourceTextEntry checkMultiNoPrevNext(String sourceText, String id, String path, String comment) {
    SourceTextEntry ste = fi.entries.get(fiCount);
    assertEquals(path, ste.getKey().path);
    assertEquals(id, ste.getKey().id);
    assertEquals(sourceText, ste.getKey().sourceText);
    assertEquals(comment, ste.getComment());
    fiCount++;
    return ste;
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry)

Example 22 with SourceTextEntry

use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.

the class GlossaryAutoCompleterViewTest method setUp.

@Before
public final void setUp() {
    Core.setProject(new NotLoadedProject() {

        @Override
        public ITokenizer getTargetTokenizer() {
            return new DefaultTokenizer();
        }

        @Override
        public ProjectProperties getProjectProperties() {
            try {
                return new ProjectProperties() {

                    @Override
                    public Language getTargetLanguage() {
                        return new Language(Locale.ENGLISH);
                    }
                };
            } catch (Exception e) {
                return null;
            }
        }
    });
    TestCoreInitializer.initEditor(new IEditor() {

        @Override
        public String getCurrentFile() {
            return null;
        }

        @Override
        public String getCurrentTargetFile() {
            return null;
        }

        @Override
        public SourceTextEntry getCurrentEntry() {
            return null;
        }

        @Override
        public int getCurrentEntryNumber() {
            return 0;
        }

        @Override
        public void activateEntry() {
        }

        @Override
        public void commitAndDeactivate() {
        }

        @Override
        public void commitAndLeave() {
        }

        @Override
        public void nextEntry() {
        }

        @Override
        public void prevEntry() {
        }

        @Override
        public void nextEntryWithNote() {
        }

        @Override
        public void prevEntryWithNote() {
        }

        @Override
        public void nextUntranslatedEntry() {
        }

        @Override
        public void nextTranslatedEntry() {
        }

        @Override
        public void nextUniqueEntry() {
        }

        @Override
        public void gotoFile(int fileIndex) {
        }

        @Override
        public void gotoEntry(int entryNum) {
        }

        @Override
        public void gotoEntry(int entryNum, CaretPosition pos) {
        }

        @Override
        public void gotoEntry(String srcString, EntryKey key) {
        }

        @Override
        public void gotoEntryAfterFix(int fixedEntry, String fixedSource) {
        }

        @Override
        public void refreshViewAfterFix(List<Integer> fixedEntries) {
        }

        @Override
        public void refreshView(boolean doCommit) {
        }

        @Override
        public void requestFocus() {
        }

        @Override
        public void changeCase(CHANGE_CASE_TO newCase) {
        }

        @Override
        public void replaceEditText(String text) {
        }

        @Override
        public void replaceEditTextAndMark(String text) {
        }

        @Override
        public void insertText(String text) {
        }

        @Override
        public void insertTextAndMark(String text) {
        }

        @Override
        public void insertTag(String tag) {
        }

        @Override
        public void gotoHistoryForward() {
        }

        @Override
        public void gotoHistoryBack() {
        }

        @Override
        public IEditorSettings getSettings() {
            return null;
        }

        @Override
        public void undo() {
        }

        @Override
        public void redo() {
        }

        @Override
        public String getSelectedText() {
            return null;
        }

        @Override
        public void setAlternateTranslationForCurrentEntry(boolean alternate) {
        }

        @Override
        public void markActiveEntrySource(SourceTextEntry requiredActiveEntry, List<Mark> marks, String markerClassName) {
        }

        @Override
        public void registerPopupMenuConstructors(int priority, IPopupMenuConstructor constructor) {
        }

        @Override
        public void remarkOneMarker(String markerClassName) {
        }

        @Override
        public IEditorFilter getFilter() {
            return null;
        }

        @Override
        public void setFilter(IEditorFilter filter) {
        }

        @Override
        public void removeFilter() {
        }

        @Override
        public String getCurrentTranslation() {
            return null;
        }

        @Override
        public void windowDeactivated() {
        }

        @Override
        public void registerUntranslated() {
        }

        @Override
        public void registerEmptyTranslation() {
        }

        @Override
        public void registerIdenticalTranslation() {
        }

        @Override
        public IAutoCompleter getAutoCompleter() {
            return null;
        }
    });
    TestCoreInitializer.initGlossary(new IGlossaries() {

        @Override
        public List<GlossaryEntry> getDisplayedEntries() {
            return currentEntries;
        }

        @Override
        public void showCreateGlossaryEntryDialog(Frame parent) {
        }
    });
    currentEntries.clear();
}
Also used : IEditor(org.omegat.gui.editor.IEditor) Frame(java.awt.Frame) DefaultTokenizer(org.omegat.tokenizer.DefaultTokenizer) Mark(org.omegat.gui.editor.mark.Mark) ITokenizer(org.omegat.tokenizer.ITokenizer) Language(org.omegat.util.Language) SourceTextEntry(org.omegat.core.data.SourceTextEntry) ArrayList(java.util.ArrayList) List(java.util.List) IAutoCompleter(org.omegat.gui.editor.autocompleter.IAutoCompleter) EntryKey(org.omegat.core.data.EntryKey) IEditorFilter(org.omegat.gui.editor.IEditorFilter) IPopupMenuConstructor(org.omegat.gui.editor.IPopupMenuConstructor) IEditorSettings(org.omegat.gui.editor.IEditorSettings) ProjectProperties(org.omegat.core.data.ProjectProperties) NotLoadedProject(org.omegat.core.data.NotLoadedProject) Before(org.junit.Before)

Example 23 with SourceTextEntry

use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.

the class TagUtilTest method testBuildTagList.

/**
 * Test of buildTagList method, of class org.omegat.util.StaticUtils.
 *
 * @throws Exception
 */
@Test
public void testBuildTagList() throws Exception {
    TestPreferencesInitializer.init();
    String str = "Tag <test> case <b0>one</b0>.<b1>";
    List<ProtectedPart> pps = TagUtil.applyCustomProtectedParts(str, PatternConsts.OMEGAT_TAG, null);
    List<Tag> tagList = TagUtil.buildTagList(str, new SourceTextEntry(null, 0, null, null, pps).getProtectedParts());
    assertEquals("Wrong tags found in '" + str + "'", Arrays.asList(new Tag(16, "<b0>"), new Tag(23, "</b0>"), new Tag(29, "<b1>")), tagList);
    tagList.clear();
    ProtectedPart p;
    List<ProtectedPart> pp = new ArrayList<ProtectedPart>();
    p = new ProtectedPart();
    p.setTextInSourceSegment("<b0>");
    pp.add(p);
    p = new ProtectedPart();
    p.setTextInSourceSegment("</b0>");
    pp.add(p);
    tagList = TagUtil.buildTagList(str, new SourceTextEntry(null, 0, null, null, pp).getProtectedParts());
    assertEquals("Wrong tags found in '" + str + "'", Arrays.asList(new Tag(16, "<b0>"), new Tag(23, "</b0>")), tagList);
    str = "Tag <test>case</test>.";
    tagList.clear();
    pp.clear();
    p = new ProtectedPart();
    p.setTextInSourceSegment("<test>case</test>");
    pp.add(p);
    tagList = TagUtil.buildTagList(str, new SourceTextEntry(null, 0, null, null, pp).getProtectedParts());
    assertEquals("Wrong tags found in '" + str + "'", Arrays.asList(new Tag(4, "<test>case</test>")), tagList);
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) SourceTextEntry(org.omegat.core.data.SourceTextEntry) ArrayList(java.util.ArrayList) Tag(org.omegat.util.TagUtil.Tag) Test(org.junit.Test)

Example 24 with SourceTextEntry

use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.

the class MainWindowMenuHandler method editExportSelectionMenuItemActionPerformed.

public void editExportSelectionMenuItemActionPerformed() {
    if (!Core.getProject().isProjectLoaded()) {
        return;
    }
    String selection = Core.getEditor().getSelectedText();
    if (selection == null) {
        SourceTextEntry ste = Core.getEditor().getCurrentEntry();
        TMXEntry te = Core.getProject().getTranslationInfo(ste);
        if (te.isTranslated()) {
            selection = te.translation;
        } else {
            selection = ste.getSrcText();
        }
    }
    SegmentExportImport.exportCurrentSelection(selection);
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) NearString(org.omegat.core.matching.NearString) TMXEntry(org.omegat.core.data.TMXEntry)

Example 25 with SourceTextEntry

use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.

the class EditorController method iterateToEntry.

private void iterateToEntry(boolean forward, Predicate<SourceTextEntry> shouldStop) {
    UIThreadsUtil.mustBeSwingThread();
    if (!Core.getProject().isProjectLoaded()) {
        return;
    }
    Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    Cursor oldCursor = editor.getCursor();
    editor.setCursor(hourglassCursor);
    commitAndDeactivate();
    List<FileInfo> files = Core.getProject().getProjectFiles();
    if (files.isEmpty()) {
        return;
    }
    SourceTextEntry ste;
    int startFileIndex = displayedFileIndex;
    int startEntryIndex = displayedEntryIndex;
    boolean looped = false;
    while (true) {
        if (forward) {
            displayedEntryIndex++;
            if (displayedEntryIndex >= m_docSegList.length) {
                displayedFileIndex++;
                displayedEntryIndex = 0;
                if (displayedFileIndex >= files.size()) {
                    displayedFileIndex = 0;
                    looped = true;
                }
                loadDocument();
            }
        } else {
            displayedEntryIndex--;
            if (displayedEntryIndex < 0) {
                displayedFileIndex--;
                if (displayedFileIndex < 0) {
                    displayedFileIndex = files.size() - 1;
                    looped = true;
                }
                loadDocument();
                displayedEntryIndex = m_docSegList.length - 1;
            }
        }
        ste = getCurrentEntry();
        if (ste != null && shouldStop.test(ste)) {
            break;
        }
        if (looped && displayedFileIndex == startFileIndex) {
            if (forward && displayedEntryIndex >= startEntryIndex) {
                // We have looped forward to our starting point
                break;
            } else if (!forward && displayedEntryIndex <= startEntryIndex) {
                // We have looped backwards to our starting point
                break;
            }
            if (m_docSegList.length == 0) {
                // and there were no hits in any files
                break;
            }
        }
    }
    activateEntry();
    editor.setCursor(oldCursor);
}
Also used : FileInfo(org.omegat.core.data.IProject.FileInfo) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Cursor(java.awt.Cursor) Point(java.awt.Point)

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