diff --git a/platform/testRunner/src/com/intellij/execution/testframework/ToolbarPanel.java b/platform/testRunner/src/com/intellij/execution/testframework/ToolbarPanel.java index 3cd96220348d..d7456e3495aa 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/ToolbarPanel.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/ToolbarPanel.java @@ -22,10 +22,8 @@ package com.intellij.execution.testframework; import com.intellij.execution.ExecutionBundle; import com.intellij.execution.runners.ExecutionEnvironment; -import com.intellij.execution.testframework.actions.ScrollToTestSourceAction; -import com.intellij.execution.testframework.actions.ShowStatisticsAction; -import com.intellij.execution.testframework.actions.TestFrameworkActions; -import com.intellij.execution.testframework.actions.TestTreeExpander; +import com.intellij.execution.testframework.actions.*; +import com.intellij.execution.testframework.autotest.AdjustAutotestDelayActionGroup; import com.intellij.execution.testframework.export.ExportTestResultsAction; import com.intellij.execution.testframework.ui.AbstractTestTreeBuilder; import com.intellij.icons.AllIcons; @@ -104,6 +102,7 @@ public class ToolbarPanel extends JPanel implements OccurenceNavigator, Disposab properties, TestConsoleProperties.OPEN_FAILURE_LINE)).setAsSecondary(true); actionGroup.addAction(new ShowStatisticsAction(properties)).setAsSecondary(true); + actionGroup.addAction(new AdjustAutotestDelayActionGroup(environment)).setAsSecondary(true); for (ToggleModelActionProvider actionProvider : Extensions.getExtensions(ToggleModelActionProvider.EP_NAME)) { final ToggleModelAction toggleModelAction = actionProvider.createToggleModelAction(properties); diff --git a/platform/testRunner/src/com/intellij/execution/testframework/autotest/AdjustAutotestDelayActionGroup.java b/platform/testRunner/src/com/intellij/execution/testframework/autotest/AdjustAutotestDelayActionGroup.java new file mode 100644 index 000000000000..cb5b437e7865 --- /dev/null +++ b/platform/testRunner/src/com/intellij/execution/testframework/autotest/AdjustAutotestDelayActionGroup.java @@ -0,0 +1,71 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.testframework.autotest; + +import com.intellij.execution.runners.ExecutionEnvironment; +import com.intellij.openapi.actionSystem.ActionGroup; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.ToggleAction; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Dennis.Ushakov + */ +public class AdjustAutotestDelayActionGroup extends ActionGroup { + public static final int MAX_DELAY = 10; + private final ExecutionEnvironment myEnvironment; + + public AdjustAutotestDelayActionGroup(ExecutionEnvironment environment) { + super("Set AutoTest Delay", true); + myEnvironment = environment; + } + + @Override + public void update(AnActionEvent e) { + e.getPresentation().setVisible(Boolean.TRUE == myEnvironment.getUserData(AutoTestManager.AUTOTESTABLE)); + } + + @NotNull + @Override + public AnAction[] getChildren(@Nullable AnActionEvent e) { + final AnAction[] actions = new AnAction[MAX_DELAY]; + for (int i = 0; i < MAX_DELAY; i++) { + actions[i] = new SetAutoTestDelayAction(i + 1); + } + return actions; + } + + private static class SetAutoTestDelayAction extends ToggleAction { + private final int myDelay; + + public SetAutoTestDelayAction(int delay) { + super(delay + "s"); + myDelay = delay * 1000; + } + + @Override + public boolean isSelected(AnActionEvent e) { + return AutoTestManager.getInstance(e.getProject()).getDelay() == myDelay; + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + AutoTestManager.getInstance(e.getProject()).setDelay(myDelay); + } + } +} diff --git a/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java b/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java index a0de72b95043..fe885ba53321 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/autotest/AutoTestManager.java @@ -4,10 +4,12 @@ import com.intellij.execution.DelayedDocumentWatcher; import com.intellij.execution.process.ProcessHandler; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.execution.ui.RunContentManagerImpl; +import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.content.Content; import com.intellij.util.Alarm; @@ -20,9 +22,12 @@ import java.util.Collection; * @author yole */ public class AutoTestManager { - private static final int AUTOTEST_DELAY = 10000; + static final Key AUTOTESTABLE = Key.create("auto.test.manager.supported"); - private final DelayedDocumentWatcher myDocumentWatcher; + private final Project myProject; + + private int myDelay; + private DelayedDocumentWatcher myDocumentWatcher; private final Collection myEnabledDescriptors = new WeakList(); public static AutoTestManager getInstance(Project project) { @@ -30,7 +35,13 @@ public class AutoTestManager { } public AutoTestManager(Project project) { - myDocumentWatcher = new DelayedDocumentWatcher(project, new Alarm(Alarm.ThreadToUse.SWING_THREAD, project), AUTOTEST_DELAY, new Consumer() { + myProject = project; + myDocumentWatcher = createWatcher(); + myDelay = PropertiesComponent.getInstance(myProject).getOrInitInt("auto.test.manager.delay", 3000); + } + + private DelayedDocumentWatcher createWatcher() { + return new DelayedDocumentWatcher(myProject, new Alarm(Alarm.ThreadToUse.SWING_THREAD, myProject), myDelay, new Consumer() { @Override public void consume(VirtualFile[] files) { for (Content content : myEnabledDescriptors) { @@ -81,4 +92,17 @@ public class AutoTestManager { } restarter.run(); } + + int getDelay() { + return myDelay; + } + + void setDelay(int delay) { + myDelay = delay; + myDocumentWatcher.deactivate(); + myDocumentWatcher = createWatcher(); + if (!myEnabledDescriptors.isEmpty()) { + myDocumentWatcher.activate(); + } + } } \ No newline at end of file diff --git a/platform/testRunner/src/com/intellij/execution/testframework/autotest/ToggleAutoTestAction.java b/platform/testRunner/src/com/intellij/execution/testframework/autotest/ToggleAutoTestAction.java index d9ba85745999..893ddb320aab 100644 --- a/platform/testRunner/src/com/intellij/execution/testframework/autotest/ToggleAutoTestAction.java +++ b/platform/testRunner/src/com/intellij/execution/testframework/autotest/ToggleAutoTestAction.java @@ -1,11 +1,11 @@ package com.intellij.execution.testframework.autotest; +import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.execution.ui.RunContentManager; import com.intellij.icons.AllIcons; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.project.Project; @@ -13,9 +13,10 @@ import com.intellij.openapi.project.Project; * @author yole */ public class ToggleAutoTestAction extends ToggleAction { - public ToggleAutoTestAction() { + public ToggleAutoTestAction(ExecutionEnvironment environment) { super("Toggle auto-test", "Toggle automatic rerun of tests on code changes", AllIcons.Actions.SwapPanels); + environment.putUserData(AutoTestManager.AUTOTESTABLE, true); } @Override