From 53d976c22680adeb1fdc83d91480ddfa178028bd Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 20 Jun 2019 15:49:00 +0300 Subject: [PATCH] add PropertyComponentBooleanValue for simple settings GitOrigin-RevId: cef053369b4a0d6ceb2bc6d834aa560a0fd6ab9e --- .../util/PropertyComponentBooleanValue.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 platform/util-ex/src/com/intellij/util/PropertyComponentBooleanValue.kt diff --git a/platform/util-ex/src/com/intellij/util/PropertyComponentBooleanValue.kt b/platform/util-ex/src/com/intellij/util/PropertyComponentBooleanValue.kt new file mode 100644 index 000000000000..249af22bce96 --- /dev/null +++ b/platform/util-ex/src/com/intellij/util/PropertyComponentBooleanValue.kt @@ -0,0 +1,26 @@ +// 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.util + +import com.intellij.ide.util.PropertiesComponent +import kotlin.reflect.KProperty + +/** + * Value to be used as a Kotlin delegate for non-roamable application-level settings. + * + * Example: `var myCoolSetting by PropertyComponentBooleanValue("my.cool.setting", true)`. + * + * @see PropertiesComponent + */ +class PropertyComponentBooleanValue( + private val name: String, + private val defaultValue: Boolean +) { + + operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean { + return PropertiesComponent.getInstance().getBoolean(name, defaultValue) + } + + operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean) { + return PropertiesComponent.getInstance().setValue(name, value, defaultValue) + } +}