IDEA-130826 Prompt user before removing breakpoints with conditions

This commit is contained in:
Egor Ushakov
2018-04-13 17:44:33 +03:00
parent 157a19c220
commit 5f59312fac
8 changed files with 67 additions and 74 deletions
@@ -161,3 +161,7 @@ ad.extra.selection.shortcut=You can also choose an item with {0}
settings.drag.to.remove.breakpoint=Remove breakpoint:
settings.drag.to.remove.breakpoint.click=Click
settings.drag.to.remove.breakpoint.drag=Drag to the editor area
settings.confirm.breakpoint.removal=Confirm removal of conditional or logging breakpoints
message.confirm.breakpoint.removal.title=Confirm Removal
message.confirm.breakpoint.removal.message=Breakpoint contains condition or log expression
@@ -1,6 +1,7 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl;
import com.intellij.CommonBundle;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.lang.Language;
@@ -24,6 +25,8 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.util.TextRange;
@@ -157,7 +160,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
XLineBreakpoint<P> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
if (breakpoint != null) {
if (!temporary && canRemove) {
WriteAction.run(() -> breakpointManager.removeBreakpoint(breakpoint));
removeBreakpointWithConfirmation(project, breakpoint);
}
return resolvedPromise();
}
@@ -301,6 +304,29 @@ public class XDebuggerUtilImpl extends XDebuggerUtil {
res.setResult(WriteAction.compute(() -> breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)));
}
public static void removeBreakpointWithConfirmation(final Project project, final XBreakpoint<?> breakpoint) {
if ((isEmptyExpression(breakpoint.getConditionExpression()) && isEmptyExpression(breakpoint.getLogExpressionObject())) ||
ApplicationManager.getApplication().isHeadlessEnvironment() ||
ApplicationManager.getApplication().isUnitTestMode() ||
!XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isConfirmBreakpointRemoval() ||
Messages.showOkCancelDialog(XDebuggerBundle.message("message.confirm.breakpoint.removal.message"),
XDebuggerBundle.message("message.confirm.breakpoint.removal.title"),
CommonBundle.message("button.remove"),
Messages.CANCEL_BUTTON,
Messages.getQuestionIcon(),
new DialogWrapper.DoNotAskOption.Adapter() {
@Override
public void rememberChoice(boolean isSelected, int exitCode) {
if (isSelected) {
XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings()
.setConfirmBreakpointRemoval(false);
}
}
}) == Messages.OK) {
getInstance().removeBreakpoint(project, breakpoint);
}
}
@Override
public void removeBreakpoint(final Project project, final XBreakpoint<?> breakpoint) {
WriteAction.run(() -> XDebuggerManager.getInstance(project).getBreakpointManager().removeBreakpoint(breakpoint));
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2016 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.breakpoints;
import com.intellij.openapi.actionSystem.ActionManager;
@@ -20,7 +6,7 @@ import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.xdebugger.XDebuggerBundle;
import com.intellij.xdebugger.XDebuggerUtil;
import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
@@ -40,7 +26,7 @@ class RemoveBreakpointGutterIconAction extends DumbAwareAction {
InputEvent event = e.getInputEvent();
// for mouse events check that no modifiers applied
if (!(event instanceof MouseEvent) || event.getModifiersEx() == 0) {
XDebuggerUtil.getInstance().removeBreakpoint(myBreakpoint.getProject(), myBreakpoint);
XDebuggerUtilImpl.removeBreakpointWithConfirmation(myBreakpoint.getProject(), myBreakpoint);
}
}
}
@@ -1,21 +1,6 @@
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.breakpoints;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.pom.Navigatable;
@@ -24,6 +9,7 @@ import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.popup.util.DetailView;
import com.intellij.xdebugger.XDebuggerUtil;
import com.intellij.xdebugger.XSourcePosition;
import com.intellij.xdebugger.breakpoints.XBreakpoint;
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointItem;
@@ -159,8 +145,7 @@ class XBreakpointItem extends BreakpointItem {
@Override
public void removed(Project project) {
final XBreakpointManagerImpl breakpointManager = getManager();
WriteAction.run(() -> breakpointManager.removeBreakpoint(myBreakpoint));
XDebuggerUtil.getInstance().removeBreakpoint(project, myBreakpoint);
}
@Override
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.breakpoints;
import com.intellij.openapi.actionSystem.AnAction;
@@ -30,6 +28,7 @@ import com.intellij.xdebugger.breakpoints.XBreakpointManager;
import com.intellij.xdebugger.breakpoints.XBreakpointProperties;
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
import com.intellij.xdebugger.ui.DebuggerColors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -227,8 +226,7 @@ public class XLineBreakpointImpl<P extends XBreakpointProperties> extends XBreak
}
public void remove() {
XBreakpointManager breakpointManager = XDebuggerManager.getInstance(getProject()).getBreakpointManager();
WriteAction.run(() -> breakpointManager.removeBreakpoint(XLineBreakpointImpl.this));
XDebuggerUtilImpl.removeBreakpointWithConfirmation(getProject(), XLineBreakpointImpl.this);
}
@Override
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.xdebugger.impl.settings.GeneralConfigurableUi">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="6" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
@@ -18,7 +18,7 @@
</component>
<vspacer id="8e2ed">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="fc652" class="javax.swing.JCheckBox" binding="focusApplicationOnBreakpointCheckBox" default-binding="true">
@@ -84,6 +84,14 @@
</component>
</children>
</grid>
<component id="e8e46" class="javax.swing.JCheckBox" binding="myConfirmBreakpointRemoval">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/XDebuggerBundle" key="settings.confirm.breakpoint.removal"/>
</properties>
</component>
</children>
</grid>
<buttonGroups>
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.settings;
import com.intellij.openapi.options.ConfigurableUi;
@@ -29,6 +15,7 @@ class GeneralConfigurableUi implements ConfigurableUi<XDebuggerGeneralSettings>
private JCheckBox myScrollExecutionPointToCheckBox;
private JRadioButton myClickRadioButton;
private JRadioButton myDragToTheEditorRadioButton;
private JCheckBox myConfirmBreakpointRemoval;
@Override
public void reset(@NotNull XDebuggerGeneralSettings settings) {
@@ -38,6 +25,7 @@ class GeneralConfigurableUi implements ConfigurableUi<XDebuggerGeneralSettings>
myScrollExecutionPointToCheckBox.setSelected(settings.isScrollToCenter());
myClickRadioButton.setSelected(!Registry.is("debugger.click.disable.breakpoints"));
myDragToTheEditorRadioButton.setSelected(Registry.is("debugger.click.disable.breakpoints"));
myConfirmBreakpointRemoval.setSelected(settings.isConfirmBreakpointRemoval());
}
@Override
@@ -46,7 +34,8 @@ class GeneralConfigurableUi implements ConfigurableUi<XDebuggerGeneralSettings>
hideDebugWindowCheckBox.isSelected() != settings.isHideDebuggerOnProcessTermination() ||
myShowDebugWindowOnCheckBox.isSelected() != settings.isShowDebuggerOnBreakpoint() ||
myScrollExecutionPointToCheckBox.isSelected() != settings.isScrollToCenter() ||
myDragToTheEditorRadioButton.isSelected() != Registry.is("debugger.click.disable.breakpoints");
myDragToTheEditorRadioButton.isSelected() != Registry.is("debugger.click.disable.breakpoints") ||
myConfirmBreakpointRemoval.isSelected() != settings.isConfirmBreakpointRemoval();
}
@Override
@@ -56,6 +45,7 @@ class GeneralConfigurableUi implements ConfigurableUi<XDebuggerGeneralSettings>
settings.setShowDebuggerOnBreakpoint(myShowDebugWindowOnCheckBox.isSelected());
settings.setScrollToCenter(myScrollExecutionPointToCheckBox.isSelected());
Registry.get("debugger.click.disable.breakpoints").setValue(myDragToTheEditorRadioButton.isSelected());
settings.setConfirmBreakpointRemoval(myConfirmBreakpointRemoval.isSelected());
}
@NotNull
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.xdebugger.impl.settings;
import com.intellij.util.xmlb.annotations.Tag;
@@ -29,6 +15,7 @@ public class XDebuggerGeneralSettings {
private boolean hideDebuggerOnProcessTermination;
private boolean myShowDebuggerOnBreakpoint = true;
private boolean myScrollToCenter = false;
private boolean myConfirmBreakpointRemoval = true;
@Tag("evaluation-dialog-mode")
public EvaluationMode getEvaluationDialogMode() {
@@ -72,4 +59,13 @@ public class XDebuggerGeneralSettings {
public void setScrollToCenter(boolean scrollToCenter) {
myScrollToCenter = scrollToCenter;
}
@Tag("confirm-breakpoint-removal")
public boolean isConfirmBreakpointRemoval() {
return myConfirmBreakpointRemoval;
}
public void setConfirmBreakpointRemoval(boolean confirmBreakpointRemoval) {
myConfirmBreakpointRemoval = confirmBreakpointRemoval;
}
}