diff --git a/src/org/omegat/gui/accesstool/AccessTools.java b/src/org/omegat/gui/accesstool/AccessTools.java index d1705a4aba..88f8dcad2b 100644 --- a/src/org/omegat/gui/accesstool/AccessTools.java +++ b/src/org/omegat/gui/accesstool/AccessTools.java @@ -34,9 +34,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; +import java.util.Map; import java.util.stream.Collectors; +import javax.swing.Action; import javax.swing.Box; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; @@ -44,19 +45,14 @@ 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.MainMenuIcons; -import org.omegat.gui.main.MainWindow; -import org.omegat.gui.main.MainWindowMenuHandler; 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 @@ -72,15 +68,15 @@ public class AccessTools extends JPanel { private ProjectComboBoxModel projectComboBoxModel; private SourceComboBoxModel sourceComboBoxModel; - private final MainWindowMenuHandler mainWindowMenuHandler; private URI selectedProject = null; private static final int MAX_PATH_LENGTH_SHOWN = 25; private static final float CHECKBOX_HEIGHT_RATIO = 1.8f; + private final Map actions; - public AccessTools(final MainWindow mainWindow, final MainWindowMenuHandler mainWindowMenuHandler) { - this.mainWindowMenuHandler = mainWindowMenuHandler; + public AccessTools(Map actions) { + this.actions = actions; initComponents(); } @@ -123,13 +119,13 @@ 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")))); + searchButton = new JButton(); + searchButton.setAction(actions.get("EditFindInProjectMenuItem")); + 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(); + settingsButton.setAction(actions.get("OptionsPreferencesMenuItem")); + settingsButton.setText(""); settingsButton.setBorderPainted(false); // -- right side @@ -137,12 +133,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(); @@ -154,13 +144,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/main/BaseMainWindowMenu.java b/src/org/omegat/gui/main/BaseMainWindowMenu.java index 9e1e41fce1..f988863b85 100644 --- a/src/org/omegat/gui/main/BaseMainWindowMenu.java +++ b/src/org/omegat/gui/main/BaseMainWindowMenu.java @@ -51,6 +51,7 @@ 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; @@ -118,6 +119,7 @@ public abstract class BaseMainWindowMenu implements ActionListener, MenuListener /** MainWindow menu handler instance. */ protected final MainWindowMenuHandler mainWindowMenuHandler; + protected final Map actions; private final Map menus = new EnumMap<>(MenuExtender.MenuKey.class); @@ -125,6 +127,7 @@ public BaseMainWindowMenu(final MainWindow mainWindow, final MainWindowMenuHandler mainWindowMenuHandler) { this.mainWindow = mainWindow; this.mainWindowMenuHandler = mainWindowMenuHandler; + actions = MainWindowMenuHandler.getActions(); } @Override @@ -205,109 +208,110 @@ protected void createComponents() { optionsMenu = createMenu("MW_OPTIONSMENU", MenuExtender.MenuKey.OPTIONS); helpMenu = createMenu("TF_MENU_HELP", MenuExtender.MenuKey.HELP); - projectNewMenuItem = createMenuItem("TF_MENU_FILE_CREATE"); - projectTeamNewMenuItem = createMenuItem("TF_MENU_FILE_TEAM_CREATE"); - projectOpenMenuItem = createMenuItem("TF_MENU_FILE_OPEN"); + projectNewMenuItem = createMenuItemFromAction("ProjectNewMenuItem"); + projectTeamNewMenuItem = createMenuItemFromAction("ProjectTeamNewMenuItem"); + projectOpenMenuItem = createMenuItemFromAction("ProjectOpenMenuItem"); 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"); + projectClearRecentMenuItem = createMenuItemFromAction("ProjectClearRecentMenuItem"); + + projectReloadMenuItem = createMenuItemFromAction("ProjectReloadMenuItem"); + projectCloseMenuItem = createMenuItemFromAction("ProjectCloseMenuItem"); + projectSaveMenuItem = createMenuItemFromAction("ProjectSaveMenuItem"); + projectImportMenuItem = createMenuItemFromAction("ProjectImportMenuItem"); + projectWikiImportMenuItem = createMenuItemFromAction("ProjectWikiImportMenuItem"); + projectCommitSourceFiles = createMenuItemFromAction("ProjectCommitSourceFiles"); + projectCommitTargetFiles = createMenuItemFromAction("ProjectCommitTargetFiles"); + projectCompileMenuItem = createMenuItemFromAction("ProjectCompileMenuItem"); + projectSingleCompileMenuItem = createMenuItemFromAction("ProjectSingleCompileMenuItem"); + projectMedOpenMenuItem = createMenuItemFromAction("ProjectMedOpenMenuItem"); + projectMedCreateMenuItem = createMenuItemFromAction("ProjectMedCreateMenuItem"); + projectEditMenuItem = createMenuItemFromAction("ProjectEditMenuItem"); viewFileListMenuItem = createMenuItem("TF_MENU_FILE_PROJWIN"); 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"); - 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"); + projectAccessRootMenuItem = createMenuItemFromAction("ProjectAccessRootMenuItem"); + projectAccessDictionaryMenuItem = createMenuItemFromAction("ProjectAccessDictionaryMenuItem"); + projectAccessGlossaryMenuItem = createMenuItemFromAction("ProjectAccessGlossaryMenuItem"); + projectAccessSourceMenuItem = createMenuItemFromAction("ProjectAccessSourceMenuItem"); + projectAccessTargetMenuItem = createMenuItemFromAction("ProjectAccessTargetMenuItem"); + projectAccessTMMenuItem = createMenuItemFromAction("ProjectAccessTMMenuItem"); + projectAccessExportTMMenuItem = createMenuItemFromAction("ProjectAccessExportTMMenuItem"); + projectAccessCurrentSourceDocumentMenuItem = createMenuItemFromAction( + "ProjectAccessCurrentSourceDocumentMenuItem"); + projectAccessCurrentTargetDocumentMenuItem = createMenuItemFromAction( + "ProjectAccessCurrentTargetDocumentMenuItem"); + projectAccessWriteableGlossaryMenuItem = createMenuItemFromAction( + "ProjectAccessWriteableGlossaryMenuItem"); + + projectAccessRootMenuItem = createMenuItemFromAction("ProjectAccessRootMenuItem"); + projectAccessDictionaryMenuItem = createMenuItemFromAction("ProjectAccessDictionaryMenuItem"); + projectAccessGlossaryMenuItem = createMenuItemFromAction("ProjectAccessGlossaryMenuItem"); + projectAccessSourceMenuItem = createMenuItemFromAction("ProjectAccessSourceMenuItem"); + projectAccessTargetMenuItem = createMenuItemFromAction("ProjectAccessTargetMenuItem"); + projectAccessTMMenuItem = createMenuItemFromAction("ProjectAccessTMMenuItem"); + projectAccessExportTMMenuItem = createMenuItemFromAction("ProjectAccessExportTMMenuItem"); + projectAccessCurrentSourceDocumentMenuItem = createMenuItemFromAction( + "ProjectAccessCurrentSourceDocumentMenuItem"); + projectAccessCurrentTargetDocumentMenuItem = createMenuItemFromAction( + "ProjectAccessCurrentTargetDocumentMenuItem"); + projectAccessWriteableGlossaryMenuItem = createMenuItemFromAction( + "ProjectAccessWriteableGlossaryMenuItem"); + projectRestartMenuItem = createMenuItemFromAction("ProjectRestartMenuItem"); + projectExitMenuItem = createMenuItemFromAction("ProjectExitMenuItem"); + + editUndoMenuItem = createMenuItemFromAction("EditUndoMenuItem"); + editRedoMenuItem = createMenuItemFromAction("EditRedoMenuItem"); + editOverwriteTranslationMenuItem = createMenuItemFromAction("EditOverwriteTranslationMenuItem"); + editInsertTranslationMenuItem = createMenuItemFromAction("EditInsertTranslationMenuItem"); + editOverwriteSourceMenuItem = createMenuItemFromAction("EditOverwriteSourceMenuItem"); + editInsertSourceMenuItem = createMenuItemFromAction("EditInsertSourceMenuItem"); + editSelectSourceMenuItem = createMenuItemFromAction("EditSelectSourceMenuItem"); + editOverwriteMachineTranslationMenuItem = createMenuItemFromAction("EditOverwriteMachineTranslationMenuItem"); 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"); + editExportSelectionMenuItem = createMenuItemFromAction("EditExportSelectionMenuItem"); + editCreateGlossaryEntryMenuItem = createMenuItemFromAction("EditCreateGlossaryEntryMenuItem"); + editFindInProjectMenuItem = createMenuItemFromAction("EditFindInProjectMenuItem"); + editReplaceInProjectMenuItem = createMenuItemFromAction("EditReplaceInProjectMenuItem"); + editSearchDictionaryMenuItem = createMenuItemFromAction("EditSearchDictionaryMenuItem"); 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 = createMenuItemFromAction("EditSelectFuzzyPrevMenuItem"); + editSelectFuzzyNextMenuItem = createMenuItemFromAction("EditSelectFuzzyNextMenuItem"); + editSelectFuzzy1MenuItem = createMenuItemFromAction("EditSelectFuzzy1MenuItem"); + editSelectFuzzy2MenuItem = createMenuItemFromAction("EditSelectFuzzy2MenuItem"); + editSelectFuzzy3MenuItem = createMenuItemFromAction("EditSelectFuzzy3MenuItem"); + editSelectFuzzy4MenuItem = createMenuItemFromAction("EditSelectFuzzy4MenuItem"); + editSelectFuzzy5MenuItem = createMenuItemFromAction("EditSelectFuzzy5MenuItem"); 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"); + insertCharsLRM = createMenuItemFromAction("InsertCharsLRM"); + insertCharsRLM = createMenuItemFromAction("InsertCharsRLM"); + insertCharsLRE = createMenuItemFromAction("InsertCharsLRE"); + insertCharsRLE = createMenuItemFromAction("InsertCharsRLE"); + insertCharsPDF = createMenuItemFromAction("InsertCharsPDF"); + + editMultipleDefault = createMenuItemFromAction("EditMultipleDefault"); + editMultipleAlternate = createMenuItemFromAction("EditMultipleAlternate"); + editRegisterUntranslatedMenuItem = createMenuItemFromAction("EditRegisterUntranslatedMenuItem"); + editRegisterEmptyMenuItem = createMenuItemFromAction("EditRegisterEmptyMenuItem"); + editRegisterIdenticalMenuItem = createMenuItemFromAction("EditRegisterIdenticalMenuItem"); + + lowerCaseMenuItem = createMenuItemFromAction("LowerCaseMenuItem"); + upperCaseMenuItem = createMenuItemFromAction("UpperCaseMenuItem"); + titleCaseMenuItem = createMenuItemFromAction("TitleCaseMenuItem"); + sentenceCaseMenuItem = createMenuItemFromAction("SentenceCaseMenuItem"); + cycleSwitchCaseMenuItem = createMenuItemFromAction("CycleSwitchCaseMenuItem"); + + gotoNextUntranslatedMenuItem = createMenuItemFromAction("GotoNextUntranslatedMenuItem"); + gotoNextTranslatedMenuItem = createMenuItemFromAction("GotoNextTranslatedMenuItem"); + gotoNextSegmentMenuItem = createMenuItemFromAction("GotoNextSegmentMenuItem"); 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"); + gotoNextUniqueMenuItem = createMenuItemFromAction("GotoNextUniqueMenuItem"); gotoMatchSourceSegment = createMenuItem("TF_MENU_GOTO_SELECTED_MATCH_SOURCE"); gotoXEntrySubmenu = createMenu("TF_MENU_GOTO_X_SUBMENU"); @@ -382,7 +386,7 @@ protected void createComponents() { toolsShowStatisticsMatchesMenuItem = createMenuItem("TF_MENU_TOOLS_STATISTICS_MATCHES"); toolsShowStatisticsMatchesPerFileMenuItem = createMenuItem( "TF_MENU_TOOLS_STATISTICS_MATCHES_PER_FILE"); - optionsPreferencesMenuItem = createMenuItem("MW_OPTIONSMENU_PREFERENCES"); + optionsPreferencesMenuItem = createMenuItemFromAction("OptionsPreferencesMenuItem"); optionsMachineTranslateMenu = createMenu("TF_OPTIONSMENU_MACHINETRANSLATE"); @@ -409,8 +413,8 @@ protected void createComponents() { optionsAccessConfigDirMenuItem = createMenuItem("MW_OPTIONSMENU_ACCESS_CONFIG_DIR"); helpContentsMenuItem = createMenuItem("TF_MENU_HELP_CONTENTS"); - helpAboutMenuItem = createMenuItem("TF_MENU_HELP_ABOUT"); - helpLastChangesMenuItem = createMenuItem("TF_MENU_HELP_LAST_CHANGES"); + helpAboutMenuItem = createMenuItemFromAction("HelpAboutMenuItem"); + helpLastChangesMenuItem = createMenuItemFromAction("HelpLastChangesMenuItem"); helpLogMenuItem = createMenuItem("TF_MENU_HELP_LOG"); helpUpdateCheckMenuItem = createMenuItem("TF_MENU_HELP_CHECK_FOR_UPDATES"); @@ -760,6 +764,26 @@ protected JMenuItem createMenuItem(String titleKey) { return result; } + protected JMenuItem createMenuItemFromAction(String commandKey) { + Action action = actions.get(commandKey); + if (action == null) { + throw new RuntimeException("Unexpected error when creating a menu item." + commandKey); + } + JMenuItem item = new JMenuItem(); + item.setAction(action); + item.setIcon(null); + return item; + } + + protected JMenuItem createMenuItem(String titleKey, String name) { + JMenuItem result = new JMenuItem(); + result.setName(name); + Action action = actions.get(name); + Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); + result.addActionListener(action); + return result; + } + /** * Create menu item instance and set title. * @@ -928,10 +952,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(actions.get("ProjectExitMenuItem")); + OSXIntegration.setAboutHandler(actions.get("HelpAboutMenuItem")); + OSXIntegration.setPreferencesHandler(actions.get("OptionsPreferencesMenuItem")); } catch (NoClassDefFoundError e) { Log.log(e); } diff --git a/src/org/omegat/gui/main/ConsoleWindow.java b/src/org/omegat/gui/main/ConsoleWindow.java index 30aa0a3003..8fc23ea093 100644 --- a/src/org/omegat/gui/main/ConsoleWindow.java +++ b/src/org/omegat/gui/main/ConsoleWindow.java @@ -31,6 +31,7 @@ import javax.swing.JFrame; +import org.omegat.gui.search.SearchWindowController; import org.omegat.util.OStrings; import org.omegat.util.RuntimePreferences; import org.omegat.util.StringUtil; @@ -142,6 +143,18 @@ public DockingDesktop getDesktop() { return null; } + @Override + public void doRecycleTrans() { + } + + @Override + public void doInsertTrans() { + } + + @Override + public void addSearchWindow(final SearchWindowController search) { + } + public Cursor getCursor() { return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } diff --git a/src/org/omegat/gui/main/IMainWindow.java b/src/org/omegat/gui/main/IMainWindow.java index 50b7f7b6ba..3de35051b1 100644 --- a/src/org/omegat/gui/main/IMainWindow.java +++ b/src/org/omegat/gui/main/IMainWindow.java @@ -31,6 +31,8 @@ import javax.swing.JFrame; +import org.omegat.gui.search.SearchWindowController; + import com.vlsolutions.swing.docking.Dockable; import com.vlsolutions.swing.docking.DockingDesktop; @@ -204,4 +206,10 @@ public interface IMainWindow { * Retrieve main docking desktop. */ DockingDesktop getDesktop(); + + void doRecycleTrans(); + + void doInsertTrans(); + + void addSearchWindow(SearchWindowController search); } diff --git a/src/org/omegat/gui/main/MainWindow.java b/src/org/omegat/gui/main/MainWindow.java index 37a8fbe94a..d2bec5a209 100644 --- a/src/org/omegat/gui/main/MainWindow.java +++ b/src/org/omegat/gui/main/MainWindow.java @@ -208,7 +208,7 @@ private void initMainMenu() { applicationFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { - mainWindowMenuHandler.projectExitMenuItemActionPerformed(); + MainWindowMenuHandler.projectExitAction(); } @Override @@ -362,7 +362,7 @@ private String getSelectedTextInMatcher() { return matcher instanceof JTextComponent ? ((JTextComponent) matcher).getSelectedText() : null; } - protected void addSearchWindow(final SearchWindowController newSearchWindow) { + public void addSearchWindow(final SearchWindowController newSearchWindow) { newSearchWindow.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { diff --git a/src/org/omegat/gui/main/MainWindowBurgerMenu.java b/src/org/omegat/gui/main/MainWindowBurgerMenu.java index 689f2e950e..e9129b628a 100644 --- a/src/org/omegat/gui/main/MainWindowBurgerMenu.java +++ b/src/org/omegat/gui/main/MainWindowBurgerMenu.java @@ -69,6 +69,6 @@ void createMenuBar() { burgerMenu.add(helpMenu); burgerMenu.add(burgerMenu); mainMenu.add(burgerMenu); - mainMenu.add(new AccessTools(mainWindow, mainWindowMenuHandler)); + mainMenu.add(new AccessTools(MainWindowMenuHandler.getActions())); } } diff --git a/src/org/omegat/gui/main/MainWindowMenuHandler.java b/src/org/omegat/gui/main/MainWindowMenuHandler.java index 765464e959..a50b6385ac 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 @@ -40,19 +41,26 @@ import java.awt.KeyboardFocusManager; import java.awt.event.ActionEvent; import java.io.File; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.regex.Pattern; +import javax.swing.Action; import javax.swing.JOptionPane; import javax.swing.SwingWorker; +import javax.swing.UIManager; import javax.swing.text.JTextComponent; +import org.omegat.util.gui.ResourcesUtil; +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; @@ -107,7 +115,6 @@ * @author Aaron Madlon-Kay */ public final class MainWindowMenuHandler { - private static final String PROP_ORIGIN = ProjectTMX.PROP_ORIGIN; private final MainWindow mainWindow; @@ -115,90 +122,302 @@ public MainWindowMenuHandler(final MainWindow mainWindow) { this.mainWindow = mainWindow; } + private static final Action[] ACTIONS = { + new ProjectNewMenuItemAction(), + new ProjectTeamNewMenuItemAction(), + new ProjectOpenMenuItemAction(), + new ProjectCloseMenuItemAction(), + new ProjectClearRecentMenuItemAction(), + new ProjectImportMenuItemAction(), + new ProjectWikiImportMenuItemAction(), + new ProjectSaveMenuItemAction(), + new ProjectReloadMenuItemAction(), + new ProjectCommitSourceFilesAction(), + new ProjectCommitTargetFilesAction(), + new ProjectCompileMenuItemAction(), + new ProjectSingleCompileMenuItemAction(), + new ProjectMedOpenMenuItemAction(), + new ProjectMedCreateMenuItemAction(), + new ProjectEditMenuItemAction(), + new ProjectAccessRootMenuItemAction(), + new ProjectAccessDictionaryMenuItemAction(), + new ProjectAccessGlossaryMenuItemAction(), + new ProjectAccessSourceMenuItemAction(), + new ProjectAccessTargetMenuItemAction(), + new ProjectAccessTMMenuItemAction(), + new ProjectAccessExportTMMenuItemAction(), + new ProjectRestartMenuItemAction(), + new ProjectExitMenuItemAction(), + new ProjectAccessCurrentSourceDocumentMenuItemAction(), + new ProjectAccessCurrentTargetDocumentMenuItemAction(), + new ProjectAccessWriteableGlossaryMenuItemAction(), + new EditUndoMenuItemAction(), + new EditRedoMenuItemAction(), + new EditFindInProjectMenuItemAction(), + new EditOverwriteTranslationMenuItemAction(), + new EditInsertSourceMenuItemAction(), + new EditSelectSourceMenuItemAction(), + new EditInsertTranslationMenuItemAction(), + new EditOverwriteMachineTranslationMenuItemAction(), + new EditReplaceInProjectMenuItemAction(), + new EditExportSelectionMenuItemAction(), + new EditOverwriteSourceMenuItemAction(), + new EditSearchDictionaryMenuItemAction(), + new EditCreateGlossaryEntryMenuItemAction(), + new EditSelectFuzzy1MenuItemAction(), + new EditSelectFuzzy2MenuItemAction(), + new EditSelectFuzzy3MenuItemAction(), + new EditSelectFuzzy4MenuItemAction(), + new EditSelectFuzzy5MenuItemAction(), + new EditSelectFuzzyPrevMenuItemAction(), + new EditSelectFuzzyNextMenuItemAction(), + new InsertCharsLRMAction(), + new InsertCharsRLMAction(), + new InsertCharsLREAction(), + new InsertCharsRLEAction(), + new InsertCharsPDFAction(), + new EditMultipleDefaultAction(), + new EditMultipleAlternateAction(), + new EditRegisterUntranslatedMenuItemAction(), + new EditRegisterEmptyMenuItemAction(), + new EditRegisterIdenticalMenuItemAction(), + new TitleCaseMenuItemAction(), + new SentenceCaseMenuItemAction(), + new CycleSwitchCaseMenuItemAction(), + new UpperCaseMenuItemAction(), + new LowerCaseMenuItemAction(), + new GotoNextUntranslatedMenuItemAction(), + new GotoNextUniqueMenuItemAction(), + new GotoNextTranslatedMenuItemAction(), + new GotoNextSegmentMenuItemAction(), + new OptionsPreferencesMenuItemAction(), + new HelpAboutMenuItemAction(), + new HelpLastChangesMenuItemAction() + }; + + public static Map getActions() { + Map result = new HashMap<>(); + for (Action a: ACTIONS) { + result.put(a.getValue(Action.ACTION_COMMAND_KEY), a); + } + return result; + } + /** - * Create new project. + * Create a new project. */ - public void projectNewMenuItemActionPerformed() { - ProjectUICommands.projectCreate(); - } + @SuppressWarnings("serial") + public static class ProjectNewMenuItemAction extends AbstractMnemonicsAction { + public ProjectNewMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_CREATE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectNewMenuItem"); + } + @Override + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectCreate(); + } + } /** - * Create new team project. + * Create a new team project. */ - public void projectTeamNewMenuItemActionPerformed() { - ProjectUICommands.projectTeamCreate(); + @SuppressWarnings("serial") + public static class ProjectTeamNewMenuItemAction extends AbstractMnemonicsAction { + public ProjectTeamNewMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_TEAM_CREATE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectTeamNewMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectTeamCreate(); + } } /** * Open project. */ - public void projectOpenMenuItemActionPerformed() { - ProjectUICommands.projectOpen(null); + @SuppressWarnings("serial") + public static class ProjectOpenMenuItemAction extends AbstractMnemonicsAction { + public ProjectOpenMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_OPEN"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectOpenMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectOpen(null); + } } - public void projectClearRecentMenuItemActionPerformed() { - RecentProjects.clear(); + @SuppressWarnings("serial") + public static class ProjectClearRecentMenuItemAction extends AbstractMnemonicsAction { + public ProjectClearRecentMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_CLEAR_RECENT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectClearRecentMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + RecentProjects.clear(); + } } /** * Open MED project. */ - public void projectMedOpenMenuItemActionPerformed() { - ProjectUICommands.projectOpenMED(); + @SuppressWarnings("serial") + public static class ProjectMedOpenMenuItemAction extends AbstractMnemonicsAction { + public ProjectMedOpenMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_MED_OPEN"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectMedOpenMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectOpenMED(); + } } /** * Create MED project. */ - public void projectMedCreateMenuItemActionPerformed() { - ProjectUICommands.projectCreateMED(); + @SuppressWarnings("serial") + public static class ProjectMedCreateMenuItemAction extends AbstractMnemonicsAction { + public ProjectMedCreateMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_MED_CREATE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectMedCreateMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectCreateMED(); + } } /** * Imports the file/files/folder into project's source files. */ - public void projectImportMenuItemActionPerformed() { - ProjectUICommands.doPromptImportSourceFiles(); + @SuppressWarnings("serial") + public static class ProjectImportMenuItemAction extends AbstractMnemonicsAction { + public ProjectImportMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_IMPORT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectImportMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.doPromptImportSourceFiles(); + } } - public void projectWikiImportMenuItemActionPerformed() { - ProjectUICommands.doWikiImport(); + @SuppressWarnings("serial") + public static class ProjectWikiImportMenuItemAction extends AbstractMnemonicsAction { + public ProjectWikiImportMenuItemAction() { + super(OStrings.getString("TF_MENU_WIKI_IMPORT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectWikiImportMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.doWikiImport(); + } } - public void projectReloadMenuItemActionPerformed() { - ProjectUICommands.projectReload(); + @SuppressWarnings("serial") + public static class ProjectReloadMenuItemAction extends AbstractMnemonicsAction { + public ProjectReloadMenuItemAction() { + super(OStrings.getString("TF_MENU_PROJECT_RELOAD"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectReloadMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectReload(); + } } /** * Close project. */ - public void projectCloseMenuItemActionPerformed() { - ProjectUICommands.projectClose(); + @SuppressWarnings("serial") + public static class ProjectCloseMenuItemAction extends AbstractMnemonicsAction { + public ProjectCloseMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_CLOSE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectCloseMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectClose(); + } } /** * Save project. */ - public void projectSaveMenuItemActionPerformed() { - ProjectUICommands.projectSave(); + @SuppressWarnings("serial") + public static class ProjectSaveMenuItemAction extends AbstractMnemonicsAction { + public ProjectSaveMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_SAVE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectSaveMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectSave(); + } } /** * Create translated documents. */ - public void projectCompileMenuItemActionPerformed() { - if (!checkTags()) { - return; + @SuppressWarnings("serial") + public static class ProjectCompileMenuItemAction extends AbstractMnemonicsAction { + public ProjectCompileMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_COMPILE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectCompileMenuItem"); } - ProjectUICommands.projectCompile(); + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!checkTags()) { + return; + } + + ProjectUICommands.projectCompile(); + } } /** * Check whether tags are OK * @return false is there is a tag issue, true otherwise */ - private boolean checkTags() { + private static boolean checkTags() { if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) { List stes = Core.getTagValidation().listInvalidTags(); if (!stes.isEmpty()) { @@ -209,46 +428,106 @@ private boolean checkTags() { return true; } - public void projectCommitTargetFilesActionPerformed() { - if (!checkTags()) { - return; + @SuppressWarnings("serial") + public static class ProjectCommitTargetFilesAction extends AbstractMnemonicsAction { + public ProjectCommitTargetFilesAction() { + super(OStrings.getString("TF_MENU_FILE_TARGET"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectCommitTargetFiles"); } - ProjectUICommands.projectCompileAndCommit(); + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!checkTags()) { + return; + } + + ProjectUICommands.projectCompileAndCommit(); + + } } /** * Commit source files */ - public void projectCommitSourceFilesActionPerformed() { - ProjectUICommands.projectCommitSourceFiles(); + @SuppressWarnings("serial") + public static class ProjectCommitSourceFilesAction extends AbstractMnemonicsAction { + public ProjectCommitSourceFilesAction() { + super(OStrings.getString("TF_MENU_FILE_COMMIT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectCommitSourceFiles"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectCommitSourceFiles(); + } } /** * Create current translated document. */ - public void projectSingleCompileMenuItemActionPerformed() { - String midName = Core.getEditor().getCurrentFile(); - if (StringUtil.isEmpty(midName)) { - return; + @SuppressWarnings("serial") + public static class ProjectSingleCompileMenuItemAction extends AbstractMnemonicsAction { + public ProjectSingleCompileMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_SINGLE_COMPILE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectSingleCompileMenuItem"); } - 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) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + + 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(); + @SuppressWarnings("serial") + public static class ProjectEditMenuItemAction extends AbstractMnemonicsAction { + public ProjectEditMenuItemAction() { + super(OStrings.getString("MW_PROJECTMENU_EDIT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectEditMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + ProjectUICommands.projectEditProperties(); + } + } + + /* + @SupressWarnings("serial") + public static class ViewFileListMenuItemAction extends AbstractAction { + public ViewFileListMenuItemAction() { + super("view-file-list"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + + } } + */ public void viewFileListMenuItemActionPerformed() { IProjectFilesList projWin = Core.getProjectFilesList(); @@ -260,110 +539,268 @@ public void viewFileListMenuItemActionPerformed() { projWin.setActive(!projWin.isActive()); } - public void projectAccessRootMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessRootMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessRootMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_ROOT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessRootMenuItem"); } - 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) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getProjectRoot(); + openFile(new File(path)); + } - String path = Core.getProject().getProjectProperties().getDictRoot(); - openFile(new File(path)); } - public void projectAccessGlossaryMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessDictionaryMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessDictionaryMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_DICTIONARY"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessDictionaryMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getDictRoot(); + openFile(new File(path)); } - String path = Core.getProject().getProjectProperties().getGlossaryRoot(); - openFile(new File(path)); } - public void projectAccessSourceMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessGlossaryMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessGlossaryMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_GLOSSARY"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessGlossaryMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getGlossaryRoot(); + openFile(new File(path)); } - String path = Core.getProject().getProjectProperties().getSourceRoot(); - openFile(new File(path)); } - public void projectAccessTargetMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessSourceMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_SOURCE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessSourceMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getSourceRoot(); + openFile(new File(path)); + } - String path = Core.getProject().getProjectProperties().getTargetRoot(); - openFile(new File(path)); } - public void projectAccessTMMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessTargetMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessTargetMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_TARGET"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessTargetMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getTargetRoot(); + openFile(new File(path)); } - String path = Core.getProject().getProjectProperties().getTMRoot(); - openFile(new File(path)); } - public void projectAccessExportTMMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessTMMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessTMMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_TM"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessTMMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getTMRoot(); + openFile(new File(path)); } - String path = Core.getProject().getProjectProperties().getExportTMRoot(); - openFile(new File(path)); } - public void projectAccessCurrentSourceDocumentMenuItemActionPerformed(int modifier) { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessExportTMMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessExportTMMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_EXPORT_TM"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessExportTMMenuItem"); } - String root = Core.getProject().getProjectProperties().getSourceRoot(); - String path = Core.getEditor().getCurrentFile(); - if (StringUtil.isEmpty(path)) { - return; + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getExportTMRoot(); + openFile(new File(path)); + } - File toOpen = new File(root, path); - if ((modifier & ActionEvent.ALT_MASK) != 0) { - toOpen = toOpen.getParentFile(); + } + + @SuppressWarnings("serial") + public static class ProjectAccessCurrentSourceDocumentMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessCurrentSourceDocumentMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_CURRENT_SOURCE_DOCUMENT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessCurrentSourceDocumentMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + 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(); + } + openFile(toOpen); } - openFile(toOpen); } - public void projectAccessCurrentTargetDocumentMenuItemActionPerformed(int modifier) { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class ProjectAccessCurrentTargetDocumentMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessCurrentTargetDocumentMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_CURRENT_TARGET_DOCUMENT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessCurrentTargetDocumentMenuItem"); } - String root = Core.getProject().getProjectProperties().getTargetRoot(); - String path = Core.getEditor().getCurrentTargetFile(); - if (StringUtil.isEmpty(path)) { - return; + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + 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(); + } + openFile(toOpen); } - File toOpen = new File(root, path); - if ((modifier & ActionEvent.ALT_MASK) != 0) { - toOpen = toOpen.getParentFile(); + } + + @SuppressWarnings("serial") + public static class ProjectAccessWriteableGlossaryMenuItemAction extends AbstractMnemonicsAction { + public ProjectAccessWriteableGlossaryMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_ACCESS_WRITEABLE_GLOSSARY"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectAccessWriteableGlossaryMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + if (!Core.getProject().isProjectLoaded()) { + return; + } + String path = Core.getProject().getProjectProperties().getWriteableGlossary(); + if (StringUtil.isEmpty(path)) { + return; + } + File toOpen = new File(path); + int modifier = e.getModifiers(); + if ((modifier & ActionEvent.ALT_MASK) != 0) { + toOpen = toOpen.getParentFile(); + } + openFile(toOpen); + } - openFile(toOpen); } - public void projectAccessWriteableGlossaryMenuItemActionPerformed(int modifier) { - if (!Core.getProject().isProjectLoaded()) { - return; + /** Quits OmegaT */ + @SuppressWarnings("serial") + public static class ProjectExitMenuItemAction extends AbstractMnemonicsAction { + public ProjectExitMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_QUIT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectExitMenuItem"); } - String path = Core.getProject().getProjectProperties().getWriteableGlossary(); - if (StringUtil.isEmpty(path)) { - return; + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + prepareForExit(() -> System.exit(0)); + } + } + + /** Restart OmegaT */ + @SuppressWarnings("serial") + public static class ProjectRestartMenuItemAction extends AbstractMnemonicsAction { + public ProjectRestartMenuItemAction() { + super(OStrings.getString("TF_MENU_FILE_RESTART"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "ProjectRestartMenuItem"); } - File toOpen = new File(path); - if ((modifier & ActionEvent.ALT_MASK) != 0) { - toOpen = toOpen.getParentFile(); + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + String projectDir = Core.getProject().isProjectLoaded() + ? Core.getProject().getProjectProperties().getProjectRoot() + : null; + prepareForExit(() -> { + Main.restartGUI(projectDir); + }); } - openFile(toOpen); } - private void openFile(File path) { + protected static void projectExitAction() { + prepareForExit(() -> System.exit(0)); + } + + private static void openFile(File path) { try { path = path.getCanonicalFile(); // Normalize file name in case it is displayed } catch (Exception ex) { @@ -381,22 +818,7 @@ private void openFile(File path) { } } - /** Quits OmegaT */ - public void projectExitMenuItemActionPerformed() { - prepareForExit(() -> System.exit(0)); - } - - /** Restart OmegaT */ - public void projectRestartMenuItemActionPerformed() { - String projectDir = Core.getProject().isProjectLoaded() - ? Core.getProject().getProjectProperties().getProjectRoot() - : null; - prepareForExit(() -> { - Main.restartGUI(projectDir); - }); - } - - protected void prepareForExit(Runnable onCompletion) { + private 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()) { @@ -410,7 +832,7 @@ protected void prepareForExit(Runnable onCompletion) { // 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(), + if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Core.getMainWindow().getApplicationFrame(), OStrings.getString("MW_QUIT_CONFIRM"), OStrings.getString("CONFIRM_DIALOG_TITLE"), JOptionPane.YES_NO_OPTION)) { return; @@ -448,7 +870,7 @@ protected void done() { try { get(); - MainWindowUI.saveScreenLayout(mainWindow); + MainWindowUI.saveScreenLayout((MainWindow) Core.getMainWindow()); Preferences.save(); @@ -461,119 +883,243 @@ protected void done() { }.execute(); } - public void editUndoMenuItemActionPerformed() { - Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (focused == Core.getNotes()) { - Core.getNotes().undo(); - } else { - Core.getEditor().undo(); + @SuppressWarnings("serial") + public static class EditUndoMenuItemAction extends AbstractMnemonicsAction { + + public EditUndoMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_UNDO"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditUndoMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + 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(); + /** Quits OmegaT */ + @SuppressWarnings("serial") + public static class EditRedoMenuItemAction extends AbstractMnemonicsAction { + public EditRedoMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_REDO"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditRedoMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + String action = e.getActionCommand(); + Log.logInfoRB("LOG_MENU_CLICK", action); + Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + if (focused == Core.getNotes()) { + Core.getNotes().redo(); + } else { + Core.getEditor().redo(); + } } } - public void editOverwriteTranslationMenuItemActionPerformed() { - mainWindow.doRecycleTrans(); + @SuppressWarnings("serial") + public static class EditOverwriteTranslationMenuItemAction extends AbstractMnemonicsAction { + + public EditOverwriteTranslationMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_RECYCLE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditOverwriteTranslationMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMainWindow().doRecycleTrans(); + } } - public void editInsertTranslationMenuItemActionPerformed() { - mainWindow.doInsertTrans(); + @SuppressWarnings("serial") + public static class EditInsertTranslationMenuItemAction extends AbstractMnemonicsAction { + public EditInsertTranslationMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditInsertTranslationMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMainWindow().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)); + @SuppressWarnings("serial") + public static class EditOverwriteMachineTranslationMenuItemAction extends AbstractMnemonicsAction { + + public EditOverwriteMachineTranslationMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_OVERWRITE_MACHITE_TRANSLATION"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditOverwriteMachineTranslationMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + 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; + @SuppressWarnings("serial") + public static class EditOverwriteSourceMenuItemAction extends AbstractMnemonicsAction { + + public EditOverwriteSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SOURCE_OVERWRITE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditOverwriteSourceMenuItem"); } - 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) { + 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; + @SuppressWarnings("serial") + public static class EditInsertSourceMenuItemAction extends AbstractMnemonicsAction { + + public EditInsertSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SOURCE_INSERT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditInsertSourceMenuItem"); } - 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) { + 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; + @SuppressWarnings("serial") + public static class EditSelectSourceMenuItemAction extends AbstractMnemonicsAction { + + public EditSelectSourceMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SOURCE_SELECT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectSourceMenuItem"); + } + @Override + public void actionPerformed(ActionEvent e) { + if (!Core.getProject().isProjectLoaded()) { + return; + } + Core.getEditor().selectSourceText(); } - Core.getEditor().selectSourceText(); } - public void editExportSelectionMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class EditExportSelectionMenuItemAction extends AbstractMnemonicsAction { + + public EditExportSelectionMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_EXPORT_SELECTION"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditExportSelectionMenuItem"); } - 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) { + 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; + @SuppressWarnings("serial") + public static class EditSearchDictionaryMenuItemAction extends AbstractMnemonicsAction { + public EditSearchDictionaryMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_SEARCH_DICTIONARY"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSearchDictionaryMenuItem"); } - String selection = Core.getEditor().getSelectedText(); - if (selection == null) { - SourceTextEntry ste = Core.getEditor().getCurrentEntry(); - selection = ste.getSrcText(); + + @Override + public void actionPerformed(ActionEvent e) { + 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; + @SuppressWarnings("serial") + public static class EditCreateGlossaryEntryMenuItemAction extends AbstractMnemonicsAction { + public EditCreateGlossaryEntryMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_CREATE_GLOSSARY_ENTRY"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditCreateGlossaryEntryMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (!Core.getProject().isProjectLoaded()) { + return; + } + Core.getGlossary().showCreateGlossaryEntryDialog(Core.getMainWindow().getApplicationFrame()); } - Core.getGlossary().showCreateGlossaryEntryDialog(Core.getMainWindow().getApplicationFrame()); } - public void editFindInProjectMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class EditFindInProjectMenuItemAction extends AbstractMnemonicsAction { + public EditFindInProjectMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_FIND"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditFindInProjectMenuItem"); + putValue(Action.SMALL_ICON, Objects.requireNonNullElseGet(UIManager.getIcon("OmegaT.newUI.search.icon"), + () -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.search.png")))); } - SearchWindowController search = new SearchWindowController(SearchMode.SEARCH); - mainWindow.addSearchWindow(search); - search.makeVisible(getTrimmedSelectedTextInMainWindow()); + @Override + public void actionPerformed(ActionEvent e) { + editFindInProject(); + } + } + + private static void editFindInProject() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + SearchWindowController search = new SearchWindowController(SearchMode.SEARCH); + Core.getMainWindow().addSearchWindow(search); + + search.makeVisible(getTrimmedSelectedTextInMainWindow()); } void findInProjectReuseLastWindow() { @@ -589,22 +1135,32 @@ void findInProjectReuseLastWindow() { return; } } - editFindInProjectMenuItemActionPerformed(); + editFindInProject(); } - public void editReplaceInProjectMenuItemActionPerformed() { - if (!Core.getProject().isProjectLoaded()) { - return; + @SuppressWarnings("serial") + public static class EditReplaceInProjectMenuItemAction extends AbstractMnemonicsAction { + + public EditReplaceInProjectMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_REPLACE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditReplaceInProjectMenuItem"); } - SearchWindowController search = new SearchWindowController(SearchMode.REPLACE); - mainWindow.addSearchWindow(search); - search.makeVisible(getTrimmedSelectedTextInMainWindow()); + @Override + public void actionPerformed(final ActionEvent e) { + if (!Core.getProject().isProjectLoaded()) { + return; + } + SearchWindowController search = new SearchWindowController(SearchMode.REPLACE); + Core.getMainWindow().addSearchWindow(search); + + search.makeVisible(getTrimmedSelectedTextInMainWindow()); + } } - private String getTrimmedSelectedTextInMainWindow() { + private static String getTrimmedSelectedTextInMainWindow() { String selection = null; - Component component = mainWindow.getApplicationFrame().getMostRecentFocusOwner(); + Component component = Core.getMainWindow().getApplicationFrame().getMostRecentFocusOwner(); if (component instanceof JTextComponent) { selection = ((JTextComponent) component).getSelectedText(); if (!StringUtil.isEmpty(selection)) { @@ -616,121 +1172,367 @@ private String getTrimmedSelectedTextInMainWindow() { } /** Set active match to #1. */ - public void editSelectFuzzy1MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(0); + @SuppressWarnings("serial") + public static class EditSelectFuzzy1MenuItemAction extends AbstractMnemonicsAction { + public EditSelectFuzzy1MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_1"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzy1MenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMatcher().setActiveMatch(0); + } } /** Set active match to #2. */ - public void editSelectFuzzy2MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(1); + @SuppressWarnings("serial") + public static class EditSelectFuzzy2MenuItemAction extends AbstractMnemonicsAction { + public EditSelectFuzzy2MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_2"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzy2MenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMatcher().setActiveMatch(1); + } } /** Set active match to #3. */ - public void editSelectFuzzy3MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(2); + @SuppressWarnings("serial") + public static class EditSelectFuzzy3MenuItemAction extends AbstractMnemonicsAction { + public EditSelectFuzzy3MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_3"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzy3MenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMatcher().setActiveMatch(2); + } } /** Set active match to #4. */ - public void editSelectFuzzy4MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(3); + @SuppressWarnings("serial") + public static class EditSelectFuzzy4MenuItemAction extends AbstractMnemonicsAction { + public EditSelectFuzzy4MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_4"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzy4MenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMatcher().setActiveMatch(3); + } } /** Set active match to #5. */ - public void editSelectFuzzy5MenuItemActionPerformed() { - Core.getMatcher().setActiveMatch(4); + @SuppressWarnings("serial") + public static class EditSelectFuzzy5MenuItemAction extends AbstractMnemonicsAction { + public EditSelectFuzzy5MenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_5"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzy5MenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + Core.getMatcher().setActiveMatch(4); + } } /** Set active match to the next one */ - public void editSelectFuzzyNextMenuItemActionPerformed() { - Core.getMatcher().setNextActiveMatch(); + @SuppressWarnings("serial") + public static class EditSelectFuzzyNextMenuItemAction extends AbstractMnemonicsAction { + public EditSelectFuzzyNextMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_NEXT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzyNextMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getMatcher().setNextActiveMatch(); + } } /** Set active match to the previous one */ - public void editSelectFuzzyPrevMenuItemActionPerformed() { - Core.getMatcher().setPrevActiveMatch(); + @SuppressWarnings("serial") + public static class EditSelectFuzzyPrevMenuItemAction extends AbstractMnemonicsAction { + + public EditSelectFuzzyPrevMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_COMPARE_PREV"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditSelectFuzzyPrevMenuItem"); + } + @Override + public void actionPerformed(ActionEvent e) { + Core.getMatcher().setPrevActiveMatch(); + } } - public void insertCharsLRMActionPerformed() { - Core.getEditor().insertText("\u200E"); + @SuppressWarnings("serial") + public static class InsertCharsLRMAction extends AbstractMnemonicsAction { + public InsertCharsLRMAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_LRM"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "InsertCharsLRM"); + } + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().insertText("\u200E"); + + } } - public void insertCharsRLMActionPerformed() { - Core.getEditor().insertText("\u200F"); + @SuppressWarnings("serial") + public static class InsertCharsRLMAction extends AbstractMnemonicsAction { + public InsertCharsRLMAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_RLM"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "InsertCharsRLM"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().insertText("\u200F"); + } } - public void insertCharsLREActionPerformed() { - Core.getEditor().insertText("\u202A"); + @SuppressWarnings("serial") + public static class InsertCharsLREAction extends AbstractMnemonicsAction { + public InsertCharsLREAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_LRE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "InsertCharsLRE"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().insertText("\u202A"); + } } - public void insertCharsRLEActionPerformed() { - Core.getEditor().insertText("\u202B"); + @SuppressWarnings("serial") + public static class InsertCharsRLEAction extends AbstractMnemonicsAction { + public InsertCharsRLEAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_RLE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "InsertCharsRLE"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().insertText("\u202B"); + } } - public void insertCharsPDFActionPerformed() { - Core.getEditor().insertText("\u202C"); + @SuppressWarnings("serial") + public static class InsertCharsPDFAction extends AbstractMnemonicsAction { + + public InsertCharsPDFAction() { + super(OStrings.getString("TF_MENU_EDIT_INSERT_CHARS_PDF"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "InsertCharsPDF"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().insertText("\u202C"); + } } - public void editMultipleDefaultActionPerformed() { - Core.getEditor().setAlternateTranslationForCurrentEntry(false); + @SuppressWarnings("serial") + public static class EditMultipleDefaultAction extends AbstractMnemonicsAction { + public EditMultipleDefaultAction() { + super(OStrings.getString("MULT_MENU_DEFAULT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditMultipleDefault"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().setAlternateTranslationForCurrentEntry(false); + } } - public void editMultipleAlternateActionPerformed() { - Core.getEditor().setAlternateTranslationForCurrentEntry(true); + @SuppressWarnings("serial") + public static class EditMultipleAlternateAction extends AbstractMnemonicsAction { + public EditMultipleAlternateAction() { + super(OStrings.getString("MULT_MENU_MULTIPLE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditMultipleAlternate"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().setAlternateTranslationForCurrentEntry(true); + } } - public void editRegisterUntranslatedMenuItemActionPerformed() { - Core.getEditor().registerUntranslated(); + @SuppressWarnings("serial") + public static class EditRegisterUntranslatedMenuItemAction extends AbstractMnemonicsAction { + public EditRegisterUntranslatedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_UNTRANSLATED_TRANSLATION"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditRegisterUntranslatedMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().registerUntranslated(); + } } - public void editRegisterEmptyMenuItemActionPerformed() { - Core.getEditor().registerEmptyTranslation(); + @SuppressWarnings("serial") + public static class EditRegisterEmptyMenuItemAction extends AbstractMnemonicsAction { + public EditRegisterEmptyMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_EMPTY_TRANSLATION"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditRegisterEmptyMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().registerEmptyTranslation(); + } } - public void editRegisterIdenticalMenuItemActionPerformed() { - Core.getEditor().registerIdenticalTranslation(); + @SuppressWarnings("serial") + public static class EditRegisterIdenticalMenuItemAction extends AbstractMnemonicsAction { + public EditRegisterIdenticalMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_IDENTICAL_TRANSLATION"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "EditRegisterIdenticalMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().registerIdenticalTranslation(); + } } - public void optionsPreferencesMenuItemActionPerformed() { - PreferencesWindowController pwc = new PreferencesWindowController(); - pwc.show(Core.getMainWindow().getApplicationFrame()); + @SuppressWarnings("serial") + public static class OptionsPreferencesMenuItemAction extends AbstractMnemonicsAction { + + public OptionsPreferencesMenuItemAction() { + super(OStrings.getString("MW_OPTIONSMENU_PREFERENCES"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "OptionsPreferencesMenuItem"); + 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) { + new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame()); + } } - public void cycleSwitchCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.CYCLE); + @SuppressWarnings("serial") + public static class CycleSwitchCaseMenuItemAction extends AbstractMnemonicsAction { + public CycleSwitchCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_CYCLE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "CycleSwitchCaseMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.CYCLE); + } } - public void sentenceCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.SENTENCE); + @SuppressWarnings("serial") + public static class SentenceCaseMenuItemAction extends AbstractMnemonicsAction { + public SentenceCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_SENTENCE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "SentenceCaseMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.SENTENCE); + } } - public void titleCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.TITLE); + @SuppressWarnings("serial") + public static class TitleCaseMenuItemAction extends AbstractMnemonicsAction { + public TitleCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_TITLE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "TitleCaseMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.TITLE); + } } - public void upperCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.UPPER); + @SuppressWarnings("serial") + public static class UpperCaseMenuItemAction extends AbstractMnemonicsAction { + public UpperCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_UPPER"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "UpperCaseMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.UPPER); + } } - public void lowerCaseMenuItemActionPerformed() { - Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.LOWER); + @SuppressWarnings("serial") + public static class LowerCaseMenuItemAction extends AbstractMnemonicsAction { + public LowerCaseMenuItemAction() { + super(OStrings.getString("TF_EDIT_MENU_SWITCH_CASE_TO_LOWER"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "LowerCaseMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().changeCase(IEditor.CHANGE_CASE_TO.LOWER); + } } - public void gotoNextUntranslatedMenuItemActionPerformed() { - Core.getEditor().nextUntranslatedEntry(); + @SuppressWarnings("serial") + public static class GotoNextUntranslatedMenuItemAction extends AbstractMnemonicsAction { + public GotoNextUntranslatedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_UNTRANS"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "GotoNextUntranslatedMenuItem"); + } + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().nextUntranslatedEntry(); + } } - public void gotoNextUniqueMenuItemActionPerformed() { - Core.getEditor().nextUniqueEntry(); + @SuppressWarnings("serial") + public static class GotoNextUniqueMenuItemAction extends AbstractMnemonicsAction { + public GotoNextUniqueMenuItemAction() { + super(OStrings.getString("TF_MENU_GOTO_NEXT_UNIQUE"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "GotoNextUniqueMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().nextUniqueEntry(); + } } - public void gotoNextTranslatedMenuItemActionPerformed() { - Core.getEditor().nextTranslatedEntry(); + @SuppressWarnings("serial") + public static class GotoNextTranslatedMenuItemAction extends AbstractMnemonicsAction { + public GotoNextTranslatedMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_TRANS"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "GotoNextTranslatedMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().nextTranslatedEntry(); + } } - public void gotoNextSegmentMenuItemActionPerformed() { - Core.getEditor().nextEntry(); + @SuppressWarnings("serial") + public static class GotoNextSegmentMenuItemAction extends AbstractMnemonicsAction { + public GotoNextSegmentMenuItemAction() { + super(OStrings.getString("TF_MENU_EDIT_NEXT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "GotoNextSegmentMenuItem"); + } + + @Override + public void actionPerformed(ActionEvent e) { + Core.getEditor().nextEntry(); + } } + public void gotoPreviousSegmentMenuItemActionPerformed() { Core.getEditor().prevEntry(); } @@ -1024,15 +1826,34 @@ public void helpContentsMenuItemActionPerformed() { /** * Shows About dialog */ - public void helpAboutMenuItemActionPerformed() { - new AboutDialog(mainWindow.getApplicationFrame()).setVisible(true); + @SuppressWarnings("serial") + public static class HelpAboutMenuItemAction extends AbstractMnemonicsAction { + + public HelpAboutMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_ABOUT"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "HelpAboutMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + new AboutDialog(Core.getMainWindow().getApplicationFrame()).setVisible(true); + } } /** * Shows Last changes */ - public void helpLastChangesMenuItemActionPerformed() { - new LastChangesDialog(mainWindow.getApplicationFrame()).setVisible(true); + @SuppressWarnings("serial") + public static class HelpLastChangesMenuItemAction extends AbstractMnemonicsAction { + public HelpLastChangesMenuItemAction() { + super(OStrings.getString("TF_MENU_HELP_LAST_CHANGES"), OStrings.getLocale()); + putValue(Action.ACTION_COMMAND_KEY, "HelpLastChangesMenuItem"); + } + + @Override + public void actionPerformed(final ActionEvent e) { + new LastChangesDialog(Core.getMainWindow().getApplicationFrame()).setVisible(true); + } } /** 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-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java b/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java index aeada09dd3..86d94bba38 100644 --- a/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java +++ b/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java @@ -72,6 +72,7 @@ import org.omegat.gui.glossary.IGlossaries; import org.omegat.gui.main.IMainMenu; import org.omegat.gui.main.IMainWindow; +import org.omegat.gui.search.SearchWindowController; import org.omegat.util.Log; import org.omegat.util.OConsts; import org.omegat.util.OStrings; @@ -678,6 +679,18 @@ public DockingDesktop getDesktop() { return null; } + @Override + public void doRecycleTrans() { + } + + @Override + public void doInsertTrans() { + } + + @Override + public void addSearchWindow(final SearchWindowController search) { + } + public Cursor getCursor() { return null; } diff --git a/test/fixtures/org/omegat/core/TestCore.java b/test/fixtures/org/omegat/core/TestCore.java index bda24d9a09..4880d11e1a 100644 --- a/test/fixtures/org/omegat/core/TestCore.java +++ b/test/fixtures/org/omegat/core/TestCore.java @@ -51,6 +51,7 @@ import org.omegat.gui.editor.mark.Mark; import org.omegat.gui.main.IMainMenu; import org.omegat.gui.main.IMainWindow; +import org.omegat.gui.search.SearchWindowController; import org.omegat.util.Platform; import org.omegat.util.TestPreferencesInitializer; import org.omegat.util.gui.MenuExtender; @@ -274,6 +275,18 @@ public DockingDesktop getDesktop() { return null; } + @Override + public void doRecycleTrans() { + } + + @Override + public void doInsertTrans() { + } + + @Override + public void addSearchWindow(final SearchWindowController search) { + } + public Cursor getCursor() { return null; } diff --git a/test/src/org/omegat/gui/main/MainWindowMenuTest.java b/test/src/org/omegat/gui/main/MainWindowMenuTest.java index 0222b20f13..6f18960c6a 100644 --- a/test/src/org/omegat/gui/main/MainWindowMenuTest.java +++ b/test/src/org/omegat/gui/main/MainWindowMenuTest.java @@ -29,6 +29,7 @@ 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; @@ -37,7 +38,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.swing.JLabel; import javax.swing.JMenu; @@ -48,9 +53,11 @@ import org.omegat.core.Core; import org.omegat.core.TestCore; +import org.omegat.util.CommonVerifications; 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; @@ -68,7 +75,7 @@ public class MainWindowMenuTest extends TestCore { public void testMenuActions() throws Exception { int count = 0; - Map existsMethods = new HashMap(); + Map existsMethods = new HashMap<>(); for (Method m : MainWindowMenuHandler.class.getDeclaredMethods()) { if (Modifier.isPublic(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())) { @@ -82,6 +89,7 @@ public void testMenuActions() throws Exception { } } } + Set actionTargets = MainWindowMenuHandler.getActions().keySet(); for (Field f : StaticUtils.getAllModelFields(MainWindowMenu.class)) { if (JMenuItem.class.isAssignableFrom(f.getType()) && f.getType() != JMenu.class) { @@ -89,13 +97,20 @@ public void testMenuActions() throws Exception { String actionMethodName = f.getName() + "ActionPerformed"; Method m; try { - m = MainWindowMenuHandler.class.getMethod(actionMethodName); + MainWindowMenuHandler.class.getMethod(actionMethodName); + assertNotNull(existsMethods.remove(actionMethodName)); } catch (NoSuchMethodException ignore) { // See if the method accepts a modifier key argument. - m = MainWindowMenuHandler.class.getMethod(actionMethodName, Integer.TYPE); + try { + MainWindowMenuHandler.class.getMethod(actionMethodName, Integer.TYPE); + assertNotNull(existsMethods.remove(actionMethodName)); + } catch (NoSuchMethodException ignore2) { + String actionClassName = StringUtil.capitalizeFirst(f.getName(), Locale.ENGLISH); + if (!actionTargets.contains(actionClassName)) { + fail("Action method or class not defined for " + f.getName()); + } + } } - assertNotNull("Action method not defined for " + f.getName(), m); - assertNotNull(existsMethods.remove(actionMethodName)); } } assertTrue("menu items not found", count > 30); @@ -309,4 +324,22 @@ private List addMenuItemsToPager(MenuKey target) { newMenuItems.forEach(pager::add); return pager.getFirstPage(); } + + @Test + public void actionMenuCheck() throws Exception { + assertMenuKeyMatches(new String[] {"src/org/omegat/gui/main/"}); + } + + protected void assertMenuKeyMatches(String[] targets) throws Exception { + Set actions = MainWindowMenuHandler.getActions().keySet(); + Locale.setDefault(Locale.ENGLISH); + Pattern pattern = Pattern.compile("createMenuItemFromAction\\(\\s*\"([^\"]+)\"\\s*[,)]"); + CommonVerifications.processSourceContent(targets, (path, chars) -> { + Matcher m = pattern.matcher(chars); + while (m.find()) { + assertTrue(actions.contains(m.group(1))); + } + }); + } } +