Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: call MenuHandlers without reflection #983

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
65a7db0
feat: MenuHanlder actions with AbstractAction
miurahr Mar 12, 2024
db5820c
wip
miurahr May 25, 2024
5021ff7
refactor: AccessTools constructor
miurahr May 25, 2024
b067c1b
refactor: IMainMenu#invokeAction
miurahr May 25, 2024
89692d0
refactor: Log menu selection for debug
miurahr May 25, 2024
c9ca4b1
refactor: invokeAction to invoke Action object
miurahr May 25, 2024
c5b3b43
feat: menu actions (wip)
miurahr May 25, 2024
cb53607
feat: MainWindowMenu deprecate old menu creation methods
miurahr May 25, 2024
0f0b835
fix: logging component names
miurahr May 25, 2024
459d213
fix: define missing menu action
miurahr May 25, 2024
10bf490
style: apply spotless
miurahr May 25, 2024
9ead61b
style: suppress MainWindowMenuHandler file length warning
miurahr May 25, 2024
cd9aa4d
refactor: menu class constructor to be default
miurahr May 26, 2024
43ef472
fix: remove an unwanted change
miurahr May 26, 2024
1c61262
refactor: direct instantiate Action classes
miurahr May 28, 2024
0e0edca
style: default constructor
miurahr May 28, 2024
c9ab3c3
style: private default constructor
miurahr May 28, 2024
4f7b238
style: menu action logging in single line
miurahr May 28, 2024
e9d2ae0
fix: action command str equals field name for shortcut key assign
miurahr May 29, 2024
3bab572
feat: set shortcut key to Action object
miurahr May 29, 2024
d05b66b
fix: drop action listener in BaseMainWindowMenu
miurahr May 29, 2024
63decb6
fix: NPE and refactor
miurahr May 29, 2024
9e78061
fix: duplicated UI component initialization
miurahr May 29, 2024
a12a52c
refactor: import actions sub classes
miurahr May 29, 2024
f85d470
style: suppress star import of a hundred of actions
miurahr May 29, 2024
18b84d4
refactor: SearchWindowMenu uses Action in MainMenuHandler
miurahr May 31, 2024
58ea3fd
refactor: MainMenuHandler to move helpers to ProjectUICommands
miurahr May 31, 2024
13d60e7
refactor: GlossaryTextArea to use Actions classes
miurahr May 31, 2024
9110727
Revert "refactor: GlossaryTextArea to use Actions classes"
miurahr May 31, 2024
bdbfc60
revert change
miurahr May 31, 2024
4b10ca5
style: add serialVersionUID for actions
miurahr Jun 1, 2024
9c535fc
revert other text area changes
miurahr Jun 1, 2024
6ccb5f5
refactor: JButton constructor takes Action object
miurahr Jun 1, 2024
95f9427
fix: replace invokeAction with alternative
miurahr Jun 1, 2024
ffe1c3d
revert SearchWindowMenu chages
miurahr Jun 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

<!-- Permanently suppress errors/warnings -->

<!-- All menu actions are defined as inner-class in Handler class.
MainWindowMenu class imports a hundred of actions with star-import -->
<suppress files="MainWindowMenuHandler\.java" checks="FileLength"/>
<suppress files="MainWindowMenu\.java" checks="AvoidStarImport"/>

<!-- tests -->
<suppress files="TestCore\.java" checks="MethodLength"/>
<suppress checks="(MethodName|MemberName|OperatorWrap)" files=".*Test\.java"/>
Expand Down
34 changes: 11 additions & 23 deletions src/org/omegat/gui/accesstool/AccessTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.swing.Box;
Expand All @@ -44,18 +43,16 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.omegat.core.Core;
import org.omegat.core.CoreEvents;
import org.omegat.core.events.IProjectEventListener;
import org.omegat.gui.main.BaseMainWindowMenuHandler;
import org.omegat.gui.main.MainMenuIcons;
import org.omegat.gui.main.MainWindowMenuHandler.EditFindInProjectMenuItemAction;
import org.omegat.gui.main.MainWindowMenuHandler.OptionsPreferencesMenuItemAction;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.util.OConsts;
import org.omegat.util.OStrings;
import org.omegat.util.RecentProjects;
import org.omegat.util.gui.ResourcesUtil;

