IDEA-90910 Multiline breakpoint condition
authorEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 19 Apr 2016 13:47:19 +0000 (16:47 +0300)
committerEgor.Ushakov <egor.ushakov@jetbrains.com>
Tue, 19 Apr 2016 13:49:10 +0000 (16:49 +0300)
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XExpressionState.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XBreakpointActionsPanel.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/ui/XLightBreakpointPropertiesPanel.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/evaluate/CodeFragmentInputComponent.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerEditorBase.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerExpressionComboBox.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/XDebuggerExpressionEditor.java
platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/XDebuggerTreeInplaceEditor.java

index 65dc92e97ec10116890e1771155c1fc530a0407f..70e28978a48a7a8477bc1050c19bb5b5f31ffa72 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * 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.
@@ -20,6 +20,7 @@ import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.xmlb.annotations.Attribute;
 import com.intellij.util.xmlb.annotations.Text;
 import com.intellij.xdebugger.XExpression;
+import com.intellij.xdebugger.evaluation.EvaluationMode;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -39,21 +40,29 @@ public class XExpressionState {
   @Attribute("custom")
   public String myCustomInfo;
 
+  @Attribute("mode")
+  public EvaluationMode myMode = EvaluationMode.EXPRESSION;
+
   @Text
   public String myOldExpression;
 
   public XExpressionState() {
   }
 
-  public XExpressionState(boolean disabled, @NotNull String expression, String language, String customInfo) {
+  public XExpressionState(boolean disabled, @NotNull String expression, String language, String customInfo, EvaluationMode mode) {
     myDisabled = disabled;
     myExpression = expression;
     myLanguage = language;
     myCustomInfo = customInfo;
+    myMode = mode;
   }
 
   public XExpressionState(boolean disabled, XExpression expression) {
-    this(disabled, expression.getExpression(), expression.getLanguage() != null ? expression.getLanguage().getID() : null, expression.getCustomInfo());
+    this(disabled,
+         expression.getExpression(),
+         expression.getLanguage() != null ? expression.getLanguage().getID() : null,
+         expression.getCustomInfo(),
+         expression.getMode());
   }
 
   public XExpressionState(XExpression expression) {
@@ -74,6 +83,6 @@ public class XExpressionState {
     if (StringUtil.isEmptyOrSpaces(myExpression)) {
       return null;
     }
-    return new XExpressionImpl(myExpression, Language.findLanguageByID(myLanguage), myCustomInfo);
+    return new XExpressionImpl(myExpression, Language.findLanguageByID(myLanguage), myCustomInfo, myMode);
   }
 }
index 22e4e053e24d4fa247de5ed2f1349bd078c95eab..02ceba3714e8dd364e1e3f9af54c9f7aa4519432 100644 (file)
@@ -59,7 +59,7 @@ public class XBreakpointActionsPanel extends XBreakpointPropertiesSubPanel {
           onCheckboxChanged();
         }
       };
-      myLogExpressionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, LOG_EXPRESSION_HISTORY_ID, myBreakpoint.getSourcePosition());
+      myLogExpressionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, LOG_EXPRESSION_HISTORY_ID, myBreakpoint.getSourcePosition(), true);
       JComponent logExpressionComponent = myLogExpressionComboBox.getComponent();
       myLogExpressionPanel.add(logExpressionComponent, BorderLayout.CENTER);
       myLogExpressionComboBox.setEnabled(false);
index 6f334d5ef31d4ff124ba16412f04d98a71a2984b..fe8c9ae01a9dc9c3bdacdbca781c62124729b39e 100644 (file)
@@ -139,7 +139,7 @@ public class XLightBreakpointPropertiesPanel implements XSuspendPolicyPanel.Dele
     myCustomPanels = new ArrayList<>();
     if (debuggerEditorsProvider != null) {
       myConditionEnabledCheckbox = new JBCheckBox(XDebuggerBundle.message("xbreakpoints.condition.checkbox"));
-      myConditionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, CONDITION_HISTORY_ID, myBreakpoint.getSourcePosition());
+      myConditionComboBox = new XDebuggerExpressionComboBox(project, debuggerEditorsProvider, CONDITION_HISTORY_ID, myBreakpoint.getSourcePosition(), true);
       JComponent conditionComponent = myConditionComboBox.getComponent();
       conditionComponent.setBorder(JBUI.Borders.emptyRight(3));
       myConditionExpressionPanel.add(conditionComponent, BorderLayout.CENTER);
