diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index e8874b3b41..61cc1075ca 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -32,6 +32,11 @@ + + + + diff --git a/src/org/omegat/gui/accesstool/AccessTools.java b/src/org/omegat/gui/accesstool/AccessTools.java index 3598235974..c0edd3ae79 100644 --- a/src/org/omegat/gui/accesstool/AccessTools.java +++ b/src/org/omegat/gui/accesstool/AccessTools.java @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import javax.swing.Box; @@ -44,18 +43,16 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import org.omegat.core.Core; import org.omegat.core.CoreEvents; import org.omegat.core.events.IProjectEventListener; -import org.omegat.gui.main.BaseMainWindowMenuHandler; -import org.omegat.gui.main.MainMenuIcons; +import org.omegat.gui.main.MainWindowMenuHandler.EditFindInProjectMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.OptionsPreferencesMenuItemAction; import org.omegat.gui.main.ProjectUICommands; import org.omegat.util.OConsts; import org.omegat.util.OStrings; import org.omegat.util.RecentProjects; -import org.omegat.util.gui.ResourcesUtil; /** * @author Hiroshi Miura @@ -71,15 +68,13 @@ public class AccessTools extends JPanel { private ProjectComboBoxModel projectComboBoxModel; private SourceComboBoxModel sourceComboBoxModel; - private final BaseMainWindowMenuHandler mainWindowMenuHandler; private URI selectedProject = null; private static final int MAX_PATH_LENGTH_SHOWN = 25; private static final float CHECKBOX_HEIGHT_RATIO = 1.8f; - public AccessTools(final BaseMainWindowMenuHandler mainWindowMenuHandler) { - this.mainWindowMenuHandler = mainWindowMenuHandler; + public AccessTools() { initComponents(); } @@ -122,13 +117,12 @@ public void initComponents() { sourceFilesCB.setMaximumSize(new Dimension(cbWidth, cbHeight)); add(sourceFilesCB); - searchButton = new JButton("", - Objects.requireNonNullElseGet(UIManager.getIcon("OmegaT.newUI.search.icon"), - () -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.search.png")))); + // These buttons show only icon + searchButton = new JButton(new EditFindInProjectMenuItemAction()); + searchButton.setText(""); searchButton.setBorderPainted(false); - settingsButton = new JButton("", Objects.requireNonNullElseGet( - UIManager.getIcon("OmegaT.newUI.settings.icon"), - () -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.settings.png")))); + settingsButton = new JButton(new OptionsPreferencesMenuItemAction()); + settingsButton.setText(""); settingsButton.setBorderPainted(false); // -- right side @@ -136,12 +130,6 @@ public void initComponents() { add(searchButton); add(settingsButton); - searchButton.addActionListener(actionEvent -> { - mainWindowMenuHandler.editFindInProjectMenuItemActionPerformed(); - }); - settingsButton.addActionListener(actionEvent -> { - mainWindowMenuHandler.optionsPreferencesMenuItemActionPerformed(); - }); recentProjectCB.addActionListener(actionEvent -> { // when select a project from the list, we open it. final Object item = recentProjectCB.getSelectedItem(); @@ -153,13 +141,13 @@ public void initComponents() { if (projectUri.getScheme().equals("omegat")) { switch (projectUri.getSchemeSpecificPart()) { case "new": - mainWindowMenuHandler.projectNewMenuItemActionPerformed(); + ProjectUICommands.projectCreate(); break; case "open": - mainWindowMenuHandler.projectOpenMenuItemActionPerformed(); + ProjectUICommands.projectOpen(null); break; case "team": - mainWindowMenuHandler.projectTeamNewMenuItemActionPerformed(); + ProjectUICommands.projectTeamCreate(); break; default: break; diff --git a/src/org/omegat/gui/glossary/GlossaryTextArea.java b/src/org/omegat/gui/glossary/GlossaryTextArea.java index 44259638e4..fea14e0c92 100644 --- a/src/org/omegat/gui/glossary/GlossaryTextArea.java +++ b/src/org/omegat/gui/glossary/GlossaryTextArea.java @@ -72,6 +72,7 @@ import org.omegat.gui.editor.EditorUtils; import org.omegat.gui.main.DockableScrollPane; import org.omegat.gui.main.IMainWindow; +import org.omegat.gui.main.ProjectUICommands; import org.omegat.gui.shortcuts.PropertiesShortcuts; import org.omegat.util.HttpConnectionUtils; import org.omegat.util.Log; @@ -414,8 +415,8 @@ public void populatePaneMenu(JPopupMenu menu) { openFile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - Core.getMainWindow().getMainMenu().invokeAction("projectAccessWritableGlossaryMenuItem", - e.getModifiers()); + int modifier = e.getModifiers(); + ProjectUICommands.openWritableGlossaryFile((modifier & ActionEvent.ALT_MASK) != 0); } }); openFile.setEnabled(false); diff --git a/src/org/omegat/gui/main/BaseMainWindowMenu.java b/src/org/omegat/gui/main/BaseMainWindowMenu.java index be2e9d55ed..5cb6387d74 100644 --- a/src/org/omegat/gui/main/BaseMainWindowMenu.java +++ b/src/org/omegat/gui/main/BaseMainWindowMenu.java @@ -15,7 +15,7 @@ * 2014 Aaron Madlon-Kay * 2015 Didier Briel, Yu Tang * 2017 Didier Briel - * 2023 Hiroshi Miura + * 2023-2024 Hiroshi Miura * Home page: https://www.omegat.org/ * Support center: https://omegat.org/support * @@ -37,29 +37,19 @@ package org.omegat.gui.main; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.File; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.EnumMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; -import javax.swing.KeyStroke; -import javax.swing.UIManager; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; @@ -70,7 +60,7 @@ import org.omegat.core.CoreEvents; import org.omegat.core.events.IApplicationEventListener; import org.omegat.gui.editor.EditorSettings; -import org.omegat.gui.shortcuts.PropertiesShortcuts; +import org.omegat.gui.main.MainWindowMenuHandler.*; import org.omegat.util.Log; import org.omegat.util.OStrings; import org.omegat.util.Platform; @@ -80,7 +70,6 @@ import org.omegat.util.StringUtil; import org.omegat.util.gui.MenuExtender; import org.omegat.util.gui.OSXIntegration; -import org.omegat.util.gui.Styles; /** * Base class for create main menu and handle main menu events. @@ -106,40 +95,40 @@ * /src/org/omegat/gui/main/MainMenuShortcuts.mac.properties with the proper * shortcuts if set. */ -public abstract class BaseMainWindowMenu implements ActionListener, MenuListener, IMainMenu { - - private static final Logger LOGGER = Logger.getLogger(BaseMainWindowMenu.class.getName()); - - public static final String HELP_MENU = "help_menu"; - public static final String HELP_ABOUT_MENUITEM = "help_about_menuitem"; - - /** MainWindow instance. */ - protected final IMainWindow mainWindow; +public abstract class BaseMainWindowMenu implements MenuListener, IMainMenu { /** menu bar instance */ protected final JMenuBar mainMenu = new JMenuBar(); - /** MainWindow menu handler instance. */ - protected final BaseMainWindowMenuHandler mainWindowMenuHandler; - private final Map menus = new EnumMap<>(MenuExtender.MenuKey.class); - public BaseMainWindowMenu(final IMainWindow mainWindow, - final BaseMainWindowMenuHandler mainWindowMenuHandler) { - this.mainWindow = mainWindow; - this.mainWindowMenuHandler = mainWindowMenuHandler; + @Deprecated + public BaseMainWindowMenu(IMainWindow mainWindow, MainWindowMenuHandler handler) { + this(); } - @Override - public void actionPerformed(ActionEvent evt) { - // Get item name from actionCommand. - String action = evt.getActionCommand(); + @Deprecated + public BaseMainWindowMenu(IMainWindow mainWindow) { + this(); + } - Log.logInfoRB("LOG_MENU_CLICK", action); + public BaseMainWindowMenu() { + } - invokeAction(action, evt.getModifiers()); + /** + * Initialize menu items. + *

+ * Call order should not be changed. + */ + void initComponents() { + createComponents(); + constructMenu(); + createMenuBar(); + configureActions(); } + abstract void createMenuBar(); + /** * Code for dispatching events from components to event handlers. * @@ -150,31 +139,8 @@ public void actionPerformed(ActionEvent evt) { public void menuSelected(MenuEvent evt) { // Item what perform event. JMenu menu = (JMenu) evt.getSource(); - // Get item name from actionCommand. - String action = menu.getActionCommand(); - - Log.logInfoRB("LOG_MENU_CLICK", action); - - // Find method by item name. - String methodName = action + "MenuSelected"; - Method method = null; - try { - method = mainWindowMenuHandler.getClass().getMethod(methodName, JMenu.class); - } catch (NoSuchMethodException ex) { - // method not declared - return; - } - - // Call ...MenuMenuSelected method. - try { - method.invoke(mainWindowMenuHandler, menu); - } catch (IllegalAccessException ex) { - throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); - } catch (InvocationTargetException ex) { - LOGGER.log(Level.SEVERE, "Error execute method", ex); - throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); - } + Log.logInfoRB("LOG_MENU_CLICK", menu.getActionCommand()); } public void menuCanceled(MenuEvent e) { @@ -183,22 +149,6 @@ public void menuCanceled(MenuEvent e) { public void menuDeselected(MenuEvent e) { } - /** - * Initialize menu items. - *

- * Call order should not be changed. - */ - void initComponents() { - createComponents(); - setActionCommands(); - constructMenu(); - createMenuBar(); - PropertiesShortcuts.getMainMenuShortcuts().bindKeyStrokes(mainMenu); - configureActions(); - } - - abstract void createMenuBar(); - protected void createComponents() { projectMenu = createMenu("TF_MENU_FILE", MenuExtender.MenuKey.PROJECT); editMenu = createMenu("TF_MENU_EDIT", MenuExtender.MenuKey.EDIT); @@ -207,218 +157,185 @@ protected void createComponents() { toolsMenu = createMenu("TF_MENU_TOOLS", MenuExtender.MenuKey.TOOLS); optionsMenu = createMenu("MW_OPTIONSMENU", MenuExtender.MenuKey.OPTIONS); helpMenu = createMenu("TF_MENU_HELP", MenuExtender.MenuKey.HELP); - helpMenu.setName(HELP_MENU); - projectNewMenuItem = createMenuItem("TF_MENU_FILE_CREATE"); - projectTeamNewMenuItem = createMenuItem("TF_MENU_FILE_TEAM_CREATE"); - projectOpenMenuItem = createMenuItem("TF_MENU_FILE_OPEN"); + projectNewMenuItem = createMenuItem(new ProjectNewMenuItemAction()); + projectTeamNewMenuItem = createMenuItem(new ProjectTeamNewMenuItemAction()); + projectOpenMenuItem = createMenuItem(new ProjectOpenMenuItemAction()); projectOpenRecentMenuItem = createMenu("TF_MENU_FILE_OPEN_RECENT"); - projectClearRecentMenuItem = createMenuItem("TF_MENU_FILE_CLEAR_RECENT"); - - projectReloadMenuItem = createMenuItem("TF_MENU_PROJECT_RELOAD"); - projectCloseMenuItem = createMenuItem("TF_MENU_FILE_CLOSE"); - projectSaveMenuItem = createMenuItem("TF_MENU_FILE_SAVE"); - projectImportMenuItem = createMenuItem("TF_MENU_FILE_IMPORT"); - projectWikiImportMenuItem = createMenuItem("TF_MENU_WIKI_IMPORT"); - projectCommitSourceFiles = createMenuItem("TF_MENU_FILE_COMMIT"); - projectCommitTargetFiles = createMenuItem("TF_MENU_FILE_TARGET"); - projectCompileMenuItem = createMenuItem("TF_MENU_FILE_COMPILE"); - projectSingleCompileMenuItem = createMenuItem("TF_MENU_FILE_SINGLE_COMPILE"); - projectMedOpenMenuItem = createMenuItem("TF_MENU_FILE_MED_OPEN"); - projectMedCreateMenuItem = createMenuItem("TF_MENU_FILE_MED_CREATE"); - projectEditMenuItem = createMenuItem("MW_PROJECTMENU_EDIT"); - viewFileListMenuItem = createMenuItem("TF_MENU_FILE_PROJWIN"); + projectClearRecentMenuItem = createMenuItem(new ProjectClearRecentMenuItemAction()); + + projectReloadMenuItem = createMenuItem(new ProjectReloadMenuItemAction()); + projectCloseMenuItem = createMenuItem(new ProjectCloseMenuItemAction()); + projectSaveMenuItem = createMenuItem(new ProjectSaveMenuItemAction()); + projectImportMenuItem = createMenuItem(new ProjectImportMenuItemAction()); + projectWikiImportMenuItem = createMenuItem(new ProjectWikiImportMenuItemAction()); + projectCommitSourceFiles = createMenuItem(new ProjectCommitSourceFilesAction()); + projectCommitTargetFiles = createMenuItem(new ProjectCommitTargetFilesAction()); + projectCompileMenuItem = createMenuItem(new ProjectCompileMenuItemAction()); + projectSingleCompileMenuItem = createMenuItem(new ProjectSingleCompileMenuItemAction()); + projectMedOpenMenuItem = createMenuItem(new ProjectMedOpenMenuItemAction()); + projectMedCreateMenuItem = createMenuItem(new ProjectMedCreateMenuItemAction()); + projectEditMenuItem = createMenuItem(new ProjectEditMenuItemAction()); + viewFileListMenuItem = createMenuItem(new ViewFileListMenuItemAction()); projectAccessProjectFilesMenu = createMenu("TF_MENU_FILE_ACCESS_PROJECT_FILES"); - projectAccessRootMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_ROOT"); - projectAccessDictionaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_DICTIONARY"); - projectAccessGlossaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_GLOSSARY"); - projectAccessSourceMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_SOURCE"); - projectAccessTargetMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_TARGET"); - projectAccessTMMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_TM"); - projectAccessExportTMMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_EXPORT_TM"); - projectAccessCurrentSourceDocumentMenuItem = createMenuItem( - "TF_MENU_FILE_ACCESS_CURRENT_SOURCE_DOCUMENT"); - projectAccessCurrentTargetDocumentMenuItem = createMenuItem( - "TF_MENU_FILE_ACCESS_CURRENT_TARGET_DOCUMENT"); - projectAccessWriteableGlossaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_WRITEABLE_GLOSSARY"); - - projectAccessRootMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_ROOT"); - projectAccessDictionaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_DICTIONARY"); - projectAccessGlossaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_GLOSSARY"); - projectAccessSourceMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_SOURCE"); - projectAccessTargetMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_TARGET"); - projectAccessTMMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_TM"); - projectAccessExportTMMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_EXPORT_TM"); + projectAccessRootMenuItem = createMenuItem(new ProjectAccessRootMenuItemAction()); + projectAccessDictionaryMenuItem = createMenuItem(new ProjectAccessDictionaryMenuItemAction()); + projectAccessGlossaryMenuItem = createMenuItem(new ProjectAccessGlossaryMenuItemAction()); + projectAccessSourceMenuItem = createMenuItem(new ProjectAccessSourceMenuItemAction()); + projectAccessTargetMenuItem = createMenuItem(new ProjectAccessTargetMenuItemAction()); + projectAccessTMMenuItem = createMenuItem(new ProjectAccessTMMenuItemAction()); + projectAccessExportTMMenuItem = createMenuItem(new ProjectAccessExportTMMenuItemAction()); projectAccessCurrentSourceDocumentMenuItem = createMenuItem( - "TF_MENU_FILE_ACCESS_CURRENT_SOURCE_DOCUMENT"); - projectAccessCurrentTargetDocumentMenuItem = createMenuItem( - "TF_MENU_FILE_ACCESS_CURRENT_TARGET_DOCUMENT"); - projectAccessWriteableGlossaryMenuItem = createMenuItem("TF_MENU_FILE_ACCESS_WRITEABLE_GLOSSARY"); - projectRestartMenuItem = createMenuItem("TF_MENU_FILE_RESTART"); - projectExitMenuItem = createMenuItem("TF_MENU_FILE_QUIT"); - - editUndoMenuItem = createMenuItem("TF_MENU_EDIT_UNDO"); - editRedoMenuItem = createMenuItem("TF_MENU_EDIT_REDO"); - editOverwriteTranslationMenuItem = createMenuItem("TF_MENU_EDIT_RECYCLE"); - editInsertTranslationMenuItem = createMenuItem("TF_MENU_EDIT_INSERT"); - editOverwriteSourceMenuItem = createMenuItem("TF_MENU_EDIT_SOURCE_OVERWRITE"); - editInsertSourceMenuItem = createMenuItem("TF_MENU_EDIT_SOURCE_INSERT"); - editSelectSourceMenuItem = createMenuItem("TF_MENU_EDIT_SOURCE_SELECT"); - editOverwriteMachineTranslationMenuItem = createMenuItem( - "TF_MENU_EDIT_OVERWRITE_MACHITE_TRANSLATION"); - editTagPainterMenuItem = createMenuItem("TF_MENU_EDIT_TAGPAINT"); - editTagNextMissedMenuItem = createMenuItem("TF_MENU_EDIT_TAG_NEXT_MISSED"); - editExportSelectionMenuItem = createMenuItem("TF_MENU_EDIT_EXPORT_SELECTION"); - editCreateGlossaryEntryMenuItem = createMenuItem("TF_MENU_EDIT_CREATE_GLOSSARY_ENTRY"); - editFindInProjectMenuItem = createMenuItem("TF_MENU_EDIT_FIND"); - editReplaceInProjectMenuItem = createMenuItem("TF_MENU_EDIT_REPLACE"); - editSearchDictionaryMenuItem = createMenuItem("TF_MENU_EDIT_SEARCH_DICTIONARY"); + new ProjectAccessCurrentSourceDocumentMenuItemAction()); + projectAccessCurrentTargetDocumentMenuItem = createMenuItem(new + ProjectAccessCurrentTargetDocumentMenuItemAction()); + projectAccessWriteableGlossaryMenuItem = createMenuItem( + new ProjectAccessWriteableGlossaryMenuItemAction()); + projectRestartMenuItem = createMenuItem(new ProjectRestartMenuItemAction()); + projectExitMenuItem = createMenuItem(new ProjectExitMenuItemAction()); + + editUndoMenuItem = createMenuItem(new EditUndoMenuItemAction()); + editRedoMenuItem = createMenuItem(new EditRedoMenuItemAction()); + editOverwriteTranslationMenuItem = createMenuItem(new EditOverwriteTranslationMenuItemAction()); + editInsertTranslationMenuItem = createMenuItem(new EditInsertTranslationMenuItemAction()); + editOverwriteSourceMenuItem = createMenuItem(new EditOverwriteSourceMenuItemAction()); + editInsertSourceMenuItem = createMenuItem(new EditInsertSourceMenuItemAction()); + editSelectSourceMenuItem = createMenuItem(new EditSelectSourceMenuItemAction()); + editOverwriteMachineTranslationMenuItem = createMenuItem(new EditOverwriteMachineTranslationMenuItemAction()); + editTagPainterMenuItem = createMenuItem(new EditTagPainterMenuItemAction()); + editTagNextMissedMenuItem = createMenuItem(new EditTagNextMissedMenuItemAction()); + editExportSelectionMenuItem = createMenuItem(new EditExportSelectionMenuItemAction()); + editCreateGlossaryEntryMenuItem = createMenuItem(new EditCreateGlossaryEntryMenuItemAction()); + editFindInProjectMenuItem = createMenuItem(new EditFindInProjectMenuItemAction()); + editReplaceInProjectMenuItem = createMenuItem(new EditReplaceInProjectMenuItemAction()); + editSearchDictionaryMenuItem = createMenuItem(new EditSearchDictionaryMenuItemAction()); + switchCaseSubMenu = createMenu("TF_EDIT_MENU_SWITCH_CASE"); selectFuzzySubMenu = createMenu("TF_MENU_EDIT_COMPARE"); - editSelectFuzzyPrevMenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_PREV"); - editSelectFuzzyNextMenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_NEXT"); - editSelectFuzzy1MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_1"); - editSelectFuzzy2MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_2"); - editSelectFuzzy3MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_3"); - editSelectFuzzy4MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_4"); - editSelectFuzzy5MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_5"); + editSelectFuzzyPrevMenuItem = createMenuItem(new EditSelectFuzzyPrevMenuItemAction()); + editSelectFuzzyNextMenuItem = createMenuItem(new EditSelectFuzzyNextMenuItemAction()); + editSelectFuzzy1MenuItem = createMenuItem(new EditSelectFuzzy1MenuItemAction()); + editSelectFuzzy2MenuItem = createMenuItem(new EditSelectFuzzy2MenuItemAction()); + editSelectFuzzy3MenuItem = createMenuItem(new EditSelectFuzzy3MenuItemAction()); + editSelectFuzzy4MenuItem = createMenuItem(new EditSelectFuzzy4MenuItemAction()); + editSelectFuzzy5MenuItem = createMenuItem(new EditSelectFuzzy5MenuItemAction()); insertCharsSubMenu = createMenu("TF_MENU_EDIT_INSERT_CHARS"); - insertCharsLRM = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_LRM"); - insertCharsRLM = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_RLM"); - insertCharsLRE = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_LRE"); - insertCharsRLE = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_RLE"); - insertCharsPDF = createMenuItem("TF_MENU_EDIT_INSERT_CHARS_PDF"); - - editMultipleDefault = createMenuItem("MULT_MENU_DEFAULT"); - editMultipleAlternate = createMenuItem("MULT_MENU_MULTIPLE"); - editRegisterUntranslatedMenuItem = createMenuItem("TF_MENU_EDIT_UNTRANSLATED_TRANSLATION"); - editRegisterEmptyMenuItem = createMenuItem("TF_MENU_EDIT_EMPTY_TRANSLATION"); - editRegisterIdenticalMenuItem = createMenuItem("TF_MENU_EDIT_IDENTICAL_TRANSLATION"); - - lowerCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_LOWER"); - upperCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_UPPER"); - titleCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_TITLE"); - sentenceCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_TO_SENTENCE"); - cycleSwitchCaseMenuItem = createMenuItem("TF_EDIT_MENU_SWITCH_CASE_CYCLE"); - - gotoNextUntranslatedMenuItem = createMenuItem("TF_MENU_EDIT_UNTRANS"); - gotoNextTranslatedMenuItem = createMenuItem("TF_MENU_EDIT_TRANS"); - gotoNextSegmentMenuItem = createMenuItem("TF_MENU_EDIT_NEXT"); - gotoPreviousSegmentMenuItem = createMenuItem("TF_MENU_EDIT_PREV"); - gotoSegmentMenuItem = createMenuItem("TF_MENU_EDIT_GOTO"); - gotoNextNoteMenuItem = createMenuItem("TF_MENU_EDIT_NEXT_NOTE"); - gotoPreviousNoteMenuItem = createMenuItem("TF_MENU_EDIT_PREV_NOTE"); - gotoNextUniqueMenuItem = createMenuItem("TF_MENU_GOTO_NEXT_UNIQUE"); - gotoMatchSourceSegment = createMenuItem("TF_MENU_GOTO_SELECTED_MATCH_SOURCE"); + insertCharsLRM = createMenuItem(new InsertCharsLRMAction()); + insertCharsRLM = createMenuItem(new InsertCharsRLMAction()); + insertCharsLRE = createMenuItem(new InsertCharsLREAction()); + insertCharsRLE = createMenuItem(new InsertCharsRLEAction()); + insertCharsPDF = createMenuItem(new InsertCharsPDFAction()); + + editMultipleDefault = createMenuItem(new EditMultipleDefaultAction()); + editMultipleAlternate = createMenuItem(new EditMultipleAlternateAction()); + editRegisterUntranslatedMenuItem = createMenuItem(new EditRegisterUntranslatedMenuItemAction()); + editRegisterEmptyMenuItem = createMenuItem(new EditRegisterEmptyMenuItemAction()); + editRegisterIdenticalMenuItem = createMenuItem(new EditRegisterIdenticalMenuItemAction()); + + lowerCaseMenuItem = createMenuItem(new LowerCaseMenuItemAction()); + upperCaseMenuItem = createMenuItem(new UpperCaseMenuItemAction()); + titleCaseMenuItem = createMenuItem(new TitleCaseMenuItemAction()); + sentenceCaseMenuItem = createMenuItem(new SentenceCaseMenuItemAction()); + cycleSwitchCaseMenuItem = createMenuItem(new CycleSwitchCaseMenuItemAction()); + + gotoNextUntranslatedMenuItem = createMenuItem(new GotoNextUntranslatedMenuItemAction()); + gotoNextTranslatedMenuItem = createMenuItem(new GotoNextTranslatedMenuItemAction()); + gotoNextSegmentMenuItem = createMenuItem(new GotoNextSegmentMenuItemAction()); + gotoPreviousSegmentMenuItem = createMenuItem(new GotoPreviousSegmentMenuItemAction()); + gotoSegmentMenuItem = createMenuItem(new GotoSegmentMenuItemAction()); + gotoNextNoteMenuItem = createMenuItem(new GotoNextNoteMenuItemAction()); + gotoPreviousNoteMenuItem = createMenuItem(new GotoPreviousNoteMenuItemAction()); + gotoNextUniqueMenuItem = createMenuItem(new GotoNextUniqueMenuItemAction()); + gotoMatchSourceSegment = createMenuItem(new GotoMatchSourceSegmentAction()); gotoXEntrySubmenu = createMenu("TF_MENU_GOTO_X_SUBMENU"); - gotoNextXAutoMenuItem = createMenuItem("TF_MENU_GOTO_NEXT_XAUTO"); - gotoPrevXAutoMenuItem = createMenuItem("TF_MENU_GOTO_PREV_XAUTO"); - gotoNextXEnforcedMenuItem = createMenuItem("TF_MENU_GOTO_NEXT_XENFORCED"); - gotoPrevXEnforcedMenuItem = createMenuItem("TF_MENU_GOTO_PREV_XENFORCED"); + gotoNextXAutoMenuItem = createMenuItem(new GotoNextXAutoMenuItemAction()); + gotoPrevXAutoMenuItem = createMenuItem(new GotoPrevXAutoMenuItemAction()); + gotoNextXEnforcedMenuItem = createMenuItem(new GotoNextXEnforcedMenuItemAction()); + gotoPrevXEnforcedMenuItem = createMenuItem(new GotoPrevXEnforcedMenuItemAction()); - gotoHistoryBackMenuItem = createMenuItem("TF_MENU_GOTO_BACK_IN_HISTORY"); - gotoHistoryForwardMenuItem = createMenuItem("TF_MENU_GOTO_FORWARD_IN_HISTORY"); - gotoNotesPanelMenuItem = createMenuItem("TF_MENU_GOTO_NOTES_PANEL"); - gotoEditorPanelMenuItem = createMenuItem("TF_MENU_GOTO_EDITOR_PANEL"); + gotoHistoryBackMenuItem = createMenuItem(new GotoHistoryBackMenuItemAction()); + gotoHistoryForwardMenuItem = createMenuItem(new GotoHistoryForwardMenuItemAction()); + gotoNotesPanelMenuItem = createMenuItem(new GotoNotesPanelMenuItemAction()); + gotoEditorPanelMenuItem = createMenuItem(new GotoEditorPanelMenuItemAction()); viewMarkTranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( - "TF_MENU_DISPLAY_MARK_TRANSLATED"); + new ViewMarkTranslatedSegmentsCheckBoxMenuItemAction()); viewMarkUntranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( - "TF_MENU_DISPLAY_MARK_UNTRANSLATED"); - viewMarkParagraphStartCheckBoxMenuItem = createCheckboxMenuItem("TF_MENU_DISPLAY_MARK_PARAGRAPH"); + new ViewMarkUntranslatedSegmentsCheckBoxMenuItemAction()); + viewMarkParagraphStartCheckBoxMenuItem = createCheckboxMenuItem( + new ViewMarkParagraphStartCheckBoxMenuItemAction()); viewDisplaySegmentSourceCheckBoxMenuItem = createCheckboxMenuItem( - "MW_VIEW_MENU_DISPLAY_SEGMENT_SOURCES"); + new ViewDisplaySegmentSourceCheckBoxMenuItemAction()); viewMarkNonUniqueSegmentsCheckBoxMenuItem = createCheckboxMenuItem( - "MW_VIEW_MENU_MARK_NON_UNIQUE_SEGMENTS"); - viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NOTED_SEGMENTS"); - viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NBSP"); - viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_WHITESPACE"); - viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_BIDI"); - viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_AUTOPOPULATED"); - viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_GLOSSARY_MARK"); - viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItem("LT_OPTIONS_MENU_ENABLED"); - viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_FONT_FALLBACK"); - viewModificationInfoMenu = createMenu("MW_VIEW_MENU_MODIFICATION_INFO"); + new ViewMarkNonUniqueSegmentsCheckBoxMenuItemAction()); + viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( + new ViewMarkNotedSegmentsCheckBoxMenuItemAction()); + viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItem(new ViewMarkNBSPCheckBoxMenuItemAction()); + viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItem(new ViewMarkWhitespaceCheckBoxMenuItemAction()); + viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItem(new ViewMarkBidiCheckBoxMenuItemAction()); + viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItem( + new ViewMarkAutoPopulatedCheckBoxMenuItemAction()); + viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItem( + new ViewMarkGlossaryMatchesCheckBoxMenuItemAction()); + viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItem( + new ViewMarkLanguageCheckerCheckBoxMenuItemAction()); + viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItem( + new ViewMarkFontFallbackCheckBoxMenuItemAction()); + viewModificationInfoMenu = createMenu("MW_VIEW_MENU_MODIFICATION_INFO"); + viewModificationInfoMenu.setIcon(MainMenuIcons.newBlankIcon()); ButtonGroup viewModificationInfoMenuBG = new ButtonGroup(); viewDisplayModificationInfoNoneRadioButtonMenuItem = createRadioButtonMenuItem( - "MW_VIEW_MENU_MODIFICATION_INFO_NONE", viewModificationInfoMenuBG); + new ViewDisplayModificationInfoNoneRadioButtonMenuItemAction(), viewModificationInfoMenuBG); viewDisplayModificationInfoSelectedRadioButtonMenuItem = createRadioButtonMenuItem( - "MW_VIEW_MENU_MODIFICATION_INFO_SELECTED", viewModificationInfoMenuBG); + new ViewDisplayModificationInfoSelectedRadioButtonMenuItemAction(), viewModificationInfoMenuBG); viewDisplayModificationInfoAllRadioButtonMenuItem = createRadioButtonMenuItem( - "MW_VIEW_MENU_MODIFICATION_INFO_ALL", viewModificationInfoMenuBG); + new ViewDisplayModificationInfoAllRadioButtonMenuItemAction(), viewModificationInfoMenuBG); + viewRestoreGUIMenuItem = createMenuItem(new ViewRestoreGUIMenuItemAction()); - viewMarkUntranslatedSegmentsCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_UNTRANSLATED.getColor())); - viewMarkParagraphStartCheckBoxMenuItem.setIcon( - MainMenuIcons.newTextIcon(Styles.EditorColor.COLOR_PARAGRAPH_START.getColor(), '\u00b6')); - viewDisplaySegmentSourceCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_SOURCE.getColor())); - viewMarkNonUniqueSegmentsCheckBoxMenuItem - .setIcon(MainMenuIcons.newTextIcon(Styles.EditorColor.COLOR_NON_UNIQUE.getColor(), 'M')); - viewMarkNotedSegmentsCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_NOTED.getColor())); - viewMarkNBSPCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_NBSP.getColor())); - viewMarkWhitespaceCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_WHITESPACE.getColor())); - viewMarkBidiCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_BIDIMARKERS.getColor())); - viewModificationInfoMenu.setIcon(MainMenuIcons.newBlankIcon()); - viewMarkAutoPopulatedCheckBoxMenuItem.setIcon( - MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_MARK_COMES_FROM_TM_XAUTO.getColor())); - viewMarkGlossaryMatchesCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_TRANSTIPS.getColor())); - viewMarkLanguageCheckerCheckBoxMenuItem - .setIcon(MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_LANGUAGE_TOOLS.getColor())); - viewMarkFontFallbackCheckBoxMenuItem.setIcon(MainMenuIcons.newTextIcon( - UIManager.getColor("Label.foreground"), new Font("Serif", Font.ITALIC, 16), 'F')); - - viewRestoreGUIMenuItem = createMenuItem("MW_OPTIONSMENU_RESTORE_GUI"); - - toolsCheckIssuesMenuItem = createMenuItem("TF_MENU_TOOLS_CHECK_ISSUES"); - toolsCheckIssuesCurrentFileMenuItem = createMenuItem("TF_MENU_TOOLS_CHECK_ISSUES_CURRENT_FILE"); - toolsShowStatisticsStandardMenuItem = createMenuItem("TF_MENU_TOOLS_STATISTICS_STANDARD"); - toolsShowStatisticsMatchesMenuItem = createMenuItem("TF_MENU_TOOLS_STATISTICS_MATCHES"); + toolsCheckIssuesMenuItem = createMenuItem(new ToolsCheckIssuesMenuItemAction()); + toolsCheckIssuesCurrentFileMenuItem = createMenuItem(new ToolsCheckIssuesCurrentFileMenuItemAction()); + toolsShowStatisticsStandardMenuItem = createMenuItem(new ToolsShowStatisticsStandardMenuItemAction()); + toolsShowStatisticsMatchesMenuItem = createMenuItem(new ToolsShowStatisticsMatchesMenuItemAction()); toolsShowStatisticsMatchesPerFileMenuItem = createMenuItem( - "TF_MENU_TOOLS_STATISTICS_MATCHES_PER_FILE"); - optionsPreferencesMenuItem = createMenuItem("MW_OPTIONSMENU_PREFERENCES"); + new ToolsShowStatisticsMatchesPerFileMenuItemAction()); + + optionsPreferencesMenuItem = createMenuItem(new OptionsPreferencesMenuItemAction()); optionsMachineTranslateMenu = createMenu("TF_OPTIONSMENU_MACHINETRANSLATE"); - optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItem("MT_AUTO_FETCH"); + optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItem(new OptionsMTAutoFetchCheckboxMenuItemAction()); optionsGlossaryMenu = createMenu("TF_OPTIONSMENU_GLOSSARY"); optionsGlossaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem( - "TF_OPTIONSMENU_GLOSSARY_FUZZY"); + new OptionsGlossaryFuzzyMatchingCheckBoxMenuItemAction()); optionsDictionaryMenu = createMenu("TF_OPTIONSMENU_DICTIONARY"); optionsDictionaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem( - "TF_OPTIONSMENU_DICTIONARY_FUZZY"); + new OptionsDictionaryFuzzyMatchingCheckBoxMenuItemAction()); optionsAutoCompleteMenu = createMenu("MW_OPTIONSMENU_AUTOCOMPLETE"); // add any autocomplete view configuration menu items below optionsAutoCompleteShowAutomaticallyItem = createCheckboxMenuItem( - "MW_OPTIONSMENU_AUTOCOMPLETE_SHOW_AUTOMATICALLY"); + new OptionsAutoCompleteShowAutomaticallyItemAction()); optionsAutoCompleteHistoryCompletionMenuItem = createCheckboxMenuItem( - "MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_COMPLETION"); + new OptionsAutoCompleteHistoryCompletionMenuItemAction()); optionsAutoCompleteHistoryPredictionMenuItem = createCheckboxMenuItem( - "MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_PREDICTION"); - optionsSetupFileFiltersMenuItem = createMenuItem("TF_MENU_DISPLAY_GLOBAL_FILTERS"); - optionsSentsegMenuItem = createMenuItem("MW_OPTIONSMENU_GLOBAL_SENTSEG"); - optionsWorkflowMenuItem = createMenuItem("MW_OPTIONSMENU_WORKFLOW"); - optionsAccessConfigDirMenuItem = createMenuItem("MW_OPTIONSMENU_ACCESS_CONFIG_DIR"); - - helpContentsMenuItem = createMenuItem("TF_MENU_HELP_CONTENTS"); - helpAboutMenuItem = createMenuItem("TF_MENU_HELP_ABOUT"); - helpAboutMenuItem.setName(HELP_ABOUT_MENUITEM); - helpLastChangesMenuItem = createMenuItem("TF_MENU_HELP_LAST_CHANGES"); - helpLogMenuItem = createMenuItem("TF_MENU_HELP_LOG"); - helpUpdateCheckMenuItem = createMenuItem("TF_MENU_HELP_CHECK_FOR_UPDATES"); - + new OptionsAutoCompleteHistoryPredictionMenuItemAction()); + + optionsSetupFileFiltersMenuItem = createMenuItem(new OptionsSetupFileFiltersMenuItemAction()); + optionsSentsegMenuItem = createMenuItem(new OptionsSentsegMenuItemAction()); + optionsWorkflowMenuItem = createMenuItem(new OptionsWorkflowMenuItemAction()); + optionsAccessConfigDirMenuItem = createMenuItem(new OptionsAccessConfigDirMenuItemAction()); + + helpContentsMenuItem = createMenuItem(new HelpContentsMenuItemAction()); + helpAboutMenuItem = createMenuItem(new HelpAboutMenuItemAction()); + helpLastChangesMenuItem = createMenuItem(new HelpLastChangesMenuItemAction()); + helpLogMenuItem = createMenuItem(new HelpLogMenuItemAction()); + helpUpdateCheckMenuItem = createMenuItem(new HelpUpdateCheckMenuItemAction()); } protected void constructMenu() { @@ -656,17 +573,6 @@ public void menuCanceled(MenuEvent e) { } }); - String key = "findInProjectReuseLastWindow"; - KeyStroke stroke = PropertiesShortcuts.getMainMenuShortcuts().getKeyStroke(key); - mainWindow.getApplicationFrame().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key); - mainWindow.getApplicationFrame().getRootPane().getActionMap().put(key, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - Log.logInfoRB("LOG_MENU_CLICK", key); - mainWindowMenuHandler.findInProjectReuseLastWindow(); - } - }); - if (Platform.isMacOSX()) { initMacSpecific(); } @@ -702,32 +608,10 @@ public void onApplicationShutdown() { * @param modifiers * Modifier key flags (can be zero) */ + @Deprecated @Override public void invokeAction(String action, int modifiers) { - // Find method by item name. - String methodName = action + "ActionPerformed"; - Method method = null; - try { - method = mainWindowMenuHandler.getClass().getMethod(methodName); - } catch (NoSuchMethodException ignore) { - try { - method = mainWindowMenuHandler.getClass().getMethod(methodName, Integer.TYPE); - } catch (NoSuchMethodException ex) { - throw new IncompatibleClassChangeError( - "Error invoke method handler for main menu: there is no method " + methodName); - } - } - - // Call ...MenuItemActionPerformed method. - Object[] args = method.getParameterTypes().length == 0 ? null : new Object[] { modifiers }; - try { - method.invoke(mainWindowMenuHandler, args); - } catch (IllegalAccessException ex) { - throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); - } catch (InvocationTargetException ex) { - LOGGER.log(Level.SEVERE, "Error execute method", ex); - throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); - } + throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); } /** @@ -744,6 +628,7 @@ protected JMenu createMenu(String titleKey) { protected JMenu createMenu(String titleKey, MenuExtender.MenuKey menuKey) { JMenu result = new JMenu(); Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); + result.setName(titleKey); result.addMenuListener(this); if (menuKey != null) { menus.put(menuKey, result); @@ -754,14 +639,29 @@ protected JMenu createMenu(String titleKey, MenuExtender.MenuKey menuKey) { /** * Create menu item instance and set title. * - * @param titleKey - * title name key in resource bundle + * @param action + * corresponding action * @return menu item instance */ - protected JMenuItem createMenuItem(String titleKey) { + protected JMenuItem createMenuItem(Action action) { + JMenuItem item = new JMenuItem(); + item.setAction(action); + item.setIcon(null); + item.setName(action.getValue(Action.ACTION_COMMAND_KEY).toString()); + return item; + } + + @Deprecated + protected JMenuItem createMenuItem(String titleKey, String name) { JMenuItem result = new JMenuItem(); + result.setName(name); Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); - result.addActionListener(this); + return result; + } + + protected JCheckBoxMenuItem createCheckboxMenuItem(Action action) { + JCheckBoxMenuItem result = new JCheckBoxMenuItem(); + result.setAction(action); return result; } @@ -772,10 +672,18 @@ protected JMenuItem createMenuItem(String titleKey) { * title name key in resource bundle * @return menu item instance */ + @Deprecated protected JCheckBoxMenuItem createCheckboxMenuItem(final String titleKey) { JCheckBoxMenuItem result = new JCheckBoxMenuItem(); Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); - result.addActionListener(this); + return result; + } + + protected JRadioButtonMenuItem createRadioButtonMenuItem(Action action, ButtonGroup buttonGroup) { + JRadioButtonMenuItem result = new JRadioButtonMenuItem(); + result.setAction(action); + result.setIcon(null); + buttonGroup.add(result); return result; } @@ -786,18 +694,18 @@ protected JCheckBoxMenuItem createCheckboxMenuItem(final String titleKey) { * title name key in resource bundle * @return menu item instance */ - protected JRadioButtonMenuItem createRadioButtonMenuItem(final String titleKey, ButtonGroup buttonGroup) { + @Deprecated + protected JRadioButtonMenuItem createRadioButtonMenuItem(String titleKey, ButtonGroup buttonGroup) { JRadioButtonMenuItem result = new JRadioButtonMenuItem(); Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); - result.addActionListener(this); buttonGroup.add(result); return result; } /** - * Set 'actionCommand' for all menu items. TODO: change to key from resource - * bundle values + * Set 'actionCommand' for all menu items. bundle values */ + @Deprecated protected void setActionCommands() { try { for (Field f : StaticUtils.getAllModelFields(this.getClass())) { @@ -933,10 +841,9 @@ protected void updateCheckboxesOnStart() { protected void initMacSpecific() { try { // MacOSX-specific - OSXIntegration.setQuitHandler(e -> mainWindowMenuHandler.projectExitMenuItemActionPerformed()); - OSXIntegration.setAboutHandler(e -> mainWindowMenuHandler.helpAboutMenuItemActionPerformed()); - OSXIntegration.setPreferencesHandler( - e -> mainWindowMenuHandler.optionsPreferencesMenuItemActionPerformed()); + OSXIntegration.setQuitHandler(new ProjectExitMenuItemAction()); + OSXIntegration.setAboutHandler(new HelpAboutMenuItemAction()); + OSXIntegration.setPreferencesHandler(new OptionsPreferencesMenuItemAction()); } catch (NoClassDefFoundError e) { Log.log(e); } diff --git a/src/org/omegat/gui/main/BaseMainWindowMenuHandler.java b/src/org/omegat/gui/main/BaseMainWindowMenuHandler.java deleted file mode 100644 index 305d2f1410..0000000000 --- a/src/org/omegat/gui/main/BaseMainWindowMenuHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, Henry Pijffers, - Benjamin Siband, and Kim Bruning - 2007 Zoltan Bartko - 2008 Andrzej Sawula, Alex Buloichik - 2009 Didier Briel, Alex Buloichik - 2010 Wildrich Fourie, Didier Briel - 2012 Wildrich Fourie, Guido Leenders, Didier Briel - 2013 Zoltan Bartko, Didier Briel, Yu Tang - 2014 Aaron Madlon-Kay - 2015 Yu Tang, Aaron Madlon-Kay, Didier Briel - 2017 Didier Briel - 2019 Thomas Cordonnier - Home page: https://www.omegat.org/ - Support center: https://omegat.org/support - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - **************************************************************************/ -package org.omegat.gui.main; - -/** - * @author Hiroshi Miura - */ -public abstract class BaseMainWindowMenuHandler { - - /** - * Common base class for menu handler. - *

