Search in sources :

Example 1 with EditorController

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

Example 2 with EditorController

use of org.omegat.gui.editor.EditorController in project omegat by omegat-org.

the class SearchWindowController method getCurrentPositionInEntryTranslationInEditor.

/*
     * TODO: This should be a method on EditorController exposed via IEditor, NOT here.
     */
private CaretPosition getCurrentPositionInEntryTranslationInEditor(IEditor editor) {
    if (editor instanceof EditorController) {
        EditorController c = (EditorController) editor;
        int selectionEnd = c.getCurrentPositionInEntryTranslation();
        String selection = c.getSelectedText();
        String translation = c.getCurrentTranslation();
        if (StringUtil.isEmpty(translation) || StringUtil.isEmpty(selection)) {
            // no translation or no selection
            return new CaretPosition(selectionEnd);
        } else {
            // get selected range
            int selectionStart = selectionEnd;
            int pos = 0;
            do {
                pos = translation.indexOf(selection, pos);
                if (pos == selectionEnd) {
                    selectionStart = pos;
                    selectionEnd = pos + selection.length();
                    break;
                } else if ((pos + selection.length()) == selectionEnd) {
                    selectionStart = pos;
                    break;
                }
                pos++;
            } while (pos > 0);
            return new CaretPosition(selectionStart, selectionEnd);
        }
    } else {
        return CaretPosition.startOfEntry();
    }
}
Also used : EditorController(org.omegat.gui.editor.EditorController) CaretPosition(org.omegat.gui.editor.IEditor.CaretPosition)

Example 3 with EditorController

use of org.omegat.gui.editor.EditorController in project omegat by omegat-org.

the class SearchWindowController method initActions.

