mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
customizable navbar extension (IDEA-98199)
This commit is contained in:
+42
-26
@@ -24,6 +24,8 @@ import com.intellij.ide.navigationToolbar.ui.NavBarUIManager;
|
||||
import com.intellij.ide.ui.LafManager;
|
||||
import com.intellij.ide.ui.UISettings;
|
||||
import com.intellij.ide.ui.UISettingsListener;
|
||||
import com.intellij.ide.ui.customization.CustomActionsSchema;
|
||||
import com.intellij.ide.ui.customization.CustomisedActionGroup;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -56,16 +58,24 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension {
|
||||
UISettings.getInstance().addUISettingsListener(new UISettingsListener() {
|
||||
@Override
|
||||
public void uiSettingsChanged(UISettings source) {
|
||||
toggleRunPanel(!source.SHOW_MAIN_TOOLBAR);
|
||||
toggleRunPanel(!source.SHOW_MAIN_TOOLBAR && source.SHOW_NAVIGATION_BAR);
|
||||
}
|
||||
}, this);
|
||||
|
||||
final AnAction navBarToolBar = ActionManager.getInstance().getAction("NavBarToolBar");
|
||||
myNavToolbarGroupExist = navBarToolBar instanceof DefaultActionGroup && ((DefaultActionGroup)navBarToolBar).getChildrenCount() > 0;
|
||||
myNavToolbarGroupExist = runToolbarExists();
|
||||
|
||||
Disposer.register(myProject, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revalidate() {
|
||||
final UISettings settings = UISettings.getInstance();
|
||||
if (!settings.SHOW_MAIN_TOOLBAR && settings.SHOW_NAVIGATION_BAR) {
|
||||
toggleRunPanel(false);
|
||||
toggleRunPanel(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdeRootPaneNorthExtension copy() {
|
||||
return new NavBarRootPaneExtension(myProject);
|
||||
@@ -76,8 +86,9 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension {
|
||||
}
|
||||
|
||||
public static boolean runToolbarExists() {
|
||||
final AnAction navBarToolBar = ActionManager.getInstance().getAction("NavBarToolBar");
|
||||
return navBarToolBar instanceof DefaultActionGroup && ((DefaultActionGroup)navBarToolBar).getChildrenCount() > 0;
|
||||
final AnAction correctedAction = CustomActionsSchema.getInstance().getCorrectedAction("NavBarToolBar");
|
||||
return correctedAction instanceof DefaultActionGroup && ((DefaultActionGroup)correctedAction).getChildrenCount() > 0 ||
|
||||
correctedAction instanceof CustomisedActionGroup && ((CustomisedActionGroup)correctedAction).getFirstAction() != null;
|
||||
}
|
||||
|
||||
public JComponent getComponent() {
|
||||
@@ -120,11 +131,10 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension {
|
||||
private void toggleRunPanel(final boolean show) {
|
||||
if (show && myRunPanel == null && runToolbarExists()) {
|
||||
final ActionManager manager = ActionManager.getInstance();
|
||||
final AnAction toolbarRunGroup = manager.getAction("NavBarToolBar");
|
||||
if (toolbarRunGroup instanceof DefaultActionGroup) {
|
||||
final DefaultActionGroup group = (DefaultActionGroup)toolbarRunGroup;
|
||||
final boolean needGap = isNeedGap(group);
|
||||
final ActionToolbar actionToolbar = manager.createActionToolbar(ActionPlaces.NAVIGATION_BAR, group, true);
|
||||
AnAction toolbarRunGroup = CustomActionsSchema.getInstance().getCorrectedAction("NavBarToolBar");
|
||||
if (toolbarRunGroup instanceof ActionGroup) {
|
||||
final boolean needGap = isNeedGap(toolbarRunGroup);
|
||||
final ActionToolbar actionToolbar = manager.createActionToolbar(ActionPlaces.NAVIGATION_BAR, (ActionGroup)toolbarRunGroup, true);
|
||||
final JComponent component = actionToolbar.getComponent();
|
||||
component.setOpaque(false);
|
||||
myRunPanel = new JPanel(new BorderLayout()) {
|
||||
@@ -151,30 +161,36 @@ public class NavBarRootPaneExtension extends IdeRootPaneNorthExtension {
|
||||
return (ancestor != null && !(ancestor instanceof IdeFrameImpl)) || !UISettings.getInstance().SHOW_MAIN_TOOLBAR;
|
||||
}
|
||||
|
||||
private static boolean isNeedGap(final DefaultActionGroup group) {
|
||||
private static boolean isNeedGap(final AnAction group) {
|
||||
final AnAction firstAction = getFirstAction(group);
|
||||
return firstAction instanceof ComboBoxAction;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static AnAction getFirstAction(final DefaultActionGroup group) {
|
||||
AnAction firstAction = null;
|
||||
for (final AnAction action : group.getChildActionsOrStubs()) {
|
||||
if (action instanceof DefaultActionGroup) {
|
||||
firstAction = getFirstAction((DefaultActionGroup)action);
|
||||
}
|
||||
else if (action instanceof Separator || action instanceof ActionGroup) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
firstAction = action;
|
||||
break;
|
||||
private static AnAction getFirstAction(final AnAction group) {
|
||||
if (group instanceof DefaultActionGroup) {
|
||||
AnAction firstAction = null;
|
||||
for (final AnAction action : ((DefaultActionGroup)group).getChildActionsOrStubs()) {
|
||||
if (action instanceof DefaultActionGroup) {
|
||||
firstAction = getFirstAction((DefaultActionGroup)action);
|
||||
}
|
||||
else if (action instanceof Separator || action instanceof ActionGroup) {
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
firstAction = action;
|
||||
break;
|
||||
}
|
||||
|
||||
if (firstAction != null) break;
|
||||
}
|
||||
|
||||
if (firstAction != null) break;
|
||||
return firstAction;
|
||||
}
|
||||
|
||||
return firstAction;
|
||||
if (group instanceof CustomisedActionGroup) {
|
||||
return ((CustomisedActionGroup)group).getFirstAction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JComponent buildNavBarPanel() {
|
||||
|
||||
@@ -36,4 +36,6 @@ public abstract class IdeRootPaneNorthExtension implements Disposable {
|
||||
public abstract void uiSettingsChanged(UISettings settings);
|
||||
|
||||
public abstract IdeRootPaneNorthExtension copy();
|
||||
|
||||
public void revalidate(){}
|
||||
}
|
||||
|
||||
+3
-3
@@ -80,6 +80,7 @@ public class CustomActionsSchema implements ExportableComponent, NamedJDOMExtern
|
||||
myIdToNameList.add(new Pair(IdeActions.GROUP_COMMANDER_POPUP, ActionsTreeUtil.COMMANDER_POPUP));
|
||||
myIdToNameList.add(new Pair(IdeActions.GROUP_J2EE_VIEW_POPUP, ActionsTreeUtil.J2EE_POPUP));
|
||||
myIdToNameList.add(new Pair(IdeActions.GROUP_NAVBAR_POPUP, "Navigation Bar"));
|
||||
myIdToNameList.add(new Pair("NavBarToolBar", "Navigation Bar Toolbar"));
|
||||
|
||||
CustomizableActionGroupProvider.CustomizableActionGroupRegistrar registrar =
|
||||
new CustomizableActionGroupProvider.CustomizableActionGroupRegistrar() {
|
||||
@@ -335,13 +336,12 @@ public class CustomActionsSchema implements ExportableComponent, NamedJDOMExtern
|
||||
}
|
||||
final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
|
||||
if (frame != null) {
|
||||
frame.updateToolbar();
|
||||
frame.updateMenuBar();
|
||||
frame.updateView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@NotNull
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{PathManager.getOptionsFile(this)};
|
||||
}
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.ide.ui.customization;
|
||||
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
*/
|
||||
public class CustomisedActionGroup extends ActionGroup {
|
||||
private boolean myForceUpdate;
|
||||
private final ActionGroup myGroup;
|
||||
private AnAction[] myChildren;
|
||||
private final CustomActionsSchema mySchema;
|
||||
private final String myDefaultGroupName;
|
||||
|
||||
public CustomisedActionGroup(String shortName,
|
||||
boolean popup,
|
||||
final ActionGroup group,
|
||||
CustomActionsSchema schema,
|
||||
String defaultGroupName) {
|
||||
super(shortName, popup);
|
||||
myGroup = group;
|
||||
mySchema = schema;
|
||||
myDefaultGroupName = defaultGroupName;
|
||||
myForceUpdate = true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnAction[] getChildren(@Nullable final AnActionEvent e) {
|
||||
if (myForceUpdate){
|
||||
myChildren = CustomizationUtil.getReordableChildren(myGroup, mySchema, myDefaultGroupName, e);
|
||||
myForceUpdate = false;
|
||||
return myChildren;
|
||||
} else {
|
||||
if (!(myGroup instanceof DefaultActionGroup) || myChildren == null){
|
||||
myChildren = CustomizationUtil.getReordableChildren(myGroup, mySchema, myDefaultGroupName, e);
|
||||
}
|
||||
return myChildren;
|
||||
}
|
||||
}
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
myGroup.update(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDumbAware() {
|
||||
return myGroup.isDumbAware();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public AnAction getFirstAction() {
|
||||
final AnAction[] children = getChildren(null);
|
||||
return children.length > 0 ? children[0] : null;
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -388,8 +388,7 @@ public class CustomizableActionsPanel {
|
||||
for (Project project : openProjects) {
|
||||
final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(project);
|
||||
if (frame != null) {
|
||||
frame.updateToolbar();
|
||||
frame.updateMenuBar();
|
||||
frame.updateView();
|
||||
}
|
||||
|
||||
//final FavoritesManager favoritesView = FavoritesManager.getInstance(project);
|
||||
@@ -400,8 +399,7 @@ public class CustomizableActionsPanel {
|
||||
}
|
||||
final IdeFrameImpl frame = WindowManagerEx.getInstanceEx().getFrame(null);
|
||||
if (frame != null) {
|
||||
frame.updateToolbar();
|
||||
frame.updateMenuBar();
|
||||
frame.updateView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-41
@@ -65,11 +65,11 @@ public class CustomizationUtil {
|
||||
}
|
||||
}
|
||||
|
||||
return new CachedAction(text, group.isPopup(), group, schema, defaultGroupName);
|
||||
return new CustomisedActionGroup(text, group.isPopup(), group, schema, defaultGroupName);
|
||||
}
|
||||
|
||||
|
||||
private static AnAction [] getReordableChildren(ActionGroup group, CustomActionsSchema schema, String defaultGroupName, AnActionEvent e) {
|
||||
static AnAction [] getReordableChildren(ActionGroup group, CustomActionsSchema schema, String defaultGroupName, AnActionEvent e) {
|
||||
String text = group.getTemplatePresentation().getText();
|
||||
ActionManager actionManager = ActionManager.getInstance();
|
||||
final ArrayList<AnAction> reorderedChildren = new ArrayList<AnAction>();
|
||||
@@ -117,45 +117,6 @@ public class CustomizationUtil {
|
||||
return reorderedChildren.toArray(new AnAction[reorderedChildren.size()]);
|
||||
}
|
||||
|
||||
private static class CachedAction extends ActionGroup {
|
||||
private boolean myForceUpdate;
|
||||
private final ActionGroup myGroup;
|
||||
private AnAction[] myChildren;
|
||||
private final CustomActionsSchema mySchema;
|
||||
private final String myDefaultGroupName;
|
||||
|
||||
public CachedAction(String shortName, boolean popup, final ActionGroup group, CustomActionsSchema schema, String defaultGroupName) {
|
||||
super(shortName, popup);
|
||||
myGroup = group;
|
||||
mySchema = schema;
|
||||
myDefaultGroupName = defaultGroupName;
|
||||
myForceUpdate = true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public AnAction[] getChildren(@Nullable final AnActionEvent e) {
|
||||
if (myForceUpdate){
|
||||
myChildren = getReordableChildren(myGroup, mySchema, myDefaultGroupName, e);
|
||||
myForceUpdate = false;
|
||||
return myChildren;
|
||||
} else {
|
||||
if (!(myGroup instanceof DefaultActionGroup) || myChildren == null){
|
||||
myChildren = getReordableChildren(myGroup, mySchema, myDefaultGroupName, e);
|
||||
}
|
||||
return myChildren;
|
||||
}
|
||||
}
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
myGroup.update(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDumbAware() {
|
||||
return myGroup.isDumbAware();
|
||||
}
|
||||
}
|
||||
|
||||
public static void optimizeSchema(final JTree tree, final CustomActionsSchema schema) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
Group rootGroup = new Group("root", null, null);
|
||||
|
||||
@@ -202,14 +202,6 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider {
|
||||
return ((IdeRootPane)getRootPane()).getStatusBar();
|
||||
}
|
||||
|
||||
public void updateToolbar() {
|
||||
((IdeRootPane)getRootPane()).updateToolbar();
|
||||
}
|
||||
|
||||
public void updateMenuBar(){
|
||||
((IdeRootPane)getRootPane()).updateMainMenuActions();
|
||||
}
|
||||
|
||||
public void setTitle(final String title) {
|
||||
if (myUpdatingTitle) {
|
||||
super.setTitle(title);
|
||||
@@ -268,6 +260,12 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateView() {
|
||||
((IdeRootPane)getRootPane()).updateToolbar();
|
||||
((IdeRootPane)getRootPane()).updateMainMenuActions();
|
||||
((IdeRootPane)getRootPane()).updateNorthComponents();
|
||||
}
|
||||
|
||||
private static final class Builder {
|
||||
public StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
||||
@@ -183,6 +183,13 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
|
||||
updateToolbarVisibility();
|
||||
myContentPane.revalidate();
|
||||
}
|
||||
|
||||
void updateNorthComponents() {
|
||||
for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
|
||||
northComponent.revalidate();
|
||||
}
|
||||
myContentPane.revalidate();
|
||||
}
|
||||
|
||||
void updateMainMenuActions(){
|
||||
((IdeMenuBar)menuBar).updateMenuActions();
|
||||
|
||||
Reference in New Issue
Block a user