From c208dce910c17e9f15817914a93072aeef275281 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 9 Apr 2014 14:46:20 +0400 Subject: [PATCH] IDEA-27445 Breakpoint groups - added support for default group --- .../breakpoints/XBreakpointManagerImpl.java | 23 +++++++++++++++++- .../breakpoints/ui/BreakpointsDialog.java | 24 ++++++++++++++++++- .../ui/grouping/XBreakpointCustomGroup.java | 11 ++++++++- .../XBreakpointCustomGroupingRule.java | 2 +- .../ui/tree/BreakpointsGroupNode.java | 2 +- .../ui/tree/BreakpointsTreeCellRenderer.java | 10 +++++++- 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java index 6e9cf979d2e9..38d497992099 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointManagerImpl.java @@ -60,7 +60,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta private final XDebuggerManagerImpl myDebuggerManager; private final XDependentBreakpointManager myDependentBreakpointManager; private long myTime; - + private String myDefaultGroup; public XBreakpointManagerImpl(final Project project, final XDebuggerManagerImpl debuggerManager, StartupManager startupManager) { myProject = project; @@ -131,6 +131,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta type.getId(), defaultBreakpoint ? 0 : myTime++); getBreakpointDefaults(type).applyDefaults(state); + state.setGroup(myDefaultGroup); return new XBreakpointBase,T, BreakpointState>(type, this, properties, state); } @@ -220,6 +221,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta LineBreakpointState state = new LineBreakpointState(true, type.getId(), fileUrl, line, temporary, myTime++); getBreakpointDefaults(type).applyDefaults(state); + state.setGroup(myDefaultGroup); XLineBreakpointImpl breakpoint = new XLineBreakpointImpl(type, this, properties, state); addBreakpoint(breakpoint, false, true); @@ -368,6 +370,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta state.setBreakpointsDialogProperties(myBreakpointsDialogSettings); state.setTime(myTime); + state.setDefaultGroup(myDefaultGroup); return state; } @@ -420,6 +423,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta myDependentBreakpointManager.loadState(); myLineBreakpointManager.updateBreakpointsUI(); myTime = state.getTime(); + myDefaultGroup = state.getDefaultGroup(); } private

