-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IDEA-127205 Specify Editor Tab Width
- Loading branch information
Vassiliy.Kudryashov
authored and
Vassiliy.Kudryashov
committed
Jun 4, 2015
1 parent
5e1a42a
commit 2228d3e
Showing
8 changed files
with
257 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
platform/platform-api/src/com/intellij/ui/tabs/impl/TabsSideSplitter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright 2000-2015 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.ui.tabs.impl; | ||
|
||
import com.intellij.openapi.ui.OnePixelDivider; | ||
import com.intellij.openapi.ui.Splittable; | ||
import com.intellij.ui.tabs.JBTabsPosition; | ||
import com.intellij.ui.tabs.TabInfo; | ||
import com.intellij.util.ui.JBUI; | ||
import com.intellij.util.ui.UIUtil; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
|
||
|
||
class TabsSideSplitter implements Splittable, PropertyChangeListener { | ||
private static final int MIN_TAB_WIDTH = JBUI.scale(75); | ||
|
||
@NotNull private final JBTabsImpl myTabs; | ||
private int mySideTabsLimit = 0; | ||
private boolean myDragging; | ||
private final OnePixelDivider myDivider; | ||
|
||
|
||
TabsSideSplitter(@NotNull JBTabsImpl tabs) { | ||
myTabs = tabs; | ||
myTabs.addPropertyChangeListener(JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString(), this); | ||
myDivider = new OnePixelDivider(false, this); | ||
} | ||
|
||
OnePixelDivider getDivider() { | ||
return myDivider; | ||
} | ||
|
||
@Override | ||
public float getMinProportion(boolean first) { | ||
return Math.min(.5F, (float)MIN_TAB_WIDTH / Math.max(1, myTabs.getWidth())); | ||
} | ||
|
||
@Override | ||
public void setProportion(float proportion) { | ||
int width = myTabs.getWidth(); | ||
if (myTabs.getTabsPosition() == JBTabsPosition.left) { | ||
setSideTabsLimit((int)Math.max(MIN_TAB_WIDTH, proportion * width)); | ||
} | ||
else if (myTabs.getTabsPosition() == JBTabsPosition.right) { | ||
setSideTabsLimit(width - (int)Math.max(MIN_TAB_WIDTH, proportion * width)); | ||
} | ||
} | ||
|
||
int getSideTabsLimit() { | ||
return mySideTabsLimit; | ||
} | ||
|
||
void setSideTabsLimit(int sideTabsLimit) { | ||
if (mySideTabsLimit != sideTabsLimit) { | ||
mySideTabsLimit = sideTabsLimit; | ||
UIUtil.putClientProperty(myTabs, JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY, mySideTabsLimit); | ||
myTabs.resetLayout(true); | ||
myTabs.doLayout(); | ||
myTabs.repaint(); | ||
TabInfo info = myTabs.getSelectedInfo(); | ||
JComponent page = info != null ? info.getComponent() : null; | ||
if (page != null) { | ||
page.revalidate(); | ||
page.repaint(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean getOrientation() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setOrientation(boolean verticalSplit) { | ||
//ignore | ||
} | ||
|
||
@Override | ||
public void setDragging(boolean dragging) { | ||
myDragging = dragging; | ||
} | ||
|
||
boolean isDragging() { | ||
return myDragging; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Component asComponent() { | ||
return myTabs; | ||
} | ||
|
||
@Override | ||
public void propertyChange(PropertyChangeEvent evt) { | ||
if (evt.getSource() != myTabs) return; | ||
Integer limit = UIUtil.getClientProperty(myTabs, JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY); | ||
if (limit == null) limit = 0; | ||
setSideTabsLimit(limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.