diff --git a/src/org/omegat/gui/main/BaseMainWindowMenu.java b/src/org/omegat/gui/main/BaseMainWindowMenu.java index 74fef3d850..6563408ebe 100644 --- a/src/org/omegat/gui/main/BaseMainWindowMenu.java +++ b/src/org/omegat/gui/main/BaseMainWindowMenu.java @@ -44,9 +44,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.EnumMap; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -119,8 +117,6 @@ public abstract class BaseMainWindowMenu implements ActionListener, MenuListener /** MainWindow menu handler instance. */ protected final MainWindowMenuHandler mainWindowMenuHandler; - private final Map menus = new EnumMap<>(MenuExtender.MenuKey.class); - public BaseMainWindowMenu(final MainWindow mainWindow, final MainWindowMenuHandler mainWindowMenuHandler) { this.mainWindow = mainWindow; @@ -197,18 +193,18 @@ void initComponents() { abstract void createMenuBar(); protected void createComponents() { - projectMenu = createMenu("TF_MENU_FILE", MenuExtender.MenuKey.PROJECT); - editMenu = createMenu("TF_MENU_EDIT", MenuExtender.MenuKey.EDIT); - gotoMenu = createMenu("MW_GOTOMENU", MenuExtender.MenuKey.GOTO); - viewMenu = createMenu("MW_VIEW_MENU", MenuExtender.MenuKey.VIEW); - toolsMenu = createMenu("TF_MENU_TOOLS", MenuExtender.MenuKey.TOOLS); - optionsMenu = createMenu("MW_OPTIONSMENU", MenuExtender.MenuKey.OPTIONS); - helpMenu = createMenu("TF_MENU_HELP", MenuExtender.MenuKey.HELP); + projectMenu = createMenu(PROJECT_MENU, "TF_MENU_FILE"); + editMenu = createMenu(EDIT_MENU, "TF_MENU_EDIT"); + gotoMenu = createMenu(GOTO_MENU, "MW_GOTOMENU"); + viewMenu = createMenu(VIEW_NEMU, "MW_VIEW_MENU"); + toolsMenu = createMenu(TOOLS_MENU, "TF_MENU_TOOLS"); + optionsMenu = createMenu(OPTIONS_MENU, "MW_OPTIONSMENU"); + helpMenu = createMenu(HELP_MENU, "TF_MENU_HELP"); projectNewMenuItem = createMenuItem("TF_MENU_FILE_CREATE"); projectTeamNewMenuItem = createMenuItem("TF_MENU_FILE_TEAM_CREATE"); projectOpenMenuItem = createMenuItem("TF_MENU_FILE_OPEN"); - projectOpenRecentMenuItem = createMenu("TF_MENU_FILE_OPEN_RECENT"); + projectOpenRecentMenuItem = createMenu(PROJECT_OPEN_RECENT_SUBMENU, "TF_MENU_FILE_OPEN_RECENT"); projectClearRecentMenuItem = createMenuItem("TF_MENU_FILE_CLEAR_RECENT"); projectReloadMenuItem = createMenuItem("TF_MENU_PROJECT_RELOAD"); @@ -223,9 +219,10 @@ protected void createComponents() { projectMedOpenMenuItem = createMenuItem("TF_MENU_FILE_MED_OPEN"); projectMedCreateMenuItem = createMenuItem("TF_MENU_FILE_MED_CREATE"); projectEditMenuItem = createMenuItem("MW_PROJECTMENU_EDIT"); - viewFileListMenuItem = createMenuItem("TF_MENU_FILE_PROJWIN"); + viewFileListMenuItem = createMenuItem(PROJECT_VIEW_FILE_LIST_MENUITEM, "TF_MENU_FILE_PROJWIN"); - projectAccessProjectFilesMenu = createMenu("TF_MENU_FILE_ACCESS_PROJECT_FILES"); + projectAccessProjectFilesMenu = createMenu(PROJECT_ACCESS_PROJECT_FILES_SUBMENU, + "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"); @@ -270,8 +267,8 @@ protected void createComponents() { editFindInProjectMenuItem = createMenuItem("TF_MENU_EDIT_FIND"); editReplaceInProjectMenuItem = createMenuItem("TF_MENU_EDIT_REPLACE"); editSearchDictionaryMenuItem = createMenuItem("TF_MENU_EDIT_SEARCH_DICTIONARY"); - switchCaseSubMenu = createMenu("TF_EDIT_MENU_SWITCH_CASE"); - selectFuzzySubMenu = createMenu("TF_MENU_EDIT_COMPARE"); + switchCaseSubMenu = createMenu(SWITCH_CASE_SUBMENU, "TF_EDIT_MENU_SWITCH_CASE"); + selectFuzzySubMenu = createMenu(SELECT_FUZZY_SUBMENU, "TF_MENU_EDIT_COMPARE"); editSelectFuzzyPrevMenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_PREV"); editSelectFuzzyNextMenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_NEXT"); @@ -281,7 +278,7 @@ protected void createComponents() { editSelectFuzzy4MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_4"); editSelectFuzzy5MenuItem = createMenuItem("TF_MENU_EDIT_COMPARE_5"); - insertCharsSubMenu = createMenu("TF_MENU_EDIT_INSERT_CHARS"); + insertCharsSubMenu = createMenu(INSERT_CHARS_SUBMENU, "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"); @@ -309,7 +306,7 @@ protected void createComponents() { gotoPreviousNoteMenuItem = createMenuItem("TF_MENU_EDIT_PREV_NOTE"); gotoNextUniqueMenuItem = createMenuItem("TF_MENU_GOTO_NEXT_UNIQUE"); gotoMatchSourceSegment = createMenuItem("TF_MENU_GOTO_SELECTED_MATCH_SOURCE"); - gotoXEntrySubmenu = createMenu("TF_MENU_GOTO_X_SUBMENU"); + gotoXEntrySubmenu = createMenu(GOTO_X_ENTRY_SUBMENU, "TF_MENU_GOTO_X_SUBMENU"); gotoNextXAutoMenuItem = createMenuItem("TF_MENU_GOTO_NEXT_XAUTO"); gotoPrevXAutoMenuItem = createMenuItem("TF_MENU_GOTO_PREV_XAUTO"); @@ -321,24 +318,34 @@ protected void createComponents() { gotoNotesPanelMenuItem = createMenuItem("TF_MENU_GOTO_NOTES_PANEL"); gotoEditorPanelMenuItem = createMenuItem("TF_MENU_GOTO_EDITOR_PANEL"); - viewMarkTranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( - "TF_MENU_DISPLAY_MARK_TRANSLATED"); + viewMarkTranslatedSegmentsCheckBoxMenuItem = + createCheckboxMenuItem(VIEW_MARK_TRANSLATED_SEGMENTS_CHECKBOX, "TF_MENU_DISPLAY_MARK_TRANSLATED"); viewMarkUntranslatedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( - "TF_MENU_DISPLAY_MARK_UNTRANSLATED"); - viewMarkParagraphStartCheckBoxMenuItem = createCheckboxMenuItem("TF_MENU_DISPLAY_MARK_PARAGRAPH"); + VIEW_MARK_UNTRANSLATED_SEGMENTS_CHECKBOX, "TF_MENU_DISPLAY_MARK_UNTRANSLATED"); + viewMarkParagraphStartCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_PARAGRAPH_START_CHECKBOX, "TF_MENU_DISPLAY_MARK_PARAGRAPH"); viewDisplaySegmentSourceCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_DISPLAY_SEGMENT_SOURCE_CHECKBOX, "MW_VIEW_MENU_DISPLAY_SEGMENT_SOURCES"); viewMarkNonUniqueSegmentsCheckBoxMenuItem = createCheckboxMenuItem( - "MW_VIEW_MENU_MARK_NON_UNIQUE_SEGMENTS"); - viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NOTED_SEGMENTS"); - viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_NBSP"); - viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_WHITESPACE"); - viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_BIDI"); - viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_AUTOPOPULATED"); - viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_GLOSSARY_MARK"); - viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItem("LT_OPTIONS_MENU_ENABLED"); - viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItem("MW_VIEW_MENU_MARK_FONT_FALLBACK"); - viewModificationInfoMenu = createMenu("MW_VIEW_MENU_MODIFICATION_INFO"); + VIEW_MARK_NON_UNIQUE_SEGMENTS_CHECKBOX, "MW_VIEW_MENU_MARK_NON_UNIQUE_SEGMENTS"); + viewMarkNotedSegmentsCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_NOTED_SEGMENTS_CHECKBOX, "MW_VIEW_MENU_MARK_NOTED_SEGMENTS"); + viewMarkNBSPCheckBoxMenuItem = createCheckboxMenuItem(VIEW_MARK_NBSP_CHECKBOX, "MW_VIEW_MENU_MARK_NBSP"); + viewMarkWhitespaceCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_WHITE_SPACE_CHECKBOX, "MW_VIEW_MENU_MARK_WHITESPACE"); + viewMarkBidiCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_BIDI_CHECKBOX, "MW_VIEW_MENU_MARK_BIDI"); + viewMarkAutoPopulatedCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_AUTO_POPULATED_CHECKBOX, "MW_VIEW_MENU_MARK_AUTOPOPULATED"); + viewMarkGlossaryMatchesCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_GLOSSARY_MATCHES_CHECKBOX, "MW_VIEW_GLOSSARY_MARK"); + viewMarkLanguageCheckerCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_LANGUAGE_CHECKER_CHECKBOX, "LT_OPTIONS_MENU_ENABLED"); + viewMarkFontFallbackCheckBoxMenuItem = createCheckboxMenuItem( + VIEW_MARK_FONT_FALLBACK_CHECKBOX, "MW_VIEW_MENU_MARK_FONT_FALLBACK"); + viewModificationInfoMenu = createMenu(VIEW_MODIFICATION_INFO_SUBMENU, + "MW_VIEW_MENU_MODIFICATION_INFO"); ButtonGroup viewModificationInfoMenuBG = new ButtonGroup(); viewDisplayModificationInfoNoneRadioButtonMenuItem = createRadioButtonMenuItem( @@ -384,24 +391,30 @@ protected void createComponents() { "TF_MENU_TOOLS_STATISTICS_MATCHES_PER_FILE"); optionsPreferencesMenuItem = createMenuItem("MW_OPTIONSMENU_PREFERENCES"); - optionsMachineTranslateMenu = createMenu("TF_OPTIONSMENU_MACHINETRANSLATE"); + optionsMachineTranslateMenu = createMenu(OPTIONS_MACHINE_TRANSLATE_SUBMENU, + "TF_OPTIONSMENU_MACHINETRANSLATE"); - optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItem("MT_AUTO_FETCH"); - optionsGlossaryMenu = createMenu("TF_OPTIONSMENU_GLOSSARY"); - optionsGlossaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem( + optionsMTAutoFetchCheckboxMenuItem = createCheckboxMenuItem(OPTIONS_MT_AUTO_FETCH_CHECKBOX_MENUITEM, + "MT_AUTO_FETCH"); + optionsGlossaryMenu = createMenu(OPTIONS_GLOSSARY_SUBMENU, "TF_OPTIONSMENU_GLOSSARY"); + optionsGlossaryFuzzyMatchingCheckBoxMenuItem = + createCheckboxMenuItem(OPTIONS_DICTIONARY_FUZZY_MATCHING_CHECKBOX, "TF_OPTIONSMENU_GLOSSARY_FUZZY"); - optionsDictionaryMenu = createMenu("TF_OPTIONSMENU_DICTIONARY"); - optionsDictionaryFuzzyMatchingCheckBoxMenuItem = createCheckboxMenuItem( - "TF_OPTIONSMENU_DICTIONARY_FUZZY"); + optionsDictionaryMenu = createMenu(OPTIONS_DICTIONARY_SUBMENU, "TF_OPTIONSMENU_DICTIONARY"); + optionsDictionaryFuzzyMatchingCheckBoxMenuItem = + createCheckboxMenuItem(OPTIONS_DICTIONARY_FUZZY_MATCHING_CHECKBOX, "TF_OPTIONSMENU_DICTIONARY_FUZZY"); - optionsAutoCompleteMenu = createMenu("MW_OPTIONSMENU_AUTOCOMPLETE"); + optionsAutoCompleteMenu = createMenu(OPTIONS_AUTOCOMPLETE_SUBMENU, "MW_OPTIONSMENU_AUTOCOMPLETE"); // add any autocomplete view configuration menu items below - optionsAutoCompleteShowAutomaticallyItem = createCheckboxMenuItem( + optionsAutoCompleteShowAutomaticallyItem = + createCheckboxMenuItem(OPTIONS_AUTO_COMPLETE_SHOW_AUTOMATICALLY_MENUITEM, "MW_OPTIONSMENU_AUTOCOMPLETE_SHOW_AUTOMATICALLY"); - optionsAutoCompleteHistoryCompletionMenuItem = createCheckboxMenuItem( + optionsAutoCompleteHistoryCompletionMenuItem = + createCheckboxMenuItem(OPTIONS_AUTO_COMPLETE_HISTORY_COMPLETION_MENUITEM, "MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_COMPLETION"); - optionsAutoCompleteHistoryPredictionMenuItem = createCheckboxMenuItem( + optionsAutoCompleteHistoryPredictionMenuItem = + createCheckboxMenuItem(OPTIONS_AUTO_COMPLETE_HISTORY_PREDICTION_MENUITEM, "MW_OPTIONSMENU_AUTOCOMPLETE_HISTORY_PREDICTION"); optionsSetupFileFiltersMenuItem = createMenuItem("TF_MENU_DISPLAY_GLOBAL_FILTERS"); optionsSentsegMenuItem = createMenuItem("MW_OPTIONSMENU_GLOBAL_SENTSEG"); @@ -728,21 +741,17 @@ public void invokeAction(String action, int modifiers) { /** * Create menu instance and set title. * + * @param name + * name of menu. * @param titleKey * title name key in resource bundle * @return menu instance */ - protected JMenu createMenu(String titleKey) { - return createMenu(titleKey, null); - } - - protected JMenu createMenu(String titleKey, MenuExtender.MenuKey menuKey) { + protected JMenu createMenu(String name, String titleKey) { JMenu result = new JMenu(); + result.setName(name); Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); result.addMenuListener(this); - if (menuKey != null) { - menus.put(menuKey, result); - } return result; } @@ -760,6 +769,13 @@ protected JMenuItem createMenuItem(String titleKey) { return result; } + protected JMenuItem createMenuItem(String name, String titleKey) { + JMenuItem result = new JMenuItem(); + result.setName(name); + Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); + result.addActionListener(this); + return result; + } /** * Create menu item instance and set title. * @@ -774,6 +790,14 @@ protected JCheckBoxMenuItem createCheckboxMenuItem(final String titleKey) { return result; } + protected JCheckBoxMenuItem createCheckboxMenuItem(String name, String titleKey) { + JCheckBoxMenuItem result = new JCheckBoxMenuItem(); + result.setName(name); + Mnemonics.setLocalizedText(result, OStrings.getString(titleKey)); + result.addActionListener(this); + return result; + } + /** * Create menu item instance and set title. * @@ -854,6 +878,21 @@ protected void onProjectStatusChanged(final boolean isProjectOpened) { && Core.getProject().getProjectProperties().getTargetDir().isUnderRoot()); } + public JMenuItem getMenuItemForNames(String menuName, String itemName) { + for (int i = 0; i < mainMenu.getMenuCount(); i ++) { + JMenu menu = mainMenu.getMenu(i); + if (menuName.equals(menu.getName())) { + for (int j = 0; j < menu.getItemCount(); j++) { + JMenuItem item = optionsMenu.getItem(i); + if (itemName.equals(item.getName())) { + return item; + } + } + } + } + return null; + } + protected JMenuItem getItemForPreference(String preference) { switch (preference) { case Preferences.AC_SHOW_SUGGESTIONS_AUTOMATICALLY: @@ -982,7 +1021,24 @@ public JMenu getHelpMenu() { } public JMenu getMenu(MenuExtender.MenuKey marker) { - return menus.get(marker); + switch(marker) { + case PROJECT: + return projectMenu; + case EDIT: + return editMenu; + case VIEW: + return viewMenu; + case GOTO: + return gotoMenu; + case TOOLS: + return toolsMenu; + case OPTIONS: + return optionsMenu; + case HELP: + return helpMenu; + default: + return null; + } } JMenuItem cycleSwitchCaseMenuItem; @@ -1124,4 +1180,61 @@ public JMenu getMenu(MenuExtender.MenuKey marker) { JCheckBoxMenuItem viewMarkUntranslatedSegmentsCheckBoxMenuItem; JCheckBoxMenuItem viewMarkParagraphStartCheckBoxMenuItem; JMenu viewMenu; + + public static final String PROJECT_MENU = "project_menu"; + public static final String EDIT_MENU = "edit_menu"; + public static final String GOTO_MENU = "goto_menu;"; + public static final String VIEW_NEMU = "view_menu"; + public static final String TOOLS_MENU = "tools_menu"; + public static final String OPTIONS_MENU = "options_menu"; + public static final String HELP_MENU = "help_menu"; + public static final String PROJECT_NEW_MENUITEM = "project_new_menuitem"; + public static final String PROJECT_NEW_TEAM_MENUITEM = "project_new_team_menuitem"; + public static final String PROJECT_OPEN_MENUITEM = "project_open_menuitem"; + public static final String PROJECT_OPEN_RECENT_SUBMENU = "project_open_recent_submenu"; + public static final String PROJECT_CLEAR_RECENT_MENUITEM = "project_clear_recent_menuitem"; + public static final String PROJECT_ACCESS_PROJECT_FILES_SUBMENU = "project_access_project_files_submenu"; + public static final String PROJECT_EXIT_MENUITEM = "project_exit_menuitem"; + public static final String PROJECT_RELOAD_MENU = "project_reload_menu"; + public static final String PROJECT_ACCESS_ROOT_MENU = "project_access_root_menu"; + public static final String PROJECT_VIEW_FILE_LIST_MENUITEM = "project_view_file_list_menuitem"; + public static final String SELECT_FUZZY_SUBMENU = "select_fuzzy_submenu"; + public static final String EDIT_CREATE_GLOSSARY_MENUITEM = "edit_create_glossary_menuitem"; + public static final String INSERT_CHARS_SUBMENU = "insert_chars_submenu"; + public static final String GOTO_X_ENTRY_SUBMENU = "goto_x_entry_submenu"; + public static final String VIEW_MODIFICATION_INFO_SUBMENU = "view_modification_info_submenu"; + public static final String VIEW_MARK_TRANSLATED_SEGMENTS_CHECKBOX = "view_mark_translated_segment_checkbox"; + public static final String VIEW_MARK_UNTRANSLATED_SEGMENTS_CHECKBOX = "view_mark_untranslated_segments_checkbox"; + public static final String VIEW_MARK_PARAGRAPH_START_CHECKBOX = "view_mark_paragraph_start_checkbox"; + public static final String VIEW_DISPLAY_SEGMENT_SOURCE_CHECKBOX = "view_display_segment_source_checkbox"; + public static final String VIEW_DISPLAY_MODIFICATION_INFO_NONE_RADIO_BUTTON = + "view_display_modification_info_none_radio_button"; + public static final String VIEW_MARK_NON_UNIQUE_SEGMENTS_CHECKBOX = "view_mark_non_unique_segments_checkbox"; + public static final String VIEW_MARK_NOTED_SEGMENTS_CHECKBOX = "view_mark_noted_segments_checkbox"; + public static final String VIEW_MARK_WHITE_SPACE_CHECKBOX = "view_mark_white_space_checkbox"; + public static final String VIEW_MARK_NBSP_CHECKBOX = "view_mark_nbsp_checkbox"; + public static final String VIEW_MARK_BIDI_CHECKBOX = "view_mark_bidi_checkbox"; + public static final String VIEW_MARK_AUTO_POPULATED_CHECKBOX = "view_mark_auto_populated_checkbox"; + public static final String VIEW_MARK_GLOSSARY_MATCHES_CHECKBOX = "view_mark_glossary_matches_checkbox"; + public static final String VIEW_MARK_LANGUAGE_CHECKER_CHECKBOX = "view_mark_language_checker_checkbox"; + public static final String VIEW_MARK_FONT_FALLBACK_CHECKBOX = "view_mark_font_fallback_checkbox"; + public static final String OPTIONS_MACHINE_TRANSLATE_SUBMENU = "options_machine_translate_submenu"; + public static final String OPTIONS_DICTIONARY_SUBMENU = "options_dictionary_submenu"; + public static final String OPTIONS_GLOSSARY_SUBMENU = "options_glossary_submenu"; + public static final String OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM = + "options_glossary_fuzzy_matching_checkbox_menuitem"; + public static final String OPTIONS_AUTOCOMPLETE_SUBMENU = "options_autocomplete_submenu"; + public static final String OPTIONS_DICTIONARY_FUZZY_MATCHING_CHECKBOX = + "options_dictionary_fuzzy_matching_checkbox"; + public static final String OPTIONS_MT_AUTO_FETCH_CHECKBOX_MENUITEM = + "options_mt_auto_fetch_checkbox"; + public static final String OPTIONS_AUTO_COMPLETE_HISTORY_PREDICTION_MENUITEM = + "options_auto_complete_history_prediction_menuitem"; + public static final String OPTIONS_AUTO_COMPLETE_HISTORY_COMPLETION_MENUITEM = + "options_auto_complete_history_completion_menuitem"; + public static final String OPTIONS_AUTO_COMPLETE_SHOW_AUTOMATICALLY_MENUITEM = + "options_auto_complete_show_automatically_menuitem"; + public static final String HELP_ABOUT_MENUITEM = "help_about_menuitem"; + public static final String HELP_LOG_MENUITEM = "help_log_menuitem"; + public static final String SWITCH_CASE_SUBMENU = "switch_case_submenu"; } diff --git a/src/org/omegat/gui/main/BaseMainWindowMenuHandler.java b/src/org/omegat/gui/main/BaseMainWindowMenuHandler.java new file mode 100644 index 0000000000..dd6d6e9e0c --- /dev/null +++ b/src/org/omegat/gui/main/BaseMainWindowMenuHandler.java @@ -0,0 +1,77 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, Henry Pijffers, + Benjamin Siband, and Kim Bruning + 2007 Zoltan Bartko + 2008 Andrzej Sawula, Alex Buloichik + 2009 Didier Briel, Alex Buloichik + 2010 Wildrich Fourie, Didier Briel + 2012 Wildrich Fourie, Guido Leenders, Didier Briel + 2013 Zoltan Bartko, Didier Briel, Yu Tang + 2014 Aaron Madlon-Kay + 2015 Yu Tang, Aaron Madlon-Kay, Didier Briel + 2017 Didier Briel + 2019 Thomas Cordonnier + Home page: https://www.omegat.org/ + Support center: https://omegat.org/support + + This file is part of OmegaT. + + OmegaT is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OmegaT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + **************************************************************************/ +package org.omegat.gui.main; + +/** + * @author Hiroshi Miura + */ +public abstract class BaseMainWindowMenuHandler { + + /** + * Common base class for menu handler. + *

+ * There should be a mandatory methods for mandatory + * commands. + */ + public BaseMainWindowMenuHandler() { + } + + public void projectExitMenuItemActionPerformed() { + System.exit(0); + } + + public void editFindInProjectMenuItemActionPerformed() { + } + + public void optionsPreferencesMenuItemActionPerformed() { + } + + public void projectNewMenuItemActionPerformed() { + } + + public void projectOpenMenuItemActionPerformed() { + } + + public void projectTeamNewMenuItemActionPerformed() { + } + + void findInProjectReuseLastWindow() { + } + + public void helpAboutMenuItemActionPerformed() { + } + +} diff --git a/src/org/omegat/gui/main/ConsoleWindow.java b/src/org/omegat/gui/main/ConsoleWindow.java index 30aa0a3003..69e47c6f65 100644 --- a/src/org/omegat/gui/main/ConsoleWindow.java +++ b/src/org/omegat/gui/main/ConsoleWindow.java @@ -28,9 +28,11 @@ import java.awt.Cursor; import java.awt.Font; import java.awt.HeadlessException; +import java.util.List; 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 +144,24 @@ public DockingDesktop getDesktop() { return null; } + @Override + public void resetDesktopLayout() { + } + + @Override + public void addSearchWindow(final SearchWindowController newSearchWindow) { + } + + @Override + public List getSearchWindows() { + return null; + } + + @Override + public void saveScreenLayout() { + + } + public Cursor getCursor() { return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } diff --git a/src/org/omegat/gui/main/IMainMenu.java b/src/org/omegat/gui/main/IMainMenu.java index 793051dd28..c0d59d3629 100644 --- a/src/org/omegat/gui/main/IMainMenu.java +++ b/src/org/omegat/gui/main/IMainMenu.java @@ -28,6 +28,7 @@ package org.omegat.gui.main; import javax.swing.JMenu; +import javax.swing.JMenuItem; import org.omegat.util.gui.MenuExtender; @@ -55,5 +56,7 @@ public interface IMainMenu { JMenu getMenu(MenuExtender.MenuKey marker); + JMenuItem getMenuItemForNames(String menuName, String itemName); + void invokeAction(String action, int modifiers); } diff --git a/src/org/omegat/gui/main/IMainWindow.java b/src/org/omegat/gui/main/IMainWindow.java index 50b7f7b6ba..0e92fb2500 100644 --- a/src/org/omegat/gui/main/IMainWindow.java +++ b/src/org/omegat/gui/main/IMainWindow.java @@ -28,9 +28,12 @@ import java.awt.Cursor; import java.awt.Font; import java.awt.HeadlessException; +import java.util.List; import javax.swing.JFrame; +import org.omegat.gui.search.SearchWindowController; + import com.vlsolutions.swing.docking.Dockable; import com.vlsolutions.swing.docking.DockingDesktop; @@ -204,4 +207,12 @@ public interface IMainWindow { * Retrieve main docking desktop. */ DockingDesktop getDesktop(); + + void resetDesktopLayout(); + + void addSearchWindow(SearchWindowController newSearchWindow); + + List getSearchWindows(); + + void saveScreenLayout(); } diff --git a/src/org/omegat/gui/main/MainWindow.java b/src/org/omegat/gui/main/MainWindow.java index 64943c83de..c5c21c7f1d 100644 --- a/src/org/omegat/gui/main/MainWindow.java +++ b/src/org/omegat/gui/main/MainWindow.java @@ -67,16 +67,12 @@ import javax.swing.UIManager; import javax.swing.WindowConstants; import javax.swing.plaf.FontUIResource; -import javax.swing.text.JTextComponent; import org.omegat.core.Core; import org.omegat.core.CoreEvents; -import org.omegat.core.data.DataUtils; import org.omegat.core.events.IApplicationEventListener; import org.omegat.core.events.IProjectEventListener; -import org.omegat.core.matching.NearString; import org.omegat.gui.filelist.ProjectFilesListController; -import org.omegat.gui.matches.IMatcher; import org.omegat.gui.search.SearchWindowController; import org.omegat.util.OStrings; import org.omegat.util.Preferences; @@ -273,73 +269,7 @@ private void updateTitle() { setTitle(s); } - /** insert current fuzzy match or selection at cursor position */ - public void doInsertTrans() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - - String text = getSelectedTextInMatcher(); - boolean fromMT = false; - if (StringUtil.isEmpty(text)) { - NearString near = Core.getMatcher().getActiveMatch(); - if (near != null) { - text = near.translation; - if (Preferences.isPreference(Preferences.CONVERT_NUMBERS)) { - text = Core.getMatcher().substituteNumbers( - Core.getEditor().getCurrentEntry().getSrcText(), near.source, near.translation); - } - - if (DataUtils.isFromMTMemory(near)) { - fromMT = true; - } - } - } - if (!StringUtil.isEmpty(text)) { - if (fromMT) { - Core.getEditor().insertTextAndMark(text); - } else { - Core.getEditor().insertText(text); - } - Core.getEditor().requestFocus(); - } - } - - /** replace entire edit area with active fuzzy match or selection */ - public void doRecycleTrans() { - if (!Core.getProject().isProjectLoaded()) { - return; - } - - String selection = getSelectedTextInMatcher(); - if (!StringUtil.isEmpty(selection)) { - Core.getEditor().replaceEditText(selection); - Core.getEditor().requestFocus(); - return; - } - - NearString near = Core.getMatcher().getActiveMatch(); - if (near != null) { - String translation = near.translation; - if (Preferences.isPreference(Preferences.CONVERT_NUMBERS)) { - translation = Core.getMatcher().substituteNumbers( - Core.getEditor().getCurrentEntry().getSrcText(), near.source, near.translation); - } - if (DataUtils.isFromMTMemory(near)) { - Core.getEditor().replaceEditTextAndMark(translation, "TM:[tm/mt]"); - } else { - Core.getEditor().replaceEditText(translation, "TM:[generic]"); - } - Core.getEditor().requestFocus(); - } - } - - private String getSelectedTextInMatcher() { - IMatcher matcher = Core.getMatcher(); - 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) { @@ -367,7 +297,7 @@ private void closeSearchWindows() { } } - protected List getSearchWindows() { + public List getSearchWindows() { return Collections.unmodifiableList(searches); } @@ -636,7 +566,18 @@ public void showMessageDialog(String message) { /** * get DockableDesktop object. */ + @Override public DockingDesktop getDesktop() { return desktop; } + + @Override + public void resetDesktopLayout() { + MainWindowUI.resetDesktopLayout(this); + } + + @Override + public void saveScreenLayout() { + MainWindowUI.saveScreenLayout(this); + } } diff --git a/src/org/omegat/gui/main/MainWindowMenuHandler.java b/src/org/omegat/gui/main/MainWindowMenuHandler.java index b1e70ca3e5..c4faa55a3c 100644 --- a/src/org/omegat/gui/main/MainWindowMenuHandler.java +++ b/src/org/omegat/gui/main/MainWindowMenuHandler.java @@ -43,6 +43,8 @@ import java.util.List; import java.util.regex.Pattern; +import javax.swing.JDialog; +import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.SwingWorker; import javax.swing.text.JTextComponent; @@ -52,7 +54,6 @@ 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; @@ -105,12 +106,11 @@ * @author Yu Tang * @author Aaron Madlon-Kay */ -public final class MainWindowMenuHandler { - private static final String PROP_ORIGIN = ProjectTMX.PROP_ORIGIN; +public final class MainWindowMenuHandler extends BaseMainWindowMenuHandler { private final MainWindow mainWindow; - public MainWindowMenuHandler(final MainWindow mainWindow) { + public MainWindowMenuHandler(MainWindow mainWindow) { this.mainWindow = mainWindow; } @@ -187,7 +187,7 @@ public void projectSaveMenuItemActionPerformed() { */ public void projectCompileMenuItemActionPerformed() { if (!checkTags()) { - return; + return; } ProjectUICommands.projectCompile(); @@ -195,6 +195,7 @@ public void projectCompileMenuItemActionPerformed() { /** * Check whether tags are OK + * * @return false is there is a tag issue, true otherwise */ private boolean checkTags() { @@ -210,7 +211,7 @@ private boolean checkTags() { public void projectCommitTargetFilesActionPerformed() { if (!checkTags()) { - return; + return; } ProjectUICommands.projectCompileAndCommit(); @@ -251,7 +252,8 @@ public void projectEditMenuItemActionPerformed() { public void viewFileListMenuItemActionPerformed() { if (mainWindow.projWin == null) { - mainWindow.menu.viewFileListMenuItem.setSelected(false); + mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.PROJECT_MENU, + BaseMainWindowMenu.PROJECT_VIEW_FILE_LIST_MENUITEM).setSelected(false); return; } @@ -363,7 +365,8 @@ public void projectAccessWriteableGlossaryMenuItemActionPerformed(int modifier) private void openFile(File path) { try { - path = path.getCanonicalFile(); // Normalize file name in case it is displayed + // Normalize file name in case it is displayed + path = path.getCanonicalFile(); } catch (Exception ex) { // Ignore } @@ -396,7 +399,8 @@ public void projectRestartMenuItemActionPerformed() { protected void prepareForExit(Runnable onCompletion) { // Bug #902: commit the current entry first - // We do it before checking project status, so that it can eventually change it + // We do it before checking project status, so that it can eventually + // change it if (Core.getProject().isProjectLoaded()) { Core.getEditor().commitAndLeave(); } @@ -445,11 +449,8 @@ protected Void doInBackground() throws Exception { protected void done() { try { get(); - - MainWindowUI.saveScreenLayout(mainWindow); - + mainWindow.saveScreenLayout(); Preferences.save(); - onCompletion.run(); } catch (Exception ex) { Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); @@ -478,11 +479,11 @@ public void editRedoMenuItemActionPerformed() { } public void editOverwriteTranslationMenuItemActionPerformed() { - mainWindow.doRecycleTrans(); + ProjectUICommands.doRecycleTrans(); } public void editInsertTranslationMenuItemActionPerformed() { - mainWindow.doInsertTrans(); + ProjectUICommands.doInsertTrans(); } public void editOverwriteMachineTranslationMenuItemActionPerformed() { @@ -495,7 +496,8 @@ public void editOverwriteMachineTranslationMenuItemActionPerformed() { } /** - * replaces entire edited segment text with a the source text of a segment at cursor position + * replaces entire edited segment text with a the source text of a segment + * at cursor position */ public void editOverwriteSourceMenuItemActionPerformed() { if (!Core.getProject().isProjectLoaded()) { @@ -796,84 +798,81 @@ public void gotoMatchSourceSegmentActionPerformed() { } public void viewMarkTranslatedSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkTranslated(mainWindow.menu.viewMarkTranslatedSegmentsCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_TRANSLATED_SEGMENTS_CHECKBOX); + Core.getEditor().getSettings().setMarkTranslated(menuItem.isSelected()); } public void viewMarkUntranslatedSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkUntranslated( - mainWindow.menu.viewMarkUntranslatedSegmentsCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_UNTRANSLATED_SEGMENTS_CHECKBOX); + Core.getEditor().getSettings().setMarkUntranslated(menuItem.isSelected()); } public void viewMarkParagraphStartCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkParagraphDelimitations( - mainWindow.menu.viewMarkParagraphStartCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_PARAGRAPH_START_CHECKBOX); + Core.getEditor().getSettings().setMarkParagraphDelimitations(menuItem.isSelected()); } public void viewDisplaySegmentSourceCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setDisplaySegmentSources( - mainWindow.menu.viewDisplaySegmentSourceCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_DISPLAY_SEGMENT_SOURCE_CHECKBOX); + Core.getEditor().getSettings().setDisplaySegmentSources(menuItem.isSelected()); } public void viewMarkNonUniqueSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkNonUniqueSegments( - mainWindow.menu.viewMarkNonUniqueSegmentsCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_NON_UNIQUE_SEGMENTS_CHECKBOX); + Core.getEditor().getSettings().setMarkNonUniqueSegments(menuItem.isSelected()); } public void viewMarkNotedSegmentsCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkNotedSegments( - mainWindow.menu.viewMarkNotedSegmentsCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_NOTED_SEGMENTS_CHECKBOX); + Core.getEditor().getSettings().setMarkNotedSegments(menuItem.isSelected()); } public void viewMarkNBSPCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkNBSP( - mainWindow.menu.viewMarkNBSPCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_NBSP_CHECKBOX); + Core.getEditor().getSettings().setMarkNBSP(menuItem.isSelected()); } public void viewMarkWhitespaceCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkWhitespace( - mainWindow.menu.viewMarkWhitespaceCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_WHITE_SPACE_CHECKBOX); + Core.getEditor().getSettings().setMarkWhitespace(menuItem.isSelected()); } public void viewMarkBidiCheckBoxMenuItemActionPerformed() { - Core.getEditor() - .getSettings() - .setMarkBidi( - mainWindow.menu.viewMarkBidiCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_BIDI_CHECKBOX); + Core.getEditor().getSettings().setMarkBidi(menuItem.isSelected()); } public void viewMarkAutoPopulatedCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkAutoPopulated(mainWindow.menu.viewMarkAutoPopulatedCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_AUTO_POPULATED_CHECKBOX); + Core.getEditor().getSettings().setMarkAutoPopulated(menuItem.isSelected()); } public void viewMarkGlossaryMatchesCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkGlossaryMatches(mainWindow.menu.viewMarkGlossaryMatchesCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_GLOSSARY_MATCHES_CHECKBOX); + Core.getEditor().getSettings().setMarkGlossaryMatches(menuItem.isSelected()); } public void viewMarkLanguageCheckerCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setMarkLanguageChecker(mainWindow.menu.viewMarkLanguageCheckerCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_LANGUAGE_CHECKER_CHECKBOX); + Core.getEditor().getSettings().setMarkLanguageChecker(menuItem.isSelected()); } public void viewMarkFontFallbackCheckBoxMenuItemActionPerformed() { - Core.getEditor().getSettings() - .setDoFontFallback(mainWindow.menu.viewMarkFontFallbackCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.VIEW_NEMU, + BaseMainWindowMenu.VIEW_MARK_FONT_FALLBACK_CHECKBOX); + Core.getEditor().getSettings().setDoFontFallback(menuItem.isSelected()); } public void viewDisplayModificationInfoNoneRadioButtonMenuItemActionPerformed() { @@ -906,7 +905,8 @@ public void toolsCheckIssuesCurrentFileMenuItemActionPerformed() { } /** - * Identify all the placeholders in the source text and automatically inserts them into the target text. + * Identify all the placeholders in the source text and automatically + * inserts them into the target text. */ public void editTagPainterMenuItemActionPerformed() { // insert tags @@ -935,70 +935,82 @@ public void toolsShowStatisticsMatchesMenuItemActionPerformed() { } public void toolsShowStatisticsMatchesPerFileMenuItemActionPerformed() { - new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), StatisticsWindow.STAT_TYPE.MATCHES_PER_FILE) - .setVisible(true); + new StatisticsWindow(Core.getMainWindow().getApplicationFrame(), + StatisticsWindow.STAT_TYPE.MATCHES_PER_FILE).setVisible(true); } public void optionsAutoCompleteShowAutomaticallyItemActionPerformed() { - Preferences.setPreference(Preferences.AC_SHOW_SUGGESTIONS_AUTOMATICALLY, - mainWindow.menu.optionsAutoCompleteShowAutomaticallyItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.OPTIONS_MENU, + BaseMainWindowMenu.OPTIONS_AUTO_COMPLETE_SHOW_AUTOMATICALLY_MENUITEM); + Preferences.setPreference(Preferences.AC_SHOW_SUGGESTIONS_AUTOMATICALLY, menuItem.isSelected()); } public void optionsAutoCompleteHistoryCompletionMenuItemActionPerformed() { - Preferences.setPreference(Preferences.AC_HISTORY_COMPLETION_ENABLED, - mainWindow.menu.optionsAutoCompleteHistoryCompletionMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.OPTIONS_MENU, + BaseMainWindowMenu.OPTIONS_AUTO_COMPLETE_HISTORY_COMPLETION_MENUITEM); + Preferences.setPreference(Preferences.AC_HISTORY_COMPLETION_ENABLED, menuItem.isSelected()); } public void optionsAutoCompleteHistoryPredictionMenuItemActionPerformed() { - Preferences.setPreference(Preferences.AC_HISTORY_PREDICTION_ENABLED, - mainWindow.menu.optionsAutoCompleteHistoryPredictionMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.OPTIONS_MENU, + BaseMainWindowMenu.OPTIONS_AUTO_COMPLETE_HISTORY_PREDICTION_MENUITEM); + Preferences.setPreference(Preferences.AC_HISTORY_PREDICTION_ENABLED, menuItem.isSelected()); } public void optionsMTAutoFetchCheckboxMenuItemActionPerformed() { - boolean enabled = mainWindow.menu.optionsMTAutoFetchCheckboxMenuItem.isSelected(); - Preferences.setPreference(Preferences.MT_AUTO_FETCH, enabled); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.OPTIONS_MENU, + BaseMainWindowMenu.OPTIONS_MT_AUTO_FETCH_CHECKBOX_MENUITEM); + Preferences.setPreference(Preferences.MT_AUTO_FETCH, menuItem.isSelected()); } public void optionsGlossaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { - Preferences.setPreference(Preferences.GLOSSARY_STEMMING, - mainWindow.menu.optionsGlossaryFuzzyMatchingCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.OPTIONS_MENU, + BaseMainWindowMenu.OPTIONS_GLOSSARY_FUZZY_MATCHING_CHECKBOX_MENUITEM); + Preferences.setPreference(Preferences.GLOSSARY_STEMMING, menuItem.isSelected()); Preferences.save(); } public void optionsDictionaryFuzzyMatchingCheckBoxMenuItemActionPerformed() { - Preferences.setPreference(Preferences.DICTIONARY_FUZZY_MATCHING, - mainWindow.menu.optionsDictionaryFuzzyMatchingCheckBoxMenuItem.isSelected()); + JMenuItem menuItem = mainWindow.getMainMenu().getMenuItemForNames(BaseMainWindowMenu.OPTIONS_MENU, + BaseMainWindowMenu.OPTIONS_DICTIONARY_FUZZY_MATCHING_CHECKBOX); + Preferences.setPreference(Preferences.DICTIONARY_FUZZY_MATCHING, menuItem.isSelected()); Preferences.save(); } + /** - * Displays the filters setup dialog to allow customizing file filters in detail. + * Displays the filters setup dialog to allow customizing file filters in + * detail. */ public void optionsSetupFileFiltersMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), FiltersCustomizerController.class); + new PreferencesWindowController().show(mainWindow.getApplicationFrame(), + FiltersCustomizerController.class); } /** - * Displays the segmentation setup dialog to allow customizing the segmentation rules in detail. + * Displays the segmentation setup dialog to allow customizing the + * segmentation rules in detail. */ public void optionsSentsegMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), SegmentationCustomizerController.class); - + new PreferencesWindowController().show(mainWindow.getApplicationFrame(), + SegmentationCustomizerController.class); } /** - * Displays the workflow setup dialog to allow customizing the diverse workflow options. + * Displays the workflow setup dialog to allow customizing the diverse + * workflow options. */ public void optionsWorkflowMenuItemActionPerformed() { - new PreferencesWindowController().show(mainWindow.getApplicationFrame(), EditingBehaviorController.class); + new PreferencesWindowController().show(mainWindow.getApplicationFrame(), + EditingBehaviorController.class); } /** - * Restores defaults for all dockable parts. May be expanded in the future to reset the entire GUI to its - * defaults. + * Restores defaults for all dockable parts. May be expanded in the future + * to reset the entire GUI to its defaults. */ public void viewRestoreGUIMenuItemActionPerformed() { - MainWindowUI.resetDesktopLayout(mainWindow); + mainWindow.resetDesktopLayout(); } public void optionsAccessConfigDirMenuItemActionPerformed() { @@ -1012,9 +1024,8 @@ public void helpContentsMenuItemActionPerformed() { try { Help.showHelp(); } catch (Exception ex) { - JOptionPane.showMessageDialog(mainWindow.getApplicationFrame(), ex.getLocalizedMessage(), OStrings.getString( - "ERROR_TITLE"), - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(mainWindow.getApplicationFrame(), ex.getLocalizedMessage(), + OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE); Log.log(ex); } } @@ -1023,7 +1034,8 @@ public void helpContentsMenuItemActionPerformed() { * Shows About dialog */ public void helpAboutMenuItemActionPerformed() { - new AboutDialog(mainWindow).setVisible(true); + JDialog aboutDialog = new AboutDialog(mainWindow.getApplicationFrame()); + aboutDialog.setVisible(true); } /** diff --git a/src/org/omegat/gui/main/ProjectUICommands.java b/src/org/omegat/gui/main/ProjectUICommands.java index 2b2215f443..30db829c07 100644 --- a/src/org/omegat/gui/main/ProjectUICommands.java +++ b/src/org/omegat/gui/main/ProjectUICommands.java @@ -48,17 +48,21 @@ import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; +import javax.swing.text.JTextComponent; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.builder.EqualsBuilder; + import org.omegat.CLIParameters; import org.omegat.convert.ConvertProject; import org.omegat.core.Core; import org.omegat.core.CoreEvents; import org.omegat.core.KnownException; +import org.omegat.core.data.DataUtils; import org.omegat.core.data.ProjectFactory; import org.omegat.core.data.ProjectProperties; import org.omegat.core.events.IProjectEventListener; +import org.omegat.core.matching.NearString; import org.omegat.core.segmentation.SRX; import org.omegat.core.segmentation.Segmenter; import org.omegat.core.team2.IRemoteRepository2; @@ -69,6 +73,7 @@ import org.omegat.gui.dialogs.NewProjectFileChooser; import org.omegat.gui.dialogs.NewTeamProjectController; import org.omegat.gui.dialogs.ProjectPropertiesDialog; +import org.omegat.gui.matches.IMatcher; import org.omegat.util.FileUtil; import org.omegat.util.FileUtil.ICollisionCallback; import org.omegat.util.HttpConnectionUtils; @@ -1352,4 +1357,74 @@ private static void processSwingWorkerException(Exception ex, String errorCode) Core.getMainWindow().displayErrorRB(ex, errorCode); } } + + /* Edit UI command helpers. + */ + + /** insert current fuzzy match or selection at cursor position */ + public static void doInsertTrans() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + + String text = getSelectedTextInMatcher(); + boolean fromMT = false; + if (StringUtil.isEmpty(text)) { + NearString near = Core.getMatcher().getActiveMatch(); + if (near != null) { + text = near.translation; + if (Preferences.isPreference(Preferences.CONVERT_NUMBERS)) { + text = Core.getMatcher().substituteNumbers( + Core.getEditor().getCurrentEntry().getSrcText(), near.source, near.translation); + } + + if (DataUtils.isFromMTMemory(near)) { + fromMT = true; + } + } + } + if (!StringUtil.isEmpty(text)) { + if (fromMT) { + Core.getEditor().insertTextAndMark(text); + } else { + Core.getEditor().insertText(text); + } + Core.getEditor().requestFocus(); + } + } + + /** replace entire edit area with active fuzzy match or selection */ + public static void doRecycleTrans() { + if (!Core.getProject().isProjectLoaded()) { + return; + } + + String selection = getSelectedTextInMatcher(); + if (!StringUtil.isEmpty(selection)) { + Core.getEditor().replaceEditText(selection); + Core.getEditor().requestFocus(); + return; + } + + NearString near = Core.getMatcher().getActiveMatch(); + if (near != null) { + String translation = near.translation; + if (Preferences.isPreference(Preferences.CONVERT_NUMBERS)) { + translation = Core.getMatcher().substituteNumbers( + Core.getEditor().getCurrentEntry().getSrcText(), near.source, near.translation); + } + if (DataUtils.isFromMTMemory(near)) { + Core.getEditor().replaceEditTextAndMark(translation, "TM:[tm/mt]"); + } else { + Core.getEditor().replaceEditText(translation, "TM:[generic]"); + } + Core.getEditor().requestFocus(); + } + } + + private static String getSelectedTextInMatcher() { + IMatcher matcher = Core.getMatcher(); + return matcher instanceof JTextComponent ? ((JTextComponent) matcher).getSelectedText() : null; + } + } diff --git a/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java b/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java index 15132254b6..5077eec58d 100644 --- a/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java +++ b/test-integration/src/org/omegat/core/data/TestTeamIntegrationChild.java @@ -46,6 +46,7 @@ import javax.swing.JFrame; import javax.swing.JMenu; +import javax.swing.JMenuItem; import org.madlonkay.supertmxmerge.StmProperties; import org.madlonkay.supertmxmerge.SuperTmxMerge; @@ -72,6 +73,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; @@ -655,6 +657,11 @@ public JMenu getMenu(MenuKey marker) { return null; } + @Override + public JMenuItem getMenuItemForNames(final String menuName, final String itemName) { + return null; + } + public void invokeAction(String action, int modifiers) { } }; @@ -668,6 +675,24 @@ public DockingDesktop getDesktop() { return null; } + @Override + public void resetDesktopLayout() { + } + + @Override + public void addSearchWindow(final SearchWindowController newSearchWindow) { + + } + + @Override + public List getSearchWindows() { + return null; + } + + @Override + public void saveScreenLayout() { + } + 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..34d53c9471 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; @@ -196,6 +197,11 @@ public JMenu getMenu(final MenuExtender.MenuKey marker) { } } + @Override + public JMenuItem getMenuItemForNames(final String menuName, final String itemName) { + return null; + } + private JMenu getGotoMenu() { if (gotoMenu.getItemCount() == 0) { gotoMenu.add(new JMenuItem("gotoNextUntranslatedMenuItem")); @@ -274,6 +280,25 @@ public DockingDesktop getDesktop() { return null; } + @Override + public void resetDesktopLayout() { + } + + @Override + public void addSearchWindow(final SearchWindowController newSearchWindow) { + + } + + @Override + public List getSearchWindows() { + return null; + } + + @Override + public void saveScreenLayout() { + + } + 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..ce077b1b76 100644 --- a/test/src/org/omegat/gui/main/MainWindowMenuTest.java +++ b/test/src/org/omegat/gui/main/MainWindowMenuTest.java @@ -70,6 +70,19 @@ public void testMenuActions() throws Exception { Map existsMethods = new HashMap(); + for (Method m : BaseMainWindowMenuHandler.class.getDeclaredMethods()) { + if (Modifier.isPublic(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())) { + Class[] params = m.getParameterTypes(); + if (params.length == 0) { + existsMethods.put(m.getName(), m); + } + // Include menu items that take a modifier key. + if (params.length == 1 && params[0] == Integer.TYPE) { + existsMethods.put(m.getName(), m); + } + } + } + for (Method m : MainWindowMenuHandler.class.getDeclaredMethods()) { if (Modifier.isPublic(m.getModifiers()) && !Modifier.isStatic(m.getModifiers())) { Class[] params = m.getParameterTypes();