From 97c80e446f49cfb3a8439f125030ee8c3d0a1661 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 28 Mar 2012 16:57:33 +0400 Subject: [PATCH] Hide GitHub credentials from the settings Ground: * It fixes AE happening because of the necessary fix for IDEA-78716. * It makes master password not appear during navigation through the settings. Remove host, login and password fields. Rename "Test" button to "Change credentials", fix layout. Pressing the button invokes the standard GithubLoginDialog with credentials filled from the GitHubSettings (possibly with master password prompt). Connection failure notification is not needed, since the dialog doesn't allow to OK on failure. Connection success notification is shown, fix the parent of the Message. --- .../github/ui/GitHubSettingsConfigurable.java | 19 +---- .../github/ui/GithubSettingsPanel.form | 69 ++----------------- .../github/ui/GithubSettingsPanel.java | 43 +++--------- 3 files changed, 18 insertions(+), 113 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java index b5dfe06f98a9..3ec134a45def 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GitHubSettingsConfigurable.java @@ -2,8 +2,6 @@ package org.jetbrains.plugins.github.ui; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; -import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.IconLoader; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.github.GithubSettings; import org.jetbrains.plugins.github.GithubUtil; @@ -29,38 +27,27 @@ public class GitHubSettingsConfigurable implements SearchableConfigurable { return GithubUtil.GITHUB_ICON; } + @NotNull public String getHelpTopic() { return "settings.github"; } public JComponent createComponent() { if (mySettingsPane == null) { - mySettingsPane = new GithubSettingsPanel(); + mySettingsPane = new GithubSettingsPanel(mySettings); } reset(); return mySettingsPane.getPanel(); } public boolean isModified() { - return mySettingsPane != null && (!Comparing.equal(mySettings.getLogin(), mySettingsPane.getLogin()) || - !Comparing.strEqual(mySettings.getPassword(), mySettingsPane.getPassword()) || - !Comparing.equal(mySettings.getHost(), mySettingsPane.getHost())); + return false; } public void apply() throws ConfigurationException { - if (mySettingsPane != null) { - mySettings.setLogin(mySettingsPane.getLogin()); - mySettings.setPassword(mySettingsPane.getPassword()); - mySettings.setHost(mySettingsPane.getHost()); - } } public void reset() { - if (mySettingsPane != null) { - mySettingsPane.setLogin(mySettings.getLogin()); - mySettingsPane.setPassword(mySettings.getPassword()); - mySettingsPane.setHost(mySettings.getHost()); - } } public void disposeUIResources() { diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form index f828dabfa194..043dc84c7ab0 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.form @@ -1,6 +1,6 @@
- + @@ -8,36 +8,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -45,55 +18,25 @@ + - - - - - - - - - - - - - - - - - - - - - + - + - + - - - - - - - - - - - diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java index 29e352692067..267941384273 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubSettingsPanel.java @@ -16,11 +16,11 @@ package org.jetbrains.plugins.github.ui; import com.intellij.ide.BrowserUtil; +import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.ui.Messages; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.HyperlinkAdapter; -import org.jetbrains.plugins.github.GithubUtil; +import org.jetbrains.plugins.github.GithubSettings; import javax.swing.*; import javax.swing.event.HyperlinkEvent; @@ -33,14 +33,11 @@ import java.awt.event.ActionListener; * @date 10/20/10 */ public class GithubSettingsPanel { - private JTextField myLoginTextField; - private JPasswordField myPasswordField; private JTextPane mySignupTextField; private JPanel myPane; private JButton myTestButton; - private JTextField myHostTextField; - public GithubSettingsPanel() { + public GithubSettingsPanel(final GithubSettings settings) { mySignupTextField.addHyperlinkListener(new HyperlinkAdapter() { @Override protected void hyperlinkActivated(final HyperlinkEvent e) { @@ -54,10 +51,12 @@ public class GithubSettingsPanel { myTestButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (GithubUtil.checkCredentials(ProjectManager.getInstance().getDefaultProject(), getHost(), getLogin(), getPassword())){ - Messages.showInfoMessage("Connection successful", "Success"); - } else { - Messages.showErrorDialog("Cannot login to the " + getHost() + " using given credentials", "Failure"); + Project project = ProjectManager.getInstance().getDefaultProject(); + final GithubLoginDialog dialog = new GithubLoginDialog(project); + dialog.show(); + if (dialog.isOK()){ + // the dialog won't let close after pressing OK if the connection is not successful + Messages.showInfoMessage(myPane, "Connection successful", "Success"); } } }); @@ -67,29 +66,5 @@ public class GithubSettingsPanel { return myPane; } - public void setLogin(final String login) { - myLoginTextField.setText(login); - } - - public void setPassword(final String password) { - // Show password as blank if password is empty - myPasswordField.setText(StringUtil.isEmpty(password) ? null : password); - } - - public String getLogin() { - return myLoginTextField.getText().trim(); - } - - public String getPassword() { - return String.valueOf(myPasswordField.getPassword()); - } - - public void setHost(final String host) { - myHostTextField.setText(host); - } - - public String getHost() { - return myHostTextField.getText().trim(); - } }