hg auth dialog: don't show "remember password" checkbox if remembering is disabled...
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Sun, 24 Apr 2011 11:27:35 +0000 (15:27 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Sun, 24 Apr 2011 12:13:04 +0000 (16:13 +0400)
plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgUsernamePasswordDialog.java

index f80249d7ff9c72a152909e6029948db52526f761..7b50dd9f335003f84a289ee96a34614793ed2487 100644 (file)
@@ -12,6 +12,9 @@
 // limitations under the License.
 package org.zmlx.hg4idea.ui;
 
 // limitations under the License.
 package org.zmlx.hg4idea.ui;
 
+import com.intellij.ide.passwordSafe.PasswordSafe;
+import com.intellij.ide.passwordSafe.config.PasswordSafeSettings;
+import com.intellij.ide.passwordSafe.impl.PasswordSafeImpl;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.util.net.AuthenticationPanel;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.util.net.AuthenticationPanel;
@@ -26,8 +29,16 @@ public class HgUsernamePasswordDialog extends DialogWrapper {
   public HgUsernamePasswordDialog(Project project, String url, String login, String password) {
     super(project, false);
     setTitle(HgVcsMessages.message("hg4idea.dialog.login.password.required"));
   public HgUsernamePasswordDialog(Project project, String url, String login, String password) {
     super(project, false);
     setTitle(HgVcsMessages.message("hg4idea.dialog.login.password.required"));
+
+    // if password is prefilled, it is expected to continue remembering it.
+    Boolean rememberPassword = !StringUtils.isBlank(password);
+    final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance();
+    // if password saving is disabled, don't show the checkbox.
+    if (passwordSafe.getSettings().getProviderType().equals(PasswordSafeSettings.ProviderType.DO_NOT_STORE)) {
+      rememberPassword = null;
+    }
     authPanel = new AuthenticationPanel(HgVcsMessages.message("hg4idea.dialog.login.description", url), login, password,
     authPanel = new AuthenticationPanel(HgVcsMessages.message("hg4idea.dialog.login.description", url), login, password,
-                                        !StringUtils.isBlank(password));
+                                        rememberPassword);
     init();
   }
 
     init();
   }