-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated ActionSystem to Compose Traversal API & UiDataProvider API (#…
…532)
- Loading branch information
1 parent
576c345
commit 9e136d9
Showing
24 changed files
with
395 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...dation/src/main/kotlin/org/jetbrains/jewel/foundation/actionSystem/DataProviderContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jetbrains.jewel.foundation.actionSystem | ||
|
||
public interface DataProviderContext { | ||
public fun <TValue : Any> set( | ||
key: String, | ||
value: TValue?, | ||
) | ||
|
||
public fun <TValue : Any> lazy( | ||
key: String, | ||
initializer: () -> TValue?, | ||
) | ||
} |
5 changes: 2 additions & 3 deletions
5
...ridge/actionSystem/DataProviderElement.kt → ...ation/actionSystem/DataProviderElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
foundation/src/main/kotlin/org/jetbrains/jewel/foundation/actionSystem/DataProviderNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.jetbrains.jewel.foundation.actionSystem | ||
|
||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusEventModifierNode | ||
import androidx.compose.ui.focus.FocusState | ||
import androidx.compose.ui.node.TraversableNode | ||
|
||
public class DataProviderNode( | ||
public var dataProvider: DataProviderContext.() -> Unit, | ||
) : Modifier.Node(), FocusEventModifierNode, TraversableNode { | ||
public var hasFocus: Boolean = false | ||
|
||
override fun onFocusEvent(focusState: FocusState) { | ||
hasFocus = focusState.hasFocus | ||
} | ||
|
||
override val traverseKey: TraverseKey = TraverseKey | ||
|
||
public companion object TraverseKey | ||
} |
21 changes: 21 additions & 0 deletions
21
foundation/src/main/kotlin/org/jetbrains/jewel/foundation/actionSystem/ProvideData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.jetbrains.jewel.foundation.actionSystem | ||
|
||
import androidx.compose.foundation.focusable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusEventModifierNode | ||
|
||
/** | ||
* Configure component to provide data for IntelliJ Actions system. | ||
* | ||
* Use this modifier to provide context related data that can be used by | ||
* IntelliJ Actions functionality such as Search Everywhere, Action Popups | ||
* etc. | ||
* | ||
* Important note: modifiers order is important, so be careful with order | ||
* of [focusable] and [provideData] (see [FocusEventModifierNode]). | ||
* | ||
* This can be traversed from Modifier.Node() using Compose traversal API using DataProviderNode as a TraverseKey | ||
* | ||
*/ | ||
@Suppress("unused") | ||
public fun Modifier.provideData(dataProvider: DataProviderContext.() -> Unit): Modifier = this then DataProviderElement(dataProvider) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
plugins { | ||
jewel | ||
`jewel-publish` | ||
`jewel-check-public-api` | ||
`ide-version-checker` | ||
alias(libs.plugins.composeDesktop) | ||
alias(libs.plugins.ideaPluginModule) | ||
} | ||
|
||
// Because we need to define IJP dependencies, the dependencyResolutionManagement | ||
// from settings.gradle.kts is overridden and we have to redeclare everything here. | ||
repositories { | ||
google() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
mavenCentral() | ||
|
||
intellijPlatform { | ||
defaultRepositories() | ||
} | ||
} | ||
|
||
dependencies { | ||
testImplementation(projects.ui) { | ||
exclude(group = "org.jetbrains.kotlinx") | ||
} | ||
testImplementation(projects.ideLafBridge) | ||
|
||
intellijPlatform { | ||
intellijIdeaCommunity(libs.versions.idea) | ||
instrumentationTools() | ||
} | ||
|
||
testImplementation(compose.desktop.uiTestJUnit4) | ||
testImplementation(compose.desktop.currentOs) { | ||
exclude(group = "org.jetbrains.compose.material") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
ide-laf-bridge-tests/src/test/kotlin/org/jetbrains/jewel/bridge/actionSystem/TestDataSink.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.jetbrains.jewel.bridge.actionSystem | ||
|
||
import com.intellij.openapi.actionSystem.DataKey | ||
import com.intellij.openapi.actionSystem.DataProvider | ||
import com.intellij.openapi.actionSystem.DataSink | ||
import com.intellij.openapi.actionSystem.DataSnapshotProvider | ||
import com.intellij.openapi.actionSystem.UiDataProvider | ||
|
||
@Suppress("OverrideOnly", "NonExtendableApiUsage") | ||
internal class TestDataSink : DataSink { | ||
val allData = mutableMapOf<String, Any>() | ||
|
||
fun clear() { | ||
allData.clear() | ||
} | ||
|
||
inline fun <reified T> get(key: String): T? { | ||
val data = allData[key] as T? | ||
if (data is T) return data | ||
return null | ||
} | ||
|
||
override fun dataSnapshot(provider: DataSnapshotProvider) { | ||
provider.dataSnapshot(this) | ||
} | ||
|
||
override fun uiDataSnapshot(provider: DataProvider) { | ||
// NOT needed in current tests | ||
} | ||
|
||
override fun uiDataSnapshot(provider: UiDataProvider) { | ||
provider.uiDataSnapshot(this) | ||
} | ||
|
||
override fun <T : Any> setNull(key: DataKey<T>) { | ||
allData.remove(key.name) | ||
} | ||
|
||
override fun <T : Any> set( | ||
key: DataKey<T>, | ||
data: T?, | ||
) { | ||
if (data != null) { | ||
allData[key.name] = data | ||
} | ||
} | ||
|
||
override fun <T : Any> lazy( | ||
key: DataKey<T>, | ||
data: () -> T?, | ||
) { | ||
set(key, data()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.