From a296eb4f134e435257455c7b092f32ce8726facc Mon Sep 17 00:00:00 2001 From: Thomas CORDONNIER Date: Fri, 21 Jun 2024 14:50:36 +0200 Subject: [PATCH] Prevent any replacement in lock segment based on menu --- .../omegat/gui/editor/EditorTextArea3.java | 43 +++++-------------- 1 file changed, 10 insertions(+), 33 deletions(-) diff --git a/src/org/omegat/gui/editor/EditorTextArea3.java b/src/org/omegat/gui/editor/EditorTextArea3.java index 4fa4df0c17..a3b38876d7 100644 --- a/src/org/omegat/gui/editor/EditorTextArea3.java +++ b/src/org/omegat/gui/editor/EditorTextArea3.java @@ -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 @@ -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; } @@ -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); @@ -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); @@ -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); @@ -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. @@ -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()