- * There should be a mandatory methods for mandatory - * commands. - */ - public BaseMainWindowMenuHandler() { - } - - public void projectExitMenuItemActionPerformed() { - System.exit(0); - } - - public void editFindInProjectMenuItemActionPerformed() { - } - - public void optionsPreferencesMenuItemActionPerformed() { - } - - public void projectNewMenuItemActionPerformed() { - } - - public void projectOpenMenuItemActionPerformed() { - } - - public void projectTeamNewMenuItemActionPerformed() { - } - - void findInProjectReuseLastWindow() { - } - - public void helpAboutMenuItemActionPerformed() { - } - -} diff --git a/src/org/omegat/gui/main/IMainMenu.java b/src/org/omegat/gui/main/IMainMenu.java index 793051dd28..878f77882b 100644 --- a/src/org/omegat/gui/main/IMainMenu.java +++ b/src/org/omegat/gui/main/IMainMenu.java @@ -55,5 +55,15 @@ public interface IMainMenu { JMenu getMenu(MenuExtender.MenuKey marker); - void invokeAction(String action, int modifiers); + /** + * Code for dispatching events from components to event handlers. + * + * @param action + * ActionCommand of triggering menu item + * @param modifiers + * Modifier key flags (can be zero) + */ + @Deprecated + default void invokeAction(String action, int modifiers) { + } } diff --git a/src/org/omegat/gui/main/MainWindow.java b/src/org/omegat/gui/main/MainWindow.java index f6d34a9082..4892aca865 100644 --- a/src/org/omegat/gui/main/MainWindow.java +++ b/src/org/omegat/gui/main/MainWindow.java @@ -33,6 +33,8 @@ package org.omegat.gui.main; +import static org.omegat.gui.main.ProjectUICommands.prepareForExit; + import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; @@ -44,22 +46,26 @@ import java.awt.Toolkit; import java.awt.Window; import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; +import javax.swing.AbstractAction; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; +import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; +import javax.swing.KeyStroke; import javax.swing.ScrollPaneConstants; import javax.swing.SwingUtilities; import javax.swing.Timer; @@ -75,6 +81,8 @@ import org.omegat.core.events.IProjectEventListener; import org.omegat.core.matching.NearString; import org.omegat.gui.matches.IMatcher; +import org.omegat.gui.shortcuts.PropertiesShortcuts; +import org.omegat.util.Log; import org.omegat.util.OStrings; import org.omegat.util.Preferences; import org.omegat.util.StaticUtils; @@ -178,30 +186,39 @@ public void onApplicationShutdown() { @SuppressWarnings("unchecked") private void initMainMenu() { - MainWindowMenuHandler mainWindowMenuHandler = new MainWindowMenuHandler(this); - // Load Menu extension Object menuClass = UIManager.get(UIDesignManager.menuClassID); if (menuClass != null) { BaseMainWindowMenu menu1; try { menu1 = ((Class) menuClass) - .getDeclaredConstructor(MainWindow.class, MainWindowMenuHandler.class) - .newInstance(this, mainWindowMenuHandler); + .getDeclaredConstructor() + .newInstance(); } catch (Exception e) { // fall back to default when loading failed. - menu1 = new MainWindowMenu(this, mainWindowMenuHandler); + menu1 = new MainWindowMenu(); } menu = menu1; } else { // Default menu. - menu = new MainWindowMenu(this, mainWindowMenuHandler); + menu = new MainWindowMenu(); } applicationFrame.setJMenuBar(menu.mainMenu); + final String key = "findInProjectReuseLastWindow"; + KeyStroke stroke = PropertiesShortcuts.getMainMenuShortcuts().getKeyStroke(key); + applicationFrame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, key); + applicationFrame.getRootPane().getActionMap().put(key, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", key); + ProjectUICommands.findInProjectReuseLastWindow(); + } + }); + applicationFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { - mainWindowMenuHandler.projectExitMenuItemActionPerformed(); + prepareForExit(() -> System.exit(0)); } @Override @@ -216,8 +233,8 @@ public void windowDeactivated(WindowEvent we) { try { applicationFrame.getContentPane() .add((Component) ((Class) toolbarClass) - .getDeclaredConstructor(MainWindow.class, MainWindowMenuHandler.class) - .newInstance(this, mainWindowMenuHandler), BorderLayout.NORTH); + .getDeclaredConstructor(IMainWindow.class) + .newInstance(this), BorderLayout.NORTH); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException ignored) { } diff --git a/src/org/omegat/gui/main/MainWindowBurgerMenu.java b/src/org/omegat/gui/main/MainWindowBurgerMenu.java index e0a7b3c750..7e542b3f41 100644 --- a/src/org/omegat/gui/main/MainWindowBurgerMenu.java +++ b/src/org/omegat/gui/main/MainWindowBurgerMenu.java @@ -25,14 +25,12 @@ package org.omegat.gui.main; -import java.awt.event.ActionListener; import java.util.Objects; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JMenu; import javax.swing.UIManager; -import javax.swing.event.MenuListener; import org.omegat.gui.accesstool.AccessTools; import org.omegat.util.gui.ResourcesUtil; @@ -43,13 +41,12 @@ * @author Hiroshi Miura */ @SuppressWarnings("unused") -public final class MainWindowBurgerMenu extends BaseMainWindowMenu - implements ActionListener, MenuListener, IMainMenu { +public final class MainWindowBurgerMenu extends BaseMainWindowMenu implements IMainMenu { JMenu burgerMenu; - public MainWindowBurgerMenu(MainWindow mainWindow, MainWindowMenuHandler mainWindowMenuHandler) { - super(mainWindow, mainWindowMenuHandler); + public MainWindowBurgerMenu(MainWindow mainWindow) { + super(); initComponents(); } @@ -69,6 +66,6 @@ void createMenuBar() { burgerMenu.add(helpMenu); burgerMenu.add(burgerMenu); mainMenu.add(burgerMenu); - mainMenu.add(new AccessTools(mainWindowMenuHandler)); + mainMenu.add(new AccessTools()); } } diff --git a/src/org/omegat/gui/main/MainWindowMenu.java b/src/org/omegat/gui/main/MainWindowMenu.java index 4a31bf4e1c..474646dd57 100644 --- a/src/org/omegat/gui/main/MainWindowMenu.java +++ b/src/org/omegat/gui/main/MainWindowMenu.java @@ -37,23 +37,22 @@ package org.omegat.gui.main; -import java.awt.event.ActionListener; - -import javax.swing.event.MenuListener; - /** * Class for classic main menu. * * @author Hiroshi Miura */ -public final class MainWindowMenu extends BaseMainWindowMenu - implements ActionListener, MenuListener, IMainMenu { +public final class MainWindowMenu extends BaseMainWindowMenu implements IMainMenu { - public MainWindowMenu(final MainWindow mainWindow, final MainWindowMenuHandler mainWindowMenuHandler) { - super(mainWindow, mainWindowMenuHandler); + public MainWindowMenu() { initComponents(); } + @Deprecated + public MainWindowMenu(MainWindow mainWindow) { + this(); + } + @Override void createMenuBar() { mainMenu.add(projectMenu); diff --git a/src/org/omegat/gui/main/MainWindowMenuHandler.java b/src/org/omegat/gui/main/MainWindowMenuHandler.java index 5bc5d721c7..09f39ac9f7 100644 --- a/src/org/omegat/gui/main/MainWindowMenuHandler.java +++ b/src/org/omegat/gui/main/MainWindowMenuHandler.java @@ -15,6 +15,7 @@ 2015 Yu Tang, Aaron Madlon-Kay, Didier Briel 2017 Didier Briel 2019 Thomas Cordonnier + 2024 Hiroshi Miura Home page: https://www.omegat.org/ Support center: https://omegat.org/support @@ -37,30 +38,30 @@ package org.omegat.gui.main; import java.awt.Component; +import java.awt.Font; import java.awt.KeyboardFocusManager; import java.awt.event.ActionEvent; import java.io.File; import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; +import javax.swing.Action; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFrame; import javax.swing.JOptionPane; -import javax.swing.SwingWorker; -import javax.swing.text.JTextComponent; +import javax.swing.UIManager; + +import org.openide.awt.AbstractMnemonicsAction; import org.omegat.Main; import org.omegat.core.Core; -import org.omegat.core.CoreEvents; -import org.omegat.core.KnownException; -import org.omegat.core.data.ProjectFactory; -import org.omegat.core.data.ProjectTMX; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.TMXEntry; import org.omegat.core.matching.NearString; import org.omegat.core.matching.NearString.MATCH_SOURCE; import org.omegat.core.search.SearchMode; -import org.omegat.core.spellchecker.ISpellChecker; import org.omegat.core.tagvalidation.ErrorReport; -import org.omegat.filters2.master.PluginUtils; import org.omegat.gui.dialogs.AboutDialog; import org.omegat.gui.dialogs.GoToSegmentDialog; import org.omegat.gui.dialogs.LastChangesDialog; @@ -77,6 +78,7 @@ import org.omegat.gui.preferences.PreferencesWindowController; import org.omegat.gui.preferences.view.EditingBehaviorController; import org.omegat.gui.segmentation.SegmentationCustomizerController; +import org.omegat.gui.shortcuts.PropertiesShortcuts; import org.omegat.gui.stat.StatisticsWindow; import org.omegat.help.Help; import org.omegat.util.Log; @@ -87,7 +89,8 @@ import org.omegat.util.StringUtil; import org.omegat.util.TagUtil; import org.omegat.util.TagUtil.Tag; -import org.omegat.util.gui.DesktopWrapper; +import org.omegat.util.gui.ResourcesUtil; +import org.omegat.util.gui.Styles; /** * Handler for main menu items. @@ -105,935 +108,2329 @@ * @author Yu Tang * @author Aaron Madlon-Kay */ -public final class MainWindowMenuHandler extends BaseMainWindowMenuHandler { - private static final String PROP_ORIGIN = ProjectTMX.PROP_ORIGIN; - - private final MainWindow mainWindow; +public final class MainWindowMenuHandler { - public MainWindowMenuHandler(final MainWindow mainWindow) { - this.mainWindow = mainWindow; + private MainWindowMenuHandler() { } /** - * Create new project. + * Create a new project. */ - public void projectNewMenuItemActionPerformed() { - ProjectUICommands.projectCreate(); + public static class ProjectNewMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectNewMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_CREATE"), OStrings.getLocale()); + final String key = "projectNewMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectCreate(); + } } /** - * Create new team project. + * Create a new team project. */ - public void projectTeamNewMenuItemActionPerformed() { - ProjectUICommands.projectTeamCreate(); + public static class ProjectTeamNewMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectTeamNewMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_TEAM_CREATE"), OStrings.getLocale()); + final String key = "projectTeamNewMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectTeamCreate(); + } } /** * Open project. */ - public void projectOpenMenuItemActionPerformed() { - ProjectUICommands.projectOpen(null); + public static class ProjectOpenMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectOpenMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_OPEN"), OStrings.getLocale()); + final String key = "projectOpenMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectOpen(null); + } } - public void projectClearRecentMenuItemActionPerformed() { - RecentProjects.clear(); + public static class ProjectClearRecentMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectClearRecentMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_CLEAR_RECENT"), OStrings.getLocale()); + final String key = "projectClearRecentMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + RecentProjects.clear(); + } } /** * Open MED project. */ - public void projectMedOpenMenuItemActionPerformed() { - ProjectUICommands.projectOpenMED(); + public static class ProjectMedOpenMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectMedOpenMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_MED_OPEN"), OStrings.getLocale()); + final String key = "projectMedOpenMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectOpenMED(); + } } /** * Create MED project. */ - public void projectMedCreateMenuItemActionPerformed() { - ProjectUICommands.projectCreateMED(); + public static class ProjectMedCreateMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectMedCreateMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_MED_CREATE"), OStrings.getLocale()); + final String key = "projectMedCreateMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectCreateMED(); + } } /** * Imports the file/files/folder into project's source files. */ - public void projectImportMenuItemActionPerformed() { - ProjectUICommands.doPromptImportSourceFiles(); + public static class ProjectImportMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectImportMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_IMPORT"), OStrings.getLocale()); + final String key = "projectImportMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.doPromptImportSourceFiles(); + } } - public void projectWikiImportMenuItemActionPerformed() { - ProjectUICommands.doWikiImport(); + public static class ProjectWikiImportMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectWikiImportMenuItemAction() { + super(OStrings.getString("TF_MENU_WIKI_IMPORT"), OStrings.getLocale()); + final String key = "projectWikiImportMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.doWikiImport(); + } } - public void projectReloadMenuItemActionPerformed() { - ProjectUICommands.projectReload(); + public static class ProjectReloadMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectReloadMenuItemAction() { + super(OStrings.getString("TF_MENU_PROJECT_RELOAD"), OStrings.getLocale()); + final String key = "projectReloadMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectReload(); + } } /** * Close project. */ - public void projectCloseMenuItemActionPerformed() { - ProjectUICommands.projectClose(); + public static class ProjectCloseMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectCloseMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_CLOSE"), OStrings.getLocale()); + final String key = "projectCloseMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectClose(); + } } /** * Save project. */ - public void projectSaveMenuItemActionPerformed() { - ProjectUICommands.projectSave(); + public static class ProjectSaveMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectSaveMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_SAVE"), OStrings.getLocale()); + final String key = "projectSaveMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectSave(); + } } /** * Create translated documents. */ - public void projectCompileMenuItemActionPerformed() { - if (!checkTags()) { - return; + public static class ProjectCompileMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectCompileMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_COMPILE"), OStrings.getLocale()); + final String key = "projectCompileMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - ProjectUICommands.projectCompile(); - } - - /** - * Check whether tags are OK - * @return false is there is a tag issue, true otherwise - */ - private boolean checkTags() { - if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { - List stes = Core.getTagValidation().listInvalidTags(); - if (!stes.isEmpty()) { - Core.getIssues().showAll(OStrings.getString("TF_MESSAGE_COMPILE")); - return false; + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (ProjectUICommands.IsTagsInvalid()) { + return; } + + ProjectUICommands.projectCompile(); } - return true; } - public void projectCommitTargetFilesActionPerformed() { - if (!checkTags()) { - return; + public static class ProjectCommitTargetFilesAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectCommitTargetFilesAction() { + super(OStrings.getString("TF_MENU_FILE_TARGET"), OStrings.getLocale()); + final String key = "projectCommitTargetFiles"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - ProjectUICommands.projectCompileAndCommit(); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (ProjectUICommands.IsTagsInvalid()) { + return; + } + ProjectUICommands.projectCompileAndCommit(); + } } /** * Commit source files */ - public void projectCommitSourceFilesActionPerformed() { - ProjectUICommands.projectCommitSourceFiles(); + public static class ProjectCommitSourceFilesAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectCommitSourceFilesAction() { + super(OStrings.getString("TF_MENU_FILE_COMMIT"), OStrings.getLocale()); + final String key = "projectCommitSourceFiles"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectCommitSourceFiles(); + } } /** * Create current translated document. */ - public void projectSingleCompileMenuItemActionPerformed() { - String midName = Core.getEditor().getCurrentFile(); - if (StringUtil.isEmpty(midName)) { - return; + public static class ProjectSingleCompileMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectSingleCompileMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_SINGLE_COMPILE"), OStrings.getLocale()); + final String key = "projectSingleCompileMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String sourcePattern = Pattern.quote(midName); - if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { - List stes = Core.getTagValidation().listInvalidTags(sourcePattern); - if (!stes.isEmpty()) { - Core.getIssues().showForFiles(midName, OStrings.getString("TF_MESSAGE_COMPILE")); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + String midName = Core.getEditor().getCurrentFile(); + if (StringUtil.isEmpty(midName)) { return; } - } - ProjectUICommands.projectSingleCompile(sourcePattern); + String sourcePattern = Pattern.quote(midName); + if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { + List stes = Core.getTagValidation().listInvalidTags(sourcePattern); + if (!stes.isEmpty()) { + Core.getIssues().showForFiles(midName, OStrings.getString("TF_MESSAGE_COMPILE")); + return; + } + } + + ProjectUICommands.projectSingleCompile(sourcePattern); + } } /** Edits project's properties */ - public void projectEditMenuItemActionPerformed() { - ProjectUICommands.projectEditProperties(); + public static class ProjectEditMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectEditMenuItemAction() { + super(OStrings.getString("MW_PROJECTMENU_EDIT"), OStrings.getLocale()); + final String key = "projectEditMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.projectEditProperties(); + } } - public void viewFileListMenuItemActionPerformed() { - IProjectFilesList projWin = Core.getProjectFilesList(); - if (projWin == null) { - mainWindow.menu.viewFileListMenuItem.setSelected(false); - return; + public static class ViewFileListMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewFileListMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_PROJWIN"), OStrings.getLocale()); + final String key = "viewFileListMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - projWin.setActive(!projWin.isActive()); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + IProjectFilesList projWin = Core.getProjectFilesList(); + if (projWin != null) { + projWin.setActive(!projWin.isActive()); + } + } } - public void projectAccessRootMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class ProjectAccessRootMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessRootMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_ROOT"), OStrings.getLocale()); + final String key = "projectAccessRootMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String path = Core.getProject().getProjectProperties().getProjectRoot(); - openFile(new File(path)); - } - public void projectAccessDictionaryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getProjectRoot(); + ProjectUICommands.openFile(new File(path)); + } - String path = Core.getProject().getProjectProperties().getDictRoot(); - openFile(new File(path)); } - public void projectAccessGlossaryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class ProjectAccessDictionaryMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessDictionaryMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_DICTIONARY"), OStrings.getLocale()); + final String key = "projectAccessDictionaryMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String path = Core.getProject().getProjectProperties().getGlossaryRoot(); - openFile(new File(path)); - } - public void projectAccessSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getDictRoot(); + ProjectUICommands.openFile(new File(path)); } - String path = Core.getProject().getProjectProperties().getSourceRoot(); - openFile(new File(path)); } - public void projectAccessTargetMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class ProjectAccessGlossaryMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessGlossaryMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_GLOSSARY"), OStrings.getLocale()); + final String key = "projectAccessGlossaryMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String path = Core.getProject().getProjectProperties().getTargetRoot(); - openFile(new File(path)); - } - public void projectAccessTMMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getGlossaryRoot(); + ProjectUICommands.openFile(new File(path)); } - String path = Core.getProject().getProjectProperties().getTMRoot(); - openFile(new File(path)); } - public void projectAccessExportTMMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class ProjectAccessSourceMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_SOURCE"), OStrings.getLocale()); + final String key = "projectAccessSourceMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String path = Core.getProject().getProjectProperties().getExportTMRoot(); - openFile(new File(path)); - } - public void projectAccessCurrentSourceDocumentMenuItemActionPerformed(int modifier) { - if (!Core.getProject().isProjectLoaded()) { - return; + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getSourceRoot(); + ProjectUICommands.openFile(new File(path)); } - String root = Core.getProject().getProjectProperties().getSourceRoot(); - String path = Core.getEditor().getCurrentFile(); - if (StringUtil.isEmpty(path)) { - return; + } + + public static class ProjectAccessTargetMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessTargetMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_TARGET"), OStrings.getLocale()); + final String key = "projectAccessTargetMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - File toOpen = new File(root, path); - if ((modifier & ActionEvent.ALT_MASK) != 0) { - toOpen = toOpen.getParentFile(); + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getTargetRoot(); + ProjectUICommands.openFile(new File(path)); } - openFile(toOpen); } - public void projectAccessCurrentTargetDocumentMenuItemActionPerformed(int modifier) { - if (!Core.getProject().isProjectLoaded()) { - return; - } - String root = Core.getProject().getProjectProperties().getTargetRoot(); - String path = Core.getEditor().getCurrentTargetFile(); - if (StringUtil.isEmpty(path)) { - return; + public static class ProjectAccessTMMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessTMMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_TM"), OStrings.getLocale()); + final String key = "projectAccessTMMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - File toOpen = new File(root, path); - if ((modifier & ActionEvent.ALT_MASK) != 0) { - toOpen = toOpen.getParentFile(); + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getTMRoot(); + ProjectUICommands.openFile(new File(path)); } - openFile(toOpen); } - public void projectAccessWriteableGlossaryMenuItemActionPerformed(int modifier) { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class ProjectAccessExportTMMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessExportTMMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_EXPORT_TM"), OStrings.getLocale()); + final String key = "projectAccessExportTMMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String path = Core.getProject().getProjectProperties().getWriteableGlossary(); - if (StringUtil.isEmpty(path)) { - return; - } - File toOpen = new File(path); - if ((modifier & ActionEvent.ALT_MASK) != 0) { - toOpen = toOpen.getParentFile(); + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getExportTMRoot(); + ProjectUICommands.openFile(new File(path)); } - openFile(toOpen); } - private void openFile(File path) { - try { - path = path.getCanonicalFile(); // Normalize file name in case it is displayed - } catch (Exception ex) { - // Ignore + public static class ProjectAccessCurrentSourceDocumentMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessCurrentSourceDocumentMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_CURRENT_SOURCE_DOCUMENT"), OStrings.getLocale()); + final String key = "projectAccessCurrentSourceDocumentMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - if (!path.exists()) { - Core.getMainWindow().showStatusMessageRB("LFC_ERROR_FILE_DOESNT_EXIST", path); - return; - } - try { - DesktopWrapper.open(path); - } catch (Exception ex) { - Log.logErrorRB(ex, "RPF_ERROR"); - Core.getMainWindow().displayErrorRB(ex, "RPF_ERROR"); + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String root = Core.getProject().getProjectProperties().getSourceRoot(); + String path = Core.getEditor().getCurrentFile(); + if (StringUtil.isEmpty(path)) { + return; + } + File toOpen = new File(root, path); + int modifier = e.getModifiers(); + if ((modifier & ActionEvent.ALT_MASK) != 0) { + toOpen = toOpen.getParentFile(); + } + ProjectUICommands.openFile(toOpen); } } - /** Quits OmegaT */ - public void projectExitMenuItemActionPerformed() { - prepareForExit(() -> System.exit(0)); - } + public static class ProjectAccessCurrentTargetDocumentMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessCurrentTargetDocumentMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_CURRENT_TARGET_DOCUMENT"), OStrings.getLocale()); + final String key = "projectAccessCurrentTargetDocumentMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } - /** Restart OmegaT */ - public void projectRestartMenuItemActionPerformed() { - String projectDir = Core.getProject().isProjectLoaded() - ? Core.getProject().getProjectProperties().getProjectRoot() - : null; - prepareForExit(() -> { - Main.restartGUI(projectDir); - }); - } - - protected void prepareForExit(Runnable onCompletion) { - // Bug #902: commit the current entry first - // We do it before checking project status, so that it can eventually change it - if (Core.getProject().isProjectLoaded()) { - Core.getEditor().commitAndLeave(); - } - - boolean projectModified = false; - if (Core.getProject().isProjectLoaded()) { - projectModified = Core.getProject().isProjectModified(); - } - // RFE 1302358 - // Add Yes/No Warning before OmegaT quits - if (projectModified || Preferences.isPreference(Preferences.ALWAYS_CONFIRM_QUIT)) { - if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(mainWindow.getApplicationFrame(), - OStrings.getString("MW_QUIT_CONFIRM"), OStrings.getString("CONFIRM_DIALOG_TITLE"), - JOptionPane.YES_NO_OPTION)) { + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String root = Core.getProject().getProjectProperties().getTargetRoot(); + String path = Core.getEditor().getCurrentTargetFile(); + if (StringUtil.isEmpty(path)) { return; } + File toOpen = new File(root, path); + int modifier = e.getModifiers(); + if ((modifier & ActionEvent.ALT_MASK) != 0) { + toOpen = toOpen.getParentFile(); + } + ProjectUICommands.openFile(toOpen); } + } - SegmentExportImport.flushExportedSegments(); - - new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - if (Core.getProject().isProjectLoaded()) { - // Save the list of learned and ignore words - ISpellChecker sc = Core.getSpellChecker(); - sc.saveWordLists(); - try { - Core.executeExclusively(true, () -> { - Core.getProject().saveProject(true); - ProjectFactory.closeProject(); - }); - } catch (KnownException ex) { - // hide exception on shutdown - } - } + public static class ProjectAccessWriteableGlossaryMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectAccessWriteableGlossaryMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_WRITEABLE_GLOSSARY"), OStrings.getLocale()); + final String key = "projectAccessWriteableGlossaryMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } - CoreEvents.fireApplicationShutdown(); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + int modifier = e.getModifiers(); + ProjectUICommands.openWritableGlossaryFile((modifier & ActionEvent.ALT_MASK) != modifier); + } + } - PluginUtils.unloadPlugins(); + /** Quits OmegaT */ + public static class ProjectExitMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectExitMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_QUIT"), OStrings.getLocale()); + final String key = "projectExitMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } - return null; - } + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.prepareForExit(() -> System.exit(0)); + } + } - @Override - protected void done() { - try { - get(); + /** Restart OmegaT */ + public static class ProjectRestartMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ProjectRestartMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_RESTART"), OStrings.getLocale()); + final String key = "projectRestartMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } - MainWindowUI.saveScreenLayout(mainWindow); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + String projectDir = Core.getProject().isProjectLoaded() + ? Core.getProject().getProjectProperties().getProjectRoot() + : null; + ProjectUICommands.prepareForExit(() -> { + Main.restartGUI(projectDir); + }); + } + } - Preferences.save(); + public static class EditUndoMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditUndoMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_UNDO"), OStrings.getLocale()); + final String key = "editUndoMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } - onCompletion.run(); - } catch (Exception ex) { - Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); - Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); - } + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (focused == Core.getNotes()) { + Core.getNotes().undo(); + } else { + Core.getEditor().undo(); } - }.execute(); + } } - public void editUndoMenuItemActionPerformed() { - Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (focused == Core.getNotes()) { - Core.getNotes().undo(); - } else { - Core.getEditor().undo(); + /** Quits OmegaT */ + public static class EditRedoMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditRedoMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_REDO"), OStrings.getLocale()); + final String key = "editRedoMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - } - public void editRedoMenuItemActionPerformed() { - Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (focused == Core.getNotes()) { - Core.getNotes().redo(); - } else { - Core.getEditor().redo(); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (focused == Core.getNotes()) { + Core.getNotes().redo(); + } else { + Core.getEditor().redo(); + } } } - public void editOverwriteTranslationMenuItemActionPerformed() { - MainWindow.doRecycleTrans(); + public static class EditOverwriteTranslationMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditOverwriteTranslationMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_RECYCLE"), OStrings.getLocale()); + final String key = "editOverwriteTranslationMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + MainWindow.doRecycleTrans(); + } } - public void editInsertTranslationMenuItemActionPerformed() { - MainWindow.doInsertTrans(); + public static class EditInsertTranslationMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditInsertTranslationMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT"), OStrings.getLocale()); + final String key = "editInsertTranslationMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + MainWindow.doInsertTrans(); + } } - public void editOverwriteMachineTranslationMenuItemActionPerformed() { - MachineTranslationInfo tr = Core.getMachineTranslatePane().getDisplayedTranslation(); - if (tr == null) { - Core.getMachineTranslatePane().forceLoad(); - } else if (!StringUtil.isEmpty(tr.result)) { - Core.getEditor().replaceEditText(tr.result, String.format("MT:[%s]", tr.translatorName)); + public static class EditOverwriteMachineTranslationMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditOverwriteMachineTranslationMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_OVERWRITE_MACHITE_TRANSLATION"), OStrings.getLocale()); + final String key = "editOverwriteMachineTranslationMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + MachineTranslationInfo tr = Core.getMachineTranslatePane().getDisplayedTranslation(); + if (tr == null) { + Core.getMachineTranslatePane().forceLoad(); + } else if (!StringUtil.isEmpty(tr.result)) { + Core.getEditor().replaceEditText(tr.result, String.format("MT:[%s]", tr.translatorName)); + } } } /** - * replaces entire edited segment text with a the source text of a segment at cursor position + * replaces entire edited segment text with a the source text of a segment + * at cursor position */ - public void editOverwriteSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditOverwriteSourceMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditOverwriteSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SOURCE_OVERWRITE"), OStrings.getLocale()); + final String key = "editOverwriteSourceMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); - if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { - toInsert = EditorUtils.replaceGlossaryEntries(toInsert); + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); + if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { + toInsert = EditorUtils.replaceGlossaryEntries(toInsert); + } + Core.getEditor().replaceEditText(toInsert); } - Core.getEditor().replaceEditText(toInsert); } /** inserts the source text of a segment at cursor position */ - public void editInsertSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditInsertSourceMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditInsertSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SOURCE_INSERT"), OStrings.getLocale()); + final String key = "editInsertSourceMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); - if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { - toInsert = EditorUtils.replaceGlossaryEntries(toInsert); + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); + if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { + toInsert = EditorUtils.replaceGlossaryEntries(toInsert); + } + Core.getEditor().insertText(toInsert); } - Core.getEditor().insertText(toInsert); } /** select the source text of the current segment */ - public void editSelectSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditSelectSourceMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SOURCE_SELECT"), OStrings.getLocale()); + final String key = "editSelectSourceMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + Core.getEditor().selectSourceText(); } - Core.getEditor().selectSourceText(); } - public void editExportSelectionMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditExportSelectionMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditExportSelectionMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_EXPORT_SELECTION"), OStrings.getLocale()); + final String key = "editExportSelectionMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String selection = Core.getEditor().getSelectedText(); - if (selection == null) { - SourceTextEntry ste = Core.getEditor().getCurrentEntry(); - TMXEntry te = Core.getProject().getTranslationInfo(ste); - if (te.isTranslated()) { - selection = te.translation; - } else { - selection = ste.getSrcText(); + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String selection = Core.getEditor().getSelectedText(); + if (selection == null) { + SourceTextEntry ste = Core.getEditor().getCurrentEntry(); + TMXEntry te = Core.getProject().getTranslationInfo(ste); + if (te.isTranslated()) { + selection = te.translation; + } else { + selection = ste.getSrcText(); + } } + SegmentExportImport.exportCurrentSelection(selection); } - SegmentExportImport.exportCurrentSelection(selection); } - public void editSearchDictionaryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditSearchDictionaryMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSearchDictionaryMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SEARCH_DICTIONARY"), OStrings.getLocale()); + final String key = "editSearchDictionaryMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String selection = Core.getEditor().getSelectedText(); - if (selection == null) { - SourceTextEntry ste = Core.getEditor().getCurrentEntry(); - selection = ste.getSrcText(); + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String selection = Core.getEditor().getSelectedText(); + if (selection == null) { + SourceTextEntry ste = Core.getEditor().getCurrentEntry(); + selection = ste.getSrcText(); + } + Core.getDictionaries().searchText(selection); } - Core.getDictionaries().searchText(selection); } - public void editCreateGlossaryEntryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditCreateGlossaryEntryMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + private final JFrame parent; + public EditCreateGlossaryEntryMenuItemAction() { + this(null); } - Core.getGlossary().showCreateGlossaryEntryDialog(Core.getMainWindow().getApplicationFrame()); - } - public void editFindInProjectMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public EditCreateGlossaryEntryMenuItemAction(JFrame parent) { + super(OStrings.getString("TF_MENU_EDIT_CREATE_GLOSSARY_ENTRY"), OStrings.getLocale()); + this.parent = parent; + final String key = "editCreateGlossaryEntryMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + if (parent != null) { + Core.getGlossary().showCreateGlossaryEntryDialog(parent); + } else { + Core.getGlossary().showCreateGlossaryEntryDialog(Core.getMainWindow().getApplicationFrame()); + } } - MainWindowUI.createSearchWindow(SearchMode.SEARCH, getTrimmedSelectedTextInMainWindow()); } - void findInProjectReuseLastWindow() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditFindInProjectMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditFindInProjectMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_FIND"), OStrings.getLocale()); + final String key = "editFindInProjectMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.SMALL_ICON, Objects.requireNonNullElseGet( + UIManager.getIcon("OmegaT.newUI.search.icon"), + () -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.search.png")))); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - String text = getTrimmedSelectedTextInMainWindow(); - if (!MainWindowUI.reuseSearchWindow(text)) { - MainWindowUI.createSearchWindow(SearchMode.SEARCH, text); + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; + } + MainWindowUI.createSearchWindow(SearchMode.SEARCH, ProjectUICommands.getTrimmedSelectedTextInMainWindow()); } - editFindInProjectMenuItemActionPerformed(); } - public void editReplaceInProjectMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + public static class EditReplaceInProjectMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditReplaceInProjectMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_REPLACE"), OStrings.getLocale()); + final String key = "editReplaceInProjectMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); } - MainWindowUI.createSearchWindow(SearchMode.REPLACE, getTrimmedSelectedTextInMainWindow()); - } - private String getTrimmedSelectedTextInMainWindow() { - String selection = null; - Component component = mainWindow.getApplicationFrame().getMostRecentFocusOwner(); - if (component instanceof JTextComponent) { - selection = ((JTextComponent) component).getSelectedText(); - if (!StringUtil.isEmpty(selection)) { - selection = EditorUtils.removeDirectionChars(selection); - selection = selection.trim(); + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Core.getProject().isProjectLoaded()) { + return; } + MainWindowUI.createSearchWindow(SearchMode.REPLACE, ProjectUICommands.getTrimmedSelectedTextInMainWindow()); } - return selection; } /** Set active match to #1. */ - public void editSelectFuzzy1MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(0); + public static class EditSelectFuzzy1MenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzy1MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_1"), OStrings.getLocale()); + final String key = "editSelectFuzzy1MenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setActiveMatch(0); + } } /** Set active match to #2. */ - public void editSelectFuzzy2MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(1); + public static class EditSelectFuzzy2MenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzy2MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_2"), OStrings.getLocale()); + final String key = "editSelectFuzzy2MenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setActiveMatch(1); + } } /** Set active match to #3. */ - public void editSelectFuzzy3MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(2); + public static class EditSelectFuzzy3MenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzy3MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_3"), OStrings.getLocale()); + final String key = "editSelectFuzzy3MenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setActiveMatch(2); + } } /** Set active match to #4. */ - public void editSelectFuzzy4MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(3); + public static class EditSelectFuzzy4MenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzy4MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_4"), OStrings.getLocale()); + final String key = "editSelectFuzzy4MenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setActiveMatch(3); + } } /** Set active match to #5. */ - public void editSelectFuzzy5MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(4); + public static class EditSelectFuzzy5MenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzy5MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_5"), OStrings.getLocale()); + final String key = "editSelectFuzzy5MenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setActiveMatch(4); + } } /** Set active match to the next one */ - public void editSelectFuzzyNextMenuItemActionPerformed() { - Core.getMatcher().setNextActiveMatch(); + public static class EditSelectFuzzyNextMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzyNextMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_NEXT"), OStrings.getLocale()); + final String key = "editSelectFuzzyNextMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setNextActiveMatch(); + } } /** Set active match to the previous one */ - public void editSelectFuzzyPrevMenuItemActionPerformed() { - Core.getMatcher().setPrevActiveMatch(); + public static class EditSelectFuzzyPrevMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditSelectFuzzyPrevMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_PREV"), OStrings.getLocale()); + final String key = "editSelectFuzzyPrevMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getMatcher().setPrevActiveMatch(); + } } - public void insertCharsLRMActionPerformed() { - Core.getEditor().insertText("\u200E"); + public static class InsertCharsLRMAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public InsertCharsLRMAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_LRM"), OStrings.getLocale()); + final String key = "insertCharsLRM"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().insertText("\u200E"); + + } } - public void insertCharsRLMActionPerformed() { - Core.getEditor().insertText("\u200F"); + public static class InsertCharsRLMAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public InsertCharsRLMAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_RLM"), OStrings.getLocale()); + final String key = "insertCharsRLM"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().insertText("\u200F"); + } } - public void insertCharsLREActionPerformed() { - Core.getEditor().insertText("\u202A"); + public static class InsertCharsLREAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public InsertCharsLREAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_LRE"), OStrings.getLocale()); + final String key = "insertCharsLRE"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().insertText("\u202A"); + } } - public void insertCharsRLEActionPerformed() { - Core.getEditor().insertText("\u202B"); + public static class InsertCharsRLEAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public InsertCharsRLEAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_RLE"), OStrings.getLocale()); + final String key = "insertCharsRLE"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().insertText("\u202B"); + } } - public void insertCharsPDFActionPerformed() { - Core.getEditor().insertText("\u202C"); + public static class InsertCharsPDFAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public InsertCharsPDFAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_PDF"), OStrings.getLocale()); + final String key = "insertCharsPDF"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().insertText("\u202C"); + } } - public void editMultipleDefaultActionPerformed() { - Core.getEditor().setAlternateTranslationForCurrentEntry(false); + public static class EditMultipleDefaultAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditMultipleDefaultAction() { + super(OStrings.getString("MULT_MENU_DEFAULT"), OStrings.getLocale()); + final String key = "editMultipleDefault"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().setAlternateTranslationForCurrentEntry(false); + } } - public void editMultipleAlternateActionPerformed() { - Core.getEditor().setAlternateTranslationForCurrentEntry(true); + public static class EditMultipleAlternateAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditMultipleAlternateAction() { + super(OStrings.getString("MULT_MENU_MULTIPLE"), OStrings.getLocale()); + final String key = "editMultipleAlternate"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().setAlternateTranslationForCurrentEntry(true); + } } - public void editRegisterUntranslatedMenuItemActionPerformed() { - Core.getEditor().registerUntranslated(); + public static class EditRegisterUntranslatedMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditRegisterUntranslatedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_UNTRANSLATED_TRANSLATION"), OStrings.getLocale()); + final String key = "editRegisterUntranslatedMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().registerUntranslated(); + } } - public void editRegisterEmptyMenuItemActionPerformed() { - Core.getEditor().registerEmptyTranslation(); + public static class EditRegisterEmptyMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditRegisterEmptyMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_EMPTY_TRANSLATION"), OStrings.getLocale()); + final String key = "editRegisterEmptyMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().registerEmptyTranslation(); + } } - public void editRegisterIdenticalMenuItemActionPerformed() { - Core.getEditor().registerIdenticalTranslation(); + public static class EditRegisterIdenticalMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditRegisterIdenticalMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_IDENTICAL_TRANSLATION"), OStrings.getLocale()); + final String key = "editRegisterIdenticalMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().registerIdenticalTranslation(); + } } - public void optionsPreferencesMenuItemActionPerformed() { - PreferencesWindowController pwc = new PreferencesWindowController(); - pwc.show(Core.getMainWindow().getApplicationFrame()); + public static class OptionsPreferencesMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsPreferencesMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_PREFERENCES"), OStrings.getLocale()); + final String key = "optionsPreferencesMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, Objects.requireNonNullElseGet( + UIManager.getIcon("OmegaT.newUI.settings.icon"), + () -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.settings.png")))); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame()); + } } - public void cycleSwitchCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.CYCLE); + public static class CycleSwitchCaseMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public CycleSwitchCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_CYCLE"), OStrings.getLocale()); + final String key = "cycleSwitchCaseMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.CYCLE); + } } - public void sentenceCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.SENTENCE); + public static class SentenceCaseMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public SentenceCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_SENTENCE"), OStrings.getLocale()); + final String key = "sentenceCaseMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.SENTENCE); + } } - public void titleCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.TITLE); + public static class TitleCaseMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public TitleCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_TITLE"), OStrings.getLocale()); + final String key = "titleCaseMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.TITLE); + } } - public void upperCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.UPPER); + public static class UpperCaseMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public UpperCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_UPPER"), OStrings.getLocale()); + final String key = "upperCaseMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.UPPER); + } } - public void lowerCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.LOWER); + public static class LowerCaseMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public LowerCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_LOWER"), OStrings.getLocale()); + final String key = "lowerCaseMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.LOWER); + } } - public void gotoNextUntranslatedMenuItemActionPerformed() { - Core.getEditor().nextUntranslatedEntry(); + public static class GotoNextUntranslatedMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextUntranslatedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_UNTRANS"), OStrings.getLocale()); + final String key = "gotoNextUntranslatedMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextUntranslatedEntry(); + } } - public void gotoNextUniqueMenuItemActionPerformed() { - Core.getEditor().nextUniqueEntry(); + public static class GotoNextUniqueMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextUniqueMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_NEXT_UNIQUE"), OStrings.getLocale()); + final String key = "gotoNextUniqueMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextUniqueEntry(); + } } - public void gotoNextTranslatedMenuItemActionPerformed() { - Core.getEditor().nextTranslatedEntry(); + public static class GotoNextTranslatedMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextTranslatedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_TRANS"), OStrings.getLocale()); + final String key = "gotoNextTranslatedMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextTranslatedEntry(); + } } - public void gotoNextSegmentMenuItemActionPerformed() { - Core.getEditor().nextEntry(); + public static class GotoNextSegmentMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextSegmentMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_NEXT"), OStrings.getLocale()); + final String key = "gotoNextSegmentMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextEntry(); + } } - public void gotoPreviousSegmentMenuItemActionPerformed() { - Core.getEditor().prevEntry(); + public static class GotoPreviousSegmentMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoPreviousSegmentMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_PREV"), OStrings.getLocale()); + final String key = "gotoPreviousSegmentMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().prevEntry(); + } } - public void gotoNextXAutoMenuItemActionPerformed() { - Core.getEditor().nextXAutoEntry(); + public static class GotoNextXAutoMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextXAutoMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_NEXT_XAUTO"), OStrings.getLocale()); + final String key = "gotoNextXAutoMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextXAutoEntry(); + } } - public void gotoPrevXAutoMenuItemActionPerformed() { - Core.getEditor().prevXAutoEntry(); + public static class GotoPrevXAutoMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoPrevXAutoMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_PREV_XAUTO"), OStrings.getLocale()); + final String key = "gotoPrevXAutoMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().prevXAutoEntry(); + } } - public void gotoNextXEnforcedMenuItemActionPerformed() { - Core.getEditor().nextXEnforcedEntry(); + public static class GotoNextXEnforcedMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextXEnforcedMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_NEXT_XENFORCED", OStrings.getLocale())); + final String key = "gotoNextXEnforcedMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextXEnforcedEntry(); + } } - public void gotoPrevXEnforcedMenuItemActionPerformed() { - Core.getEditor().prevXEnforcedEntry(); + public static class GotoPrevXEnforcedMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoPrevXEnforcedMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_PREV_XENFORCED"), OStrings.getLocale()); + final String key = "gotoPrevXEnforcedMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().prevXEnforcedEntry(); + } } - public void gotoNextNoteMenuItemActionPerformed() { - Core.getEditor().nextEntryWithNote(); + public static class GotoNextNoteMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNextNoteMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_NEXT_NOTE"), OStrings.getLocale()); + final String key = "gotoNextNoteMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().nextEntryWithNote(); + } } - public void gotoPreviousNoteMenuItemActionPerformed() { - Core.getEditor().prevEntryWithNote(); + public static class GotoPreviousNoteMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoPreviousNoteMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_PREV_NOTE"), OStrings.getLocale()); + final String key = "gotoPreviousNoteMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().prevEntryWithNote(); + } } - public void gotoNotesPanelMenuItemActionPerformed() { - Core.getNotes().requestFocus(); + public static class GotoNotesPanelMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoNotesPanelMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_NOTES_PANEL"), OStrings.getLocale()); + final String key = "gotoNotesPanelMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getNotes().requestFocus(); + } } - public void gotoEditorPanelMenuItemActionPerformed() { - Core.getEditor().requestFocus(); + public static class GotoEditorPanelMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoEditorPanelMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_EDITOR_PANEL"), OStrings.getLocale()); + final String key = "gotoEditorPanelMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().requestFocus(); + } } /** * Asks the user for a segment number and then displays the segment. */ - public void gotoSegmentMenuItemActionPerformed() { - // Create a dialog for input - GoToSegmentDialog dialog = new GoToSegmentDialog(mainWindow.getApplicationFrame()); - dialog.setVisible(true); + public static class GotoSegmentMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoSegmentMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_GOTO"), OStrings.getLocale()); + final String key = "gotoSegmentMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } - int jumpTo = dialog.getResult(); + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + // Create a dialog for input + GoToSegmentDialog dialog = new GoToSegmentDialog(Core.getMainWindow().getApplicationFrame()); + dialog.setVisible(true); - if (jumpTo != -1) { - Core.getEditor().gotoEntry(jumpTo); + int jumpTo = dialog.getResult(); + + if (jumpTo != -1) { + Core.getEditor().gotoEntry(jumpTo); + } } } - public void gotoHistoryBackMenuItemActionPerformed() { - Core.getEditor().gotoHistoryBack(); + public static class GotoHistoryBackMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoHistoryBackMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_BACK_IN_HISTORY"), OStrings.getLocale()); + final String key = "gotoHistoryBackMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().gotoHistoryBack(); + } } - public void gotoHistoryForwardMenuItemActionPerformed() { - Core.getEditor().gotoHistoryForward(); + public static class GotoHistoryForwardMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoHistoryForwardMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_FORWARD_IN_HISTORY"), OStrings.getLocale()); + final String key = "gotoHistoryForwardMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().gotoHistoryForward(); + } } - public void gotoMatchSourceSegmentActionPerformed() { - NearString ns = Core.getMatcher().getActiveMatch(); - if (ns != null && ns.comesFrom == MATCH_SOURCE.MEMORY) { - Core.getEditor().gotoEntry(ns.source, ns.key); + public static class GotoMatchSourceSegmentAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public GotoMatchSourceSegmentAction() { + super(OStrings.getString("TF_MENU_GOTO_SELECTED_MATCH_SOURCE"), OStrings.getLocale()); + final String key = "gotoMatchSourceSegment"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + NearString ns = Core.getMatcher().getActiveMatch(); + if (ns != null && ns.comesFrom == MATCH_SOURCE.MEMORY) { + Core.getEditor().gotoEntry(ns.source, ns.key); + } } } - public void viewMarkTranslatedSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkTranslated(mainWindow.menu.viewMarkTranslatedSegmentsCheckBoxMenuItem.isSelected()); + public static class ViewMarkTranslatedSegmentsCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkTranslatedSegmentsCheckBoxMenuItemAction() { + super(OStrings.getString("TF_MENU_DISPLAY_MARK_TRANSLATED"), OStrings.getLocale()); + final String key = "viewMarkTranslatedSegmentsCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkTranslated(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkUntranslatedSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkUntranslated( - mainWindow.menu.viewMarkUntranslatedSegmentsCheckBoxMenuItem.isSelected()); + public static class ViewMarkUntranslatedSegmentsCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkUntranslatedSegmentsCheckBoxMenuItemAction() { + super(OStrings.getString("TF_MENU_DISPLAY_MARK_UNTRANSLATED"), OStrings.getLocale()); + final String key = "viewMarkUntranslatedSegmentsCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_UNTRANSLATED.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkUntranslated(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkParagraphStartCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkParagraphDelimitations( - mainWindow.menu.viewMarkParagraphStartCheckBoxMenuItem.isSelected()); + public static class ViewMarkParagraphStartCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkParagraphStartCheckBoxMenuItemAction() { + super(OStrings.getString("TF_MENU_DISPLAY_MARK_PARAGRAPH"), OStrings.getLocale()); + final String key = "viewMarkParagraphStartCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newTextIcon(Styles.EditorColor.COLOR_PARAGRAPH_START.getColor(), '\u00b6')); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings() + .setMarkParagraphDelimitations(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewDisplaySegmentSourceCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setDisplaySegmentSources( - mainWindow.menu.viewDisplaySegmentSourceCheckBoxMenuItem.isSelected()); + public static class ViewDisplaySegmentSourceCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewDisplaySegmentSourceCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_DISPLAY_SEGMENT_SOURCES"), OStrings.getLocale()); + final String key = "viewDisplaySegmentSourceCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_SOURCE.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setDisplaySegmentSources(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkNonUniqueSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkNonUniqueSegments( - mainWindow.menu.viewMarkNonUniqueSegmentsCheckBoxMenuItem.isSelected()); + public static class ViewMarkNonUniqueSegmentsCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkNonUniqueSegmentsCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_NON_UNIQUE_SEGMENTS"), OStrings.getLocale()); + final String key = "viewMarkNonUniqueSegmentsCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newTextIcon(Styles.EditorColor.COLOR_NON_UNIQUE.getColor(), 'M')); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkNonUniqueSegments(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkNotedSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkNotedSegments( - mainWindow.menu.viewMarkNotedSegmentsCheckBoxMenuItem.isSelected()); + public static class ViewMarkNotedSegmentsCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkNotedSegmentsCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_NOTED_SEGMENTS"), OStrings.getLocale()); + final String key = "viewMarkNotedSegmentsCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_NOTED.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkNotedSegments(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkNBSPCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkNBSP( - mainWindow.menu.viewMarkNBSPCheckBoxMenuItem.isSelected()); + public static class ViewMarkNBSPCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkNBSPCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_NBSP"), OStrings.getLocale()); + final String key = "viewMarkNBSPCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_NBSP.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkNBSP(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkWhitespaceCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkWhitespace( - mainWindow.menu.viewMarkWhitespaceCheckBoxMenuItem.isSelected()); + public static class ViewMarkWhitespaceCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkWhitespaceCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_WHITESPACE"), OStrings.getLocale()); + final String key = "viewMarkWhitespaceCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_WHITESPACE.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkWhitespace(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkBidiCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkBidi( - mainWindow.menu.viewMarkBidiCheckBoxMenuItem.isSelected()); + public static class ViewMarkBidiCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkBidiCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_BIDI"), OStrings.getLocale()); + final String key = "viewMarkBidiCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_BIDIMARKERS.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkBidi(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkAutoPopulatedCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkAutoPopulated(mainWindow.menu.viewMarkAutoPopulatedCheckBoxMenuItem.isSelected()); + public static class ViewMarkAutoPopulatedCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkAutoPopulatedCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_AUTOPOPULATED"), OStrings.getLocale()); + final String key = "viewMarkAutoPopulatedCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_MARK_COMES_FROM_TM_XAUTO.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkAutoPopulated(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkGlossaryMatchesCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkGlossaryMatches(mainWindow.menu.viewMarkGlossaryMatchesCheckBoxMenuItem.isSelected()); + public static class ViewMarkGlossaryMatchesCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkGlossaryMatchesCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_GLOSSARY_MARK"), OStrings.getLocale()); + final String key = "viewMarkGlossaryMatchesCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_TRANSTIPS.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkGlossaryMatches(((JCheckBoxMenuItem) o).isSelected()); + } + + } } - public void viewMarkLanguageCheckerCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkLanguageChecker(mainWindow.menu.viewMarkLanguageCheckerCheckBoxMenuItem.isSelected()); + public static class ViewMarkLanguageCheckerCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkLanguageCheckerCheckBoxMenuItemAction() { + super(OStrings.getString("LT_OPTIONS_MENU_ENABLED"), OStrings.getLocale()); + final String key = "viewMarkLanguageCheckerCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, + MainMenuIcons.newColorIcon(Styles.EditorColor.COLOR_LANGUAGE_TOOLS.getColor())); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setMarkLanguageChecker(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewMarkFontFallbackCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setDoFontFallback(mainWindow.menu.viewMarkFontFallbackCheckBoxMenuItem.isSelected()); + public static class ViewMarkFontFallbackCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewMarkFontFallbackCheckBoxMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MARK_FONT_FALLBACK"), OStrings.getLocale()); + final String key = "viewMarkFontFallbackCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + putValue(Action.SMALL_ICON, MainMenuIcons.newTextIcon(UIManager.getColor("Label.foreground"), + new Font("Serif", Font.ITALIC, 16), 'F')); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Core.getEditor().getSettings().setDoFontFallback(((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void viewDisplayModificationInfoNoneRadioButtonMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setDisplayModificationInfo(EditorSettings.DISPLAY_MODIFICATION_INFO_NONE); + public static class ViewDisplayModificationInfoNoneRadioButtonMenuItemAction + extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewDisplayModificationInfoNoneRadioButtonMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MODIFICATION_INFO_NONE"), OStrings.getLocale()); + final String key = "viewDisplayModificationInfoNoneRadioButtonMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().getSettings() + .setDisplayModificationInfo(EditorSettings.DISPLAY_MODIFICATION_INFO_NONE); + } } - public void viewDisplayModificationInfoSelectedRadioButtonMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setDisplayModificationInfo(EditorSettings.DISPLAY_MODIFICATION_INFO_SELECTED); + public static class ViewDisplayModificationInfoSelectedRadioButtonMenuItemAction + extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewDisplayModificationInfoSelectedRadioButtonMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MODIFICATION_INFO_SELECTED"), OStrings.getLocale()); + final String key = "viewDisplayModificationInfoSelectedRadioButtonMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().getSettings() + .setDisplayModificationInfo(EditorSettings.DISPLAY_MODIFICATION_INFO_SELECTED); + } } - public void viewDisplayModificationInfoAllRadioButtonMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setDisplayModificationInfo(EditorSettings.DISPLAY_MODIFICATION_INFO_ALL); + public static class ViewDisplayModificationInfoAllRadioButtonMenuItemAction + extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewDisplayModificationInfoAllRadioButtonMenuItemAction() { + super(OStrings.getString("MW_VIEW_MENU_MODIFICATION_INFO_ALL"), OStrings.getLocale()); + final String key = "viewDisplayModificationInfoAllRadioButtonMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getEditor().getSettings() + .setDisplayModificationInfo(EditorSettings.DISPLAY_MODIFICATION_INFO_ALL); + } } - public void toolsCheckIssuesMenuItemActionPerformed() { - if (!Preferences.isPreference(Preferences.ISSUE_PROVIDERS_DONT_ASK)) { - IssueProvidersSelectorController dialog = new IssueProvidersSelectorController(); - if (!dialog.show(mainWindow.getApplicationFrame())) { - return; + public static class ToolsCheckIssuesMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ToolsCheckIssuesMenuItemAction() { + super(OStrings.getString("TF_MENU_TOOLS_CHECK_ISSUES"), OStrings.getLocale()); + final String key = "toolsCheckIssuesMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + if (!Preferences.isPreference(Preferences.ISSUE_PROVIDERS_DONT_ASK)) { + IssueProvidersSelectorController dialog = new IssueProvidersSelectorController(); + if (!dialog.show(Core.getMainWindow().getApplicationFrame())) { + return; + } } + Core.getIssues().showAll(); } - Core.getIssues().showAll(); } - public void toolsCheckIssuesCurrentFileMenuItemActionPerformed() { - Core.getIssues().showForFiles(Pattern.quote(Core.getEditor().getCurrentFile())); + public static class ToolsCheckIssuesCurrentFileMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ToolsCheckIssuesCurrentFileMenuItemAction() { + super(OStrings.getString("TF_MENU_TOOLS_CHECK_ISSUES_CURRENT_FILE"), OStrings.getLocale()); + final String key = "toolsCheckIssuesCurrentFileMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Core.getIssues().showForFiles(Pattern.quote(Core.getEditor().getCurrentFile())); + } } /** - * Identify all the placeholders in the source text and automatically inserts them into the target text. + * Identify all the placeholders in the source text and automatically + * inserts them into the target text. */ - public void editTagPainterMenuItemActionPerformed() { - // insert tags - for (Tag tag : TagUtil.getAllTagsMissingFromTarget()) { - Core.getEditor().insertTag(tag.tag); + public static class EditTagPainterMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditTagPainterMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_TAGPAINT"), OStrings.getLocale()); + final String key = "editTagPainterMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + // insert tags + for (Tag tag : TagUtil.getAllTagsMissingFromTarget()) { + Core.getEditor().insertTag(tag.tag); + } } } - public void editTagNextMissedMenuItemActionPerformed() { - // insert next tag - List tags = TagUtil.getAllTagsMissingFromTarget(); - if (tags.isEmpty()) { - return; + public static class EditTagNextMissedMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public EditTagNextMissedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_TAG_NEXT_MISSED"), OStrings.getLocale()); + final String key = "editTagNextMissedMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + // insert next tag + List tags = TagUtil.getAllTagsMissingFromTarget(); + if (tags.isEmpty()) { + return; + } + Core.getEditor().insertTag(tags.get(0).tag); } - Core.getEditor().insertTag(tags.get(0).tag); } - public void toolsShowStatisticsStandardMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.STANDARD) - .setVisible(true); + public static class ToolsShowStatisticsStandardMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ToolsShowStatisticsStandardMenuItemAction() { + super(OStrings.getString("TF_MENU_TOOLS_STATISTICS_STANDARD"), OStrings.getLocale()); + final String key = "toolsShowStatisticsStandardMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), + StatisticsWindow.STAT_TYPE.STANDARD).setVisible(true); + } } - public void toolsShowStatisticsMatchesMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.MATCHES) - .setVisible(true); + public static class ToolsShowStatisticsMatchesMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ToolsShowStatisticsMatchesMenuItemAction() { + super(OStrings.getString("TF_MENU_TOOLS_STATISTICS_MATCHES"), OStrings.getLocale()); + final String key = "toolsShowStatisticsMatchesMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), + StatisticsWindow.STAT_TYPE.MATCHES).setVisible(true); + } } - public void toolsShowStatisticsMatchesPerFileMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.MATCHES_PER_FILE) - .setVisible(true); + public static class ToolsShowStatisticsMatchesPerFileMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ToolsShowStatisticsMatchesPerFileMenuItemAction() { + super(OStrings.getString("TF_MENU_TOOLS_STATISTICS_MATCHES_PER_FILE"), OStrings.getLocale()); + final String key = "toolsShowStatisticsMatchesPerFileMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), + StatisticsWindow.STAT_TYPE.MATCHES_PER_FILE).setVisible(true); + } } - public void optionsAutoCompleteShowAutomaticallyItemActionPerformed() { - Preferences.setPreference(Preferences.AC_SHOW_SUGGESTIONS_AUTOMATICALLY, - mainWindow.menu.optionsAutoCompleteShowAutomaticallyItem.isSelected()); + public static class OptionsAutoCompleteShowAutomaticallyItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsAutoCompleteShowAutomaticallyItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_AUTOCOMPLETE_SHOW_AUTOMATICALLY"), OStrings.getLocale()); + final String key = "optionsAutoCompleteShowAutomaticallyItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Preferences.setPreference(Preferences.AC_SHOW_SUGGESTIONS_AUTOMATICALLY, + ((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void optionsAutoCompleteHistoryCompletionMenuItemActionPerformed() { - Preferences.setPreference(Preferences.AC_HISTORY_COMPLETION_ENABLED, - mainWindow.menu.optionsAutoCompleteHistoryCompletionMenuItem.isSelected()); + public static class OptionsAutoCompleteHistoryCompletionMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsAutoCompleteHistoryCompletionMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_COMPLETION"), OStrings.getLocale()); + final String key = "optionsAutoCompleteHistoryCompletionMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Preferences.setPreference(Preferences.AC_HISTORY_COMPLETION_ENABLED, + ((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void optionsAutoCompleteHistoryPredictionMenuItemActionPerformed() { - Preferences.setPreference(Preferences.AC_HISTORY_PREDICTION_ENABLED, - mainWindow.menu.optionsAutoCompleteHistoryPredictionMenuItem.isSelected()); + public static class OptionsAutoCompleteHistoryPredictionMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsAutoCompleteHistoryPredictionMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_PREDICTION"), OStrings.getLocale()); + final String key = "optionsAutoCompleteHistoryPredictionMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Preferences.setPreference(Preferences.AC_HISTORY_PREDICTION_ENABLED, + ((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void optionsMTAutoFetchCheckboxMenuItemActionPerformed() { - boolean enabled = mainWindow.menu.optionsMTAutoFetchCheckboxMenuItem.isSelected(); - Preferences.setPreference(Preferences.MT_AUTO_FETCH, enabled); + public static class OptionsMTAutoFetchCheckboxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsMTAutoFetchCheckboxMenuItemAction() { + super(OStrings.getString("MT_AUTO_FETCH"), OStrings.getLocale()); + final String key = "optionsMTAutoFetchCheckboxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Preferences.setPreference(Preferences.MT_AUTO_FETCH, ((JCheckBoxMenuItem) o).isSelected()); + } + } } - public void optionsGlossaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { - Preferences.setPreference(Preferences.GLOSSARY_STEMMING, - mainWindow.menu.optionsGlossaryFuzzyMatchingCheckBoxMenuItem.isSelected()); - Preferences.save(); + public static class OptionsGlossaryFuzzyMatchingCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsGlossaryFuzzyMatchingCheckBoxMenuItemAction() { + super(OStrings.getString("TF_OPTIONSMENU_GLOSSARY_FUZZY"), OStrings.getLocale()); + final String key = "optionsGlossaryFuzzyMatchingCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Preferences.setPreference(Preferences.GLOSSARY_STEMMING, + ((JCheckBoxMenuItem) o).isSelected()); + Preferences.save(); + } + } } - public void optionsDictionaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { - Preferences.setPreference(Preferences.DICTIONARY_FUZZY_MATCHING, - mainWindow.menu.optionsDictionaryFuzzyMatchingCheckBoxMenuItem.isSelected()); - Preferences.save(); + public static class OptionsDictionaryFuzzyMatchingCheckBoxMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsDictionaryFuzzyMatchingCheckBoxMenuItemAction() { + super(OStrings.getString("TF_OPTIONSMENU_DICTIONARY_FUZZY"), OStrings.getLocale()); + final String key = "optionsDictionaryFuzzyMatchingCheckBoxMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + Object o = e.getSource(); + if (o instanceof JCheckBoxMenuItem) { + Preferences.setPreference(Preferences.DICTIONARY_FUZZY_MATCHING, + ((JCheckBoxMenuItem) o).isSelected()); + Preferences.save(); + } + } } /** - * Displays the filters setup dialog to allow customizing file filters in detail. + * Displays the filters setup dialog to allow customizing file filters in + * detail. */ - public void optionsSetupFileFiltersMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), FiltersCustomizerController.class); + public static class OptionsSetupFileFiltersMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsSetupFileFiltersMenuItemAction() { + super(OStrings.getString("TF_MENU_DISPLAY_GLOBAL_FILTERS"), OStrings.getLocale()); + final String key = "optionsSetupFileFiltersMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame(), + FiltersCustomizerController.class); + } } /** - * Displays the segmentation setup dialog to allow customizing the segmentation rules in detail. + * Displays the segmentation setup dialog to allow customizing the + * segmentation rules in detail. */ - public void optionsSentsegMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), SegmentationCustomizerController.class); + public static class OptionsSentsegMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsSentsegMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_GLOBAL_SENTSEG"), OStrings.getLocale()); + final String key = "optionsSentsegMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame(), + SegmentationCustomizerController.class); + } } /** - * Displays the workflow setup dialog to allow customizing the diverse workflow options. + * Displays the workflow setup dialog to allow customizing the diverse + * workflow options. */ - public void optionsWorkflowMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), EditingBehaviorController.class); + public static class OptionsWorkflowMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsWorkflowMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_WORKFLOW"), OStrings.getLocale()); + final String key = "optionsWorkflowMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame(), + EditingBehaviorController.class); + } } /** - * Restores defaults for all dockable parts. May be expanded in the future to reset the entire GUI to its - * defaults. + * Restores defaults for all dockable parts. May be expanded in the future + * to reset the entire GUI to its defaults. */ - public void viewRestoreGUIMenuItemActionPerformed() { - MainWindowUI.resetDesktopLayout(mainWindow); + public static class ViewRestoreGUIMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public ViewRestoreGUIMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_RESTORE_GUI"), OStrings.getLocale()); + final String key = "viewRestoreGUIMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + MainWindowUI.resetDesktopLayout((MainWindow) Core.getMainWindow()); // FIXME + } } - public void optionsAccessConfigDirMenuItemActionPerformed() { - openFile(new File(StaticUtils.getConfigDir())); + public static class OptionsAccessConfigDirMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public OptionsAccessConfigDirMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_ACCESS_CONFIG_DIR"), OStrings.getLocale()); + final String key = "optionsAccessConfigDirMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + ProjectUICommands.openFile(new File(StaticUtils.getConfigDir())); + } } /** * Show help. */ - public void helpContentsMenuItemActionPerformed() { - try { - Help.showHelp(); - } catch (Exception ex) { - JOptionPane.showMessageDialog(mainWindow.getApplicationFrame(), ex.getLocalizedMessage(), OStrings.getString( - "ERROR_TITLE"), - JOptionPane.ERROR_MESSAGE); - Log.log(ex); + public static class HelpContentsMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public HelpContentsMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_CONTENTS"), OStrings.getLocale()); + final String key = "helpContentsMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + try { + Help.showHelp(); + } catch (Exception ex) { + JOptionPane.showMessageDialog(Core.getMainWindow().getApplicationFrame(), + ex.getLocalizedMessage(), OStrings.getString("ERROR_TITLE"), + JOptionPane.ERROR_MESSAGE); + Log.log(ex); + } } } /** * Shows About dialog */ - public void helpAboutMenuItemActionPerformed() { - new AboutDialog(mainWindow.getApplicationFrame()).setVisible(true); + public static class HelpAboutMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public HelpAboutMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_ABOUT"), OStrings.getLocale()); + final String key = "helpAboutMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new AboutDialog(Core.getMainWindow().getApplicationFrame()).setVisible(true); + } } /** * Shows Last changes */ - public void helpLastChangesMenuItemActionPerformed() { - new LastChangesDialog(mainWindow.getApplicationFrame()).setVisible(true); + public static class HelpLastChangesMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public HelpLastChangesMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_LAST_CHANGES"), OStrings.getLocale()); + final String key = "helpLastChangesMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new LastChangesDialog(Core.getMainWindow().getApplicationFrame()).setVisible(true); + } } /** * Show log */ - public void helpLogMenuItemActionPerformed() { - new LogDialog(mainWindow.getApplicationFrame()).setVisible(true); + public static class HelpLogMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public HelpLogMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_LOG"), OStrings.getLocale()); + final String key = "helpLogMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + new LogDialog(Core.getMainWindow().getApplicationFrame()).setVisible(true); + } } /** * Check for updates */ - public void helpUpdateCheckMenuItemActionPerformed() { - VersionCheckDialog.checkAndShowResultAsync(mainWindow.getApplicationFrame()); + public static class HelpUpdateCheckMenuItemAction extends AbstractMnemonicsAction { + private static final long serialVersionUID = 1L; + public HelpUpdateCheckMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_CHECK_FOR_UPDATES"), OStrings.getLocale()); + final String key = "helpUpdateCheckMenuItem"; + putValue(Action.ACTION_COMMAND_KEY, key); + putValue(Action.ACCELERATOR_KEY, PropertiesShortcuts.getMainMenuShortcuts().getKeyStrokeOrNull(key)); + } + + @Override + public void actionPerformed(ActionEvent e) { + Log.logInfoRB("LOG_MENU_CLICK", e.getActionCommand()); + VersionCheckDialog.checkAndShowResultAsync(Core.getMainWindow().getApplicationFrame()); + } } } diff --git a/src/org/omegat/gui/main/MainWindowUI.java b/src/org/omegat/gui/main/MainWindowUI.java index 43b526bbe9..54bbc40406 100644 --- a/src/org/omegat/gui/main/MainWindowUI.java +++ b/src/org/omegat/gui/main/MainWindowUI.java @@ -55,10 +55,6 @@ import org.omegat.util.StaticUtils; import org.omegat.util.gui.UIDesignManager; -import com.vlsolutions.swing.docking.DockingDesktop; -import com.vlsolutions.swing.docking.event.DockableStateWillChangeEvent; -import com.vlsolutions.swing.docking.event.DockableStateWillChangeListener; - /** * Class for initialize, load/save, etc. for main window UI components. * @@ -85,22 +81,6 @@ private MainWindowUI() { public static final String UI_LAYOUT_FILE = "uiLayout" + OStrings.getBrandingToken() + ".xml"; - /** - * Create docking desktop panel. - */ - public static DockingDesktop initDocking(final MainWindow mainWindow) { - mainWindow.desktop = new DockingDesktop(); - mainWindow.desktop.addDockableStateWillChangeListener(new DockableStateWillChangeListener() { - public void dockableStateWillChange(DockableStateWillChangeEvent event) { - if (event.getFutureState().isClosed()) { - event.cancel(); - } - } - }); - - return mainWindow.desktop; - } - /** * Installs a {@link IProjectEventListener} that handles loading, storing, * and restoring the main window layout when a project-specific layout is diff --git a/src/org/omegat/gui/main/ProjectUICommands.java b/src/org/omegat/gui/main/ProjectUICommands.java index 817acbe067..854f56a779 100644 --- a/src/org/omegat/gui/main/ProjectUICommands.java +++ b/src/org/omegat/gui/main/ProjectUICommands.java @@ -34,6 +34,7 @@ package org.omegat.gui.main; +import java.awt.Component; import java.awt.Cursor; import java.io.File; import java.io.IOException; @@ -48,6 +49,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import javax.swing.text.JTextComponent; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -60,17 +62,23 @@ import org.omegat.core.data.ProjectFactory; import org.omegat.core.data.ProjectProperties; import org.omegat.core.events.IProjectEventListener; +import org.omegat.core.search.SearchMode; import org.omegat.core.segmentation.SRX; import org.omegat.core.segmentation.Segmenter; +import org.omegat.core.spellchecker.ISpellChecker; +import org.omegat.core.tagvalidation.ErrorReport; import org.omegat.core.team2.IRemoteRepository2; import org.omegat.core.team2.RemoteRepositoryProvider; import org.omegat.filters2.master.FilterMaster; +import org.omegat.filters2.master.PluginUtils; import org.omegat.gui.dialogs.ChooseMedProject; import org.omegat.gui.dialogs.FileCollisionDialog; import org.omegat.gui.dialogs.NewProjectFileChooser; import org.omegat.gui.dialogs.NewTeamProjectController; import org.omegat.gui.dialogs.ProjectPropertiesDialog; import org.omegat.gui.dialogs.ProjectPropertiesDialogController; +import org.omegat.gui.editor.EditorUtils; +import org.omegat.gui.editor.SegmentExportImport; import org.omegat.util.FileUtil; import org.omegat.util.FileUtil.ICollisionCallback; import org.omegat.util.HttpConnectionUtils; @@ -83,6 +91,7 @@ import org.omegat.util.StaticUtils; import org.omegat.util.StringUtil; import org.omegat.util.WikiGet; +import org.omegat.util.gui.DesktopWrapper; import org.omegat.util.gui.OmegaTFileChooser; import org.omegat.util.gui.OpenProjectFileChooser; import org.omegat.util.gui.UIThreadsUtil; @@ -1240,6 +1249,146 @@ public static void projectImportFiles(String destination, File[] toImport, boole } } + public static void findInProjectReuseLastWindow() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + String text = getTrimmedSelectedTextInMainWindow(); + if (!MainWindowUI.reuseSearchWindow(text)) { + MainWindowUI.createSearchWindow(SearchMode.SEARCH, text); + } + } + + public static String getTrimmedSelectedTextInMainWindow() { + String selection = null; + Component component = Core.getMainWindow().getApplicationFrame().getMostRecentFocusOwner(); + if (component instanceof JTextComponent) { + selection = ((JTextComponent) component).getSelectedText(); + if (!StringUtil.isEmpty(selection)) { + selection = EditorUtils.removeDirectionChars(selection); + selection = selection.trim(); + } + } + return selection; + } + + public static void prepareForExit(Runnable onCompletion) { + // Bug #902: commit the current entry first + // We do it before checking project status, so that it can eventually + // change it + if (Core.getProject().isProjectLoaded()) { + Core.getEditor().commitAndLeave(); + } + + boolean projectModified = false; + if (Core.getProject().isProjectLoaded()) { + projectModified = Core.getProject().isProjectModified(); + } + // RFE 1302358 + // Add Yes/No Warning before OmegaT quits + if (projectModified || Preferences.isPreference(Preferences.ALWAYS_CONFIRM_QUIT)) { + if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog( + Core.getMainWindow().getApplicationFrame(), OStrings.getString("MW_QUIT_CONFIRM"), + OStrings.getString("CONFIRM_DIALOG_TITLE"), JOptionPane.YES_NO_OPTION)) { + return; + } + } + + SegmentExportImport.flushExportedSegments(); + + new SwingWorker() { + @Override + protected Void doInBackground() throws Exception { + if (Core.getProject().isProjectLoaded()) { + // Save the list of learned and ignore words + ISpellChecker sc = Core.getSpellChecker(); + sc.saveWordLists(); + try { + Core.executeExclusively(true, () -> { + Core.getProject().saveProject(true); + ProjectFactory.closeProject(); + }); + } catch (KnownException ex) { + // hide exception on shutdown + } + } + + CoreEvents.fireApplicationShutdown(); + + PluginUtils.unloadPlugins(); + + return null; + } + + @Override + protected void done() { + try { + get(); + + MainWindowUI.saveScreenLayout((MainWindow) Core.getMainWindow()); + + Preferences.save(); + + onCompletion.run(); + } catch (Exception ex) { + Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); + Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); + } + } + }.execute(); + } + + public static void openWritableGlossaryFile(boolean parent) { + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getWriteableGlossary(); + if (StringUtil.isEmpty(path)) { + return; + } + File toOpen = new File(path); + if (parent) { + toOpen = toOpen.getParentFile(); + } + openFile(toOpen); + } + + public static void openFile(File path) { + try { + path = path.getCanonicalFile(); // Normalize file name in case it is + // displayed + } catch (Exception ex) { + // Ignore + } + if (!path.exists()) { + Core.getMainWindow().showStatusMessageRB("LFC_ERROR_FILE_DOESNT_EXIST", path); + return; + } + try { + DesktopWrapper.open(path); + } catch (Exception ex) { + Log.logErrorRB(ex, "RPF_ERROR"); + Core.getMainWindow().displayErrorRB(ex, "RPF_ERROR"); + } + } + + /** + * Check whether tags are OK + * + * @return false is there is a tag issue, true otherwise + */ + static boolean IsTagsInvalid() { + boolean result = false; + if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { + List stes = Core.getTagValidation().listInvalidTags(); + if (!stes.isEmpty()) { + Core.getIssues().showAll(OStrings.getString("TF_MESSAGE_COMPILE")); + result = true; + } + } + return result; + } + private static class CollisionCallback implements ICollisionCallback { private boolean isCanceled = false; private boolean yesToAll = false; diff --git a/src/org/omegat/gui/matches/MatchesTextArea.java b/src/org/omegat/gui/matches/MatchesTextArea.java index a95e246941..190e5a3cfa 100644 --- a/src/org/omegat/gui/matches/MatchesTextArea.java +++ b/src/org/omegat/gui/matches/MatchesTextArea.java @@ -71,8 +71,10 @@ import org.omegat.core.matching.NearString.SORT_KEY; import org.omegat.core.matching.NearString.ScoresComparator; import org.omegat.gui.common.EntryInfoThreadPane; +import org.omegat.gui.exttrans.MachineTranslationInfo; import org.omegat.gui.main.DockableScrollPane; import org.omegat.gui.main.IMainWindow; +import org.omegat.gui.main.MainWindow; import org.omegat.gui.preferences.PreferencesWindowController; import org.omegat.gui.preferences.view.TMMatchesPreferencesController; import org.omegat.gui.shortcuts.PropertiesShortcuts; @@ -612,7 +614,7 @@ public void actionPerformed(ActionEvent e) { if (StringUtil.isEmpty(getSelectedText())) { setActiveMatch(index); } - Core.getMainWindow().getMainMenu().invokeAction("editInsertTranslationMenuItem", 0); + MainWindow.doInsertTrans(); } }); item.setEnabled(hasMatches); @@ -624,7 +626,13 @@ public void actionPerformed(ActionEvent e) { if (StringUtil.isEmpty(getSelectedText())) { setActiveMatch(index); } - Core.getMainWindow().getMainMenu().invokeAction("editOverwriteTranslationMenuItem", 0); + // Core.getMainWindow().getMainMenu().invokeAction("editOverwriteTranslationMenuItem", 0); + MachineTranslationInfo tr = Core.getMachineTranslatePane().getDisplayedTranslation(); + if (tr == null) { + Core.getMachineTranslatePane().forceLoad(); + } else if (!StringUtil.isEmpty(tr.result)) { + Core.getEditor().replaceEditText(tr.result, String.format("MT:[%s]", tr.translatorName)); + } } }); item.setEnabled(hasMatches); diff --git a/src/org/omegat/gui/search/SearchWindowMenu.java b/src/org/omegat/gui/search/SearchWindowMenu.java index 937606248b..6e1902ce7b 100644 --- a/src/org/omegat/gui/search/SearchWindowMenu.java +++ b/src/org/omegat/gui/search/SearchWindowMenu.java @@ -32,12 +32,13 @@ import javax.swing.JMenuItem; import javax.swing.KeyStroke; +import org.openide.awt.Mnemonics; + import org.omegat.core.Core; import org.omegat.gui.shortcuts.PropertiesShortcuts; import org.omegat.util.Java8Compat; import org.omegat.util.OStrings; import org.omegat.util.StringUtil; -import org.openide.awt.Mnemonics; @SuppressWarnings("serial") public class SearchWindowMenu extends JMenuBar { @@ -79,6 +80,7 @@ private void init() { // members in order to get matching shortcuts. item = editMenu.add(new JMenuItem()); + Mnemonics.setLocalizedText(item, OStrings.getString("TF_MENU_EDIT_SOURCE_INSERT")); item.setActionCommand("editInsertSourceMenuItem"); item.addActionListener( diff --git a/src/org/omegat/gui/shortcuts/PropertiesShortcuts.java b/src/org/omegat/gui/shortcuts/PropertiesShortcuts.java index 0f99272ddd..0183aad890 100644 --- a/src/org/omegat/gui/shortcuts/PropertiesShortcuts.java +++ b/src/org/omegat/gui/shortcuts/PropertiesShortcuts.java @@ -175,6 +175,14 @@ public KeyStroke getKeyStroke(String key) { return result; } + public KeyStroke getKeyStrokeOrNull(String key) { + try { + return getKeyStroke(key); + } catch (Exception ignored) { + } + return null; + } + public void bindKeyStrokes(JMenuBar menu) { applyTo(menu.getComponents()); } diff --git a/src/org/omegat/util/OStrings.java b/src/org/omegat/util/OStrings.java index 6e7b3a375f..4a4f683f23 100644 --- a/src/org/omegat/util/OStrings.java +++ b/src/org/omegat/util/OStrings.java @@ -28,6 +28,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.util.Locale; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import java.util.function.Function; @@ -81,6 +82,10 @@ public static ResourceBundle getResourceBundle() { return bundle; } + public static Locale getLocale() { + return bundle.getLocale(); + } + /** * Loads resources from the specified file. If the file cannot be loaded, * resources are reverted to the default locale. Useful when testing diff --git a/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java b/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java index 04f60ab024..65cd6a046e 100644 --- a/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java +++ b/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java @@ -31,7 +31,6 @@ import org.junit.Test; -import org.omegat.gui.main.BaseMainWindowMenu; import org.omegat.gui.main.TestCoreGUI; import org.omegat.util.OStrings; @@ -39,8 +38,8 @@ public class AboutDialogTest extends TestCoreGUI { @Test public void testAboutDialog() throws InterruptedException { - window.menuItem(BaseMainWindowMenu.HELP_MENU).click(); - window.menuItem(BaseMainWindowMenu.HELP_ABOUT_MENUITEM).click(); + window.menuItem("TF_MENU_HELP").click(); + window.menuItem("HELP_ABOUT_MENUITEM").click(); // Check about dialog window.dialog(AboutDialog.DIALOG_NAME).requireModal(); Pattern pattern = Pattern.compile(OStrings.getApplicationDisplayName() diff --git a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java index e5a1bf2992..ee8417186e 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java +++ b/test-acceptance/src/org/omegat/gui/main/TestCoreGUI.java @@ -69,7 +69,7 @@ protected void onSetUp() throws Exception { frame = GuiActionRunner.execute(() -> { Core.setProject(new NotLoadedProject()); UIDesignManager.initialize(); - TestMainWindow mw = new TestMainWindow(TestMainWindowMenuHandler.class); + TestMainWindow mw = new TestMainWindow(); TestCoreInitializer.initMainWindow(mw); TestCoreInitializer.initAutoSave(autoSave); @@ -94,10 +94,9 @@ public void disable() { } }; - static class TestMainWindowMenu extends BaseMainWindowMenu { + public static class TestMainWindowMenu extends BaseMainWindowMenu { - TestMainWindowMenu(IMainWindow mainWindow, BaseMainWindowMenuHandler mainWindowMenuHandler) { - super(mainWindow, mainWindowMenuHandler); + TestMainWindowMenu() { initComponents(); } diff --git a/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java b/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java index e9f24910e2..e0a315a8df 100644 --- a/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java +++ b/test-acceptance/src/org/omegat/gui/main/TestMainWindow.java @@ -73,17 +73,11 @@ class TestMainWindow implements IMainWindow { */ private final List searches = new ArrayList<>(); - TestMainWindow(Class mainWindowMenuHandler) throws IOException { + TestMainWindow() throws IOException { applicationFrame = new JFrame(); applicationFrame.setPreferredSize(new Dimension(1920, 1040)); font = FontUtil.getScaledFont(); - try { - BaseMainWindowMenuHandler handler = mainWindowMenuHandler - .getDeclaredConstructor(IMainWindow.class).newInstance(this); - menu = new TestCoreGUI.TestMainWindowMenu(this, handler); - } catch (Exception e) { - throw new RuntimeException(); - } + menu = new TestCoreGUI.TestMainWindowMenu(); applicationFrame.setJMenuBar(menu.mainMenu); applicationFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); diff --git a/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java b/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java deleted file mode 100644 index 2cbeb9267e..0000000000 --- a/test-acceptance/src/org/omegat/gui/main/TestMainWindowMenuHandler.java +++ /dev/null @@ -1,393 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2024 Hiroshi Miura - Home page: https://www.omegat.org/ - Support center: https://omegat.org/support - - This file is part of OmegaT. - - OmegaT is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OmegaT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - **************************************************************************/ -package org.omegat.gui.main; - -import java.awt.Component; -import java.awt.KeyboardFocusManager; -import java.io.File; - -import javax.swing.JDialog; -import javax.swing.text.JTextComponent; - -import org.omegat.core.Core; -import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.data.TMXEntry; -import org.omegat.gui.dialogs.AboutDialog; -import org.omegat.gui.dialogs.LogDialog; -import org.omegat.gui.editor.EditorUtils; -import org.omegat.gui.editor.SegmentExportImport; -import org.omegat.gui.exttrans.MachineTranslationInfo; -import org.omegat.gui.filelist.IProjectFilesList; -import org.omegat.gui.filters2.FiltersCustomizerController; -import org.omegat.gui.preferences.PreferencesWindowController; -import org.omegat.gui.preferences.view.EditingBehaviorController; -import org.omegat.gui.segmentation.SegmentationCustomizerController; -import org.omegat.gui.stat.StatisticsWindow; -import org.omegat.util.Log; -import org.omegat.util.Preferences; -import org.omegat.util.StaticUtils; -import org.omegat.util.StringUtil; - -public class TestMainWindowMenuHandler extends BaseMainWindowMenuHandler { - - IMainWindow mainWindow; - - public TestMainWindowMenuHandler(IMainWindow mw) { - this.mainWindow = mw; - } - - /** - * Create a new project. - */ - public void projectNewMenuItemActionPerformed() { - ProjectUICommands.projectCreate(); - } - - public void projectExitMenuItemActionPerformed() { - mainWindow.getApplicationFrame().setVisible(false); - mainWindow.getApplicationFrame().setEnabled(false); - } - - public void viewFileListMenuItemActionPerformed() { - IProjectFilesList projWin = Core.getProjectFilesList(); - if (projWin == null) { - return; - } - projWin.setActive(!projWin.isActive()); - } - - public void editUndoMenuItemActionPerformed() { - Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (focused == Core.getNotes()) { - Core.getNotes().undo(); - } else { - Core.getEditor().undo(); - } - } - - public void editRedoMenuItemActionPerformed() { - Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (focused == Core.getNotes()) { - Core.getNotes().redo(); - } else { - Core.getEditor().redo(); - } - } - - public void editOverwriteTranslationMenuItemActionPerformed() { - } - - public void editInsertTranslationMenuItemActionPerformed() { - } - - public void editOverwriteMachineTranslationMenuItemActionPerformed() { - MachineTranslationInfo tr = Core.getMachineTranslatePane().getDisplayedTranslation(); - if (tr == null) { - Core.getMachineTranslatePane().forceLoad(); - } else if (!StringUtil.isEmpty(tr.result)) { - Core.getEditor().replaceEditText(tr.result, String.format("MT:[%s]", tr.translatorName)); - } - } - - /** - * replaces entire edited segment text with a the source text of a segment - * at cursor position - */ - public void editOverwriteSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); - if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { - toInsert = EditorUtils.replaceGlossaryEntries(toInsert); - } - Core.getEditor().replaceEditText(toInsert); - } - - /** inserts the source text of a segment at cursor position */ - public void editInsertSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - String toInsert = Core.getEditor().getCurrentEntry().getSrcText(); - if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) { - toInsert = EditorUtils.replaceGlossaryEntries(toInsert); - } - Core.getEditor().insertText(toInsert); - } - - /** select the source text of the current segment */ - public void editSelectSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - Core.getEditor().selectSourceText(); - } - - public void editExportSelectionMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - String selection = Core.getEditor().getSelectedText(); - if (selection == null) { - SourceTextEntry ste = Core.getEditor().getCurrentEntry(); - TMXEntry te = Core.getProject().getTranslationInfo(ste); - if (te.isTranslated()) { - selection = te.translation; - } else { - selection = ste.getSrcText(); - } - } - SegmentExportImport.exportCurrentSelection(selection); - } - - public void editSearchDictionaryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - String selection = Core.getEditor().getSelectedText(); - if (selection == null) { - SourceTextEntry ste = Core.getEditor().getCurrentEntry(); - selection = ste.getSrcText(); - } - Core.getDictionaries().searchText(selection); - } - - public void editCreateGlossaryEntryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - Core.getGlossary().showCreateGlossaryEntryDialog(Core.getMainWindow().getApplicationFrame()); - } - - public void editFindInProjectMenuItemActionPerformed() { - } - - void findInProjectReuseLastWindow() { - } - - public void editReplaceInProjectMenuItemActionPerformed() { - } - - private String getTrimmedSelectedTextInMainWindow() { - String selection = null; - Component component = mainWindow.getApplicationFrame().getMostRecentFocusOwner(); - if (component instanceof JTextComponent) { - selection = ((JTextComponent) component).getSelectedText(); - if (!StringUtil.isEmpty(selection)) { - selection = EditorUtils.removeDirectionChars(selection); - selection = selection.trim(); - } - } - return selection; - } - - /** Set active match to #1. */ - public void editSelectFuzzy1MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(0); - } - - /** Set active match to #2. */ - public void editSelectFuzzy2MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(1); - } - - /** Set active match to #3. */ - public void editSelectFuzzy3MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(2); - } - - /** Set active match to #4. */ - public void editSelectFuzzy4MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(3); - } - - /** Set active match to #5. */ - public void editSelectFuzzy5MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(4); - } - - /** Set active match to the next one */ - public void editSelectFuzzyNextMenuItemActionPerformed() { - Core.getMatcher().setNextActiveMatch(); - } - - /** Set active match to the previous one */ - public void editSelectFuzzyPrevMenuItemActionPerformed() { - Core.getMatcher().setPrevActiveMatch(); - } - - public void insertCharsLRMActionPerformed() { - Core.getEditor().insertText("\u200E"); - } - - public void insertCharsRLMActionPerformed() { - Core.getEditor().insertText("\u200F"); - } - - public void insertCharsLREActionPerformed() { - Core.getEditor().insertText("\u202A"); - } - - public void insertCharsRLEActionPerformed() { - Core.getEditor().insertText("\u202B"); - } - - public void insertCharsPDFActionPerformed() { - Core.getEditor().insertText("\u202C"); - } - - public void editMultipleDefaultActionPerformed() { - Core.getEditor().setAlternateTranslationForCurrentEntry(false); - } - - public void editMultipleAlternateActionPerformed() { - Core.getEditor().setAlternateTranslationForCurrentEntry(true); - } - - public void editRegisterUntranslatedMenuItemActionPerformed() { - Core.getEditor().registerUntranslated(); - } - - public void editRegisterEmptyMenuItemActionPerformed() { - Core.getEditor().registerEmptyTranslation(); - } - - public void editRegisterIdenticalMenuItemActionPerformed() { - Core.getEditor().registerIdenticalTranslation(); - } - - public void toolsShowStatisticsStandardMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.STANDARD) - .setVisible(true); - } - - public void toolsShowStatisticsMatchesMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.MATCHES) - .setVisible(true); - } - - public void toolsShowStatisticsMatchesPerFileMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), - StatisticsWindow.STAT_TYPE.MATCHES_PER_FILE).setVisible(true); - } - - public void optionsAutoCompleteShowAutomaticallyItemActionPerformed() { - /* - * Preferences.setPreference(Preferences. - * AC_SHOW_SUGGESTIONS_AUTOMATICALLY, - * mainWindow.menu.optionsAutoCompleteShowAutomaticallyItem.isSelected() - * ); - */ } - - public void optionsAutoCompleteHistoryCompletionMenuItemActionPerformed() { - /* - * Preferences.setPreference(Preferences.AC_HISTORY_COMPLETION_ENABLED, - * mainWindow.menu.optionsAutoCompleteHistoryCompletionMenuItem. - * isSelected()); - */ } - - public void optionsAutoCompleteHistoryPredictionMenuItemActionPerformed() { - /* - * Preferences.setPreference(Preferences.AC_HISTORY_PREDICTION_ENABLED, - * mainWindow.menu.optionsAutoCompleteHistoryPredictionMenuItem. - * isSelected()); - */ } - - public void optionsMTAutoFetchCheckboxMenuItemActionPerformed() { - /* - * boolean enabled = - * mainWindow.menu.optionsMTAutoFetchCheckboxMenuItem.isSelected(); - * Preferences.setPreference(Preferences.MT_AUTO_FETCH, enabled); - */ } - - public void optionsGlossaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { - /* - * Preferences.setPreference(Preferences.GLOSSARY_STEMMING, - * mainWindow.menu.optionsGlossaryFuzzyMatchingCheckBoxMenuItem. - * isSelected()); Preferences.save(); - */ } - - public void optionsDictionaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { - /* - * Preferences.setPreference(Preferences.DICTIONARY_FUZZY_MATCHING, - * mainWindow.menu.optionsDictionaryFuzzyMatchingCheckBoxMenuItem. - * isSelected()); Preferences.save(); - */ } - - /** - * Displays the filters setup dialog to allow customizing file filters in - * detail. - */ - public void optionsSetupFileFiltersMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), - FiltersCustomizerController.class); - } - - /** - * Displays the segmentation setup dialog to allow customizing the - * segmentation rules in detail. - */ - public void optionsSentsegMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), - SegmentationCustomizerController.class); - } - - /** - * Displays the workflow setup dialog to allow customizing the diverse - * workflow options. - */ - public void optionsWorkflowMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), - EditingBehaviorController.class); - } - - /** - * Restores defaults for all dockable parts. May be expanded in the future - * to reset the entire GUI to its defaults. - */ - public void viewRestoreGUIMenuItemActionPerformed() { - } - - public void optionsAccessConfigDirMenuItemActionPerformed() { - openFile(new File(StaticUtils.getConfigDir())); - } - - /** - * Show log - */ - public void helpLogMenuItemActionPerformed() { - new LogDialog(mainWindow.getApplicationFrame()).setVisible(true); - } - - public void helpAboutMenuItemActionPerformed() { - JDialog aboutDialog = new AboutDialog(mainWindow.getApplicationFrame()); - aboutDialog.setVisible(true); - } - - private void openFile(File file) { - Log.log("TestMainWindowMenuHanlder.openFile called with " + file.toString()); - } -} diff --git a/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java b/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java index aeada09dd3..4e197ffead 100644 --- a/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java +++ b/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java @@ -664,9 +664,6 @@ public JMenu getHelpMenu() { public JMenu getMenu(MenuKey marker) { return null; } - - public void invokeAction(String action, int modifiers) { - } }; public IMainMenu getMainMenu() { diff --git a/test/fixtures/org/omegat/core/TestCore.java b/test/fixtures/org/omegat/core/TestCore.java index bda24d9a09..de58c65a77 100644 --- a/test/fixtures/org/omegat/core/TestCore.java +++ b/test/fixtures/org/omegat/core/TestCore.java @@ -218,9 +218,6 @@ private JMenu getGotoMenu() { } return gotoMenu; } - - public void invokeAction(String action, int modifiers) { - } }; Core.setMainWindow(new IMainWindow() { diff --git a/test/src/org/omegat/gui/main/MainWindowMenuTest.java b/test/src/org/omegat/gui/main/MainWindowMenuTest.java index 0222b20f13..448288c9e2 100644 --- a/test/src/org/omegat/gui/main/MainWindowMenuTest.java +++ b/test/src/org/omegat/gui/main/MainWindowMenuTest.java @@ -25,24 +25,26 @@ package org.omegat.gui.main; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.awt.Component; import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Arrays; import java.util.List; -import java.util.Map; +import java.util.Locale; +import java.util.stream.Collectors; +import javax.swing.Action; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; +import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.Test; import org.openide.awt.Mnemonics; @@ -51,6 +53,7 @@ import org.omegat.util.OStrings; import org.omegat.util.Platform; import org.omegat.util.StaticUtils; +import org.omegat.util.StringUtil; import org.omegat.util.gui.MenuExtender; import org.omegat.util.gui.MenuExtender.MenuKey; import org.omegat.util.gui.MenuItemPager; @@ -62,45 +65,45 @@ public class MainWindowMenuTest extends TestCore { /** * Check MainWindow for all menu items action handlers exist. * - * @throws Exception */ @Test - public void testMenuActions() throws Exception { + public void testMenuActionsClassNames() { int count = 0; - Map existsMethods = new HashMap(); - - for (Method m : MainWindowMenuHandler.class.getDeclaredMethods()) { - if (Modifier.isPublic(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())) { - Class[] params = m.getParameterTypes(); - if (params.length == 0) { - existsMethods.put(m.getName(), m); - } - // Include menu items that take a modifier key. - if (params.length == 1 && params[0] == Integer.TYPE) { - existsMethods.put(m.getName(), m); - } - } - } + // List all the inner class implements Action + List actions = Arrays.stream(MainWindowMenuHandler.class.getDeclaredClasses()) + .filter(Action.class::isAssignableFrom) + .map(Class::getSimpleName).collect(Collectors.toList()); for (Field f : StaticUtils.getAllModelFields(MainWindowMenu.class)) { if (JMenuItem.class.isAssignableFrom(f.getType()) && f.getType() != JMenu.class) { count++; - String actionMethodName = f.getName() + "ActionPerformed"; - Method m; - try { - m = MainWindowMenuHandler.class.getMethod(actionMethodName); - } catch (NoSuchMethodException ignore) { - // See if the method accepts a modifier key argument. - m = MainWindowMenuHandler.class.getMethod(actionMethodName, Integer.TYPE); + String actionClassName = StringUtil.capitalizeFirst(f.getName(), Locale.ENGLISH) + "Action"; + if (!actions.contains(actionClassName)) { + fail("Action method or class not defined for " + actionClassName); + } else { + assertTrue(actions.remove(actionClassName)); } - assertNotNull("Action method not defined for " + f.getName(), m); - assertNotNull(existsMethods.remove(actionMethodName)); } } assertTrue("menu items not found", count > 30); assertTrue("There is action handlers in MainWindow which doesn't used in menu: " - + existsMethods.keySet(), existsMethods.isEmpty()); + + actions, actions.isEmpty()); + } + + @Test + public void testMenuActionCommandIsEqualsToShortcutKey() throws IllegalAccessException, NoSuchFieldException { + // shortcut keys are as same as field name of menu item + BaseMainWindowMenu testMenu = new TestMainMenu(); + testMenu.initComponents(); + for (Field f : FieldUtils.getAllFields(testMenu.getClass())) { + if (JMenuItem.class.isAssignableFrom(f.getType()) && f.getType() != JMenu.class) { + JMenuItem item = (JMenuItem) FieldUtils.readField(f, testMenu, true); + assertThat(f.getName()) + .as("JMenuItem field name should be as same as action command") + .isEqualTo(item.getActionCommand()); + } + } } @Test @@ -139,7 +142,7 @@ private String getLocalizedText(final String key) { static class TestMainMenu extends BaseMainWindowMenu { TestMainMenu() { - super(null, null); + super(); } @Override diff --git a/test/src/org/omegat/gui/shortcuts/PropertiesShortcutsTest.java b/test/src/org/omegat/gui/shortcuts/PropertiesShortcutsTest.java index f542a07412..d4345665eb 100644 --- a/test/src/org/omegat/gui/shortcuts/PropertiesShortcutsTest.java +++ b/test/src/org/omegat/gui/shortcuts/PropertiesShortcutsTest.java @@ -25,16 +25,20 @@ package org.omegat.gui.shortcuts; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; import java.io.InputStream; +import javax.swing.AbstractAction; +import javax.swing.Action; import javax.swing.InputMap; import javax.swing.JMenu; import javax.swing.JMenuBar; @@ -47,6 +51,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; + +import org.omegat.gui.main.MainWindowMenuHandler; import org.omegat.util.StaticUtils; /** @@ -263,4 +269,64 @@ public void testLoadBundled() { PropertiesShortcuts props = PropertiesShortcuts.loadBundled(BUNDLED_ROOT, USER_FILE_NAME); assertEquals(shortcuts.getData(), props.getData()); } + + /** + * Test bind key stroke override a value from action. + */ + @Test + public void testBindKeyStrokeOverAction() { + JMenuItem item = new JMenuItem(); + item.setAction(new TestSaveAction()); + assertThat(item.getAccelerator()).as("Configured by Action object").isEqualTo(CTRL_D); + shortcuts.bindKeyStrokes(item); + assertThat(item.getAccelerator()).as("Override by bindKeyStroke").isEqualTo(CTRL_S); + } + + /** + * Test accelarator key is null, when action value not set. + */ + @Test + public void testShortcutKeySetActionEmpty() { + JMenuItem item = new JMenuItem(); + Action action = new TestCutAction(); + item.setAction(action); + assertThat(action.getValue(Action.ACCELERATOR_KEY)).isNull(); + assertThat(item.getAccelerator()).as("Null when there is no accelarator key defined in action").isNull(); + } + + /** + * Test accelarator key configured from action object. + */ + @Test + public void testShortcutKeySetActionValue() { + Action action = new MainWindowMenuHandler.ProjectNewMenuItemAction(); + JMenuItem item = new JMenuItem(); + item.setAction(action); + KeyStroke stroke = PropertiesShortcuts.getMainMenuShortcuts().getKeyStroke("projectNewMenuItem"); + assertThat(item.getAccelerator()).as("Configured by Action object").isEqualTo(stroke); + } + + @SuppressWarnings("serial") + public static class TestSaveAction extends AbstractAction { + public TestSaveAction() { + putValue(Action.ACTION_COMMAND_KEY, TEST_SAVE); + putValue(Action.ACCELERATOR_KEY, CTRL_D); + } + + @Override + public void actionPerformed(final ActionEvent e) { + } + } + + @SuppressWarnings("serial") + public static class TestCutAction extends AbstractAction { + public TestCutAction() { + putValue(Action.ACTION_COMMAND_KEY, TEST_CUT); + putValue(Action.ACCELERATOR_KEY, null); + } + + @Override + public void actionPerformed(final ActionEvent e) { + } + } }