breakpoints ui. registry key. selection policy for chooser popups.

This commit is contained in:
andrey.zaytsev
2012-05-15 17:51:38 +04:00
parent 0cab6dbd64
commit 64649816ec
16 changed files with 129 additions and 96 deletions
@@ -27,6 +27,7 @@ import com.intellij.debugger.jdi.StackFrameProxyImpl;
import com.intellij.debugger.jdi.ThreadReferenceProxyImpl;
import com.intellij.debugger.ui.breakpoints.*;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
@@ -410,7 +411,7 @@ public class PositionHighlighter {
DefaultActionGroup group = new DefaultActionGroup();
for (Pair<Breakpoint, Event> eventDescriptor : myEventsOutOfLine) {
Breakpoint breakpoint = eventDescriptor.getFirst();
ViewBreakpointsAction viewBreakpointsAction = new ViewBreakpointsAction(breakpoint.getDisplayName(), breakpoint);
AnAction viewBreakpointsAction = new ViewBreakpointsAction(breakpoint.getDisplayName(), breakpoint);
group.add(viewBreakpointsAction);
}
@@ -51,6 +51,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
@@ -110,6 +112,16 @@ public abstract class BreakpointPropertiesPanel {
private boolean myMoreOptionsVisible = true;
private Breakpoint myBreakpoint;
public boolean isSaveOnRemove() {
return mySaveOnRemove;
}
public void setSaveOnRemove(boolean saveOnRemove) {
mySaveOnRemove = saveOnRemove;
}
private boolean mySaveOnRemove = false;
public boolean isMoreOptionsVisible() {
return myMoreOptionsVisible;
}
@@ -119,10 +131,12 @@ public abstract class BreakpointPropertiesPanel {
@Override
public void removeNotify() {
super.removeNotify();
saveTo(myBreakpoint, new Runnable() {
@Override
public void run() {}
});
if (mySaveOnRemove) {
saveTo(myBreakpoint, new Runnable() {
@Override
public void run() {}
});
}
}
};
}
@@ -262,6 +276,24 @@ public abstract class BreakpointPropertiesPanel {
myBreakpointComboboxHandler = new BreakpointComboboxHandler(myProject, baseBreakpointCombo);
baseBreakpointCombo.setRenderer(new BreakpointComboRenderer(baseBreakpointCombo.getRenderer()));
baseBreakpointCombo.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent event) {
event.getClass();//To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent event) {
//To change body of implemented methods use File | Settings | File Templates.
event.getClass();
}
@Override
public void popupMenuCanceled(PopupMenuEvent event) {
//To change body of implemented methods use File | Settings | File Templates.
event.getClass();
}
});
baseBreakpointCombo.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
ComboboxItem item = (ComboboxItem)baseBreakpointCombo.getSelectedItem();
@@ -637,7 +637,8 @@ public abstract class BreakpointWithHighlighter extends Breakpoint {
}
}
ViewBreakpointsAction viewBreakpointsAction =
AnAction viewBreakpointsAction =
new ViewBreakpointsAction(ActionsBundle.actionText(XDebuggerActions.VIEW_BREAKPOINTS), this);
DefaultActionGroup group = new DefaultActionGroup();
@@ -19,6 +19,7 @@ import com.intellij.debugger.DebuggerManagerEx;
import com.intellij.debugger.SourcePosition;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.popup.util.DetailView;
@@ -54,11 +55,12 @@ class JavaBreakpointItem implements BreakpointItem {
}
@Override
public void execute(Project project) {
public void execute(Project project, JBPopup popup) {
if (myBreakpoint instanceof BreakpointWithHighlighter) {
final SourcePosition position = ((BreakpointWithHighlighter)myBreakpoint).getSourcePosition();
if (position != null) {
position.navigate(true);
popup.cancel();
}
}
}
@@ -77,6 +79,7 @@ class JavaBreakpointItem implements BreakpointItem {
public void updateDetailView(DetailView panel) {
BreakpointPropertiesPanel breakpointPropertiesPanel = myBreakpointFactory
.createBreakpointPropertiesPanel(myBreakpoint.getProject(), false);
breakpointPropertiesPanel.setSaveOnRemove(true);
if (breakpointPropertiesPanel != null) {
breakpointPropertiesPanel.initFrom(myBreakpoint, true);
@@ -16,6 +16,7 @@
package com.intellij.ui.popup.util;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.ui.ColoredListCellRenderer;
import org.jetbrains.annotations.Nullable;
@@ -32,7 +33,7 @@ public interface ItemWrapper {
void setupRenderer(ColoredListCellRenderer renderer, Project project, boolean selected);
void updateMnemonicLabel(JLabel label);
void execute(Project project);
void execute(Project project, JBPopup popup);
String speedSearchText();
@@ -16,6 +16,7 @@
package com.intellij.ui.popup.util;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.ui.ColoredListCellRenderer;
import javax.swing.*;
@@ -50,7 +51,7 @@ public class SplitterItem implements ItemWrapper {
}
@Override
public void execute(Project project) {
public void execute(Project project, JBPopup popup) {
//To change body of implemented methods use File | Settings | File Templates.
}
@@ -19,6 +19,7 @@ import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.markup.EffectType;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.util.Iconable;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.vcs.FileStatusManager;
@@ -102,7 +103,7 @@ public class BookmarkItem implements ItemWrapper {
return myBookmark.getFile().getName() + " " + myBookmark.getDescription();
}
public void execute(Project project) {
public void execute(Project project, JBPopup popup) {
myBookmark.navigate();
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.Gray;
@@ -55,6 +56,7 @@ public class MasterDetailPopupBuilder {
private ActionGroup myActions;
private JBList myList;
private Delegate myDelegate;
private boolean myCloseOnEnter;
public MasterDetailPopupBuilder(Project project) {
@@ -143,6 +145,7 @@ public class MasterDetailPopupBuilder {
updatePreviewPanel(wrapper);
}
});
final Ref<JBPopup> popupRef = Ref.create(null);
Runnable runnable = new Runnable() {
public void run() {
@@ -151,12 +154,12 @@ public class MasterDetailPopupBuilder {
Object[] values = myList.getSelectedValues();
if (values.length == 1) {
((ItemWrapper)values[0]).execute(myProject);
((ItemWrapper)values[0]).execute(myProject, popupRef.get());
}
else {
for (Object value : values) {
if (value instanceof BookmarkItem) {
((ItemWrapper)value).execute(myProject);
((ItemWrapper)value).execute(myProject, popupRef.get());
}
}
}
@@ -196,6 +199,7 @@ public class MasterDetailPopupBuilder {
setSouthComponent(footerPanel).
setEastComponent(detailView).
setItemChoosenCallback(runnable).
setCloseOnEnter(myCloseOnEnter).
setMayBeParent(true).
setMinSize(new Dimension(-1, 700)).
setFilteringEnabled(new Function<Object, String>() {
@@ -204,6 +208,8 @@ public class MasterDetailPopupBuilder {
}
}).createPopup();
popupRef.set(popup);
myList.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
@@ -265,6 +271,11 @@ public class MasterDetailPopupBuilder {
return this;
}
public MasterDetailPopupBuilder setCloseOnEnter(boolean closeOnEnter) {
myCloseOnEnter = closeOnEnter;
return this;
}
public interface Delegate {
String getTitle();
@@ -280,9 +291,7 @@ public class MasterDetailPopupBuilder {
private ItemRenderer(Project project) {
super(new BorderLayout());
myProject = project;
setBackground(UIUtil.getPanelBackground());
setBackground(UIUtil.getListBackground());
final JLabel mnemonicLabel = new JLabel();
mnemonicLabel.setFont(Bookmark.MNEMONIC_FONT);
@@ -313,6 +322,8 @@ public class MasterDetailPopupBuilder {
if (value instanceof SplitterItem) {
String label = ((SplitterItem)value).getText();
final TitledSeparator separator = new TitledSeparator(label);
separator.setBackground(UIUtil.getListBackground());
separator.setForeground(UIUtil.getListForeground());
return separator;
}
myRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
@@ -81,6 +81,7 @@ public class PopupChooserBuilder {
private boolean myMayBeParent;
private int myAdAlignment = SwingUtilities.LEFT;
private boolean myModalContext;
private boolean myCloseOnEnter = true;
public PopupChooserBuilder(@NotNull JList list) {
myChooserComponent = list;
@@ -205,13 +206,28 @@ public class PopupChooserBuilder {
@Override
public void mouseReleased(MouseEvent e) {
if (UIUtil.isActionClick(e, MouseEvent.MOUSE_RELEASED) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) {
closePopup(true, e, true);
if (myCloseOnEnter) {
closePopup(true, e, true);
}
else {
myItemChosenRunnable.run();
}
}
}
});
registerClosePopupKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), false);
registerClosePopupKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), true);
if (myCloseOnEnter) {
registerClosePopupKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), true);
}
else {
registerKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
myItemChosenRunnable.run();
}
});
}
for (KeyStroke keystroke : myAdditionalKeystrokes) {
registerClosePopupKeyboardAction(keystroke, true);
}
@@ -295,14 +311,18 @@ public class PopupChooserBuilder {
}
private void registerClosePopupKeyboardAction(final KeyStroke keyStroke, final boolean shouldPerformAction) {
myChooserComponent.registerKeyboardAction(new AbstractAction() {
registerPopupKeyboardAction(keyStroke, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (!shouldPerformAction && myChooserComponent instanceof ListWithFilter) {
if (((ListWithFilter)myChooserComponent).resetFilter()) return;
}
closePopup(shouldPerformAction, null, shouldPerformAction);
}
}, keyStroke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
});
}
private void registerPopupKeyboardAction(final KeyStroke keyStroke, AbstractAction action) {
myChooserComponent.registerKeyboardAction(action, keyStroke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void closePopup(boolean shouldPerformAction, MouseEvent e, boolean isOk) {
@@ -419,6 +439,11 @@ public class PopupChooserBuilder {
return this;
}
public PopupChooserBuilder setCloseOnEnter(boolean closeOnEnter) {
myCloseOnEnter = closeOnEnter;
return this;
}
private class MyListWrapper extends JBScrollPane implements DataProvider {
@SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
private final JList myList;
@@ -118,6 +118,7 @@ debugger.valueTooltipAutoShow.description=Auto show tooltip on mouse over
debugger.mayBringFrameToFrontOnBreakpoint=true
debugger.breakpoint.message.full.trace=false
debugger.breakpoint.message.full.trace.description='Log message to console' breakpoint action will out full stacktrace for the thread that hit the breakpoint
debugger.breakpoint.use.breakpoints.popup=false
filesystem.useNative=true
@@ -628,8 +628,7 @@
<separator/>
<action id="ToggleLineBreakpoint" class="com.intellij.xdebugger.impl.actions.ToggleLineBreakpointAction"/>
<action id="EditBreakpoint" class="com.intellij.xdebugger.impl.actions.EditBreakpointAction"/>
<action id="ViewBreakpoints" class="com.intellij.xdebugger.impl.actions.ViewBreakpointsActionNew" icon="/debugger/viewBreakpoints.png"/>
<!--<action id="ViewBreakpoints" class="com.intellij.xdebugger.impl.actions.ViewBreakpointsAction" icon="/debugger/viewBreakpoints.png"/>-->
<action id="ViewBreakpoints" class="com.intellij.xdebugger.impl.actions.ViewBreakpointsAction" icon="/debugger/viewBreakpoints.png"/>
<separator/>
<add-to-group group-id="RunMenu" anchor="last"/>
@@ -25,8 +25,10 @@ import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointsConfigurationDialogFactory;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointsMasterDetailPopupFactory;
public class ViewBreakpointsAction extends AnAction implements AnAction.TransparentUpdate {
private Object myInitialBreakpoint;
@@ -52,8 +54,14 @@ public class ViewBreakpointsAction extends AnAction implements AnAction.Transpar
}
}
DialogWrapper dialog = BreakpointsConfigurationDialogFactory.getInstance(project).createDialog(myInitialBreakpoint);
dialog.show();
if (Registry.is("debugger.breakpoint.use.breakpoints.popup")) {
BreakpointsMasterDetailPopupFactory.
getInstance(project).createPopup(myInitialBreakpoint).showCenteredInCurrentWindow(project);
}
else {
DialogWrapper dialog = BreakpointsConfigurationDialogFactory.getInstance(project).createDialog(myInitialBreakpoint);
dialog.show();
}
myInitialBreakpoint = null;
}
@@ -1,68 +0,0 @@
/*
* Copyright 2000-2012 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.xdebugger.impl.actions;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointsMasterDetailPopupFactory;
import org.jetbrains.annotations.Nullable;
public class ViewBreakpointsActionNew extends AnAction implements AnAction.TransparentUpdate {
@Nullable
private Object myInitialBreakpoint;
public ViewBreakpointsActionNew() {
this(ActionsBundle.actionText(XDebuggerActions.VIEW_BREAKPOINTS), null);
}
public ViewBreakpointsActionNew(String name, Object initialBreakpoint) {
super(name);
myInitialBreakpoint = initialBreakpoint;
}
public void actionPerformed(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Project project = PlatformDataKeys.PROJECT.getData(dataContext);
if (project == null) return;
if (myInitialBreakpoint == null) {
Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
if (editor != null) {
myInitialBreakpoint = XBreakpointUtil.findSelectedBreakpoint(project, editor).second;
}
}
BreakpointsMasterDetailPopupFactory.
getInstance(project).createPopup(myInitialBreakpoint).showCenteredInCurrentWindow(project);
myInitialBreakpoint = null;
}
public void update(AnActionEvent event) {
Presentation presentation = event.getPresentation();
Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
if (project == null) {
presentation.setEnabled(false);
return;
}
presentation.setEnabled(true);
}
}
@@ -400,8 +400,7 @@ public class XBreakpointBase<Self extends XBreakpoint<P>, P extends XBreakpointP
public boolean equals(Object obj) {
return obj instanceof XLineBreakpointImpl.BreakpointGutterIconRenderer
&& getBreakpoint() == ((XLineBreakpointImpl.BreakpointGutterIconRenderer)obj).getBreakpoint()
&& Comparing.equal(getIcon(), ((XLineBreakpointImpl.BreakpointGutterIconRenderer)obj).getIcon())
;
&& Comparing.equal(getIcon(), ((XLineBreakpointImpl.BreakpointGutterIconRenderer)obj).getIcon());
}
@Override
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.ui.ColoredListCellRenderer;
import com.intellij.ui.popup.util.DetailView;
import com.intellij.xdebugger.XSourcePosition;
@@ -54,10 +55,11 @@ class XBreakpointItem implements BreakpointItem {
}
@Override
public void execute(Project project) {
public void execute(Project project, JBPopup popup) {
final XSourcePosition position = myBreakpoint.getSourcePosition();
if (position != null) {
position.createNavigatable(project).navigate(true);
popup.cancel();
}
}
@@ -28,6 +28,7 @@ import com.intellij.ui.components.JBList;
import com.intellij.ui.popup.util.ItemWrapper;
import com.intellij.ui.popup.util.MasterDetailPopupBuilder;
import com.intellij.util.PlatformIcons;
import com.intellij.xdebugger.breakpoints.ui.BreakpointItem;
import com.intellij.xdebugger.impl.DebuggerSupport;
import org.jetbrains.annotations.Nullable;
@@ -73,7 +74,10 @@ public class BreakpointsMasterDetailPopupFactory {
final BreakpointListModel model = createBreakpointsItemsList(selectionModel);
final JBList list = new JBList(model);
list.setSelectionModel(selectionModel);
list.getEmptyText().setText("No Bookmarks");
selectInitial(initialBreakpoint, model, list);
list.getEmptyText().setText("No Breakpoints");
DefaultActionGroup actions = getActions();
@@ -94,7 +98,7 @@ public class BreakpointsMasterDetailPopupFactory {
public boolean hasItemsWithMnemonic(Project project) {
return false;
}
}).createMasterDetailPopup();
}).setCloseOnEnter(false).createMasterDetailPopup();
popup.addListener(new JBPopupListener() {
@Override
@@ -111,6 +115,18 @@ public class BreakpointsMasterDetailPopupFactory {
return popup;
}
private void selectInitial(Object initialBreakpoint, BreakpointListModel model, JBList list) {
for (int i = 0, l = model.size(); i < l; ++i) {
final ItemWrapper item = (ItemWrapper)model.get(i);
if (item instanceof BreakpointItem) {
if (((BreakpointItem)item).getBreakpoint() == initialBreakpoint) {
list.setSelectedIndex(i);
break;
}
}
}
}
private DefaultActionGroup getActions() {
DefaultActionGroup actions = new DefaultActionGroup();
final DefaultActionGroup breakpointTypes = new DefaultActionGroup();