From 3271076d61de2bc6b2e4c9cc958ea08f8c1dfbd1 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Thu, 31 Jan 2019 13:04:38 +0300 Subject: [PATCH] IDEA-89608 Should be able to set editor view options like soft wraps for certain file types --- .../options/editor/EditorOptionsPanel.form | 48 ++++++++++++------- .../options/editor/EditorOptionsPanel.java | 32 ++++++------- .../editor/EditorOptionsTopHitProvider.java | 14 ++++++ .../actions/ConfigureSoftWrapsAction.java | 15 ++++++ .../ToggleSoftWrapsGloballyAction.java | 24 ---------- .../ex/EditorSettingsExternalizable.java | 16 +++++++ .../openapi/editor/impl/SettingsImpl.java | 23 ++++++++- .../src/messages/ActionsBundle.properties | 8 ++-- .../src/messages/ApplicationBundle.properties | 3 +- .../src/idea/PlatformActions.xml | 5 +- .../impl/DuplexConsoleActionsTest.java | 4 +- 11 files changed, 121 insertions(+), 71 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/openapi/editor/actions/ConfigureSoftWrapsAction.java delete mode 100644 platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleSoftWrapsGloballyAction.java diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form index 283c455dfad2..dae5b21a8f3b 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.form @@ -438,7 +438,7 @@ - + @@ -449,36 +449,23 @@ - - - - - - - - - - - - - - + - + - + @@ -487,7 +474,7 @@ - + @@ -499,6 +486,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java index 93561eaf4dec..c98df9381cd0 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsPanel.java @@ -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 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() { diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsTopHitProvider.java b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsTopHitProvider.java index 64edea70cd29..df06bacf5409 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsTopHitProvider.java +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorOptionsTopHitProvider.java @@ -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; + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/editor/actions/ConfigureSoftWrapsAction.java b/platform/lang-impl/src/com/intellij/openapi/editor/actions/ConfigureSoftWrapsAction.java new file mode 100644 index 000000000000..e5d91bf5b8c1 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/openapi/editor/actions/ConfigureSoftWrapsAction.java @@ -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); + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleSoftWrapsGloballyAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleSoftWrapsGloballyAction.java deleted file mode 100644 index b5e77757c7bb..000000000000 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleSoftWrapsGloballyAction.java +++ /dev/null @@ -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); - } -} diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java index 821d0bfcd681..2d82404cb621 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorSettingsExternalizable.java @@ -28,10 +28,14 @@ public class EditorSettingsExternalizable implements PersistentStateComponentWhen tabs exceed the limit: 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: diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index 7a08f4f65126..f8d90e52a6ee 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -426,11 +426,12 @@ + + - @@ -711,8 +712,8 @@ - + diff --git a/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java b/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java index d620ab5aff11..f0338c62a4b5 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/impl/DuplexConsoleActionsTest.java @@ -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() {