IDEA-155080 - add soft wrap to context menu

This commit is contained in:
Egor.Ushakov
2017-09-06 15:35:28 +03:00
parent 1d8af6a290
commit 05f6018e7b
3 changed files with 29 additions and 18 deletions
@@ -843,6 +843,11 @@
<reference ref="XDebugger.ValueGroup"/>
</group>
<group id="XDebugger.Evaluate.Code.Fragment.Editor.Popup">
<reference ref="BasicEditorPopupMenu"/>
<reference ref="EditorToggleUseSoftWraps"/>
</group>
<group id="XDebugger.Settings" icon="AllIcons.General.SecondaryGroup" popup="true">
<action id="XDebugger.Inline" class="com.intellij.xdebugger.impl.actions.UseInlineDebuggerAction"/>
<separator/>
@@ -17,12 +17,14 @@ package com.intellij.xdebugger.impl.ui;
import com.intellij.icons.AllIcons;
import com.intellij.ide.DataManager;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.lang.Language;
import com.intellij.lang.LanguageUtil;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actions.AbstractToggleUseSoftWrapsAction;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.keymap.KeymapUtil;
@@ -456,7 +458,11 @@ public abstract class XDebuggerEditorBase implements Expandable {
Editor baseEditor = getEditor();
if (baseEditor != null) {
WriteAction.run(() -> baseEditor.getDocument().setText(expressionEditor.getExpression().getExpression()));
copyCaretPosition(expressionEditor.getEditor(), baseEditor);
Editor newEditor = expressionEditor.getEditor();
if (newEditor != null) {
copyCaretPosition(newEditor, baseEditor);
PropertiesComponent.getInstance().setValue(SOFT_WRAPS_KEY, newEditor.getSoftWrapModel().isSoftWrappingEnabled());
}
}
myExpandedPopup = null;
return true;
@@ -487,6 +493,8 @@ public abstract class XDebuggerEditorBase implements Expandable {
EditorEx editor = (EditorEx)expressionEditor.getEditor();
copyCaretPosition(getEditor(), editor);
prepareEditor(editor);
editor.getSettings().setUseSoftWraps(isUseSoftWraps());
editor.setContextMenuGroupId("XDebugger.Evaluate.Code.Fragment.Editor.Popup");
ErrorStripeEditorCustomization.DISABLED.customize(editor);
// TODO: copied from ExpandableTextField
@@ -560,4 +568,18 @@ public abstract class XDebuggerEditorBase implements Expandable {
return isEnabled() ? ENABLED_COLOR : DISABLED_COLOR;
}
}
private static final String SOFT_WRAPS_KEY = "XDebuggerExpressionEditor_Use_Soft_Wraps";
public boolean isUseSoftWraps() {
return PropertiesComponent.getInstance().getBoolean(SOFT_WRAPS_KEY);
}
public void setUseSoftWraps(boolean use) {
PropertiesComponent.getInstance().setValue(SOFT_WRAPS_KEY, use);
Editor editor = getEditor();
if (editor != null) {
AbstractToggleUseSoftWrapsAction.toggleSoftWraps(editor, null, use);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* 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.
@@ -15,12 +15,10 @@
*/
package com.intellij.xdebugger.impl.ui;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actions.AbstractToggleUseSoftWrapsAction;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.project.Project;
@@ -134,18 +132,4 @@ public class XDebuggerExpressionEditor extends XDebuggerEditorBase {
public void selectAll() {
myEditorTextField.selectAll();
}
private static final String SOFT_WRAPS_KEY = "XDebuggerExpressionEditor_Use_Soft_Wraps";
public boolean isUseSoftWraps() {
return PropertiesComponent.getInstance().getBoolean(SOFT_WRAPS_KEY);
}
public void setUseSoftWraps(boolean use) {
PropertiesComponent.getInstance().setValue(SOFT_WRAPS_KEY, use);
Editor editor = getEditor();
if (editor != null) {
AbstractToggleUseSoftWrapsAction.toggleSoftWraps(editor, null, use);
}
}
}