Skip to content

Commit e9ae525

Browse files
committed
优化 drift 功能
1 parent 4a4f88b commit e9ae525

15 files changed

Lines changed: 646 additions & 343 deletions

.idea/kotlinc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 173 additions & 151 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ dependencies {
7272
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:latest.release")
7373
intellijPlatform {
7474
intellijIdeaCommunity("2025.2.1")
75-
// local("/Applications/Android Studio.app")
7675
bundledPlugins(bPlugins)
7776
//"io.flutter:88.2.0"
78-
plugins("Dart:$dartVersion","io.flutter:88.2.0")
77+
plugins("Dart:$dartVersion")
7978
pluginVerifier()
8079
zipSigner()
8180
javaCompiler()
@@ -85,7 +84,6 @@ dependencies {
8584
testBundledModules("intellij.libraries.ktor.client", "intellij.libraries.ktor.client.cio")
8685
testPlugins("Dart:$dartVersion")
8786
testFramework(TestFrameworkType.Platform)
88-
// jewel
8987
bundledModule("intellij.platform.jewel.foundation")
9088
bundledModule("intellij.platform.jewel.ui")
9189
bundledModule("intellij.platform.jewel.ideLafBridge")
@@ -141,6 +139,7 @@ tasks {
141139

142140
patchPluginXml {
143141
sinceBuild.set(sinceBuildVersion)
142+
untilBuild.set("253.*")
144143
changeNotes.set(myChangeLog)
145144
pluginDescription.set(file("插件介绍h.md").readText().trim())
146145
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
kotlin.stdlib.default.dependency=false
22
pluginVersion=6.9.0
3-
dartVersion=500.0.0
3+
dartVersion=502.0.0
44
sinceBuildVersion=252
55
kotlin.daemon.jvmargs=-Xmx5024m
66
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8

src/main/kotlin/icons/MyIcons.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package icons
22

33
import com.intellij.openapi.util.IconLoader
4+
import org.jetbrains.jewel.ui.icon.PathIconKey
45
import javax.swing.Icon
56

67
object MyImages {
@@ -18,4 +19,6 @@ object MyImages {
1819
fun load(path: String): Icon {
1920
return IconLoader.getIcon(path, MyImages::class.java)
2021
}
22+
23+
val wxDs = PathIconKey("images/wx.png", MyImages::class.java)
2124
}

src/main/kotlin/shop/itbug/flutterx/constance/StringConstance.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ object Links {
1616
const val OPEN_IN =
1717
"https://mdddj.github.io/flutterx-doc/en/settings/quick-open-subdirectory/"
1818

19+
const val DriftDocument = "https://mdddj.github.io/flutterx-doc/en/vm/drift/"
1920

2021
//链接
2122
const val LINK = "https://mdddj.github.io/flutterx-doc/en/settings/links/"

src/main/kotlin/shop/itbug/flutterx/window/vm/DriftComposeComponent.kt

Lines changed: 186 additions & 14 deletions
Large diffs are not rendered by default.

src/main/kotlin/shop/itbug/flutterx/window/vm/FlutterAppsTab.kt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package shop.itbug.flutterx.window.vm
22

3-
import androidx.compose.foundation.layout.Arrangement
4-
import androidx.compose.foundation.layout.Column
5-
import androidx.compose.foundation.layout.Row
6-
import androidx.compose.foundation.layout.fillMaxSize
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.layout.*
76
import androidx.compose.runtime.*
87
import androidx.compose.ui.Alignment
98
import androidx.compose.ui.Modifier
109
import androidx.compose.ui.unit.dp
10+
import androidx.compose.ui.window.Popup
1111
import com.intellij.ide.BrowserUtil
1212
import com.intellij.openapi.project.Project
13+
import icons.MyImages
1314
import org.jetbrains.jewel.foundation.theme.JewelTheme
15+
import org.jetbrains.jewel.ui.component.Icon
1416
import org.jetbrains.jewel.ui.component.Link
1517
import org.jetbrains.jewel.ui.component.Text
1618
import shop.itbug.flutterx.common.dart.FlutterAppInstance
@@ -27,6 +29,7 @@ import java.net.URI
2729
@Composable
2830
fun FlutterAppsTabComponent(project: Project, body: @Composable (app: FlutterAppInstance) -> Unit) {
2931
var tabIndex by remember { mutableIntStateOf(0) }
32+
var showRewardPopup by remember { mutableStateOf(false) }
3033
val flutterAppList by FlutterXVMService.getInstance(project).runningApps.collectAsState()
3134
val isEnableFuture = FlutterXVMService.getInstance(project).isEnableFuture.collectAsState().value
3235
val showRewardAction = PluginConfig.getState(project).showRewardAction
@@ -64,9 +67,27 @@ If you are running on a real device, please make sure the device is connected to
6467
})
6568

6669
if (showRewardAction) {
67-
Link(PluginBundle.get("reward") + "(wechat)", onClick = {
68-
BrowserUtil.browse(URI.create("https://itbug.shop/static/ds.68eb4cac.jpg"))
69-
})
70+
Box {
71+
Link(PluginBundle.get("reward") + "(WeChat)", onClick = {
72+
showRewardPopup = !showRewardPopup
73+
})
74+
75+
if (showRewardPopup) {
76+
Popup(onDismissRequest = { showRewardPopup = false }) {
77+
Box(
78+
modifier = Modifier.background(JewelTheme.globalColors.panelBackground)
79+
.border(1.dp, JewelTheme.globalColors.borders.normal)
80+
.padding(12.dp)
81+
) {
82+
Icon(
83+
MyImages.wxDs,
84+
modifier = Modifier.size(200.dp),
85+
contentDescription = "微信打赏"
86+
)
87+
}
88+
}
89+
}
90+
}
7091
}
7192

7293
if (showRewardAction) {

src/main/kotlin/vm/drift/DriftModels.kt

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package vm.drift
22

33
import com.google.gson.JsonObject
4+
import com.intellij.openapi.fileEditor.FileEditorManager
5+
import com.intellij.openapi.project.Project
6+
import com.intellij.testFramework.LightVirtualFile
47

58
/**
69
* Drift 数据库基础信息
@@ -45,6 +48,33 @@ data class DriftQueryResult(
4548
val rows: List<DriftRow>
4649
)
4750

51+
/**
52+
* 将查询结果转换为 CSV 字符串
53+
*/
54+
fun DriftQueryResult.toCsv(): String {
55+
val header = columns.joinToString(",") { "\"${it.replace("\"", "\"\"")}\"" }
56+
val dataRows = rows.joinToString("\n") { row ->
57+
columns.joinToString(",") { col ->
58+
val value = row.data[col]?.toString() ?: ""
59+
"\"${value.replace("\"", "\"\"")}\""
60+
}
61+
}
62+
return "$header\n$dataRows"
63+
}
64+
65+
66+
/**
67+
* 在编辑器中打开虚拟的 csv文件
68+
*/
69+
fun DriftQueryResult.openInEditor(project: Project) {
70+
val csvContent = toCsv()
71+
val fileName = "Query_Result_${System.currentTimeMillis()}.csv"
72+
val virtualFile = LightVirtualFile(fileName, csvContent)
73+
FileEditorManager.getInstance(project).openFile(virtualFile, true)
74+
75+
}
76+
77+
4878
/**
4979
* Drift 支持的 SQL 类型
5080
*/
@@ -73,7 +103,7 @@ fun parseDatabaseDescription(id: Int, dbName: String, json: JsonObject): DriftDa
73103
} ?: emptyList()
74104
DriftTable(tableName, tableType, columns)
75105
} ?: emptyList()
76-
106+
77107
return DriftDatabase(id, dbName, dateTimeAsText, tables)
78108
}
79109

