Skip to content

Commit

Permalink
Merge branch 'refs/heads/next' into compat/203-212
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed Apr 9, 2024
2 parents d64fbd3 + 93f631e commit 9d10bd4
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 82 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased]

- User interaction experience optimization and improvement.
- Compatible with 2024.4.
- Bug fixes.
- 用户交互体验优化与改进
- 兼容 IDE 2024.1 版本
- Bug 修复

## [3.5.7] (2024/03/14)

- Bug fixes.
- Bug 修复

Expand Down Expand Up @@ -449,7 +458,8 @@
- 支持单词拆分。翻译变量名或方法名时更方便
- Bug修复

[Unreleased]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.6...HEAD
[Unreleased]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.7...HEAD
[3.5.7]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.6...v3.5.7
[3.5.6]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.5...v3.5.6
[3.5.5]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.4...v3.5.5
[3.5.4]: https://github.com/YiiGuxing/TranslationPlugin/compare/v3.5.3...v3.5.4
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pluginGroup = cn.yiiguxing.plugin.translate
pluginRepositoryUrl = https://github.com/YiiGuxing/TranslationPlugin

# SemVer format -> https://semver.org
pluginMajorVersion = 3.5.7
pluginMajorVersion = 3.5.8
pluginPreReleaseVersion =
pluginBuildMetadata = 203u212
autoSnapshotVersion = true
Expand All @@ -32,7 +32,7 @@ platformPlugins = java, org.jetbrains.kotlin, \
kotlin.stdlib.default.dependency = false

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.5
gradleVersion = 8.7

# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache = true
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ kotlin = "1.9.23"
kover = "0.7.6"
qodana = "0.1.13"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.17.2"
gradleIntelliJPlugin = "1.17.3"

[libraries]
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 7 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -202,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/cn/yiiguxing/plugin/translate/Settings.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cn.yiiguxing.plugin.translate

import cn.yiiguxing.plugin.translate.trans.Lang
import cn.yiiguxing.plugin.translate.ui.WindowLocation
import cn.yiiguxing.plugin.translate.ui.settings.TranslationEngine
import cn.yiiguxing.plugin.translate.util.*
import cn.yiiguxing.plugin.translate.util.credential.SimpleStringCredentialManager
Expand Down Expand Up @@ -165,6 +166,11 @@ class Settings : PersistentStateComponent<Settings> {
}
}

/**
* 翻译对话框位置
*/
var translationWindowLocation: WindowLocation = WindowLocation.MOUSE_SCREEN

override fun getState(): Settings = this

