provide information about a place where we are

This commit is contained in:
Konstantin Bulenkov
2011-12-30 12:07:14 +01:00
parent 9e368febb4
commit db6338fade
8 changed files with 90 additions and 10 deletions
@@ -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<String> {
private static final Collection<NodeProvider> NODE_PROVIDERS = Arrays.<NodeProvider>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;
}
}
@@ -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;
@@ -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<String> model) {
return PLACE.equals(model.getPlace());
}
public static FileStructureDialog createStructureViewBasedDialog(final StructureViewModel structureViewModel,
@@ -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<String> {
private final InputEvent myInputEvent;
private final ActionManager myActionManager;
@NotNull private final DataContext myDataContext;
@@ -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<Place> extends PlaceProvider<Place> {
void setPlace(Place place);
}
@@ -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> {
Place getPlace();
}
@@ -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<String> {
public static final String ACTION_GROUP = "actionGroup";
public static final String ICON = "icon";
@@ -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<String> {
Project getProject();
@Nullable
@@ -45,8 +46,6 @@ public interface VcsContext {
Refreshable getRefreshableDialog();
String getPlace();
File getSelectedIOFile();
FilePath[] getSelectedFilePaths();