listen popup actions

This commit is contained in:
Konstantin Bulenkov
2011-03-11 16:56:49 +03:00
parent 84fcd02e0d
commit bc75f4be30
7 changed files with 174 additions and 119 deletions

View File

@@ -11451,7 +11451,7 @@ com/intellij/codeInsight/folding/impl/actions/CollapseBlockAction.class:/lib/ide
com/intellij/codeInsight/folding/impl/actions/ExpandJavadocsAction.class:/lib/idea.jar
com/intellij/codeInsight/folding/impl/actions/CollapseJavadocsAction.class:/lib/idea.jar
com/intellij/codeInsight/generation/actions/GenerateAction.class:/lib/idea.jar
com/intellij/ide/navigationToolbar/PopupToolbarAction.class:/lib/idea.jar
com/intellij/ide/navigationToolbar/ShowNavBarAction.class:/lib/idea.jar
com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.class:/lib/idea.jar
com/intellij/ide/util/PsiElementListCellRenderer.class:/lib/idea.jar
com/intellij/ide/util/DefaultPsiElementCellRenderer.class:/lib/idea.jar

View File

@@ -0,0 +1,90 @@
/*
* 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.ide.navigationToolbar;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.ui.ListScrollingUtil;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
/**
* @author Konstantin Bulenkov
*/
class NavBarListWrapper extends JBScrollPane implements DataProvider {
private static final int MAX_SIZE = 20;
private final JList myList;
public NavBarListWrapper(final JList list) {
super(list);
list.addMouseMotionListener(new MouseMotionAdapter() {
boolean myIsEngaged = false;
public void mouseMoved(MouseEvent e) {
if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) {
final Point point = e.getPoint();
final int index = list.locationToIndex(point);
list.setSelectedIndex(index);
} else {
myIsEngaged = true;
}
}
});
ListScrollingUtil.installActions(list);
final int modelSize = list.getModel().getSize();
setBorder(BorderFactory.createEmptyBorder());
if (modelSize > 0 && modelSize <= MAX_SIZE) {
list.setVisibleRowCount(0);
getViewport().setPreferredSize(list.getPreferredSize());
} else {
list.setVisibleRowCount(MAX_SIZE);
}
myList = list;
}
@Nullable
public Object getData(@NonNls String dataId) {
if (PlatformDataKeys.SELECTED_ITEM.is(dataId)){
return myList.getSelectedValue();
}
return null;
}
public void setBorder(Border border) {
if (myList != null){
myList.setBorder(border);
}
}
public void requestFocus() {
myList.requestFocus();
}
public synchronized void addMouseListener(MouseListener l) {
myList.addMouseListener(l);
}
}

View File

@@ -16,6 +16,8 @@
package com.intellij.ide.navigationToolbar;
import com.intellij.ProjectTopics;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.AnActionListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
@@ -44,7 +46,7 @@ import java.util.ArrayList;
* @author Konstantin Bulenkov
*/
public class NavBarListener extends WolfTheProblemSolver.ProblemListener
implements ActionListener, FocusListener, FileStatusListener,
implements ActionListener, FocusListener, FileStatusListener, AnActionListener,
PsiTreeChangeListener, ModuleRootListener, NavBarModelListener, PropertyChangeListener {
private static final String LISTENER = "NavBarListener";
private static final String BUS = "NavBarMessageBus";
@@ -61,6 +63,7 @@ public class NavBarListener extends WolfTheProblemSolver.ProblemListener
FileStatusManager.getInstance(project).addFileStatusListener(listener);
PsiManager.getInstance(project).addPsiTreeChangeListener(listener);
WolfTheProblemSolver.getInstance(project).addProblemListener(listener);
ActionManager.getInstance().addAnActionListener(listener);
final MessageBusConnection connection = project.getMessageBus().connect();
connection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
@@ -77,6 +80,7 @@ public class NavBarListener extends WolfTheProblemSolver.ProblemListener
FileStatusManager.getInstance(project).removeFileStatusListener(listener);
PsiManager.getInstance(project).removePsiTreeChangeListener(listener);
WolfTheProblemSolver.getInstance(project).removeProblemListener(listener);
ActionManager.getInstance().removeAnActionListener(listener);
final MessageBusConnection connection = (MessageBusConnection)panel.getClientProperty(BUS);
panel.putClientProperty(BUS, null);
if (connection != null) {
@@ -232,8 +236,24 @@ public class NavBarListener extends WolfTheProblemSolver.ProblemListener
}
}
}
@Override
public void afterActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {
if (!(action instanceof PopupAction)) {
if (myPanel.isInFloatingMode()) {
myPanel.hideHint();
} else {
myPanel.cancelPopup();
}
}
}
//---- Ignored
@Override
public void beforeActionPerformed(AnAction action, DataContext dataContext, AnActionEvent event) {}
@Override
public void beforeEditorTyping(char c, DataContext dataContext) {}
@Override
public void beforeRootsChange(ModuleRootEvent event) {}

