mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
XDebugger: creating different editors for expression and code fragment mode
AppCode:Debugger: do not show incorrect parsing errors in evaluate dialog (OC-1434)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.evaluation;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public enum EvaluationMode {
|
||||
EXPRESSION, CODE_FRAGMENT
|
||||
}
|
||||
+17
-1
@@ -30,7 +30,23 @@ public abstract class XDebuggerEditorsProvider {
|
||||
@NotNull
|
||||
public abstract FileType getFileType();
|
||||
|
||||
/**
|
||||
* @deprecated use createDocument(Project,String,XSourcePosition,EvaluationMode) instead
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition);
|
||||
@Deprecated
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition) {
|
||||
throw new UnsupportedOperationException("This method should not be called");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Document createDocument(@NotNull Project project,
|
||||
@NotNull String text,
|
||||
@Nullable XSourcePosition sourcePosition,
|
||||
@NotNull EvaluationMode mode) {
|
||||
return createDocument(project, text, sourcePosition);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-13
@@ -25,6 +25,7 @@ import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.XDebuggerBundle;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.evaluation.EvaluationMode;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
|
||||
import com.intellij.xdebugger.impl.actions.XDebuggerActions;
|
||||
@@ -50,7 +51,7 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
|
||||
private final XDebuggerEvaluator myEvaluator;
|
||||
private final XDebugSession mySession;
|
||||
private final XDebuggerEditorsProvider myEditorsProvider;
|
||||
private EvaluationDialogMode myMode;
|
||||
private EvaluationMode myMode;
|
||||
private final XSourcePosition mySourcePosition;
|
||||
private final SwitchModeAction mySwitchModeAction;
|
||||
|
||||
@@ -87,10 +88,10 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
|
||||
}
|
||||
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_R, KeyEvent.ALT_DOWN_MASK)), getRootPane(), myDisposable);
|
||||
|
||||
EvaluationDialogMode mode = EvaluationDialogMode.EXPRESSION;
|
||||
EvaluationMode mode = EvaluationMode.EXPRESSION;
|
||||
if (text.indexOf('\n') != -1) {
|
||||
if (myEvaluator.isCodeFragmentEvaluationSupported()) {
|
||||
mode = EvaluationDialogMode.CODE_FRAGMENT;
|
||||
mode = EvaluationMode.CODE_FRAGMENT;
|
||||
}
|
||||
else {
|
||||
text = StringUtil.replace(text, "\n", " ");
|
||||
@@ -116,8 +117,8 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
|
||||
protected JButton createJButtonForAction(Action action) {
|
||||
final JButton button = super.createJButtonForAction(action);
|
||||
if (action == mySwitchModeAction) {
|
||||
int width1 = new JButton(getSwitchButtonText(EvaluationDialogMode.EXPRESSION)).getPreferredSize().width;
|
||||
int width2 = new JButton(getSwitchButtonText(EvaluationDialogMode.CODE_FRAGMENT)).getPreferredSize().width;
|
||||
int width1 = new JButton(getSwitchButtonText(EvaluationMode.EXPRESSION)).getPreferredSize().width;
|
||||
int width2 = new JButton(getSwitchButtonText(EvaluationMode.CODE_FRAGMENT)).getPreferredSize().width;
|
||||
final Dimension size = new Dimension(Math.max(width1, width2), button.getPreferredSize().height);
|
||||
button.setMinimumSize(size);
|
||||
button.setPreferredSize(size);
|
||||
@@ -129,13 +130,13 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
|
||||
return myInputComponent.getInputEditor().getText();
|
||||
}
|
||||
|
||||
private static String getSwitchButtonText(EvaluationDialogMode mode) {
|
||||
return mode != EvaluationDialogMode.EXPRESSION
|
||||
private static String getSwitchButtonText(EvaluationMode mode) {
|
||||
return mode != EvaluationMode.EXPRESSION
|
||||
? XDebuggerBundle.message("button.text.expression.mode")
|
||||
: XDebuggerBundle.message("button.text.code.fragment.mode");
|
||||
}
|
||||
|
||||
private void switchToMode(EvaluationDialogMode mode, String text) {
|
||||
private void switchToMode(EvaluationMode mode, String text) {
|
||||
if (myMode == mode) return;
|
||||
myMode = mode;
|
||||
|
||||
@@ -151,9 +152,9 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
private EvaluationInputComponent createInputComponent(EvaluationDialogMode mode, String text) {
|
||||
private EvaluationInputComponent createInputComponent(EvaluationMode mode, String text) {
|
||||
final Project project = mySession.getProject();
|
||||
if (mode == EvaluationDialogMode.EXPRESSION) {
|
||||
if (mode == EvaluationMode.EXPRESSION) {
|
||||
return new ExpressionInputComponent(project, myEditorsProvider, mySourcePosition, text);
|
||||
}
|
||||
else {
|
||||
@@ -191,12 +192,12 @@ public class XDebuggerEvaluationDialog extends DialogWrapper {
|
||||
private class SwitchModeAction extends AbstractAction {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String text = myInputComponent.getInputEditor().getText();
|
||||
if (myMode == EvaluationDialogMode.EXPRESSION) {
|
||||
switchToMode(EvaluationDialogMode.CODE_FRAGMENT, text);
|
||||
if (myMode == EvaluationMode.EXPRESSION) {
|
||||
switchToMode(EvaluationMode.CODE_FRAGMENT, text);
|
||||
}
|
||||
else {
|
||||
if (text.indexOf('\n') != -1) text = "";
|
||||
switchToMode(EvaluationDialogMode.EXPRESSION, text);
|
||||
switchToMode(EvaluationMode.EXPRESSION, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -17,10 +17,12 @@ package com.intellij.xdebugger.impl.ui;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.evaluation.EvaluationMode;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
|
||||
import com.intellij.xdebugger.impl.XDebuggerHistoryManager;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -33,14 +35,19 @@ import java.util.List;
|
||||
public abstract class XDebuggerEditorBase {
|
||||
private final Project myProject;
|
||||
private final XDebuggerEditorsProvider myDebuggerEditorsProvider;
|
||||
private final EvaluationMode myMode;
|
||||
@Nullable private final String myHistoryId;
|
||||
private final XSourcePosition mySourcePosition;
|
||||
private int myHistoryIndex;
|
||||
|
||||
protected XDebuggerEditorBase(final Project project, XDebuggerEditorsProvider debuggerEditorsProvider, @Nullable @NonNls String historyId,
|
||||
protected XDebuggerEditorBase(final Project project,
|
||||
@NotNull XDebuggerEditorsProvider debuggerEditorsProvider,
|
||||
@NotNull EvaluationMode mode,
|
||||
@Nullable @NonNls String historyId,
|
||||
final @Nullable XSourcePosition sourcePosition) {
|
||||
myProject = project;
|
||||
myDebuggerEditorsProvider = debuggerEditorsProvider;
|
||||
myMode = mode;
|
||||
myHistoryId = historyId;
|
||||
mySourcePosition = sourcePosition;
|
||||
}
|
||||
@@ -92,7 +99,7 @@ public abstract class XDebuggerEditorBase {
|
||||
}
|
||||
|
||||
protected Document createDocument(final String text) {
|
||||
return getEditorsProvider().createDocument(getProject(), text, mySourcePosition);
|
||||
return getEditorsProvider().createDocument(getProject(), text, mySourcePosition, myMode);
|
||||
}
|
||||
|
||||
public boolean canGoBackward() {
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.ui.EditorComboBoxEditor;
|
||||
import com.intellij.ui.EditorComboBoxRenderer;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.evaluation.EvaluationMode;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
|
||||
import com.intellij.xdebugger.impl.XDebuggerHistoryManager;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -42,7 +43,7 @@ public class XDebuggerExpressionComboBox extends XDebuggerEditorBase {
|
||||
|
||||
public XDebuggerExpressionComboBox(final @NotNull Project project, final @NotNull XDebuggerEditorsProvider debuggerEditorsProvider, final @Nullable @NonNls String historyId,
|
||||
final @Nullable XSourcePosition sourcePosition) {
|
||||
super(project, debuggerEditorsProvider, historyId, sourcePosition);
|
||||
super(project, debuggerEditorsProvider, EvaluationMode.EXPRESSION, historyId, sourcePosition);
|
||||
myDebuggerEditorsProvider = debuggerEditorsProvider;
|
||||
myComboBox = new ComboBox();
|
||||
myComboBox.setEditable(true);
|
||||
|
||||
+4
-3
@@ -15,11 +15,12 @@
|
||||
*/
|
||||
package com.intellij.xdebugger.impl.ui;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.EditorTextField;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.evaluation.EvaluationMode;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -37,7 +38,7 @@ public class XDebuggerMultilineEditor extends XDebuggerEditorBase {
|
||||
XDebuggerEditorsProvider debuggerEditorsProvider,
|
||||
@Nullable @NonNls String historyId,
|
||||
@Nullable XSourcePosition sourcePosition, @NotNull String text) {
|
||||
super(project, debuggerEditorsProvider, historyId, sourcePosition);
|
||||
super(project, debuggerEditorsProvider, EvaluationMode.CODE_FRAGMENT, historyId, sourcePosition);
|
||||
myEditorTextField = new EditorTextField(createDocument(text), project, debuggerEditorsProvider.getFileType()) {
|
||||
@Override
|
||||
protected EditorEx createEditor() {
|
||||
|
||||
+5
-1
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.evaluation.EvaluationMode;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
|
||||
import org.intellij.lang.xpath.XPathFileType;
|
||||
import org.intellij.plugins.xsltDebugger.BreakpointContext;
|
||||
@@ -25,7 +26,10 @@ public class XsltDebuggerEditorsProvider extends XDebuggerEditorsProvider {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Document createDocument(@NotNull Project project, @NotNull String text, @Nullable XSourcePosition sourcePosition) {
|
||||
public Document createDocument(@NotNull Project project,
|
||||
@NotNull String text,
|
||||
@Nullable XSourcePosition sourcePosition,
|
||||
@NotNull EvaluationMode mode) {
|
||||
final PsiFile psiFile = PsiFileFactory.getInstance(project)
|
||||
.createFileFromText("XPathExpr.xpath", XPathFileType.XPATH, text, LocalTimeCounter.currentTime(), true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user