@@ -95,9 +125,19 @@ enum class DriftFilterOperator(val label: String, val sql: String) {
95125
/**
96126
* 筛选条件
97127
*/
128+
98129
data class DriftFilter(
99130
val columnName: String,
100131
val columnType: String,
101132
val operator: DriftFilterOperator,
102133
val value: String
103134
)
135+
136+
/**
137+
* 排序条件
138+
*/
139+
data class DriftOrderBy(
140+
val columnName: String,
141+
val isAscending: Boolean = true
142+
)
143+

src/main/kotlin/vm/drift/DriftServices.kt

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ data class DriftState(
3838
val logs: List<String> = emptyList(),
3939
val selectedColumns: Set<String> = emptySet(),
4040
val filters: List<DriftFilter> = emptyList(),
41+
val orderBy: List<DriftOrderBy> = emptyList(),
4142
val limit: Int = 100
4243
)
4344

@@ -136,7 +137,8 @@ class DriftServices(val vmService: VmService) : CoroutineScope, VmServiceListene
136137
selectedTable = null,
137138
queryResult = null,
138139
selectedColumns = emptySet(),
139-
filters = emptyList()
140+
filters = emptyList(),
141+
orderBy = emptyList()
140142
)
141143
}
142144

@@ -147,7 +149,8 @@ class DriftServices(val vmService: VmService) : CoroutineScope, VmServiceListene
147149
_state.value = _state.value.copy(
148150
selectedTable = table,
149151
selectedColumns = table.columns.map { it.name }.toSet(),
150-
filters = emptyList()
152+
filters = emptyList(),
153+
orderBy = emptyList()
151154
)
152155
executeSelect(table.name)
153156
}
@@ -185,6 +188,12 @@ class DriftServices(val vmService: VmService) : CoroutineScope, VmServiceListene
185188
sql += " WHERE ${whereClauses.joinToString(" AND ")}"
186189
}
187190
}
191+
192+
val orderBy = _state.value.orderBy
193+
if (orderBy.isNotEmpty()) {
194+
val orderClauses = orderBy.joinToString(", ") { "${it.columnName} ${if (it.isAscending) "ASC" else "DESC"}" }
195+
sql += " ORDER BY $orderClauses"
196+
}
188197

189198
if (limit > 0) sql += " LIMIT $limit"
190199

@@ -233,6 +242,29 @@ class DriftServices(val vmService: VmService) : CoroutineScope, VmServiceListene
233242
applyFilters()
234243
}
235244

245+
/**
246+
* 切换排序
247+
*/
248+
fun toggleOrderBy(columnName: String) {
249+
val current = _state.value.orderBy
250+
val existing = current.find { it.columnName == columnName }
251+
val next = when {
252+
existing == null -> current + DriftOrderBy(columnName, true)
253+
existing.isAscending -> current.filter { it.columnName != columnName } + DriftOrderBy(columnName, false)
254+
else -> current.filter { it.columnName != columnName }
255+
}
256+
_state.value = _state.value.copy(orderBy = next)
257+
applyFilters()
258+
}
259+
260+
/**
261+
* 清空排序
262+
*/
263+
fun clearOrderBy() {
264+
_state.value = _state.value.copy(orderBy = emptyList())
265+
applyFilters()
266+
}
267+
236268
/**
237269
* 应用筛选并查询
238270
*/

0 commit comments

Comments
 (0)