mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
lazy toolwindow content manager creation - part 5
GitOrigin-RevId: 87b8f8883ba739791e0f42777ab0c740335923aa
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6e5ce9cb5c
commit
a87ed3eeeb
@@ -29,7 +29,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
private final int myAnchor;
|
||||
private final ArrayList<StripeButton> buttons = new ArrayList<>();
|
||||
|
||||
private Dimension prefferedSize;
|
||||
private Dimension preferredSize;
|
||||
private StripeButton myDragButton;
|
||||
private Rectangle myDropRectangle;
|
||||
private JComponent myDragButtonImage;
|
||||
@@ -123,7 +123,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
}
|
||||
|
||||
void addButton(@NotNull StripeButton button, @NotNull Comparator<? super StripeButton> comparator) {
|
||||
prefferedSize = null;
|
||||
preferredSize = null;
|
||||
buttons.add(button);
|
||||
buttons.sort(comparator);
|
||||
add(button);
|
||||
@@ -131,7 +131,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
}
|
||||
|
||||
void removeButton(@NotNull StripeButton button) {
|
||||
prefferedSize = null;
|
||||
preferredSize = null;
|
||||
buttons.remove(button);
|
||||
remove(button);
|
||||
revalidate();
|
||||
@@ -139,7 +139,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
prefferedSize = null;
|
||||
preferredSize = null;
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@@ -416,11 +416,10 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
if (prefferedSize == null) {
|
||||
prefferedSize = recomputeBounds(false, null, false).size;
|
||||
if (preferredSize == null) {
|
||||
preferredSize = recomputeBounds(false, null, false).size;
|
||||
}
|
||||
|
||||
return prefferedSize;
|
||||
return preferredSize;
|
||||
}
|
||||
|
||||
void updatePresentation() {
|
||||
@@ -456,7 +455,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
myDragButton = null;
|
||||
myDragButtonImage = null;
|
||||
myFinishingDrop = false;
|
||||
prefferedSize = null;
|
||||
preferredSize = null;
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
@@ -467,7 +466,7 @@ final class Stripe extends JPanel implements UISettingsListener {
|
||||
buttonImage.paint(image.getGraphics());
|
||||
myDragButton = button;
|
||||
myDragButtonImage = buttonImage;
|
||||
prefferedSize = null;
|
||||
preferredSize = null;
|
||||
}
|
||||
|
||||
Point point = new Point(screenPoint);
|
||||
|
||||
@@ -45,15 +45,14 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
private KeyEventDispatcher myDragKeyEventDispatcher;
|
||||
private boolean myDragCancelled = false;
|
||||
|
||||
StripeButton(@NotNull ToolWindowsPane pane, @NotNull WindowInfo info, @NotNull ToolWindowImpl toolWindow) {
|
||||
StripeButton(@NotNull ToolWindowsPane pane, @NotNull ToolWindowImpl toolWindow) {
|
||||
myPane = pane;
|
||||
this.toolWindow = toolWindow;
|
||||
|
||||
setFocusable(false);
|
||||
|
||||
setBorder(JBUI.Borders.empty(5, 5, 0, 5));
|
||||
updatePresentation();
|
||||
apply(info);
|
||||
|
||||
addActionListener(this);
|
||||
addMouseListener(new PopupHandler() {
|
||||
@Override
|
||||
@@ -74,6 +73,14 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
});
|
||||
}
|
||||
|
||||
void init(@NotNull ToolWindowImpl toolWindow, @NotNull WindowInfo info) {
|
||||
updateState(toolWindow);
|
||||
updateText(toolWindow);
|
||||
updateIcon(toolWindow.getIcon());
|
||||
|
||||
apply(info);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WindowInfo getWindowInfo() {
|
||||
return windowInfo;
|
||||
@@ -102,11 +109,11 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
* doesn't work via standard Swing rules (processing of Alt keystrokes).
|
||||
*/
|
||||
@Override
|
||||
public void setMnemonic(final int mnemonic) {
|
||||
public void setMnemonic(int mnemonic) {
|
||||
throw new UnsupportedOperationException("use setMnemonic2(int)");
|
||||
}
|
||||
|
||||
private void setMnemonic2(final int mnemonic) {
|
||||
private void setMnemonic2(int mnemonic) {
|
||||
myMnemonic = mnemonic;
|
||||
revalidate();
|
||||
repaint();
|
||||
@@ -284,9 +291,10 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
public void actionPerformed(@NotNull ActionEvent e) {
|
||||
String id = toolWindow.getId();
|
||||
if (myPressedWhenSelected) {
|
||||
toolWindow.getToolWindowManager().hideToolWindow(toolWindow.getId(), false);
|
||||
toolWindow.getToolWindowManager().hideToolWindow(id, false);
|
||||
}
|
||||
else {
|
||||
toolWindow.getToolWindowManager().activated(toolWindow);
|
||||
@@ -294,14 +302,14 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
|
||||
myPressedWhenSelected = false;
|
||||
//noinspection SpellCheckingInspection
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("toolwindow.clickstat." + getId());
|
||||
FeatureUsageTracker.getInstance().triggerFeatureUsed("toolwindow.clickstat." + id);
|
||||
}
|
||||
|
||||
public void apply(@NotNull WindowInfo info) {
|
||||
windowInfo = info;
|
||||
|
||||
setSelected(info.isVisible() || info.isActive());
|
||||
updateState();
|
||||
updateState(toolWindow);
|
||||
}
|
||||
|
||||
private void showPopup(@Nullable Component component, int x, int y) {
|
||||
@@ -317,18 +325,17 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
}
|
||||
|
||||
void updatePresentation() {
|
||||
updateState();
|
||||
updateText();
|
||||
updateIcon();
|
||||
updateState(toolWindow);
|
||||
updateText(toolWindow);
|
||||
updateIcon(toolWindow.getIcon());
|
||||
}
|
||||
|
||||
void updateIcon() {
|
||||
Icon icon = toolWindow.getIcon();
|
||||
void updateIcon(@Nullable Icon icon) {
|
||||
setIcon(icon);
|
||||
setDisabledIcon(icon == null ? null : IconLoader.getDisabledIcon(icon));
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
private void updateText(@NotNull ToolWindowImpl toolWindow) {
|
||||
String text = toolWindow.getStripeTitle();
|
||||
if (UISettings.getInstance().getShowToolWindowsNumbers()) {
|
||||
String toolWindowId = toolWindow.getId();
|
||||
@@ -344,16 +351,15 @@ public final class StripeButton extends AnchoredButton implements ActionListener
|
||||
setText(text);
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
ToolWindowImpl window = toolWindow;
|
||||
boolean toShow = window.isAvailable() || window.isPlaceholderMode();
|
||||
private void updateState(@NotNull ToolWindowImpl toolWindow) {
|
||||
boolean toShow = toolWindow.isAvailable() || toolWindow.isPlaceholderMode();
|
||||
if (UISettings.getInstance().getAlwaysShowWindowsButton()) {
|
||||
setVisible(window.isShowStripeButton() || isSelected());
|
||||
setVisible(toolWindow.isShowStripeButton() || isSelected());
|
||||
}
|
||||
else {
|
||||
setVisible(toShow && (window.isShowStripeButton() || isSelected()));
|
||||
setVisible(toShow && (toolWindow.isShowStripeButton() || isSelected()));
|
||||
}
|
||||
setEnabled(window.isAvailable());
|
||||
setEnabled(toolWindow.isAvailable());
|
||||
}
|
||||
|
||||
private boolean isDraggingNow() {
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.ui.content.ContentManagerListener
|
||||
import com.intellij.ui.content.impl.ContentImpl
|
||||
import com.intellij.ui.content.impl.ContentManagerImpl
|
||||
import com.intellij.ui.scale.JBUIScale
|
||||
import com.intellij.util.ObjectUtils
|
||||
import com.intellij.util.ui.update.Activatable
|
||||
import com.intellij.util.ui.update.UiNotifyConnector
|
||||
import java.awt.Component
|
||||
@@ -344,7 +343,7 @@ class ToolWindowImpl internal constructor(val toolWindowManager: ToolWindowManag
|
||||
|
||||
override fun getStripeTitle(): String {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread()
|
||||
return ObjectUtils.notNull(stripeTitle, id)
|
||||
return stripeTitle ?: id
|
||||
}
|
||||
|
||||
override fun setIcon(newIcon: Icon) {
|
||||
|
||||
@@ -345,18 +345,6 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
val toolWindowPane = rootPane.toolWindowPane
|
||||
toolWindowPane.initDocumentComponent(project)
|
||||
this.toolWindowPane = toolWindowPane
|
||||
rootPane.updateToolbar()
|
||||
|
||||
toolWindowPane.putClientProperty(UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Iterable {
|
||||
val result = ArrayList<JComponent>(idToEntry.size)
|
||||
for (entry in idToEntry.values) {
|
||||
val component = entry.toolWindow.decoratorComponent
|
||||
if (component != null && component.parent == null) {
|
||||
result.add(component)
|
||||
}
|
||||
}
|
||||
result.iterator()
|
||||
})
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) {
|
||||
commandProcessor.activate()
|
||||
@@ -387,6 +375,8 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
|
||||
// must be executed in EDT
|
||||
ApplicationManager.getApplication().invokeLater(Runnable {
|
||||
frame!!.rootPane!!.updateToolbar()
|
||||
|
||||
pendingSetLayoutTask.getAndSet(null)?.run()
|
||||
|
||||
if (toolWindowPane == null) {
|
||||
@@ -431,11 +421,19 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
LOG.error("failed to init toolwindow ${bean.factoryClass}", t)
|
||||
}
|
||||
}
|
||||
|
||||
toolWindowPane!!.validate()
|
||||
toolWindowPane!!.repaint()
|
||||
}
|
||||
|
||||
toolWindowPane!!.putClientProperty(UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Iterable {
|
||||
val result = ArrayList<JComponent>(idToEntry.size)
|
||||
for (entry in idToEntry.values) {
|
||||
val component = entry.toolWindow.decoratorComponent
|
||||
if (component != null && component.parent == null) {
|
||||
result.add(component)
|
||||
}
|
||||
}
|
||||
result.iterator()
|
||||
})
|
||||
|
||||
service<ToolWindowManagerAppLevelHelper>()
|
||||
}
|
||||
|
||||
@@ -913,7 +911,7 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
icon = if (icon == null) null else ToolWindowIcon(icon, task.id),
|
||||
isAvailable = task.shouldBeAvailable)
|
||||
|
||||
val button = StripeButton(toolWindowPane!!, windowInfoSnapshot, toolWindow)
|
||||
val button = StripeButton(toolWindowPane!!, toolWindow)
|
||||
val commands = mutableListOf<Runnable>()
|
||||
|
||||
toolWindowPane.addStripeButton(button, info.anchor, layout.MyStripeButtonComparator(info.anchor, this))
|
||||
@@ -921,6 +919,9 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
val entry = ToolWindowEntry(button, toolWindow, disposable, windowInfoSnapshot)
|
||||
idToEntry.put(task.id, entry)
|
||||
|
||||
// only after added to idToEntry map
|
||||
button.init(toolWindow, windowInfoSnapshot)
|
||||
|
||||
// If preloaded info is visible or active then we have to show/activate the installed
|
||||
// tool window. This step has sense only for windows which are not in the auto hide
|
||||
// mode. But if tool window was active but its mode doesn't allow to activate it again
|
||||
@@ -1772,7 +1773,7 @@ open class ToolWindowManagerImpl(val project: Project) : ToolWindowManagerEx(),
|
||||
val stripeButton = entry?.stripeButton
|
||||
if (stripeButton != null) {
|
||||
if (property == ToolWindowProperty.ICON) {
|
||||
stripeButton.updateIcon()
|
||||
stripeButton.updateIcon(toolWindow.icon)
|
||||
}
|
||||
else {
|
||||
stripeButton.updatePresentation()
|
||||
|
||||
Reference in New Issue
Block a user