Skip to content

Commit a3f69ec

Browse files
committed
✅ (version): 兼容低版本
1 parent 2ec416a commit a3f69ec

File tree

10 files changed

+49
-55
lines changed

10 files changed

+49
-55
lines changed

build.gradle.kts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id("java")
3-
id("org.jetbrains.kotlin.jvm") version "1.9.23"
4-
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.23"
3+
id("org.jetbrains.kotlin.jvm") version "1.9.24"
4+
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.24"
55
id("org.jetbrains.intellij") version "1.17.2"
66
}
77

@@ -19,12 +19,13 @@ repositories {
1919
dependencies {
2020
implementation("com.squareup.okhttp3:okhttp:4.12.0")
2121
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
22+
implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.24")
2223
}
2324

2425
// Configure Gradle IntelliJ Plugin
2526
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
2627
intellij {
27-
version.set("2023.2.5")
28+
version.set("2021.3")
2829
type.set("PC") // Target IDE Platform
2930

3031
plugins.set(listOf(/* Plugin Dependencies */))
@@ -33,15 +34,15 @@ intellij {
3334
tasks {
3435
// Set the JVM compatibility versions
3536
withType<JavaCompile> {
36-
sourceCompatibility = "17"
37-
targetCompatibility = "17"
37+
sourceCompatibility = "11"
38+
targetCompatibility = "11"
3839
}
3940
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
40-
kotlinOptions.jvmTarget = "17"
41+
kotlinOptions.jvmTarget = "11"
4142
}
4243

4344
patchPluginXml {
44-
sinceBuild.set("232")
45+
sinceBuild.set("213")
4546
untilBuild.set("242.*")
4647
}
4748

src/main/kotlin/irony/pycharm/qsseditor/QSSAction.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
package irony.pycharm.qsseditor
1212

13-
import com.intellij.openapi.actionSystem.ActionUpdateThread
1413
import com.intellij.openapi.actionSystem.AnAction
1514
import com.intellij.openapi.actionSystem.AnActionEvent
1615
import com.intellij.openapi.actionSystem.CommonDataKeys
@@ -20,8 +19,13 @@ import com.intellij.openapi.vfs.VirtualFile
2019

2120
private val Log = logger<QSSAction>()
2221

22+
enum class ActionUpdateThread {
23+
BGT,
24+
EDT,
25+
}
26+
2327
class QSSAction : AnAction() {
24-
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
28+
fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
2529

2630
override fun update(e: AnActionEvent) {
2731
// 默认菜单不可用,需要判断当前文件类型
@@ -31,7 +35,7 @@ class QSSAction : AnAction() {
3135
if (!(ext == "qss" || ext == "css" || ext == "style")) {
3236
return
3337
}
34-
e.presentation.isEnabledAndVisible = true
38+
e.presentation.isEnabledAndVisible = QSSClient.isConnected()
3539
}
3640

3741
override fun actionPerformed(e: AnActionEvent) {

src/main/kotlin/irony/pycharm/qsseditor/QSSBundle.kt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,17 @@ import org.jetbrains.annotations.Nls
1515
import org.jetbrains.annotations.NonNls
1616
import org.jetbrains.annotations.Nullable
1717
import org.jetbrains.annotations.PropertyKey
18-
import java.util.function.Supplier
1918

20-
object QSSBundle {
21-
private const val BUNDLE: @NonNls String = "messages.QSSBundle"
22-
private val INSTANCE = DynamicBundle(QSSBundle::class.java, BUNDLE)
23-
24-
fun message(
25-
key:
26-
@PropertyKey(resourceBundle = BUNDLE)
27-
String,
28-
vararg params: Any,
29-
): @Nls String {
30-
return INSTANCE.messageOrDefault(key, key, *params)
31-
}
19+
private const val BUNDLE: @NonNls String = "messages.QSSBundle"
3220

21+
object QSSBundle : DynamicBundle(BUNDLE) {
3322
fun message(
3423
key:
3524
@PropertyKey(resourceBundle = BUNDLE)
3625
String,
3726
@Nullable @Nls defaultValue: String,
3827
vararg params: Any,
3928
): @Nls String {
40-
return INSTANCE.messageOrDefault(key, defaultValue, *params)
41-
}
42-
43-
fun lazyMessage(
44-
@PropertyKey(resourceBundle = BUNDLE) key: String,
45-
vararg params: Any,
46-
): Supplier<@Nls String> {
47-
return INSTANCE.getLazyMessage(key, *params)
29+
return messageOrDefault(key, defaultValue, *params)
4830
}
4931
}

src/main/kotlin/irony/pycharm/qsseditor/QSSClient.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class QSSClient : WebSocketListener() {
4242
response: Response,
4343
) {
4444
twice = 0
45-
Log.debug("onOpen")
45+
Log.info("onOpen")
4646
}
4747

4848
override fun onMessage(
@@ -161,6 +161,10 @@ class QSSClient : WebSocketListener() {
161161
disconnect()
162162
}
163163

164+
fun isConnected(): Boolean {
165+
return socket != null
166+
}
167+
164168
private fun buildMessage(
165169
method: String,
166170
message: List<String>,
@@ -181,7 +185,7 @@ class QSSClient : WebSocketListener() {
181185
@Nullable message: List<String>,
182186
delay: Boolean = false,
183187
) {
184-
if (message.isEmpty()) {
188+
if (socket == null || message.isEmpty()) {
185189
return
186190
}
187191
if (delay) {

src/main/kotlin/irony/pycharm/qsseditor/QSSConfig.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
package irony.pycharm.qsseditor
1212

13-
import com.intellij.openapi.diagnostic.logger
1413
import com.intellij.openapi.options.BoundSearchableConfigurable
1514
import com.intellij.openapi.options.Configurable.NoScroll
1615
import com.intellij.openapi.ui.DialogPanel
@@ -19,23 +18,27 @@ import com.intellij.ui.dsl.builder.bindSelected
1918
import com.intellij.ui.dsl.builder.bindText
2019
import com.intellij.ui.dsl.builder.panel
2120

22-
private val Log = logger<QSSConfig>()
21+
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
22+
@Retention(AnnotationRetention.BINARY)
23+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
24+
annotation class ExperimentalQSSConfig
2325

26+
@ExperimentalQSSConfig
2427
class QSSConfig :
2528
BoundSearchableConfigurable(
2629
"QSS Editor",
27-
QSSBundle.message("setting.topic.title", "QSS Editor Configurable"),
30+
QSSBundle.message("setting.topic.text", "QSS Editor Configurable"),
2831
),
2932
NoScroll {
3033
override fun createPanel(): DialogPanel {
3134
return panel {
32-
row(QSSBundle.message("setting.host.title", "Host")) {
35+
row(QSSBundle.message("setting.host.text", "Host")) {
3336
textField().bindText(QSSState.instance::host)
3437
}
35-
row(QSSBundle.message("setting.port.title", "Port")) {
38+
row(QSSBundle.message("setting.port.text", "Port")) {
3639
intTextField(IntRange(1000, 65535)).bindIntText(QSSState.instance::port)
3740
}
38-
row(QSSBundle.message("setting.auto.title", "Auto Apply")) {
41+
row(QSSBundle.message("setting.auto.text", "Auto Apply")) {
3942
checkBox("").bindSelected(QSSState.instance::auto)
4043
}
4144
}

src/main/kotlin/irony/pycharm/qsseditor/QSSDocumentListener.kt renamed to src/main/kotlin/irony/pycharm/qsseditor/QSSListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package irony.pycharm.qsseditor
33
import com.intellij.openapi.editor.event.DocumentEvent
44
import com.intellij.openapi.editor.event.DocumentListener
55

6-
class QSSDocumentListener : DocumentListener {
6+
class QSSListener : DocumentListener {
77
override fun documentChanged(event: DocumentEvent) {
88
if (QSSState.instance::auto.get()) {
99
QSSClient.applyStyle(listOf(event.document.text), true)

src/main/kotlin/irony/pycharm/qsseditor/QSSStartup.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ package irony.pycharm.qsseditor
1212

1313
import com.intellij.openapi.diagnostic.logger
1414
import com.intellij.openapi.project.Project
15-
import com.intellij.openapi.startup.ProjectActivity
15+
import com.intellij.openapi.startup.StartupActivity
1616

1717
private val Log = logger<QSSStartup>()
1818

19-
class QSSStartup : ProjectActivity {
20-
override suspend fun execute(project: Project) {
19+
class QSSStartup : StartupActivity {
20+
override fun runActivity(project: Project) {
2121
// 启动客户端连接
2222
Log.info("project[${project.name}] opened")
2323
QSSClient.connect(QSSState.instance.host, QSSState.instance.port)

src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
22
<idea-plugin>
33
<!-- Unique identifier of the plugin. It should be FQN. It cannot be changed between the plugin versions. -->
4-
<id>irony.pycharm.QSSEditor</id>
4+
<id>irony.ide.plugin.qsseditor</id>
55

66
<!-- Public plugin name should be written in Title Case.
77
Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-name -->
@@ -46,7 +46,7 @@ Must Install Proxy Server from first(首先需要安装设计师插件)<br/><br/
4646
<!-- Extension points defined by the plugin.
4747
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
4848
<extensions defaultExtensionNs="com.intellij">
49-
<backgroundPostStartupActivity implementation="irony.pycharm.qsseditor.QSSStartup"/>
49+
<postStartupActivity implementation="irony.pycharm.qsseditor.QSSStartup"/>
5050
<applicationService
5151
serviceImplementation="irony.pycharm.qsseditor.QSSState"/>
5252
<applicationConfigurable
@@ -56,7 +56,7 @@ Must Install Proxy Server from first(首先需要安装设计师插件)<br/><br/
5656
id="irony.pycharm.qsseditor.QSSConfig"
5757
displayName="QSS Editor"/>
5858
<editorFactoryDocumentListener
59-
implementation="irony.pycharm.qsseditor.QSSDocumentListener"/>
59+
implementation="irony.pycharm.qsseditor.QSSListener"/>
6060
</extensions>
6161

6262
<applicationListeners>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
action.apply.text=Apply Style
2-
setting.topic.title=QSS Editor Configurable
3-
setting.auto.title=Auto Apply
4-
setting.host.title=Host
5-
setting.port.title=Port
2+
setting.topic.text=QSS Editor Configurable
3+
setting.auto.text=Auto Apply
4+
setting.host.text=Host
5+
setting.port.text=Port
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
action.apply.title=应用样式
2-
setting.topic.title=QSS 编辑器配置
3-
setting.auto.title=自动应用
4-
setting.host.title=地址
5-
setting.port.title=端口
1+
action.apply.text=应用样式
2+
setting.topic.text=QSS 编辑器配置
3+
setting.auto.text=自动应用
4+
setting.host.text=地址
5+
setting.port.text=端口

0 commit comments

Comments
 (0)