mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[service-view] do not collapse toolbar if service action group hasn't visible actions
GitOrigin-RevId: 3a2120a4c27b286a6e10478a467bf2e2fef90457
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f1f6b63c7d
commit
1ca94659cf
+52
-14
@@ -20,6 +20,8 @@ import javax.swing.*;
|
||||
import javax.swing.event.TreeModelEvent;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,6 +45,35 @@ class ServiceViewActionProvider {
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
JComponent wrapServiceToolbar(@NotNull ActionToolbar toolbar) {
|
||||
JPanel wrapper = new JPanel(new BorderLayout());
|
||||
wrapper.add(toolbar.getComponent(), BorderLayout.CENTER);
|
||||
toolbar.getComponent().addComponentListener(new ComponentListener() {
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
wrapper.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
wrapper.setVisible(false);
|
||||
}
|
||||
});
|
||||
ActionToolbar prototypeToolbar = createPrototypeToolbar();
|
||||
JLabel spacer = new JLabel();
|
||||
spacer.setPreferredSize(new Dimension(prototypeToolbar.getComponent().getPreferredSize().width, 0));
|
||||
wrapper.add(spacer, BorderLayout.SOUTH);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
void installPopupHandler(@NotNull JComponent component) {
|
||||
ActionGroup actions = (ActionGroup)ActionManager.getInstance().getAction(SERVICE_VIEW_ITEM_POPUP);
|
||||
PopupHandler.installPopupHandler(component, actions, ActionPlaces.SERVICES_POPUP, ActionManager.getInstance());
|
||||
@@ -94,6 +125,25 @@ class ServiceViewActionProvider {
|
||||
return (ServiceView)contextComponent;
|
||||
}
|
||||
|
||||
private static final AnAction EMPTY_ACTION = new DumbAwareAction(null, null, EmptyIcon.ICON_16) {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
}
|
||||
};
|
||||
|
||||
private static ActionToolbar createPrototypeToolbar() {
|
||||
DefaultActionGroup actionGroup = new DefaultActionGroup();
|
||||
actionGroup.add(EMPTY_ACTION);
|
||||
ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.TOOLBAR, actionGroup, false);
|
||||
toolbar.updateActionsImmediately();
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
private static class ServiceViewTreeExpander extends DefaultTreeExpander {
|
||||
private final TreeModel myTreeModel;
|
||||
private boolean myFlat;
|
||||
@@ -152,7 +202,7 @@ class ServiceViewActionProvider {
|
||||
descriptor = selectedItems.get(0).getViewDescriptor();
|
||||
}
|
||||
else {
|
||||
ServiceViewContributor contributor = getTheOnlyRootContributor(selectedItems);
|
||||
ServiceViewContributor<?> contributor = getTheOnlyRootContributor(selectedItems);
|
||||
descriptor = contributor == null ? null : contributor.getViewDescriptor();
|
||||
}
|
||||
if (descriptor == null) return AnAction.EMPTY_ARRAY;
|
||||
@@ -162,22 +212,10 @@ class ServiceViewActionProvider {
|
||||
}
|
||||
|
||||
public static class ItemToolbarActionGroup extends ActionGroup {
|
||||
private final static AnAction[] FAKE_GROUP = new AnAction[]{new DumbAwareAction(null, null, EmptyIcon.ICON_16) {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
}
|
||||
}};
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction[] getChildren(@Nullable AnActionEvent e) {
|
||||
AnAction[] actions = doGetActions(e, true);
|
||||
return actions.length != 0 ? actions : FAKE_GROUP;
|
||||
return doGetActions(e, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.execution.services;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionToolbar;
|
||||
import com.intellij.openapi.ui.SimpleToolWindowPanel;
|
||||
import com.intellij.ui.components.JBPanelWithEmptyText;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
@@ -33,7 +34,8 @@ class ServiceViewSingleUi implements ServiceViewUi {
|
||||
|
||||
@Override
|
||||
public void setServiceToolbar(@NotNull ServiceViewActionProvider actionManager) {
|
||||
myMainPanel.setToolbar(actionManager.createServiceToolbar(myMainPanel).getComponent());
|
||||
ActionToolbar toolbar = actionManager.createServiceToolbar(myMainPanel);
|
||||
myMainPanel.setToolbar(actionManager.wrapServiceToolbar(toolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,7 @@ class ServiceViewTreeUi implements ServiceViewUi {
|
||||
@Override
|
||||
public void setServiceToolbar(@NotNull ServiceViewActionProvider actionProvider) {
|
||||
myServiceActionToolbar = actionProvider.createServiceToolbar(myMainPanel);
|
||||
myContentPanel.setToolbar(myServiceActionToolbar.getComponent());
|
||||
myContentPanel.setToolbar(actionProvider.wrapServiceToolbar(myServiceActionToolbar));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user