From 03ab4727c88f92b8251c2a71e8959b3d3beb23e6 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Tue, 7 Dec 2010 18:43:09 +0300 Subject: [PATCH] ExecutableValidator (Git & Hg): lazy getConfigurable(), because it's recreated in HgVcs.getConfigurable() on each access. [Reviewed by Maxim Shafirov] --- .../execution/util/ExecutableValidator.java | 21 +++++++++++++------ .../config/GitExecutableValidator.java | 8 ++++++- .../zmlx/hg4idea/HgExecutableValidator.java | 8 ++++++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecutableValidator.java b/platform/platform-api/src/com/intellij/execution/util/ExecutableValidator.java index b610531079d9..0bf4efa93977 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecutableValidator.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecutableValidator.java @@ -43,7 +43,6 @@ public abstract class ExecutableValidator { private Notification myNotification; protected final Project myProject; private final String myNotificationGroupId; - private Configurable myConfigurable; private String myNotificationErrorTitle = "Executable not valid"; private String myNotificationErrorDescription = "You haven't configured a valid executable. Fix"; @@ -53,10 +52,9 @@ public abstract class ExecutableValidator { private String myFileChooserTitle = "Executable"; private String myFileChooserDescription = "Specify the full path to the executable"; - public ExecutableValidator(Project project, String notificationGroupId, @Nullable Configurable settingsConfigurable) { + public ExecutableValidator(Project project, String notificationGroupId) { myProject = project; myNotificationGroupId = notificationGroupId; - myConfigurable = settingsConfigurable; } /** @@ -94,6 +92,16 @@ public abstract class ExecutableValidator { protected void saveCurrentExecutable(String executable) { } + /** + * Returns the configurable page for the vcs containing settings for executable. + * This configurable will be opened if user presses "Fix" on the notification about invalid executable. + * May return null - in this case the settings dialog won't be displayed. + */ + @Nullable + protected Configurable getConfigurable(Project project) { + return null; + } + /** * Returns true if the supplied executable is valid. * Default implementation: try to execute the given executable and test if output returned errors. @@ -160,7 +168,7 @@ public abstract class ExecutableValidator { myNotification.expire(); } myNotification = newNotification; - Notifications.Bus.notify(myNotification, myProject); + Notifications.Bus.notify(myNotification, myProject.isDefault() ? null : myProject); } }); } @@ -173,8 +181,9 @@ public abstract class ExecutableValidator { * Parameters are the same as in {@link com.intellij.notification.NotificationListener#hyperlinkUpdate(com.intellij.notification.Notification, javax.swing.event.HyperlinkEvent)} */ protected void notificationHyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { - if (myConfigurable != null) { - ShowSettingsUtil.getInstance().showSettingsDialog(myProject, myConfigurable); + Configurable configurable = getConfigurable(myProject); + if (configurable != null) { + ShowSettingsUtil.getInstance().showSettingsDialog(myProject, configurable); if (isExecutableValid(getCurrentExecutable())) { notification.expire(); } diff --git a/plugins/git4idea/src/git4idea/config/GitExecutableValidator.java b/plugins/git4idea/src/git4idea/config/GitExecutableValidator.java index ef89859b32d8..bd6c8ef4697c 100644 --- a/plugins/git4idea/src/git4idea/config/GitExecutableValidator.java +++ b/plugins/git4idea/src/git4idea/config/GitExecutableValidator.java @@ -19,6 +19,7 @@ import com.intellij.execution.configurations.GeneralCommandLine; import com.intellij.execution.process.CapturingProcessHandler; import com.intellij.execution.process.ProcessOutput; import com.intellij.execution.util.ExecutableValidator; +import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.CharsetToolkit; @@ -35,7 +36,7 @@ public class GitExecutableValidator extends ExecutableValidator { private GitVcs myVcs; public GitExecutableValidator(Project project) { - super(project, GitVcs.NOTIFICATION_GROUP_ID, GitVcs.getInstance(project).getConfigurable()); + super(project, GitVcs.NOTIFICATION_GROUP_ID); myVcs = GitVcs.getInstance(project); setMessagesAndTitles(GitBundle.message("git.executable.notification.title"), GitBundle.message("git.executable.notification.description"), @@ -51,6 +52,11 @@ public class GitExecutableValidator extends ExecutableValidator { return myVcs.getAppSettings().getPathToGit(); } + @Override + protected Configurable getConfigurable(Project project) { + return myVcs == null ? null : myVcs.getConfigurable(); + } + @Override public boolean isExecutableValid(String executable) { try { diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java index c9d5ee7c8f2b..c50b81e77488 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgExecutableValidator.java @@ -13,6 +13,7 @@ package org.zmlx.hg4idea; import com.intellij.execution.util.ExecutableValidator; +import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; import org.zmlx.hg4idea.command.HgVersionCommand; @@ -21,7 +22,7 @@ public class HgExecutableValidator extends ExecutableValidator { private final HgVcs myVcs; public HgExecutableValidator(Project project) { - super(project, HgVcs.NOTIFICATION_GROUP_ID, HgVcs.getInstance(project).getConfigurable()); + super(project, HgVcs.NOTIFICATION_GROUP_ID); myVcs = HgVcs.getInstance(project); setMessagesAndTitles(HgVcsMessages.message("hg4idea.executable.notification.title"), HgVcsMessages.message("hg4idea.executable.notification.description"), @@ -37,6 +38,11 @@ public class HgExecutableValidator extends ExecutableValidator { return myVcs.getHgExecutable(); } + @Override + protected Configurable getConfigurable(Project project) { + return myVcs == null ? null : myVcs.getConfigurable(); + } + @Override public boolean isExecutableValid(String executable) { return new HgVersionCommand().isValid(executable, myVcs.getGlobalSettings().isRunViaBash());