IDEA-89608 Should be able to set editor view options like soft wraps for certain file types

This commit is contained in:
Dmitry Batrak
2019-01-31 17:11:52 +03:00
parent daa1611ffb
commit 3271076d61
11 changed files with 121 additions and 71 deletions
@@ -438,7 +438,7 @@
</component>
</children>
</grid>
<grid id="7bb4" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="7bb4" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="true" hgap="-1" vgap="0">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -449,36 +449,23 @@
</clientProperties>
<border type="none" title-resource-bundle="messages/ApplicationBundle" title-key="group.soft.wraps"/>
<children>
<vspacer id="32f7b">
<constraints>
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="2a6d" class="javax.swing.JCheckBox" binding="myCbUseSoftWrapsAtEditor">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="messages/ApplicationBundle" key="checkbox.use.soft.wraps.at.editor"/>
</properties>
</component>
<component id="42c6f" class="javax.swing.JCheckBox" binding="myCbShowSoftWrapsOnlyOnCaretLine">
<constraints>
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="messages/ApplicationBundle" key="checkbox.show.softwraps.only.for.caret.line"/>
</properties>
</component>
<component id="579d0" class="javax.swing.JCheckBox" binding="myCbUseCustomSoftWrapIndent">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="318" height="22"/>
<preferred-size width="378" height="-1"/>
</grid>
</constraints>
<properties>
<enabled value="false"/>
<enabled value="true"/>
<text resource-bundle="messages/ApplicationBundle" key="checkbox.use.custom.soft.wraps.indent"/>
</properties>
</component>
@@ -487,7 +474,7 @@
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="false"/>
<enabled value="true"/>
<text value=""/>
</properties>
</component>
@@ -499,6 +486,31 @@
<text resource-bundle="messages/ApplicationBundle" key="label.use.custom.soft.wraps.indent"/>
</properties>
</component>
<grid id="8800e" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="2a6d" class="javax.swing.JCheckBox" binding="myCbUseSoftWrapsAtEditor">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="false"/>
<text resource-bundle="messages/ApplicationBundle" key="checkbox.use.soft.wraps.at.editor"/>
</properties>
</component>
<component id="2a016" class="com.intellij.ui.components.JBTextField" binding="mySoftWrapFileMasks">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</children>
@@ -1,4 +1,4 @@
// 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.
// Copyright 2000-2019 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.application.options.editor;
@@ -18,7 +18,6 @@ import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import com.intellij.openapi.editor.richcopy.settings.RichCopySettings;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -39,6 +38,7 @@ import com.intellij.profile.codeInspection.ui.ErrorOptionsProviderEP;
import com.intellij.ui.ListCellRendererWrapper;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -98,6 +98,7 @@ public class EditorOptionsPanel extends CompositeConfigurable<ErrorOptionsProvid
private JCheckBox myShowWhitespacesModificationsInLSTGutterCheckBox;
private JCheckBox myCbKeepTrailingSpacesOnCaretLine;
private JTextField myRecentLocationsLimitField;
private JBTextField mySoftWrapFileMasks;
private static final String ACTIVE_COLOR_SCHEME = ApplicationBundle.message("combobox.richcopy.color.scheme.active");
private static final UINumericRange RECENT_FILES_RANGE = new UINumericRange(50, 1, 500);
@@ -110,6 +111,8 @@ public class EditorOptionsPanel extends CompositeConfigurable<ErrorOptionsProvid
myCbEnableWheelFontChange.setText(ApplicationBundle.message("checkbox.enable.ctrl.mousewheel.changes.font.size.macos"));
}
mySoftWrapFileMasks.getEmptyText().setText(ApplicationBundle.message("soft.wraps.file.masks.empty.text"));
myStripTrailingSpacesCombo.addItem(STRIP_CHANGED);
myStripTrailingSpacesCombo.addItem(STRIP_ALL);
myStripTrailingSpacesCombo.addItem(STRIP_NONE);
@@ -167,7 +170,8 @@ public class EditorOptionsPanel extends CompositeConfigurable<ErrorOptionsProvid
// Virtual space
myCbUseSoftWrapsAtEditor.setSelected(editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR));
myCbUseSoftWrapsAtEditor.setSelected(editorSettings.isUseSoftWraps());
mySoftWrapFileMasks.setText(editorSettings.getSoftWrapFileMasks());
myCbUseCustomSoftWrapIndent.setSelected(editorSettings.isUseCustomSoftWrapIndent());
myCustomSoftWrapIndent.setText(Integer.toString(editorSettings.getCustomSoftWrapIndent()));
myCbShowSoftWrapsOnlyOnCaretLine.setSelected(!editorSettings.isAllSoftWrapsShown());
@@ -261,7 +265,8 @@ public class EditorOptionsPanel extends CompositeConfigurable<ErrorOptionsProvid
// Virtual space
editorSettings.setUseSoftWraps(myCbUseSoftWrapsAtEditor.isSelected(), SoftWrapAppliancePlaces.MAIN_EDITOR);
editorSettings.setUseSoftWraps(myCbUseSoftWrapsAtEditor.isSelected());
editorSettings.setSoftWrapFileMasks(mySoftWrapFileMasks.getText());
editorSettings.setUseCustomSoftWrapIndent(myCbUseCustomSoftWrapIndent.isSelected());
editorSettings.setCustomSoftWrapIndent(getCustomSoftWrapIndent());
editorSettings.setAllSoftwrapsShown(!myCbShowSoftWrapsOnlyOnCaretLine.isSelected());
@@ -449,7 +454,8 @@ public class EditorOptionsPanel extends CompositeConfigurable<ErrorOptionsProvid
isModified |= isModified(myCbHighlightIdentifierUnderCaret, codeInsightSettings.HIGHLIGHT_IDENTIFIER_UNDER_CARET);
// Virtual space
isModified |= isModified(myCbUseSoftWrapsAtEditor, editorSettings.isUseSoftWraps(SoftWrapAppliancePlaces.MAIN_EDITOR));
isModified |= isModified(myCbUseSoftWrapsAtEditor, editorSettings.isUseSoftWraps());
isModified |= !mySoftWrapFileMasks.getText().equals(editorSettings.getSoftWrapFileMasks());
isModified |= isModified(myCbUseCustomSoftWrapIndent, editorSettings.isUseCustomSoftWrapIndent());
isModified |= editorSettings.getCustomSoftWrapIndent() != getCustomSoftWrapIndent();
isModified |= isModified(myCbShowSoftWrapsOnlyOnCaretLine, !editorSettings.isAllSoftWrapsShown());
@@ -542,22 +548,12 @@ public class EditorOptionsPanel extends CompositeConfigurable<ErrorOptionsProvid
}
private void initSoftWrapsSettingsProcessing() {
ItemListener listener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
updateSoftWrapSettingsRepresentation();
}
};
myCbUseSoftWrapsAtEditor.addItemListener(listener);
myCbUseCustomSoftWrapIndent.addItemListener(listener);
myCbUseCustomSoftWrapIndent.addItemListener(e -> updateSoftWrapSettingsRepresentation());
}
private void updateSoftWrapSettingsRepresentation() {
boolean softWrapsEnabled = myCbUseSoftWrapsAtEditor.isSelected();
myCbUseCustomSoftWrapIndent.setEnabled(softWrapsEnabled);
myCustomSoftWrapIndent.setEnabled(myCbUseCustomSoftWrapIndent.isEnabled() && myCbUseCustomSoftWrapIndent.isSelected());
myCustomSoftWrapIndentLabel.setEnabled(myCustomSoftWrapIndent.isEnabled());
myCbShowSoftWrapsOnlyOnCaretLine.setEnabled(softWrapsEnabled);
myCustomSoftWrapIndent.setEnabled(myCbUseCustomSoftWrapIndent.isSelected());
myCustomSoftWrapIndentLabel.setEnabled(myCbUseCustomSoftWrapIndent.isSelected());
}
private void initVcsSettingsProcessing() {
@@ -1,9 +1,13 @@
// 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.application.options.editor;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.project.Project;
import javax.swing.*;
/**
* @author Sergey.Malenkov
*/
@@ -12,4 +16,14 @@ public class EditorOptionsTopHitProvider extends EditorOptionsTopHitProviderBase
protected Configurable getConfigurable(Project project) {
return new EditorOptionsPanel();
}
@Override
protected String getOptionName(JCheckBox checkbox) {
String optionName = super.getOptionName(checkbox);
if (optionName != null && optionName.contains(ApplicationBundle.message("checkbox.use.soft.wraps.at.editor"))) {
String masks = EditorSettingsExternalizable.getInstance().getSoftWrapFileMasks();
optionName += masks.isEmpty() ? ApplicationBundle.message("soft.wraps.file.masks.empty.text") : masks;
}
return optionName;
}
}
@@ -0,0 +1,15 @@
// Copyright 2000-2019 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.openapi.editor.actions;
import com.intellij.application.options.editor.EditorOptionsPanel;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull;
public class ConfigureSoftWrapsAction extends DumbAwareAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
ShowSettingsUtil.getInstance().showSettingsDialog(e.getProject(), EditorOptionsPanel.class);
}
}
@@ -1,24 +0,0 @@
/*
* 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.
*/
package com.intellij.openapi.editor.actions;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
public class ToggleSoftWrapsGloballyAction extends AbstractToggleUseSoftWrapsAction {
public ToggleSoftWrapsGloballyAction() {
super(SoftWrapAppliancePlaces.MAIN_EDITOR, true);
}
}
@@ -28,10 +28,14 @@ public class EditorSettingsExternalizable implements PersistentStateComponent<Ed
public static final UINumericRange BLINKING_RANGE = new UINumericRange(500, 10, 1500);
public static final UINumericRange QUICK_DOC_DELAY_RANGE = new UINumericRange(500, 1, 5000);
private static final String SOFT_WRAP_FILE_MASKS_ENABLED_DEFAULT = "*";
private static final String SOFT_WRAP_FILE_MASKS_DISABLED_DEFAULT = "*.md; *.txt; *.rst; *.adoc";
//Q: make it interface?
public static final class OptionSet {
public String LINE_SEPARATOR;
public String USE_SOFT_WRAPS;
public String SOFT_WRAP_FILE_MASKS;
public boolean USE_CUSTOM_SOFT_WRAP_INDENT = false;
public int CUSTOM_SOFT_WRAP_INDENT = 0;
public boolean IS_VIRTUAL_SPACE = false;
@@ -371,6 +375,7 @@ public class EditorSettingsExternalizable implements PersistentStateComponent<Ed
myPlacesToUseSoftWraps.remove(place);
}
storeRawSoftWraps();
if (place == SoftWrapAppliancePlaces.MAIN_EDITOR) setSoftWrapFileMasks(getSoftWrapFileMasks());
}
public boolean isUseCustomSoftWrapIndent() {
@@ -624,4 +629,15 @@ public class EditorSettingsExternalizable implements PersistentStateComponent<Ed
public void setKeepTrailingSpacesOnCaretLine(boolean keep) {
myOptions.KEEP_TRAILING_SPACE_ON_CARET_LINE = keep;
}
@NotNull
public String getSoftWrapFileMasks() {
String storedValue = myOptions.SOFT_WRAP_FILE_MASKS;
if (storedValue != null) return storedValue;
return isUseSoftWraps() ? SOFT_WRAP_FILE_MASKS_ENABLED_DEFAULT : SOFT_WRAP_FILE_MASKS_DISABLED_DEFAULT;
}
public void setSoftWrapFileMasks(@NotNull String value) {
myOptions.SOFT_WRAP_FILE_MASKS = value;
}
}
@@ -12,12 +12,15 @@ import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.impl.softwrap.SoftWrapAppliancePlaces;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.util.PatternUtil;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -624,8 +627,24 @@ public class SettingsImpl implements EditorSettings {
@Override
public boolean isUseSoftWraps() {
return myUseSoftWraps != null ? myUseSoftWraps.booleanValue()
: EditorSettingsExternalizable.getInstance().isUseSoftWraps(mySoftWrapAppliancePlace);
if (myUseSoftWraps != null) return myUseSoftWraps.booleanValue();
boolean softWrapsEnabled = EditorSettingsExternalizable.getInstance().isUseSoftWraps(mySoftWrapAppliancePlace);
if (!softWrapsEnabled || mySoftWrapAppliancePlace != SoftWrapAppliancePlaces.MAIN_EDITOR || myEditor == null) return softWrapsEnabled;
String masks = EditorSettingsExternalizable.getInstance().getSoftWrapFileMasks();
if (masks.trim().equals("*")) return true;
VirtualFile file = FileDocumentManager.getInstance().getFile(myEditor.getDocument());
return file != null && fileNameMatches(file.getName(), masks);
}
private static boolean fileNameMatches(@NotNull String fileName, @NotNull String globPatterns) {
for (String p : globPatterns.split(";")) {
String pTrimmed = p.trim();
if (!pTrimmed.isEmpty() && PatternUtil.fromMask(pTrimmed).matcher(fileName).matches()) return true;
}
return false;
}
@Override
@@ -189,9 +189,9 @@ action.EditorToggleShowLineNumbers.text=Show L_ine Numbers
action.EditorToggleShowLineNumbers.description=Toggle display line numbers in current editor
action.EditorToggleShowGutterIcons.text=Show Gutter Ic_ons
action.EditorToggleShowGutterIcons.description=Toggle display gutter icons in current editor
action.EditorToggleUseSoftWraps.text=Use Soft Wraps
action.EditorToggleUseSoftWraps.text=Soft-Wrap
action.EditorToggleUseSoftWraps.description=Toggle using soft wraps in current editor
action.EditorToggleUseSoftWrapsInPreview.text=Use Soft Wraps in Preview Editor
action.EditorToggleUseSoftWrapsInPreview.text=Soft-Wrap Preview Editor
action.EditorToggleUseSoftWrapsInPreview.description=Toggle using soft wraps in preview editors
action.EditorConsoleScrollToTheEnd.text=Scroll to the end
action.EditorIncreaseFontSize.text=Increase Font Size
@@ -1543,8 +1543,8 @@ action.CreateLauncherScript.description=Create a script for opening files and pr
action.CreateDesktopEntry.text=Create Desktop Entry...
action.CreateDesktopEntry.description=Create a desktop entry for integration with system application menu
group.EditorGutterPopupMenu.text=Editor Gutter Popup Menu
action.EditorGutterToggleGlobalSoftWraps.text=Soft-Wrap All Files
action.EditorGutterToggleLocalSoftWraps.gutterText=Soft-Wrap Current File
action.ConfigureSoftWraps.text=Configure Soft Wraps...
action.EditorGutterToggleLocalSoftWraps.gutterText=Soft-Wrap Current Editor
action.EditorGutterToggleGlobalLineNumbers.text=Show Line Numbers
action.EditorGutterToggleGlobalIndentLines.text=Show Indent Guides
action.ShowGutterIconsSettings.text=Configure Gutter Icons...
@@ -432,7 +432,8 @@ radio.close.less.frequently.used.files=Close unused
radio.close.non.modified.files.first=Close unchanged
label.when.number.of.opened.editors.exceeds.tab.limit=<html>When tabs exceed the limit:</html>
group.soft.wraps=Soft Wraps
checkbox.use.soft.wraps.at.editor=Use soft wraps in editor
checkbox.use.soft.wraps.at.editor=Soft-wrap file types:
soft.wraps.file.masks.empty.text=No file types
checkbox.use.soft.wraps.at.console=Use soft wraps in console
checkbox.use.custom.soft.wraps.indent=Use original line's indent for wrapped parts
label.use.custom.soft.wraps.indent=Additional shift:
@@ -426,11 +426,12 @@
</group>
<group id="EditorToggleActions" popup="true">
<action id="EditorToggleUseSoftWraps" class="com.intellij.openapi.editor.actions.ToggleUseSoftWrapsMenuAction" icon="AllIcons.Actions.ToggleSoftWrap"/>
<separator/>
<action id="EditorToggleShowWhitespaces" class="com.intellij.openapi.editor.actions.ToggleShowWhitespacesAction"/>
<action id="EditorToggleShowLineNumbers" class="com.intellij.openapi.editor.actions.ToggleShowLineNumbersAction"/>
<action id="EditorToggleShowGutterIcons" class="com.intellij.openapi.editor.actions.ToggleShowGutterIconsAction"/>
<action id="EditorToggleShowIndentLines" class="com.intellij.openapi.editor.actions.ToggleShowIndentLinesAction"/>
<action id="EditorToggleUseSoftWraps" class="com.intellij.openapi.editor.actions.ToggleUseSoftWrapsMenuAction" icon="AllIcons.Actions.ToggleSoftWrap"/>
</group>
<separator/>
@@ -711,8 +712,8 @@
</group>
<group id="EditorGutterPopupMenu">
<action id="EditorGutterToggleGlobalSoftWraps" class="com.intellij.openapi.editor.actions.ToggleSoftWrapsGloballyAction"/>
<reference ref="EditorToggleUseSoftWraps"/>
<action id="ConfigureSoftWraps" class="com.intellij.openapi.editor.actions.ConfigureSoftWrapsAction"/>
<separator/>
<action id="EditorGutterToggleGlobalLineNumbers" class="com.intellij.openapi.editor.actions.ToggleShowLineNumbersGloballyAction"/>
<action id="EditorGutterToggleGlobalIndentLines" class="com.intellij.openapi.editor.actions.ToggleShowIndentLinesGloballyAction"/>
@@ -68,7 +68,7 @@ public class DuplexConsoleActionsTest extends LightPlatformTestCase {
final AnAction[] mergedActions = duplexConsoleView.createConsoleActions();
assertEquals(actions1.length, actions2.length);
assertEquals(actions1.length, mergedActions.length - 1);
assertHasActions(mergedActions, "Up", "Down", "Soft Wraps", "Scroll", "Clear", "Print");
assertHasActions(mergedActions, "Up", "Down", "Soft-Wrap", "Scroll", "Clear", "Print");
}
public void testMergeReversedConsoles() {
@@ -82,7 +82,7 @@ public class DuplexConsoleActionsTest extends LightPlatformTestCase {
final AnAction[] mergedActions = duplexConsoleView.createConsoleActions();
assertEquals(actions1.length, actions2.length);
assertEquals(actions1.length, mergedActions.length - 1);
assertHasActions(mergedActions, "Up", "Down", "Soft Wraps", "Scroll", "Clear", "Print");
assertHasActions(mergedActions, "Up", "Down", "Soft-Wrap", "Scroll", "Clear", "Print");
}
public void testMergedClear() {