index 7039fd3eaf46aed4ee309a4a910ed00f22e7627a..a6bcc1126849bf4d32617ea87537da2ef8596b46 100644 (file)
@@ -66,10 +66,14 @@ public class CodeFragmentInputComponent extends EvaluationInputComponent {
 
   @Override
   @NotNull
-  protected XDebuggerEditorBase getInputEditor() {
+  public XDebuggerEditorBase getInputEditor() {
     return myMultilineEditor;
   }
 
+  public JPanel getMainComponent() {
+    return myMainPanel;
+  }
+
   @Override
   public void addComponent(JPanel contentPanel, JPanel resultPanel) {
     final JBSplitter splitter = new JBSplitter(true, 0.3f, 0.2f, 0.7f);
index 7fef7449e5c2d0d8ee303b759c428f6cdb00b581..7f60fe8841565d38074ae7f428134643bd79c7e7 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.xdebugger.impl.ui;
 
+import com.intellij.icons.AllIcons;
 import com.intellij.ide.DataManager;
 import com.intellij.lang.Language;
 import com.intellij.lang.LanguageUtil;
@@ -26,6 +27,8 @@ import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.fileTypes.FileType;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.ComponentWithBrowseButton;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
 import com.intellij.openapi.ui.popup.ListPopup;
 import com.intellij.openapi.util.IconLoader;
@@ -40,6 +43,7 @@ import com.intellij.xdebugger.evaluation.EvaluationMode;
 import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
 import com.intellij.xdebugger.impl.XDebuggerHistoryManager;
 import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
+import com.intellij.xdebugger.impl.evaluate.CodeFragmentInputComponent;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -119,13 +123,23 @@ public abstract class XDebuggerEditorBase {
                                                                false);
   }
 
-  protected JPanel addChooseFactoryLabel(JComponent component, boolean top) {
-    JPanel panel = new JPanel(new BorderLayout());
-    panel.add(component, BorderLayout.CENTER);
+  protected JPanel decorate(JComponent component, boolean multiline, boolean showEditor) {
+    JPanel panel = JBUI.Panels.simplePanel();
 
-    JPanel factoryPanel = new JPanel(new BorderLayout());
-    factoryPanel.add(myChooseFactory, top ? BorderLayout.NORTH : BorderLayout.CENTER);
+    JPanel factoryPanel = JBUI.Panels.simplePanel();
+    factoryPanel.add(myChooseFactory, multiline ? BorderLayout.NORTH : BorderLayout.CENTER);
     panel.add(factoryPanel, BorderLayout.WEST);
+
+    if (!multiline && showEditor) {
+      ComponentWithBrowseButton<JComponent> componentWithButton =
+        new ComponentWithBrowseButton<>(component, e -> showCodeFragmentEditor(component, this));
+      componentWithButton.setButtonIcon(AllIcons.Actions.ShowViewer);
+      componentWithButton.getButton().setDisabledIcon(IconLoader.getDisabledIcon(AllIcons.Actions.ShowViewer));
+      panel.add(componentWithButton, BorderLayout.CENTER);
+    } else {
+      panel.add(component, BorderLayout.CENTER);
+    }
+
     return panel;
   }
 
@@ -164,8 +178,8 @@ public abstract class XDebuggerEditorBase {
       if (language == null) {
         language = LanguageUtil.getFileTypeLanguage(getEditorsProvider().getFileType());
       }
+      text = new XExpressionImpl(text.getExpression(), language, text.getCustomInfo(), text.getMode());
     }
-    text = new XExpressionImpl(text.getExpression(), language, text.getCustomInfo(), getMode());
 
     Collection<Language> languages = getEditorsProvider().getSupportedLanguages(myProject, mySourcePosition);
     boolean many = languages.size() > 1;
@@ -267,4 +281,44 @@ public abstract class XDebuggerEditorBase {
       setExpression(expressions.get(myHistoryIndex));
     }
   }
+
+  private void showCodeFragmentEditor(Component parent, XDebuggerEditorBase baseEditor) {
+    DialogWrapper dialog = new DialogWrapper(parent, true) {
+      CodeFragmentInputComponent inputComponent =
+        new CodeFragmentInputComponent(baseEditor.getProject(), baseEditor.getEditorsProvider(), mySourcePosition,
+                                       XExpressionImpl.changeMode(baseEditor.getExpression(), EvaluationMode.CODE_FRAGMENT),
+                                       null, null);
+
+      {
+        setTitle("Edit");
+        init();
+      }
+
+      @Nullable
+      @Override
+      protected String getDimensionServiceKey() {
+        return "#xdebugger.code.fragment.editor";
+      }
+
+      @Nullable
+      @Override
+      protected JComponent createCenterPanel() {
+        return inputComponent.getMainComponent();
+      }
+
+      @Override
+      protected void doOKAction() {
+        super.doOKAction();
+        baseEditor.setExpression(inputComponent.getInputEditor().getExpression());
+        IdeFocusManager.findInstance().requestFocus(baseEditor.getEditorComponent(), false);
+      }
+
+      @Nullable
+      @Override
+      public JComponent getPreferredFocusedComponent() {
+        return inputComponent.getInputEditor().getPreferredFocusedComponent();
+      }
+    };
+    dialog.show();
+  }
 }
index 3d394a79d34af002fe8cc8fabd159289ea106578..0bf83c4d51bde97001dffc31d08f3d3095d1379a 100644 (file)
@@ -41,14 +41,14 @@ import java.awt.*;
  */
 public class XDebuggerExpressionComboBox extends XDebuggerEditorBase {
   private final JComponent myComponent;
-  private final ComboBox myComboBox;
+  private final ComboBox<XExpression> myComboBox;
   private EditorComboBoxEditor myEditor;
   private XExpression myExpression;
 
-  public XDebuggerExpressionComboBox(final @NotNull Project project, final @NotNull XDebuggerEditorsProvider debuggerEditorsProvider, final @Nullable @NonNls String historyId,
-                                     final @Nullable XSourcePosition sourcePosition) {
+  public XDebuggerExpressionComboBox(@NotNull Project project, @NotNull XDebuggerEditorsProvider debuggerEditorsProvider, @Nullable @NonNls String historyId,
+                                     @Nullable XSourcePosition sourcePosition, boolean showEditor) {
     super(project, debuggerEditorsProvider, EvaluationMode.EXPRESSION, historyId, sourcePosition);
-    myComboBox = new ComboBox(100);
+    myComboBox = new ComboBox<>(100);
     myComboBox.setEditable(true);
     myExpression = XExpressionImpl.EMPTY_EXPRESSION;
     Dimension minimumSize = new Dimension(myComboBox.getMinimumSize());
@@ -56,7 +56,7 @@ public class XDebuggerExpressionComboBox extends XDebuggerEditorBase {
     myComboBox.setMinimumSize(minimumSize);
     initEditor();
     fillComboBox();
-    myComponent = addChooseFactoryLabel(myComboBox, false);
+    myComponent = decorate(myComboBox, false, showEditor);
   }
 
   public ComboBox getComboBox() {
@@ -146,7 +146,7 @@ public class XDebuggerExpressionComboBox extends XDebuggerEditorBase {
   public XExpression getExpression() {
     Object document = myEditor.getItem();
     if (document instanceof Document) { // sometimes null on Mac
-      return getEditorsProvider().createExpression(getProject(), (Document)document, myExpression.getLanguage(), EvaluationMode.EXPRESSION);
+      return getEditorsProvider().createExpression(getProject(), (Document)document, myExpression.getLanguage(), myExpression.getMode());
     }
     return myExpression;
   }
index 056504e7d0ac93cebf19b6215dcfd6b18020eea9..ef7a7c4aad1986a01c701602e57d3edeacfae7b1 100644 (file)
@@ -78,7 +78,7 @@ public class XDebuggerExpressionEditor extends XDebuggerEditorBase {
       myEditorTextField.setFontInheritedFromLAF(false);
       myEditorTextField.setFont(EditorUtil.getEditorFont());
     }
-    myComponent = addChooseFactoryLabel(myEditorTextField, multiline);
+    myComponent = decorate(myEditorTextField, multiline, false);
   }
 
   @Override
index bd2a2a93d4deb044a32c365bca9a66c78a812cd8..c10d2ecdb25c700568b2febed25a2cd18c9fa58f 100644 (file)
@@ -37,7 +37,7 @@ public abstract class XDebuggerTreeInplaceEditor extends TreeInplaceEditor {
   public XDebuggerTreeInplaceEditor(final XDebuggerTreeNode node, @NonNls final String historyId) {
     myNode = node;
     myTree = myNode.getTree();
-    myExpressionEditor = new XDebuggerExpressionComboBox(myTree.getProject(), myTree.getEditorsProvider(), historyId, myTree.getSourcePosition());
+    myExpressionEditor = new XDebuggerExpressionComboBox(myTree.getProject(), myTree.getEditorsProvider(), historyId, myTree.getSourcePosition(), false);
   }
 
   @Override