diff --git a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.kt b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.kt index 7ade72514801..cab31a7e7468 100644 --- a/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.kt +++ b/platform/lang-impl/src/com/intellij/application/options/editor/EditorTabsConfigurable.kt @@ -5,7 +5,7 @@ import com.intellij.ide.ui.UINumericRange import com.intellij.ide.ui.UISettings import com.intellij.ide.ui.UISettingsState import com.intellij.openapi.application.ApplicationBundle.message -import com.intellij.openapi.ui.ComboBox +import com.intellij.openapi.options.BoundConfigurable import com.intellij.openapi.ui.DialogPanel import com.intellij.openapi.util.registry.Registry import com.intellij.ui.ListCellRendererWrapper @@ -13,7 +13,7 @@ import com.intellij.ui.components.Label import com.intellij.ui.layout.* import javax.swing.* -class EditorTabsConfigurable : EditorOptionsProvider { +class EditorTabsConfigurable : BoundConfigurable("Editor Tabs", "reference.settingsdialog.IDE.editor.tabs"), EditorOptionsProvider { companion object { private const val LEFT = "Left" private const val RIGHT = "Right" @@ -25,17 +25,8 @@ class EditorTabsConfigurable : EditorOptionsProvider { private lateinit var myEditorTabPlacement: JComboBox private lateinit var myScrollTabLayoutInEditorCheckBox: JCheckBox - private val panel = doCreateComponent() - override fun getDisplayName() = "Editor Tabs" - - override fun getHelpTopic() = "reference.settingsdialog.IDE.editor.tabs" - - override fun createComponent(): JComponent { - return panel - } - - private fun doCreateComponent(): DialogPanel { + override fun createPanel(): DialogPanel { val uiSettings = UISettings.instance.state return panel { @@ -119,10 +110,6 @@ class EditorTabsConfigurable : EditorOptionsProvider { enableIf(myEditorTabPlacement.selectedValueMatches { it != UISettings.TABS_NONE }) } - override fun reset() { - panel.reset() - } - private fun getCloseButtonPlacement(uiSettings: UISettingsState): String { val placement: String if (!uiSettings.showCloseButton) { @@ -135,19 +122,14 @@ class EditorTabsConfigurable : EditorOptionsProvider { } override fun apply() { - val uiSettingsChanged = panel.isModified() - panel.apply() - val settingsManager = UISettings.instance + val uiSettingsChanged = isModified + super.apply() if (uiSettingsChanged) { - settingsManager.fireUISettingsChanged() + UISettings.instance.fireUISettingsChanged() } } - override fun isModified(): Boolean { - return panel.isModified() - } - private class MyTabsPlacementComboBoxRenderer internal constructor() : ListCellRendererWrapper() { override fun customize(list: JList<*>, value: Int, index: Int, selected: Boolean, hasFocus: Boolean) { diff --git a/platform/platform-api/src/com/intellij/openapi/options/BoundConfigurable.kt b/platform/platform-api/src/com/intellij/openapi/options/BoundConfigurable.kt new file mode 100644 index 000000000000..30799245e761 --- /dev/null +++ b/platform/platform-api/src/com/intellij/openapi/options/BoundConfigurable.kt @@ -0,0 +1,30 @@ +// 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.options + +import com.intellij.openapi.ui.DialogPanel +import javax.swing.JComponent + +/** + * @author yole + */ +abstract class BoundConfigurable(private val displayName: String, private val helpTopic: String? = null) : Configurable { + private val panel: DialogPanel by lazy { createPanel() } + + abstract fun createPanel(): DialogPanel + + final override fun createComponent(): JComponent? = panel + + override fun isModified() = panel.isModified() + + override fun getDisplayName(): String = displayName + + override fun reset() { + panel.reset() + } + + override fun apply() { + panel.apply() + } + + override fun getHelpTopic(): String? = helpTopic +} \ No newline at end of file