/**
* @author Hiroshi Miura
Expand All @@ -71,15 +68,13 @@ public class AccessTools extends JPanel {

private ProjectComboBoxModel projectComboBoxModel;
private SourceComboBoxModel sourceComboBoxModel;
private final BaseMainWindowMenuHandler mainWindowMenuHandler;

private URI selectedProject = null;

private static final int MAX_PATH_LENGTH_SHOWN = 25;
private static final float CHECKBOX_HEIGHT_RATIO = 1.8f;

public AccessTools(final BaseMainWindowMenuHandler mainWindowMenuHandler) {
this.mainWindowMenuHandler = mainWindowMenuHandler;
public AccessTools() {
initComponents();
}

Expand Down Expand Up @@ -122,26 +117,19 @@ public void initComponents() {
sourceFilesCB.setMaximumSize(new Dimension(cbWidth, cbHeight));
add(sourceFilesCB);

searchButton = new JButton("",
Objects.requireNonNullElseGet(UIManager.getIcon("OmegaT.newUI.search.icon"),
() -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.search.png"))));
// These buttons show only icon
searchButton = new JButton(new EditFindInProjectMenuItemAction());
searchButton.setText("");
searchButton.setBorderPainted(false);
settingsButton = new JButton("", Objects.requireNonNullElseGet(
UIManager.getIcon("OmegaT.newUI.settings.icon"),
() -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.settings.png"))));
settingsButton = new JButton(new OptionsPreferencesMenuItemAction());
settingsButton.setText("");
settingsButton.setBorderPainted(false);

// -- right side
add(Box.createGlue());
add(searchButton);
add(settingsButton);

searchButton.addActionListener(actionEvent -> {
mainWindowMenuHandler.editFindInProjectMenuItemActionPerformed();
});
settingsButton.addActionListener(actionEvent -> {
mainWindowMenuHandler.optionsPreferencesMenuItemActionPerformed();
});
recentProjectCB.addActionListener(actionEvent -> {
// when select a project from the list, we open it.
final Object item = recentProjectCB.getSelectedItem();
Expand All @@ -153,13 +141,13 @@ public void initComponents() {
if (projectUri.getScheme().equals("omegat")) {
switch (projectUri.getSchemeSpecificPart()) {
case "new":
mainWindowMenuHandler.projectNewMenuItemActionPerformed();
ProjectUICommands.projectCreate();
break;
case "open":
mainWindowMenuHandler.projectOpenMenuItemActionPerformed();
ProjectUICommands.projectOpen(null);
break;
case "team":
mainWindowMenuHandler.projectTeamNewMenuItemActionPerformed();
ProjectUICommands.projectTeamCreate();
break;
default:
break;
Expand Down
5 changes: 3 additions & 2 deletions src/org/omegat/gui/glossary/GlossaryTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.omegat.gui.editor.EditorUtils;
import org.omegat.gui.main.DockableScrollPane;
import org.omegat.gui.main.IMainWindow;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.gui.shortcuts.PropertiesShortcuts;
import org.omegat.util.HttpConnectionUtils;
import org.omegat.util.Log;
Expand Down Expand Up @@ -414,8 +415,8 @@ public void populatePaneMenu(JPopupMenu menu) {
openFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Core.getMainWindow().getMainMenu().invokeAction("projectAccessWritableGlossaryMenuItem",
e.getModifiers());
int modifier = e.getModifiers();
ProjectUICommands.openWritableGlossaryFile((modifier & ActionEvent.ALT_MASK) != 0);
}
});
openFile.setEnabled(false);
Expand Down
Loading
Loading