ExecutableValidator (Git & Hg): lazy getConfigurable(), because it's recreated in HgVcs.getConfigurable() on each access. [Reviewed by Maxim Shafirov]

This commit is contained in:
Kirill Likhodedov
2010-12-07 18:45:39 +03:00
parent 4dc28abb5b
commit 03ab4727c8
3 changed files with 29 additions and 8 deletions
@@ -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. <a href=''>Fix</a>";
@@ -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();
}
@@ -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 {
@@ -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());