From db6338fade5538afc067dd2e6ebd8a4098363730 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Fri, 30 Dec 2011 12:06:01 +0100 Subject: [PATCH] provide information about a place where we are --- .../impl/java/JavaFileTreeModel.java | 21 +++++++++++++++-- .../structureView/impl/java/KindSorter.java | 8 +++++-- .../ide/actions/ViewStructureAction.java | 14 ++++++++++- .../openapi/actionSystem/AnActionEvent.java | 3 ++- .../src/com/intellij/ui/PlaceHolder.java | 23 +++++++++++++++++++ .../src/com/intellij/ui/PlaceProvider.java | 23 +++++++++++++++++++ .../src/com/intellij/ui/tabs/TabInfo.java | 3 ++- .../openapi/vcs/actions/VcsContext.java | 5 ++-- 8 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/ui/PlaceHolder.java create mode 100644 platform/platform-api/src/com/intellij/ui/PlaceProvider.java diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeModel.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeModel.java index d45c90798879..325c2867a4c8 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeModel.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/JavaFileTreeModel.java @@ -15,6 +15,7 @@ */ package com.intellij.ide.structureView.impl.java; +import com.intellij.ide.actions.ViewStructureAction; import com.intellij.ide.structureView.StructureViewModel; import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.ide.structureView.TextEditorBasedStructureViewModel; @@ -23,15 +24,17 @@ import com.intellij.ide.util.treeView.smartTree.Grouper; import com.intellij.ide.util.treeView.smartTree.NodeProvider; import com.intellij.ide.util.treeView.smartTree.Sorter; import com.intellij.psi.*; +import com.intellij.ui.PlaceHolder; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Collection; -public class JavaFileTreeModel extends TextEditorBasedStructureViewModel implements StructureViewModel.ElementInfoProvider { +public class JavaFileTreeModel extends TextEditorBasedStructureViewModel implements StructureViewModel.ElementInfoProvider, PlaceHolder { private static final Collection NODE_PROVIDERS = Arrays.asList(new JavaInheritedMembersNodeProvider(), new JavaAnonymousClassesNodeProvider()); private final PsiJavaFile myFile; + private String myPlace; public JavaFileTreeModel(@NotNull PsiJavaFile file) { super(file); @@ -65,7 +68,11 @@ public class JavaFileTreeModel extends TextEditorBasedStructureViewModel impleme @NotNull public Sorter[] getSorters() { - return new Sorter[]{KindSorter.INSTANCE, VisibilitySorter.INSTANCE, AnonymousClassesSorter.INSTANCE, Sorter.ALPHA_SORTER}; + return new Sorter[] { + ViewStructureAction.isInStructureViewPopup(this) ? KindSorter.POPUP_INSTANCE : KindSorter.INSTANCE, + VisibilitySorter.INSTANCE, + AnonymousClassesSorter.INSTANCE, + Sorter.ALPHA_SORTER}; } protected PsiFile getPsiFile() { @@ -110,4 +117,14 @@ public class JavaFileTreeModel extends TextEditorBasedStructureViewModel impleme protected Class[] getSuitableClasses() { return new Class[]{PsiClass.class, PsiMethod.class, PsiField.class, PsiJavaFile.class}; } + + @Override + public void setPlace(String place) { + myPlace = place; + } + + @Override + public String getPlace() { + return myPlace; + } } diff --git a/java/java-impl/src/com/intellij/ide/structureView/impl/java/KindSorter.java b/java/java-impl/src/com/intellij/ide/structureView/impl/java/KindSorter.java index 584f0a3e5f5c..18cc5972d29a 100644 --- a/java/java-impl/src/com/intellij/ide/structureView/impl/java/KindSorter.java +++ b/java/java-impl/src/com/intellij/ide/structureView/impl/java/KindSorter.java @@ -25,9 +25,13 @@ import java.util.Comparator; public class KindSorter implements Sorter { public static final Sorter INSTANCE = new KindSorter(); + public static final Sorter POPUP_INSTANCE = new KindSorter(){{isPopup = true;}}; + @NonNls public static final String ID = "KIND"; - private static final Comparator COMPARATOR = new Comparator() { + boolean isPopup = false; + + private final Comparator COMPARATOR = new Comparator() { public int compare(final Object o1, final Object o2) { return getWeight(o1) - getWeight(o2); } @@ -37,7 +41,7 @@ public class KindSorter implements Sorter { return 55; } if (value instanceof JavaClassTreeElement) { - return 10; + return isPopup ? 53 : 10; } if (value instanceof ClassInitializerTreeElement) { return 15; diff --git a/platform/lang-impl/src/com/intellij/ide/actions/ViewStructureAction.java b/platform/lang-impl/src/com/intellij/ide/actions/ViewStructureAction.java index 9b4de3c2ee48..a1e115a7f014 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/ViewStructureAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/ViewStructureAction.java @@ -33,10 +33,13 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.pom.Navigatable; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; +import com.intellij.ui.PlaceHolder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class ViewStructureAction extends AnAction { + private static final String PLACE = "StructureViewPopup"; + public ViewStructureAction() { setEnabledInModalContext(true); } @@ -91,7 +94,16 @@ public class ViewStructureAction extends AnAction { final StructureViewBuilder structureViewBuilder = fileEditor.getStructureViewBuilder(); if (structureViewBuilder == null) return null; StructureView structureView = structureViewBuilder.createStructureView(fileEditor, project); - return createStructureViewPopup(structureView.getTreeModel(), editor, project, navigatable, structureView); + final StructureViewModel model = structureView.getTreeModel(); + if (model instanceof PlaceHolder) { + //noinspection unchecked + ((PlaceHolder)model).setPlace(PLACE); + } + return createStructureViewPopup(model, editor, project, navigatable, structureView); + } + + public static boolean isInStructureViewPopup(@NotNull PlaceHolder model) { + return PLACE.equals(model.getPlace()); } public static FileStructureDialog createStructureViewBasedDialog(final StructureViewModel structureViewModel, diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java index 05e9217dc5c0..6e0547b827e3 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java @@ -17,6 +17,7 @@ package com.intellij.openapi.actionSystem; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.ui.PlaceProvider; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; @@ -32,7 +33,7 @@ import java.util.Map; * @see AnAction#update(AnActionEvent) */ -public class AnActionEvent { +public class AnActionEvent implements PlaceProvider { private final InputEvent myInputEvent; private final ActionManager myActionManager; @NotNull private final DataContext myDataContext; diff --git a/platform/platform-api/src/com/intellij/ui/PlaceHolder.java b/platform/platform-api/src/com/intellij/ui/PlaceHolder.java new file mode 100644 index 000000000000..88f4d0a140fc --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/PlaceHolder.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 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.ui; + +/** + * @author Konstantin Bulenkov + */ +public interface PlaceHolder extends PlaceProvider { + void setPlace(Place place); +} diff --git a/platform/platform-api/src/com/intellij/ui/PlaceProvider.java b/platform/platform-api/src/com/intellij/ui/PlaceProvider.java new file mode 100644 index 000000000000..c74cbc5e79b4 --- /dev/null +++ b/platform/platform-api/src/com/intellij/ui/PlaceProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2011 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.ui; + +/** + * @author Konstantin Bulenkov + */ +public interface PlaceProvider { + Place getPlace(); +} diff --git a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java index 3ffe498ed2e8..0a17ff9e0258 100644 --- a/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java +++ b/platform/platform-api/src/com/intellij/ui/tabs/TabInfo.java @@ -18,6 +18,7 @@ package com.intellij.ui.tabs; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.ui.Queryable; import com.intellij.openapi.util.IconLoader; +import com.intellij.ui.PlaceProvider; import com.intellij.ui.SimpleColoredText; import com.intellij.ui.SimpleTextAttributes; import com.intellij.ui.content.AlertIcon; @@ -31,7 +32,7 @@ import java.beans.PropertyChangeSupport; import java.lang.ref.WeakReference; import java.util.Map; -public final class TabInfo implements Queryable { +public final class TabInfo implements Queryable, PlaceProvider { public static final String ACTION_GROUP = "actionGroup"; public static final String ICON = "icon"; diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/actions/VcsContext.java b/platform/vcs-api/src/com/intellij/openapi/vcs/actions/VcsContext.java index 63e3e48d0430..5e55583a2dc7 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/actions/VcsContext.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/actions/VcsContext.java @@ -22,12 +22,13 @@ import com.intellij.openapi.vcs.changes.Change; import com.intellij.openapi.vcs.changes.ChangeList; import com.intellij.openapi.vcs.ui.Refreshable; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.ui.PlaceProvider; import org.jetbrains.annotations.Nullable; import java.io.File; import java.util.Collection; -public interface VcsContext { +public interface VcsContext extends PlaceProvider { Project getProject(); @Nullable @@ -45,8 +46,6 @@ public interface VcsContext { Refreshable getRefreshableDialog(); - String getPlace(); - File getSelectedIOFile(); FilePath[] getSelectedFilePaths();