From 1c6126249ffb47cf843d4b67abac25a51e79ec60 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Tue, 28 May 2024 22:09:43 +0900 Subject: [PATCH] refactor: direct instantiate Action classes Signed-off-by: Hiroshi Miura --- .../omegat/gui/accesstool/AccessTools.java | 4 +- .../omegat/gui/glossary/GlossaryTextArea.java | 2 +- .../omegat/gui/main/BaseMainWindowMenu.java | 417 +++++++++--------- .../omegat/gui/main/MainWindowBurgerMenu.java | 2 +- .../gui/main/MainWindowMenuHandler.java | 91 ---- .../omegat/gui/matches/MatchesTextArea.java | 6 +- .../omegat/gui/dialogs/AboutDialogTest.java | 5 +- .../omegat/gui/main/MainWindowMenuTest.java | 41 +- 8 files changed, 222 insertions(+), 346 deletions(-) diff --git a/src/org/omegat/gui/accesstool/AccessTools.java b/src/org/omegat/gui/accesstool/AccessTools.java index c0c2d8a9a3..62f6b1ee28 100644 --- a/src/org/omegat/gui/accesstool/AccessTools.java +++ b/src/org/omegat/gui/accesstool/AccessTools.java @@ -117,11 +117,11 @@ public void initComponents() { add(sourceFilesCB); searchButton = new JButton(); - searchButton.setAction(MainWindowMenuHandler.getAction("EditFindInProjectMenuItem")); + searchButton.setAction(new MainWindowMenuHandler.EditFindInProjectMenuItemAction()); searchButton.setText(""); searchButton.setBorderPainted(false); settingsButton = new JButton(); - settingsButton.setAction(MainWindowMenuHandler.getAction("OptionsPreferencesMenuItem")); + settingsButton.setAction(new MainWindowMenuHandler.OptionsPreferencesMenuItemAction()); settingsButton.setText(""); settingsButton.setBorderPainted(false); diff --git a/src/org/omegat/gui/glossary/GlossaryTextArea.java b/src/org/omegat/gui/glossary/GlossaryTextArea.java index dd4b1b6fd2..a6c4709731 100644 --- a/src/org/omegat/gui/glossary/GlossaryTextArea.java +++ b/src/org/omegat/gui/glossary/GlossaryTextArea.java @@ -412,7 +412,7 @@ public void populatePaneMenu(JPopupMenu menu) { populateContextMenu(menu); menu.addSeparator(); final JMenuItem openFile = new JMenuItem(OStrings.getString("GUI_GLOSSARYWINDOW_SETTINGS_OPEN_FILE")); - openFile.setAction(MainWindowMenuHandler.getAction("ProjectAccessWritableGlossaryMenuItem")); + openFile.setAction(new MainWindowMenuHandler.ProjectAccessWriteableGlossaryMenuItemAction()); openFile.setEnabled(false); if (Core.getProject().isProjectLoaded()) { String glossaryPath = Core.getProject().getProjectProperties().getWriteableGlossary(); diff --git a/src/org/omegat/gui/main/BaseMainWindowMenu.java b/src/org/omegat/gui/main/BaseMainWindowMenu.java index 9af5b0c7d7..6bad2de112 100644 --- a/src/org/omegat/gui/main/BaseMainWindowMenu.java +++ b/src/org/omegat/gui/main/BaseMainWindowMenu.java @@ -37,14 +37,14 @@ package org.omegat.gui.main; -import java.awt.Component; +import static org.omegat.gui.main.MainWindowMenuHandler.findInProjectReuseLastWindow; + import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.lang.reflect.Field; import java.util.EnumMap; import java.util.List; -import java.util.Locale; import java.util.Map; import javax.swing.AbstractAction; @@ -67,6 +67,17 @@ import org.omegat.core.CoreEvents; import org.omegat.core.events.IApplicationEventListener; import org.omegat.gui.editor.EditorSettings; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectCloseMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectCommitSourceFilesAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectCommitTargetFilesAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectCompileMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectImportMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectNewMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectReloadMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectSaveMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectSingleCompileMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectTeamNewMenuItemAction; +import org.omegat.gui.main.MainWindowMenuHandler.ProjectWikiImportMenuItemAction; import org.omegat.gui.shortcuts.PropertiesShortcuts; import org.omegat.util.Log; import org.omegat.util.OStrings; @@ -107,8 +118,6 @@ public abstract class BaseMainWindowMenu implements ActionListener, MenuListener /** menu bar instance */ protected final JMenuBar mainMenu = new JMenuBar(); - protected final Map actions; - private final Map menus = new EnumMap<>(MenuExtender.MenuKey.class); @Deprecated @@ -122,7 +131,6 @@ public BaseMainWindowMenu(IMainWindow mainWindow) { } public BaseMainWindowMenu() { - actions = MainWindowMenuHandler.getActions(); } /** @@ -169,200 +177,206 @@ protected void createComponents() { optionsMenu = createMenu("MW_OPTIONSMENU", MenuExtender.MenuKey.OPTIONS); helpMenu = createMenu("TF_MENU_HELP", MenuExtender.MenuKey.HELP); - projectNewMenuItem = createMenuItemFromAction("ProjectNewMenuItem"); - projectTeamNewMenuItem = createMenuItemFromAction("ProjectTeamNewMenuItem"); - projectOpenMenuItem = createMenuItemFromAction("ProjectOpenMenuItem"); + projectNewMenuItem = createMenuItem(new ProjectNewMenuItemAction()); + projectTeamNewMenuItem = createMenuItem(new ProjectTeamNewMenuItemAction()); + projectOpenMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectOpenMenuItemAction()); projectOpenRecentMenuItem = createMenu("TF_MENU_FILE_OPEN_RECENT"); - 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 = createMenuItemFromAction("ViewFileListMenuItem"); + projectClearRecentMenuItem = createMenuItem(new MainWindowMenuHandler.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 MainWindowMenuHandler.ProjectMedOpenMenuItemAction()); + projectMedCreateMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectMedCreateMenuItemAction()); + projectEditMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectEditMenuItemAction()); + viewFileListMenuItem = createMenuItem(new MainWindowMenuHandler.ViewFileListMenuItemAction()); projectAccessProjectFilesMenu = createMenu("TF_MENU_FILE_ACCESS_PROJECT_FILES"); - 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 = createMenuItemFromAction("EditTagPainterMenuItem"); - editTagNextMissedMenuItem = createMenuItemFromAction("EditTagNextMissedMenuItem"); - editExportSelectionMenuItem = createMenuItemFromAction("EditExportSelectionMenuItem"); - editCreateGlossaryEntryMenuItem = createMenuItemFromAction("EditCreateGlossaryEntryMenuItem"); - editFindInProjectMenuItem = createMenuItemFromAction("EditFindInProjectMenuItem"); - editReplaceInProjectMenuItem = createMenuItemFromAction("EditReplaceInProjectMenuItem"); - editSearchDictionaryMenuItem = createMenuItemFromAction("EditSearchDictionaryMenuItem"); + projectAccessRootMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessRootMenuItemAction()); + projectAccessDictionaryMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessDictionaryMenuItemAction()); + projectAccessGlossaryMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessGlossaryMenuItemAction()); + projectAccessSourceMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessSourceMenuItemAction()); + projectAccessTargetMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessTargetMenuItemAction()); + projectAccessTMMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessTMMenuItemAction()); + projectAccessExportTMMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessExportTMMenuItemAction()); + projectAccessCurrentSourceDocumentMenuItem = createMenuItem( + new MainWindowMenuHandler.ProjectAccessCurrentSourceDocumentMenuItemAction()); + projectAccessCurrentTargetDocumentMenuItem = createMenuItem( + new MainWindowMenuHandler.ProjectAccessCurrentTargetDocumentMenuItemAction()); + projectAccessWriteableGlossaryMenuItem = createMenuItem( + new MainWindowMenuHandler.ProjectAccessWriteableGlossaryMenuItemAction()); + projectAccessRootMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessRootMenuItemAction()); + projectAccessDictionaryMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessDictionaryMenuItemAction()); + projectAccessGlossaryMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessGlossaryMenuItemAction()); + projectAccessSourceMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessSourceMenuItemAction()); + projectAccessTargetMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessTargetMenuItemAction()); + projectAccessTMMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessTMMenuItemAction()); + projectAccessExportTMMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectAccessExportTMMenuItemAction()); + projectAccessCurrentSourceDocumentMenuItem = createMenuItem( + new MainWindowMenuHandler.ProjectAccessCurrentSourceDocumentMenuItemAction()); + projectAccessCurrentTargetDocumentMenuItem = createMenuItem(new + MainWindowMenuHandler.ProjectAccessCurrentTargetDocumentMenuItemAction()); + projectAccessWriteableGlossaryMenuItem = createMenuItem( + new MainWindowMenuHandler.ProjectAccessWriteableGlossaryMenuItemAction()); + projectRestartMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectRestartMenuItemAction()); + projectExitMenuItem = createMenuItem(new MainWindowMenuHandler.ProjectExitMenuItemAction()); + + editUndoMenuItem = createMenuItem(new MainWindowMenuHandler.EditUndoMenuItemAction()); + editRedoMenuItem = createMenuItem(new MainWindowMenuHandler.EditRedoMenuItemAction()); + editOverwriteTranslationMenuItem = createMenuItem(new MainWindowMenuHandler.EditOverwriteTranslationMenuItemAction()); + editInsertTranslationMenuItem = createMenuItem(new MainWindowMenuHandler.EditInsertTranslationMenuItemAction()); + editOverwriteSourceMenuItem = createMenuItem(new MainWindowMenuHandler.EditOverwriteSourceMenuItemAction()); + editInsertSourceMenuItem = createMenuItem(new MainWindowMenuHandler.EditInsertSourceMenuItemAction()); + editSelectSourceMenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectSourceMenuItemAction()); + editOverwriteMachineTranslationMenuItem = createMenuItem( + new MainWindowMenuHandler.EditOverwriteMachineTranslationMenuItemAction()); + editTagPainterMenuItem = createMenuItem(new MainWindowMenuHandler.EditTagPainterMenuItemAction()); + editTagNextMissedMenuItem = createMenuItem(new MainWindowMenuHandler.EditTagNextMissedMenuItemAction()); + editExportSelectionMenuItem = createMenuItem(new MainWindowMenuHandler.EditExportSelectionMenuItemAction()); + editCreateGlossaryEntryMenuItem = createMenuItem(new MainWindowMenuHandler.EditCreateGlossaryEntryMenuItemAction()); + editFindInProjectMenuItem = createMenuItem(new MainWindowMenuHandler.EditFindInProjectMenuItemAction()); + editReplaceInProjectMenuItem = createMenuItem(new MainWindowMenuHandler.EditReplaceInProjectMenuItemAction()); + editSearchDictionaryMenuItem = createMenuItem(new MainWindowMenuHandler.EditSearchDictionaryMenuItemAction()); switchCaseSubMenu = createMenu("TF_EDIT_MENU_SWITCH_CASE"); selectFuzzySubMenu = createMenu("TF_MENU_EDIT_COMPARE"); - editSelectFuzzyPrevMenuItem = createMenuItemFromAction("EditSelectFuzzyPrevMenuItem"); - editSelectFuzzyNextMenuItem = createMenuItemFromAction("EditSelectFuzzyNextMenuItem"); - editSelectFuzzy1MenuItem = createMenuItemFromAction("EditSelectFuzzy1MenuItem"); - editSelectFuzzy2MenuItem = createMenuItemFromAction("EditSelectFuzzy2MenuItem"); - editSelectFuzzy3MenuItem = createMenuItemFromAction("EditSelectFuzzy3MenuItem"); - editSelectFuzzy4MenuItem = createMenuItemFromAction("EditSelectFuzzy4MenuItem"); - editSelectFuzzy5MenuItem = createMenuItemFromAction("EditSelectFuzzy5MenuItem"); + editSelectFuzzyPrevMenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzyPrevMenuItemAction()); + editSelectFuzzyNextMenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzyNextMenuItemAction()); + editSelectFuzzy1MenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzy1MenuItemAction()); + editSelectFuzzy2MenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzy2MenuItemAction()); + editSelectFuzzy3MenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzy3MenuItemAction()); + editSelectFuzzy4MenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzy4MenuItemAction()); + editSelectFuzzy5MenuItem = createMenuItem(new MainWindowMenuHandler.EditSelectFuzzy5MenuItemAction()); insertCharsSubMenu = createMenu("TF_MENU_EDIT_INSERT_CHARS"); - 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 = createMenuItemFromAction("GotoPreviousSegmentMenuItem"); - gotoSegmentMenuItem = createMenuItemFromAction("GotoSegmentMenuItem"); - gotoNextNoteMenuItem = createMenuItemFromAction("GotoNextNoteMenuItem"); - gotoPreviousNoteMenuItem = createMenuItemFromAction("GotoPreviousNoteMenuItem"); - gotoNextUniqueMenuItem = createMenuItemFromAction("GotoNextUniqueMenuItem"); - gotoMatchSourceSegment = createMenuItemFromAction("GotoMatchSourceSegment"); + insertCharsLRM = createMenuItem(new MainWindowMenuHandler.InsertCharsLRMAction()); + insertCharsRLM = createMenuItem(new MainWindowMenuHandler.InsertCharsRLMAction()); + insertCharsLRE = createMenuItem(new MainWindowMenuHandler.InsertCharsLREAction()); + insertCharsRLE = createMenuItem(new MainWindowMenuHandler.InsertCharsRLEAction()); + insertCharsPDF = createMenuItem(new MainWindowMenuHandler.InsertCharsPDFAction()); + + editMultipleDefault = createMenuItem(new MainWindowMenuHandler.EditMultipleDefaultAction()); + editMultipleAlternate = createMenuItem(new MainWindowMenuHandler.EditMultipleAlternateAction()); + editRegisterUntranslatedMenuItem = createMenuItem(new MainWindowMenuHandler.EditRegisterUntranslatedMenuItemAction()); + editRegisterEmptyMenuItem = createMenuItem(new MainWindowMenuHandler.EditRegisterEmptyMenuItemAction()); + editRegisterIdenticalMenuItem = createMenuItem(new MainWindowMenuHandler.EditRegisterIdenticalMenuItemAction()); + + lowerCaseMenuItem = createMenuItem(new MainWindowMenuHandler.LowerCaseMenuItemAction()); + upperCaseMenuItem = createMenuItem(new MainWindowMenuHandler.UpperCaseMenuItemAction()); + titleCaseMenuItem = createMenuItem(new MainWindowMenuHandler.TitleCaseMenuItemAction()); + sentenceCaseMenuItem = createMenuItem(new MainWindowMenuHandler.SentenceCaseMenuItemAction()); + cycleSwitchCaseMenuItem = createMenuItem(new MainWindowMenuHandler.CycleSwitchCaseMenuItemAction()); + + gotoNextUntranslatedMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextUntranslatedMenuItemAction()); + gotoNextTranslatedMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextTranslatedMenuItemAction()); + gotoNextSegmentMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextSegmentMenuItemAction()); + gotoPreviousSegmentMenuItem = createMenuItem(new MainWindowMenuHandler.GotoPreviousSegmentMenuItemAction()); + gotoSegmentMenuItem = createMenuItem(new MainWindowMenuHandler.GotoSegmentMenuItemAction()); + gotoNextNoteMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextNoteMenuItemAction()); + gotoPreviousNoteMenuItem = createMenuItem(new MainWindowMenuHandler.GotoPreviousNoteMenuItemAction()); + gotoNextUniqueMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextUniqueMenuItemAction()); + gotoMatchSourceSegment = createMenuItem(new MainWindowMenuHandler.GotoMatchSourceSegmentAction()); gotoXEntrySubmenu = createMenu("TF_MENU_GOTO_X_SUBMENU"); - gotoNextXAutoMenuItem = createMenuItemFromAction("GotoNextXAutoMenuItem"); - gotoPrevXAutoMenuItem = createMenuItemFromAction("GotoPrevXAutoMenuItem"); - gotoNextXEnforcedMenuItem = createMenuItemFromAction("GotoNextXEnforcedMenuItem"); - gotoPrevXEnforcedMenuItem = createMenuItemFromAction("GotoPrevXEnforcedMenuItem"); - - gotoHistoryBackMenuItem = createMenuItemFromAction("GotoHistoryBackMenuItem"); - gotoHistoryForwardMenuItem = createMenuItemFromAction("GotoHistoryForwardMenuItem"); - gotoNotesPanelMenuItem = createMenuItemFromAction("GotoNotesPanelMenuItem"); - gotoEditorPanelMenuItem = createMenuItemFromAction("GotoEditorPanelMenuItem"); - - viewMarkTranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkTranslatedSegmentsCheckBoxMenuItem"); - viewMarkUntranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkUntranslatedSegmentsCheckBoxMenuItem"); - viewMarkParagraphStartCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkParagraphStartCheckBoxMenuItem"); - viewDisplaySegmentSourceCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewDisplaySegmentSourceCheckBoxMenuItem"); - viewMarkNonUniqueSegmentsCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkNonUniqueSegmentsCheckBoxMenuItem"); - viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkNotedSegmentsCheckBoxMenuItem"); - viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItemFromAction("ViewMarkNBSPCheckBoxMenuItem"); - viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkWhitespaceCheckBoxMenuItem"); - viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItemFromAction("ViewMarkBidiCheckBoxMenuItem"); - viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkAutoPopulatedCheckBoxMenuItem"); - viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkGlossaryMatchesCheckBoxMenuItem"); - viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkLanguageCheckerCheckBoxMenuItem"); - viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "ViewMarkFontFallbackCheckBoxMenuItem"); + gotoNextXAutoMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextXAutoMenuItemAction()); + gotoPrevXAutoMenuItem = createMenuItem(new MainWindowMenuHandler.GotoPrevXAutoMenuItemAction()); + gotoNextXEnforcedMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNextXEnforcedMenuItemAction()); + gotoPrevXEnforcedMenuItem = createMenuItem(new MainWindowMenuHandler.GotoPrevXEnforcedMenuItemAction()); + + gotoHistoryBackMenuItem = createMenuItem(new MainWindowMenuHandler.GotoHistoryBackMenuItemAction()); + gotoHistoryForwardMenuItem = createMenuItem(new MainWindowMenuHandler.GotoHistoryForwardMenuItemAction()); + gotoNotesPanelMenuItem = createMenuItem(new MainWindowMenuHandler.GotoNotesPanelMenuItemAction()); + gotoEditorPanelMenuItem = createMenuItem(new MainWindowMenuHandler.GotoEditorPanelMenuItemAction()); + + viewMarkTranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkTranslatedSegmentsCheckBoxMenuItemAction()); + viewMarkUntranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkUntranslatedSegmentsCheckBoxMenuItemAction()); + viewMarkParagraphStartCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkParagraphStartCheckBoxMenuItemAction()); + viewDisplaySegmentSourceCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewDisplaySegmentSourceCheckBoxMenuItemAction()); + viewMarkNonUniqueSegmentsCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkNonUniqueSegmentsCheckBoxMenuItemAction()); + viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkNotedSegmentsCheckBoxMenuItemAction()); + viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkNBSPCheckBoxMenuItemAction()); + viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkWhitespaceCheckBoxMenuItemAction()); + viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkBidiCheckBoxMenuItemAction()); + viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkAutoPopulatedCheckBoxMenuItemAction()); + viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkGlossaryMatchesCheckBoxMenuItemAction()); + viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkLanguageCheckerCheckBoxMenuItemAction()); + viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.ViewMarkFontFallbackCheckBoxMenuItemAction()); viewModificationInfoMenu = createMenu("MW_VIEW_MENU_MODIFICATION_INFO"); viewModificationInfoMenu.setIcon(MainMenuIcons.newBlankIcon()); ButtonGroup viewModificationInfoMenuBG = new ButtonGroup(); - viewDisplayModificationInfoNoneRadioButtonMenuItem = createRadioButtonMenuItemFromAction( - "ViewDisplayModificationInfoNoneRadioButtonMenuItem", viewModificationInfoMenuBG); - viewDisplayModificationInfoSelectedRadioButtonMenuItem = createRadioButtonMenuItemFromAction( - "ViewDisplayModificationInfoSelectedRadioButtonMenuItem", viewModificationInfoMenuBG); - viewDisplayModificationInfoAllRadioButtonMenuItem = createRadioButtonMenuItemFromAction( - "ViewDisplayModificationInfoAllRadioButtonMenuItem", viewModificationInfoMenuBG); - viewRestoreGUIMenuItem = createMenuItemFromAction("ViewRestoreGUIMenuItem"); - - toolsCheckIssuesMenuItem = createMenuItemFromAction("ToolsCheckIssuesMenuItem"); - toolsCheckIssuesCurrentFileMenuItem = createMenuItemFromAction("ToolsCheckIssuesCurrentFileMenuItem"); - toolsShowStatisticsStandardMenuItem = createMenuItemFromAction("ToolsShowStatisticsStandardMenuItem"); - toolsShowStatisticsMatchesMenuItem = createMenuItemFromAction("ToolsShowStatisticsMatchesMenuItem"); - toolsShowStatisticsMatchesPerFileMenuItem = createMenuItemFromAction( - "ToolsShowStatisticsMatchesPerFileMenuItem"); - - optionsPreferencesMenuItem = createMenuItemFromAction("OptionsPreferencesMenuItem"); + viewDisplayModificationInfoNoneRadioButtonMenuItem = createRadioButtonMenuItem( + new MainWindowMenuHandler.ViewDisplayModificationInfoNoneRadioButtonMenuItemAction(), + viewModificationInfoMenuBG); + viewDisplayModificationInfoSelectedRadioButtonMenuItem = createRadioButtonMenuItem( + new MainWindowMenuHandler.ViewDisplayModificationInfoSelectedRadioButtonMenuItemAction(), + viewModificationInfoMenuBG); + viewDisplayModificationInfoAllRadioButtonMenuItem = createRadioButtonMenuItem( + new MainWindowMenuHandler.ViewDisplayModificationInfoAllRadioButtonMenuItemAction(), + viewModificationInfoMenuBG); + viewRestoreGUIMenuItem = createMenuItem(new MainWindowMenuHandler.ViewRestoreGUIMenuItemAction()); + + toolsCheckIssuesMenuItem = createMenuItem(new MainWindowMenuHandler.ToolsCheckIssuesMenuItemAction()); + toolsCheckIssuesCurrentFileMenuItem = createMenuItem(new MainWindowMenuHandler.ToolsCheckIssuesCurrentFileMenuItemAction()); + toolsShowStatisticsStandardMenuItem = + createMenuItem(new MainWindowMenuHandler.ToolsShowStatisticsStandardMenuItemAction()); + toolsShowStatisticsMatchesMenuItem = createMenuItem(new MainWindowMenuHandler.ToolsShowStatisticsMatchesMenuItemAction()); + toolsShowStatisticsMatchesPerFileMenuItem = createMenuItem( + new MainWindowMenuHandler.ToolsShowStatisticsMatchesPerFileMenuItemAction()); + + optionsPreferencesMenuItem = createMenuItem(new MainWindowMenuHandler.OptionsPreferencesMenuItemAction()); optionsMachineTranslateMenu = createMenu("TF_OPTIONSMENU_MACHINETRANSLATE"); - optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItemFromAction( - "OptionsMTAutoFetchCheckboxMenuItem"); + optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.OptionsMTAutoFetchCheckboxMenuItemAction()); optionsGlossaryMenu = createMenu("TF_OPTIONSMENU_GLOSSARY"); - optionsGlossaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "OptionsGlossaryFuzzyMatchingCheckBoxMenuItem"); + optionsGlossaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.OptionsGlossaryFuzzyMatchingCheckBoxMenuItemAction()); optionsDictionaryMenu = createMenu("TF_OPTIONSMENU_DICTIONARY"); - optionsDictionaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItemFromAction( - "OptionsDictionaryFuzzyMatchingCheckBoxMenuItem"); + optionsDictionaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.OptionsDictionaryFuzzyMatchingCheckBoxMenuItemAction()); optionsAutoCompleteMenu = createMenu("MW_OPTIONSMENU_AUTOCOMPLETE"); // add any autocomplete view configuration menu items below - optionsAutoCompleteShowAutomaticallyItem = createCheckboxMenuItemFromAction( - "OptionsAutoCompleteShowAutomaticallyItem"); - optionsAutoCompleteHistoryCompletionMenuItem = createCheckboxMenuItemFromAction( - "OptionsAutoCompleteHistoryCompletionMenuItem"); - optionsAutoCompleteHistoryPredictionMenuItem = createCheckboxMenuItemFromAction( - "OptionsAutoCompleteHistoryPredictionMenuItem"); - - optionsSetupFileFiltersMenuItem = createMenuItemFromAction("OptionsSetupFileFiltersMenuItem"); - optionsSentsegMenuItem = createMenuItemFromAction("OptionsSentsegMenuItem"); - optionsWorkflowMenuItem = createMenuItemFromAction("OptionsWorkflowMenuItem"); - optionsAccessConfigDirMenuItem = createMenuItemFromAction("OptionsAccessConfigDirMenuItem"); - - helpContentsMenuItem = createMenuItemFromAction("HelpContentsMenuItem"); - helpAboutMenuItem = createMenuItemFromAction("HelpAboutMenuItem"); - helpLastChangesMenuItem = createMenuItemFromAction("HelpLastChangesMenuItem"); - helpLogMenuItem = createMenuItemFromAction("HelpLogMenuItem"); - helpUpdateCheckMenuItem = createMenuItemFromAction("HelpUpdateCheckMenuItem"); + optionsAutoCompleteShowAutomaticallyItem = createCheckboxMenuItem( + new MainWindowMenuHandler.OptionsAutoCompleteShowAutomaticallyItemAction()); + optionsAutoCompleteHistoryCompletionMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.OptionsAutoCompleteHistoryCompletionMenuItemAction()); + optionsAutoCompleteHistoryPredictionMenuItem = createCheckboxMenuItem( + new MainWindowMenuHandler.OptionsAutoCompleteHistoryPredictionMenuItemAction()); + + optionsSetupFileFiltersMenuItem = createMenuItem(new MainWindowMenuHandler.OptionsSetupFileFiltersMenuItemAction()); + optionsSentsegMenuItem = createMenuItem(new MainWindowMenuHandler.OptionsSentsegMenuItemAction()); + optionsWorkflowMenuItem = createMenuItem(new MainWindowMenuHandler.OptionsWorkflowMenuItemAction()); + optionsAccessConfigDirMenuItem = createMenuItem(new MainWindowMenuHandler.OptionsAccessConfigDirMenuItemAction()); + + helpContentsMenuItem = createMenuItem(new MainWindowMenuHandler.HelpContentsMenuItemAction()); + helpAboutMenuItem = createMenuItem(new MainWindowMenuHandler.HelpAboutMenuItemAction()); + helpLastChangesMenuItem = createMenuItem(new MainWindowMenuHandler.HelpLastChangesMenuItemAction()); + helpLogMenuItem = createMenuItem(new MainWindowMenuHandler.HelpLogMenuItemAction()); + helpUpdateCheckMenuItem = createMenuItem(new MainWindowMenuHandler.HelpUpdateCheckMenuItemAction()); } protected void constructMenu() { @@ -608,7 +622,7 @@ public void menuCanceled(MenuEvent e) { @Override public void actionPerformed(ActionEvent e) { Log.logInfoRB("LOG_MENU_CLICK", key); - MainWindowMenuHandler.findInProjectReuseLastWindow(); + findInProjectReuseLastWindow(); } }); @@ -658,17 +672,7 @@ public void actionPerformed(ActionEvent evt) { @Deprecated @Override public void invokeAction(String action, int modifiers) { - String actionName; - if (modifiers > 0) { - actionName = StringUtil.capitalizeFirst(action, Locale.ENGLISH) + "withModifiers"; - } else { - actionName = StringUtil.capitalizeFirst(action, Locale.ENGLISH); - } - if (actions.containsKey(actionName)) { - actions.get(actionName).actionPerformed(null); - } else { - throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); - } + throw new IncompatibleClassChangeError("Error invoke method handler for main menu"); } /** @@ -696,21 +700,11 @@ 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) { - JMenuItem result = new JMenuItem(); - Mnemonics.setLocalizedText(result, OStrings.getString(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); - } + protected JMenuItem createMenuItem(Action action) { JMenuItem item = new JMenuItem(); item.setAction(action); item.setIcon(null); @@ -722,17 +716,11 @@ protected JMenuItem createMenuItemFromAction(String commandKey) { 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; } - protected JCheckBoxMenuItem createCheckboxMenuItemFromAction(String commandKey) { - Action action = actions.get(commandKey); - if (action == null) { - throw new RuntimeException("Unexpected error when creating a menu item." + commandKey); - } + protected JCheckBoxMenuItem createCheckboxMenuItem(Action action) { JCheckBoxMenuItem result = new JCheckBoxMenuItem(); result.setAction(action); return result; @@ -753,12 +741,7 @@ protected JCheckBoxMenuItem createCheckboxMenuItem(final String titleKey) { return result; } - protected JRadioButtonMenuItem createRadioButtonMenuItemFromAction(String commandKey, - ButtonGroup buttonGroup) { - Action action = actions.get(commandKey); - if (action == null) { - throw new RuntimeException("Unexpected error when creating a menu item." + commandKey); - } + protected JRadioButtonMenuItem createRadioButtonMenuItem(Action action, ButtonGroup buttonGroup) { JRadioButtonMenuItem result = new JRadioButtonMenuItem(); result.setAction(action); result.setIcon(null); @@ -774,7 +757,7 @@ protected JRadioButtonMenuItem createRadioButtonMenuItemFromAction(String comman * @return menu item instance */ @Deprecated - protected JRadioButtonMenuItem createRadioButtonMenuItem(final String titleKey, ButtonGroup buttonGroup) { + protected JRadioButtonMenuItem createRadioButtonMenuItem(String titleKey, ButtonGroup buttonGroup) { JRadioButtonMenuItem result = new JRadioButtonMenuItem(); Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); buttonGroup.add(result); @@ -921,9 +904,9 @@ protected void updateCheckboxesOnStart() { protected void initMacSpecific() { try { // MacOSX-specific - OSXIntegration.setQuitHandler(actions.get("ProjectExitMenuItem")); - OSXIntegration.setAboutHandler(actions.get("HelpAboutMenuItem")); - OSXIntegration.setPreferencesHandler(actions.get("OptionsPreferencesMenuItem")); + OSXIntegration.setQuitHandler(new MainWindowMenuHandler.ProjectExitMenuItemAction()); + OSXIntegration.setAboutHandler(new MainWindowMenuHandler.HelpAboutMenuItemAction()); + OSXIntegration.setPreferencesHandler(new MainWindowMenuHandler.OptionsPreferencesMenuItemAction()); } catch (NoClassDefFoundError e) { Log.log(e); } diff --git a/src/org/omegat/gui/main/MainWindowBurgerMenu.java b/src/org/omegat/gui/main/MainWindowBurgerMenu.java index d078af5c7b..7e542b3f41 100644 --- a/src/org/omegat/gui/main/MainWindowBurgerMenu.java +++ b/src/org/omegat/gui/main/MainWindowBurgerMenu.java @@ -46,7 +46,7 @@ public final class MainWindowBurgerMenu extends BaseMainWindowMenu implements IM JMenu burgerMenu; public MainWindowBurgerMenu(MainWindow mainWindow) { - super(mainWindow); + super(); initComponents(); } diff --git a/src/org/omegat/gui/main/MainWindowMenuHandler.java b/src/org/omegat/gui/main/MainWindowMenuHandler.java index 95c9ef4219..d1b9584a4d 100644 --- a/src/org/omegat/gui/main/MainWindowMenuHandler.java +++ b/src/org/omegat/gui/main/MainWindowMenuHandler.java @@ -42,9 +42,7 @@ 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; @@ -125,95 +123,6 @@ private MainWindowMenuHandler() { public MainWindowMenuHandler(final 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 EditTagPainterMenuItemAction(), - new EditTagNextMissedMenuItemAction(), 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 GotoPreviousSegmentMenuItemAction(), new GotoSegmentMenuItemAction(), - new GotoNextUniqueMenuItemAction(), new GotoNextNoteMenuItemAction(), - new GotoPreviousNoteMenuItemAction(), new GotoMatchSourceSegmentAction(), - new GotoNextXAutoMenuItemAction(), new GotoPrevXAutoMenuItemAction(), - new GotoNextXEnforcedMenuItemAction(), new GotoPrevXEnforcedMenuItemAction(), - new GotoHistoryBackMenuItemAction(), new GotoHistoryForwardMenuItemAction(), - new GotoNotesPanelMenuItemAction(), new GotoEditorPanelMenuItemAction(), - new ViewMarkTranslatedSegmentsCheckBoxMenuItemAction(), - new ViewMarkUntranslatedSegmentsCheckBoxMenuItemAction(), - new ViewMarkParagraphStartCheckBoxMenuItemAction(), - new ViewDisplaySegmentSourceCheckBoxMenuItemAction(), - new ViewMarkNonUniqueSegmentsCheckBoxMenuItemAction(), - new ViewMarkNotedSegmentsCheckBoxMenuItemAction(), new ViewMarkNBSPCheckBoxMenuItemAction(), - new ViewMarkWhitespaceCheckBoxMenuItemAction(), new ViewMarkBidiCheckBoxMenuItemAction(), - new ViewMarkAutoPopulatedCheckBoxMenuItemAction(), - new ViewMarkGlossaryMatchesCheckBoxMenuItemAction(), - new ViewMarkLanguageCheckerCheckBoxMenuItemAction(), - new ViewMarkFontFallbackCheckBoxMenuItemAction(), - new ViewDisplayModificationInfoNoneRadioButtonMenuItemAction(), - new ViewDisplayModificationInfoSelectedRadioButtonMenuItemAction(), - new ViewDisplayModificationInfoAllRadioButtonMenuItemAction(), new ViewRestoreGUIMenuItemAction(), - new ViewFileListMenuItemAction(), new ToolsCheckIssuesMenuItemAction(), - new ToolsCheckIssuesCurrentFileMenuItemAction(), new ToolsShowStatisticsStandardMenuItemAction(), - new ToolsShowStatisticsMatchesMenuItemAction(), - new ToolsShowStatisticsMatchesPerFileMenuItemAction(), new OptionsPreferencesMenuItemAction(), - new OptionsAutoCompleteShowAutomaticallyItemAction(), - new OptionsAutoCompleteHistoryCompletionMenuItemAction(), - new OptionsAutoCompleteHistoryPredictionMenuItemAction(), - new OptionsMTAutoFetchCheckboxMenuItemAction(), - new OptionsGlossaryFuzzyMatchingCheckBoxMenuItemAction(), - new OptionsDictionaryFuzzyMatchingCheckBoxMenuItemAction(), - new OptionsSetupFileFiltersMenuItemAction(), new OptionsSentsegMenuItemAction(), - new OptionsWorkflowMenuItemAction(), new OptionsAccessConfigDirMenuItemAction(), - new HelpAboutMenuItemAction(), new HelpLastChangesMenuItemAction(), - new HelpContentsMenuItemAction(), new HelpLogMenuItemAction(), - new HelpUpdateCheckMenuItemAction() }; - - public static Map getActions() { - Map result = new HashMap<>(); - for (Action a : ACTIONS) { - result.put(a.getValue(Action.ACTION_COMMAND_KEY), a); - } - return result; - } - - public static Action getAction(String key) { - for (Action a : ACTIONS) { - if (a.getValue(Action.ACTION_COMMAND_KEY).equals(key)) { - return a; - } - } - return null; - } - /** * Create a new project. */ diff --git a/src/org/omegat/gui/matches/MatchesTextArea.java b/src/org/omegat/gui/matches/MatchesTextArea.java index 202c62f76c..f98c328c82 100644 --- a/src/org/omegat/gui/matches/MatchesTextArea.java +++ b/src/org/omegat/gui/matches/MatchesTextArea.java @@ -591,7 +591,7 @@ private void populateContextMenu(JPopupMenu popup, final int index) { for (int i = 0; i < m.projs.length; i++) { String proj = m.projs[i]; StringBuilder b = new StringBuilder(); - if (proj.equals("")) { + if (proj.isEmpty()) { b.append(OStrings.getString("MATCHES_THIS_PROJECT")); } else { b.append(proj); @@ -606,11 +606,11 @@ private void populateContextMenu(JPopupMenu popup, final int index) { } JMenuItem item = popup.add(OStrings.getString("MATCHES_INSERT")); - item.setAction(MainWindowMenuHandler.getAction("EditInsertTranslationMenuItem")); + item.setAction(new MainWindowMenuHandler.EditInsertTranslationMenuItemAction()); item.setEnabled(hasMatches); item = popup.add(OStrings.getString("MATCHES_REPLACE")); - item.setAction(MainWindowMenuHandler.getAction("EditOverwriteTranslationMenuItem")); + item.setAction(new MainWindowMenuHandler.EditOverwriteTranslationMenuItemAction()); item.setEnabled(hasMatches); popup.addSeparator(); diff --git a/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java b/test-acceptance/src/org/omegat/gui/dialogs/AboutDialogTest.java index 1e8bb4f7ba..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(OStrings.getString("TF_MENU_HELP")).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/src/org/omegat/gui/main/MainWindowMenuTest.java b/test/src/org/omegat/gui/main/MainWindowMenuTest.java index a956dcc77f..8ab60e25c7 100644 --- a/test/src/org/omegat/gui/main/MainWindowMenuTest.java +++ b/test/src/org/omegat/gui/main/MainWindowMenuTest.java @@ -33,12 +33,12 @@ import java.awt.Component; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Locale; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import java.util.stream.Collectors; +import javax.swing.Action; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -48,7 +48,6 @@ 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; @@ -66,25 +65,28 @@ public class MainWindowMenuTest extends TestCore { * */ @Test - public void testMenuActions() { + public void testMenuActionsClassNames() { int count = 0; - Set actionTargets = MainWindowMenuHandler.getActions().keySet(); + // 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 actionClassName = StringUtil.capitalizeFirst(f.getName(), Locale.ENGLISH); - if (!actionTargets.contains(actionClassName)) { + String actionClassName = StringUtil.capitalizeFirst(f.getName(), Locale.ENGLISH) + "Action"; + if (!actions.contains(actionClassName)) { fail("Action method or class not defined for " + actionClassName); } else { - assertTrue(actionTargets.remove(actionClassName)); + assertTrue(actions.remove(actionClassName)); } } } assertTrue("menu items not found", count > 30); assertTrue("There is action handlers in MainWindow which doesn't used in menu: " - + actionTargets, actionTargets.isEmpty()); + + actions, actions.isEmpty()); } @Test @@ -123,7 +125,7 @@ private String getLocalizedText(final String key) { static class TestMainMenu extends BaseMainWindowMenu { TestMainMenu() { - super(null); + super(); } @Override @@ -293,21 +295,4 @@ 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))); - } - }); - } }