Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clean todo comments #1178

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/org/omegat/CLIParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ private CLIParameters() {
* CLI parameter to specify target tokenizer
*/
public static final String TOKENIZER_TARGET = "ITokenizerTarget";
// TODO: Document this; see RealProject.patchFileNameForEntryKey()
public static final String ALTERNATE_FILENAME_FROM = "alternate-filename-from";
// TODO: Document this; see RealProject.patchFileNameForEntryKey()
public static final String ALTERNATE_FILENAME_TO = "alternate-filename-to";

// Non-GUI modes only
Expand Down
4 changes: 1 addition & 3 deletions src/org/omegat/core/data/ProjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
/**
* Factory for load project, create project, and create "not-loaded" project.
*
* TODO: change exception handling
*
* @author Alex Buloichik ([email protected])
*/
public final class ProjectFactory {
Expand All @@ -48,7 +46,7 @@ public static void createNotLoadedProject() {
}

/**
* Create new project.
* Create a new project.
*/
public static void createProject(ProjectProperties newProps) {
RealProject p = new RealProject(newProps);
Expand Down
23 changes: 6 additions & 17 deletions src/org/omegat/core/data/RealProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1264,24 +1264,13 @@ private void loadSourceFiles() throws IOException {
loadFilesCallback.fileFinished();

if (filter != null && !fi.entries.isEmpty()) {
fi.filterClass = filter.getClass(); // Don't store the
// instance, because
// every file gets an
// instance and
// then we consume a lot
// of memory for all
// instances.
// See also IFilter
// "TODO: each filter
// should be stateless"
fi.filterClass = filter.getClass();
// Don't store the instance, because
// every file gets an instance and
// then we consume a lot of memory for all
// instances. See also IFilter
fi.filterFileFormatName = filter.getFileFormatName();
try {
fi.fileEncoding = filter.getInEncodingLastParsedFile();
} catch (Error e) { // In case a filter doesn't have
// getInEncodingLastParsedFile() (e.g.,
// Okapi plugin)
fi.fileEncoding = "";
}
fi.fileEncoding = filter.getInEncodingLastParsedFile();
projectFilesList.add(fi);
}
} catch (TranslationException e) {
Expand Down
12 changes: 5 additions & 7 deletions src/org/omegat/filters2/IFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@

/**
* Interface for filters declaration.
*
* TODO: each filter should be stateless, i.e. options shouldn't be stored in
* <p>
* Note: each filter should be stateless, i.e., options shouldn't be stored in
* filter, but should be sent to filter on each parse, align, or translate
* operation.
*
* Filters shouldn't use Core, but use Context instead.
* operation through context. Filters shouldn't use Core, but use Context.
*
* @author Alex Buloichik ([email protected])
*/
Expand All @@ -61,7 +59,7 @@ public interface IFilter {
/**
* The default list of filter instances that this filter class has. One
* filter class may have different filter instances, different by source
* file mask, encoding of the source file etc.
* file mask, encoding of the source file, etc.
* <p>
* Note that the user may change the instances freely.
*
Expand All @@ -75,7 +73,7 @@ public interface IFilter {
* True means that OmegaT should handle all the encoding mess.
* <p>
* Return false to state that your filter doesn't need encoding management
* provided by OmegaT, because it either autodetects the encoding based on
* provided by OmegaT, because it either autodetect the encoding based on
* file contents (like HTML filter does) or the encoding is fixed (like in
* OpenOffice files).
*
Expand Down
7 changes: 3 additions & 4 deletions src/org/omegat/filters2/latex/LatexFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,10 @@ private String replaceUnknownCommand(LinkedList<String[]> substituted, List<Stri

par = sb.toString();
} catch (java.util.regex.PatternSyntaxException e) {
// TODO: understand the exceptions
Log.log("LaTeX PatternSyntaxException: " + e.getMessage());
Log.log(command);
Log.getLogger(LatexFilter.class).atDebug()
.setMessage("LaTeX command \"{}\" cause PatternSyntaxException: {}")
.addArgument(command).addArgument(e.getMessage()).log();
}

}
return par;
}
Expand Down
15 changes: 8 additions & 7 deletions src/org/omegat/filters3/xml/Translator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.xml.sax.Attributes;

import org.omegat.core.data.ProtectedPart;
import org.omegat.util.Language;
import org.xml.sax.Attributes;

/**
* The interface to specify the method a Handler can use to translate text.
Expand All @@ -44,7 +45,7 @@
* @author Didier Briel
* @author Alex Buloichik
*/
interface Translator {
public interface Translator {
/**
* The method the Handler would call to pass translatable content to OmegaT
* core and receive translation.
Expand All @@ -56,15 +57,15 @@ interface Translator {
*
* @param inFile
* The source file.
* @param outEncoding
* @param inEncoding
* Encoding of the source file, if the filter supports it.
* Otherwise null.
* Otherwise, it should be null.
* @return The reader of the source file.
*
* @throws UnsupportedEncodingException
* Thrown if JVM doesn't support the specified inEncoding.
* @throws IOException
* If any I/O Error occurs upon reader creation.
* If I/O Error occurs upon reader creation.
*/
BufferedReader createReader(File inFile, String inEncoding) throws UnsupportedEncodingException,
IOException;
Expand All @@ -76,7 +77,7 @@ BufferedReader createReader(File inFile, String inEncoding) throws UnsupportedEn
* The target file.
* @param outEncoding
* Encoding of the target file, if the filter supports it.
* Otherwise null.
* Otherwise, it should be null.
* @return The writer for the target file.
*
* @throws UnsupportedEncodingException
Expand Down Expand Up @@ -116,7 +117,7 @@ BufferedWriter createWriter(File outFile, String outEncoding) throws Unsupported
void text(String text);

/**
* Returns true if current section should be ignored by parser.
* Returns true if the current section should be ignored by parser.
*/
boolean isInIgnored();

Expand Down
29 changes: 29 additions & 0 deletions src/org/omegat/gui/editor/EditorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,35 @@ public void windowDeactivated() {
editor.autoCompleter.setVisible(false);
}

@Override
public CaretPosition getCurrentPositionInEntryTranslationInEditor() {
int selectionEnd = getCurrentPositionInEntryTranslation();
String selection = getSelectedText();
String translation = 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);
}
}

/**
* Class for checking if alternative translation exist.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/org/omegat/gui/editor/IEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,4 +499,12 @@ public static CaretPosition startOfEntry() {
default boolean isOrientationAllLtr() {
return true;
}

/**
* Get the current position in the entity translation in the editor
* @return caret position.
*/
default CaretPosition getCurrentPositionInEntryTranslationInEditor() {
return CaretPosition.startOfEntry();
}
}
3 changes: 1 addition & 2 deletions src/org/omegat/gui/main/BaseMainWindowMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,7 @@ protected JRadioButtonMenuItem createRadioButtonMenuItem(final String titleKey,
}

/**
* Set 'actionCommand' for all menu items. TODO: change to key from resource
* bundle values
* Set 'actionCommand' for all menu items.
*/
protected void setActionCommands() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ private void doInstall() {
}
}

// TODO: We shouldn't be persisting anything here.
// Note: When we realize spellchecker dictionary as an extension plugin,
// We should remove the URL preference.
// See also SpellcheckerConfigurationController#initFromPrefs.
Preferences.setPreference(Preferences.SPELLCHECKER_DICTIONARY_URL, panel.dictionaryUrlTextField.getText());

try {
Expand Down
40 changes: 1 addition & 39 deletions src/org/omegat/gui/search/SearchWindowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import org.omegat.core.search.Searcher;
import org.omegat.core.threads.SearchThread;
import org.omegat.gui.editor.EditorController;
import org.omegat.gui.editor.IEditor;
import org.omegat.gui.editor.IEditor.CaretPosition;
import org.omegat.gui.editor.IEditorFilter;
import org.omegat.gui.editor.filter.ReplaceFilter;
Expand Down Expand Up @@ -123,7 +122,7 @@ public SearchWindowController(SearchMode mode) {

this.mode = mode;
initialEntry = Core.getEditor().getCurrentEntryNumber();
initialCaret = getCurrentPositionInEntryTranslationInEditor(Core.getEditor());
initialCaret = Core.getEditor().getCurrentPositionInEntryTranslationInEditor();

if (Platform.isMacOSX()) {
OSXIntegration.enableFullScreen(form);
Expand Down Expand Up @@ -1165,43 +1164,6 @@ private void setEnabled(Container component, boolean enabled) {
}
}

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

public void addWindowListener(WindowListener listener) {
form.addWindowListener(listener);
}
Expand Down
Loading
Loading