allow specifying custom name for "jump to source" action (IDEA-59460)

This commit is contained in:
Dmitry Jemerov
2010-11-09 14:10:04 +03:00
parent e5cca9cde5
commit d1164f1c36
3 changed files with 43 additions and 6 deletions
@@ -33,6 +33,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.NavigatableWithText;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -40,7 +41,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement>{
public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement> implements NavigatableWithText {
private static final Icon GENERIC_JDK_ICON = IconLoader.getIcon("/general/jdk.png");
private static final Icon LIB_ICON_OPEN = IconLoader.getIcon("/nodes/ppLibOpen.png");
private static final Icon LIB_ICON_CLOSED = IconLoader.getIcon("/nodes/ppLibClosed.png");
@@ -123,4 +124,9 @@ public class NamedLibraryElementNode extends ProjectViewNode<NamedLibraryElement
public boolean canNavigate() {
return true;
}
@Override
public String getNavigateActionText(boolean focusEditor) {
return "Open Library Settings";
}
}
@@ -0,0 +1,23 @@
/*
* Copyright 2000-2010 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.pom;
/**
* @author yole
*/
public interface NavigatableWithText extends Navigatable {
String getNavigateActionText(boolean focusEditor);
}
@@ -18,6 +18,7 @@ package com.intellij.ide.actions;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.DumbAware;
import com.intellij.pom.Navigatable;
import com.intellij.pom.NavigatableWithText;
import com.intellij.util.OpenSourceUtil;
import org.jetbrains.annotations.Nullable;
@@ -34,25 +35,32 @@ public abstract class BaseNavigateToSourceAction extends AnAction implements Dum
}
public void update(AnActionEvent event){
public void update(AnActionEvent event) {
DataContext dataContext = event.getDataContext();
final boolean enabled = isEnabled(dataContext);
final Navigatable target = getTarget(dataContext);
boolean enabled = target != null;
if (ActionPlaces.isPopupPlace(event.getPlace())) {
event.getPresentation().setVisible(enabled);
}
else {
event.getPresentation().setEnabled(enabled);
}
if (target != null && target instanceof NavigatableWithText) {
event.getPresentation().setText(((NavigatableWithText)target).getNavigateActionText(myFocusEditor));
}
else {
event.getPresentation().setText(getTemplatePresentation().getText());
}
}
private boolean isEnabled(final DataContext dataContext) {
private Navigatable getTarget(final DataContext dataContext) {
Navigatable[] navigatables = getNavigatables(dataContext);
if (navigatables != null) {
for (Navigatable navigatable : navigatables) {
if (navigatable.canNavigate()) return true;
if (navigatable.canNavigate()) return navigatable;
}
}
return false;
return null;
}
@Nullable