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

feat: Optionally allow selecting segment with a single click #1053

Draft
wants to merge 3 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
1 change: 1 addition & 0 deletions src/org/omegat/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ WG_SAVE_ORIGIN=Save origin of &translation
WG_INITIAL_SEGMENT_LOAD_COUNT=Initial number of loaded segments:
WG_INITIAL_SEGMENT_LOAD_COUNT_TOOLTIP=When a single file has more segments than this, additional segments will be loaded on-demand as you scroll.
WG_PARA_MARK=Paragraph delimiter:
WF_OPTION_ALLOW_SELECT_SINGLE_CLICK=Activate segment with single click (Feature is only active while the cursor is locked.)

# org.omegat.gui.preferences.view.TMMatchesPreferencesPanel.java
EXT_TMX_DESCRIPTION=Settings for tags originating from non-OmegaT TMX files:
Expand Down
32 changes: 31 additions & 1 deletion src/org/omegat/gui/editor/EditorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,11 @@ private void insertStartParagraphMark(Document3 doc, SegmentBuilder sb, int star
*/
public void activateEntry() {
activateEntry(CaretPosition.startOfEntry());

}

public void activateEntryAndGotoOffset(int offset) {
activateEntry(CaretPosition.goToCharacterAtIndex(offset));
}

/**
Expand Down Expand Up @@ -1002,7 +1007,7 @@ public void showStat() {
* Go to segment at specified location.
*
* @param location
* location
* location relative to the whole document
* @return true if segment changed, false if location inside current segment
*/
protected boolean goToSegmentAtLocation(int location) {
Expand All @@ -1022,6 +1027,31 @@ protected boolean goToSegmentAtLocation(int location) {
}
}

protected boolean goToSegmentAtLocationAndJumpToOffset(int location, int offset) {
// clicked segment

int segmentAtLocation = getSegmentIndexAtLocation(location);
if (segmentAtLocation < 0) {
return false;
}
if (displayedEntryIndex != segmentAtLocation) {
commitAndDeactivate();
displayedEntryIndex = segmentAtLocation;
activateEntryAndGotoOffset(offset);
return true;
} else {
return false;
}
}

protected int getStartForSegmentWithIndex(int segmentIndex) {
if (m_docSegList == null) {
return -1;
}
SegmentBuilder builder = m_docSegList[segmentIndex];
return builder.getStartPosition();
}

protected int getSegmentIndexAtLocation(int location) {
if (m_docSegList == null) {
return -1;
Expand Down
19 changes: 19 additions & 0 deletions src/org/omegat/gui/editor/EditorTextArea3.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import org.omegat.util.StringUtil;
import org.omegat.util.gui.Styles;
import org.omegat.util.gui.UIDesignManager;
import org.omegat.util.Preferences;


/**
* Changes of standard JEditorPane implementation for support custom behavior.
Expand Down Expand Up @@ -228,6 +230,23 @@ public boolean isInActiveTranslation(int position) {
public void mouseClicked(MouseEvent e) {
autoCompleter.setVisible(false);

boolean singleClickSegmentActivation =
Preferences.isPreference(Preferences.SINGLE_CLICK_SEGMENT_ACTIVATION);
System.out.println("Preferences.SINGLE_CLICK_SEGMENT_ACTIVATION: " + (singleClickSegmentActivation ? "ENABLED" : "DISABLED"));

if (singleClickSegmentActivation
&& e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1
&& lockCursorToInputArea) {
int location = getCaretPosition();
int mousepos = EditorTextArea3.this.viewToModel2D(e.getPoint());
int segmentIndex = controller.getSegmentIndexAtLocation(location);
int startLocation = controller.getStartForSegmentWithIndex(segmentIndex);
int offset = mousepos - startLocation;
boolean changed = controller.goToSegmentAtLocationAndJumpToOffset(mousepos, offset);
if (changed) {
return;
}
}
// Handle double-click
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
int mousepos = EditorTextArea3.this.viewToModel2D(e.getPoint());
Expand Down
11 changes: 11 additions & 0 deletions src/org/omegat/gui/editor/IEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ public CaretPosition(int selectionStart, int selectionEnd) {
public static CaretPosition startOfEntry() {
return new CaretPosition(0);
}

/**
* Set caret to a specific character.
* @param location 0 when first character of String, otherwise
* location counts all text, both original language
* and translated text.
* @return caret position.
*/
public static CaretPosition goToCharacterAtIndex(int location) {
return new CaretPosition(location);
}
}

/**
Expand Down
43 changes: 41 additions & 2 deletions src/org/omegat/gui/preferences/view/EditingBehaviorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

package org.omegat.gui.preferences.view;

import static org.openide.awt.Mnemonics.setLocalizedText;

import javax.swing.JComponent;

import org.omegat.gui.editor.SegmentBuilder;
Expand Down Expand Up @@ -63,6 +65,7 @@ public String toString() {

private void initGui() {
panel = new EditingBehaviorPanel();
initLabels();
panel.insertFuzzyCheckBox.addActionListener(e -> {
panel.similarityLabel.setEnabled(panel.insertFuzzyCheckBox.isSelected());
panel.similaritySpinner.setEnabled(panel.insertFuzzyCheckBox.isSelected());
Expand All @@ -71,10 +74,40 @@ private void initGui() {
});
}

/**
* Set localized labels from Bundle.
*/
private void initLabels() {
panel.descriptionTextArea.setText(OStrings.getString("GUI_WORKFLOW_DESCRIPTION"));
setLocalizedText(panel.defaultRadio, OStrings.getString("WF_OPTION_INSERT_SOURCE"));
setLocalizedText(panel.leaveEmptyRadio, OStrings.getString("WF_OPTION_INSERT_NOTHTHING"));
setLocalizedText(panel.insertFuzzyCheckBox, OStrings.getString("WF_OPTION_INSERT_FUZZY_MATCH"));
setLocalizedText(panel.similarityLabel,
OStrings.getString("GUI_WORKFLOW_OPTION_Minimal_Similarity"));
setLocalizedText(panel.prefixLabel, OStrings.getString("WF_OPTION_INSERT_FUZZY_PREFIX"));
setLocalizedText(panel.convertNumbers, OStrings.getString("WF_OPTION_REPLACE_NUMBERS"));
setLocalizedText(panel.allowTranslationEqualToSource, OStrings.getString(
"WF_OPTION_ALLOW_TRANS_EQ_TO_SRC"));
setLocalizedText(panel.exportCurrentSegment, OStrings.getString("WF_OPTION_EXPORT__CURRENT_SEGMENT"));
setLocalizedText(panel.stopOnAlternativeTranslation, OStrings.getString(
"WF_OPTION_GOTO_NEXT_UNTRANSLATED"));
setLocalizedText(panel.allowTagEditing, OStrings.getString("WF_TAG_EDITING"));
setLocalizedText(panel.tagValidateOnLeave, OStrings.getString("WG_TAG_VALIDATE_ON_LEAVE"));
setLocalizedText(panel.cbSaveAutoStatus, OStrings.getString("WG_SAVE_AUTO_STATUS"));
setLocalizedText(panel.cbSaveOrigin, OStrings.getString("WG_SAVE_ORIGIN"));
setLocalizedText(panel.initialSegCountLabel, OStrings.getString("WG_INITIAL_SEGMENT_LOAD_COUNT"));
panel.initialSegCountSpinner.setToolTipText(OStrings.getString(
"WG_INITIAL_SEGMENT_LOAD_COUNT_TOOLTIP"));
setLocalizedText(panel.paraMarkLabel, OStrings.getString("WG_PARA_MARK"));
setLocalizedText(panel.singleClickActivationCheckBox, OStrings.getString(
"WF_OPTION_ALLOW_SELECT_SINGLE_CLICK"));
}

@Override
protected void initFromPrefs() {
// Double negation? then prefInsertSource is the contrary of Preferences.DONT_INSERT_SOURCE_TEXT
boolean prefInsertSource = !Preferences.isPreferenceDefault(Preferences.DONT_INSERT_SOURCE_TEXT, SegmentBuilder.DONT_INSERT_SOURCE_TEXT_DEFAULT);
boolean prefInsertSource = !Preferences.isPreferenceDefault(Preferences.DONT_INSERT_SOURCE_TEXT,
SegmentBuilder.DONT_INSERT_SOURCE_TEXT_DEFAULT);
panel.defaultRadio.setSelected(prefInsertSource);
panel.leaveEmptyRadio.setSelected(!prefInsertSource);

Expand All @@ -87,7 +120,10 @@ protected void initFromPrefs() {
panel.prefixText.setText(Preferences.getPreference(Preferences.BEST_MATCH_EXPLANATORY_TEXT));
}

panel.allowTranslationEqualToSource.setSelected(Preferences.isPreferenceDefault(Preferences.ALLOW_TRANS_EQUAL_TO_SRC, true));
panel.allowTranslationEqualToSource.setSelected(
Preferences.isPreferenceDefault(Preferences.ALLOW_TRANS_EQUAL_TO_SRC, true));
panel.singleClickActivationCheckBox.setSelected(
Preferences.isPreferenceDefault(Preferences.SINGLE_CLICK_SEGMENT_ACTIVATION, false));
panel.exportCurrentSegment.setSelected(Preferences.isPreference(Preferences.EXPORT_CURRENT_SEGMENT));
panel.stopOnAlternativeTranslation
.setSelected(Preferences.isPreference(Preferences.STOP_ON_ALTERNATIVE_TRANSLATION));
Expand All @@ -113,6 +149,7 @@ public void restoreDefaults() {
panel.prefixText.setText(OStrings.getString("WF_DEFAULT_PREFIX"));

panel.allowTranslationEqualToSource.setSelected(true);
panel.singleClickActivationCheckBox.setSelected(false);
panel.exportCurrentSegment.setSelected(false);
panel.stopOnAlternativeTranslation.setSelected(false);
panel.convertNumbers.setSelected(true);
Expand Down Expand Up @@ -147,6 +184,8 @@ public void persist() {
Preferences.setPreference(Preferences.ALLOW_TRANS_EQUAL_TO_SRC,
panel.allowTranslationEqualToSource.isSelected());
Preferences.setPreference(Preferences.EXPORT_CURRENT_SEGMENT, panel.exportCurrentSegment.isSelected());
Preferences.setPreference(Preferences.SINGLE_CLICK_SEGMENT_ACTIVATION,
panel.singleClickActivationCheckBox.isSelected());
Preferences.setPreference(Preferences.STOP_ON_ALTERNATIVE_TRANSLATION,
panel.stopOnAlternativeTranslation.isSelected());
Preferences.setPreference(Preferences.CONVERT_NUMBERS, panel.convertNumbers.isSelected());
Expand Down
43 changes: 25 additions & 18 deletions src/org/omegat/gui/preferences/view/EditingBehaviorPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
<Connection component="prefixLabel" name="getFont" type="method"/>
</Property>
<Property name="lineWrap" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/omegat/Bundle.properties" key="GUI_WORKFLOW_DESCRIPTION" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
<Property name="text" type="java.lang.String" value="descriptionTextArea" noResource="true"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
<Property name="wrapStyleWord" type="boolean" value="true"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="opaque" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="0" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="10" insetsLeft="0" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
Expand All @@ -53,9 +55,7 @@
<ComponentRef name="ourButtonGroup"/>
</Property>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/omegat/Bundle.properties" key="WF_OPTION_INSERT_SOURCE" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
<Property name="text" type="java.lang.String" value="defaultRadio" noResource="true"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
Expand All @@ -79,9 +79,7 @@
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="ourButtonGroup"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/omegat/Bundle.properties" key="WF_OPTION_INSERT_NOTHTHING" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
<Property name="text" type="java.lang.String" value="leaveEmptyRadio" noResource="true"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EmptyBorderInfo">
<EmptyBorder bottom="0" left="0" right="0" top="0"/>
Expand All @@ -99,13 +97,8 @@
</Component>
<Component class="javax.swing.JCheckBox" name="insertFuzzyCheckBox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/omegat/Bundle.properties" key="WF_OPTION_INSERT_FUZZY_MATCH" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
<Property name="text" type="java.lang.String" value="insertFuzzyCheckBox" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="radiosActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
Expand All @@ -120,9 +113,7 @@
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="similaritySpinner"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/omegat/Bundle.properties" key="GUI_WORKFLOW_OPTION_Minimal_Similarity" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
<Property name="text" type="java.lang.String" value="similarityLabel" noResource="true"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<AuxValues>
Expand Down Expand Up @@ -311,6 +302,9 @@
<ResourceString bundle="org/omegat/Bundle.properties" key="WG_INITIAL_SEGMENT_LOAD_COUNT_TOOLTIP" replaceFormat="OStrings.getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="14" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="5" insetsRight="5" anchor="17" weightX="0.0" weightY="0.0"/>
Expand Down Expand Up @@ -375,5 +369,18 @@
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="singleClickActivationCheckBox">
<Properties>
<Property name="text" type="java.lang.String" value="jCheckBox1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="0"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="16" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Form>
Loading
Loading