Skip to content

Commit

Permalink
feat: MenuHanlder actions with AbstractAction
Browse files Browse the repository at this point in the history
- refactor exit actions menus

Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed May 25, 2024
1 parent 358a3be commit 65a7db0
Show file tree
Hide file tree
Showing 18 changed files with 1,314 additions and 1,043 deletions.
37 changes: 14 additions & 23 deletions src/org/omegat/gui/accesstool/AccessTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,25 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Map;
import java.util.stream.Collectors;

import javax.swing.Action;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
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.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,15 @@ 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;
private final Map<Object, Action> actions;

public AccessTools(final BaseMainWindowMenuHandler mainWindowMenuHandler) {
this.mainWindowMenuHandler = mainWindowMenuHandler;
public AccessTools(Map<Object, Action> actions) {
this.actions = actions;
initComponents();
}

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

searchButton = new JButton("",
Objects.requireNonNullElseGet(UIManager.getIcon("OmegaT.newUI.search.icon"),
() -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.search.png"))));
searchButton = new JButton();
searchButton.setAction(actions.get("EditFindInProjectMenuItem"));
searchButton.setText("");
searchButton.setBorderPainted(false);
settingsButton = new JButton("", Objects.requireNonNullElseGet(
UIManager.getIcon("OmegaT.newUI.settings.icon"),
() -> MainMenuIcons.newImageIcon(ResourcesUtil.getBundledImage("newUI.settings.png"))));
settingsButton = new JButton();
settingsButton.setAction(actions.get("OptionsPreferencesMenuItem"));
settingsButton.setText("");
settingsButton.setBorderPainted(false);

// -- right side
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 +144,13 @@ public void initComponents() {
if (projectUri.getScheme().equals("omegat")) {
switch (projectUri.getSchemeSpecificPart()) {
case "new":
mainWindowMenuHandler.projectNewMenuItemActionPerformed();
ProjectUICommands.projectCreate();
break;
case "open":
mainWindowMenuHandler.projectOpenMenuItemActionPerformed();
ProjectUICommands.projectOpen(null);
break;
case "team":
mainWindowMenuHandler.projectTeamNewMenuItemActionPerformed();
ProjectUICommands.projectTeamCreate();
break;
default:
break;
Expand Down
9 changes: 2 additions & 7 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.MainWindowMenuHandler;
import org.omegat.gui.shortcuts.PropertiesShortcuts;
import org.omegat.util.HttpConnectionUtils;
import org.omegat.util.Log;
Expand Down Expand Up @@ -411,13 +412,7 @@ public void populatePaneMenu(JPopupMenu menu) {
populateContextMenu(menu);
menu.addSeparator();
final JMenuItem openFile = new JMenuItem(OStrings.getString("GUI_GLOSSARYWINDOW_SETTINGS_OPEN_FILE"));
openFile.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Core.getMainWindow().getMainMenu().invokeAction("projectAccessWritableGlossaryMenuItem",
e.getModifiers());
}
});
openFile.setAction(MainWindowMenuHandler.getAction("ProjectAccessWritableGlossaryMenuItem"));
openFile.setEnabled(false);
if (Core.getProject().isProjectLoaded()) {
String glossaryPath = Core.getProject().getProjectProperties().getWriteableGlossary();
Expand Down
Loading

0 comments on commit 65a7db0

Please sign in to comment.