Skip to content

Commit

Permalink
Prevent any replacement in lock segment based on menu
Browse files Browse the repository at this point in the history
  • Loading branch information
t-cordonnier committed Aug 26, 2024
1 parent ff26f45 commit a296eb4
Showing 1 changed file with 10 additions and 33 deletions.
43 changes: 10 additions & 33 deletions src/org/omegat/gui/editor/EditorTextArea3.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
2013 Zoltan Bartko
2014 Aaron Madlon-Kay
2015 Yu Tang
2023-2024 Thomas Cordonnier
Home page: https://www.omegat.org/
Support center: https://omegat.org/support
Expand Down Expand Up @@ -355,14 +356,6 @@ protected void processKeyEvent(KeyEvent e) {
return;
} else if (keyEvent == KeyEvent.KEY_TYPED) {
//key typed
// Treat the case of enforced translations which should be locked
if (lockListener.isLocked != null) {
// If active, prevent modifying the segment. Else, only display locked status
Core.getMainWindow().showStatusMessageRB("MW_SEGMENT_LOCKED", lockListener.isLocked);
if (Preferences.isPreferenceDefault(Preferences.SUPPORT_LOCKED_SEGMENTS, true)) {
return;
}
}
super.processKeyEvent(e);
return;
}
Expand Down Expand Up @@ -417,13 +410,6 @@ protected void processKeyEvent(KeyEvent e) {
processed = true;
}
} else if (s.equals(KEYSTROKE_INSERT_LF)) {
// Treat the case of enforced translations which should be locked
if (lockListener.isLocked != null) {
Core.getMainWindow().showStatusMessageRB("MW_SEGMENT_LOCKED", lockListener.isLocked);
if (Preferences.isPreferenceDefault(Preferences.SUPPORT_LOCKED_SEGMENTS, true)) {
return;
}
}
// Insert LF
KeyEvent ke = new KeyEvent(e.getComponent(), e.getID(), e.getWhen(), 0, KeyEvent.VK_ENTER, '\n');
super.processKeyEvent(ke);
Expand All @@ -434,13 +420,6 @@ protected void processKeyEvent(KeyEvent e) {
setSelectionEnd(doc.getTranslationEnd());
processed = true;
} else if (s.equals(KEYSTROKE_DELETE_PREV_TOKEN)) {
// Treat the case of enforced translations which should be locked
if (lockListener.isLocked != null) {
Core.getMainWindow().showStatusMessageRB("MW_SEGMENT_LOCKED", lockListener.isLocked);
if (Preferences.isPreferenceDefault(Preferences.SUPPORT_LOCKED_SEGMENTS, true)) {
return;
}
}
// Delete previous token
try {
processed = wholeTagDelete(false);
Expand All @@ -458,13 +437,6 @@ protected void processKeyEvent(KeyEvent e) {
// do nothing
}
} else if (s.equals(KEYSTROKE_DELETE_NEXT_TOKEN)) {
// Treat the case of enforced translations which should be locked
if (lockListener.isLocked != null) {
Core.getMainWindow().showStatusMessageRB("MW_SEGMENT_LOCKED", lockListener.isLocked);
if (Preferences.isPreferenceDefault(Preferences.SUPPORT_LOCKED_SEGMENTS, true)) {
return;
}
}
// Delete next token
try {
processed = wholeTagDelete(true);
Expand Down Expand Up @@ -526,16 +498,15 @@ protected void processKeyEvent(KeyEvent e) {
checkAndFixCaret(true);
}
}
// Treat the case of enforced translations which should be locked
// Treat the case of enforced translations which should be locked - this case does not seem to be treated via replaceSelection
if (lockListener.isLocked != null) {
if ( ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE) || (e.getKeyCode() == KeyEvent.VK_DELETE))
|| (e.getKeyCode() == KeyEvent.VK_V && ( (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) ) ) {
if ((e.getKeyCode() == KeyEvent.VK_BACK_SPACE) || (e.getKeyCode() == KeyEvent.VK_DELETE)) {
Core.getMainWindow().showStatusMessageRB("MW_SEGMENT_LOCKED", lockListener.isLocked);
if (Preferences.isPreferenceDefault(Preferences.SUPPORT_LOCKED_SEGMENTS, true)) {
return;
}
}
}
}
super.processKeyEvent(e);
// note that the translation start/end position are not updated yet. This has been updated when
// then keyreleased event occurs.
Expand Down Expand Up @@ -889,6 +860,12 @@ private static class PopupMenuConstructorInfo {

@Override
public void replaceSelection(String content) {
if (lockListener.isLocked != null) {
Core.getMainWindow().showStatusMessageRB("MW_SEGMENT_LOCKED", lockListener.isLocked);
if (Preferences.isPreferenceDefault(Preferences.SUPPORT_LOCKED_SEGMENTS, true)) {
return;
}
}
// Overwrite current selection, and if at the end of the segment, allow
// inserting new text.
if (isEditable() && overtypeMode && getSelectionStart() == getSelectionEnd()
Expand Down

0 comments on commit a296eb4

Please sign in to comment.