use of com.intellij.ui.content.ContentManager in project intellij-community by JetBrains.
the class PinActiveTabAction method getNonToolWindowContent.
@Nullable
private static Content getNonToolWindowContent(@NotNull AnActionEvent e) {
Content result = null;
Content[] contents = e.getData(ViewContext.CONTENT_KEY);
if (contents != null && contents.length == 1)
result = contents[0];
if (result != null && result.isPinnable())
return result;
ContentManager contentManager = ContentManagerUtil.getContentManagerFromContext(e.getDataContext(), true);
result = contentManager != null ? contentManager.getSelectedContent() : null;
if (result != null && result.isPinnable())
return result;
return null;
}
use of com.intellij.ui.content.ContentManager in project intellij-community by JetBrains.
the class TabNavigationActionBase method actionPerformed.
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null || project.isDisposed()) {
return;
}
ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
if (windowManager.isEditorComponentActive()) {
doNavigate(dataContext, project);
return;
}
ContentManager contentManager = PlatformDataKeys.NONEMPTY_CONTENT_MANAGER.getData(dataContext);
if (contentManager == null)
return;
doNavigate(contentManager);
}
use of com.intellij.ui.content.ContentManager in project intellij-community by JetBrains.
the class TabContentLayout method layout.
@Override
public void layout() {
Rectangle bounds = myUi.getBounds();
ContentManager manager = myUi.myManager;
LayoutData data = new LayoutData(myUi);
data.eachX = 2;
data.eachY = 0;
if (isIdVisible()) {
myIdLabel.setBounds(data.eachX, data.eachY, myIdLabel.getPreferredSize().width, bounds.height);
data.eachX += myIdLabel.getPreferredSize().width;
}
int tabsStart = data.eachX;
if (manager.getContentCount() == 0)
return;
Content selected = manager.getSelectedContent();
if (selected == null) {
selected = manager.getContents()[0];
}
if (myLastLayout != null && myLastLayout.layoutSize.equals(bounds.getSize()) && myLastLayout.contentCount == manager.getContentCount()) {
for (ContentTabLabel each : myTabs) {
if (!each.isValid())
break;
if (each.myContent == selected && each.getBounds().width != 0) {
data = myLastLayout;
data.fullLayout = false;
}
}
}
if (data.fullLayout) {
for (ContentTabLabel eachTab : myTabs) {
final Dimension eachSize = eachTab.getPreferredSize();
data.requiredWidth += eachSize.width;
data.requiredWidth++;
data.toLayout.add(eachTab);
}
data.moreRectWidth = myMoreIcon.getIconWidth() + MORE_ICON_BORDER * TAB_ARC;
data.toFitWidth = bounds.getSize().width - data.eachX;
final ContentTabLabel selectedTab = myContent2Tabs.get(selected);
while (true) {
if (data.requiredWidth <= data.toFitWidth)
break;
if (data.toLayout.size() <= 1)
break;
if (data.toLayout.get(0) != selectedTab) {
dropTab(data, data.toLayout.remove(0));
} else if (data.toLayout.get(data.toLayout.size() - 1) != selectedTab) {
dropTab(data, data.toLayout.remove(data.toLayout.size() - 1));
} else {
break;
}
}
boolean reachedBounds = false;
data.moreRect = null;
for (ContentTabLabel each : data.toLayout) {
data.eachY = 0;
final Dimension eachSize = each.getPreferredSize();
if (data.eachX + eachSize.width < data.toFitWidth + tabsStart) {
each.setBounds(data.eachX, data.eachY, eachSize.width, bounds.height - data.eachY);
data.eachX += eachSize.width;
} else {
if (!reachedBounds) {
final int width = bounds.width - data.eachX - data.moreRectWidth;
each.setBounds(data.eachX, data.eachY, width, bounds.height - data.eachY);
data.eachX += width;
} else {
each.setBounds(0, 0, 0, 0);
}
reachedBounds = true;
}
}
for (ContentTabLabel each : data.toDrop) {
each.setBounds(0, 0, 0, 0);
}
}
if (data.toDrop.size() > 0) {
data.moreRect = new Rectangle(data.eachX + MORE_ICON_BORDER, 0, myMoreIcon.getIconWidth(), bounds.height);
final int selectedIndex = manager.getIndexOfContent(manager.getSelectedContent());
if (selectedIndex == 0) {
myMoreIcon.setPaintedIcons(false, true);
} else if (selectedIndex == manager.getContentCount() - 1) {
myMoreIcon.setPaintedIcons(true, false);
} else {
myMoreIcon.setPaintedIcons(true, true);
}
} else {
data.moreRect = null;
}
myLastLayout = data;
}
use of com.intellij.ui.content.ContentManager in project intellij-community by JetBrains.
the class XDebugView method getData.
@Nullable
public static <T> T getData(DataKey<T> key, @NotNull Component component) {
DataContext dataContext = DataManager.getInstance().getDataContext(component);
ViewContext viewContext = ViewContext.CONTEXT_KEY.getData(dataContext);
ContentManager contentManager = viewContext == null ? null : viewContext.getContentManager();
if (contentManager != null) {
T data = key.getData(DataManager.getInstance().getDataContext(contentManager.getComponent()));
if (data != null) {
return data;
}
}
return key.getData(dataContext);
}
use of com.intellij.ui.content.ContentManager in project intellij-community by JetBrains.
the class ProjectViewImpl method doAddPane.
private void doAddPane(@NotNull final AbstractProjectViewPane newPane) {
ApplicationManager.getApplication().assertIsDispatchThread();
int index;
final ContentManager manager = getContentManager();
for (index = 0; index < manager.getContentCount(); index++) {
Content content = manager.getContent(index);
String id = content.getUserData(ID_KEY);
AbstractProjectViewPane pane = myId2Pane.get(id);
int comp = PANE_WEIGHT_COMPARATOR.compare(pane, newPane);
LOG.assertTrue(comp != 0, "Project view pane " + newPane + " has the same weight as " + pane + ". Please make sure that you overload getWeight() and return a distinct weight value.");
if (comp > 0) {
break;
}
}
final String id = newPane.getId();
myId2Pane.put(id, newPane);
String[] subIds = newPane.getSubIds();
subIds = subIds.length == 0 ? new String[] { null } : subIds;
boolean first = true;
for (String subId : subIds) {
final String title = subId != null ? newPane.getPresentableSubIdName(subId) : newPane.getTitle();
final Content content = getContentManager().getFactory().createContent(getComponent(), title, false);
content.setTabName(title);
content.putUserData(ID_KEY, id);
content.putUserData(SUB_ID_KEY, subId);
content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
content.setIcon(newPane.getIcon());
content.setPopupIcon(subId != null ? AllIcons.General.Bullet : newPane.getIcon());
content.setPreferredFocusedComponent(() -> {
final AbstractProjectViewPane current = getCurrentProjectViewPane();
return current != null ? current.getComponentToFocus() : null;
});
content.setBusyObject(this);
if (first && subId != null) {
content.setSeparator(newPane.getTitle());
}
manager.addContent(content, index++);
first = false;
}
}
Aggregations