/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
return false;
}
-
private static boolean activatePsiElementIfOpen(@NotNull PsiElement elt, boolean searchForOpen, boolean requestFocus) {
if (!elt.isValid()) return false;
elt = elt.getNavigationElement();
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.ide.actions;
import com.intellij.codeInsight.navigation.NavigationUtil;
import com.intellij.featureStatistics.FeatureUsageTracker;
+import com.intellij.ide.IdeBundle;
import com.intellij.ide.structureView.StructureView;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.navigation.AnonymousElementProvider;
import com.intellij.navigation.ChooseByNameRegistry;
-import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.NavigationItem;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.AccessToken;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.awt.*;
+import java.awt.event.InputEvent;
import java.util.ArrayList;
import java.util.List;
public class GotoClassAction extends GotoActionBase implements DumbAware {
@Override
- public void actionPerformed(@NotNull final AnActionEvent e) {
- final Project project = e.getData(CommonDataKeys.PROJECT);
- assert project != null;
+ public void actionPerformed(@NotNull AnActionEvent e) {
+ Project project = e.getProject();
+ if (project == null) return;
+
if (!DumbService.getInstance(project).isDumb()) {
super.actionPerformed(e);
}
else {
- DumbService.getInstance(project)
- .showDumbModeNotification("Goto Class action is not available until indices are built, using Goto File instead");
- ActionManager.getInstance()
- .tryToExecute(ActionManager.getInstance().getAction(GotoFileAction.ID), ActionCommand.getInputEvent(GotoFileAction.ID),
- e.getData(PlatformDataKeys.CONTEXT_COMPONENT), e.getPlace(), true);
+ DumbService.getInstance(project).showDumbModeNotification(IdeBundle.message("go.to.class.dumb.mode.message"));
+ AnAction action = ActionManager.getInstance().getAction(GotoFileAction.ID);
+ InputEvent event = ActionCommand.getInputEvent(GotoFileAction.ID);
+ Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT);
+ ActionManager.getInstance().tryToExecute(action, event, component, e.getPlace(), true);
}
}
@Override
- public void gotoActionPerformed(AnActionEvent e) {
- final Project project = e.getData(CommonDataKeys.PROJECT);
- assert project != null;
+ public void gotoActionPerformed(@NotNull AnActionEvent e) {
+ final Project project = e.getProject();
+ if (project == null) return;
+
+ FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class");
PsiDocumentManager.getInstance(project).commitAllDocuments();
- FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.class");
final GotoClassModel2 model = new GotoClassModel2(project);
showNavigationPopup(e, model, new GotoActionCallback<Language>() {
@Override
if (element instanceof PsiElement) {
final PsiElement psiElement = getElement(((PsiElement)element), popup);
final VirtualFile file = PsiUtilCore.getVirtualFile(psiElement);
- if (popup.getLinePosition() != -1 && file != null) {
- Navigatable n = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition()).setUseCurrentWindow(
- popup.isOpenInCurrentWindowRequested());
+
+ if (file != null && popup.getLinePosition() != -1) {
+ OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
+ Navigatable n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
if (n.canNavigate()) {
n.navigate(true);
return;
}
}
+
if (psiElement != null && file != null && popup.getMemberPattern() != null) {
NavigationUtil.activateFileWithPsiElement(psiElement, !popup.isOpenInCurrentWindowRequested());
Navigatable member = findMember(popup.getMemberPattern(), psiElement, file);
token.finish();
}
}
- }, "Classes matching pattern", true);
+ }, IdeBundle.message("go.to.class.toolwindow.title"), true);
}
- @Nullable private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
+ @Nullable
+ private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
Object target = null;
for (TreeElement treeElement : element.getChildren()) {
if (treeElement instanceof StructureViewTreeElement) {
- final ItemPresentation presentation = treeElement.getPresentation();
- String presentableText = presentation == null ? null : presentation.getPresentableText();
+ String presentableText = treeElement.getPresentation().getPresentableText();
if (presentableText != null) {
final int degree = matcher.matchingDegree(presentableText);
if (degree > max) {
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package com.intellij.ide.actions;
import com.intellij.featureStatistics.FeatureUsageTracker;
-import com.intellij.ide.util.gotoByName.*;
+import com.intellij.ide.IdeBundle;
+import com.intellij.ide.util.gotoByName.ChooseByNameFilter;
+import com.intellij.ide.util.gotoByName.ChooseByNamePopup;
+import com.intellij.ide.util.gotoByName.GotoFileConfiguration;
+import com.intellij.ide.util.gotoByName.GotoFileModel;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@Override
public void gotoActionPerformed(AnActionEvent e) {
- FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
final Project project = e.getData(CommonDataKeys.PROJECT);
+ if (project == null) return;
+
+ FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
+
final GotoFileModel gotoFileModel = new GotoFileModel(project);
GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() {
@Override
//this is for better cursor position
if (element instanceof PsiFile) {
- VirtualFile vfile = ((PsiFile)element).getVirtualFile();
- if (vfile == null) return;
- n = new OpenFileDescriptor(project, vfile, popup.getLinePosition(), popup.getColumnPosition()).setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
+ VirtualFile file = ((PsiFile)element).getVirtualFile();
+ if (file == null) return;
+ OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
+ n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
}
if (!n.canNavigate()) return;
}, ModalityState.NON_MODAL);
}
};
- PsiElement context = getPsiContext(e);
- showNavigationPopup(e, gotoFileModel, callback, "Files matching pattern", true, true, new GotoFileItemProvider(project, context));
+ GotoFileItemProvider provider = new GotoFileItemProvider(project, getPsiContext(e));
+ showNavigationPopup(e, gotoFileModel, callback, IdeBundle.message("go.to.file.toolwindow.title"), true, true, provider);
}
protected static class GotoFileFilter extends ChooseByNameFilter<FileType> {
return o1.getName().compareToIgnoreCase(o2.getName());
}
}
-
}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 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.
public class OpenFileDescriptor implements Navigatable {
/**
- * Tells descriptor to navigate in specific editor rather than file editor
- * in main IDEA window.
- * For example if you want to navigate in editor embedded into modal dialog,
- * you should provide this data.
+ * Tells descriptor to navigate in specific editor rather than file editor in main IDEA window.
+ * For example if you want to navigate in editor embedded into modal dialog, you should provide this data.
*/
public static final DataKey<Editor> NAVIGATE_IN_EDITOR = DataKey.create("NAVIGATE_IN_EDITOR");
- @NotNull
+ private final Project myProject;
private final VirtualFile myFile;
- private final int myOffset;
private final int myLogicalLine;
private final int myLogicalColumn;
+ private final int myOffset;
private final RangeMarker myRangeMarker;
- @NotNull
- private final Project myProject;
private boolean myUseCurrentWindow = false;
this(project, file, logicalLine, logicalColumn, -1, false);
}
- public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file,
- int logicalLine, int logicalColumn, boolean persistent) {
+ public OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int logicalLine, int logicalColumn, boolean persistent) {
this(project, file, logicalLine, logicalColumn, -1, persistent);
}
this(project, file, -1, -1, -1, false);
}
- private OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file,
- int logicalLine, int logicalColumn, int offset, boolean persistent) {
+ private OpenFileDescriptor(@NotNull Project project, @NotNull VirtualFile file, int logicalLine, int logicalColumn, int offset, boolean persistent) {
myProject = project;
-
myFile = file;
myLogicalLine = logicalLine;
myLogicalColumn = logicalColumn;
}
private boolean navigateInRequestedEditor() {
- DataContext ctx = DataManager.getInstance().getDataContext();
+ @SuppressWarnings("deprecation") DataContext ctx = DataManager.getInstance().getDataContext();
Editor e = NAVIGATE_IN_EDITOR.getData(ctx);
if (e == null) return false;
if (!Comparing.equal(FileDocumentManager.getInstance().getFile(e.getDocument()), myFile)) return false;
new.dir.project.default.generator=Empty project
new.dir.project.error.empty=Project name can't be empty
new.dir.project.error.buck=Project directory name must not contain the ''$'' character
+
+go.to.file.toolwindow.title=Files matching pattern
+go.to.class.toolwindow.title=Classes matching pattern
+go.to.class.dumb.mode.message=Go To Class action is not available until indices are built, using Go To File instead