Skip to content

Commit

Permalink
reafactor: use StaticUIUtils#isGUI for env detections
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Dec 16, 2024
1 parent 903af81 commit 4628ca7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
15 changes: 7 additions & 8 deletions src/org/omegat/core/team2/impl/GITCredentialsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.eclipse.jgit.errors.UnsupportedCredentialItem;
Expand All @@ -49,7 +50,6 @@
import org.omegat.core.team2.gui.PassphraseDialog;
import org.omegat.core.team2.gui.UserPassDialog;
import org.omegat.core.team2.impl.TeamUtils.Credentials;
import org.omegat.gui.main.IMainWindow;
import org.omegat.util.Log;
import org.omegat.util.OStrings;
import org.omegat.util.gui.StaticUIUtils;
Expand Down Expand Up @@ -281,8 +281,7 @@ public boolean supports(CredentialItem... items) {
}

private void askYesNoGUI(CredentialItem item, String promptText, URIish uri, String promptedFingerprint) {
IMainWindow mw = Core.getMainWindow();
int choice = mw.showConfirmDialog(promptText, null, JOptionPane.YES_NO_OPTION,
int choice = Core.getMainWindow().showConfirmDialog(promptText, null, JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (choice == JOptionPane.YES_OPTION) {
((CredentialItem.YesNoType) item).setValue(true);
Expand Down Expand Up @@ -325,10 +324,10 @@ private void askYesNo(CredentialItem item, String promptText, URIish uri, String
*/
private Credentials askCredentialsGUI(URIish uri, Credentials credentials, boolean passwordOnly,
String msg) {
IMainWindow mw = Core.getMainWindow();
JFrame parent = Core.getMainWindow().getApplicationFrame();
if (passwordOnly) {
PassphraseDialog passphraseDialog = new PassphraseDialog(mw.getApplicationFrame());
passphraseDialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
PassphraseDialog passphraseDialog = new PassphraseDialog(parent);
passphraseDialog.setLocationRelativeTo(parent);
if (uri.getScheme() == null) {
// asked passphrase
passphraseDialog.setTitleDesc(OStrings.getString(
Expand All @@ -347,8 +346,8 @@ private Credentials askCredentialsGUI(URIish uri, Credentials credentials, boole
return credentials;
}
} else {
UserPassDialog userPassDialog = new UserPassDialog(mw.getApplicationFrame());
userPassDialog.setLocationRelativeTo(Core.getMainWindow().getApplicationFrame());
UserPassDialog userPassDialog = new UserPassDialog(parent);
userPassDialog.setLocationRelativeTo(parent);
userPassDialog.setDescription(OStrings.getString(
credentials.username == null ? "TEAM_USERPASS_FIRST" : "TEAM_USERPASS_WRONG",
uri.getHumanishName()));
Expand Down
14 changes: 7 additions & 7 deletions src/org/omegat/core/team2/impl/SVNAuthenticationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
import org.omegat.core.team2.ProjectTeamSettings;
import org.omegat.core.team2.gui.UserPassDialog;
import org.omegat.core.team2.impl.TeamUtils.Credentials;
import org.omegat.gui.main.ConsoleWindow;
import org.omegat.util.Log;
import org.omegat.util.OStrings;
import org.omegat.util.gui.StaticUIUtils;

import gen.core.project.RepositoryDefinition;

Expand Down Expand Up @@ -194,11 +194,11 @@ public SVNAuthentication getFirstAuthentication(String kind, String realm, SVNUR
return getAuthenticatorInstance(kind, url, credentials);
}

if (Core.getMainWindow() == null || Core.getMainWindow() instanceof ConsoleWindow) {
if (StaticUIUtils.isGUI()) {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_FIRST", url.getPath()));
} else {
// run on headless.
return askCUI(kind, url, OStrings.getString("TEAM_USERPASS_FIRST", url.getPath()));
} else {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_FIRST", url.getPath()));
}
}

Expand All @@ -207,11 +207,11 @@ public SVNAuthentication getNextAuthentication(String kind, String realm, SVNURL
if (predefinedUser != null && predefinedPass != null) {
throw new KnownException("TEAM_PREDEFINED_CREDENTIALS_ERROR");
}
if (Core.getMainWindow() == null) {
if (StaticUIUtils.isGUI()) {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_WRONG", url.getPath()));
} else {
// run on headless.
return askCUI(kind, url, OStrings.getString("TEAM_USERPASS_WRONG", url.getPath()));
} else {
return ask(kind, url, OStrings.getString("TEAM_USERPASS_WRONG", url.getPath()));
}
}

Expand Down
7 changes: 3 additions & 4 deletions test/fixtures/org/omegat/core/TestCoreInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.omegat.core.threads.IAutoSave;
import org.omegat.gui.editor.IEditor;
import org.omegat.gui.glossary.IGlossaries;
import org.omegat.gui.main.ConsoleWindow;
import org.omegat.gui.main.IMainWindow;
import org.omegat.util.gui.StaticUIUtils;

/**
* Core initializer for unit tests.
Expand All @@ -52,10 +52,9 @@ public static void initAutoSave(IAutoSave autoSave) {
public static void initMainWindow(IMainWindow mainWindow) throws Exception {
Core.setMainWindow(mainWindow);

if (mainWindow instanceof ConsoleWindow) {
return;
if (StaticUIUtils.isGUI()) {
Core.initializeGUIimpl(mainWindow);
}
Core.initializeGUIimpl(mainWindow);
}

public static void initGlossary(IGlossaries glossaries) {
Expand Down

0 comments on commit 4628ca7

Please sign in to comment.