Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
YiiGuxing committed Feb 22, 2020
2 parents 3f0d4d4 + 49d58ff commit b253559
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [v2.7.3](https://github.com/YiiGuxing/TranslationPlugin/tree/v2.7.3) (2020-02-22)

- 修复了一些Bug

## [v2.7.2](https://github.com/YiiGuxing/TranslationPlugin/tree/v2.7.2) (2020-01-21)

- 修复了Dart语言中无法对类的第一个成员的文档注释进行文档翻译的问题
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ FAQ
更新日志
--------

## [v2.7.2](https://github.com/YiiGuxing/TranslationPlugin/tree/v2.7.2) (2020-01-21)
## [v2.7.3](https://github.com/YiiGuxing/TranslationPlugin/tree/v2.7.3) (2020-02-22)

- 修复了Dart语言中无法对类的第一个成员的文档注释进行文档翻译的问题
- 修复了一些Bug

[完整的更新历史记录](./CHANGELOG.md)

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# suppress inspection "UnusedProperty" for whole file
version=2.7.2
version=2.7.3
buildNumber=
#buildNumber=SNAPSHOT
ideaVersion=IU-2017.1
javaVersion=1.8
javaTargetVersion=1.8
kotlinLanguageVersion=1.3
kotlinTargetVersion=1.1
sources=false
customSinceBuild=171
customUntilBuild=
customUntilBuild=201.*
kotlin.code.style=official
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ public void setShowPointer(final boolean show) {

@SuppressWarnings("MethodMayBeStatic")
public Icon getCloseButton() {
return AllIcons.General.BalloonClose;
return AllIcons.Ide.Notification.Close;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cn.yiiguxing.plugin.translate.activity

import cn.yiiguxing.plugin.translate.message
import cn.yiiguxing.plugin.translate.util.Application
import cn.yiiguxing.plugin.translate.util.IdeVersion
import cn.yiiguxing.plugin.translate.util.show
import com.intellij.ide.util.PropertiesComponent
import com.intellij.notification.*
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity

class IdeaVersionUpgradeNoticeActivity : StartupActivity, DumbAware {

private var veryFirstProjectOpening: Boolean = true

override fun runActivity(project: Project) {
if (IdeVersion.isIde2019OrNewer
|| !veryFirstProjectOpening
|| Application.isUnitTestMode
|| PropertiesComponent.getInstance().getBoolean(DO_NOT_NOTIFY_AGAIN_PROPERTY, false)
) {
return
}

println(DO_NOT_NOTIFY_AGAIN_PROPERTY)

veryFirstProjectOpening = false
Activity.runLater(project, 3) {
showNotification(project)
}
}

private class DoNotShowAgainAction : NotificationAction(message("notification.idea.version.do.not.show.again")) {
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
notification.expire()
PropertiesComponent.getInstance().setValue(DO_NOT_NOTIFY_AGAIN_PROPERTY, true)
}
}

companion object {
private const val DISPLAY_ID = "Outdated IDE Version"

private val DO_NOT_NOTIFY_AGAIN_PROPERTY =
"yii.guxing.translate.IdeaVersionUpgradeNotice.${IdeVersion.buildNumber}.disable"

private fun showNotification(project: Project) {
NotificationGroup(DISPLAY_ID, NotificationDisplayType.STICKY_BALLOON, false)
.createNotification(
message("notification.idea.version.title"),
message("notification.idea.version"),
NotificationType.WARNING,
null
)
.addAction(DoNotShowAgainAction())
.setImportant(true)
.show(project)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,44 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.util.PsiTreeUtil

abstract class AbstractDocumentationElementProvider<T : PsiComment> : DocumentationElementProvider {
abstract class AbstractDocumentationElementProvider : DocumentationElementProvider {

@Suppress("UNCHECKED_CAST")
override fun findDocumentationElementAt(psiFile: PsiFile, offset: Int): T? {
override fun findDocumentationElementAt(psiFile: PsiFile, offset: Int): PsiComment? {
val offsetElement = psiFile.findElementAt(offset) ?: return null
val comment = PsiTreeUtil.getParentOfType(offsetElement, PsiComment::class.java, false)
val documentationElement: T? = if (
val documentationElement: PsiComment? = if (
comment == null // 如果当前元素或其父元素是注释元素,则跳过边缘拾取
&& offsetElement is PsiWhiteSpace
&& offsetElement.startOffset == offset // 光标处于边缘处
) {
// 如果可在边缘拾取,则从末尾边缘处拾取
(offsetElement.prevSibling as? T)?.takeIf { it.isPickAtEdge }
} else {
comment as? T
}
(offsetElement.prevSibling as? PsiComment)?.takeIf { it.isPickAtEdge }
} else comment

return documentationElement?.takeIf { it.isDocComment && it.cachedOwner.owner != null }
}

/**
* 检测目标注释是否是文档注释
*/
protected abstract val T.isDocComment: Boolean
protected abstract val PsiComment.isDocComment: Boolean

/**
* 目标注释是否可在边缘处拾取
*/
protected open val T.isPickAtEdge: Boolean get() = false
protected open val PsiComment.isPickAtEdge: Boolean get() = false

final override fun getDocumentationOwner(documentationElement: PsiElement): PsiElement? {
@Suppress("UNCHECKED_CAST")
return (documentationElement as? T)?.cachedOwner?.owner
return (documentationElement as? PsiComment)?.cachedOwner?.owner
}

/**
* 缓存的注释所有者
*/
@Suppress("MemberVisibilityCanBePrivate")
protected val T.cachedOwner: CachedOwner
protected val PsiComment.cachedOwner: CachedOwner
get() {
val modificationStamp = containingFile.modificationStamp
return DOCUMENTATION_OWNER_CACHE[this@cachedOwner]
Expand All @@ -59,7 +57,7 @@ abstract class AbstractDocumentationElementProvider<T : PsiComment> : Documentat
/**
* 文档注释所有者
*/
protected open val T.documentationOwner: PsiElement? get() = super.getDocumentationOwner(this)
protected open val PsiComment.documentationOwner: PsiElement? get() = super.getDocumentationOwner(this)

/**
* 缓存的注释所有者
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.jetbrains.lang.dart.psi.DartComponent
import com.jetbrains.lang.dart.psi.DartDocComment
import com.jetbrains.lang.dart.psi.DartVarDeclarationList

class DartDocumentationElementProvider : AbstractDocumentationElementProvider<PsiComment>() {
class DartDocumentationElementProvider : AbstractDocumentationElementProvider() {

override val PsiComment.isDocComment: Boolean
get() = this@isDocComment is DartDocComment || elementType == DartTokenTypesSets.SINGLE_LINE_DOC_COMMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.intellij.psi.PsiComment
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace

class GoDocumentationElementProvider : AbstractDocumentationElementProvider<PsiComment>() {
class GoDocumentationElementProvider : AbstractDocumentationElementProvider() {

override val PsiComment.isDocComment: Boolean
get() = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import com.jetbrains.cidr.lang.psi.OCDeclarationStatement
import com.jetbrains.cidr.lang.psi.OCStruct
import com.jetbrains.cidr.lang.types.OCStructType

class ObjectiveCDocumentationElementProvider : AbstractDocumentationElementProvider<PsiDocCommentBase>() {
class ObjectiveCDocumentationElementProvider : AbstractDocumentationElementProvider() {

override val PsiDocCommentBase.isDocComment: Boolean
get() = true
override val PsiComment.isDocComment: Boolean
get() = this@isDocComment is PsiDocCommentBase

override val PsiDocCommentBase.documentationOwner: PsiElement?
get() = innerOwner
override val PsiComment.documentationOwner: PsiElement?
get() = (this@documentationOwner as PsiDocCommentBase).innerOwner

companion object {
private val IS_OC_STRUCT: (PsiElement) -> Boolean = { it is OCStruct }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package cn.yiiguxing.plugin.translate.util

import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.util.BuildNumber

// http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
enum class IdeVersion(val buildNumber: Int) {
IDE2018_1(181),
IDE2019_1(191);

companion object {

val buildNumber: BuildNumber get() = ApplicationInfo.getInstance().build

@Suppress("MemberVisibilityCanBePrivate")
val BUILD_NUMBER = ApplicationInfo.getInstance().build.baselineVersion
val BUILD_NUMBER = buildNumber.baselineVersion

val isIde2018OrNewer: Boolean = BUILD_NUMBER >= IDE2018_1.buildNumber

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class WordBookView {
.addMenuItem(panel, message("wordbook.window.menu.copy"), AllIcons.Actions.Copy) { word ->
CopyPasteManager.getInstance().setContents(StringSelection(word.word))
}
.addMenuItem(panel, message("wordbook.window.menu.delete"), AllIcons.Actions.Delete) { word ->
.addMenuItem(panel, message("wordbook.window.menu.delete"), AllIcons.Actions.Cancel) { word ->
val id = word.id
if (id != null) {
val confirmed = Messages.showOkCancelDialog(
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
<p><a href="https://github.com/YiiGuxing/TranslationPlugin/issues">Send feedback</a></p>
]]></description>

<!--suppress PluginXmlValidity -->
<change-notes><![CDATA[
<ul>
<li>修复了Dart语言中无法对类的第一个成员的文档注释进行文档翻译的问题</li>
<li>修复了一些Bug</li>
</ul>
<a href="https://github.com/YiiGuxing/TranslationPlugin/blob/master/CHANGELOG.md"><b>Full Changelog History</b></a>
]]></change-notes>
Expand Down Expand Up @@ -87,6 +88,7 @@
factoryClass="cn.yiiguxing.plugin.translate.wordbook.WordBookToolWindowFactory"/>

<postStartupActivity implementation="cn.yiiguxing.plugin.translate.update.UpdateManager"/>
<postStartupActivity implementation="cn.yiiguxing.plugin.translate.activity.IdeaVersionUpgradeNoticeActivity"/>
<postStartupActivity implementation="cn.yiiguxing.plugin.translate.activity.WordOfTheDayStartupActivity"/>
</extensions>

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/messages/TranslationBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ error.youdao.invalidKey=Invalid application key - <a href="{0}">Settings</a>
notification.title.settings.appKey=Set up your App key for translator
notification.content.settings.appKey=Your application key is empty or invalid, please set a proper key.<br/><br/><a href="{0}">Don't show again</a> - <a href="{1}">Settings</a>
notification.ttk.update.failed=Failed to update TKK, please check your network connection
notification.idea.version=This version of the IDE will be not supported in a future release, please upgrade the IDE to keep getting new features!
notification.idea.version.title=Translation: Outdated IDE version
notification.idea.version.do.not.show.again=Do not show again
notification.title.wordbook=Wordbook
notification.content.wordbook.addFailed=Unable to add word
wordbook.window.action.refresh=Refresh
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/messages/TranslationBundle_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ error.youdao.invalidKey=AppKey无效 - <a href="{0}">设置</a>
notification.title.settings.appKey=设置App Key
notification.content.settings.appKey=当前App Key为空或者无效,请设置App Key.<br/><br/><a href="{0}">不再提示</a> - <a href="{1}">设置</a>
notification.ttk.update.failed=更新TTK失败,请检查网络连接
notification.idea.version=将来的版本将不再支持此版本的IDE,请升级IDE以持续获取新的功能!
notification.idea.version.title=Translation: 过旧的IDE版本
notification.idea.version.do.not.show.again=不再提示
notification.title.wordbook=单词本
notification.content.wordbook.addFailed=无法添加单词
wordbook.window.action.refresh=刷新
Expand Down

0 comments on commit b253559

Please sign in to comment.