2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.xdebugger.impl.ui;
18 import com.intellij.lang.Language;
19 import com.intellij.openapi.actionSystem.CommonDataKeys;
20 import com.intellij.openapi.actionSystem.LangDataKeys;
21 import com.intellij.openapi.editor.Editor;
22 import com.intellij.openapi.editor.ex.EditorEx;
23 import com.intellij.openapi.editor.ex.util.EditorUtil;
24 import com.intellij.openapi.fileTypes.FileType;
25 import com.intellij.openapi.project.Project;
26 import com.intellij.psi.PsiDocumentManager;
27 import com.intellij.ui.EditorTextField;
28 import com.intellij.xdebugger.XExpression;
29 import com.intellij.xdebugger.XSourcePosition;
30 import com.intellij.xdebugger.evaluation.EvaluationMode;
31 import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
32 import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
33 import org.jetbrains.annotations.NonNls;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
42 public class XDebuggerExpressionEditor extends XDebuggerEditorBase {
43 private final JComponent myComponent;
44 private final EditorTextField myEditorTextField;
45 private XExpression myExpression;
47 public XDebuggerExpressionEditor(Project project,
48 XDebuggerEditorsProvider debuggerEditorsProvider,
49 @Nullable @NonNls String historyId,
50 @Nullable XSourcePosition sourcePosition,
51 @NotNull XExpression text,
52 final boolean multiline) {
53 super(project, debuggerEditorsProvider, multiline ? EvaluationMode.CODE_FRAGMENT : EvaluationMode.EXPRESSION, historyId, sourcePosition);
54 myExpression = XExpressionImpl.changeMode(text, getMode());
55 myEditorTextField = new EditorTextField(createDocument(myExpression), project, debuggerEditorsProvider.getFileType()) {
57 protected EditorEx createEditor() {
58 final EditorEx editor = super.createEditor();
59 editor.setOneLineMode(!multiline);
60 editor.setVerticalScrollbarVisible(multiline);
61 editor.getColorsScheme().setEditorFontName(getFont().getFontName());
62 editor.getColorsScheme().setEditorFontSize(getFont().getSize());
67 public Object getData(String dataId) {
68 if (LangDataKeys.CONTEXT_LANGUAGES.is(dataId)) {
69 return new Language[]{myExpression.getLanguage()};
70 } else if (CommonDataKeys.PSI_FILE.is(dataId)) {
71 return PsiDocumentManager.getInstance(getProject()).getPsiFile(getDocument());
73 return super.getData(dataId);
77 protected boolean isOneLineMode() {
81 myEditorTextField.setFontInheritedFromLAF(false);
82 myEditorTextField.setFont(EditorUtil.getEditorFont());
83 myComponent = addChooseFactoryLabel(myEditorTextField, multiline);
87 public JComponent getComponent() {
92 protected void doSetText(XExpression text) {
94 Language language = text.getLanguage();
95 FileType fileType = language != null ? language.getAssociatedFileType() : getEditorsProvider().getFileType();
96 myEditorTextField.setNewDocumentAndFileType(fileType, createDocument(text));
100 public XExpression getExpression() {
101 return getEditorsProvider().createExpression(getProject(), myEditorTextField.getDocument(), myExpression.getLanguage(), getMode());
106 public JComponent getPreferredFocusedComponent() {
107 final Editor editor = myEditorTextField.getEditor();
108 return editor != null ? editor.getContentComponent() : null;
113 public Editor getEditor() {
114 return myEditorTextField.getEditor();
118 public void selectAll() {
119 myEditorTextField.selectAll();