final void initActions() {
    // ///////////////////////////////////
    // action listeners
    form.m_dismissButton.addActionListener(e -> doCancel());
    form.m_filterButton.addActionListener(e -> doFilter());
    form.m_replaceButton.addActionListener(e -> doReplace());
    form.m_replaceAllButton.addActionListener(e -> doReplaceAll());
    form.m_searchButton.addActionListener(e -> doSearch());
    form.m_advancedButton.addActionListener(e -> setAdvancedOptionsVisible(!form.m_advancedVisiblePane.isVisible()));
    form.m_authorCB.addActionListener(e -> enableDisableAuthor());
    form.m_authorField.addActionListener(e -> doSearch());
    form.m_dateToCB.addActionListener(e -> enableDisableDateTo());
    form.m_dateToButton.addActionListener(e -> doResetDateTo());
    form.m_dateFromButton.addActionListener(e -> doResetDateFrom());
    form.m_dateFromCB.addActionListener(e -> enableDisableDateFrom());
    form.m_dirButton.addActionListener(e -> doBrowseDirectory());
    StaticUIUtils.setEscapeAction(form, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doCancel();
        }
    });
    // Set search and replace combo boxes' actions, undo, key handling
    configureHistoryComboBox(form.m_searchField);
    configureHistoryComboBox(form.m_replaceField);
    // need to control check boxes and radio buttons manually
    // 
    // keyword search can only be used when searching current project
    // TM search only works with exact/regex search on current project
    // file search only works with exact/regex search
    // 
    // keep track of settings and only show what are valid choices
    ActionListener searchFieldRequestFocus = e -> form.m_searchField.requestFocus();
    form.m_searchExactSearchRB.addActionListener(searchFieldRequestFocus);
    form.m_searchKeywordSearchRB.addActionListener(searchFieldRequestFocus);
    form.m_searchRegexpSearchRB.addActionListener(searchFieldRequestFocus);
    form.m_searchCase.addActionListener(searchFieldRequestFocus);
    form.m_searchSpaceMatchNbsp.addActionListener(searchFieldRequestFocus);
    form.m_searchSource.addActionListener(searchFieldRequestFocus);
    form.m_searchTranslation.addActionListener(searchFieldRequestFocus);
    form.m_searchTranslatedUntranslated.addActionListener(searchFieldRequestFocus);
    form.m_searchTranslated.addActionListener(searchFieldRequestFocus);
    form.m_searchUntranslated.addActionListener(searchFieldRequestFocus);
    form.m_searchNotesCB.addActionListener(searchFieldRequestFocus);
    form.m_searchCommentsCB.addActionListener(searchFieldRequestFocus);
    form.m_cbSearchInGlossaries.addActionListener(searchFieldRequestFocus);
    form.m_cbSearchInMemory.addActionListener(searchFieldRequestFocus);
    form.m_cbSearchInTMs.addActionListener(searchFieldRequestFocus);
    form.m_allResultsCB.addActionListener(searchFieldRequestFocus);
    form.m_fileNamesCB.addActionListener(searchFieldRequestFocus);
    form.m_autoSyncWithEditor.addActionListener(e -> {
        // update auto-sync flag in EntryListPane
        EntryListPane viewer = (EntryListPane) form.m_viewer;
        viewer.setAutoSyncWithEditor(form.m_autoSyncWithEditor.isSelected());
    });
    form.m_rbDir.addActionListener(e -> {
        updateOptionStatus();
        // otherwise move focus to search field
        if (form.m_rbDir.isSelected()) {
            form.m_dirField.requestFocus();
        } else {
            form.m_searchField.requestFocus();
        }
    });
    form.m_rbProject.addActionListener(e -> {
        updateOptionStatus();
        form.m_searchField.requestFocus();
    });
    form.m_numberOfResults.addChangeListener(e -> {
        // move focus to search edit field
        form.m_searchField.requestFocus();
    });
    form.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            // save user preferences
            savePreferences();
            if (thread != null) {
                thread.fin();
            }
            // back to the initial segment
            int currentEntry = Core.getEditor().getCurrentEntryNumber();
            if (initialEntry > 0 && form.m_backToInitialSegment.isSelected() && initialEntry != currentEntry) {
                boolean isSegDisplayed = isSegmentDisplayed(initialEntry);
                if (isSegDisplayed) {
                    // Restore caretPosition too
                    ((EditorController) Core.getEditor()).gotoEntry(initialEntry, initialCaret);
                } else {
                    // The segment is not displayed (maybe filter on). Ignore caretPosition.
                    Core.getEditor().gotoEntry(initialEntry);
                }
            }
        }
    });
}
Also used : OConsts(org.omegat.util.OConsts) SourceTextEntry(org.omegat.core.data.SourceTextEntry) EditorController(org.omegat.gui.editor.EditorController) Date(java.util.Date) Platform(org.omegat.util.Platform) StaticUIUtils(org.omegat.util.gui.StaticUIUtils) StringUtil(org.omegat.util.StringUtil) OSXIntegration(org.omegat.util.gui.OSXIntegration) WindowListener(java.awt.event.WindowListener) Core(org.omegat.core.Core) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) SearchFilter(org.omegat.gui.editor.filter.SearchFilter) ParseException(java.text.ParseException) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) KeyStroke(javax.swing.KeyStroke) SpinnerDateModel(javax.swing.SpinnerDateModel) BadLocationException(javax.swing.text.BadLocationException) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) Component(java.awt.Component) WindowEvent(java.awt.event.WindowEvent) AbstractAction(javax.swing.AbstractAction) Preferences(org.omegat.util.Preferences) Toolkit(java.awt.Toolkit) ActionListener(java.awt.event.ActionListener) OmegaTFileChooser(org.omegat.util.gui.OmegaTFileChooser) JTextField(javax.swing.JTextField) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Log(org.omegat.util.Log) Mnemonics(org.openide.awt.Mnemonics) SimpleDateFormat(java.text.SimpleDateFormat) UndoManager(javax.swing.undo.UndoManager) CaretPosition(org.omegat.gui.editor.IEditor.CaretPosition) MessageFormat(java.text.MessageFormat) IEditor(org.omegat.gui.editor.IEditor) Calendar(java.util.Calendar) OStrings(org.omegat.util.OStrings) Container(java.awt.Container) Searcher(org.omegat.core.search.Searcher) SearchExpression(org.omegat.core.search.SearchExpression) UIThreadsUtil(org.omegat.util.gui.UIThreadsUtil) JOptionPane(javax.swing.JOptionPane) IEditorFilter(org.omegat.gui.editor.IEditorFilter) ActionEvent(java.awt.event.ActionEvent) File(java.io.File) SearchMode(org.omegat.core.search.SearchMode) ReplaceFilter(org.omegat.gui.editor.filter.ReplaceFilter) SearchThread(org.omegat.core.threads.SearchThread) InputMap(javax.swing.InputMap) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) AbstractAction(javax.swing.AbstractAction)

Example 4 with EditorController

use of org.omegat.gui.editor.EditorController in project omegat by omegat-org.

the class Core method initializeGUI.

/**
 * Initialize application components.
 */
