'Mark Object' action in xdebugger

This commit is contained in:
nik
2011-04-15 18:30:52 +04:00
parent 87ba84e74e
commit 54213ca634
27 changed files with 538 additions and 115 deletions
@@ -37,7 +37,6 @@ public interface DebuggerActions extends XDebuggerActions {
@NonNls String REMOVE_WATCH = "Debugger.RemoveWatch";
@NonNls String NEW_WATCH = "Debugger.NewWatch";
@NonNls String EDIT_WATCH = "Debugger.EditWatch";
@NonNls String MARK_OBJECT = "Debugger.MarkObject";
@NonNls String COPY_VALUE = "Debugger.CopyValue";
@NonNls String SET_VALUE = "Debugger.SetValue";
@NonNls String EDIT_FRAME_SOURCE = "Debugger.EditFrameSource";
@@ -16,6 +16,7 @@
package com.intellij.debugger.actions;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.debugger.engine.DebugProcess;
import com.intellij.debugger.engine.DebugProcessImpl;
import com.intellij.debugger.engine.DebuggerUtils;
import com.intellij.debugger.engine.events.DebuggerContextCommandImpl;
@@ -26,17 +27,18 @@ import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl;
import com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl;
import com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl;
import com.intellij.debugger.ui.tree.ValueDescriptor;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkup;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.util.containers.HashMap;
import com.intellij.xdebugger.impl.actions.MarkObjectActionHandler;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkup;
import com.sun.jdi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -51,14 +53,13 @@ import java.util.Map;
* Class SetValueAction
* @author Jeka
*/
public class MarkObjectAction extends DebuggerAction {
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.actions.MarkObjectAction");
public class JavaMarkObjectActionHandler extends MarkObjectActionHandler {
private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.actions.JavaMarkObjectActionHandler");
public static final long AUTO_MARKUP_REFERRING_OBJECTS_LIMIT = 100L; // todo: some reasonable limit
private final String MARK_TEXT = ActionsBundle.message("action.Debugger.MarkObject.text");
private final String UNMARK_TEXT = ActionsBundle.message("action.Debugger.MarkObject.unmark.text");
public void actionPerformed(final AnActionEvent event) {
final DebuggerTreeNodeImpl node = getSelectedNode(event.getDataContext());
@Override
public void perform(@NotNull Project project, AnActionEvent event) {
final DebuggerTreeNodeImpl node = DebuggerAction.getSelectedNode(event.getDataContext());
if (node == null) {
return;
}
@@ -233,24 +234,27 @@ public class MarkObjectAction extends DebuggerAction {
return builder.append("<br><b>").append(refType.name()).append(".").append(fieldName).append("</b>").toString();
}
@Override
public boolean isEnabled(@NotNull Project project, AnActionEvent event) {
final DebuggerTreeNodeImpl node = DebuggerAction.getSelectedNode(event.getDataContext());
return node != null && node.getDescriptor() instanceof ValueDescriptor;
}
public void update(AnActionEvent e) {
boolean enable = false;
String text = MARK_TEXT;
final DebuggerTreeNodeImpl node = getSelectedNode(e.getDataContext());
if (node != null) {
final NodeDescriptorImpl descriptor = node.getDescriptor();
enable = (descriptor instanceof ValueDescriptor);
if (enable) {
final ValueMarkup markup = ((ValueDescriptor)descriptor).getMarkup(node.getTree().getDebuggerContext().getDebugProcess());
if (markup != null) { // already exists
text = UNMARK_TEXT;
}
}
}
final Presentation presentation = e.getPresentation();
presentation.setVisible(enable);
presentation.setText(text);
@Override
public boolean isHidden(@NotNull Project project, AnActionEvent event) {
return DebuggerAction.getSelectedNode(event.getDataContext()) == null;
}
@Override
public boolean isMarked(@NotNull Project project, @NotNull AnActionEvent event) {
final DebuggerTreeNodeImpl node = DebuggerAction.getSelectedNode(event.getDataContext());
if (node == null) return false;
final NodeDescriptorImpl descriptor = node.getDescriptor();
if (!(descriptor instanceof ValueDescriptor)) return false;
DebugProcess debugProcess = node.getTree().getDebuggerContext().getDebugProcess();
return ((ValueDescriptor)descriptor).getMarkup(debugProcess) != null;
}
public static Color getAutoMarkupColor() {
@@ -17,7 +17,7 @@ package com.intellij.debugger.actions;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.ui.ex.MultiLineLabel;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkerPresentationDialog;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkerPresentationDialogBase;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -28,7 +28,7 @@ import java.awt.*;
* @author Eugene Zhuravlev
* Date: Feb 4, 2007
*/
public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialog {
public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogBase {
@NonNls private static final String MARK_ALL_REFERENCED_VALUES_KEY = "debugger.mark.all.referenced.values";
private JCheckBox myCbMarkAdditionalFields;
private final boolean mySuggestAdditionalMarkup;
@@ -29,8 +29,8 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.xdebugger.AbstractDebuggerSession;
import com.intellij.xdebugger.impl.DebuggerSupport;
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
import com.intellij.xdebugger.impl.actions.DebuggerToggleActionHandler;
import com.intellij.xdebugger.impl.actions.*;
import com.intellij.xdebugger.impl.actions.MarkObjectActionHandler;
import com.intellij.xdebugger.impl.breakpoints.ui.AbstractBreakpointPanel;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointPanelProvider;
import com.intellij.xdebugger.impl.evaluate.quick.common.QuickEvaluateHandler;
@@ -63,6 +63,7 @@ public class JavaDebuggerSupport extends DebuggerSupport {
private final MuteBreakpointsActionHandler myMuteBreakpointsHandler = new MuteBreakpointsActionHandler();
private final DebuggerActionHandler mySmartStepIntoHandler = new SmartStepIntoActionHandler();
private final DebuggerActionHandler myAddToWatchedActionHandler = new AddToWatchActionHandler();
private JavaMarkObjectActionHandler myMarkObjectActionHandler = new JavaMarkObjectActionHandler();
@NotNull
public BreakpointPanelProvider<?> getBreakpointPanelProvider() {
@@ -150,6 +151,12 @@ public class JavaDebuggerSupport extends DebuggerSupport {
return myMuteBreakpointsHandler;
}
@NotNull
@Override
public MarkObjectActionHandler getMarkObjectHandler() {
return myMarkObjectActionHandler;
}
@Override
public AbstractDebuggerSession getCurrentSession(@NotNull Project project) {
final DebuggerContextImpl context = (DebuggerManagerEx.getInstanceEx(project)).getContext();
@@ -19,7 +19,6 @@
*/
package com.intellij.debugger.ui.impl;
import com.intellij.debugger.actions.DebuggerActions;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.impl.DebuggerStateManager;
import com.intellij.debugger.ui.impl.watch.DebuggerTree;
@@ -30,6 +29,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.wm.ex.IdeFocusTraversalPolicy;
import com.intellij.ui.PopupHandler;
import com.intellij.xdebugger.impl.actions.XDebuggerActions;
import javax.swing.*;
import java.awt.*;
@@ -68,7 +68,7 @@ public abstract class DebuggerTreePanel extends UpdatableDebuggerView implements
final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts("ToggleBookmark");
final CustomShortcutSet shortcutSet = shortcuts.length > 0? new CustomShortcutSet(shortcuts) : new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0));
overrideShortcut(myTree, DebuggerActions.MARK_OBJECT, shortcutSet);
overrideShortcut(myTree, XDebuggerActions.MARK_OBJECT, shortcutSet);
}
protected abstract DebuggerTree createTreeView();
@@ -672,6 +672,7 @@
icon="/debugger/muteBreakpoints.png"/>
<action id="XDebugger.AutoTooltip" class="com.intellij.xdebugger.impl.actions.ValueTooltipAutoShowAction"/>
<action id="XDebugger.ToggleSortValues" class="com.intellij.xdebugger.impl.ui.tree.actions.SortValuesToggleAction" icon="/objectBrowser/sorted.png"/>
<action id="Debugger.MarkObject" class="com.intellij.xdebugger.impl.actions.MarkObjectAction"/>
</group>
<group id="XDebugger.ToolWindow.TopToolbar">
@@ -699,12 +700,14 @@
<reference ref="XDebugger.Inspect"/>
<reference ref="XDebugger.SetValue"/>
<reference ref="XDebugger.CopyValue"/>
<reference ref="Debugger.MarkObject"/>
</group>
<group id="XDebugger.Variables.Tree.Popup">
<reference ref="XDebugger.Inspect"/>
<reference ref="XDebugger.SetValue"/>
<reference ref="XDebugger.CopyValue"/>
<reference ref="Debugger.MarkObject"/>
<reference ref="XDebugger.JumpToSource"/>
<reference ref="XDebugger.AddToWatches"/>
</group>
@@ -717,6 +720,7 @@
<reference ref="XDebugger.Inspect"/>
<reference ref="XDebugger.SetValue"/>
<reference ref="XDebugger.CopyValue"/>
<reference ref="Debugger.MarkObject"/>
</group>
<group id="XDebugger.Watches.Tree.Toolbar">
@@ -727,6 +731,7 @@
<group id="XDebugger.Inspect.Tree.Popup">
<reference ref="XDebugger.Inspect"/>
<reference ref="XDebugger.CopyValue"/>
<reference ref="Debugger.MarkObject"/>
</group>
<group id="XDebugger.Value.Hint.Tree.Popup">
@@ -24,6 +24,7 @@ import com.intellij.execution.ui.RunnerLayoutUi;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.xdebugger.breakpoints.XBreakpointHandler;
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
import com.intellij.xdebugger.frame.XValueMarkerProvider;
import com.intellij.xdebugger.stepping.XSmartStepIntoHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -161,6 +162,15 @@ public abstract class XDebugProcess {
return consoleBuilder.getConsole();
}
/**
* Override this method to enable 'Mark Object' action
* @return new instance of {@link XValueMarkerProvider}'s implementation or {@code null} if 'Mark Object' feature isn't supported
*/
@Nullable
public XValueMarkerProvider<?,?> createValueMarkerProvider() {
return null;
}
/**
* Override this method to provide additional tabs for 'Debug' tool window
*/
@@ -116,7 +116,6 @@ public abstract class XDebuggerEvaluator {
* Override this method to format selected text before it is shown in 'Evaluate' dialog
*/
@NotNull
@SuppressWarnings({"MethodMayBeStatic"})
public String formatTextForEvaluation(@NotNull String text) {
return text;
}
@@ -0,0 +1,68 @@
/*
* 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.xdebugger.frame;
import org.jetbrains.annotations.NotNull;
/**
* Provides implementation of 'Mark Object' feature. <p>
*
* If debugger values have unique ids just return these ids from {@link #getMarker(XValue)} method.
* Alternatively implement {@link #markValue(XValue)} to store a value in some registry and implement {@link #unmarkValue(XValue, Object)}
* to remote it from the registry. In such a case the {@link #getMarker(XValue)} method can return {@code null} if the {@code value} isn't marked.
*
* @author nik
*/
public abstract class XValueMarkerProvider<V extends XValue, M> {
private final Class<V> myValueClass;
protected XValueMarkerProvider(Class<V> valueClass) {
myValueClass = valueClass;
}
/**
* @return {@code true} if 'Mark Object' action should be enabled for {@code value}
*/
public abstract boolean canMark(@NotNull V value);
/**
* This method is used to determine whether the {@code value} was marked or not. The returned object is compared using {@link Object#equals(Object)}
* method with markers returned by {@link #markValue(XValue)} methods. <p>
* This method may return {@code null} if the {@code value} wasn't marked by {@link #markValue(XValue)} method.
* @return a marker for {@code value}
*/
public abstract M getMarker(@NotNull V value);
/**
* This method is called when 'Mark Object' action is invoked. Return an unique marker for {@code value} and store it in some registry
* if necessary.
* @return a marker for {@code value}
*/
@NotNull
public M markValue(@NotNull V value) {
return getMarker(value);
}
/**
* This method is called when 'Unmark Object' action is invoked.
*/
public void unmarkValue(@NotNull V value, @NotNull M marker) {
}
public final Class<V> getValueClass() {
return myValueClass;
}
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.AbstractDebuggerSession;
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
import com.intellij.xdebugger.impl.actions.DebuggerToggleActionHandler;
import com.intellij.xdebugger.impl.actions.MarkObjectActionHandler;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointPanelProvider;
import com.intellij.xdebugger.impl.evaluate.quick.common.QuickEvaluateHandler;
import com.intellij.xdebugger.impl.settings.DebuggerSettingsPanelProvider;
@@ -33,7 +34,7 @@ import org.jetbrains.annotations.Nullable;
public abstract class DebuggerSupport {
private static final ExtensionPointName<DebuggerSupport> EXTENSION_POINT = ExtensionPointName.create("com.intellij.xdebugger.debuggerSupport");
@NotNull
@NotNull
public static DebuggerSupport[] getDebuggerSupports() {
return Extensions.getExtensions(EXTENSION_POINT);
}
@@ -96,6 +97,10 @@ public abstract class DebuggerSupport {
@NotNull
public abstract DebuggerToggleActionHandler getMuteBreakpointsHandler();
@NotNull
public abstract MarkObjectActionHandler getMarkObjectHandler();
@Nullable
public abstract AbstractDebuggerSession getCurrentSession(@NotNull Project project);
}
@@ -29,6 +29,7 @@ import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.execution.ui.RunnerLayoutUi;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.diagnostic.Logger;
@@ -46,8 +47,10 @@ import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
import com.intellij.xdebugger.frame.XExecutionStack;
import com.intellij.xdebugger.frame.XStackFrame;
import com.intellij.xdebugger.frame.XSuspendContext;
import com.intellij.xdebugger.frame.XValueMarkerProvider;
import com.intellij.xdebugger.impl.breakpoints.*;
import com.intellij.xdebugger.impl.evaluate.quick.common.ValueLookupManager;
import com.intellij.xdebugger.impl.frame.XValueMarkers;
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
import com.intellij.xdebugger.impl.ui.XDebugSessionData;
import com.intellij.xdebugger.impl.ui.XDebugSessionTab;
@@ -78,6 +81,7 @@ public class XDebugSessionImpl implements XDebugSession {
private XSourcePosition myCurrentPosition;
private boolean myPaused;
private MyDependentBreakpointListener myDependentBreakpointListener;
private XValueMarkers<?,?> myValueMarkers;
private String mySessionName;
private XDebugSessionTab mySessionTab;
private XDebugSessionData mySessionData;
@@ -255,6 +259,17 @@ public class XDebugSessionImpl implements XDebugSession {
ExecutionManager.getInstance(getProject()).getContentManager().showRunContent(DefaultDebugExecutor.getDebugExecutorInstance(), descriptor);
}
public XValueMarkers<?, ?> getValueMarkers() {
ApplicationManager.getApplication().assertIsDispatchThread();
if (myValueMarkers == null) {
XValueMarkerProvider<?,?> provider = myDebugProcess.createValueMarkerProvider();
if (provider != null) {
myValueMarkers = XValueMarkers.createValueMarkers(provider);
}
}
return myValueMarkers;
}
private static <B extends XBreakpoint<?>> XBreakpointType<?, ?> getBreakpointTypeClass(final XBreakpointHandler<B> handler) {
return XDebuggerUtil.getInstance().findBreakpointType(handler.getBreakpointTypeClass());
}
@@ -22,6 +22,7 @@ import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XDebuggerManager;
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
import com.intellij.xdebugger.impl.actions.DebuggerToggleActionHandler;
import com.intellij.xdebugger.impl.actions.MarkObjectActionHandler;
import com.intellij.xdebugger.impl.actions.XDebuggerSuspendedActionHandler;
import com.intellij.xdebugger.impl.actions.handlers.*;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointPanelProvider;
@@ -54,6 +55,7 @@ public class XDebuggerSupport extends DebuggerSupport {
private final XAddToWatchesFromEditorActionHandler myAddToWatchesActionHandler;
private final DebuggerToggleActionHandler myMuteBreakpointsHandler;
private final DebuggerActionHandler mySmartStepIntoHandler;
private final XMarkObjectActionHandler myMarkObjectActionHandler;
public XDebuggerSupport() {
myBreakpointPanelProvider = new XBreakpointPanelProvider();
@@ -106,6 +108,7 @@ public class XDebuggerSupport extends DebuggerSupport {
myEvaluateHandler = new XDebuggerEvaluateActionHandler();
myQuickEvaluateHandler = new XQuickEvaluateHandler();
mySettingsPanelProvider = new XDebuggerSettingsPanelProviderImpl();
myMarkObjectActionHandler = new XMarkObjectActionHandler();
}
@NotNull
@@ -194,6 +197,12 @@ public class XDebuggerSupport extends DebuggerSupport {
return myMuteBreakpointsHandler;
}
@NotNull
@Override
public MarkObjectActionHandler getMarkObjectHandler() {
return myMarkObjectActionHandler;
}
@Override
public AbstractDebuggerSession getCurrentSession(@NotNull Project project) {
return XDebuggerManager.getInstance(project).getCurrentSession();
@@ -0,0 +1,64 @@
/*
* 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.xdebugger.impl.actions;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.impl.DebuggerSupport;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class MarkObjectAction extends XDebuggerActionBase {
@Override
public void update(AnActionEvent event) {
Project project = event.getData(PlatformDataKeys.PROJECT);
boolean enabled = false;
Presentation presentation = event.getPresentation();
boolean hidden = true;
if (project != null) {
for (DebuggerSupport support : DebuggerSupport.getDebuggerSupports()) {
MarkObjectActionHandler handler = support.getMarkObjectHandler();
hidden &= handler.isHidden(project, event);
if (handler.isEnabled(project, event)) {
enabled = true;
String text;
if (handler.isMarked(project, event)) {
text = ActionsBundle.message("action.Debugger.MarkObject.unmark.text");
}
else {
text = ActionsBundle.message("action.Debugger.MarkObject.text");
}
presentation.setText(text);
break;
}
}
}
presentation.setVisible(!hidden && (!ActionPlaces.isPopupPlace(event.getPlace()) || enabled));
presentation.setEnabled(enabled);
}
@NotNull
@Override
protected DebuggerActionHandler getHandler(@NotNull DebuggerSupport debuggerSupport) {
return debuggerSupport.getMarkObjectHandler();
}
}
@@ -0,0 +1,27 @@
/*
* 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.xdebugger.impl.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public abstract class MarkObjectActionHandler extends DebuggerActionHandler {
public abstract boolean isMarked(@NotNull Project project, @NotNull AnActionEvent event);
}
@@ -62,4 +62,5 @@ public interface XDebuggerActions {
@NonNls String TOGGLE_SORT_VALUES = "XDebugger.ToggleSortValues";
@NonNls String AUTO_TOOLTIP = "XDebugger.AutoTooltip";
@NonNls String MARK_OBJECT = "Debugger.MarkObject";
}
@@ -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.xdebugger.impl.actions.handlers;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.xdebugger.XDebugSession;
import com.intellij.xdebugger.XDebuggerManager;
import com.intellij.xdebugger.frame.XValue;
import com.intellij.xdebugger.impl.XDebugSessionImpl;
import com.intellij.xdebugger.impl.actions.MarkObjectActionHandler;
import com.intellij.xdebugger.impl.frame.XValueMarkers;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkerPresentationDialog;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkup;
import com.intellij.xdebugger.impl.ui.tree.actions.XDebuggerTreeActionBase;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public class XMarkObjectActionHandler extends MarkObjectActionHandler {
@Override
public void perform(@NotNull Project project, AnActionEvent event) {
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session == null) return;
XValueMarkers<?, ?> markers = ((XDebugSessionImpl)session).getValueMarkers();
XValueNodeImpl node = XDebuggerTreeActionBase.getSelectedNode(event.getDataContext());
if (markers == null || node == null) return;
XValue value = node.getValueContainer();
ValueMarkup existing = markers.getMarkup(value);
if (existing != null) {
markers.unmarkValue(value);
}
else {
ValueMarkerPresentationDialog dialog = new ValueMarkerPresentationDialog(node.getName());
dialog.show();
ValueMarkup markup = dialog.getConfiguredMarkup();
if (dialog.isOK() && markup != null) {
markers.markValue(value, markup);
}
}
session.rebuildViews();
}
@Override
public boolean isEnabled(@NotNull Project project, AnActionEvent event) {
XValueMarkers<?, ?> markers = getValueMarkers(project);
if (markers == null) return false;
XValue value = XDebuggerTreeActionBase.getSelectedValue(event.getDataContext());
return value != null && markers.canMarkValue(value);
}
@Override
public boolean isMarked(@NotNull Project project, @NotNull AnActionEvent event) {
XValueMarkers<?, ?> markers = getValueMarkers(project);
if (markers == null) return false;
XValue value = XDebuggerTreeActionBase.getSelectedValue(event.getDataContext());
return value != null && markers.getMarkup(value) != null;
}
@Override
public boolean isHidden(@NotNull Project project, AnActionEvent event) {
return getValueMarkers(project) == null;
}
@Nullable
private static XValueMarkers<?, ?> getValueMarkers(@NotNull Project project) {
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
return session != null ? ((XDebugSessionImpl)session).getValueMarkers() : null;
}
}
@@ -0,0 +1,77 @@
/*
* 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.xdebugger.impl.frame;
import com.intellij.xdebugger.frame.XValue;
import com.intellij.xdebugger.frame.XValueMarkerProvider;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkup;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
/**
* @author nik
*/
public class XValueMarkers<V extends XValue, M> {
private final XValueMarkerProvider<V, M> myProvider;
private final Map<M, ValueMarkup> myMarkers;
private XValueMarkers(@NotNull XValueMarkerProvider<V, M> provider) {
myProvider = provider;
myMarkers = new HashMap<M, ValueMarkup>();
}
public static <V extends XValue, M> XValueMarkers<V, M> createValueMarkers(@NotNull XValueMarkerProvider<V, M> provider) {
return new XValueMarkers<V, M>(provider);
}
@Nullable
public ValueMarkup getMarkup(@NotNull XValue value) {
Class<V> valueClass = myProvider.getValueClass();
if (!valueClass.isInstance(value)) return null;
V v = valueClass.cast(value);
if (!myProvider.canMark(v)) return null;
M m = myProvider.getMarker(v);
if (m == null) return null;
return myMarkers.get(m);
}
public boolean canMarkValue(@NotNull XValue value) {
Class<V> valueClass = myProvider.getValueClass();
if (!valueClass.isInstance(value)) return false;
return myProvider.canMark(valueClass.cast(value));
}
public void markValue(@NotNull XValue value, @NotNull ValueMarkup markup) {
//noinspection unchecked
M m = myProvider.markValue((V)value);
myMarkers.put(m, markup);
}
public void unmarkValue(@NotNull XValue value) {
//noinspection unchecked
M m = myProvider.getMarker((V)value);
if (m != null) {
myMarkers.remove(m);
}
}
}
@@ -15,83 +15,14 @@
*/
package com.intellij.xdebugger.impl.ui.tree;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.FixedSizeButton;
import com.intellij.ui.ColorChooser;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author nik
*/
public abstract class ValueMarkerPresentationDialog extends DialogWrapper {
private static final Color DEFAULT_COLOR = Color.RED;
private SimpleColoredComponent myColorSample;
private Color myColor;
private JPanel myMainPanel;
private JTextField myLabelField;
private FixedSizeButton myChooseColorButton;
private JPanel mySamplePanel;
public ValueMarkerPresentationDialog(final @Nullable String defaultText) {
super(true);
setTitle("Select Object Label");
setModal(true);
myLabelField.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
updateLabelSample();
}
});
myChooseColorButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final Color color = ColorChooser.chooseColor(myColorSample, "Choose Label Color", myColor);
if (color != null) {
myColor = color;
updateLabelSample();
}
}
});
myColor = DEFAULT_COLOR;
if (defaultText != null) {
myLabelField.setText(defaultText.trim());
updateLabelSample();
}
}
public JComponent getPreferredFocusedComponent() {
return myLabelField;
}
@Override
protected JComponent createCenterPanel() {
return myMainPanel;
}
private void updateLabelSample() {
myColorSample.clear();
SimpleTextAttributes attributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, myColor);
myColorSample.append(myLabelField.getText().trim(), attributes);
}
@Nullable
public ValueMarkup getConfiguredMarkup() {
final String text = myLabelField.getText().trim();
return text.isEmpty() ? null : new ValueMarkup(text, myColor, null);
}
private void createUIComponents() {
myColorSample = new SimpleColoredComponent();
mySamplePanel = new JPanel(new BorderLayout());
mySamplePanel.setBorder(BorderFactory.createEtchedBorder());
mySamplePanel.add(BorderLayout.CENTER, myColorSample);
myChooseColorButton = new FixedSizeButton(mySamplePanel);
public class ValueMarkerPresentationDialog extends ValueMarkerPresentationDialogBase {
public ValueMarkerPresentationDialog(@Nullable String defaultText) {
super(defaultText);
init();
}
}
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.xdebugger.impl.ui.tree.ValueMarkerPresentationDialog">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.xdebugger.impl.ui.tree.ValueMarkerPresentationDialogBase">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="0" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
@@ -0,0 +1,97 @@
/*
* 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.xdebugger.impl.ui.tree;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.FixedSizeButton;
import com.intellij.ui.ColorChooser;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author nik
*/
public abstract class ValueMarkerPresentationDialogBase extends DialogWrapper {
private static final Color DEFAULT_COLOR = Color.RED;
private SimpleColoredComponent myColorSample;
private Color myColor;
private JPanel myMainPanel;
private JTextField myLabelField;
private FixedSizeButton myChooseColorButton;
private JPanel mySamplePanel;
public ValueMarkerPresentationDialogBase(final @Nullable String defaultText) {
super(true);
setTitle("Select Object Label");
setModal(true);
myLabelField.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
updateLabelSample();
}
});
myChooseColorButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
final Color color = ColorChooser.chooseColor(myColorSample, "Choose Label Color", myColor);
if (color != null) {
myColor = color;
updateLabelSample();
}
}
});
myColor = DEFAULT_COLOR;
if (defaultText != null) {
myLabelField.setText(defaultText.trim());
updateLabelSample();
}
}
public JComponent getPreferredFocusedComponent() {
return myLabelField;
}
@Override
protected JComponent createCenterPanel() {
return myMainPanel;
}
private void updateLabelSample() {
myColorSample.clear();
SimpleTextAttributes attributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, myColor);
myColorSample.append(myLabelField.getText().trim(), attributes);
}
@Nullable
public ValueMarkup getConfiguredMarkup() {
final String text = myLabelField.getText().trim();
return text.isEmpty() ? null : new ValueMarkup(text, myColor, null);
}
private void createUIComponents() {
myColorSample = new SimpleColoredComponent();
mySamplePanel = new JPanel(new BorderLayout());
mySamplePanel.setBorder(BorderFactory.createEtchedBorder());
mySamplePanel.add(BorderLayout.CENTER, myColorSample);
myChooseColorButton = new FixedSizeButton(mySamplePanel);
}
}
@@ -18,6 +18,7 @@ package com.intellij.xdebugger.impl.ui.tree;
import com.intellij.ide.dnd.aware.DnDAwareTree;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.keymap.KeymapManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.changes.issueLinks.TreeLinkMouseListener;
import com.intellij.ui.PopupHandler;
@@ -210,6 +211,7 @@ public class XDebuggerTree extends DnDAwareTree implements DataProvider, Disposa
actionManager.getAction(XDebuggerActions.SET_VALUE).unregisterCustomShortcutSet(this);
actionManager.getAction(XDebuggerActions.COPY_VALUE).unregisterCustomShortcutSet(this);
actionManager.getAction(XDebuggerActions.JUMP_TO_SOURCE).unregisterCustomShortcutSet(this);
actionManager.getAction(XDebuggerActions.MARK_OBJECT).unregisterCustomShortcutSet(this);
}
private void registerShortcuts() {
@@ -217,6 +219,7 @@ public class XDebuggerTree extends DnDAwareTree implements DataProvider, Disposa
actionManager.getAction(XDebuggerActions.SET_VALUE).registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)), this);
actionManager.getAction(XDebuggerActions.COPY_VALUE).registerCustomShortcutSet(CommonShortcuts.getCopy(), this);
actionManager.getAction(XDebuggerActions.JUMP_TO_SOURCE).registerCustomShortcutSet(CommonShortcuts.getEditSource(), this);
actionManager.getAction(XDebuggerActions.MARK_OBJECT).registerCustomShortcutSet(new CustomShortcutSet( KeymapManager.getInstance().getActiveKeymap().getShortcuts("ToggleBookmark")), this);
}
private static void markNodesObsolete(final XValueContainerNode<?> node) {
@@ -24,6 +24,7 @@ import com.intellij.xdebugger.frame.XValue;
import com.intellij.xdebugger.impl.actions.XDebuggerActions;
import com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -34,7 +35,7 @@ import javax.swing.*;
public class XInspectDialog extends DialogWrapper {
private final XDebuggerTreePanel myTreePanel;
public XInspectDialog(final XDebugSession session, XDebuggerEditorsProvider editorsProvider, XSourcePosition sourcePosition, String nodeName, XValue value) {
public XInspectDialog(final XDebugSession session, XDebuggerEditorsProvider editorsProvider, XSourcePosition sourcePosition, @NotNull String nodeName, @NotNull XValue value) {
super(session.getProject(), false);
setTitle(XDebuggerBundle.message("inspect.value.dialog.title", nodeName));
setModal(false);
@@ -53,7 +53,7 @@ public abstract class XDebuggerTreeActionBase extends AnAction {
}
@Nullable
protected static XValueNodeImpl getSelectedNode(final DataContext dataContext) {
public static XValueNodeImpl getSelectedNode(final DataContext dataContext) {
XDebuggerTree tree = XDebuggerTree.getTree(dataContext);
if (tree == null) return null;
@@ -17,12 +17,13 @@ package com.intellij.xdebugger.impl.ui.tree.nodes;
import com.intellij.xdebugger.frame.XStackFrame;
import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class XStackFrameNode extends XValueContainerNode<XStackFrame> {
public XStackFrameNode(final XDebuggerTree tree, final XStackFrame xStackFrame) {
public XStackFrameNode(final @NotNull XDebuggerTree tree, final @NotNull XStackFrame xStackFrame) {
super(tree, null, xStackFrame);
setLeaf(false);
}
@@ -39,7 +39,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
protected final ValueContainer myValueContainer;
private volatile boolean myObsolete;
protected XValueContainerNode(XDebuggerTree tree, final XDebuggerTreeNode parent, ValueContainer valueContainer) {
protected XValueContainerNode(XDebuggerTree tree, final XDebuggerTreeNode parent, @NotNull ValueContainer valueContainer) {
super(tree, parent, true);
myValueContainer = valueContainer;
myText.append(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE, XDebuggerUIConstants.COLLECTING_DATA_HIGHLIGHT_ATTRIBUTES);
@@ -162,6 +162,7 @@ public abstract class XValueContainerNode<ValueContainer extends XValueContainer
return myCachedAllChildren;
}
@NotNull
public ValueContainer getValueContainer() {
return myValueContainer;
}
@@ -20,8 +20,11 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.StringBuilderSpinAllocator;
import com.intellij.xdebugger.frame.*;
import com.intellij.xdebugger.impl.XDebugSessionImpl;
import com.intellij.xdebugger.impl.frame.XValueMarkers;
import com.intellij.xdebugger.impl.ui.DebuggerUIUtil;
import com.intellij.xdebugger.impl.ui.XDebuggerUIConstants;
import com.intellij.xdebugger.impl.ui.tree.ValueMarkup;
import com.intellij.xdebugger.impl.ui.tree.XDebuggerTree;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -48,7 +51,7 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
private String mySeparator;
private boolean myChanged;
public XValueNodeImpl(XDebuggerTree tree, final XDebuggerTreeNode parent, String name, final XValue value) {
public XValueNodeImpl(XDebuggerTree tree, final XDebuggerTreeNode parent, String name, final @NotNull XValue value) {
super(tree, parent, value);
myName = name;
if (myName != null) {
@@ -106,6 +109,13 @@ public class XValueNodeImpl extends XValueContainerNode<XValue> implements XValu
private void updateText() {
myText.clear();
XValueMarkers<?,?> markers = ((XDebugSessionImpl)myTree.getSession()).getValueMarkers();
if (markers != null) {
ValueMarkup markup = markers.getMarkup(myValueContainer);
if (markup != null) {
myText.append("[" + markup.getText() + "] ", new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, markup.getColor()));
}
}
myText.append(myName, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
myText.append(mySeparator, SimpleTextAttributes.REGULAR_ATTRIBUTES);
if (myType != null) {
-1
View File
@@ -299,7 +299,6 @@
<action id="Debugger.RemoveAllWatches" class="com.intellij.debugger.actions.RemoveAllWatchesAction"/>
<action id="Debugger.RemoveWatch" class="com.intellij.debugger.actions.RemoveWatchAction" icon="/actions/delete.png"/>
<action id="Debugger.ViewAsGroup" class="com.intellij.debugger.actions.ViewAsGroup"/>
<action id="Debugger.MarkObject" class="com.intellij.debugger.actions.MarkObjectAction"/>
<action id="Debugger.SetValue" class="com.intellij.debugger.actions.SetValueAction"/>
<!--<action id="Debugger.ShowAsHex" class="com.intellij.debugger.actions.ShowAsHexAction" text="Show as Hex"/>-->
<action id="Debugger.ShowFrame" class="com.intellij.debugger.actions.ShowFrameAction"/>