diff options
Diffstat (limited to 'platform/platform-api/src/com/intellij/ui/tabs')
6 files changed, 44 insertions, 18 deletions
diff --git a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java index d1dfa976e479..c8c944c86e4a 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java @@ -92,6 +92,7 @@ public final class TabInfo implements Queryable, PlaceProvider<String> { * out of its container. (IDEA-61536) */ private WeakReference<TabInfo> myPreviousSelection = new WeakReference<TabInfo>(null); + private boolean myTitleShortened; public TabInfo(final JComponent component) { myComponent = component; @@ -392,6 +393,14 @@ public final class TabInfo implements Queryable, PlaceProvider<String> { return myPreviousSelection.get(); } + public boolean isTitleShortened() { + return myTitleShortened; + } + + public void setTitleIsShortened(boolean titleIsShortened) { + myTitleShortened = titleIsShortened; + } + public interface DragOutDelegate { void dragOutStarted(MouseEvent mouseEvent, TabInfo info); diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/DragHelper.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/DragHelper.java index 655854ac933c..b0df0917dfe0 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/DragHelper.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/DragHelper.java @@ -240,7 +240,7 @@ class DragHelper extends MouseDragHelper { final JBTabsPosition position = myTabs.getTabsPosition(); - if (!willDragOutStart && JBEditorTabs.isAlphabeticalMode() && position != JBTabsPosition.top && position != JBTabsPosition.bottom) { + if (!willDragOutStart && myTabs.isAlphabeticalMode() && position != JBTabsPosition.top && position != JBTabsPosition.bottom) { Point p = new Point(event.getPoint()); p = SwingUtilities.convertPoint(event.getComponent(), p, myTabs); if (myTabs.getVisibleRect().contains(p) && myPressedOnScreenPoint.distance(new RelativePoint(event).getScreenPoint()) > 15) { 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 761d3ea0d341..a842f623ac45 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 @@ -43,7 +43,8 @@ import java.util.List; * @author pegov */ public class JBEditorTabs extends JBTabsImpl { - private static final String TABS_ALPHABETICAL_KEY = "tabs.alphabetical"; + public static final String TABS_ALPHABETICAL_KEY = "tabs.alphabetical"; + static final String TABS_SHORTEN_TITLE_IF_NEED = "tabs.shorten.title.if.need"; private JBEditorTabsPainter myDarkPainter = new DarculaEditorTabsPainter(); private JBEditorTabsPainter myDefaultPainter = new DefaultEditorTabsPainter(); @@ -61,6 +62,13 @@ public class JBEditorTabs extends JBTabsImpl { } @Override + protected TabLabel createTabLabel(TabInfo info) { + TabLabel label = super.createTabLabel(info); + label.putClientProperty(TABS_SHORTEN_TITLE_IF_NEED, Boolean.TRUE); + return label; + } + + @Override public boolean isEditorTabs() { return true; } @@ -130,7 +138,7 @@ public class JBEditorTabs extends JBTabsImpl { return UIUtil.isUnderDarcula() ? myDarkPainter : myDefaultPainter; } - public static boolean isAlphabeticalMode() { + public boolean isAlphabeticalMode() { return Registry.is(TABS_ALPHABETICAL_KEY); } 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 a058badddd41..60898a6e9bd8 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 @@ -1262,6 +1262,10 @@ public class JBTabsImpl extends JComponent return null; } + public boolean isAlphabeticalMode() { + return false; + } + @Nullable private TabInfo findEnabledBackward(int from, boolean cycle) { if (from < 0) return null; @@ -1653,19 +1657,13 @@ public class JBTabsImpl extends JComponent config.setAntialiasing(false); - if (isSideComponentVertical()) { - Toolbar toolbarComp = myInfo2Toolbar.get(mySelectedInfo); - if (toolbarComp != null && !toolbarComp.isEmpty()) { - Rectangle toolBounds = toolbarComp.getBounds(); - g2d.setColor(CaptionPanel.CNT_ACTIVE_BORDER_COLOR); + Toolbar toolbarComp = myInfo2Toolbar.get(mySelectedInfo); + if (toolbarComp != null && !toolbarComp.isEmpty()) { + Rectangle toolBounds = toolbarComp.getBounds(); + g2d.setColor(CaptionPanel.CNT_ACTIVE_BORDER_COLOR); + if (isSideComponentVertical()) { g2d.drawLine((int)toolBounds.getMaxX(), toolBounds.y, (int)toolBounds.getMaxX(), (int)toolBounds.getMaxY() - 1); - } - } - else if (!isSideComponentOnTabs()) { - Toolbar toolbarComp = myInfo2Toolbar.get(mySelectedInfo); - if (toolbarComp != null && !toolbarComp.isEmpty()) { - Rectangle toolBounds = toolbarComp.getBounds(); - g2d.setColor(CaptionPanel.CNT_ACTIVE_BORDER_COLOR); + } else if (!isSideComponentOnTabs()) { g2d.drawLine(toolBounds.x, (int)toolBounds.getMaxY(), (int)toolBounds.getMaxX() - 1, (int)toolBounds.getMaxY()); } } diff --git a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java index 21c36d5dd66a..a360c4e9294f 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/impl/TabLabel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 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. @@ -22,6 +22,7 @@ import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.util.Pass; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.*; import com.intellij.ui.components.panels.Wrapper; import com.intellij.ui.tabs.JBTabsPosition; @@ -317,6 +318,16 @@ public class TabLabel extends JPanel { public void setText(final SimpleColoredText text) { + myInfo.setTitleIsShortened(false); + if (text != null && text.getTexts().size() == 1 && Boolean.TRUE == getClientProperty(JBEditorTabs.TABS_SHORTEN_TITLE_IF_NEED)) { + String title = text.getTexts().get(0); + if (title.length() > UISettings.getInstance().EDITOR_TAB_TITLE_LIMIT) { + SimpleTextAttributes attributes = text.getAttributes().get(0); + text.clear(); + text.append(StringUtil.getShortened(title, UISettings.getInstance().EDITOR_TAB_TITLE_LIMIT), attributes); + myInfo.setTitleIsShortened(true); + } + } myLabel.change(new Runnable() { public void run() { myLabel.clear(); 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 653420ae261f..4e5925d2a2ee 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 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 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. @@ -147,7 +147,7 @@ public class SingleRowLayout extends TabLayout { } public LayoutPassInfo layoutSingleRow(List<TabInfo> visibleInfos) { - if (JBEditorTabs.isAlphabeticalMode()) { + if (myTabs.isAlphabeticalMode()) { Collections.sort(visibleInfos, new Comparator<TabInfo>() { @Override public int compare(TabInfo o1, TabInfo o2) { |