From cca9caa1795df84423dc22174dd67a56579abd39 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Wed, 22 May 2024 10:01:56 +0800 Subject: [PATCH 1/9] Improve error handling in `WebPages.kt` --- Catch `Throwable` instead of `Exception` to handle all errors when opening the HTML editor in `WebPages.kt`. --- src/main/kotlin/cn/yiiguxing/plugin/translate/WebPages.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/WebPages.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/WebPages.kt index 0365409a4..4c6cb742f 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/WebPages.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/WebPages.kt @@ -110,7 +110,7 @@ object WebPages { invokeLater(modalityState, expired = project.disposed) { try { HTMLEditorProvider.openEditor(project, title, html) - } catch (e: Exception) { + } catch (e: Throwable) { LOG.warn("Failed to open website", e) BrowserUtil.browse(pageFragment.getUrl()) } From d22b091db6c593749620a342e8a06aacd2bd23ac Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Wed, 22 May 2024 15:15:56 +0800 Subject: [PATCH 2/9] Fix a NoSuchElementException in the example sentence document fix: #5716 --- .../MicrosoftExampleDocumentFactory.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftExampleDocumentFactory.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftExampleDocumentFactory.kt index 65b2b53b5..fef1e7373 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftExampleDocumentFactory.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/microsoft/MicrosoftExampleDocumentFactory.kt @@ -1,6 +1,7 @@ package cn.yiiguxing.plugin.translate.trans.microsoft import cn.yiiguxing.plugin.translate.trans.microsoft.models.DictionaryExample +import cn.yiiguxing.plugin.translate.trans.microsoft.models.DictionaryExampleItem import cn.yiiguxing.plugin.translate.trans.text.ExampleDocument import cn.yiiguxing.plugin.translate.trans.text.TranslationDocument import cn.yiiguxing.plugin.translate.util.text.StyledString @@ -15,21 +16,23 @@ internal object MicrosoftExampleDocumentFactory : return null } - val examples = input.asSequence() + return input.asSequence() .mapNotNull { it.examples.firstOrNull() } - .map { - listOf( - it.sourcePrefix, - StyledString(it.sourceTerm, ExampleDocument.STYLE_EXAMPLE_BOLD), - it.sourceSuffix, - StyledString("\t", ExampleDocument.STYLE_EXAMPLE_SPACE), - it.targetPrefix, - StyledString(it.targetTerm, ExampleDocument.STYLE_EXAMPLE_BOLD), - it.targetSuffix - ) - } + .map(::toExampleStrings) .toList() + .takeIf { it.isNotEmpty() } + ?.let { ExampleDocument(it) } + } - return ExampleDocument(examples) + private fun toExampleStrings(example: DictionaryExampleItem): List { + return listOf( + example.sourcePrefix, + StyledString(example.sourceTerm, ExampleDocument.STYLE_EXAMPLE_BOLD), + example.sourceSuffix, + StyledString("\t", ExampleDocument.STYLE_EXAMPLE_SPACE), + example.targetPrefix, + StyledString(example.targetTerm, ExampleDocument.STYLE_EXAMPLE_BOLD), + example.targetSuffix + ) } } \ No newline at end of file From c0358f64952a2fdb2f05bcad8fcd2825e850bf7c Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Wed, 22 May 2024 15:46:10 +0800 Subject: [PATCH 3/9] Fix a `NullPointerException` in `TranslationWidget` fix: #5718 --- .../cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt index 545160d32..e65bb01c9 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationWidget.kt @@ -118,7 +118,7 @@ class TranslationWidget(private val project: Project) : WithIconAndArrows(), Ico } private fun showGotItTooltipIfNeed() { - if (isDisposed || project.isDisposed) { + if (!isShowing || isDisposed || project.isDisposed) { return } From be229998985a8423f46ddf372a82331fe2e1f2ef Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Wed, 22 May 2024 15:56:24 +0800 Subject: [PATCH 4/9] Fix a `NoClassDefFoundError` in `DictionaryDocument` fix: #5719 --- .../plugin/translate/trans/text/dictionary.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/text/dictionary.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/text/dictionary.kt index 6b0a13916..f743ca4b0 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/text/dictionary.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/text/dictionary.kt @@ -4,7 +4,6 @@ import cn.yiiguxing.plugin.translate.ui.StyledViewer import cn.yiiguxing.plugin.translate.util.text.* import com.intellij.ui.JBColor import com.intellij.ui.scale.JBUIScale -import kotlinx.collections.immutable.toImmutableSet import java.awt.Color import javax.swing.text.* @@ -23,22 +22,16 @@ private const val FOLDING_STYLE = "dict-folding" */ class DictionaryDocument(private val dictionaryGroups: List) : TranslationDocument { - private val _translations: Set by lazy { - dictionaryGroups.asSequence() + override val translations: Set + get() = dictionaryGroups.asSequence() .map { it.entries } .flatten() .sortedByDescending { it.score } .map { it.word } .toSet() - .toImmutableSet() - } - private val _text: String by lazy { dictionaryGroups.toText() } - - override val translations: Set - get() = _translations override val text: String - get() = _text + get() = dictionaryGroups.toText() override fun applyTo(viewer: StyledViewer) { viewer.styledDocument.apply { From 1b25aea4d9efd43992c1ad314502a98bbc363915 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 26 May 2024 09:05:01 +0800 Subject: [PATCH 5/9] Fix `ownerWindow` is null fix: #5740 --- .../cn/yiiguxing/plugin/translate/ui/TranslationDialog.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationDialog.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationDialog.kt index 94051c9d1..b30100582 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationDialog.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/ui/TranslationDialog.kt @@ -505,7 +505,10 @@ class TranslationDialog( targetTransliterationLabel.text = translation?.transliteration } - private fun updateDictViewer(dictDocument: TranslationDocument?, extraDocuments: List>) { + private fun updateDictViewer( + dictDocument: TranslationDocument?, + extraDocuments: List> + ) { dictViewer.document.clear() dictDocument?.let { dictViewer.apply(it) @@ -812,7 +815,7 @@ class TranslationDialog( val savedWidth = states.translationDialogWidth val savedHeight = states.translationDialogHeight - val ownerWindow = window.owner + val ownerWindow = window.owner ?: window val screenDeviceBounds = GraphicsEnvironment .getLocalGraphicsEnvironment() .screenDevices From a5fbaf82d80ded005dcc658a7b920247a127c818 Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 26 May 2024 11:37:28 +0800 Subject: [PATCH 6/9] Optimize website pages launcher --- src/main/resources/website.html | 57 ++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/src/main/resources/website.html b/src/main/resources/website.html index c4ed6100f..486537f07 100644 --- a/src/main/resources/website.html +++ b/src/main/resources/website.html @@ -141,13 +141,21 @@ Loading... From a018f8f5556b560a8e3006994aa94ff8a3c7b5eb Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 26 May 2024 11:52:46 +0800 Subject: [PATCH 7/9] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf89520bc..2f46c63ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Translation Plugin Changelog ## [Unreleased] +- Bug fixes. +- Bug 修复 ## [3.6.0] (2024/05/20) From 4fb98d26256db0546509419879890d5184c6173a Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 26 May 2024 11:53:52 +0800 Subject: [PATCH 8/9] :triangular_flag_on_post: v3.6.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d2c017d3e..4bb9863d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ pluginGroup = cn.yiiguxing.plugin.translate pluginRepositoryUrl = https://github.com/YiiGuxing/TranslationPlugin # SemVer format -> https://semver.org -pluginMajorVersion = 3.6.0 +pluginMajorVersion = 3.6.1 pluginPreReleaseVersion = pluginBuildMetadata = autoSnapshotVersion = true From 10e422a22d0d513618e80cfaf3f96b9302c6da0f Mon Sep 17 00:00:00 2001 From: "Yii.Guxing" Date: Sun, 26 May 2024 12:03:50 +0800 Subject: [PATCH 9/9] Update azure service api version --- .../plugin/translate/trans/openai/AzureServiceVersion.kt | 2 +- .../yiiguxing/plugin/translate/trans/openai/OpenAiSettings.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/AzureServiceVersion.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/AzureServiceVersion.kt index 3491714f8..3d2f8c410 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/AzureServiceVersion.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/AzureServiceVersion.kt @@ -5,7 +5,7 @@ package cn.yiiguxing.plugin.translate.trans.openai enum class AzureServiceVersion(val value: String) { V2023_05_15("2023-05-15"), V2024_02_01("2024-02-01"), - V2024_04_01_PREVIEW("2024-03-01-preview"); + V2024_05_01_PREVIEW("2024-05-01-preview"); companion object { fun previewVersions() = AzureServiceVersion.values().filter { diff --git a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiSettings.kt b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiSettings.kt index ad8acb11f..8ba9f0b57 100644 --- a/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiSettings.kt +++ b/src/main/kotlin/cn/yiiguxing/plugin/translate/trans/openai/OpenAiSettings.kt @@ -70,7 +70,7 @@ class OpenAiSettings : BaseState(), PersistentStateComponent { override var apiVersion: AzureServiceVersion by enum(AzureServiceVersion.V2024_02_01) @get:OptionTag("TTS_API_VERSION") - override var ttsApiVersion: AzureServiceVersion by enum(AzureServiceVersion.V2024_04_01_PREVIEW) + override var ttsApiVersion: AzureServiceVersion by enum(AzureServiceVersion.V2024_05_01_PREVIEW) @get:OptionTag("DEPLOYMENT_ID") override var deployment: String? by string()