public static void initializeGUI(final Map<String, String> params) throws Exception {
    cmdLineParams = params;
    // 1. Initialize project
    currentProject = new NotLoadedProject();
    // 2. Initialize application frame
    MainWindow me = new MainWindow();
    mainWindow = me;
    // Load recent used projects
    RecentProjects.updateMenu();
    Core.registerMarker(new ProtectedPartsMarker());
    Core.registerMarker(new RemoveTagMarker());
    Core.registerMarker(new NBSPMarker());
    Core.registerMarker(new TransTipsMarker());
    Core.registerMarker(new WhitespaceMarkerFactory.SpaceMarker());
    Core.registerMarker(new WhitespaceMarkerFactory.TabMarker());
    Core.registerMarker(new WhitespaceMarkerFactory.LFMarker());
    Core.registerMarker(new BidiMarkerFactory.RLMMarker());
    Core.registerMarker(new BidiMarkerFactory.LRMMarker());
    Core.registerMarker(new BidiMarkerFactory.PDFMarker());
    Core.registerMarker(new BidiMarkerFactory.LROMarker());
    Core.registerMarker(new BidiMarkerFactory.RLOMarker());
    Core.registerMarker(new ReplaceMarker());
    Core.registerMarker(new ComesFromAutoTMMarker());
    Core.registerMarker(new FontFallbackMarker());
    LanguageToolWrapper.init();
    segmenter = new Segmenter(Preferences.getSRX());
    filterMaster = new FilterMaster(Preferences.getFilters());
    // 3. Initialize other components. They add themselves to the main window.
    editor = new EditorController(me);
    tagValidation = new TagValidationTool();
    issuesWindow = new IssuesPanelController(me);
    matcher = new MatchesTextArea(me);
    GlossaryTextArea glossaryArea = new GlossaryTextArea(me);
    glossary = glossaryArea;
    glossaryManager = new GlossaryManager(glossaryArea);
    notes = new NotesTextArea(me);
    comments = new CommentsTextArea(me);
    machineTranslatePane = new MachineTranslateTextArea(me);
    dictionaries = new DictionariesTextArea(me);
    spellChecker = new SpellChecker();
    multiple = new MultipleTransPane(me);
    new SegmentPropertiesArea(me);
    SaveThread th = new SaveThread();
    saveThread = th;
    th.start();
}
Also used : NBSPMarker(org.omegat.gui.editor.mark.NBSPMarker) MachineTranslateTextArea(org.omegat.gui.exttrans.MachineTranslateTextArea) EditorController(org.omegat.gui.editor.EditorController) MultipleTransPane(org.omegat.gui.multtrans.MultipleTransPane) DictionariesTextArea(org.omegat.gui.dictionaries.DictionariesTextArea) WhitespaceMarkerFactory(org.omegat.gui.editor.mark.WhitespaceMarkerFactory) GlossaryManager(org.omegat.gui.glossary.GlossaryManager) ReplaceMarker(org.omegat.gui.editor.mark.ReplaceMarker) NotesTextArea(org.omegat.gui.notes.NotesTextArea) IMainWindow(org.omegat.gui.main.IMainWindow) MainWindow(org.omegat.gui.main.MainWindow) IssuesPanelController(org.omegat.gui.issues.IssuesPanelController) BidiMarkerFactory(org.omegat.gui.editor.mark.BidiMarkerFactory) ProtectedPartsMarker(org.omegat.gui.editor.mark.ProtectedPartsMarker) FontFallbackMarker(org.omegat.gui.editor.mark.FontFallbackMarker) SaveThread(org.omegat.core.threads.SaveThread) RemoveTagMarker(org.omegat.gui.editor.mark.RemoveTagMarker) CommentsTextArea(org.omegat.gui.comments.CommentsTextArea) ComesFromAutoTMMarker(org.omegat.gui.editor.mark.ComesFromAutoTMMarker) Segmenter(org.omegat.core.segmentation.Segmenter) TagValidationTool(org.omegat.core.tagvalidation.TagValidationTool) MatchesTextArea(org.omegat.gui.matches.MatchesTextArea) GlossaryTextArea(org.omegat.gui.glossary.GlossaryTextArea) NotLoadedProject(org.omegat.core.data.NotLoadedProject) FilterMaster(org.omegat.filters2.master.FilterMaster) ISpellChecker(org.omegat.core.spellchecker.ISpellChecker) SpellChecker(org.omegat.core.spellchecker.SpellChecker) SegmentPropertiesArea(org.omegat.gui.properties.SegmentPropertiesArea) TransTipsMarker(org.omegat.gui.glossary.TransTipsMarker)

Example 5 with EditorController

use of org.omegat.gui.editor.EditorController 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

EditorController (org.omegat.gui.editor.EditorController)6 SourceTextEntry (org.omegat.core.data.SourceTextEntry)3 SearchMatch (org.omegat.core.search.SearchMatch)3 CaretPosition (org.omegat.gui.editor.IEditor.CaretPosition)3 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)2 TMXEntry (org.omegat.core.data.TMXEntry)2 IEditor (org.omegat.gui.editor.IEditor)2 Component (java.awt.Component)1 Container (java.awt.Container)1 Toolkit (java.awt.Toolkit)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyEvent (java.awt.event.KeyEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 WindowListener (java.awt.event.WindowListener)1 File (java.io.File)1 MessageFormat (java.text.MessageFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1