mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-178427 Gradle Build Sync view: "Toggle view" switches to "Tree" on every run
This commit is contained in:
@@ -16,18 +16,14 @@
|
||||
package com.intellij.build;
|
||||
|
||||
import com.intellij.build.events.*;
|
||||
import com.intellij.execution.actions.StopAction;
|
||||
import com.intellij.execution.actions.StopProcessAction;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.FakeRerunAction;
|
||||
import com.intellij.execution.ui.*;
|
||||
import com.intellij.execution.ui.actions.CloseAction;
|
||||
import com.intellij.execution.ui.layout.impl.RunnerLayoutUiImpl;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.actions.PinActiveTabAction;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentContainer;
|
||||
import com.intellij.openapi.ui.ThreeComponentsSplitter;
|
||||
@@ -48,7 +44,6 @@ import com.intellij.util.ui.EdtInvocationManager;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -219,8 +214,9 @@ public abstract class AbstractViewManager implements BuildProgressListener, Disp
|
||||
if (componentContainer == null) {
|
||||
componentContainer = executionConsole = new BuildTextConsoleView(myProject);
|
||||
}
|
||||
final BuildView buildView = new BuildView(myProject, componentContainer, ((StartBuildEvent)event));
|
||||
buildView.enableView(!isConsoleEnabledByDefault());
|
||||
final BuildView buildView =
|
||||
new BuildView(myProject, componentContainer, ((StartBuildEvent)event),
|
||||
"build.toolwindow." + getViewName() + ".selection.state", isConsoleEnabledByDefault());
|
||||
if (processHandler != null) {
|
||||
if (executionConsole instanceof ConsoleView) {
|
||||
((ConsoleView)executionConsole).attachToProcess(processHandler);
|
||||
@@ -440,77 +436,4 @@ public abstract class AbstractViewManager implements BuildProgressListener, Disp
|
||||
return AllIcons.Process.State.GreenOK;
|
||||
}
|
||||
}
|
||||
|
||||
private static class BuildView extends CompositeView<BuildConsoleView, ComponentContainer> implements DataProvider {
|
||||
private final ComponentContainer myComponentContainer;
|
||||
private final StartBuildEvent myEvent;
|
||||
|
||||
public BuildView(Project project, ComponentContainer componentContainer, StartBuildEvent event) {
|
||||
super(new BuildTreeConsoleView(project), componentContainer);
|
||||
myComponentContainer = componentContainer;
|
||||
myEvent = event;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction[] createConsoleActions() {
|
||||
final DefaultActionGroup rerunActionGroup = new DefaultActionGroup();
|
||||
AnAction stopAction = null;
|
||||
if (myEvent.getProcessHandler() != null) {
|
||||
stopAction = new StopProcessAction("Stop", "Stop", myEvent.getProcessHandler());
|
||||
}
|
||||
final DefaultActionGroup consoleActionGroup = new DefaultActionGroup() {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setVisible(!BuildView.this.isPrimaryConsoleEnabled());
|
||||
}
|
||||
};
|
||||
if (myComponentContainer instanceof BuildConsoleView) {
|
||||
final AnAction[] consoleActions = ((BuildConsoleView)myComponentContainer).createConsoleActions();
|
||||
for (AnAction anAction : consoleActions) {
|
||||
if (anAction instanceof StopAction) {
|
||||
if (stopAction == null) {
|
||||
stopAction = anAction;
|
||||
}
|
||||
}
|
||||
else if (!(anAction instanceof FakeRerunAction ||
|
||||
anAction instanceof PinActiveTabAction ||
|
||||
anAction instanceof CloseAction)) {
|
||||
consoleActionGroup.add(anAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
final DefaultActionGroup actionGroup = new DefaultActionGroup();
|
||||
for (AnAction anAction : myEvent.getRestartActions()) {
|
||||
rerunActionGroup.add(anAction);
|
||||
}
|
||||
if (stopAction != null) {
|
||||
rerunActionGroup.add(stopAction);
|
||||
}
|
||||
actionGroup.add(rerunActionGroup);
|
||||
actionGroup.addSeparator();
|
||||
AnAction[] actions = super.createConsoleActions();
|
||||
actionGroup.addAll(actions);
|
||||
if (actions.length > 0) {
|
||||
actionGroup.addSeparator();
|
||||
}
|
||||
return new AnAction[]{actionGroup, consoleActionGroup};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
Object data = super.getData(dataId);
|
||||
if (data != null) return data;
|
||||
if (LangDataKeys.RUN_PROFILE.is(dataId)) {
|
||||
ExecutionEnvironment environment = myEvent.getExecutionEnvironment();
|
||||
return environment == null ? null : environment.getRunProfile();
|
||||
}
|
||||
if (LangDataKeys.EXECUTION_ENVIRONMENT.is(dataId)) {
|
||||
return myEvent.getExecutionEnvironment();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright 2000-2017 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.build;
|
||||
|
||||
import com.intellij.build.events.StartBuildEvent;
|
||||
import com.intellij.execution.actions.StopAction;
|
||||
import com.intellij.execution.actions.StopProcessAction;
|
||||
import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.FakeRerunAction;
|
||||
import com.intellij.execution.ui.actions.CloseAction;
|
||||
import com.intellij.ide.actions.PinActiveTabAction;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComponentContainer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
*/
|
||||
class BuildView extends CompositeView<BuildConsoleView, ComponentContainer> implements DataProvider {
|
||||
private final ComponentContainer myComponentContainer;
|
||||
private final StartBuildEvent myEvent;
|
||||
|
||||
public BuildView(Project project,
|
||||
ComponentContainer componentContainer,
|
||||
StartBuildEvent event,
|
||||
String selectionStateKey,
|
||||
boolean isConsoleEnabledByDefault) {
|
||||
super(new BuildTreeConsoleView(project), componentContainer, selectionStateKey, !isConsoleEnabledByDefault);
|
||||
myComponentContainer = componentContainer;
|
||||
myEvent = event;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction[] createConsoleActions() {
|
||||
final DefaultActionGroup rerunActionGroup = new DefaultActionGroup();
|
||||
AnAction stopAction = null;
|
||||
if (myEvent.getProcessHandler() != null) {
|
||||
stopAction = new StopProcessAction("Stop", "Stop", myEvent.getProcessHandler());
|
||||
}
|
||||
final DefaultActionGroup consoleActionGroup = new DefaultActionGroup() {
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
super.update(e);
|
||||
e.getPresentation().setVisible(!BuildView.this.isPrimaryConsoleEnabled());
|
||||
}
|
||||
};
|
||||
if (myComponentContainer instanceof BuildConsoleView) {
|
||||
final AnAction[] consoleActions = ((BuildConsoleView)myComponentContainer).createConsoleActions();
|
||||
for (AnAction anAction : consoleActions) {
|
||||
if (anAction instanceof StopAction) {
|
||||
if (stopAction == null) {
|
||||
stopAction = anAction;
|
||||
}
|
||||
}
|
||||
else if (!(anAction instanceof FakeRerunAction ||
|
||||
anAction instanceof PinActiveTabAction ||
|
||||
anAction instanceof CloseAction)) {
|
||||
consoleActionGroup.add(anAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
final DefaultActionGroup actionGroup = new DefaultActionGroup();
|
||||
for (AnAction anAction : myEvent.getRestartActions()) {
|
||||
rerunActionGroup.add(anAction);
|
||||
}
|
||||
if (stopAction != null) {
|
||||
rerunActionGroup.add(stopAction);
|
||||
}
|
||||
actionGroup.add(rerunActionGroup);
|
||||
actionGroup.addSeparator();
|
||||
AnAction[] actions = super.createConsoleActions();
|
||||
actionGroup.addAll(actions);
|
||||
if (actions.length > 0) {
|
||||
actionGroup.addSeparator();
|
||||
}
|
||||
return new AnAction[]{actionGroup, consoleActionGroup};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(String dataId) {
|
||||
Object data = super.getData(dataId);
|
||||
if (data != null) return data;
|
||||
if (LangDataKeys.RUN_PROFILE.is(dataId)) {
|
||||
ExecutionEnvironment environment = myEvent.getExecutionEnvironment();
|
||||
return environment == null ? null : environment.getRunProfile();
|
||||
}
|
||||
if (LangDataKeys.EXECUTION_ENVIRONMENT.is(dataId)) {
|
||||
return myEvent.getExecutionEnvironment();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.intellij.build;
|
||||
import com.intellij.execution.console.ConsoleHistoryController;
|
||||
import com.intellij.execution.console.LanguageConsoleView;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataProvider;
|
||||
@@ -50,14 +51,17 @@ public class CompositeView<S extends ComponentContainer, T extends ComponentCont
|
||||
private final S myPrimaryView;
|
||||
@NotNull
|
||||
private final T mySecondaryView;
|
||||
private final String mySelectionStateKey;
|
||||
private final boolean myPrimaryViewEnabledByDefault;
|
||||
private boolean myPrimary;
|
||||
@NotNull
|
||||
private final SwitchViewAction mySwitchViewAction;
|
||||
|
||||
public CompositeView(@NotNull S primaryView, @NotNull T secondaryView) {
|
||||
public CompositeView(@NotNull S primaryView, @NotNull T secondaryView, String selectionStateKey, boolean isPrimaryViewEnabledByDefault) {
|
||||
super(new CardLayout());
|
||||
myPrimaryView = primaryView;
|
||||
mySecondaryView = secondaryView;
|
||||
mySelectionStateKey = selectionStateKey;
|
||||
|
||||
add(myPrimaryView.getComponent(), PRIMARY_PANEL);
|
||||
add(mySecondaryView.getComponent(), SECONDARY_PANEL);
|
||||
@@ -65,7 +69,8 @@ public class CompositeView<S extends ComponentContainer, T extends ComponentCont
|
||||
mySwitchViewAction = new SwitchViewAction();
|
||||
|
||||
myPrimary = true;
|
||||
enableView(true);
|
||||
myPrimaryViewEnabledByDefault = isPrimaryViewEnabledByDefault;
|
||||
enableView(getStoredState());
|
||||
|
||||
Disposer.register(this, myPrimaryView);
|
||||
Disposer.register(this, mySecondaryView);
|
||||
@@ -133,6 +138,19 @@ public class CompositeView<S extends ComponentContainer, T extends ComponentCont
|
||||
return consoleView instanceof DataProvider ? ((DataProvider)consoleView).getData(dataId) : null;
|
||||
}
|
||||
|
||||
private void setStoredState(boolean primary) {
|
||||
if (mySelectionStateKey != null) {
|
||||
PropertiesComponent.getInstance().setValue(mySelectionStateKey, primary, myPrimaryViewEnabledByDefault);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean getStoredState() {
|
||||
if (mySelectionStateKey == null) {
|
||||
return false;
|
||||
}
|
||||
return PropertiesComponent.getInstance().getBoolean(mySelectionStateKey, myPrimaryViewEnabledByDefault);
|
||||
}
|
||||
|
||||
private class SwitchViewAction extends ToggleAction implements DumbAware {
|
||||
public SwitchViewAction() {
|
||||
super("Toggle view", null,
|
||||
@@ -147,6 +165,7 @@ public class CompositeView<S extends ComponentContainer, T extends ComponentCont
|
||||
@Override
|
||||
public void setSelected(final AnActionEvent event, final boolean flag) {
|
||||
enableView(!flag);
|
||||
setStoredState(!flag);
|
||||
ApplicationManager.getApplication().invokeLater(() -> update(event));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user