├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ └── release.yml ├── .gitignore ├── .run ├── Run IDE with Plugin.run.xml ├── Run Plugin Tests.run.xml └── Run Plugin Verification.run.xml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── previews └── preview.mp4 ├── settings.gradle.kts └── src └── main ├── kotlin └── com │ └── github │ └── mzdm │ └── embedded_dartpad │ ├── app │ ├── constants │ │ └── Icons.kt │ └── helpers │ │ ├── ComponentList.kt │ │ └── SingleComponentBuilder.kt │ ├── browser │ ├── Browser.kt │ └── utils │ │ └── HtmlContentRenderer.kt │ ├── dartpad │ ├── data │ │ ├── DartTemplates.kt │ │ └── FlutterTemplates.kt │ ├── models │ │ ├── FlutterTemplate.kt │ │ ├── Pad.kt │ │ ├── PadSettings.kt │ │ └── Theme.kt │ └── services │ │ └── PadSettingsService.kt │ ├── editor │ └── actions │ │ └── InvokeToolWindowAction.kt │ └── toolwindow │ ├── DartPadWindowFactory.kt │ ├── DartPadWindowPanel.kt │ └── components │ ├── ToolbarActions.kt │ ├── ToolbarIconAction.kt │ ├── ToolbarPadToggleAction.kt │ ├── ToolbarTextIconAction.kt │ └── ToolbarThemeToggleAction.kt └── resources ├── META-INF ├── plugin.xml └── pluginIcon.svg └── icons ├── embedded_action.svg ├── embedded_toolbar.svg ├── logo_dart.svg ├── logo_flutter.svg ├── theme.svg └── theme_dark.svg /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Dependabot configuration: 2 | # https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates 3 | 4 | version: 2 5 | updates: 6 | # Maintain dependencies for Gradle dependencies 7 | - package-ecosystem: "gradle" 8 | directory: "/" 9 | schedule: 10 | interval: "weekly" 11 | # Maintain dependencies for GitHub Actions 12 | - package-ecosystem: "github-actions" 13 | directory: "/" 14 | schedule: 15 | interval: "weekly" 16 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow created for testing and preparing the plugin release in following steps: 2 | # - validate Gradle Wrapper, 3 | # - run test and verifyPlugin tasks, 4 | # - run buildPlugin task and prepare artifact for the further tests, 5 | # - run IntelliJ Plugin Verifier, 6 | # - create a draft release. 7 | # 8 | # Workflow is triggered on push and pull_request events. 9 | # 10 | # Docs: 11 | # - GitHub Actions: https://help.github.com/en/actions 12 | # - IntelliJ Plugin Verifier GitHub Action: https://github.com/ChrisCarini/intellij-platform-plugin-verifier-action 13 | # 14 | ## JBIJPPTPL 15 | 16 | name: Build 17 | on: 18 | # Trigger the workflow on pushes to only the 'master' and 'dev' branch 19 | # (this avoids duplicate checks being run e.g. for dependabot pull requests). 20 | push: 21 | branches: [master, dev] 22 | 23 | # Trigger the workflow on any pull request 24 | pull_request: 25 | 26 | jobs: 27 | 28 | # Run Gradle Wrapper Validation Action to verify the wrapper's checksum 29 | gradleValidation: 30 | name: Gradle Wrapper 31 | runs-on: ubuntu-latest 32 | steps: 33 | 34 | # Check out current repository 35 | - name: Fetch Sources 36 | uses: actions/checkout@v2 37 | 38 | # Validate wrapper 39 | - name: Gradle Wrapper Validation 40 | uses: gradle/wrapper-validation-action@v1.0.4 41 | 42 | # Run verifyPlugin and test Gradle tasks 43 | # test: 44 | # name: Test 45 | # needs: gradleValidation 46 | # runs-on: ubuntu-latest 47 | # steps: 48 | # 49 | # # Setup Java 11 environment for the next steps 50 | # - name: Setup Java 51 | # uses: actions/setup-java@v2 52 | # with: 53 | # distribution: zulu 54 | # java-version: 11 55 | # 56 | # # Check out current repository 57 | # - name: Fetch Sources 58 | # uses: actions/checkout@v2 59 | # 60 | # # Cache Gradle dependencies 61 | # - name: Setup Gradle Dependencies Cache 62 | # uses: actions/cache@v2.1.6 63 | # with: 64 | # path: ~/.gradle/caches 65 | # key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} 66 | # 67 | # # Cache Gradle Wrapper 68 | # - name: Setup Gradle Wrapper Cache 69 | # uses: actions/cache@v2.1.6 70 | # with: 71 | # path: ~/.gradle/wrapper 72 | # key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} 73 | # 74 | # # Run tests 75 | # - name: Run Tests 76 | # run: ./gradlew test 77 | # 78 | # # Run verifyPlugin Gradle task 79 | # - name: Verify Plugin 80 | # run: ./gradlew verifyPlugin 81 | 82 | # Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs 83 | # Requires test job to be passed 84 | build: 85 | name: Build 86 | # needs: test 87 | runs-on: ubuntu-latest 88 | outputs: 89 | name: ${{ steps.properties.outputs.name }} 90 | version: ${{ steps.properties.outputs.version }} 91 | changelog: ${{ steps.properties.outputs.changelog }} 92 | artifact: ${{ steps.properties.outputs.artifact }} 93 | steps: 94 | 95 | # Setup Java 11 environment for the next steps 96 | - name: Setup Java 97 | uses: actions/setup-java@v2 98 | with: 99 | distribution: zulu 100 | java-version: 11 101 | 102 | # Check out current repository 103 | - name: Fetch Sources 104 | uses: actions/checkout@v2 105 | 106 | # Cache Gradle Dependencies 107 | - name: Setup Gradle Dependencies Cache 108 | uses: actions/cache@v2.1.6 109 | with: 110 | path: ~/.gradle/caches 111 | key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} 112 | 113 | # Cache Gradle Wrapper 114 | - name: Setup Gradle Wrapper Cache 115 | uses: actions/cache@v2.1.6 116 | with: 117 | path: ~/.gradle/wrapper 118 | key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} 119 | 120 | # Set environment variables 121 | - name: Export Properties 122 | id: properties 123 | shell: bash 124 | run: | 125 | PROPERTIES="$(./gradlew properties --console=plain -q)" 126 | VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" 127 | NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" 128 | CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" 129 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 130 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 131 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 132 | ARTIFACT="${NAME}-${VERSION}.zip" 133 | 134 | echo "::set-output name=version::$VERSION" 135 | echo "::set-output name=name::$NAME" 136 | echo "::set-output name=changelog::$CHANGELOG" 137 | echo "::set-output name=artifact::$ARTIFACT" 138 | 139 | # Build artifact using buildPlugin Gradle task 140 | - name: Build Plugin 141 | run: ./gradlew buildPlugin 142 | 143 | # Upload plugin artifact to make it available in the next jobs 144 | - name: Upload artifact 145 | uses: actions/upload-artifact@v2.2.4 146 | with: 147 | name: plugin-artifact 148 | path: ./build/distributions/${{ steps.properties.outputs.artifact }} 149 | 150 | # Verify built plugin using IntelliJ Plugin Verifier tool 151 | # Requires build job to be passed 152 | verify: 153 | name: Verify 154 | needs: build 155 | runs-on: ubuntu-latest 156 | steps: 157 | 158 | # Setup Java 11 environment for the next steps 159 | - name: Setup Java 160 | uses: actions/setup-java@v2 161 | with: 162 | distribution: zulu 163 | java-version: 11 164 | 165 | # Check out current repository 166 | - name: Fetch Sources 167 | uses: actions/checkout@v2 168 | 169 | # Cache Gradle Dependencies 170 | - name: Setup Gradle Dependencies Cache 171 | uses: actions/cache@v2.1.6 172 | with: 173 | path: ~/.gradle/caches 174 | key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} 175 | 176 | # Cache Gradle Wrapper 177 | - name: Setup Gradle Wrapper Cache 178 | uses: actions/cache@v2.1.6 179 | with: 180 | path: ~/.gradle/wrapper 181 | key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} 182 | 183 | # Set environment variables 184 | - name: Export Properties 185 | id: properties 186 | shell: bash 187 | run: | 188 | PROPERTIES="$(./gradlew properties --console=plain -q)" 189 | IDE_VERSIONS="$(echo "$PROPERTIES" | grep "^pluginVerifierIdeVersions:" | base64)" 190 | 191 | echo "::set-output name=ideVersions::$IDE_VERSIONS" 192 | echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" 193 | 194 | # Cache Plugin Verifier IDEs 195 | - name: Setup Plugin Verifier IDEs Cache 196 | uses: actions/cache@v2.1.6 197 | with: 198 | path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides 199 | key: ${{ runner.os }}-plugin-verifier-${{ steps.properties.outputs.ideVersions }} 200 | 201 | # Run IntelliJ Plugin Verifier action using GitHub Action 202 | - name: Verify Plugin 203 | run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} 204 | 205 | # Prepare a draft release for GitHub Releases page for the manual verification 206 | # If accepted and published, release workflow would be triggered 207 | releaseDraft: 208 | name: Release Draft 209 | if: github.event_name != 'pull_request' 210 | needs: [build, verify] 211 | runs-on: ubuntu-latest 212 | steps: 213 | 214 | # Check out current repository 215 | - name: Fetch Sources 216 | uses: actions/checkout@v2 217 | 218 | # Remove old release drafts by using the curl request for the available releases with draft flag 219 | - name: Remove Old Release Drafts 220 | env: 221 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 222 | run: | 223 | curl -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$GITHUB_REPOSITORY/releases \ 224 | | tr '\r\n' ' ' \ 225 | | jq '.[] | select(.draft == true) | .id' \ 226 | | xargs -I '{}' \ 227 | curl -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$GITHUB_REPOSITORY/releases/{} 228 | 229 | # Create new release draft - which is not publicly visible and requires manual acceptance 230 | - name: Create Release Draft 231 | id: createDraft 232 | uses: actions/create-release@v1.1.4 233 | env: 234 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 235 | with: 236 | tag_name: v${{ needs.build.outputs.version }} 237 | release_name: v${{ needs.build.outputs.version }} 238 | body: ${{ needs.build.outputs.changelog }} 239 | draft: true 240 | 241 | # Download plugin artifact provided by the previous job 242 | - name: Download Artifact 243 | uses: actions/download-artifact@v2 244 | with: 245 | name: plugin-artifact 246 | 247 | # Upload artifact as a release asset 248 | - name: Upload Release Asset 249 | id: upload-release-asset 250 | uses: actions/upload-release-asset@v1.0.2 251 | env: 252 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 253 | with: 254 | upload_url: ${{ steps.createDraft.outputs.upload_url }} 255 | asset_path: ./${{ needs.build.outputs.artifact }} 256 | asset_name: ${{ needs.build.outputs.artifact }} 257 | asset_content_type: application/zip 258 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow created for handling the release process based on the draft release prepared 2 | # with the Build workflow. Running the publishPlugin task requires the PUBLISH_TOKEN secret provided. 3 | 4 | name: Release 5 | on: 6 | release: 7 | types: [prereleased, released] 8 | 9 | jobs: 10 | 11 | # Prepare and publish the plugin to the Marketplace repository 12 | release: 13 | name: Publish Plugin 14 | runs-on: ubuntu-latest 15 | steps: 16 | 17 | # Setup Java 11 environment for the next steps 18 | - name: Setup Java 19 | uses: actions/setup-java@v2 20 | with: 21 | distribution: zulu 22 | java-version: 11 23 | 24 | # Check out current repository 25 | - name: Fetch Sources 26 | uses: actions/checkout@v2 27 | with: 28 | ref: ${{ github.event.release.tag_name }} 29 | 30 | # Publish the plugin to the Marketplace 31 | - name: Publish Plugin 32 | env: 33 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} 34 | run: ./gradlew publishPlugin 35 | 36 | # Patch changelog, commit and push to the current repository 37 | changelog: 38 | name: Update Changelog 39 | needs: release 40 | runs-on: ubuntu-latest 41 | steps: 42 | 43 | # Setup Java 11 environment for the next steps 44 | - name: Setup Java 45 | uses: actions/setup-java@v2 46 | with: 47 | distribution: zulu 48 | java-version: 11 49 | 50 | # Check out current repository 51 | - name: Fetch Sources 52 | uses: actions/checkout@v2 53 | with: 54 | ref: ${{ github.event.release.tag_name }} 55 | 56 | # Update Unreleased section with the current version 57 | - name: Patch Changelog 58 | run: ./gradlew patchChangelog 59 | 60 | # Commit patched Changelog 61 | - name: Commit files 62 | run: | 63 | git config --local user.email "action@github.com" 64 | git config --local user.name "GitHub Action" 65 | git commit -m "Update changelog" -a 66 | 67 | # Push changes 68 | - name: Push changes 69 | uses: ad-m/github-push-action@master 70 | with: 71 | branch: main 72 | github_token: ${{ secrets.GITHUB_TOKEN }} 73 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build 4 | -------------------------------------------------------------------------------- /.run/Run IDE with Plugin.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /.run/Run Plugin Tests.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 24 | -------------------------------------------------------------------------------- /.run/Run Plugin Verification.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 25 | 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Changelog 4 | 5 | ## [Unreleased] 6 | ### Updated 7 | - Dependencies 8 | 9 | ## 0.0.4 10 | ### Updated 11 | - README 12 | - Dependencies 13 | - Code refactoring 14 | 15 | ## 0.0.3 16 | ### Fixed 17 | - Compatibility issue with the newest IntelliJ version 18 | 19 | ## 0.0.2 20 | ### Fixed 21 | - Compatibility issues 22 | - README styling 23 | 24 | ## 0.0.1 25 | ### Added 26 | - Initial release 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Matěj Žídek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Embedded DartPad 2 | 3 | ![Build](https://github.com/mzdm/embedded-dartpad/workflows/Build/badge.svg) 4 | [![Version](https://img.shields.io/jetbrains/plugin/v/16602-embedded-dartpad.svg)](https://plugins.jetbrains.com/plugin/16602-embedded-dartpad) 5 | [![Downloads](https://img.shields.io/jetbrains/plugin/d/com.github.mzdm.embedded_dartpad.svg)](https://plugins.jetbrains.com/plugin/com.github.mzdm.embedded_dartpad) 6 | 7 | https://user-images.githubusercontent.com/67197047/128333525-ac53ab9d-869f-457f-b489-0e7dee16a412.mp4 8 | 9 | 10 |

