From 654463b436e456f9ca565ca35d03a31de784b20d Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Mon, 24 Mar 2014 22:22:06 +0400 Subject: [PATCH] use obsolete TW title property as Stripe button text --- .../ide/projectView/impl/ProjectViewImpl.java | 2 +- .../openapi/wm/ToolWindowContentUiType.java | 13 +- .../openapi/wm/impl/InternalDecorator.java | 115 +++--------------- .../openapi/wm/impl/StripeButton.java | 2 +- .../openapi/wm/impl/ToolWindowImpl.java | 10 +- .../wm/impl/ToolWindowManagerImpl.java | 23 ++-- .../wm/impl/content/ContentLayout.java | 2 +- 7 files changed, 46 insertions(+), 121 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java index 05f404f3a44f..71cb07258966 100644 --- a/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/projectView/impl/ProjectViewImpl.java @@ -568,7 +568,7 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo if (toolWindow != null) { myContentManager = toolWindow.getContentManager(); if (!ApplicationManager.getApplication().isUnitTestMode()) { - toolWindow.setContentUiType(ToolWindowContentUiType.getInstance("combo"), null); + toolWindow.setContentUiType(ToolWindowContentUiType.COMBO, null); ((ToolWindowEx)toolWindow).setAdditionalGearActions(myActionGroup); toolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true"); } diff --git a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContentUiType.java b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContentUiType.java index 8538729b5e86..9b09923df6e5 100644 --- a/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContentUiType.java +++ b/platform/platform-api/src/com/intellij/openapi/wm/ToolWindowContentUiType.java @@ -37,11 +37,20 @@ public class ToolWindowContentUiType { public static ToolWindowContentUiType getInstance(String name) { if (TABBED.getName().equals(name)) { return TABBED; - } else if (COMBO.getName().equals(name)) { + } + else if (COMBO.getName().equals(name)) { return COMBO; - } else { + } + else { LOG.debug("Unknown content type=" + name); return TABBED; } } + + @Override + public String toString() { + return "ToolWindowContentUiType{" + + "myName='" + myName + '\'' + + '}'; + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java index 1f073f97743c..e6c84f5e7768 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/InternalDecorator.java @@ -29,12 +29,12 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.*; -import com.intellij.openapi.wm.ex.ToolWindowEx; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; import com.intellij.ui.UIBundle; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.ui.content.Content; +import com.intellij.util.EventDispatcher; import com.intellij.util.Producer; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -44,11 +44,8 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; -import javax.swing.event.EventListenerList; import java.awt.*; import java.awt.event.*; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Map; /** @@ -63,7 +60,7 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa private WindowInfoImpl myInfo; private final ToolWindowImpl myToolWindow; private final MyDivider myDivider; - private final EventListenerList myListenerList; + private final EventDispatcher myDispatcher = EventDispatcher.create(InternalDecoratorListener.class); /* * Actions */ @@ -77,7 +74,6 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa /** * Catches all event from tool window and modifies decorator's appearance. */ - private final ToolWindowHandler myToolWindowHandler; private final MyKeymapManagerListener myWeakKeymapManagerListener; @NonNls private static final String HIDE_ACTIVE_WINDOW_ACTION_ID = "HideActiveWindow"; @NonNls public static final String TOGGLE_PINNED_MODE_ACTION_ID = "TogglePinnedMode"; @@ -101,8 +97,6 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa myToggleAutoHideModeAction = new TogglePinnedModeAction(); myToggleContentUiTypeAction = new ToggleContentUiTypeAction(); - myListenerList = new EventListenerList(); - myHeader = new ToolWindowHeader(toolWindow, info, new Producer() { @Override public ActionGroup produce() { @@ -137,9 +131,6 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa init(); - myToolWindowHandler = new ToolWindowHandler(); - myToolWindow.addPropertyChangeListener(myToolWindowHandler); - apply(info); } @@ -187,8 +178,6 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa validate(); repaint(); - // - updateTitle(); // Push "apply" request forward @@ -210,17 +199,16 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa } } - final void addInternalDecoratorListener(final InternalDecoratorListener l) { - myListenerList.add(InternalDecoratorListener.class, l); + final void addInternalDecoratorListener(InternalDecoratorListener l) { + myDispatcher.addListener(l); } - final void removeInternalDecoratorListener(final InternalDecoratorListener l) { - myListenerList.remove(InternalDecoratorListener.class, l); + final void removeInternalDecoratorListener(InternalDecoratorListener l) { + myDispatcher.removeListener(l); } final void dispose() { removeAll(); - myToolWindow.removePropertyChangeListener(myToolWindowHandler); KeymapManagerEx.getInstanceEx().removeWeakListener(myWeakKeymapManagerListener); Disposer.dispose(myHeader); @@ -228,76 +216,49 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa myProject = null; } - private void fireAnchorChanged(final ToolWindowAnchor anchor) { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.anchorChanged(this, anchor); - } + private void fireAnchorChanged(ToolWindowAnchor anchor) { + myDispatcher.getMulticaster().anchorChanged(this, anchor); } - private void fireAutoHideChanged(final boolean autoHide) { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.autoHideChanged(this, autoHide); - } + private void fireAutoHideChanged(boolean autoHide) { + myDispatcher.getMulticaster().autoHideChanged(this, autoHide); } /** * Fires event that "hide" button has been pressed. */ final void fireHidden() { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.hidden(this); - } + myDispatcher.getMulticaster().hidden(this); } /** * Fires event that "hide" button has been pressed. */ final void fireHiddenSide() { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.hiddenSide(this); - } + myDispatcher.getMulticaster().hiddenSide(this); } /** * Fires event that user performed click into the title bar area. */ final void fireActivated() { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.activated(this); - } + myDispatcher.getMulticaster().activated(this); } - private void fireTypeChanged(final ToolWindowType type) { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.typeChanged(this, type); - } + private void fireTypeChanged(ToolWindowType type) { + myDispatcher.getMulticaster().typeChanged(this, type); } final void fireResized() { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.resized(this); - } + myDispatcher.getMulticaster().resized(this); } private void fireSideStatusChanged(boolean isSide) { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.sideStatusChanged(this, isSide); - } + myDispatcher.getMulticaster().sideStatusChanged(this, isSide); } private void fireContentUiTypeChanges(ToolWindowContentUiType type) { - final InternalDecoratorListener[] listeners = myListenerList.getListeners(InternalDecoratorListener.class); - for (InternalDecoratorListener listener : listeners) { - listener.contentUiTypeChanges(this, type); - } + myDispatcher.getMulticaster().contentUiTypeChanges(this, type); } private void init() { @@ -515,30 +476,6 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa } } - // TODO: to b removed - private void updateTitle() { - final StringBuffer fullTitle = new StringBuffer(); - // Due to JDK's bug #4234645 we cannot support custom decoration on Linux platform. - // The prblem is that Window.setLocation() doesn't work properly wjen the dialod is displayable. - // Therefore we use native WM decoration. When the dialog has native decoration we show window ID - // in the dialog's title and window title at the custom title panel. If the custom decoration - // is used we show composite string at the custom title panel. - // TODO[vova] investigate the problem under Mac OSX. - if (SystemInfo.isWindows || !myInfo.isFloating()) { - fullTitle.append(myInfo.getId()); - final String title = myToolWindow.getTitle(); - if (title != null && title.length() > 0) { - fullTitle.append(" - ").append(title); - } - } - else { // Unixes ans MacOSX go here when tool window is in floating mode - final String title = myToolWindow.getTitle(); - if (title != null && title.length() > 0) { - fullTitle.append(title); - } - } - } - private final class ChangeAnchorAction extends AnAction implements DumbAware { private final ToolWindowAnchor myAnchor; @@ -816,22 +753,6 @@ public final class InternalDecorator extends JPanel implements Queryable, TypeSa } } - /** - * Synchronizes decorator with IdeToolWindow changes. - */ - private final class ToolWindowHandler implements PropertyChangeListener { - @Override - public final void propertyChange(final PropertyChangeEvent e) { - final String name = e.getPropertyName(); - if (ToolWindowEx.PROP_TITLE.equals(name)) { - updateTitle(); - if (myHeader != null) { - myHeader.repaint(); - } - } - } - } - @Override public void putInfo(@NotNull Map info) { info.put("toolWindowTitle", myToolWindow.getTitle()); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/StripeButton.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/StripeButton.java index 3c112eeef198..f9625958aec7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/StripeButton.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/StripeButton.java @@ -323,7 +323,7 @@ public final class StripeButton extends AnchoredButton implements ActionListener * and short cut registered in the key map. */ void updateText() { - final String toolWindowId = getWindowInfo().getId(); + String toolWindowId = myDecorator.getToolWindow().getTitle(); String text = toolWindowId; if (UISettings.getInstance().SHOW_TOOL_WINDOW_NUMBERS) { final int mnemonic = ActivateToolWindowAction.getMnemonicForToolWindow(toolWindowId); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java index ce09b94cc7fe..084b035ede5a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowImpl.java @@ -36,6 +36,7 @@ import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.impl.ContentImpl; +import com.intellij.util.ObjectUtils; import com.intellij.util.ui.update.Activatable; import com.intellij.util.ui.update.UiNotifyConnector; import org.jetbrains.annotations.NotNull; @@ -59,7 +60,8 @@ public final class ToolWindowImpl implements ToolWindowEx { private final JComponent myComponent; private boolean myAvailable; private final ContentManager myContentManager; - private Icon myIcon = null; + private Icon myIcon; + private String myTitle; private static final Content EMPTY_CONTENT = new ContentImpl(new JLabel(), "", false); private final ToolWindowContentUi myContentUI; @@ -342,7 +344,7 @@ public final class ToolWindowImpl implements ToolWindowEx { public final String getTitle() { ApplicationManager.getApplication().assertIsDispatchThread(); - return getSelectedContent().getDisplayName(); + return ObjectUtils.notNull(myTitle, myId); } public final void setIcon(final Icon icon) { @@ -356,10 +358,10 @@ public final class ToolWindowImpl implements ToolWindowEx { myChangeSupport.firePropertyChange(PROP_ICON, oldIcon, icon); } - public final void setTitle(final String title) { + public final void setTitle(String title) { ApplicationManager.getApplication().assertIsDispatchThread(); final String oldTitle = getTitle(); - getSelectedContent().setDisplayName(title); + myTitle = title; myChangeSupport.firePropertyChange(PROP_TITLE, oldTitle, title); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index 0c02fedc5cb6..9f35bddaac03 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -57,6 +57,7 @@ import com.intellij.ui.switcher.QuickAccessSettings; import com.intellij.ui.switcher.SwitchManager; import com.intellij.util.Alarm; import com.intellij.util.ArrayUtil; +import com.intellij.util.EventDispatcher; import com.intellij.util.IJSwingUtilities; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; @@ -69,7 +70,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import javax.swing.event.EventListenerList; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import java.awt.*; @@ -89,7 +89,7 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements private final Project myProject; private final WindowManagerEx myWindowManager; - private final EventListenerList myListenerList; + private final EventDispatcher myDispatcher = EventDispatcher.create(ToolWindowManagerListener.class); private final DesktopLayout myLayout; private final Map myId2InternalDecorator; private final Map myId2FloatingDecorator; @@ -163,7 +163,6 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements myWindowManager = windowManagerEx; myFileEditorManager = fem; myLafManager = lafManager; - myListenerList = new EventListenerList(); if (!project.isDefault()) { actionManager.addAnActionListener(new AnActionListener() { @@ -570,13 +569,13 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } @Override - public void addToolWindowManagerListener(@NotNull final ToolWindowManagerListener l) { - myListenerList.add(ToolWindowManagerListener.class, l); + public void addToolWindowManagerListener(@NotNull ToolWindowManagerListener l) { + myDispatcher.addListener(l); } @Override - public void removeToolWindowManagerListener(@NotNull final ToolWindowManagerListener l) { - myListenerList.remove(ToolWindowManagerListener.class, l); + public void removeToolWindowManagerListener(@NotNull ToolWindowManagerListener l) { + myDispatcher.addListener(l); } /** @@ -1662,17 +1661,11 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } private void fireToolWindowRegistered(final String id) { - final ToolWindowManagerListener[] listeners = myListenerList.getListeners(ToolWindowManagerListener.class); - for (ToolWindowManagerListener listener : listeners) { - listener.toolWindowRegistered(id); - } + myDispatcher.getMulticaster().toolWindowRegistered(id); } private void fireStateChanged() { - final ToolWindowManagerListener[] listeners = myListenerList.getListeners(ToolWindowManagerListener.class); - for (ToolWindowManagerListener listener : listeners) { - listener.stateChanged(); - } + myDispatcher.getMulticaster().stateChanged(); } boolean isToolWindowActive(final String id) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java index 96ea3f06b5c4..fb606e577402 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/ContentLayout.java @@ -71,7 +71,7 @@ abstract class ContentLayout { public abstract boolean shouldDrawDecorations(); protected void updateIdLabel(BaseLabel label) { - label.setText(myUi.myWindow.getId() + (shouldDrawDecorations() ? ":" : "")); + label.setText(myUi.myWindow.getTitle() + (shouldDrawDecorations() ? ":" : "")); label.setBorder(new EmptyBorder(0, 2, 0, 8)); if (myUi.myManager.getContentCount() == 1) {