override fun loadState(state: Settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import javax.swing.Icon
class SettingsAction(
@ActionText text: String? = message("settings.title.translate"),
@NlsActions.ActionDescription description: String? = message("settings.title.translate"),
icon: Icon? = AllIcons.General.GearPlain
icon: Icon? = AllIcons.General.GearPlain,
private val beforeActionPerformed: ((event: AnActionEvent) -> Unit)? = null
) : AnAction(text, description, icon), DumbAware {

override fun actionPerformed(e: AnActionEvent) {
beforeActionPerformed?.invoke(e)
TranslationConfigurable.showSettingsDialog(e.project)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class TranslateAndReplaceAction : AutoSelectAction(true, NON_WHITESPACE_CONDITIO

private class TranslationItemRenderer : LookupElementRenderer<LookupElement>() {
override fun renderElement(element: LookupElement, presentation: LookupElementPresentation) {
presentation.itemText = element.lookupString.replace(CRLF, "")
presentation.itemText = element.lookupString.replace(CRLF, "").replace("\t", "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ private val COMPARATOR = Comparator.comparingInt { action: AnAction ->

class TranslationPromoter : ActionPromoter {

override fun promote(actions: MutableList<out AnAction>, context: DataContext): MutableList<AnAction> {
return ArrayList(actions).apply { sortWith(COMPARATOR) }
override fun promote(actions: MutableList<out AnAction?>, context: DataContext): MutableList<AnAction> {
return actions.asSequence().filterNotNull().sortedWith(COMPARATOR).toMutableList()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BalloonTranslationPane(
}
}

viewer.border = JBUI.Borders.emptyRight(OFFSET + GAP)
viewer.border = JBUI.Borders.empty(GAP, 0, GAP, OFFSET + GAP)

if (isDictViewer(viewer)) {
dictViewerScrollWrapper = scrollPane
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cn.yiiguxing.plugin.translate.ui

import cn.yiiguxing.plugin.translate.*
import cn.yiiguxing.plugin.translate.action.SettingsAction
import cn.yiiguxing.plugin.translate.service.TranslationUIManager
import cn.yiiguxing.plugin.translate.trans.Lang
import cn.yiiguxing.plugin.translate.trans.LanguagePair
import cn.yiiguxing.plugin.translate.trans.Translation
Expand Down Expand Up @@ -52,7 +53,7 @@ import kotlin.properties.Delegates

class TranslationDialog(
private val project: Project?,
val ui: TranslationDialogUI = TranslationDialogUiImpl(UIProvider())
val ui: TranslationDialogUI = TranslationDialogUiImpl(UIProvider(project))
) :
DialogWrapper(project),
TranslationDialogUI by ui,
Expand Down Expand Up @@ -133,7 +134,7 @@ class TranslationDialog(
else -> false
}
if (needCloseDialog) {
doCancelAction()
close()
}
}

Expand Down Expand Up @@ -244,11 +245,6 @@ class TranslationDialog(
super.setCursor(content, cursor)
}
}

override fun mouseReleased(event: MouseEvent?) {
super.mouseReleased(event)
storeWindowLocationAndSize()
}
}
glassPane.addMouseMotionPreprocessor(resizeListener, this.disposable)
glassPane.addMousePreprocessor(resizeListener, this.disposable)
Expand All @@ -275,7 +271,7 @@ class TranslationDialog(

// Close the dialog when the ESC key is pressed
override fun createCancelAction(): ActionListener {
return ActionListener { doCancelAction() }
return ActionListener { close() }
}

private fun initLangComboBoxes() {
Expand Down Expand Up @@ -656,15 +652,15 @@ class TranslationDialog(

override fun show() {
if (!isShowing) {
restoreWindowSize()
super.show()
restoreWindowLocationAndSize()
restoreWindowLocation()
}

focusManager.requestFocus(inputTextArea, true)
}

fun close() {
storeWindowLocationAndSize()
close(CLOSE_EXIT_CODE)
}

Expand All @@ -673,6 +669,7 @@ class TranslationDialog(
return
}

storeWindowLocationAndSize()
Disposer.dispose(this)
super.dispose()
_disposed = true
Expand Down Expand Up @@ -777,40 +774,65 @@ class TranslationDialog(
translationPanel.preferredSize = translationPanel.size
}

private fun restoreWindowLocationAndSize() {
val savedX = TranslationStates.translationDialogLocationX
val savedY = TranslationStates.translationDialogLocationY
private fun restoreWindowSize() {
val savedWidth = TranslationStates.translationDialogWidth
val savedHeight = TranslationStates.translationDialogHeight
if (savedX != null && savedY != null) {
val intersectWithScreen = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.screenDevices
.any { gd ->
gd.defaultConfiguration.bounds.intersects(
savedX.toDouble(),
savedY.toDouble(),
savedWidth.toDouble(),
savedHeight.toDouble()
)
}
if (intersectWithScreen) {
window.location = Point(savedX, savedY)
} else {
TranslationStates.translationDialogLocationX = null
TranslationStates.translationDialogLocationY = null
}
}
val savedSize = Dimension(savedWidth, savedHeight)
translationPanel.size = savedSize
translationPanel.preferredSize = savedSize
fixWindowHeight(savedWidth)
}

private class UIProvider : TranslationDialogUiProvider {
private fun restoreWindowLocation() {
val windowLocation = Settings.translationWindowLocation
if (windowLocation == WindowLocation.DEFAULT) {
return
}

val savedX = TranslationStates.translationDialogLocationX
val savedY = TranslationStates.translationDialogLocationY
if (savedX == null || savedY == null) {
return
}

val savedWidth = TranslationStates.translationDialogWidth
val savedHeight = TranslationStates.translationDialogHeight
val ownerWindow = window.owner
val screenDeviceBounds = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.screenDevices
.map { sd -> sd.defaultConfiguration.bounds }
val isValidArea = screenDeviceBounds
.filter { windowLocation == WindowLocation.LAST_LOCATION || it.contains(ownerWindow.location) }
.any { bounds ->
val offset = 10
Rectangle(
bounds.x + offset,
bounds.y + offset,
bounds.width - offset,
bounds.height - offset
).intersects(
savedX.toDouble(),
savedY.toDouble(),
savedWidth.toDouble(),
savedHeight.toDouble()
)
}

if (isValidArea) {
window.location = Point(savedX, savedY)
} else {
TranslationStates.translationDialogLocationX = null
TranslationStates.translationDialogLocationY = null
}
}

private class UIProvider(private val project: Project?) : TranslationDialogUiProvider {
override fun createPinButton(): JComponent = actionButton(MyPinAction())

override fun createSettingsButton(): JComponent = actionButton(SettingsAction())
override fun createSettingsButton(): JComponent = actionButton(SettingsAction {
TranslationUIManager.instance(project).currentTranslationDialog()?.close()
})

private fun actionButton(action: AnAction): ActionButton =
ActionButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ abstract class TranslationPane<T : JComponent>(

private var onSpellFixedHandler: ((String) -> Unit)? = null

@Suppress("SpellCheckingInspection")
private var onRevalidateHandler: (() -> Unit)? = null
private var onFixLanguageHandler: ((Lang) -> Unit)? = null

Expand Down Expand Up @@ -184,7 +183,7 @@ abstract class TranslationPane<T : JComponent>(
spellLabel.font = primaryFont.lessOn(2f)
spellText.font = primaryFont.deriveFont(Font.BOLD, spellLabel.font.size.toFloat())
}
originalViewer.font = primaryFont.deriveScaledFont(Font.ITALIC or Font.BOLD, FONT_SIZE_LARGE)
originalViewer.font = primaryFont.deriveScaledFont(FONT_SIZE_LARGE)
translationViewer.font = primaryFont.deriveScaledFont(FONT_SIZE_LARGE)
extraViewer.font = primaryFont.biggerOn(1f)
originalTransliterationLabel.font = phoneticFont
Expand Down Expand Up @@ -276,7 +275,6 @@ abstract class TranslationPane<T : JComponent>(
spellComponent.onSpellFixed(handler)
}

@Suppress("SpellCheckingInspection")
fun onRevalidate(handler: () -> Unit) {
onRevalidateHandler = handler
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cn.yiiguxing.plugin.translate.ui

import cn.yiiguxing.plugin.translate.message

enum class WindowLocation(val displayName: String) {
DEFAULT(message("window.location.default")),
MOUSE_SCREEN(message("window.location.mouse.screen")),
LAST_LOCATION(message("window.location.last.location"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cn.yiiguxing.plugin.translate.ui.settings
import cn.yiiguxing.plugin.translate.*
import cn.yiiguxing.plugin.translate.ui.SupportDialog
import cn.yiiguxing.plugin.translate.ui.UI
import cn.yiiguxing.plugin.translate.ui.WindowLocation
import cn.yiiguxing.plugin.translate.ui.selected
import cn.yiiguxing.plugin.translate.util.ByteSize
import cn.yiiguxing.plugin.translate.util.CacheService
Expand Down Expand Up @@ -201,6 +202,7 @@ class SettingsPanel(
|| settings.showReplacementAction != showReplacementActionCheckBox.isSelected
|| settings.showActionsInContextMenuOnlyWithSelection != showActionsInContextMenuOnlyWithSelectionCheckbox.isSelected
|| states.maxHistorySize != maxHistoriesSizeComboBox.item
|| settings.translationWindowLocation != translationWindowLocationComboBox.selected
}

private fun getConfigurationPath(vararg configurations: String): String = configurations.joinToString("|") {
Expand Down Expand Up @@ -253,6 +255,7 @@ class SettingsPanel(
showActionsInContextMenuOnlyWithSelection = showActionsInContextMenuOnlyWithSelectionCheckbox.isSelected
takeWordWhenDialogOpens = takeWordCheckBox.isSelected
ignoreRegex = this@SettingsPanel.ignoreRegExp.text
translationWindowLocation = translationWindowLocationComboBox.selected ?: WindowLocation.MOUSE_SCREEN
}
}

Expand Down Expand Up @@ -285,6 +288,7 @@ class SettingsPanel(
settings.showActionsInContextMenuOnlyWithSelection
takeWordCheckBox.isSelected = settings.takeWordWhenDialogOpens
wordbookStoragePathField.text = settings.wordbookStoragePath ?: ""
translationWindowLocationComboBox.selected = settings.translationWindowLocation
}

companion object {
Expand Down
Loading

0 comments on commit 9d10bd4

Please sign in to comment.