From acc67cfca650d0fb20f510566b1cc242a42714f7 Mon Sep 17 00:00:00 2001 From: Nebojsa Vuksic Date: Mon, 21 Jul 2025 09:45:43 +0200 Subject: [PATCH] Add Weather and Chat app sample tabs --- .../toolWindow/MyToolWindowFactory.kt | 38 +++---------------- .../plugins/template/ui/ChatAppSample.kt | 24 ++++++++++++ .../plugins/template/ui/WeatherAppSample.kt | 22 +++++++++++ 3 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 src/main/kotlin/org/jetbrains/plugins/template/ui/ChatAppSample.kt create mode 100644 src/main/kotlin/org/jetbrains/plugins/template/ui/WeatherAppSample.kt diff --git a/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt b/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt index e1ade10..5450cd7 100644 --- a/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt +++ b/src/main/kotlin/org/jetbrains/plugins/template/toolWindow/MyToolWindowFactory.kt @@ -1,48 +1,20 @@ package org.jetbrains.plugins.template.toolWindow -import androidx.compose.foundation.layout.* -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.unit.dp -import com.intellij.openapi.components.service import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.wm.ToolWindow import com.intellij.openapi.wm.ToolWindowFactory -import com.intellij.ui.content.ContentFactory -import org.jetbrains.jewel.bridge.JewelComposePanel -import org.jetbrains.jewel.ui.component.DefaultButton -import org.jetbrains.jewel.ui.component.Text -import org.jetbrains.plugins.template.ComposeTemplateBundle -import org.jetbrains.plugins.template.services.MyProjectService +import org.jetbrains.jewel.bridge.addComposeTab +import org.jetbrains.plugins.template.ui.ChatAppSample +import org.jetbrains.plugins.template.ui.WeatherAppSample class MyToolWindowFactory : ToolWindowFactory, DumbAware { override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { - val myToolWindow = MyToolWindow() - val content = ContentFactory.getInstance().createContent(myToolWindow.getContent(), null, false) - toolWindow.contentManager.addContent(content) + toolWindow.addComposeTab("Weather App") { WeatherAppSample() } + toolWindow.addComposeTab("Chat App") { ChatAppSample() } } override fun shouldBeAvailable(project: Project) = true - class MyToolWindow() { - private val service = service() - - fun getContent() = JewelComposePanel { - Column(Modifier.fillMaxWidth().padding(16.dp)) { - var param by remember { mutableStateOf("?") } - Text(ComposeTemplateBundle.message("randomLabel", param)) - Spacer(Modifier.height(8.dp)) - DefaultButton(onClick = { - param = service.getRandomNumber().toString() - }) { - Text(ComposeTemplateBundle.message("shuffle")) - } - } - } - } } diff --git a/src/main/kotlin/org/jetbrains/plugins/template/ui/ChatAppSample.kt b/src/main/kotlin/org/jetbrains/plugins/template/ui/ChatAppSample.kt new file mode 100644 index 0000000..d83f9fb --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/ui/ChatAppSample.kt @@ -0,0 +1,24 @@ +package org.jetbrains.plugins.template.ui + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.foundation.theme.JewelTheme +import org.jetbrains.jewel.ui.component.Text + +@Composable +fun ChatAppSample() { + Column(Modifier + .fillMaxWidth() + .heightIn(20.dp) + .padding(16.dp)) { + Text( + "Not yet implemented", + style = JewelTheme.defaultTextStyle + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/plugins/template/ui/WeatherAppSample.kt b/src/main/kotlin/org/jetbrains/plugins/template/ui/WeatherAppSample.kt new file mode 100644 index 0000000..4dd70fa --- /dev/null +++ b/src/main/kotlin/org/jetbrains/plugins/template/ui/WeatherAppSample.kt @@ -0,0 +1,22 @@ +package org.jetbrains.plugins.template.ui + +import androidx.compose.foundation.layout.* +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import org.jetbrains.jewel.foundation.theme.JewelTheme +import org.jetbrains.jewel.ui.component.Text + + +@Composable +fun WeatherAppSample() { + Column(Modifier + .fillMaxWidth() + .heightIn(20.dp) + .padding(16.dp)) { + Text( + "Not yet implemented", + style = JewelTheme.defaultTextStyle + ) + } +} \ No newline at end of file