diff options
Diffstat (limited to 'platform/platform-api/src/com/intellij/ui/tabs')
4 files changed, 57 insertions, 38 deletions
diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java index a842f623ac45..43f06bff2850 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBEditorTabs.java @@ -49,7 +49,7 @@ public class JBEditorTabs extends JBTabsImpl { private JBEditorTabsPainter myDefaultPainter = new DefaultEditorTabsPainter(); - public JBEditorTabs(@Nullable Project project, ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) { + public JBEditorTabs(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) { super(project, actionManager, focusManager, parent); } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java index 60898a6e9bd8..326192072c4b 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java @@ -28,6 +28,7 @@ import com.intellij.openapi.wm.*; import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.awt.RelativeRectangle; +import com.intellij.ui.components.OrphanGuardian; import com.intellij.ui.switcher.QuickActionProvider; import com.intellij.ui.switcher.SwitchProvider; import com.intellij.ui.switcher.SwitchTarget; @@ -36,6 +37,7 @@ import com.intellij.ui.tabs.impl.singleRow.SingleRowLayout; import com.intellij.ui.tabs.impl.singleRow.SingleRowPassInfo; import com.intellij.ui.tabs.impl.table.TableLayout; import com.intellij.ui.tabs.impl.table.TablePassInfo; +import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.Animator; @@ -69,7 +71,7 @@ public class JBTabsImpl extends JComponent public static final Color MAC_AQUA_BG_COLOR = Gray._200; - final ActionManager myActionManager; + @NotNull final ActionManager myActionManager; private final List<TabInfo> myVisibleInfos = new ArrayList<TabInfo>(); private final Map<TabInfo, Integer> myHiddenInfos = new HashMap<TabInfo, Integer>(); @@ -153,8 +155,8 @@ public class JBTabsImpl extends JComponent private JBTabsPosition myPosition = JBTabsPosition.top; private final TabsBorder myBorder = new TabsBorder(this); - private BaseNavigationAction myNextAction; - private BaseNavigationAction myPrevAction; + private final BaseNavigationAction myNextAction; + private final BaseNavigationAction myPrevAction; private boolean myTabDraggingEnabled; private DragHelper myDragHelper; @@ -172,6 +174,7 @@ public class JBTabsImpl extends JComponent private Runnable myDeferredFocusRequest; private boolean myAlwaysPaintSelectedTab; + private int myFirstTabOffset; public JBTabsImpl(@NotNull Project project) { this(project, project); @@ -185,7 +188,7 @@ public class JBTabsImpl extends JComponent this(project, ActionManager.getInstance(), focusManager, parent); } - public JBTabsImpl(@Nullable Project project, ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) { + public JBTabsImpl(@Nullable Project project, @NotNull ActionManager actionManager, IdeFocusManager focusManager, @NotNull Disposable parent) { myProject = project; myActionManager = actionManager; myFocusManager = focusManager != null ? focusManager : IdeFocusManager.getGlobalInstance(); @@ -197,13 +200,11 @@ public class JBTabsImpl extends JComponent myNavigationActions = new DefaultActionGroup(); - if (myActionManager != null) { - myNextAction = new SelectNextAction(this, myActionManager); - myPrevAction = new SelectPreviousAction(this, myActionManager); + myNextAction = new SelectNextAction(this, myActionManager); + myPrevAction = new SelectPreviousAction(this, myActionManager); - myNavigationActions.add(myNextAction); - myNavigationActions.add(myPrevAction); - } + myNavigationActions.add(myNextAction); + myNavigationActions.add(myPrevAction); setUiDecorator(null); @@ -315,6 +316,16 @@ public class JBTabsImpl extends JComponent } } }; + putClientProperty(OrphanGuardian.CLIENT_PROPERTY_KEY, new OrphanGuardian() { + + @Override + public void iterateOrphans(Consumer<JComponent> consumer) { + for (TabInfo info : getVisibleInfos()) { + if (info == mySelectedInfo) continue; + consumer.consume(info.getComponent()); + } + } + }); } protected SingleRowLayout createSingleRowLayout() { @@ -451,14 +462,14 @@ public class JBTabsImpl extends JComponent } private void addTimerUpdate() { - if (myActionManager != null && !myListenerAdded) { + if (!myListenerAdded) { myActionManager.addTimerListener(500, this); myListenerAdded = true; } } private void removeTimerUpdate() { - if (myActionManager != null && myListenerAdded) { + if (myListenerAdded) { myActionManager.removeTimerListener(this); myListenerAdded = false; } @@ -492,6 +503,14 @@ public class JBTabsImpl extends JComponent myDropInfoIndex = dropInfoIndex; } + public int getFirstTabOffset() { + return myFirstTabOffset; + } + + public void setFirstTabOffset(int firstTabOffset) { + myFirstTabOffset = firstTabOffset; + } + class TabActionsAutoHideListener extends MouseMotionAdapter implements Weighted { private TabLabel myCurrentOverLabel; @@ -1399,7 +1418,7 @@ public class JBTabsImpl extends JComponent final ActionGroup group = info.getGroup(); final JComponent side = info.getSideComponent(); - if (group != null && myTabs.myActionManager != null) { + if (group != null) { final String place = info.getPlace(); ActionToolbar toolbar = myTabs.myActionManager.createActionToolbar(place != null ? place : ActionPlaces.UNKNOWN, group, myTabs.myHorizontalSide); @@ -1604,7 +1623,7 @@ public class JBTabsImpl extends JComponent return 3; } - public static int getGhostTabLength() { + public int getGhostTabLength() { return 15; } @@ -2561,6 +2580,7 @@ public class JBTabsImpl extends JComponent } private void updateContainer(boolean forced, final boolean layoutNow) { + if (myProject != null && !myProject.isOpen()) return; for (TabInfo each : new ArrayList<TabInfo>(myVisibleInfos)) { final JComponent eachComponent = each.getComponent(); if (getSelectedInfo() == each && getSelectedInfo() != null) { @@ -2746,8 +2766,7 @@ public class JBTabsImpl extends JComponent } private static boolean isChanged(Object oldObject, Object newObject) { - if (oldObject == null && newObject == null) return false; - return oldObject != null && !oldObject.equals(newObject) || newObject != null && !newObject.equals(oldObject); + return !Comparing.equal(oldObject, newObject); } @Override @@ -2785,12 +2804,11 @@ public class JBTabsImpl extends JComponent } private abstract static class BaseNavigationAction extends AnAction { - private final ShadowAction myShadow; - private final ActionManager myActionManager; + @NotNull private final ActionManager myActionManager; private final JBTabsImpl myTabs; - protected BaseNavigationAction(final String copyFromID, JBTabsImpl tabs, ActionManager mgr) { + protected BaseNavigationAction(@NotNull String copyFromID, @NotNull JBTabsImpl tabs, @NotNull ActionManager mgr) { myActionManager = mgr; myTabs = tabs; myShadow = new ShadowAction(this, myActionManager.getAction(copyFromID), tabs); @@ -2858,7 +2876,7 @@ public class JBTabsImpl extends JComponent private static class SelectNextAction extends BaseNavigationAction { - private SelectNextAction(JBTabsImpl tabs, ActionManager mgr) { + private SelectNextAction(JBTabsImpl tabs, @NotNull ActionManager mgr) { super(IdeActions.ACTION_NEXT_TAB, tabs, mgr); } @@ -2874,7 +2892,7 @@ public class JBTabsImpl extends JComponent } private static class SelectPreviousAction extends BaseNavigationAction { - private SelectPreviousAction(JBTabsImpl tabs, ActionManager mgr) { + private SelectPreviousAction(JBTabsImpl tabs, @NotNull ActionManager mgr) { super(IdeActions.ACTION_PREVIOUS_TAB, tabs, mgr); } @@ -3351,7 +3369,7 @@ public class JBTabsImpl extends JComponent return myVisibleInfos.isEmpty(); } - public static int getInterTabSpaceLength() { + public int getInterTabSpaceLength() { return 1; } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java index 4e5925d2a2ee..6bd2e1aa52bf 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/singleRow/SingleRowLayout.java @@ -209,6 +209,7 @@ public class SingleRowLayout extends TabLayout { protected void prepareLayoutPassInfo(SingleRowPassInfo data, TabInfo selected) { data.insets = myTabs.getLayoutInsets(); + data.insets.left += myTabs.getFirstTabOffset(); final JBTabsImpl.Toolbar selectedToolbar = myTabs.myInfo2Toolbar.get(selected); data.hToolbar = selectedToolbar != null && myTabs.myHorizontalSide && !selectedToolbar.isEmpty() ? selectedToolbar : null; @@ -216,7 +217,7 @@ public class SingleRowLayout extends TabLayout { data.toFitLength = getStrategy().getToFitLength(data); if (myTabs.isGhostsAlwaysVisible()) { - data.toFitLength -= JBTabsImpl.getGhostTabLength() * 2 + (JBTabsImpl.getInterTabSpaceLength() * 2); + data.toFitLength -= myTabs.getGhostTabLength() * 2 + (myTabs.getInterTabSpaceLength() * 2); } } @@ -236,9 +237,9 @@ public class SingleRowLayout extends TabLayout { private void layoutLabelsAndGhosts(final SingleRowPassInfo data) { if (data.firstGhostVisible || myTabs.isGhostsAlwaysVisible()) { - data.firstGhost = getStrategy().getLayoutRect(data, data.position, JBTabsImpl.getGhostTabLength()); + data.firstGhost = getStrategy().getLayoutRect(data, data.position, myTabs.getGhostTabLength()); myTabs.layout(myLeftGhost, data.firstGhost); - data.position += getStrategy().getLengthIncrement(data.firstGhost.getSize()) + JBTabsImpl.getInterTabSpaceLength(); + data.position += getStrategy().getLengthIncrement(data.firstGhost.getSize()) + myTabs.getInterTabSpaceLength(); } int deltaToFit = 0; @@ -275,9 +276,9 @@ public class SingleRowLayout extends TabLayout { boolean continueLayout = applyTabLayout(data, label, length, deltaToFit); data.position = getStrategy().getMaxPosition(label.getBounds()); - data.position += JBTabsImpl.getInterTabSpaceLength(); + data.position += myTabs.getInterTabSpaceLength(); - totalLength = getStrategy().getMaxPosition(label.getBounds()) - positionStart + JBTabsImpl.getInterTabSpaceLength(); + totalLength = getStrategy().getMaxPosition(label.getBounds()) - positionStart + myTabs.getInterTabSpaceLength(); if (!continueLayout) { layoutStopped = true; } @@ -288,7 +289,7 @@ public class SingleRowLayout extends TabLayout { } if (data.lastGhostVisible || myTabs.isGhostsAlwaysVisible()) { - data.lastGhost = getStrategy().getLayoutRect(data, data.position, JBTabsImpl.getGhostTabLength()); + data.lastGhost = getStrategy().getLayoutRect(data, data.position, myTabs.getGhostTabLength()); myTabs.layout(myRightGhost, data.lastGhost); } } @@ -366,7 +367,7 @@ public class SingleRowLayout extends TabLayout { protected int getRequiredLength(TabInfo eachInfo) { TabLabel label = myTabs.myInfo2Label.get(eachInfo); return getStrategy().getLengthIncrement(label != null ? label.getPreferredSize() : new Dimension()) - + (myTabs.isEditorTabs() ? JBTabsImpl.getInterTabSpaceLength() : 0); + + (myTabs.isEditorTabs() ? myTabs.getInterTabSpaceLength() : 0); } @@ -417,13 +418,13 @@ public class SingleRowLayout extends TabLayout { if (!data.firstGhostVisible && isFirstSide) { data.firstGhostVisible = !myTabs.isEditorTabs(); if (!myTabs.isGhostsAlwaysVisible() && !myTabs.isEditorTabs()) { - data.toFitLength -= JBTabsImpl.getGhostTabLength(); + data.toFitLength -= myTabs.getGhostTabLength(); } } else if (!data.lastGhostVisible && !isFirstSide) { data.lastGhostVisible = !myTabs.isEditorTabs(); if (!myTabs.isGhostsAlwaysVisible() && !myTabs.isEditorTabs()) { - data.toFitLength -= JBTabsImpl.getGhostTabLength(); + data.toFitLength -= myTabs.getGhostTabLength(); } } } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java index 1326531e2465..9b313783dea7 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/table/TableLayout.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -56,8 +56,8 @@ public class TableLayout extends TabLayout { eachX = data.toFitRec.x; } myTabs.layout(eachLabel, eachX, 0, size.width, 1); - eachX += size.width + JBTabsImpl.getInterTabSpaceLength(); - data.requiredWidth += size.width + JBTabsImpl.getInterTabSpaceLength(); + eachX += size.width + myTabs.getInterTabSpaceLength(); + data.requiredWidth += size.width + myTabs.getInterTabSpaceLength(); } int selectedRow = -1; @@ -84,7 +84,7 @@ public class TableLayout extends TabLayout { if (myTabs.getSelectedInfo() == eachInfo) { selectedRow = eachRow; } - eachX += size.width + JBTabsImpl.getInterTabSpaceLength(); + eachX += size.width + myTabs.getInterTabSpaceLength(); } else { eachTableRow = new TableRow(data); @@ -161,9 +161,9 @@ public class TableLayout extends TabLayout { label.setAlignmentToCenter(deltaToFit > 0); boolean lastCell = i == eachRow.myColumns.size() - 1; - eachX += width + (lastCell ? 0 : JBTabsImpl.getInterTabSpaceLength()); + eachX += width + (lastCell ? 0 : myTabs.getInterTabSpaceLength()); } - eachY += myTabs.myHeaderFitSize.height - 1 + JBTabsImpl.getInterTabSpaceLength() - (row < data.table.size() - 1 ? tabUnderlineFix : 0); + eachY += myTabs.myHeaderFitSize.height - 1 + myTabs.getInterTabSpaceLength() - (row < data.table.size() - 1 ? tabUnderlineFix : 0); row++; } |