tool window combo - show content action

This commit is contained in:
Kirill Kalishev
2009-11-02 13:40:33 +03:00
parent a9cef6f8aa
commit 1b05fc9c85
12 changed files with 148 additions and 38 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.InputEvent;
public interface ToolWindow {
@@ -159,6 +160,8 @@ public interface ToolWindow {
boolean isDisposed();
void showContentPopup(InputEvent inputEvent);
class Border extends EmptyBorder {
public Border() {
this(true, true, true, true);
@@ -0,0 +1,64 @@
/*
* Copyright 2000-2009 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.ide.actions;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataConstants;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ShadowAction;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class ShowContentAction extends AnAction {
private ToolWindow myWindow;
public ShowContentAction() {
}
public ShowContentAction(ToolWindow window, JComponent c) {
myWindow = window;
AnAction original = ActionManager.getInstance().getAction("ShowContent");
new ShadowAction(this, original, c);
copyFrom(original);
}
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(getWindow(e) != null);
}
@Override
public void actionPerformed(AnActionEvent e) {
getWindow(e).showContentPopup(e.getInputEvent());
}
@Nullable
private ToolWindow getWindow(AnActionEvent event) {
if (myWindow != null) return myWindow;
Project project = (Project)event.getDataContext().getData(DataConstants.PROJECT);
if (project == null) return null;
ToolWindowManager manager = ToolWindowManager.getInstance(project);
return manager.getToolWindow(manager.getActiveToolWindowId());
}
}
@@ -45,6 +45,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.awt.event.InputEvent;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
@@ -161,6 +162,9 @@ public class ToolWindowHeadlessManagerImpl extends ToolWindowManagerEx {
public void activate(@Nullable Runnable runnable, boolean autoFocusContents, boolean forced) {
}
public void showContentPopup(InputEvent inputEvent) {
}
};
@NonNls private static final ContentManager MOCK_CONTENT_MANAGER = new ContentManager() {
@@ -34,6 +34,7 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
@@ -364,5 +365,7 @@ public final class ToolWindowImpl implements ToolWindowEx {
}
}
public void showContentPopup(InputEvent inputEvent) {
myContentUI.showContentPopup(inputEvent);
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.wm.impl.content;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.wm.impl.TitlePanel;
import com.intellij.ui.content.ContentManagerEvent;
@@ -154,4 +155,10 @@ class ComboContentLayout extends ContentLayout {
@Override
public void contentRemoved(ContentManagerEvent event) {
}
@Override
public void showContentPopup(ListPopup listPopup) {
listPopup.setMinimumSize(new Dimension(myComboLabel.getPreferredSize().width, 0));
listPopup.showUnderneathOf(myComboLabel);
}
}
@@ -58,45 +58,10 @@ public class ContentComboLabel extends BaseLabel {
super.processMouseEvent(e);
if (UIUtil.isActionClick(e)) {
showPopup();
myUi.showContentPopup(e);
}
}
private void showPopup() {
if (!isToDrawCombo()) return;
final ContentManager manager = myUi.myManager;
BaseListPopupStep step = new BaseListPopupStep<Content>(null, manager.getContents()) {
@Override
public PopupStep onChosen(Content selectedValue, boolean finalChoice) {
manager.setSelectedContent(selectedValue);
return FINAL_CHOICE;
}
@NotNull
@Override
public String getTextFor(Content value) {
return value.getDisplayName();
}
@Override
public Icon getIconFor(Content aValue) {
return aValue.getIcon();
}
@Override
public boolean isMnemonicsNavigationEnabled() {
return true;
}
};
step.setDefaultOptionIndex(Arrays.asList(manager.getContents()).indexOf(manager.getSelectedContent()));
ListPopup popup = JBPopupFactory.getInstance().createListPopup(step);
popup.setMinimumSize(new Dimension(getPreferredSize().width, 0));
popup.showUnderneathOf(this);
}
void update() {
if (isToDrawCombo()) {
setBorder(new EmptyBorder(0, 8, 0, 8));
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.wm.impl.content;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.ui.content.ContentManagerEvent;
import javax.swing.border.EmptyBorder;
@@ -90,5 +91,5 @@ abstract class ContentLayout {
g2d.fill(shape);
}
public abstract void showContentPopup(ListPopup listPopup);
}
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.wm.impl.content;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.wm.impl.TitlePanel;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
@@ -388,4 +389,15 @@ class TabContentLayout extends ContentLayout {
myContent2Tabs.remove(event.getContent());
}
}
@Override
public void showContentPopup(ListPopup listPopup) {
Content selected = myUi.myManager.getSelectedContent();
if (selected != null) {
ContentTabLabel tab = myContent2Tabs.get(selected);
listPopup.showUnderneathOf(tab);
} else {
listPopup.showUnderneathOf(myIdLabel);
}
}
}
@@ -16,7 +16,11 @@
package com.intellij.openapi.wm.impl.content;
import com.intellij.ide.IdeEventQueue;
import com.intellij.ide.actions.ShowContentAction;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.ToolWindowContentUiType;
import com.intellij.openapi.wm.impl.ToolWindowImpl;
@@ -32,11 +36,13 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;
public class ToolWindowContentUi extends JPanel implements ContentUI, PropertyChangeListener, DataProvider {
public static final String POPUP_PLACE = "ToolwindowPopup";
@@ -51,6 +57,8 @@ public class ToolWindowContentUi extends JPanel implements ContentUI, PropertyCh
TabbedContentAction.MyNextTabAction myNextTabAction;
TabbedContentAction.MyPreviousTabAction myPreviousTabAction;
ShowContentAction myShowContent;
ContentLayout myTabsLayout = new TabContentLayout(this);
ContentLayout myComboLayout = new ComboContentLayout(this);
@@ -62,6 +70,8 @@ public class ToolWindowContentUi extends JPanel implements ContentUI, PropertyCh
myContent.setFocusable(false);
setOpaque(false);
myShowContent = new ShowContentAction(myWindow, myContent);
setBorder(new EmptyBorder(0, 0, 0, 2));
}
@@ -269,6 +279,8 @@ public class ToolWindowContentUi extends JPanel implements ContentUI, PropertyCh
if (c instanceof BaseLabel) {
final Content content = ((BaseLabel)c).getContent();
if (content != null) {
contentGroup.add(ui.myShowContent);
contentGroup.addSeparator();
contentGroup.add(new TabbedContentAction.CloseAction(content));
contentGroup.add(ui.myCloseAllAction);
contentGroup.add(new TabbedContentAction.CloseAllButThisAction(content));
@@ -345,4 +357,34 @@ public class ToolWindowContentUi extends JPanel implements ContentUI, PropertyCh
boolean isCurrent(ContentLayout layout) {
return getCurrentLayout() == layout;
}
public void showContentPopup(InputEvent inputEvent) {
BaseListPopupStep step = new BaseListPopupStep<Content>(null, myManager.getContents()) {
@Override
public PopupStep onChosen(Content selectedValue, boolean finalChoice) {
myManager.setSelectedContent(selectedValue, true, true);
return FINAL_CHOICE;
}
@NotNull
@Override
public String getTextFor(Content value) {
return value.getDisplayName();
}
@Override
public Icon getIconFor(Content aValue) {
return aValue.getIcon();
}
@Override
public boolean isMnemonicsNavigationEnabled() {
return true;
}
};
step.setDefaultOptionIndex(Arrays.asList(myManager.getContents()).indexOf(myManager.getSelectedContent()));
getCurrentLayout().showContentPopup(JBPopupFactory.getInstance().createListPopup(step));
}
}
@@ -695,6 +695,8 @@ action.ToggleSideMode.text=Split Mode
action.ToggleSideMode.description=Tool windows split mode on/off
action.ToggleContentUiTypeMode.text=Tabbed Content
action.ToggleContentUiTypeMode.description=Toggle between tabbed/combo presentation of contents
action.ShowContent.text=Show Content
action.ShowContent.description=Show tool window content popup
action.NextTab.text=Select Ne_xt Tab
action.NextTab.description=Activate next tab
action.PreviousTab.text=Se_lect Previous Tab
@@ -518,6 +518,9 @@
<action id="NextTab">
<keyboard-shortcut first-keystroke="alt RIGHT"/>
</action>
<action id="ShowContent">
<keyboard-shortcut first-keystroke="alt DOWN"/>
</action>
<action id="NextEditorTab">
<keyboard-shortcut first-keystroke="alt shift RIGHT"/>
</action>
@@ -975,6 +978,9 @@
<action id="NextTab">
<keyboard-shortcut first-keystroke="control RIGHT"/>
</action>
<action id="ShowContent">
<keyboard-shortcut first-keystroke="control DOWN"/>
</action>
<action id="NextEditorTab">
<keyboard-shortcut first-keystroke="control shift RIGHT"/>
</action>
@@ -227,6 +227,7 @@
<action id="ToggleFloatingMode" class="com.intellij.ide.actions.ToggleFloatingModeAction"/>
<action id="ToggleSideMode" class="com.intellij.ide.actions.ToggleSideModeAction"/>
<action id="ToggleContentUiTypeMode" class="com.intellij.ide.actions.ToggleContentUiTypeAction"/>
<action id="ShowContent" class="com.intellij.ide.actions.ShowContentAction"/>
<separator/>
<action id="NextTab" class="com.intellij.ide.actions.NextTabAction"/>
<action id="PreviousTab" class="com.intellij.ide.actions.PreviousTabAction"/>