This plugin integrates DartPad directly into IntelliJ environment which lets you run Flutter & 11 | Dart code samples with ease.

12 | 13 |

Suggestions & bugs

14 |

Any suggestions and/or bugs please report to the GitHub repository.

15 | 16 |

Troubleshooting

17 |

Recommended IDE version 2020.2 (or build 202) and newer.

18 |

Note for Android Studio users: Android Studio does not ship with Chromium browser by default, so you are probably getting message "Embedded DartPad is not supported in this IDE version". As a workaround, you can follow these steps or refer to the related IntelliJ documentation page. 19 |

20 | Dart and Flutter and the related logos are trademarks of Google LLC. This is not endorsed by or affiliated with Google LLC.

21 | 22 | 23 | ## Installation 24 | 25 | - Using IDE built-in plugin system: 26 | 27 | Settings/Preferences > Plugins > Marketplace > Search for " 28 | embedded-dartpad" > 29 | Install Plugin 30 | 31 | - Manually: 32 | 33 | Download the [latest release](https://github.com/mzdm/embedded-dartpad/releases/latest) and install it manually using 34 | Settings/Preferences > Plugins > ⚙️ > Install plugin from disk... 35 | 36 | --- 37 | Plugin based on the [IntelliJ Platform Plugin Template][template]. 38 | 39 | [template]: https://github.com/JetBrains/intellij-platform-plugin-template 40 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.changelog.markdownToHTML 2 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 3 | 4 | fun properties(key: String) = project.findProperty(key) 5 | .toString() 6 | 7 | plugins { 8 | // Java support 9 | id("java") 10 | // Kotlin support 11 | id("org.jetbrains.kotlin.jvm") version "1.5.31" 12 | // gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin 13 | id("org.jetbrains.intellij") version "1.2.0" 14 | // gradle-changelog-plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin 15 | id("org.jetbrains.changelog") version "1.3.1" 16 | } 17 | 18 | group = properties("pluginGroup") 19 | version = properties("pluginVersion") 20 | 21 | // Configure project's dependencies 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | // Configure gradle-intellij-plugin plugin. 27 | // Read more: https://github.com/JetBrains/gradle-intellij-plugin 28 | intellij { 29 | pluginName.set(properties("pluginName")) 30 | version.set(properties("platformVersion")) 31 | type.set(properties("platformType")) 32 | downloadSources.set(properties("platformDownloadSources").toBoolean()) 33 | updateSinceUntilBuild.set(true) 34 | 35 | // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file. 36 | plugins.set( 37 | properties("platformPlugins").split(',') 38 | .map(String::trim) 39 | .filter(String::isNotEmpty) 40 | ) 41 | } 42 | 43 | // Configure gradle-changelog-plugin plugin. 44 | // Read more: https://github.com/JetBrains/gradle-changelog-plugin 45 | changelog { 46 | version.set(properties("pluginVersion")) 47 | groups.set(emptyList()) 48 | } 49 | 50 | tasks { 51 | // Set the JVM compatibility versions 52 | properties("javaVersion").let { 53 | withType { 54 | sourceCompatibility = it 55 | targetCompatibility = it 56 | } 57 | withType { 58 | kotlinOptions.jvmTarget = it 59 | } 60 | } 61 | 62 | wrapper { 63 | gradleVersion = properties("gradleVersion") 64 | } 65 | 66 | patchPluginXml { 67 | version.set(properties("pluginVersion")) 68 | sinceBuild.set(properties("pluginSinceBuild")) 69 | untilBuild.set(properties("pluginUntilBuild")) 70 | 71 | // Extract the section from README.md and provide for the plugin's manifest 72 | pluginDescription.set(File(projectDir, "README.md").readText() 73 | .lines() 74 | .run { 75 | val start = "" 76 | val end = "" 77 | 78 | if (!containsAll(listOf(start, end))) { 79 | throw GradleException("Plugin description section not found in README.md:\n$start ... $end") 80 | } 81 | subList(indexOf(start) + 1, indexOf(end)) 82 | } 83 | .joinToString("\n") 84 | .run { markdownToHTML(this) }) 85 | 86 | // Get the latest available change notes from the changelog file 87 | changeNotes.set( 88 | changelog.getLatest() 89 | .toHTML() 90 | ) 91 | } 92 | 93 | runPluginVerifier { 94 | ideVersions.set( 95 | properties("pluginVerifierIdeVersions").split(',') 96 | .map(String::trim) 97 | .filter(String::isNotEmpty) 98 | ) 99 | } 100 | 101 | // publishPlugin { 102 | // dependsOn("patchChangelog") 103 | // token.set(System.getenv("PUBLISH_TOKEN")) 104 | // // pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 105 | // // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: 106 | // // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel 107 | // channels.set(listOf(properties("pluginVersion").split('-') 108 | // .getOrElse(1) { "default" } 109 | // .split('.') 110 | // .first())) 111 | // } 112 | } 113 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # IntelliJ Platform Artifacts Repositories 2 | # -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html 3 | 4 | pluginGroup = com.github.mzdm.embedded_dartpad 5 | pluginName = Embedded Dartpad 6 | pluginVersion = 0.0.4 7 | pluginSinceBuild = 203 8 | pluginUntilBuild = 213.* 9 | # Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl 10 | # See https://jb.gg/intellij-platform-builds-list for available build versions 11 | pluginVerifierIdeVersions = 2020.3.4, 2021.1.3, 212.4535.15 12 | 13 | platformType = IC 14 | platformVersion = 2021.1 15 | platformDownloadSources = true 16 | # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html 17 | # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 18 | platformPlugins = 19 | 20 | # Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3 21 | javaVersion = 11 22 | 23 | gradleVersion = 7.1.1 24 | 25 | # Opt-out flag for bundling Kotlin standard library. 26 | # See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details. 27 | # suppress inspection "UnusedProperty" 28 | kotlin.stdlib.default.dependency = false 29 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzdm/embedded-dartpad/724ad6fb3627b6582382ea4c379285590626592b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /previews/preview.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mzdm/embedded-dartpad/724ad6fb3627b6582382ea4c379285590626592b/previews/preview.mp4 -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "embedded-dartpad" 2 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/app/constants/Icons.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.app.constants 2 | 3 | class Icons { 4 | 5 | companion object { 6 | private const val basePath: String = "/icons/" 7 | 8 | const val flutter_logo = "${basePath}logo_flutter.svg" 9 | const val theme = "${basePath}theme.svg" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/app/helpers/ComponentList.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.app.helpers 2 | 3 | import com.google.common.collect.ImmutableList 4 | import javax.swing.JComponent 5 | 6 | typealias ComponentList = ImmutableList 7 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/app/helpers/SingleComponentBuilder.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.app.helpers 2 | 3 | import com.google.common.collect.ImmutableList 4 | import javax.swing.JComponent 5 | import javax.swing.JPanel 6 | 7 | fun JPanel.addAll(components: ImmutableList) { 8 | for (component in components) { 9 | this.add(component) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/browser/Browser.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.browser 2 | 3 | import com.github.mzdm.embedded_dartpad.browser.utils.HtmlContentRenderer 4 | import com.github.mzdm.embedded_dartpad.dartpad.models.PadSettings 5 | import com.intellij.ui.jcef.JBCefBrowser 6 | 7 | class Browser : JBCefBrowser() { 8 | fun refresh(settings: PadSettings) { 9 | val html = HtmlContentRenderer.load(settings) 10 | this.loadHTML(html) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/browser/utils/HtmlContentRenderer.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.browser.utils 2 | 3 | import com.github.mzdm.embedded_dartpad.dartpad.data.getDartTemplate 4 | import com.github.mzdm.embedded_dartpad.dartpad.data.getFlutterTemplate 5 | import com.github.mzdm.embedded_dartpad.dartpad.models.Pad 6 | import com.github.mzdm.embedded_dartpad.dartpad.models.PadSettings 7 | import org.apache.commons.lang.StringEscapeUtils 8 | 9 | class HtmlContentRenderer { 10 | companion object { 11 | fun load(padSettings: PadSettings): String { 12 | val code = padSettings.code 13 | val pad = padSettings.pad.name.toLowerCase() 14 | val theme = padSettings.theme.name.toLowerCase() 15 | val flutterTemplate = padSettings.flutterTemplate 16 | 17 | val codeTemplate = StringEscapeUtils.escapeHtml( 18 | when (padSettings.pad) { 19 | Pad.DART -> getDartTemplate(code) 20 | Pad.FLUTTER -> getFlutterTemplate(flutterTemplate, theme, code) 21 | }, 22 | ) 23 | 24 | return """ 25 | 26 | 27 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | IntelliJ Embedded DartPad 38 | 39 | 40 | 61 | 62 | 63 | 64 |
65 |                 
66 |     $codeTemplate
67 |                 
68 |             
69 | 70 | 71 | """ 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/data/DartTemplates.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.data 2 | 3 | fun getDartTemplate(code: String?): String { 4 | return dartMainTemplate(code) 5 | } 6 | 7 | private fun dartMainTemplate(code: String?) = """ 8 | void main() { 9 | ${code ?: "print('Hello, World!');"} 10 | } 11 | """ 12 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/data/FlutterTemplates.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.data 2 | 3 | import com.github.mzdm.embedded_dartpad.dartpad.models.FlutterTemplate 4 | 5 | fun getFlutterTemplate(flutterTemplate: FlutterTemplate, theme: String, widget: String?): String { 6 | return when (flutterTemplate) { 7 | is FlutterTemplate.None -> flutterNoneTemplate(widget) 8 | is FlutterTemplate.Stateful -> flutterStatefulTemplate(theme, widget) 9 | is FlutterTemplate.Stateless -> TODO("Not implemented yet.") 10 | } 11 | } 12 | 13 | private fun flutterNoneTemplate(widget: String?) = """ 14 | import 'package:flutter/material.dart'; 15 | 16 | void main() => runApp(MyApp()); 17 | 18 | class MyApp extends StatefulWidget { 19 | _MyAppState createState() => _MyAppState(); 20 | } 21 | 22 | class _MyAppState extends State { 23 | Widget build(BuildContext context) { 24 | return MaterialApp( 25 | debugShowCheckedModeBanner: false, 26 | // TODO: Change to your widget 27 | home: FlutterLogo(), 28 | ); 29 | } 30 | } 31 | 32 | ${widget ?: ""} 33 | 34 | """ 35 | 36 | private fun flutterStatefulTemplate(theme: String, widget: String?): String { 37 | var methodWidget = widget 38 | if (widget != null && (widget.endsWith(",") || widget.endsWith(";"))) { 39 | methodWidget = widget.substring(0, widget.length - 1) 40 | } 41 | return """ 42 | import 'package:flutter/material.dart'; 43 | 44 | void main() => runApp(MyApp()); 45 | 46 | class MyApp extends StatefulWidget { 47 | _MyAppState createState() => _MyAppState(); 48 | } 49 | 50 | class _MyAppState extends State { 51 | Widget build(BuildContext context) { 52 | return MaterialApp( 53 | debugShowCheckedModeBanner: false, 54 | theme: ThemeData( 55 | brightness: Brightness.$theme, 56 | ), 57 | home: Scaffold( 58 | body: Center( 59 | child: MyStatefulWidget(), 60 | ), 61 | ), 62 | ); 63 | } 64 | } 65 | 66 | class MyStatefulWidget extends StatefulWidget { 67 | @override 68 | _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); 69 | } 70 | 71 | class _MyStatefulWidgetState extends State { 72 | @override 73 | Widget build(BuildContext context) { 74 | return ${methodWidget ?: "Text('Hello, World!'),"}; 75 | } 76 | } 77 | 78 | """ 79 | } 80 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/models/FlutterTemplate.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.models 2 | 3 | sealed class FlutterTemplate { 4 | data class None(val widget: String?) : FlutterTemplate() 5 | data class Stateful(val theme: Theme, val widget: String?) : FlutterTemplate() 6 | data class Stateless(val theme: Theme, val widget: String?) : FlutterTemplate() 7 | } 8 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/models/Pad.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.models 2 | 3 | enum class Pad { DART, FLUTTER } 4 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/models/PadSettings.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.models 2 | 3 | data class PadSettings( 4 | val theme: Theme = Theme.DARK, 5 | val pad: Pad = Pad.FLUTTER, 6 | val flutterTemplate: FlutterTemplate = FlutterTemplate.None(null), 7 | val code: String? = null, 8 | ) 9 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/models/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.models 2 | 3 | enum class Theme { DARK, LIGHT } 4 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/dartpad/services/PadSettingsService.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.dartpad.services 2 | 3 | import com.github.mzdm.embedded_dartpad.dartpad.models.PadSettings 4 | import com.github.mzdm.embedded_dartpad.dartpad.models.FlutterTemplate 5 | import com.github.mzdm.embedded_dartpad.dartpad.models.Pad 6 | import com.github.mzdm.embedded_dartpad.dartpad.models.Theme 7 | 8 | // Project service 9 | class PadSettingsService { 10 | var settings: PadSettings = PadSettings() 11 | get() = field 12 | private set 13 | 14 | fun setPad(newPad: Pad) { 15 | settings = settings.copy(pad = newPad) 16 | } 17 | 18 | fun setTheme(newTheme: Theme) { 19 | settings = settings.copy(theme = newTheme) 20 | } 21 | 22 | fun setWidget(newWidget: String?) { 23 | settings = settings.copy(code = newWidget) 24 | } 25 | 26 | fun setTemplate(newPadTemplate: FlutterTemplate) { 27 | settings = settings.copy(flutterTemplate = newPadTemplate) 28 | } 29 | 30 | fun reset() { 31 | settings = PadSettings() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/editor/actions/InvokeToolWindowAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.editor.actions 2 | 3 | import com.github.mzdm.embedded_dartpad.dartpad.models.FlutterTemplate 4 | import com.github.mzdm.embedded_dartpad.dartpad.models.Pad 5 | import com.github.mzdm.embedded_dartpad.dartpad.models.PadSettings 6 | import com.github.mzdm.embedded_dartpad.dartpad.services.PadSettingsService 7 | import com.github.mzdm.embedded_dartpad.toolwindow.DartPadWindowFactory 8 | import com.intellij.openapi.actionSystem.AnAction 9 | import com.intellij.openapi.actionSystem.AnActionEvent 10 | import com.intellij.openapi.actionSystem.CommonDataKeys 11 | import com.intellij.openapi.components.service 12 | import com.intellij.openapi.project.Project 13 | import com.intellij.openapi.wm.ToolWindow 14 | import com.intellij.openapi.wm.ToolWindowManager 15 | 16 | class InvokeToolWindowAction : AnAction() { 17 | override fun actionPerformed(event: AnActionEvent) { 18 | val project: Project? = event.project 19 | 20 | if (project != null) { 21 | val editor = event.getData(CommonDataKeys.EDITOR) 22 | val toolbarWindow = ToolWindowManager.getInstance(project) 23 | .getToolWindow(DartPadWindowFactory.id) 24 | 25 | if (editor != null && toolbarWindow != null) { 26 | val settingsService = project.service() 27 | 28 | val selectedText = editor.selectionModel.getSelectedText(true) 29 | settingsService.setWidget(selectedText) 30 | 31 | val flutterTemplate = getTemplateByAction(project, event.presentation.text, selectedText) 32 | settingsService.setTemplate(flutterTemplate) 33 | 34 | createToolWindowContent(toolbarWindow, project) 35 | toolbarWindow.show() 36 | } 37 | } 38 | } 39 | 40 | private fun getTemplateByAction(project: Project, text: String, selectedText: String?): FlutterTemplate { 41 | val settingsService = project.service() 42 | val padSettings: PadSettings = settingsService.settings 43 | 44 | return when (text) { 45 | "Flutter (Stateful)" -> { 46 | settingsService.setPad(Pad.FLUTTER) 47 | FlutterTemplate.Stateful( 48 | padSettings.theme, 49 | selectedText, 50 | ) 51 | } 52 | "Dart" -> { 53 | settingsService.setPad(Pad.DART) 54 | FlutterTemplate.None(selectedText) 55 | } 56 | else -> { 57 | settingsService.setPad(Pad.FLUTTER) 58 | FlutterTemplate.None(selectedText) 59 | } 60 | } 61 | } 62 | 63 | private fun createToolWindowContent(toolbarWindow: ToolWindow, project: Project) { 64 | val contentManager = toolbarWindow.contentManager 65 | val content = contentManager.getContent(0) 66 | if (content != null) { 67 | contentManager.removeContent(content, true) 68 | DartPadWindowFactory.instance.createToolWindowContent(project, toolbarWindow) 69 | } 70 | } 71 | 72 | override fun update(e: AnActionEvent) { 73 | val project: Project? = e.project 74 | e.presentation.isEnabledAndVisible = project != null 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/DartPadWindowFactory.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow 2 | 3 | import com.intellij.openapi.project.Project 4 | import com.intellij.openapi.wm.ToolWindow 5 | import com.intellij.openapi.wm.ToolWindowFactory 6 | 7 | class DartPadWindowFactory : ToolWindowFactory { 8 | 9 | companion object { 10 | const val id = " DartPad" 11 | val instance = DartPadWindowFactory() 12 | } 13 | 14 | override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { 15 | val contentManager = toolWindow.contentManager 16 | val content = contentManager.factory.createContent(DartPadWindowPanel(project), null, true) 17 | contentManager.addContent(content) 18 | toolWindow.show() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/DartPadWindowPanel.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow 2 | 3 | import com.github.mzdm.embedded_dartpad.app.helpers.ComponentList 4 | import com.github.mzdm.embedded_dartpad.app.helpers.addAll 5 | import com.github.mzdm.embedded_dartpad.browser.Browser 6 | import com.github.mzdm.embedded_dartpad.dartpad.models.PadSettings 7 | import com.github.mzdm.embedded_dartpad.dartpad.services.PadSettingsService 8 | import com.github.mzdm.embedded_dartpad.toolwindow.components.toolbarActions 9 | import com.intellij.ide.BrowserUtil 10 | import com.intellij.openapi.components.service 11 | import com.intellij.openapi.project.Project 12 | import com.intellij.openapi.ui.SimpleToolWindowPanel 13 | import com.intellij.ui.jcef.JBCefApp 14 | import com.intellij.ui.layout.panel 15 | import javax.swing.BoxLayout 16 | import javax.swing.SwingUtilities 17 | 18 | class DartPadWindowPanel(private val project: Project) : SimpleToolWindowPanel(false) { 19 | 20 | private val padSettingsService: PadSettingsService 21 | get() = project.service() 22 | private val settings: PadSettings 23 | get() = padSettingsService.settings 24 | 25 | init { 26 | // JBCef browser throws an error on Android Studio 27 | val isJcefSupported: Boolean = try { 28 | JBCefApp.isSupported() 29 | } catch (t: Throwable) { 30 | false 31 | } 32 | 33 | if (isJcefSupported) { 34 | SwingUtilities.invokeLater { 35 | initJbCefBrowser() 36 | } 37 | } else { 38 | showUnsupportedMessage() 39 | } 40 | } 41 | 42 | private fun initJbCefBrowser() { 43 | val browser = Browser() 44 | browser.refresh(settings) 45 | 46 | val verticalLayout = BoxLayout(this, BoxLayout.Y_AXIS) 47 | layout = verticalLayout 48 | 49 | addAll( 50 | ComponentList.of( 51 | toolbarActions( 52 | project, 53 | onRefresh = { browser.refresh(settings) }, 54 | ), 55 | browser.component, 56 | ), 57 | ) 58 | 59 | validate() 60 | repaint() 61 | } 62 | 63 | private fun showUnsupportedMessage() { 64 | add(panel { 65 | row { 66 | row { 67 | label("You're probably on Android Studio.\nEmbedded DartPad plugin is not supported in this IDE.") 68 | } 69 | row { 70 | link("Read more for a workaround (#Troubleshooting section) ...") { 71 | BrowserUtil.browse("https://github.com/mzdm/embedded-dartpad#troubleshooting") 72 | } 73 | } 74 | } 75 | }) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/components/ToolbarActions.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow.components 2 | 3 | import com.github.mzdm.embedded_dartpad.app.constants.Icons 4 | import com.github.mzdm.embedded_dartpad.dartpad.services.PadSettingsService 5 | import com.intellij.icons.AllIcons 6 | import com.intellij.openapi.actionSystem.ActionManager 7 | import com.intellij.openapi.actionSystem.ActionPlaces 8 | import com.intellij.openapi.actionSystem.DefaultActionGroup 9 | import com.intellij.openapi.components.service 10 | import com.intellij.openapi.project.Project 11 | import com.intellij.openapi.util.IconLoader 12 | import javax.swing.JComponent 13 | 14 | fun toolbarActions(project: Project, onRefresh: () -> Unit): JComponent { 15 | val actionGroup = DefaultActionGroup() 16 | 17 | actionGroup.addAll( 18 | ToolbarIconAction( 19 | "Refresh", 20 | "Reloads the current page", 21 | AllIcons.Actions.Refresh, 22 | onAction = onRefresh, 23 | ), 24 | ToolbarPadToggleAction( 25 | project, 26 | "Flutter environment", 27 | null, 28 | IconLoader.getIcon(Icons.flutter_logo), 29 | onToggled = onRefresh, 30 | ), 31 | ToolbarThemeToggleAction( 32 | project, 33 | "Dark embed theme", 34 | null, 35 | IconLoader.getIcon(Icons.theme), 36 | onToggled = onRefresh, 37 | ), 38 | ToolbarTextIconAction( 39 | "Reset", "Resets everything to default", null, 40 | onAction = { 41 | project.service() 42 | .reset() 43 | onRefresh() 44 | }, 45 | ), 46 | ) 47 | 48 | val actionManager = ActionManager.getInstance() 49 | val actionToolBar = actionManager.createActionToolbar(ActionPlaces.TOOLBAR, actionGroup, true) 50 | return actionToolBar.component 51 | } 52 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/components/ToolbarIconAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow.components 2 | 3 | import com.intellij.openapi.actionSystem.AnAction 4 | import com.intellij.openapi.actionSystem.AnActionEvent 5 | import javax.swing.Icon 6 | 7 | class ToolbarIconAction(text: String, desc: String, icon: Icon?, val onAction: () -> Unit) : 8 | AnAction(text, desc, icon) { 9 | 10 | override fun actionPerformed(e: AnActionEvent) { 11 | onAction() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/components/ToolbarPadToggleAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow.components 2 | 3 | import com.github.mzdm.embedded_dartpad.dartpad.models.Pad 4 | import com.github.mzdm.embedded_dartpad.dartpad.services.PadSettingsService 5 | import com.intellij.openapi.actionSystem.AnActionEvent 6 | import com.intellij.openapi.actionSystem.ToggleAction 7 | import com.intellij.openapi.components.service 8 | import com.intellij.openapi.project.Project 9 | import javax.swing.Icon 10 | 11 | class ToolbarPadToggleAction( 12 | private val project: Project, text: String, desc: String?, icon: Icon?, val onToggled: () -> Unit, 13 | ) : ToggleAction(text, desc, icon) { 14 | 15 | private val padSettingsService: PadSettingsService 16 | get() = project.service() 17 | private val currentPad: Pad 18 | get() = padSettingsService.settings.pad 19 | 20 | override fun isSelected(e: AnActionEvent): Boolean { 21 | return currentPad == Pad.FLUTTER 22 | } 23 | 24 | override fun setSelected(e: AnActionEvent, state: Boolean) { 25 | if (currentPad == Pad.FLUTTER) { 26 | padSettingsService.setPad(Pad.DART) 27 | } else { 28 | padSettingsService.setPad(Pad.FLUTTER) 29 | } 30 | onToggled() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/components/ToolbarTextIconAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow.components 2 | 3 | import com.intellij.openapi.actionSystem.AnActionEvent 4 | import com.intellij.openapi.roots.ui.configuration.actions.IconWithTextAction 5 | import javax.swing.Icon 6 | 7 | class ToolbarTextIconAction(text: String, desc: String, icon: Icon?, val onAction: () -> Unit) : 8 | IconWithTextAction(text, desc, icon) { 9 | 10 | override fun actionPerformed(e: AnActionEvent) { 11 | onAction() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/mzdm/embedded_dartpad/toolwindow/components/ToolbarThemeToggleAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.mzdm.embedded_dartpad.toolwindow.components 2 | 3 | import com.github.mzdm.embedded_dartpad.dartpad.models.Theme 4 | import com.github.mzdm.embedded_dartpad.dartpad.services.PadSettingsService 5 | import com.intellij.openapi.actionSystem.AnActionEvent 6 | import com.intellij.openapi.actionSystem.ToggleAction 7 | import com.intellij.openapi.components.service 8 | import com.intellij.openapi.project.Project 9 | import javax.swing.Icon 10 | 11 | class ToolbarThemeToggleAction( 12 | private val project: Project, text: String, desc: String?, icon: Icon?, val onToggled: () -> Unit, 13 | ) : ToggleAction(text, desc, icon) { 14 | 15 | private val padSettingsService: PadSettingsService 16 | get() = project.service() 17 | private val currentTheme: Theme 18 | get() = padSettingsService.settings.theme 19 | 20 | override fun isSelected(e: AnActionEvent): Boolean { 21 | return currentTheme == Theme.DARK 22 | } 23 | 24 | override fun setSelected(e: AnActionEvent, state: Boolean) { 25 | if (currentTheme == Theme.DARK) { 26 | padSettingsService.setTheme(Theme.LIGHT) 27 | } else { 28 | padSettingsService.setTheme(Theme.DARK) 29 | } 30 | onToggled() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.github.mzdm.embedded_dartpad 3 | Embedded DartPad 4 | mzdm 5 | 6 | 7 | 8 | com.intellij.modules.platform 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 21 | 22 | 25 | 26 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/pluginIcon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/icons/embedded_action.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/icons/embedded_toolbar.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/main/resources/icons/logo_dart.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/main/resources/icons/logo_flutter.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/resources/icons/theme.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/icons/theme_dark.svg: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------