diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/Theme.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/Theme.kt index 7f86bada..7643154a 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/Theme.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/Theme.kt @@ -24,7 +24,11 @@ interface Theme { override val name: String get() = "Default" override val description: String - get() = "The default theme" + get() = "Use the theme set on the global settings" + override val onlyApplicationIcons: Boolean + get() = false + override val onlyLanguageIcons: Boolean + get() = false override fun getIconSet(applicationName: String): IconSet? { return null @@ -35,6 +39,8 @@ interface Theme { val id: String val name: String val description: String + val onlyApplicationIcons: Boolean + val onlyLanguageIcons: Boolean fun getIconSet(applicationName: String): IconSet? } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/ThemeSourceMap.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/ThemeSourceMap.kt index f8bf3ab6..3c15ae1f 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/ThemeSourceMap.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/ThemeSourceMap.kt @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.JsonNode interface ThemeSourceMap : Map { fun createThemeMap(themes: Map, default: Theme): ThemeMap - fun createTheme(id: String, name: String, description: String): Theme + fun createTheme(id: String, name: String, description: String, onlyApplicationIcons: Boolean, onlyLanguageIcons: Boolean): Theme fun toThemeMap(): ThemeMap { val themes = stream() @@ -39,7 +39,9 @@ interface ThemeSourceMap : Map { fun ThemeSource.asTheme(): Theme { val name: String = node["name"]?.textValue()!! val description: String = node["description"]?.textValue()!! + val onlyApplicationIcons = node["onlyApplicationIcons"]?.booleanValue() ?: false + val onlyLanguageIcons = node["onlyLanguageIcons"]?.booleanValue() ?: false - return createTheme(id, name, description) + return createTheme(id, name, description, onlyApplicationIcons, onlyLanguageIcons) } } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/abstract/AbstractTheme.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/abstract/AbstractTheme.kt index 7914a890..e1a94888 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/abstract/AbstractTheme.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/abstract/AbstractTheme.kt @@ -23,8 +23,10 @@ abstract class AbstractTheme( override val id: String, override val name: String, override val description: String, + override val onlyApplicationIcons: Boolean, + override val onlyLanguageIcons: Boolean ) : Theme { override fun toString(): String { - return "AbstractTheme(id='$id', name='$name', description='$description')" + return "AbstractTheme(id='$id', name='$name', description='$description', onlyApplicationIcons=$onlyApplicationIcons, onlyLanguageIcons=$onlyLanguageIcons)" } } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathTheme.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathTheme.kt index f093fd19..4c46c03f 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathTheme.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathTheme.kt @@ -23,8 +23,8 @@ import org.apache.commons.io.FilenameUtils import java.util.concurrent.ConcurrentHashMap import kotlin.collections.set -class ClasspathTheme(private val source: ClasspathSource, id: String, name: String, description: String) : - AbstractTheme(id, name, description) { +class ClasspathTheme(private val source: ClasspathSource, id: String, name: String, description: String, onlyApplicationIcons: Boolean, onlyLanguageIcons: Boolean) : + AbstractTheme(id, name, description, onlyApplicationIcons, onlyLanguageIcons) { private val sets = ConcurrentHashMap() override fun getIconSet(applicationName: String): IconSet { diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathThemeSourceMap.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathThemeSourceMap.kt index 44d6bf63..01c59872 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathThemeSourceMap.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/icons/source/classpath/ClasspathThemeSourceMap.kt @@ -23,6 +23,6 @@ import dev.azn9.plugins.discord.icons.source.abstract.AbstractThemeSourceMap class ClasspathThemeSourceMap(private val source: ClasspathSource, map: Map) : AbstractThemeSourceMap(map) { override fun createThemeMap(themes: Map, default: Theme) = ClasspathThemeMap(themes, default) - override fun createTheme(id: String, name: String, description: String) = - ClasspathTheme(source, id, name, description) + override fun createTheme(id: String, name: String, description: String, onlyApplicationIcons: Boolean, onlyLanguageIcons: Boolean) = + ClasspathTheme(source, id, name, description, onlyApplicationIcons, onlyLanguageIcons) } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/IdleRenderer.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/IdleRenderer.kt index 41005739..d4fecd53 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/IdleRenderer.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/IdleRenderer.kt @@ -36,7 +36,7 @@ class IdleRenderer(context: RenderContext) : Renderer(context) { ) } - this@presence.largeImage = icons?.let { icons -> RichPresence.Image(icons.getAsset("application"), "Idling") } + this@presence.largeImage = applicationIcons?.let { icons -> RichPresence.Image(icons.getAsset("application"), "Idling") } this.partyId = Plugin.version?.toString() } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/RenderContext.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/RenderContext.kt index 39050434..7653ce51 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/RenderContext.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/RenderContext.kt @@ -24,10 +24,22 @@ import dev.azn9.plugins.discord.settings.options.types.SimpleValue import dev.azn9.plugins.discord.settings.settings class RenderContext(val source: Source, val data: Data, val mode: Renderer.Mode) { - val icons: IconSet? by lazy { - var themeValue = projectData?.projectSettings?.theme ?: settings.theme + + val applicationIcons: IconSet? by lazy { + var themeValue = projectData?.projectSettings?.applicationTheme ?: settings.applicationTheme + if (themeValue.getValue() == "default") { + themeValue = settings.applicationTheme + } + + source.getThemesOrNull() + ?.get(themeValue.getValue()) + ?.getIconSet(settings.applicationType.getValue().applicationName) + } + + val languageIcons: IconSet? by lazy { + var themeValue = projectData?.projectSettings?.iconsTheme ?: settings.iconsTheme if (themeValue.getValue() == "default") { - themeValue = settings.theme + themeValue = settings.iconsTheme } source.getThemesOrNull() diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/Renderer.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/Renderer.kt index 3626174f..b972079b 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/Renderer.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/render/Renderer.kt @@ -53,14 +53,11 @@ abstract class Renderer(protected val context: RenderContext) { DiscordPlugin.LOG.debug("Rendering presence, data=${context.data}, mode=${context.mode}") DiscordPlugin.LOG.debug("Themes: ${context.source.getThemesOrNull()}") DiscordPlugin.LOG.debug("languages: ${context.source.getLanguagesOrNull()}") - DiscordPlugin.LOG.debug("Icons: ${context.icons}") + DiscordPlugin.LOG.debug("Application Icons: ${context.applicationIcons}") + DiscordPlugin.LOG.debug("Language Icons: ${context.languageIcons}") DiscordPlugin.LOG.debug("Data: ${context.data}") DiscordPlugin.LOG.debug("Mode: ${context.mode}") - if (context.icons == null) { - DiscordPlugin.LOG.debug("RenderContext.icons=null") - } - return RichPresence(context.applicationData?.applicationId) presence@{ val customTemplateContext by lazy { context.asCustomTemplateContext() } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ApplicationSettings.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ApplicationSettings.kt index af697590..a29d18d5 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ApplicationSettings.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ApplicationSettings.kt @@ -76,7 +76,9 @@ interface ApplicationSettings : PersistentStateComponent, OptionHolder val fileTime: TimeValue val applicationType: ApplicationTypeValue - val theme: ThemeValue + + val applicationTheme: ThemeValue + val iconsTheme: ThemeValue val applicationLastUpdateNotification: StringValue } diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ProjectSettings.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ProjectSettings.kt index 9bf919e2..53aa4642 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ProjectSettings.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/ProjectSettings.kt @@ -40,7 +40,8 @@ interface ProjectSettings : PersistentStateComponent, OptionHolder { val description: StringValue - val theme: ThemeValue? + val applicationTheme: ThemeValue? + val iconsTheme: ThemeValue? val button1Title: StringValue val button1Url: StringValue diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/gui/themes/ThemeDialog.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/gui/themes/ThemeDialog.kt index a76fe2a9..db4f9a72 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/gui/themes/ThemeDialog.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/gui/themes/ThemeDialog.kt @@ -18,7 +18,6 @@ package dev.azn9.plugins.discord.settings.gui.themes import dev.azn9.plugins.discord.icons.source.Theme -import dev.azn9.plugins.discord.icons.source.ThemeMap import com.intellij.openapi.ui.DialogWrapper import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -32,7 +31,7 @@ import javax.swing.JPanel import javax.swing.plaf.basic.BasicComboBoxRenderer import kotlin.coroutines.CoroutineContext -class ThemeDialog(private val themes: ThemeMap, private val initialValue: String?, private val showDefault: Boolean = false) : DialogWrapper(null, true, IdeModalityType.IDE), CoroutineScope { +class ThemeDialog(private val themes: Map, private val initialValue: String?, private val showDefault: Boolean = false) : DialogWrapper(null, true, IdeModalityType.IDE), CoroutineScope { private val parentJob: Job = SupervisorJob() override val coroutineContext: CoroutineContext diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ApplicationSettingsImpl.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ApplicationSettingsImpl.kt index d8e7bac4..82f49cda 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ApplicationSettingsImpl.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ApplicationSettingsImpl.kt @@ -137,7 +137,9 @@ class ApplicationSettingsImpl : ApplicationSettings, PersistentStateOptionHolder /* ========== General Settings ========== */ override val applicationType by selection("Application name", ApplicationType.IDE_EDITION) - override val theme by themeChooser("Theme") + + override val applicationTheme by themeChooser("Theme for the application icon", null, false, ThemeType.APPLICATION_ONLY) + override val iconsTheme by themeChooser("Theme for the language icons", null, false, ThemeType.LANGUAGE_ONLY) /* ---------- Hidden Settings ---------- */ diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ProjectSettingsImpl.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ProjectSettingsImpl.kt index f6a9229e..42e003fe 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ProjectSettingsImpl.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/impl/ProjectSettingsImpl.kt @@ -26,6 +26,7 @@ import com.intellij.openapi.components.State import com.intellij.openapi.components.Storage import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager +import dev.azn9.plugins.discord.settings.values.ThemeType @State(name = "DiscordProjectSettings", storages = [Storage("discord.xml")]) class ProjectSettingsImpl(override val project: Project) : ProjectSettings, PersistentStateOptionHolderImpl() { @@ -40,7 +41,8 @@ class ProjectSettingsImpl(override val project: Project) : ProjectSettings, Pers override val description by text("Project description", "") - override val theme by themeChooser("Project theme", "The theme to use for this project", true) + override val applicationTheme by themeChooser("Theme for the application icon", null, true, ThemeType.APPLICATION_ONLY) + override val iconsTheme by themeChooser("Theme for the language icons", null, true, ThemeType.LANGUAGE_ONLY) override val button1Title by text("Button 1 title", "") override val button1Url by text("Button 1 url", "") diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/options/types/ThemeOption.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/options/types/ThemeOption.kt index 52f29ae0..5bbf2558 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/options/types/ThemeOption.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/options/types/ThemeOption.kt @@ -28,7 +28,7 @@ import dev.azn9.plugins.discord.utils.label import dev.azn9.plugins.discord.utils.throwing import com.intellij.openapi.util.JDOMExternalizerUtil import dev.azn9.plugins.discord.icons.source.Theme -import kotlinx.coroutines.future.asCompletableFuture +import dev.azn9.plugins.discord.settings.values.ThemeType import org.jdom.Element import java.awt.GridBagConstraints import java.awt.GridBagLayout @@ -38,10 +38,10 @@ import javax.swing.JComponent import javax.swing.JPanel import kotlin.reflect.KProperty -fun OptionCreator.themeChooser(text: String, description: String? = null, showDefault: Boolean = false) = - OptionProviderImpl(this, ThemeOption(text, description, showDefault)) +fun OptionCreator.themeChooser(text: String, description: String? = null, showDefault: Boolean = false, themeType: ThemeType) = + OptionProviderImpl(this, ThemeOption(text, description, showDefault, themeType)) -class ThemeOption(text: String, val description: String?, val showDefault: Boolean) : Option(text), ThemeValue.Provider { +class ThemeOption(text: String, val description: String?, val showDefault: Boolean, themeType: ThemeType) : Option(text), ThemeValue.Provider { private val source: Source = sourceService.source private val listeners = mutableListOf<(ThemeValue) -> Unit>() @@ -63,9 +63,17 @@ class ThemeOption(text: String, val description: String?, val showDefault: Boole addActionListener { val themes = this@ThemeOption.source.getThemesOrNull() + var themeMap = themes as Map? - if (themes != null) { - val dialog = ThemeDialog(themes, componentValue, showDefault) + if (themeType == ThemeType.APPLICATION_ONLY) { + themeMap = themeMap?.filter { !it.value.onlyLanguageIcons } + } + if (themeType == ThemeType.LANGUAGE_ONLY) { + themeMap = themes?.filter { !it.value.onlyApplicationIcons } + } + + if (themeMap != null) { + val dialog = ThemeDialog(themeMap, componentValue, showDefault) val result = dialog.showAndGet() if (result) { diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/PresenceIcon.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/PresenceIcon.kt index 8b3cc286..fd2c294d 100644 --- a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/PresenceIcon.kt +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/PresenceIcon.kt @@ -26,11 +26,11 @@ typealias IconValue = SimpleValue enum class PresenceIcon(override val text: String, override val description: String? = null) : RenderedValue, UiValueType { APPLICATION("Application") { - override fun RenderContext.getResult() = icons?.getAsset("application").toResult() + override fun RenderContext.getResult() = applicationIcons?.getAsset("application").toResult() }, FILE("File") { override fun RenderContext.getResult(): Result { - return icons?.let { icons -> language?.findIcon(icons) }?.asset.toResult() + return languageIcons?.let { icons -> language?.findIcon(icons) }?.asset.toResult() } }, NONE("None") { diff --git a/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/ThemeType.kt b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/ThemeType.kt new file mode 100644 index 00000000..53882a76 --- /dev/null +++ b/plugin/common/src/main/kotlin/dev/azn9/plugins/discord/settings/values/ThemeType.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2017-2020 Aljoscha Grebe + * Copyright 2023-2024 Axel JOLY (Azn9) + * + * 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 dev.azn9.plugins.discord.settings.values + +enum class ThemeType { + + APPLICATION_ONLY, + LANGUAGE_ONLY; + +}