From 5f59312fac2b7b507af4e519aa1601e86aeb26bf Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 13 Apr 2018 17:44:03 +0300 Subject: [PATCH] IDEA-130826 Prompt user before removing breakpoints with conditions --- .../src/messages/XDebuggerBundle.properties | 4 +++ .../xdebugger/impl/XDebuggerUtilImpl.java | 28 ++++++++++++++++++- .../RemoveBreakpointGutterIconAction.java | 20 ++----------- .../impl/breakpoints/XBreakpointItem.java | 21 ++------------ .../impl/breakpoints/XLineBreakpointImpl.java | 8 ++---- .../impl/settings/GeneralConfigurableUi.form | 12 ++++++-- .../impl/settings/GeneralConfigurableUi.java | 22 ++++----------- .../settings/XDebuggerGeneralSettings.java | 26 ++++++++--------- 8 files changed, 67 insertions(+), 74 deletions(-) diff --git a/platform/platform-resources-en/src/messages/XDebuggerBundle.properties b/platform/platform-resources-en/src/messages/XDebuggerBundle.properties index da1ca1e1ea15..88ed5368b334 100644 --- a/platform/platform-resources-en/src/messages/XDebuggerBundle.properties +++ b/platform/platform-resources-en/src/messages/XDebuggerBundle.properties @@ -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 \ No newline at end of file diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java index 497d6abca734..52401c4f934c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java @@ -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

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)); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java index 44f6874bd955..9b246db9557e 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/RemoveBreakpointGutterIconAction.java @@ -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); } } } \ No newline at end of file diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointItem.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointItem.java index 89aa146a69c9..9b1b302006f3 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointItem.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XBreakpointItem.java @@ -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 diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java index a1292ab4380e..85eb1a056d07 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java @@ -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

extends XBreak } public void remove() { - XBreakpointManager breakpointManager = XDebuggerManager.getInstance(getProject()).getBreakpointManager(); - WriteAction.run(() -> breakpointManager.removeBreakpoint(XLineBreakpointImpl.this)); + XDebuggerUtilImpl.removeBreakpointWithConfirmation(getProject(), XLineBreakpointImpl.this); } @Override diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.form b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.form index 819614f6ed30..e6b5981ad969 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.form +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.form @@ -1,6 +1,6 @@

- + @@ -18,7 +18,7 @@ - + @@ -84,6 +84,14 @@ + + + + + + + + diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.java index 1cf9eda774a7..a83ac80fb944 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/GeneralConfigurableUi.java @@ -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 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 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 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 settings.setShowDebuggerOnBreakpoint(myShowDebugWindowOnCheckBox.isSelected()); settings.setScrollToCenter(myScrollExecutionPointToCheckBox.isSelected()); Registry.get("debugger.click.disable.breakpoints").setValue(myDragToTheEditorRadioButton.isSelected()); + settings.setConfirmBreakpointRemoval(myConfirmBreakpointRemoval.isSelected()); } @NotNull diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerGeneralSettings.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerGeneralSettings.java index 451d1dc59687..752cb979b8b3 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerGeneralSettings.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/settings/XDebuggerGeneralSettings.java @@ -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; + } }