diff options
Diffstat (limited to 'platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java')
-rw-r--r-- | platform/platform-api/src/com/intellij/ui/tabs/impl/JBTabsImpl.java | 62 |
1 files changed, 40 insertions, 22 deletions
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; } |