View File

@@ -16,24 +16,19 @@
package com.intellij.ide.navigationToolbar;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.*;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.components.JBList;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.ui.speedSearch.ListWithFilter;
import com.intellij.util.Function;
import com.intellij.util.NotNullFunction;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;
@@ -120,7 +115,7 @@ public class NavBarPopup extends LightweightHint {
installMoveAction(list, panel, 1, KeyEvent.VK_RIGHT);
installEnterAction(list, panel, KeyEvent.VK_ENTER);
installEscapeAction(list, panel, KeyEvent.VK_ESCAPE);
final JComponent component = ListWithFilter.wrap(list, new MyListWrapper(list), new Function<Object, String>() {
final JComponent component = ListWithFilter.wrap(list, new NavBarListWrapper(list), new Function<Object, String>() {
@Override
public String fun(Object o) {
return NavBarPresentation.getPresentableText(o, panel.getWindow());
@@ -169,60 +164,4 @@ public class NavBarPopup extends LightweightHint {
};
list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED);
}
static class MyListWrapper extends JBScrollPane implements DataProvider {
private static final int MAX_SIZE = 20;
private final JList myList;
public MyListWrapper(final JList list) {
super(list);
list.addMouseMotionListener(new MouseMotionAdapter() {
boolean myIsEngaged = false;
public void mouseMoved(MouseEvent e) {
if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) {
final Point point = e.getPoint();
final int index = list.locationToIndex(point);
list.setSelectedIndex(index);
} else {
myIsEngaged = true;
}
}
});
ListScrollingUtil.installActions(list);
final int modelSize = list.getModel().getSize();
setBorder(BorderFactory.createEmptyBorder());
if (modelSize > 0 && modelSize <= MAX_SIZE) {
list.setVisibleRowCount(0);
getViewport().setPreferredSize(list.getPreferredSize());
} else {
list.setVisibleRowCount(MAX_SIZE);
}
myList = list;
}
@Nullable
public Object getData(@NonNls String dataId) {
if (PlatformDataKeys.SELECTED_ITEM.is(dataId)){
return myList.getSelectedValue();
}
return null;
}
public void setBorder(Border border) {
if (myList != null){
myList.setBorder(border);
}
}
public void requestFocus() {
myList.requestFocus();
}
public synchronized void addMouseListener(MouseListener l) {
myList.addMouseListener(l);
}
}
}

View File

@@ -1,54 +0,0 @@
/*
* Copyright 2000-2009 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.navigationToolbar;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
/**
* User: anna
* Date: 19-Dec-2005
*/
public class PopupToolbarAction extends AnAction implements DumbAware {
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
if (project == null) return;
if (UISettings.getInstance().SHOW_NAVIGATION_BAR){
new SelectInNavBarTarget(project).select(null, false);
return;
}
if (PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext) instanceof NavBarPanel) {
return;
}
final Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
final NavBarPanel toolbarPanel = new NavBarPanel(project);
toolbarPanel.showHint(editor, dataContext);
}
@Override
public void update(final AnActionEvent e) {
final Project project = e.getData(PlatformDataKeys.PROJECT);
e.getPresentation().setEnabled(project != null);
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright 2000-2009 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.navigationToolbar;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.util.ui.UIUtil;
import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
public class ShowNavBarAction extends AnAction implements DumbAware, PopupAction {
public void actionPerformed(AnActionEvent e){
final DataContext context = e.getDataContext();
final Project project = PlatformDataKeys.PROJECT.getData(context);
if (project != null) {
if (UISettings.getInstance().SHOW_NAVIGATION_BAR){
new SelectInNavBarTarget(project).select(null, false);
} else {
final Component component = PlatformDataKeys.CONTEXT_COMPONENT.getData(context);
if (!isInsideNavBar(component)) {
final Editor editor = PlatformDataKeys.EDITOR.getData(context);
final NavBarPanel toolbarPanel = new NavBarPanel(project);
toolbarPanel.showHint(editor, context);
}
}
}
}
private static boolean isInsideNavBar(Component c) {
return c == null
|| c instanceof NavBarPanel
|| UIUtil.getParentOfType(NavBarListWrapper.class, c) != null;
}
public void update(final AnActionEvent e){
final boolean enabled = e.getData(PlatformDataKeys.PROJECT) != null;
e.getPresentation().setEnabled(enabled);
}
}

View File

@@ -219,7 +219,7 @@
</group>
<group id="GoToCodeGroup">
<action id="ShowNavBar" class="com.intellij.ide.navigationToolbar.PopupToolbarAction"/>
<action id="ShowNavBar" class="com.intellij.ide.navigationToolbar.ShowNavBarAction"/>
<action id="GotoDeclaration" class="com.intellij.codeInsight.navigation.actions.GotoDeclarationAction"/>
<action id="GotoImplementation" class="com.intellij.codeInsight.navigation.actions.GotoImplementationAction"/>
<action id="GotoTypeDeclaration" class="com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction"/>