Skip to content

Commit

Permalink
refactor: Add BaseMainWindowMenuHandler abstract class
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Mar 9, 2024
1 parent 9d72121 commit 210b26d
Show file tree
Hide file tree
Showing 9 changed files with 445 additions and 194 deletions.
180 changes: 136 additions & 44 deletions src/org/omegat/gui/main/BaseMainWindowMenu.java

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions src/org/omegat/gui/main/BaseMainWindowMenuHandler.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
**************************************************************************/
package org.omegat.gui.main;

/**
* @author Hiroshi Miura
*/
public abstract class BaseMainWindowMenuHandler {

/**
* Common base class for menu handler.
* <p>
* 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() {
}

}
3 changes: 3 additions & 0 deletions src/org/omegat/gui/main/IMainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package org.omegat.gui.main;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import org.omegat.util.gui.MenuExtender;

Expand Down Expand Up @@ -55,5 +56,7 @@ public interface IMainMenu {

JMenu getMenu(MenuExtender.MenuKey marker);

JMenuItem getMenuItemForNames(String menuName, String itemName);

void invokeAction(String action, int modifiers);
}
11 changes: 11 additions & 0 deletions src/org/omegat/gui/main/IMainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

void resetDesktopLayout();

void addSearchWindow(SearchWindowController newSearchWindow);

List<SearchWindowController> getSearchWindows();

void saveScreenLayout();
}
85 changes: 13 additions & 72 deletions src/org/omegat/gui/main/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -367,7 +297,7 @@ private void closeSearchWindows() {
}
}

protected List<SearchWindowController> getSearchWindows() {
public List<SearchWindowController> getSearchWindows() {
return Collections.unmodifiableList(searches);
}

Expand Down Expand Up @@ -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);
}
}
Loading

0 comments on commit 210b26d

Please sign in to comment.