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 <[email protected]>
  • Loading branch information
miurahr committed May 3, 2024
1 parent 2669c85 commit e4248fe
Show file tree
Hide file tree
Showing 11 changed files with 1,322 additions and 403 deletions.
38 changes: 14 additions & 24 deletions src/org/omegat/gui/accesstool/AccessTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +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.MainMenuIcons;
import org.omegat.gui.main.MainWindow;
import org.omegat.gui.main.MainWindowMenuHandler;
import org.omegat.gui.main.ProjectUICommands;
import org.omegat.util.OConsts;
import org.omegat.util.OStrings;
import org.omegat.util.RecentProjects;
import org.omegat.util.gui.ResourcesUtil;

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

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

private URI selectedProject = null;

private static final int MAX_PATH_LENGTH_SHOWN = 25;
private static final float CHECKBOX_HEIGHT_RATIO = 1.8f;
private final Map<Object, Action> actions;

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

Expand Down Expand Up @@ -123,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 @@ -154,13 +144,13 @@ public void initComponents() {
if (projectUri.getScheme().equals("omegat")) {
switch (projectUri.getSchemeSpecificPart()) {
case "new":
mainWindowMenuHandler.projectNewMenuItemActionPerformed();
ProjectUICommands.projectCreate();
break;
case "open":
mainWindowMenuHandler.projectOpenMenuItemActionPerformed();
ProjectUICommands.projectOpen(null);
break;
case "team":
mainWindowMenuHandler.projectTeamNewMenuItemActionPerformed();
ProjectUICommands.projectTeamCreate();
break;
default:
break;
Expand Down
213 changes: 118 additions & 95 deletions src/org/omegat/gui/main/BaseMainWindowMenu.java

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/org/omegat/gui/main/ConsoleWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import javax.swing.JFrame;

import org.omegat.gui.search.SearchWindowController;
import org.omegat.util.OStrings;
import org.omegat.util.RuntimePreferences;
import org.omegat.util.StringUtil;
Expand Down Expand Up @@ -142,6 +143,18 @@ public DockingDesktop getDesktop() {
return null;
}

@Override
public void doRecycleTrans() {
}

@Override
public void doInsertTrans() {
}

@Override
public void addSearchWindow(final SearchWindowController search) {
}

public Cursor getCursor() {
return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
}
Expand Down
8 changes: 8 additions & 0 deletions src/org/omegat/gui/main/IMainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import javax.swing.JFrame;

import org.omegat.gui.search.SearchWindowController;

import com.vlsolutions.swing.docking.Dockable;
import com.vlsolutions.swing.docking.DockingDesktop;

Expand Down Expand Up @@ -204,4 +206,10 @@ public interface IMainWindow {
* Retrieve main docking desktop.
*/
DockingDesktop getDesktop();

void doRecycleTrans();

void doInsertTrans();

void addSearchWindow(SearchWindowController search);
}
4 changes: 2 additions & 2 deletions src/org/omegat/gui/main/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void initMainMenu() {

applicationFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
mainWindowMenuHandler.projectExitMenuItemActionPerformed();
MainWindowMenuHandler.projectExitAction();
}

@Override
Expand Down Expand Up @@ -362,7 +362,7 @@ private String getSelectedTextInMatcher() {
return matcher instanceof JTextComponent ? ((JTextComponent) matcher).getSelectedText() : null;
}

protected void addSearchWindow(final SearchWindowController newSearchWindow) {
public void addSearchWindow(final SearchWindowController newSearchWindow) {
newSearchWindow.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
Expand Down
2 changes: 1 addition & 1 deletion src/org/omegat/gui/main/MainWindowBurgerMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ void createMenuBar() {
burgerMenu.add(helpMenu);
burgerMenu.add(burgerMenu);
mainMenu.add(burgerMenu);
mainMenu.add(new AccessTools(mainWindow, mainWindowMenuHandler));
mainMenu.add(new AccessTools(MainWindowMenuHandler.getActions()));
}
}
Loading

0 comments on commit e4248fe

Please sign in to comment.