mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
IDEA-106210
This commit is contained in:
@@ -17,10 +17,9 @@ package com.intellij.designer;
|
||||
|
||||
import com.intellij.designer.designSurface.DesignerEditorPanel;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
@@ -31,7 +30,9 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowEx;
|
||||
import com.intellij.util.ParameterizedRunnable;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
@@ -53,7 +54,10 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
private volatile boolean myToolWindowReady;
|
||||
private volatile boolean myToolWindowDisposed;
|
||||
|
||||
protected final PropertiesComponent myPropertiesComponent;
|
||||
private final PropertiesComponent myPropertiesComponent;
|
||||
public final String myEditorModeKey;
|
||||
private ToggleEditorModeAction myLeftEditorModeAction;
|
||||
private ToggleEditorModeAction myRightEditorModeAction;
|
||||
|
||||
private MessageBusConnection myConnection;
|
||||
private final FileEditorManagerListener myListener = new FileEditorManagerListener() {
|
||||
@@ -88,6 +92,7 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
myProject = project;
|
||||
myFileEditorManager = fileEditorManager;
|
||||
myPropertiesComponent = PropertiesComponent.getInstance(myProject);
|
||||
myEditorModeKey = EDITOR_MODE + getComponentName() + ".STATE";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,7 +102,7 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
StartupManager.getInstance(myProject).registerPostStartupActivity(new Runnable() {
|
||||
public void run() {
|
||||
myToolWindowReady = true;
|
||||
if (!isEditorMode()) {
|
||||
if (getEditorMode() == null) {
|
||||
initListeners();
|
||||
bindToDesigner(getActiveDesigner());
|
||||
}
|
||||
@@ -174,21 +179,12 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
protected abstract void updateToolWindow(@Nullable DesignerEditorPanel designer);
|
||||
|
||||
protected final void initGearActions() {
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
group.add(new ToggleAction("In Editor Mode", "Pin/unpin tool window to Designer Editor", null) {
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
setEditorMode(true);
|
||||
}
|
||||
});
|
||||
((ToolWindowEx)myToolWindow).setAdditionalGearActions(group);
|
||||
ToolWindowEx toolWindow = (ToolWindowEx)myToolWindow;
|
||||
toolWindow.setAdditionalGearActions(new DefaultActionGroup(createGearActions()));
|
||||
}
|
||||
|
||||
protected abstract ToolWindowAnchor getAnchor();
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
}
|
||||
@@ -203,9 +199,25 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public final ActionGroup createGearActions() {
|
||||
DefaultActionGroup group = new DefaultActionGroup("In Editor Mode", true);
|
||||
|
||||
if (myLeftEditorModeAction == null) {
|
||||
myLeftEditorModeAction = new ToggleEditorModeAction(this, myProject, ToolWindowAnchor.LEFT);
|
||||
}
|
||||
group.add(myLeftEditorModeAction);
|
||||
|
||||
if (myRightEditorModeAction == null) {
|
||||
myRightEditorModeAction = new ToggleEditorModeAction(this, myProject, ToolWindowAnchor.RIGHT);
|
||||
}
|
||||
group.add(myRightEditorModeAction);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
public final void bind(DesignerEditorPanel designer) {
|
||||
if (isEditorMode()) {
|
||||
updateContent(designer, true);
|
||||
myCreateAction.run(designer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,15 +232,6 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
return toolWindow.getContent();
|
||||
}
|
||||
|
||||
protected final void updateContent(DesignerEditorPanel designer, boolean bindToEditor) {
|
||||
if (bindToEditor) {
|
||||
designer.putClientProperty(getComponentName(), createContent(designer));
|
||||
}
|
||||
else {
|
||||
disposeContent(designer);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract LightToolWindow createContent(DesignerEditorPanel designer);
|
||||
|
||||
protected final LightToolWindow createContent(DesignerEditorPanel designer,
|
||||
@@ -237,7 +240,6 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
Icon icon,
|
||||
JComponent component,
|
||||
JComponent focusedComponent,
|
||||
int style,
|
||||
int defaultWidth,
|
||||
AnAction[] actions) {
|
||||
return new LightToolWindow(content,
|
||||
@@ -246,7 +248,7 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
component,
|
||||
focusedComponent,
|
||||
designer.getContentSplitter(),
|
||||
style,
|
||||
getEditorMode(),
|
||||
this,
|
||||
myProject,
|
||||
myPropertiesComponent,
|
||||
@@ -262,31 +264,67 @@ public abstract class AbstractToolWindowManager implements ProjectComponent {
|
||||
toolWindow.dispose();
|
||||
}
|
||||
|
||||
private void updateContent(boolean bindToEditor) {
|
||||
private final ParameterizedRunnable<DesignerEditorPanel> myCreateAction = new ParameterizedRunnable<DesignerEditorPanel>() {
|
||||
@Override
|
||||
public void run(DesignerEditorPanel designer) {
|
||||
designer.putClientProperty(getComponentName(), createContent(designer));
|
||||
}
|
||||
};
|
||||
|
||||
private final ParameterizedRunnable<DesignerEditorPanel> myUpdateAnchorAction = new ParameterizedRunnable<DesignerEditorPanel>() {
|
||||
@Override
|
||||
public void run(DesignerEditorPanel designer) {
|
||||
LightToolWindow toolWindow = (LightToolWindow)designer.getClientProperty(getComponentName());
|
||||
toolWindow.updateAnchor(getEditorMode());
|
||||
}
|
||||
};
|
||||
|
||||
private final ParameterizedRunnable<DesignerEditorPanel> myDisposeAction = new ParameterizedRunnable<DesignerEditorPanel>() {
|
||||
@Override
|
||||
public void run(DesignerEditorPanel designer) {
|
||||
disposeContent(designer);
|
||||
}
|
||||
};
|
||||
|
||||
private void runUpdateContent(ParameterizedRunnable<DesignerEditorPanel> action) {
|
||||
for (FileEditor editor : myFileEditorManager.getAllEditors()) {
|
||||
DesignerEditorPanel designer = getDesigner(editor);
|
||||
if (designer != null) {
|
||||
updateContent(designer, bindToEditor);
|
||||
action.run(designer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isEditorMode() {
|
||||
return myPropertiesComponent.getBoolean(EDITOR_MODE + getComponentName(), true);
|
||||
protected final boolean isEditorMode() {
|
||||
return getEditorMode() != null;
|
||||
}
|
||||
|
||||
public final void setEditorMode(boolean value) {
|
||||
if (value) {
|
||||
@Nullable
|
||||
final ToolWindowAnchor getEditorMode() {
|
||||
String value = myPropertiesComponent.getValue(myEditorModeKey);
|
||||
if (value == null) {
|
||||
return getAnchor();
|
||||
}
|
||||
return value.equals("ToolWindow") ? null : ToolWindowAnchor.fromText(value);
|
||||
}
|
||||
|
||||
final void setEditorMode(@Nullable ToolWindowAnchor newState) {
|
||||
ToolWindowAnchor oldState = getEditorMode();
|
||||
myPropertiesComponent.setValue(myEditorModeKey, newState == null ? "ToolWindow" : newState.toString());
|
||||
|
||||
if (oldState != null && newState != null) {
|
||||
runUpdateContent(myUpdateAnchorAction);
|
||||
}
|
||||
else if (newState != null) {
|
||||
removeListeners();
|
||||
updateToolWindow(null);
|
||||
updateContent(true);
|
||||
runUpdateContent(myCreateAction);
|
||||
}
|
||||
else {
|
||||
updateContent(false);
|
||||
runUpdateContent(myDisposeAction);
|
||||
initListeners();
|
||||
bindToDesigner(getActiveDesigner());
|
||||
}
|
||||
myPropertiesComponent.setValue(EDITOR_MODE + getComponentName(), Boolean.toString(value));
|
||||
}
|
||||
|
||||
final ToolWindow getToolWindow() {
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowEx;
|
||||
import com.intellij.openapi.wm.impl.content.ToolWindowContentUi;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import icons.UIDesignerNewIcons;
|
||||
@@ -66,35 +65,6 @@ public final class DesignerToolWindowManager extends AbstractToolWindowManager {
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected LightToolWindow createContent(DesignerEditorPanel designer) {
|
||||
DesignerToolWindow toolWindowContent = new DesignerToolWindow(myProject, false);
|
||||
toolWindowContent.update(designer);
|
||||
|
||||
return createContent(designer,
|
||||
toolWindowContent,
|
||||
DesignerBundle.message("designer.toolwindow.title"),
|
||||
UIDesignerNewIcons.ToolWindow,
|
||||
toolWindowContent.getToolWindowPanel(),
|
||||
toolWindowContent.getComponentTree(),
|
||||
getAnchor() == ToolWindowAnchor.LEFT ? SideBorder.LEFT : SideBorder.RIGHT,
|
||||
320,
|
||||
toolWindowContent.createActions());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateToolWindow(@Nullable DesignerEditorPanel designer) {
|
||||
myToolWindowContent.update(designer);
|
||||
|
||||
if (designer == null) {
|
||||
myToolWindow.setAvailable(false, null);
|
||||
}
|
||||
else {
|
||||
myToolWindow.setAvailable(true, null);
|
||||
myToolWindow.show(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initToolWindow() {
|
||||
myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(DesignerBundle.message("designer.toolwindow.name"),
|
||||
@@ -119,11 +89,25 @@ public final class DesignerToolWindowManager extends AbstractToolWindowManager {
|
||||
myToolWindow.setAvailable(false, null);
|
||||
}
|
||||
|
||||
private static ToolWindowAnchor getAnchor() {
|
||||
@Override
|
||||
protected ToolWindowAnchor getAnchor() {
|
||||
DesignerCustomizations customization = getCustomizations();
|
||||
return customization != null ? customization.getStructureAnchor() : ToolWindowAnchor.LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateToolWindow(@Nullable DesignerEditorPanel designer) {
|
||||
myToolWindowContent.update(designer);
|
||||
|
||||
if (designer == null) {
|
||||
myToolWindow.setAvailable(false, null);
|
||||
}
|
||||
else {
|
||||
myToolWindow.setAvailable(true, null);
|
||||
myToolWindow.show(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disposeComponent() {
|
||||
myToolWindowContent.dispose();
|
||||
@@ -134,4 +118,25 @@ public final class DesignerToolWindowManager extends AbstractToolWindowManager {
|
||||
public String getComponentName() {
|
||||
return "UIDesignerToolWindowManager2";
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Impl
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected LightToolWindow createContent(DesignerEditorPanel designer) {
|
||||
DesignerToolWindow toolWindowContent = new DesignerToolWindow(myProject, false);
|
||||
toolWindowContent.update(designer);
|
||||
|
||||
return createContent(designer,
|
||||
toolWindowContent,
|
||||
DesignerBundle.message("designer.toolwindow.title"),
|
||||
UIDesignerNewIcons.ToolWindow,
|
||||
toolWindowContent.getToolWindowPanel(),
|
||||
toolWindowContent.getComponentTree(),
|
||||
320,
|
||||
toolWindowContent.createActions());
|
||||
}
|
||||
}
|
||||
@@ -44,13 +44,17 @@ import java.awt.image.BufferedImage;
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class LightToolWindow extends JPanel {
|
||||
public static final String LEFT_MIN_KEY = "left";
|
||||
public static final String RIGHT_MIN_KEY = "right";
|
||||
private static final String IGNORE_WIDTH_KEY = "ignore_width";
|
||||
|
||||
private final LightToolWindowContent myContent;
|
||||
private final JComponent myFocusedComponent;
|
||||
private final ThreeComponentsSplitter myContentSplitter;
|
||||
private ToolWindowAnchor myAnchor;
|
||||
private final Project myProject;
|
||||
private final AbstractToolWindowManager myManager;
|
||||
private final PropertiesComponent myPropertiesComponent;
|
||||
private final int myStyle;
|
||||
private boolean myShowContent;
|
||||
private final String myShowStateKey;
|
||||
private int myCurrentWidth;
|
||||
@@ -58,7 +62,6 @@ public class LightToolWindow extends JPanel {
|
||||
private final JPanel myMinimizeComponent;
|
||||
private final AnchoredButton myMinimizeButton;
|
||||
|
||||
private final ToggleInEditorModeAction myToggleInEditorModeAction = new ToggleInEditorModeAction();
|
||||
private final TogglePinnedModeAction myToggleAutoHideModeAction = new TogglePinnedModeAction();
|
||||
private final ToggleDockModeAction myToggleDockModeAction = new ToggleDockModeAction();
|
||||
private final ToggleFloatingModeAction myToggleFloatingModeAction = new ToggleFloatingModeAction();
|
||||
@@ -67,8 +70,9 @@ public class LightToolWindow extends JPanel {
|
||||
private final ComponentListener myWidthListener = new ComponentAdapter() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
int width = myStyle == SideBorder.LEFT ? myContentSplitter.getFirstSize() : myContentSplitter.getLastSize();
|
||||
if (width > 0 && width != myCurrentWidth) {
|
||||
int width = isLeft() ? myContentSplitter.getFirstSize() : myContentSplitter.getLastSize();
|
||||
if (width > 0 && width != myCurrentWidth && myContentSplitter.getInnerComponent().getClientProperty(IGNORE_WIDTH_KEY) == null) {
|
||||
myCurrentWidth = width;
|
||||
myPropertiesComponent.setValue(myWidthKey, Integer.toString(width));
|
||||
}
|
||||
}
|
||||
@@ -80,7 +84,7 @@ public class LightToolWindow extends JPanel {
|
||||
JComponent component,
|
||||
JComponent focusedComponent,
|
||||
ThreeComponentsSplitter contentSplitter,
|
||||
int style,
|
||||
ToolWindowAnchor anchor,
|
||||
AbstractToolWindowManager manager,
|
||||
Project project,
|
||||
PropertiesComponent propertiesComponent,
|
||||
@@ -91,12 +95,11 @@ public class LightToolWindow extends JPanel {
|
||||
myContent = content;
|
||||
myFocusedComponent = focusedComponent;
|
||||
myContentSplitter = contentSplitter;
|
||||
myAnchor = anchor;
|
||||
myProject = project;
|
||||
myManager = manager;
|
||||
myPropertiesComponent = propertiesComponent;
|
||||
setBorder(IdeBorderFactory.createBorder((style == SideBorder.LEFT ? SideBorder.RIGHT : SideBorder.LEFT) | SideBorder.BOTTOM));
|
||||
|
||||
myStyle = style;
|
||||
myShowStateKey = AbstractToolWindowManager.EDITOR_MODE + key + ".SHOW";
|
||||
myWidthKey = AbstractToolWindowManager.EDITOR_MODE + key + ".WIDTH";
|
||||
|
||||
@@ -157,7 +160,7 @@ public class LightToolWindow extends JPanel {
|
||||
|
||||
@Override
|
||||
public ToolWindowAnchor getAnchor() {
|
||||
return myStyle == SideBorder.LEFT ? ToolWindowAnchor.LEFT : ToolWindowAnchor.RIGHT;
|
||||
return myAnchor;
|
||||
}
|
||||
};
|
||||
myMinimizeButton.addActionListener(new ActionListener() {
|
||||
@@ -180,30 +183,68 @@ public class LightToolWindow extends JPanel {
|
||||
myMinimizeButton.setBounds(0, 0, getWidth(), size.height);
|
||||
}
|
||||
};
|
||||
myMinimizeComponent.setBorder(IdeBorderFactory.createBorder(style == SideBorder.LEFT ? SideBorder.RIGHT : SideBorder.LEFT));
|
||||
myMinimizeComponent.add(myMinimizeButton);
|
||||
|
||||
configureBorder();
|
||||
configureWidth(defaultWidth);
|
||||
updateContent(myPropertiesComponent.getBoolean(myShowStateKey, true), false);
|
||||
}
|
||||
|
||||
private void configureBorder() {
|
||||
int borderStyle = isLeft() ? SideBorder.RIGHT : SideBorder.LEFT;
|
||||
setBorder(IdeBorderFactory.createBorder(borderStyle | SideBorder.BOTTOM));
|
||||
myMinimizeComponent.setBorder(IdeBorderFactory.createBorder(borderStyle));
|
||||
}
|
||||
|
||||
private void configureWidth(int defaultWidth) {
|
||||
myCurrentWidth = myPropertiesComponent.getOrInitInt(myWidthKey, defaultWidth);
|
||||
updateWidth();
|
||||
myContentSplitter.getInnerComponent().addComponentListener(myWidthListener);
|
||||
}
|
||||
|
||||
if (myStyle == SideBorder.LEFT) {
|
||||
private void updateWidth() {
|
||||
if (isLeft()) {
|
||||
myContentSplitter.setFirstSize(myCurrentWidth);
|
||||
}
|
||||
else {
|
||||
myContentSplitter.setLastSize(myCurrentWidth);
|
||||
}
|
||||
}
|
||||
|
||||
myContentSplitter.getInnerComponent().addComponentListener(myWidthListener);
|
||||
public void updateAnchor(ToolWindowAnchor newAnchor) {
|
||||
JComponent minimizeParent = myContentSplitter.getInnerComponent();
|
||||
minimizeParent.putClientProperty(IGNORE_WIDTH_KEY, Boolean.TRUE);
|
||||
|
||||
if (myShowContent) {
|
||||
Object oldWindow = isLeft() ? myContentSplitter.getFirstComponent() : myContentSplitter.getLastComponent();
|
||||
if (oldWindow == this) {
|
||||
setContentComponent(null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
String key = getMinKey();
|
||||
if (minimizeParent.getClientProperty(key) == myMinimizeComponent) {
|
||||
minimizeParent.putClientProperty(key, null);
|
||||
}
|
||||
minimizeParent.putClientProperty(isLeft() ? RIGHT_MIN_KEY : LEFT_MIN_KEY, myMinimizeComponent);
|
||||
minimizeParent.revalidate();
|
||||
}
|
||||
|
||||
myAnchor = newAnchor;
|
||||
configureBorder();
|
||||
updateWidth();
|
||||
|
||||
if (myShowContent) {
|
||||
setContentComponent(this);
|
||||
}
|
||||
|
||||
minimizeParent.putClientProperty(IGNORE_WIDTH_KEY, null);
|
||||
}
|
||||
|
||||
private void updateContent(boolean show, boolean flag) {
|
||||
myShowContent = show;
|
||||
|
||||
String key = myStyle == SideBorder.LEFT ? "left" : "right";
|
||||
String key = getMinKey();
|
||||
|
||||
JComponent minimizeParent = myContentSplitter.getInnerComponent();
|
||||
|
||||
@@ -227,7 +268,7 @@ public class LightToolWindow extends JPanel {
|
||||
}
|
||||
|
||||
private void setContentComponent(JComponent component) {
|
||||
if (myStyle == SideBorder.LEFT) {
|
||||
if (isLeft()) {
|
||||
myContentSplitter.setFirstComponent(component);
|
||||
}
|
||||
else {
|
||||
@@ -243,16 +284,24 @@ public class LightToolWindow extends JPanel {
|
||||
myContent.dispose();
|
||||
|
||||
if (!myShowContent) {
|
||||
minimizeParent.putClientProperty(myStyle == SideBorder.LEFT ? "left" : "right", null);
|
||||
minimizeParent.putClientProperty(getMinKey(), null);
|
||||
minimizeParent.remove(myMinimizeComponent);
|
||||
minimizeParent.revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private String getMinKey() {
|
||||
return isLeft() ? LEFT_MIN_KEY : RIGHT_MIN_KEY;
|
||||
}
|
||||
|
||||
public Object getContent() {
|
||||
return myContent;
|
||||
}
|
||||
|
||||
private boolean isLeft() {
|
||||
return myAnchor == ToolWindowAnchor.LEFT;
|
||||
}
|
||||
|
||||
private boolean isActive() {
|
||||
IdeFocusManager fm = IdeFocusManager.getInstance(myProject);
|
||||
Component component = fm.getFocusedDescendantFor(this);
|
||||
@@ -270,7 +319,7 @@ public class LightToolWindow extends JPanel {
|
||||
private DefaultActionGroup createGearPopupGroup() {
|
||||
DefaultActionGroup group = new DefaultActionGroup();
|
||||
|
||||
group.add(myToggleInEditorModeAction);
|
||||
group.add(myManager.createGearActions());
|
||||
group.addSeparator();
|
||||
|
||||
ToolWindowType type = myManager.getToolWindow().getType();
|
||||
@@ -324,7 +373,7 @@ public class LightToolWindow extends JPanel {
|
||||
public HideAction() {
|
||||
Presentation presentation = getTemplatePresentation();
|
||||
presentation.setText(UIBundle.message("tool.window.hide.action.name"));
|
||||
if (myStyle == SideBorder.LEFT) {
|
||||
if (isLeft()) {
|
||||
presentation.setIcon(AllIcons.General.HideLeftPart);
|
||||
presentation.setHoveredIcon(AllIcons.General.HideLeftPartHover);
|
||||
}
|
||||
@@ -340,22 +389,6 @@ public class LightToolWindow extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private class ToggleInEditorModeAction extends ToggleAction {
|
||||
public ToggleInEditorModeAction() {
|
||||
super("In Editor Mode", "Pin/unpin tool window to Designer Editor", null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
myManager.setEditorMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
private class TogglePinnedModeAction extends ToggleAction {
|
||||
public TogglePinnedModeAction() {
|
||||
copyFrom(ActionManager.getInstance().getAction(InternalDecorator.TOGGLE_PINNED_MODE_ACTION_ID));
|
||||
@@ -370,7 +403,7 @@ public class LightToolWindow extends JPanel {
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
ToolWindow window = myManager.getToolWindow();
|
||||
window.setAutoHide(!window.isAutoHide());
|
||||
myManager.setEditorMode(false);
|
||||
myManager.setEditorMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +427,7 @@ public class LightToolWindow extends JPanel {
|
||||
else if (type == ToolWindowType.SLIDING) {
|
||||
window.setType(ToolWindowType.DOCKED, null);
|
||||
}
|
||||
myManager.setEditorMode(false);
|
||||
myManager.setEditorMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -418,7 +451,7 @@ public class LightToolWindow extends JPanel {
|
||||
else {
|
||||
window.setType(ToolWindowType.FLOATING, null);
|
||||
}
|
||||
myManager.setEditorMode(false);
|
||||
myManager.setEditorMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,7 +468,7 @@ public class LightToolWindow extends JPanel {
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
myManager.getToolWindow().setSplitMode(state, null);
|
||||
myManager.setEditorMode(false);
|
||||
myManager.setEditorMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.designer;
|
||||
|
||||
import com.intellij.designer.palette.PaletteToolWindowManager;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.ToggleAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
|
||||
/**
|
||||
* @author Alexander Lobas
|
||||
*/
|
||||
public class ToggleEditorModeAction extends ToggleAction {
|
||||
private final AbstractToolWindowManager myManager;
|
||||
private final Project myProject;
|
||||
private final ToolWindowAnchor myAnchor;
|
||||
|
||||
public ToggleEditorModeAction(AbstractToolWindowManager manager, Project project, ToolWindowAnchor anchor) {
|
||||
super(StringUtil.capitalize(anchor.toString()), "Pin/unpin tool window to " + anchor + " side UI Designer Editor", null);
|
||||
myManager = manager;
|
||||
myProject = project;
|
||||
myAnchor = anchor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(AnActionEvent e) {
|
||||
return myAnchor == myManager.getEditorMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
if (state) {
|
||||
myManager.setEditorMode(myAnchor);
|
||||
|
||||
AbstractToolWindowManager manager = getOppositeManager();
|
||||
if (manager.getEditorMode() == myAnchor) {
|
||||
manager.setEditorMode(myAnchor == ToolWindowAnchor.LEFT ? ToolWindowAnchor.RIGHT : ToolWindowAnchor.LEFT);
|
||||
}
|
||||
}
|
||||
else {
|
||||
myManager.setEditorMode(null);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractToolWindowManager getOppositeManager() {
|
||||
AbstractToolWindowManager designerManager = DesignerToolWindowManager.getInstance(myProject);
|
||||
AbstractToolWindowManager paletteManager = PaletteToolWindowManager.getInstance(myProject);
|
||||
return myManager == designerManager ? paletteManager : designerManager;
|
||||
}
|
||||
}
|
||||
@@ -849,10 +849,10 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
|
||||
Dimension contentSize = parent.getComponent(1).getPreferredSize();
|
||||
int extraWidth = 0;
|
||||
JComponent jParent = (JComponent)parent;
|
||||
if (jParent.getClientProperty("left") != null) {
|
||||
if (jParent.getClientProperty(LightToolWindow.LEFT_MIN_KEY) != null) {
|
||||
extraWidth += MINIMIZE_WIDTH;
|
||||
}
|
||||
if (jParent.getClientProperty("right") != null) {
|
||||
if (jParent.getClientProperty(LightToolWindow.RIGHT_MIN_KEY) != null) {
|
||||
extraWidth += MINIMIZE_WIDTH;
|
||||
}
|
||||
return new Dimension(Math.max(toolbarSize.width, contentSize.width + extraWidth), toolbarSize.height + contentSize.height);
|
||||
@@ -865,10 +865,10 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
|
||||
Dimension contentSize = parent.getComponent(1).getMinimumSize();
|
||||
int extraWidth = 0;
|
||||
JComponent jParent = (JComponent)parent;
|
||||
if (jParent.getClientProperty("left") != null) {
|
||||
if (jParent.getClientProperty(LightToolWindow.LEFT_MIN_KEY) != null) {
|
||||
extraWidth += MINIMIZE_WIDTH;
|
||||
}
|
||||
if (jParent.getClientProperty("right") != null) {
|
||||
if (jParent.getClientProperty(LightToolWindow.RIGHT_MIN_KEY) != null) {
|
||||
extraWidth += MINIMIZE_WIDTH;
|
||||
}
|
||||
return new Dimension(Math.max(toolbarSize.width, contentSize.width + extraWidth), toolbarSize.height + contentSize.height);
|
||||
@@ -879,11 +879,11 @@ public abstract class DesignerEditorPanel extends JPanel implements DataProvider
|
||||
int leftWidth = 0;
|
||||
int rightWidth = 0;
|
||||
JComponent jParent = (JComponent)parent;
|
||||
JComponent left = (JComponent)jParent.getClientProperty("left");
|
||||
JComponent left = (JComponent)jParent.getClientProperty(LightToolWindow.LEFT_MIN_KEY);
|
||||
if (left != null) {
|
||||
leftWidth = MINIMIZE_WIDTH;
|
||||
}
|
||||
JComponent right = (JComponent)jParent.getClientProperty("right");
|
||||
JComponent right = (JComponent)jParent.getClientProperty(LightToolWindow.RIGHT_MIN_KEY);
|
||||
if (right != null) {
|
||||
rightWidth = MINIMIZE_WIDTH;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.ui.SideBorder;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -64,22 +63,6 @@ public class PaletteToolWindowManager extends AbstractToolWindowManager {
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected LightToolWindow createContent(DesignerEditorPanel designer) {
|
||||
PalettePanel palettePanel = new PalettePanel();
|
||||
palettePanel.loadPalette(designer);
|
||||
|
||||
return createContent(designer,
|
||||
palettePanel,
|
||||
"Palette",
|
||||
AllIcons.Toolwindows.ToolWindowPalette,
|
||||
palettePanel,
|
||||
palettePanel,
|
||||
getAnchor() == ToolWindowAnchor.LEFT ? SideBorder.LEFT : SideBorder.RIGHT,
|
||||
180,
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initToolWindow() {
|
||||
myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow("Palette\t", false, getAnchor(), myProject, true);
|
||||
@@ -95,7 +78,8 @@ public class PaletteToolWindowManager extends AbstractToolWindowManager {
|
||||
myToolWindow.setAvailable(false, null);
|
||||
}
|
||||
|
||||
private static ToolWindowAnchor getAnchor() {
|
||||
@Override
|
||||
protected ToolWindowAnchor getAnchor() {
|
||||
DesignerCustomizations customization = getCustomizations();
|
||||
return customization != null ? customization.getPaletteAnchor() : ToolWindowAnchor.RIGHT;
|
||||
}
|
||||
@@ -123,4 +107,25 @@ public class PaletteToolWindowManager extends AbstractToolWindowManager {
|
||||
public String getComponentName() {
|
||||
return "PaletteToolWindowManager";
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Impl
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
protected LightToolWindow createContent(DesignerEditorPanel designer) {
|
||||
PalettePanel palettePanel = new PalettePanel();
|
||||
palettePanel.loadPalette(designer);
|
||||
|
||||
return createContent(designer,
|
||||
palettePanel,
|
||||
"Palette",
|
||||
AllIcons.Toolwindows.ToolWindowPalette,
|
||||
palettePanel,
|
||||
palettePanel,
|
||||
180,
|
||||
null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user