mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
Add setTopLeftToolbar and setTopRightToolbar Api
Remove useless isToolbarHorizontal and setToolbarHorizontal methods GitOrigin-RevId: afe121b62db941e2959b1a94c529502599fbb5ba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0509ecee4a
commit
623a38b62d
@@ -70,7 +70,7 @@ public final class GridCellImpl implements GridCell {
|
||||
return null;
|
||||
});
|
||||
|
||||
myTabs.getPresentation().setSideComponentVertical(!context.getLayoutSettings().isToolbarHorizontal())
|
||||
myTabs.getPresentation().setSideComponentVertical(true)
|
||||
.setFocusCycle(false).setPaintFocus(true)
|
||||
.setTabDraggingEnabled(context.isMoveToGridActionEnabled()).setSideComponentOnTabs(false);
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.intellij.ui.tabs.JBTabsEx.NAVIGATION_ACTIONS_KEY;
|
||||
|
||||
@@ -109,18 +110,20 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
};
|
||||
private final Project myProject;
|
||||
|
||||
private ActionGroup myTopActions = new DefaultActionGroup();
|
||||
private ActionGroup myTopLeftActions = new DefaultActionGroup();
|
||||
private ActionGroup myTopRightActions = new DefaultActionGroup();
|
||||
|
||||
private final DefaultActionGroup myViewActions = new DefaultActionGroup();
|
||||
|
||||
private final Map<GridImpl, Wrapper> myMinimizedButtonsPlaceholder = new HashMap<>();
|
||||
private final Map<GridImpl, Wrapper> myCommonActionsPlaceholder = new HashMap<>();
|
||||
private final Map<GridImpl, AnAction[]> myContextActions = new HashMap<>();
|
||||
private final Map<GridImpl, TopToolbarWrappers> myCommonActionsPlaceholder = new HashMap<>();
|
||||
private final Map<GridImpl, TopToolbarContextActions> myContextActions = new HashMap<>();
|
||||
|
||||
private boolean myUiLastStateWasRestored;
|
||||
|
||||
private final Set<Object> myRestoreStateRequestors = new HashSet<>();
|
||||
private String myActionsPlace = ActionPlaces.UNKNOWN;
|
||||
private String myTopLeftActionsPlace = ActionPlaces.UNKNOWN;
|
||||
private String myTopRightActionsPlace = ActionPlaces.UNKNOWN;
|
||||
private final IdeFocusManager myFocusManager;
|
||||
|
||||
private boolean myMinimizeActionEnabled = true;
|
||||
@@ -176,9 +179,16 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
myWindow = window == 0 ? original.findFreeWindow() : window;
|
||||
}
|
||||
|
||||
void setTopActions(@NotNull final ActionGroup topActions, @NotNull String place) {
|
||||
myTopActions = topActions;
|
||||
myActionsPlace = place;
|
||||
void setTopLeftActions(@NotNull final ActionGroup topActions, @NotNull String place) {
|
||||
myTopLeftActions = topActions;
|
||||
myTopLeftActionsPlace = place;
|
||||
|
||||
rebuildCommonActions();
|
||||
}
|
||||
|
||||
void setTopRightActions(@NotNull final ActionGroup topActions, @NotNull String place) {
|
||||
myTopRightActions = topActions;
|
||||
myTopRightActionsPlace = place;
|
||||
|
||||
rebuildCommonActions();
|
||||
}
|
||||
@@ -832,8 +842,9 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
|
||||
TabInfo tab = new TabInfo(grid).setObject(getStateFor(content).getTab()).setText("Tab");
|
||||
|
||||
Wrapper left = new Wrapper();
|
||||
myCommonActionsPlaceholder.put(grid, left);
|
||||
Wrapper leftWrapper = new Wrapper();
|
||||
Wrapper rightWrapper = new Wrapper();
|
||||
myCommonActionsPlaceholder.put(grid, new TopToolbarWrappers(leftWrapper, rightWrapper));
|
||||
|
||||
Wrapper minimizedToolbar = new Wrapper();
|
||||
myMinimizedButtonsPlaceholder.put(grid, minimizedToolbar);
|
||||
@@ -847,7 +858,7 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
TwoSideComponent right = new TwoSideComponent(searchComponent, minimizedToolbar);
|
||||
|
||||
|
||||
NonOpaquePanel sideComponent = new TwoSideComponent(left, right);
|
||||
NonOpaquePanel sideComponent = new TwoSideComponent(leftWrapper, new TwoSideComponent(right, rightWrapper));
|
||||
|
||||
tab.setSideComponent(sideComponent);
|
||||
|
||||
@@ -926,49 +937,46 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
|
||||
private boolean rebuildCommonActions() {
|
||||
boolean hasToolbarContent = false;
|
||||
for (Map.Entry<GridImpl, Wrapper> entry : myCommonActionsPlaceholder.entrySet()) {
|
||||
Wrapper eachPlaceholder = entry.getValue();
|
||||
List<Content> contentList = entry.getKey().getContents();
|
||||
for (Map.Entry<GridImpl, TopToolbarWrappers> entry : myCommonActionsPlaceholder.entrySet()) {
|
||||
Wrapper leftPlaceHolder = entry.getValue().left;
|
||||
Wrapper rightPlaceHolder = entry.getValue().right;
|
||||
|
||||
Set<Content> contents = new HashSet<>(contentList);
|
||||
TopToolbarContextActions topToolbarContextActions = myContextActions.get(entry.getKey());
|
||||
|
||||
DefaultActionGroup groupToBuild;
|
||||
JComponent contextComponent = null;
|
||||
if (isHorizontalToolbar() && contents.size() == 1) {
|
||||
Content content = contentList.get(0);
|
||||
groupToBuild = new DefaultActionGroup();
|
||||
if (content.getActions() != null) {
|
||||
groupToBuild.addAll(content.getActions());
|
||||
groupToBuild.addSeparator();
|
||||
contextComponent = content.getActionsContextComponent();
|
||||
}
|
||||
groupToBuild.addAll(myTopActions);
|
||||
}
|
||||
else {
|
||||
final DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.addAll(myTopActions);
|
||||
groupToBuild = group;
|
||||
DefaultActionGroup leftGroupToBuild = new DefaultActionGroup();
|
||||
leftGroupToBuild.addAll(myTopLeftActions);
|
||||
final AnAction[] leftActions = leftGroupToBuild.getChildren(null);
|
||||
|
||||
if (topToolbarContextActions == null || !Arrays.equals(leftActions, topToolbarContextActions.left)) {
|
||||
setActions(leftPlaceHolder, myTopLeftActionsPlace, leftGroupToBuild);
|
||||
}
|
||||
|
||||
final AnAction[] actions = groupToBuild.getChildren(null);
|
||||
if (!Arrays.equals(actions, myContextActions.get(entry.getKey()))) {
|
||||
String adjustedPlace = myActionsPlace == ActionPlaces.UNKNOWN ? ActionPlaces.TOOLBAR : myActionsPlace;
|
||||
ActionToolbar tb = myActionManager.createActionToolbar(adjustedPlace, groupToBuild, true);
|
||||
tb.getComponent().setBorder(null);
|
||||
tb.setTargetComponent(contextComponent);
|
||||
eachPlaceholder.setContent(tb.getComponent());
|
||||
DefaultActionGroup rightGroupToBuild = new DefaultActionGroup();
|
||||
rightGroupToBuild.addAll(myTopRightActions);
|
||||
final AnAction[] rightActions = rightGroupToBuild.getChildren(null);
|
||||
|
||||
if (topToolbarContextActions == null || !Arrays.equals(rightActions, topToolbarContextActions.right)) {
|
||||
setActions(rightPlaceHolder, myTopRightActionsPlace, rightGroupToBuild);
|
||||
}
|
||||
|
||||
if (groupToBuild.getChildrenCount() > 0) {
|
||||
myContextActions.put(entry.getKey(), new TopToolbarContextActions(leftActions, rightActions));
|
||||
|
||||
if (leftGroupToBuild.getChildrenCount() > 0 || rightGroupToBuild.getChildrenCount() > 0) {
|
||||
hasToolbarContent = true;
|
||||
}
|
||||
|
||||
myContextActions.put(entry.getKey(), actions);
|
||||
}
|
||||
|
||||
return hasToolbarContent;
|
||||
}
|
||||
|
||||
private void setActions(Wrapper placeHolder, String place, DefaultActionGroup group) {
|
||||
String adjustedPlace = place == ActionPlaces.UNKNOWN ? ActionPlaces.TOOLBAR : place;
|
||||
ActionToolbar tb = myActionManager.createActionToolbar(adjustedPlace, group, true);
|
||||
tb.getComponent().setBorder(null);
|
||||
|
||||
placeHolder.setContent(tb.getComponent());
|
||||
}
|
||||
|
||||
private boolean rebuildMinimizedActions() {
|
||||
for (Map.Entry<GridImpl, Wrapper> entry : myMinimizedButtonsPlaceholder.entrySet()) {
|
||||
Wrapper eachPlaceholder = entry.getValue();
|
||||
@@ -1157,17 +1165,6 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
return ContainerUtil.map(myTabs.getTabs(), RunnerContentUi::getGridFor);
|
||||
}
|
||||
|
||||
public void setHorizontalToolbar(final boolean state) {
|
||||
myLayoutSettings.setToolbarHorizontal(state);
|
||||
for (GridImpl each : getGrids()) {
|
||||
each.setToolbarHorizontal(state);
|
||||
}
|
||||
|
||||
myContextActions.clear();
|
||||
updateTabsUI(false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSingleSelection() {
|
||||
return false;
|
||||
@@ -1237,7 +1234,8 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
myContextActions.clear();
|
||||
|
||||
myOriginal = null;
|
||||
myTopActions = null;
|
||||
myTopLeftActions = null;
|
||||
myTopRightActions = null;
|
||||
myAdditionalFocusActions = null;
|
||||
myLeftToolbarActions = null;
|
||||
}
|
||||
@@ -1296,7 +1294,10 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
}
|
||||
|
||||
public void updateActionsImmediately() {
|
||||
StreamEx.of(myToolbar).append(myCommonActionsPlaceholder.values())
|
||||
Collection<TopToolbarWrappers> values = myCommonActionsPlaceholder.values();
|
||||
Stream<Wrapper> leftWrappers = values.stream().map(it -> it.left);
|
||||
Stream<Wrapper> rightWrappers = values.stream().map(it -> it.right);
|
||||
StreamEx.of(myToolbar).append(leftWrappers).append(rightWrappers)
|
||||
.map(Wrapper::getTargetComponent)
|
||||
.select(ActionToolbar.class)
|
||||
.distinct()
|
||||
@@ -1690,10 +1691,6 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
return myLayoutSettings.getStateFor(content);
|
||||
}
|
||||
|
||||
private boolean isHorizontalToolbar() {
|
||||
return myLayoutSettings.isToolbarHorizontal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionCallback select(@NotNull final Content content, final boolean requestFocus) {
|
||||
final GridImpl grid = (GridImpl)findGridFor(content);
|
||||
@@ -1994,4 +1991,24 @@ public final class RunnerContentUi implements ContentUI, Disposable, CellTransfo
|
||||
each.contentRemoved(content);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TopToolbarContextActions {
|
||||
public final AnAction[] left;
|
||||
public final AnAction[] right;
|
||||
|
||||
private TopToolbarContextActions(AnAction[] left, AnAction[] right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
}
|
||||
|
||||
private static class TopToolbarWrappers {
|
||||
public final Wrapper left;
|
||||
public final Wrapper right;
|
||||
|
||||
private TopToolbarWrappers(Wrapper left, Wrapper right) {
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,14 +156,6 @@ public class RunnerLayout {
|
||||
myTabs.clear();
|
||||
}
|
||||
|
||||
public boolean isToolbarHorizontal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setToolbarHorizontal(boolean horizontal) {
|
||||
myGeneral.horizontalToolbar = horizontal;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ViewImpl getStateFor(@NotNull Content content) {
|
||||
return getOrCreateView(getOrCreateContentId(content));
|
||||
|
||||
@@ -71,8 +71,22 @@ public class RunnerLayoutUiImpl implements Disposable.Parent, RunnerLayoutUi, La
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public LayoutViewOptions setTopToolbar(@NotNull ActionGroup actions, @NotNull String place) {
|
||||
myContentUI.setTopActions(actions, place);
|
||||
return setTopLeftToolbar(actions, place);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LayoutViewOptions setTopLeftToolbar(@NotNull ActionGroup actions, @NotNull String place) {
|
||||
myContentUI.setTopLeftActions(actions, place);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LayoutViewOptions setTopRightToolbar(@NotNull ActionGroup actions, @NotNull String place) {
|
||||
myContentUI.setTopRightActions(actions, place);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,15 @@ public interface LayoutViewOptions {
|
||||
String STARTUP = "startup";
|
||||
|
||||
@NotNull
|
||||
@Deprecated
|
||||
LayoutViewOptions setTopToolbar(@NotNull ActionGroup actions, @NotNull String place);
|
||||
|
||||
@NotNull
|
||||
LayoutViewOptions setTopLeftToolbar(@NotNull ActionGroup actions, @NotNull String place);
|
||||
|
||||
@NotNull
|
||||
LayoutViewOptions setTopRightToolbar(@NotNull ActionGroup actions, @NotNull String place);
|
||||
|
||||
@NotNull
|
||||
LayoutViewOptions setLeftToolbar(@NotNull ActionGroup leftToolbar, @NotNull String place);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user