void addDefaultBreakpoint(XBreakpointType type) { @@ -467,6 +471,14 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta return res; } + public String getDefaultGroup() { + return myDefaultGroup; + } + + public void setDefaultGroup(String defaultGroup) { + myDefaultGroup = defaultGroup; + } + @Nullable private XBreakpointBase createBreakpoint(final BreakpointState breakpointState) { XBreakpointType type = XBreakpointUtil.findType(breakpointState.getTypeId()); @@ -498,6 +510,7 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta private XBreakpointsDialogState myBreakpointsDialogProperties; private long myTime; + private String myDefaultGroup; @Tag("default-breakpoints") @AbstractCollection(surroundWithTag = false) @@ -548,5 +561,13 @@ public class XBreakpointManagerImpl implements XBreakpointManager, PersistentSta public void setTime(long time) { myTime = time; } + + public String getDefaultGroup() { + return myDefaultGroup; + } + + public void setDefaultGroup(String defaultGroup) { + myDefaultGroup = defaultGroup; + } } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/BreakpointsDialog.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/BreakpointsDialog.java index ce47f118f821..68b72e30509f 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/BreakpointsDialog.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/BreakpointsDialog.java @@ -41,9 +41,11 @@ import com.intellij.xdebugger.impl.breakpoints.XBreakpointBase; import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil; import com.intellij.xdebugger.impl.breakpoints.XBreakpointsDialogState; +import com.intellij.xdebugger.impl.breakpoints.ui.grouping.XBreakpointCustomGroup; import com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemNode; import com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointItemsTreeController; import com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointsCheckboxTree; +import com.intellij.xdebugger.impl.breakpoints.ui.tree.BreakpointsGroupNode; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -240,7 +242,13 @@ public class BreakpointsDialog extends DialogWrapper { return res; } }; - return new AnAction[]{group}; + List res = new ArrayList(); + res.add(group); + Object component = tree.getLastSelectedPathComponent(); + if (component instanceof BreakpointsGroupNode && ((BreakpointsGroupNode)component).getGroup() instanceof XBreakpointCustomGroup) { + res.add(new SetAsDefaultGroupAction((XBreakpointCustomGroup)((BreakpointsGroupNode)component).getGroup())); + } + return res.toArray(new AnAction[res.size()]); } }, ActionPlaces.UNKNOWN, ActionManager.getInstance()); @@ -473,7 +481,21 @@ public class BreakpointsDialog extends DialogWrapper { } } myTreeController.rebuildTree(myBreakpointItems); + } + } + private class SetAsDefaultGroupAction extends AnAction { + private final String myName; + + private SetAsDefaultGroupAction(XBreakpointCustomGroup group) { + super(group.isDefault() ? "Unset as default" : "Set as default"); + myName = group.isDefault() ? null : group.getName(); + } + + @Override + public void actionPerformed(AnActionEvent e) { + getBreakpointManager().setDefaultGroup(myName); + myTreeController.rebuildTree(myBreakpointItems); } } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroup.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroup.java index 03247fff10b0..0189fa1ba693 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroup.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroup.java @@ -16,7 +16,10 @@ package com.intellij.xdebugger.impl.breakpoints.ui.grouping; import com.intellij.icons.AllIcons; +import com.intellij.openapi.project.Project; +import com.intellij.xdebugger.XDebuggerManager; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroup; +import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,9 +30,11 @@ import javax.swing.*; */ public class XBreakpointCustomGroup extends XBreakpointGroup { private final String myName; + private final boolean myIsDefault; - public XBreakpointCustomGroup(@NotNull String name) { + public XBreakpointCustomGroup(@NotNull String name, Project project) { myName = name; + myIsDefault = name.equals(((XBreakpointManagerImpl)XDebuggerManager.getInstance(project).getBreakpointManager()).getDefaultGroup()); } @Nullable @@ -41,4 +46,8 @@ public class XBreakpointCustomGroup extends XBreakpointGroup { public String getName() { return myName; } + + public boolean isDefault() { + return myIsDefault; + } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroupingRule.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroupingRule.java index 88487f04ea9a..7628d3dddc4e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroupingRule.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/grouping/XBreakpointCustomGroupingRule.java @@ -51,7 +51,7 @@ public class XBreakpointCustomGroupingRule extends XBreakpointGroupingRule extends CheckedTreeNode { +public class BreakpointsGroupNode extends CheckedTreeNode { private final G myGroup; private final int myLevel; diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/tree/BreakpointsTreeCellRenderer.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/tree/BreakpointsTreeCellRenderer.java index 171303cbc59d..8aa3ed2faa30 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/tree/BreakpointsTreeCellRenderer.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/tree/BreakpointsTreeCellRenderer.java @@ -21,10 +21,13 @@ import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; import com.intellij.xdebugger.breakpoints.ui.XBreakpointGroup; import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointItem; +import com.intellij.xdebugger.impl.breakpoints.ui.grouping.XBreakpointCustomGroup; import javax.swing.*; class BreakpointsTreeCellRenderer { + private static SimpleTextAttributes SIMPLE_CELL_ATTRIBUTES_BOLD = SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES.derive(SimpleTextAttributes.STYLE_BOLD, null, null, null); + private static void customizeRenderer(Project project, Object value, boolean selected, @@ -38,7 +41,12 @@ class BreakpointsTreeCellRenderer { else if (value instanceof BreakpointsGroupNode) { XBreakpointGroup group = ((BreakpointsGroupNode)value).getGroup(); renderer.setIcon(group.getIcon(expanded)); - renderer.append(group.getName(), SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES); + if (group instanceof XBreakpointCustomGroup && ((XBreakpointCustomGroup)group).isDefault()) { + renderer.append(group.getName(), SIMPLE_CELL_ATTRIBUTES_BOLD); + } + else { + renderer.append(group.getName(), SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES); + } } }