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();
}
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();
}
}
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);
}
}
}
});
}
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();
}
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());
}
Aggregations