Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance settings with more information #206

Merged
merged 4 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ThemeDialog(private val themes: ThemeMap, private val initialValue: String
title = "Themes"
}

override fun createCenterPanel(): JComponent? = JPanel().apply panel@{
override fun createCenterPanel(): JComponent = JPanel().apply panel@{
// val tabs = JTabbedPane().apply {
// for (themeChooser in themes.values) {
// val tab = JPanel().apply tab@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,37 @@ import com.almightyalpaca.jetbrains.plugins.discord.plugin.settings.options.type
import com.almightyalpaca.jetbrains.plugins.discord.plugin.settings.values.*
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
import java.util.concurrent.TimeUnit

@Suppress("unused")
@State(name = "DiscordApplicationSettings", storages = [Storage("discord.xml")])
class ApplicationSettingsImpl : ApplicationSettings, PersistentStateOptionHolderImpl() {
override val show by check("Enable Rich Presence", true)

private val timeoutToggle by toggleable<IdleVisibility>(false)
/* ========== Timeout / Idle ========== */

override val idle by timeoutToggle.toggle { it != IdleVisibility.IGNORE }.selection(text = "When idle", initialValue = IdleVisibility.IDLE)
private val timeoutOptionPair by pair()
override val timeoutMinutes by timeoutOptionPair.first.spinner(
"Time required before considered idle",
"Time without any activity before the plugin marks the session as idle. Changes mighty require a restart to take effect",
5,
1..24 * 60,
format = "# " + "Minutes"
)
override val timeoutResetTimeEnabled by timeoutOptionPair.second.check("Reset open time when returning", "Reset open time for the application as well as open projects and files", true)

// override val timeoutEnabled by timeoutToggle.toggle.check("Hide Rich Presence after inactivity", true)
override val idle by selection(text = "While idle", "While the session is marked as idle", initialValue = IdleVisibility.IDLE)

private val timeoutOptionPair by timeoutToggle.option.pair()
override val timeoutMinutes by timeoutOptionPair.first.spinner("Timeout", 5, 1..120, format = "# Minutes")
override val timeoutResetTimeEnabled by timeoutOptionPair.second.check("Reset open time", true)
/* ========== Layout ========== */

private val group by group("Rich Presence Layout")
private val preview by group.preview()
private val layoutGroup by group("Layout")
private val preview by layoutGroup.preview()
private val tabs by preview.tabbed()

/* ---------- Application Tab ---------- */

private val applicationTab = tabs["Application"]
private val applicationInfo by applicationTab.info("Visible when no project is open")

private val applicationDetailsToggle by applicationTab.toggleable<PresenceText>()
override val applicationDetails by applicationDetailsToggle.toggle { it == PresenceText.CUSTOM }.selection("First line", PresenceText.Application1)
Expand All @@ -70,6 +79,7 @@ class ApplicationSettingsImpl : ApplicationSettings, PersistentStateOptionHolder
/* ---------- Project Tab ---------- */

private val projectTab = tabs["Project"]
private val projectInfo by projectTab.info("Visible when a project is open but no editor")

private val projectDetailsToggle by projectTab.toggleable<PresenceText>()
override val projectDetails by projectDetailsToggle.enableOn(PresenceText.CUSTOM).selection("First line", PresenceText.Project1)
Expand All @@ -96,6 +106,7 @@ class ApplicationSettingsImpl : ApplicationSettings, PersistentStateOptionHolder
/* ---------- File Tab ---------- */

private val fileTab = tabs["File"]
private val fileInfo by fileTab.info("Visible when a file is open in an editor")

private val fileDetailsToggle by fileTab.toggleable<PresenceText>()
override val fileDetails by fileDetailsToggle.enableOn(PresenceText.CUSTOM).selection("First line", PresenceText.File1)
Expand All @@ -121,7 +132,9 @@ class ApplicationSettingsImpl : ApplicationSettings, PersistentStateOptionHolder

override val filePrefixEnabled by fileTab.check("Prefix files names with Reading/Editing", true)

override val fileHideVcsIgnored by fileTab.check("Hide VCS ignored files", false)
override val fileHideVcsIgnored by fileTab.check("Hide VCS ignored files", "E.g. files in your .gitignore", false)

/* ========== General Settings ========== */

override val applicationType by selection("Application name", ApplicationType.IDE_EDITION)
override val theme by themeChooser("Theme")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class CheckOption(text: String, description: String?, initialValue: Boolean, pri
override val componentImpl by lazy {
JBCheckBox(text, currentValue).apply {
this.isEnabled = enabled
this.toolTipText = description
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2017-2020 Aljoscha Grebe
*
* 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
*
* https://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.almightyalpaca.jetbrains.plugins.discord.plugin.settings.options.types

import com.almightyalpaca.jetbrains.plugins.discord.plugin.settings.options.OptionCreator
import com.almightyalpaca.jetbrains.plugins.discord.plugin.settings.options.impl.OptionProviderImpl
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.JBUI
import org.jdom.Element
import javax.swing.JComponent

fun OptionCreator<in Unit?>.info(text: String, bold: Boolean = false) = OptionProviderImpl(this, InfoText(text, bold))

class InfoText(text: String, bold: Boolean) :
SimpleOption<Unit?>(text, null, null) {
override val componentImpl: JComponent by lazy {
val styledText: String = when {
bold -> "<html><b>$text</b></html>"
else -> "<html>$text"
}

JBLabel(styledText)
.withBorder(JBUI.Borders.empty(2, 0, 10, 0))
}

override val component: JComponent
get() = componentImpl

override var componentValue: Unit?
get() = null
set(value) = Unit

override fun addChangeListener(listener: (Unit?) -> Unit) = Unit

override val isModified = false
override val isDefault = true

override fun apply() = Unit
override fun reset() = Unit

override fun writeXml(element: Element, key: String) = Unit
override fun readXml(element: Element, key: String) = Unit

override fun writeString() = ""
override fun readString(string: String) = Unit
}

typealias DummyValue = SimpleValue<Unit?>
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ import com.almightyalpaca.jetbrains.plugins.discord.plugin.utils.label
import com.intellij.ui.JBIntSpinner
import java.awt.GridBagConstraints
import java.awt.GridBagLayout
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JSpinner
import javax.swing.SpinnerNumberModel
import javax.swing.*

fun OptionCreator<in Int>.spinner(text: String, description: String? = null, initialValue: Int, minValue: Int = Int.MIN_VALUE, maxValue: Int = Int.MAX_VALUE, step: Int = 1, format: String = "#", enabled: Boolean = true) =
OptionProviderImpl(this, IntSpinnerOption(text, description, initialValue, step, minValue, maxValue, format, enabled))
Expand Down Expand Up @@ -63,7 +60,10 @@ class IntSpinnerOption(

override val component: JComponent by lazy {
JPanel().apply {
layout = GridBagLayout()
layout = BoxLayout(this, BoxLayout.X_AXIS)


toolTipText = description

val label = label(text).apply {
this.isEnabled = enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class OptionPair : Option<Pair>(""), Pair.Provider {
add(first.second.component)
add(Box.createHorizontalStrut(20))
add(second.second.component)

add(Box.createHorizontalGlue())
}
}
override var isComponentEnabled: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class SelectionOption<T>(
index: Int,
isSelected: Boolean,
cellHasFocus: Boolean
): Component? {
): Component {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus)

value as UiValueType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun OptionCreator<in CustomTemplate>.template(text: String, initialValue: String

class TemplateOption(text: String, description: String?, initialValue: String) : SimpleOption<CustomTemplate>(text, description, CustomTemplate(initialValue)) {

private val textFieldInfoExtension = ExtendableTextComponent.Extension.create(AllIcons.General.Information, "Supports templates") {
private val textFieldInfoExtension = ExtendableTextComponent.Extension.create(AllIcons.General.Information, "Supports templates (click for more info)") {
Desktop.getDesktop().browse(URI.create(Plugin.branchBase + "/plugin/templates.adoc"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum class IdleVisibility(
override val description: String? = null
) : UiValueType {
// Do not reorder these, some logic depends on the order
IGNORE("Ignore"),
IDLE("Show Idling"),
HIDE("Hide Completely");
IGNORE("Keep showing rich presence"),
IDLE("Show \"Idling\""),
HIDE("Hide completely");
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ import com.almightyalpaca.jetbrains.plugins.discord.plugin.settings.options.type
typealias TimeValue = SimpleValue<PresenceTime>

enum class PresenceTime(override val text: String, override val description: String? = null) : RenderedValue<PresenceTime.Result>, UiValueType {
APPLICATION("Application (active)", "Time since the application has been opened and the IDE has not been idle") {
APPLICATION("Application (active)", "Time since the application was started while the session has not been idle") {
override fun RenderContext.getResult() = applicationData?.applicationTimeActive.toResult()
},
APPLICATION_TOTAL("Application (total)", "Time since the application has been started") {
override fun RenderContext.getResult() = applicationData?.applicationTimeOpened.toResult()
},
PROJECT("Project (active)", "Time since the project has been opened and the IDE has not been idle") {
PROJECT("Project (active)", "Time since the project was opened while the session has not been idle") {
override fun RenderContext.getResult() = projectData?.projectTimeActive.toResult()
},
PROJECT_TOTAL("Project (total)", "Time since the project has been opened") {
PROJECT_TOTAL("Project (total)", "Time since the opened was started") {
override fun RenderContext.getResult() = projectData?.projectTimeOpened.toResult()
},
FILE("File (active)", "Time since the file has been opened and the IDE has not been idle") {
FILE("File (active)", "Time since the file was opened while the session has not been idle") {
override fun RenderContext.getResult() = fileData?.fileTimeActive.toResult()
},
FILE_TOTAL("File (total)", "Time since the file has been opened") {
FILE_TOTAL("File (total)", "Time since the file was opened") {
override fun RenderContext.getResult() = fileData?.fileTimeOpened.toResult()
},
HIDE("Hide") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ fun createErrorMessage(message: String): JComponent = JPanel().apply warning@{
border = JBUI.Borders.merge(JBUI.Borders.empty(10), JBUI.Borders.customLine(Color(255, 25, 25, 200)), true)
}

fun label(text: String): JComponent = JBLabel(text).apply {
fun label(text: String, description: String? = null): JComponent = JBLabel(text).apply {
border = JBUI.Borders.emptyRight(10)
toolTipText = description
}

operator fun <T> DefaultComboBoxModel<T>.contains(o: Any?) = getIndexOf(o) != -1