├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ ├── pull-request.yml │ ├── release.yml │ └── run-ui-tests.yml ├── .gitignore ├── .idea └── gradle.xml ├── .run ├── Run IDE for UI Tests.run.xml ├── Run IDE with Plugin.run.xml ├── Run Plugin Tests.run.xml ├── Run Plugin Verification.run.xml └── Run Qodana.run.xml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── qodana.yml ├── screenshots ├── clear-focus.png ├── focus-on-module.png ├── startup-dialog.png ├── toolwindow-search.png └── toolwindow.png ├── settings.gradle.kts └── src ├── main ├── kotlin │ └── br │ │ └── com │ │ └── devsrsouza │ │ └── intellij │ │ └── dropboxfocus │ │ ├── actions │ │ ├── ClearFocusAction.kt │ │ └── FocusFileAction.kt │ │ ├── extensions │ │ └── FocusToolWindowFactory.kt │ │ ├── listeners │ │ ├── FocusGradleSyncListener.kt │ │ ├── FocusProjectOpenListener.kt │ │ └── ThemeChangeListener.kt │ │ ├── psi │ │ ├── GroovyPsiUtil.kt │ │ └── KotlinPsiUtil.kt │ │ ├── services │ │ ├── FocusConfigurable.kt │ │ ├── FocusGradleSettingsReader.kt │ │ ├── FocusService.kt │ │ ├── FocusSettings.kt │ │ └── FocusToolWindowService.kt │ │ └── ui │ │ ├── FocusSelection.kt │ │ ├── IntellIj.kt │ │ ├── Theme.kt │ │ └── dialog │ │ └── StartupFocusProjectDialog.kt └── resources │ └── META-INF │ ├── plugin.xml │ └── pluginIcon.svg └── test ├── kotlin └── br │ └── com │ └── devsrsouza │ └── intellij │ └── dropboxfocus │ └── MyPluginTest.kt └── testData └── rename ├── foo.xml └── foo_after.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{kt,kts}] 2 | indent_size=4 3 | continuation_indent_size=4 4 | insert_final_newline=false 5 | max_line_length=120 -------------------------------------------------------------------------------- /.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 | target-branch: "next" 10 | schedule: 11 | interval: "daily" 12 | # Maintain dependencies for GitHub Actions 13 | - package-ecosystem: "github-actions" 14 | directory: "/" 15 | target-branch: "next" 16 | schedule: 17 | interval: "daily" 18 | -------------------------------------------------------------------------------- /.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 Qodana inspections, 5 | # - run 'buildPlugin' task and prepare artifact for the further tests, 6 | # - run 'runPluginVerifier' task, 7 | # - create a draft release. 8 | # 9 | # Workflow is triggered on push and pull_request events. 10 | # 11 | # GitHub Actions reference: https://help.github.com/en/actions 12 | # 13 | ## JBIJPPTPL 14 | 15 | name: Build 16 | on: 17 | # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) 18 | push: 19 | branches: [main] 20 | # Trigger the workflow on any pull request 21 | pull_request: 22 | 23 | jobs: 24 | 25 | # Run Gradle Wrapper Validation Action to verify the wrapper's checksum 26 | # Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks 27 | # Build plugin and provide the artifact for the next workflow jobs 28 | build: 29 | name: Build 30 | runs-on: ubuntu-latest 31 | outputs: 32 | version: ${{ steps.properties.outputs.version }} 33 | changelog: ${{ steps.properties.outputs.changelog }} 34 | steps: 35 | 36 | # Check out current repository 37 | - name: Fetch Sources 38 | uses: actions/checkout@v2.4.0 39 | 40 | # Validate wrapper 41 | - name: Gradle Wrapper Validation 42 | uses: gradle/wrapper-validation-action@v1.0.4 43 | 44 | # Setup Java 11 environment for the next steps 45 | - name: Setup Java 46 | uses: actions/setup-java@v2 47 | with: 48 | distribution: zulu 49 | java-version: 11 50 | cache: gradle 51 | 52 | # Set environment variables 53 | - name: Export Properties 54 | id: properties 55 | shell: bash 56 | run: | 57 | PROPERTIES="$(./gradlew properties --console=plain -q)" 58 | VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" 59 | NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" 60 | CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" 61 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 62 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 63 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 64 | 65 | echo "::set-output name=version::$VERSION" 66 | echo "::set-output name=name::$NAME" 67 | echo "::set-output name=changelog::$CHANGELOG" 68 | echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" 69 | 70 | ./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier 71 | 72 | # Install ReviewDog 73 | - name: Setup Review Dog 74 | run: curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s 75 | 76 | # Run ktlint 77 | - name: Run KtLint 78 | run: ./gradlew lintKotlin 79 | 80 | - name: Collect KtLint Result 81 | if: ${{ failure() }} 82 | continue-on-error: true 83 | env: 84 | REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 85 | run: | 86 | cat ${{ github.workspace }}/build/reports/ktlint/main-lint.xml | ./bin/reviewdog -f=checkstyle -name="ktlint" -reporter="github-pr-check" -level="error" -filter-mode="added" -fail-on-error="false" 87 | 88 | # Run tests 89 | - name: Run Tests 90 | run: ./gradlew test 91 | 92 | # Collect Tests Result of failed tests 93 | - name: Collect Tests Result 94 | if: ${{ failure() }} 95 | uses: actions/upload-artifact@v2 96 | with: 97 | name: tests-result 98 | path: ${{ github.workspace }}/build/reports/tests 99 | 100 | # Cache Plugin Verifier IDEs 101 | - name: Setup Plugin Verifier IDEs Cache 102 | uses: actions/cache@v2.1.7 103 | with: 104 | path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides 105 | key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} 106 | 107 | # Run Verify Plugin task and IntelliJ Plugin Verifier tool 108 | - name: Run Plugin Verification tasks 109 | run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} 110 | 111 | # Collect Plugin Verifier Result 112 | - name: Collect Plugin Verifier Result 113 | if: ${{ always() }} 114 | uses: actions/upload-artifact@v2 115 | with: 116 | name: pluginVerifier-result 117 | path: ${{ github.workspace }}/build/reports/pluginVerifier 118 | 119 | # Prepare plugin archive content for creating artifact 120 | - name: Prepare Plugin Artifact 121 | id: artifact 122 | shell: bash 123 | run: | 124 | cd ${{ github.workspace }}/build/distributions 125 | FILENAME=`ls *.zip` 126 | unzip "$FILENAME" -d content 127 | 128 | echo "::set-output name=filename::${FILENAME:0:-4}" 129 | 130 | # Store already-built plugin as an artifact for downloading 131 | - name: Upload artifact 132 | uses: actions/upload-artifact@v2.2.4 133 | with: 134 | name: ${{ steps.artifact.outputs.filename }} 135 | path: ./build/distributions/content/*/* 136 | 137 | # Prepare a draft release for GitHub Releases page for the manual verification 138 | # If accepted and published, release workflow would be triggered 139 | releaseDraft: 140 | name: Release Draft 141 | if: github.event_name != 'pull_request' 142 | needs: build 143 | runs-on: ubuntu-latest 144 | steps: 145 | 146 | # Check out current repository 147 | - name: Fetch Sources 148 | uses: actions/checkout@v2.4.0 149 | 150 | # Remove old release drafts by using the curl request for the available releases with draft flag 151 | - name: Remove Old Release Drafts 152 | env: 153 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 154 | run: | 155 | gh api repos/{owner}/{repo}/releases \ 156 | --jq '.[] | select(.draft == true) | .id' \ 157 | | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} 158 | 159 | # Create new release draft - which is not publicly visible and requires manual acceptance 160 | - name: Create Release Draft 161 | env: 162 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 163 | run: | 164 | gh release create v${{ needs.build.outputs.version }} \ 165 | --draft \ 166 | --title "v${{ needs.build.outputs.version }}" \ 167 | --notes "$(cat << 'EOM' 168 | ${{ needs.build.outputs.changelog }} 169 | EOM 170 | )" 171 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request 2 | on: 3 | pull_request: 4 | 5 | jobs: 6 | pullrequest: 7 | name: Pull Request 8 | runs-on: ubuntu-latest 9 | steps: 10 | # Check out current repository 11 | - name: Fetch Sources 12 | uses: actions/checkout@v2.4.0 13 | 14 | # Validate wrapper 15 | - name: Gradle Wrapper Validation 16 | uses: gradle/wrapper-validation-action@v1.0.4 17 | 18 | # Setup Java 11 environment for the next steps 19 | - name: Setup Java 20 | uses: actions/setup-java@v2 21 | with: 22 | distribution: zulu 23 | java-version: 11 24 | cache: gradle 25 | 26 | # Run ktlint 27 | - name: Run KtLint 28 | run: ./gradlew lintKotlin 29 | 30 | - name: Collect KtLint Result 31 | if: ${{ failure() }} 32 | continue-on-error: true 33 | env: 34 | REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | run: | 36 | ./gradlew formatKotlin 37 | TMPFILE=$(mktemp) 38 | git diff >"${TMPFILE}" 39 | ./gradlew lintKotlin || true 40 | git stash -u && git stash drop || true 41 | curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s 42 | ./bin/reviewdog -name="ktlint" -f=diff -f.diff.strip=1 -reporter="github-pr-review" < "${TMPFILE}" 43 | cat ${{ github.workspace }}/build/reports/ktlint/main-lint.xml | ./bin/reviewdog -f=checkstyle -name="ktlint" -reporter="github-pr-review" -level="error" -filter-mode="added" -fail-on-error="false" -------------------------------------------------------------------------------- /.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 | # Check out current repository 18 | - name: Fetch Sources 19 | uses: actions/checkout@v2.4.0 20 | with: 21 | ref: ${{ github.event.release.tag_name }} 22 | 23 | # Setup Java 11 environment for the next steps 24 | - name: Setup Java 25 | uses: actions/setup-java@v2 26 | with: 27 | distribution: zulu 28 | java-version: 11 29 | cache: gradle 30 | 31 | # Set environment variables 32 | - name: Export Properties 33 | id: properties 34 | shell: bash 35 | run: | 36 | CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d' 37 | ${{ github.event.release.body }} 38 | EOM 39 | )" 40 | 41 | CHANGELOG="${CHANGELOG//'%'/'%25'}" 42 | CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" 43 | CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" 44 | 45 | echo "::set-output name=changelog::$CHANGELOG" 46 | 47 | # Update Unreleased section with the current release note 48 | - name: Patch Changelog 49 | if: ${{ steps.properties.outputs.changelog != '' }} 50 | env: 51 | CHANGELOG: ${{ steps.properties.outputs.changelog }} 52 | run: | 53 | ./gradlew patchChangelog --release-note="$CHANGELOG" 54 | 55 | # Publish the plugin to the Marketplace 56 | - name: Publish Plugin 57 | env: 58 | PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} 59 | CERTIFICATE_CHAIN: ${{ secrets.CERTIFICATE_CHAIN }} 60 | PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }} 61 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} 62 | run: ./gradlew publishPlugin 63 | 64 | # Upload artifact as a release asset 65 | - name: Upload Release Asset 66 | env: 67 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 68 | run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/* 69 | 70 | # Create pull request 71 | - name: Create Pull Request 72 | if: ${{ steps.properties.outputs.changelog != '' }} 73 | env: 74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 75 | run: | 76 | VERSION="${{ github.event.release.tag_name }}" 77 | BRANCH="changelog-update-$VERSION" 78 | 79 | git config user.email "action@github.com" 80 | git config user.name "GitHub Action" 81 | 82 | git checkout -b $BRANCH 83 | git commit -am "Changelog update - $VERSION" 84 | git push --set-upstream origin $BRANCH 85 | 86 | gh pr create \ 87 | --title "Changelog update - \`$VERSION\`" \ 88 | --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ 89 | --base main \ 90 | --head $BRANCH 91 | -------------------------------------------------------------------------------- /.github/workflows/run-ui-tests.yml: -------------------------------------------------------------------------------- 1 | # GitHub Actions Workflow for launching UI tests on Linux, Windows, and Mac in the following steps: 2 | # - prepare and launch IDE with your plugin and robot-server plugin, which is needed to interact with UI 3 | # - wait for IDE to start 4 | # - run UI tests with separate Gradle task 5 | # 6 | # Please check https://github.com/JetBrains/intellij-ui-test-robot for information about UI tests with IntelliJ Platform 7 | # 8 | # Workflow is triggered manually. 9 | 10 | name: Run UI Tests 11 | on: 12 | workflow_dispatch 13 | 14 | jobs: 15 | 16 | testUI: 17 | runs-on: ${{ matrix.os }} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | include: 22 | - os: ubuntu-latest 23 | runIde: | 24 | export DISPLAY=:99.0 25 | Xvfb -ac :99 -screen 0 1920x1080x16 & 26 | gradle runIdeForUiTests & 27 | - os: windows-latest 28 | runIde: start gradlew.bat runIdeForUiTests 29 | - os: macos-latest 30 | runIde: ./gradlew runIdeForUiTests & 31 | 32 | steps: 33 | 34 | # Check out current repository 35 | - name: Fetch Sources 36 | uses: actions/checkout@v2.4.0 37 | 38 | # Setup Java 11 environment for the next steps 39 | - name: Setup Java 40 | uses: actions/setup-java@v2 41 | with: 42 | distribution: zulu 43 | java-version: 11 44 | cache: gradle 45 | 46 | # Run IDEA prepared for UI testing 47 | - name: Run IDE 48 | run: ${{ matrix.runIde }} 49 | 50 | # Wait for IDEA to be started 51 | - name: Health Check 52 | uses: jtalk/url-health-check-action@v2 53 | with: 54 | url: http://127.0.0.1:8082 55 | max-attempts: 15 56 | retry-delay: 30s 57 | 58 | # Run tests 59 | - name: Tests 60 | run: ./gradlew test 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | .qodana 4 | build 5 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.run/Run IDE for UI Tests.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 15 | 17 | true 18 | true 19 | false 20 | 21 | 22 | -------------------------------------------------------------------------------- /.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 | 25 | -------------------------------------------------------------------------------- /.run/Run Plugin Verification.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 17 | 19 | true 20 | true 21 | false 22 | 23 | 25 | 26 | -------------------------------------------------------------------------------- /.run/Run Qodana.run.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 16 | 19 | 21 | true 22 | true 23 | false 24 | 25 | 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # dropbox-focus-intellij-plugin Changelog 4 | 5 | ## [Unreleased] 6 | 7 | ## [0.2.1] 8 | ### Added 9 | - Adding support to IDEA 222.* and 223.* ( IntelliJ 2022.3 EAP and Android Studio Flamingo 2022.2) 10 | 11 | ## [0.2.0] 12 | ### Added 13 | - Adding a clear focus button to side tool window 14 | - Adding clear focus action (SHIFT+SHIFT "Clear Focus") 15 | 16 | ### Fixed 17 | - Gradle sync not being triggered in Android Studio 2022.1 Canary 1 18 | 19 | ## [0.1.1] 20 | ### Changed 21 | - Fix IntelliJ missing dependency on com.intellij.modules.java 22 | 23 | ## [0.1.0] 24 | ### Added 25 | - Startup Dialog for Focus projects 26 | - Module folder right-click action to "Focus on Module" with Sync 27 | - Root project folder rick-click action to "Clear focus" with Sync 28 | - Focus Tool Window to Select Module to Focus 29 | - Initial scaffold created from [IntelliJ Platform Plugin Template](https://github.com/JetBrains/intellij-platform-plugin-template) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Gabriel Souza 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dropbox Focus IntelliJ Plugin 2 | 3 | ![Build](https://github.com/DevSrSouza/dropbox-focus-intellij-plugin/workflows/Build/badge.svg) 4 | [![Version](https://img.shields.io/jetbrains/plugin/v/19104.svg)](https://plugins.jetbrains.com/plugin/19104) 5 | [![Downloads](https://img.shields.io/jetbrains/plugin/d/19104.svg)](https://plugins.jetbrains.com/plugin/19104) 6 | 7 | 8 | 9 | [**Source code**](https://github.com/DevSrSouza/dropbox-focus-intellij-plugin/) [**Screenshots**](https://github.com/DevSrSouza/dropbox-focus-intellij-plugin/#Screenshots) 10 | 11 | This IntelliJ and Android Studio Plugin provide tooling for Gradle Plugin [Focus by Dropbox](https://github.com/dropbox/focus). 12 | The reason is to make it easy to switch focus and preventing open a big project without giving you the option to only select the module that you want to work on. 13 | 14 | - When plugin detect that the project that is being open was Focus plugin, it will prompt a Dialog to Select if you want to select a Module to Focus, Clear current Focus or just leave as it is. 15 | - Focus on a Module by right-clicking on a Module folder and selecting "Focus on Module" 16 | - Clearing current focus by right-clicking on root project folder 17 | 18 | How the Plugin works by Steps: 19 | - Resolve the Focus Plugin configuration from your project by reading your `settings.gradle[.kts]` and looking for a `plugins { id("com.dropbox.focus") }` declaration. 20 | - Resolve Focus Gradle plugin configuration if there is one by reading `focus {}`(Groovy) or `configure {}`(Kotlin DSL), and it will read properties `allSettingsFileName` and `focusFileName`, if it does not have one of the property or even the configuration block, it will use the default configurations values of the Focus Gradle plugin. 21 | - Resolve all the modules names and directories from `allSettingsFileName`. 22 | - Resolve if there is currently a Focus available by reading `focusFileName` if exists. 23 | 24 | Resolution limitations: 25 | All the gradle files resolution requires to be to use Literal Strings inside expected blocks. Do not create a variable and pass to it, for example: 26 | 27 | ```groovy 28 | plugins { 29 | val focusPlugin = "com.dropbox.focus" 30 | id(focusPlugin) version "0.4.0" 31 | } 32 | ``` 33 | 34 | Here is a working example: 35 | 36 | Groovy: 37 | 38 | ```groovy 39 | plugins { 40 | id("com.dropbox.focus") version "0.4.0" 41 | } 42 | 43 | focus { 44 | allSettingsFileName = "settings-all.gradle.kts" 45 | focusFileName = ".focus" 46 | } 47 | ``` 48 | 49 | Kotlin: 50 | ```kotlin 51 | plugins { 52 | id("com.dropbox.focus") version "0.4.0" 53 | } 54 | 55 | configure { 56 | allSettingsFileName.set("settings-all.gradle.kts") 57 | focusFileName.set(".focus") 58 | } 59 | ``` 60 | 61 | 62 | 63 | ### Screenshots 64 | 65 | 66 | 67 | 68 | 69 | ### TODO v1 70 | 71 | - [X] Focus tool window listing all possible focus modules
![](https://user-images.githubusercontent.com/29736164/162661724-6b3e70fd-3505-44d2-a519-afb43bd88fe6.png) 72 | - [X] Support project dir change on `allSettingsFileName`, ex: `project(":sample:moved").projectDir = file("sample/lib-moved")`. Currently, by not supporting this, we can't properly show the `Focus on Module` on Module that did change their `projectDir`. 73 | - [X] Support Gradle Sync also on Android Studio Canary version. 74 | - [X] Disable Dialog on startup with a checkbox, persist per project. 75 | - [X] Focus project settings 76 | - [X] Cache Current Focus Settings and update it by listening to Gradle Syncs 77 | 78 | ### Future Ideas 79 | - [ ] Focus Project View 80 | - [ ] Favorites focus, a way for easily show Focus Modules on top that you most work on. 81 | 82 | ## Building 83 | 84 | Just run the gradle task in terminal: `./gradlew buildPlugin`. The plugin will be available in `/build/distributions/` 85 | 86 | ## Installation 87 | 88 | - Using IDE built-in plugin system: 89 | 90 | Settings/Preferences > Plugins > Marketplace > Search for "Dropbox Focus" > 91 | Install Plugin 92 | 93 | - Manually: 94 | 95 | Download the [latest release](https://github.com/DevSrSouza/dropbox-focus-intellij-plugin/releases/latest) or [build your self](#Building) and install it manually using 96 | Settings/Preferences > Plugins > ⚙️ > Install plugin from disk... 97 | 98 | 99 | --- 100 | Plugin based on the [IntelliJ Platform Plugin Template][template]. 101 | 102 | [template]: https://github.com/JetBrains/intellij-platform-plugin-template 103 | -------------------------------------------------------------------------------- /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).toString() 5 | 6 | plugins { 7 | // Java support 8 | id("java") 9 | // Kotlin support 10 | id("org.jetbrains.kotlin.jvm") version "1.8.20" 11 | // Gradle IntelliJ Plugin 12 | id("org.jetbrains.intellij") version "1.13.3" 13 | // Gradle Changelog Plugin 14 | id("org.jetbrains.changelog") version "1.3.1" 15 | 16 | id("org.jmailen.kotlinter") version "3.9.0" 17 | 18 | id("org.jetbrains.compose") version "1.4.0" 19 | } 20 | 21 | group = properties("pluginGroup") 22 | version = properties("pluginVersion") 23 | 24 | val customIdePath: String? by project 25 | 26 | // Configure project's dependencies 27 | repositories { 28 | mavenCentral() 29 | maven("https://jitpack.io") 30 | } 31 | 32 | configurations { 33 | compileClasspath.resolutionStrategy.sortArtifacts(ResolutionStrategy.SortOrder.DEPENDENCY_FIRST) 34 | testCompileClasspath.resolutionStrategy.sortArtifacts(ResolutionStrategy.SortOrder.DEPENDENCY_FIRST) 35 | } 36 | 37 | dependencies { 38 | api(compose.desktop.common) 39 | api(compose.desktop.macos_x64) 40 | api(compose.desktop.macos_arm64) 41 | api(compose.desktop.windows_x64) 42 | api(compose.desktop.linux_x64) 43 | api(compose.desktop.linux_arm64) 44 | 45 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.6.3") 46 | implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3") 47 | 48 | implementation("com.github.DevSrSouza:compose-jetbrains-theme:1ad6cb4665") 49 | } 50 | 51 | // Configure Gradle IntelliJ Plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin 52 | intellij { 53 | pluginName.set(properties("pluginName")) 54 | version.set(properties("platformVersion")) 55 | type.set(properties("platformType")) 56 | 57 | // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file. 58 | plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty)) 59 | } 60 | 61 | // Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin 62 | changelog { 63 | version.set(properties("pluginVersion")) 64 | groups.set(emptyList()) 65 | } 66 | 67 | kotlinter { 68 | reporters = arrayOf("checkstyle") 69 | } 70 | 71 | tasks { 72 | // Set the JVM compatibility versions 73 | properties("javaVersion").let { 74 | withType { 75 | sourceCompatibility = it 76 | targetCompatibility = it 77 | } 78 | withType { 79 | kotlinOptions.jvmTarget = it 80 | } 81 | } 82 | 83 | wrapper { 84 | gradleVersion = properties("gradleVersion") 85 | } 86 | 87 | patchPluginXml { 88 | version.set(properties("pluginVersion")) 89 | sinceBuild.set(properties("pluginSinceBuild")) 90 | untilBuild.set(properties("pluginUntilBuild")) 91 | 92 | // Extract the section from README.md and provide for the plugin's manifest 93 | pluginDescription.set( 94 | projectDir.resolve("README.md").readText().lines().run { 95 | val start = "" 96 | val end = "" 97 | 98 | if (!containsAll(listOf(start, end))) { 99 | throw GradleException("Plugin description section not found in README.md:\n$start ... $end") 100 | } 101 | subList(indexOf(start) + 1, indexOf(end)) 102 | }.joinToString("\n").run { markdownToHTML(this) } 103 | ) 104 | 105 | // Get the latest available change notes from the changelog file 106 | changeNotes.set(provider { 107 | changelog.run { 108 | getOrNull(properties("pluginVersion")) ?: getLatest() 109 | }.toHTML() 110 | }) 111 | } 112 | 113 | // Configure UI tests plugin 114 | // Read more: https://github.com/JetBrains/intellij-ui-test-robot 115 | runIdeForUiTests { 116 | systemProperty("robot-server.port", "8082") 117 | systemProperty("ide.mac.message.dialogs.as.sheets", "false") 118 | systemProperty("jb.privacy.policy.text", "") 119 | systemProperty("jb.consents.confirmation.enabled", "false") 120 | } 121 | 122 | signPlugin { 123 | certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) 124 | privateKey.set(System.getenv("PRIVATE_KEY")) 125 | password.set(System.getenv("PRIVATE_KEY_PASSWORD")) 126 | } 127 | 128 | publishPlugin { 129 | dependsOn("patchChangelog") 130 | token.set(System.getenv("PUBLISH_TOKEN")) 131 | // pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3 132 | // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more: 133 | // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel 134 | channels.set(listOf(properties("pluginVersion").split('-').getOrElse(1) { "default" }.split('.').first())) 135 | } 136 | 137 | runIde { 138 | if(customIdePath != null) { 139 | ideDir.set(File(customIdePath)) 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # IntelliJ Platform Artifacts Repositories 2 | # -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html 3 | org.gradle.jvmargs=-Xms1g -Xmx6g -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError 4 | 5 | pluginGroup = br.com.devsrsouza.intellij.dropboxfocus 6 | pluginName = Focus 7 | # SemVer format -> https://semver.org 8 | pluginVersion = 0.2.2 9 | 10 | # See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html 11 | # for insight into build numbers and IntelliJ Platform versions. 12 | pluginSinceBuild = 211 13 | pluginUntilBuild = 231.* 14 | 15 | # IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties 16 | platformType = IC 17 | #platformVersion = 2021.1.3 18 | platformVersion = 2023.1 19 | 20 | # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html 21 | # Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22 22 | platformPlugins = org.jetbrains.kotlin, com.intellij.gradle, org.jetbrains.android, org.intellij.groovy, com.intellij.java 23 | 24 | # Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3 25 | javaVersion = 11 26 | 27 | # Gradle Releases -> https://github.com/gradle/gradle/releases 28 | gradleVersion = 7.4 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevSrSouza/dropbox-focus-intellij-plugin/fecccc7b91613ad5918862b09aeeb85797dc53b3/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.4-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original 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 POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /qodana.yml: -------------------------------------------------------------------------------- 1 | # Qodana configuration: 2 | # https://www.jetbrains.com/help/qodana/qodana-yaml.html 3 | 4 | version: 1.0 5 | profile: 6 | name: qodana.recommended 7 | -------------------------------------------------------------------------------- /screenshots/clear-focus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevSrSouza/dropbox-focus-intellij-plugin/fecccc7b91613ad5918862b09aeeb85797dc53b3/screenshots/clear-focus.png -------------------------------------------------------------------------------- /screenshots/focus-on-module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevSrSouza/dropbox-focus-intellij-plugin/fecccc7b91613ad5918862b09aeeb85797dc53b3/screenshots/focus-on-module.png -------------------------------------------------------------------------------- /screenshots/startup-dialog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevSrSouza/dropbox-focus-intellij-plugin/fecccc7b91613ad5918862b09aeeb85797dc53b3/screenshots/startup-dialog.png -------------------------------------------------------------------------------- /screenshots/toolwindow-search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevSrSouza/dropbox-focus-intellij-plugin/fecccc7b91613ad5918862b09aeeb85797dc53b3/screenshots/toolwindow-search.png -------------------------------------------------------------------------------- /screenshots/toolwindow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DevSrSouza/dropbox-focus-intellij-plugin/fecccc7b91613ad5918862b09aeeb85797dc53b3/screenshots/toolwindow.png -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "dropbox-focus-intellij-plugin" 2 | -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/actions/ClearFocusAction.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.actions 2 | 3 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettingsReader 4 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusService 5 | import com.intellij.openapi.actionSystem.AnAction 6 | import com.intellij.openapi.actionSystem.AnActionEvent 7 | import com.intellij.openapi.components.service 8 | 9 | class ClearFocusAction : AnAction() { 10 | override fun actionPerformed(event: AnActionEvent) { 11 | val project = event.project 12 | val focusSettings = project?.service()?.getProjectFocusSettings() ?: return 13 | 14 | if (focusSettings.currentFocusModulePath != null) { 15 | project.service().clearFocus(focusSettings, requireSync = true) 16 | } 17 | } 18 | 19 | override fun update(event: AnActionEvent) { 20 | val project = event.project 21 | val focusSettings = project?.service()?.getProjectFocusSettings() 22 | 23 | event.presentation.isEnabled = focusSettings?.currentFocusModulePath != null 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/actions/FocusFileAction.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.actions 2 | 3 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettingsReader 4 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusService 5 | import com.intellij.idea.IdeaLogger 6 | import com.intellij.openapi.actionSystem.AnAction 7 | import com.intellij.openapi.actionSystem.AnActionEvent 8 | import com.intellij.openapi.actionSystem.CommonDataKeys 9 | import com.intellij.openapi.components.service 10 | import com.intellij.openapi.project.guessProjectDir 11 | 12 | val logger by lazy { IdeaLogger.getFactory().getLoggerInstance("Focus") } 13 | 14 | class FocusFileAction : AnAction() { 15 | private companion object { 16 | const val FOCUS_ON_MODULE_TEXT = "Focus on Module" 17 | const val CLEAR_FOCUS_TEXT = "Clear Focus" 18 | } 19 | 20 | override fun actionPerformed(event: AnActionEvent) { 21 | val project = event.project 22 | val focusSettings = project?.service()?.getProjectFocusSettings() ?: return 23 | val clickedFolderPath = event.getData(CommonDataKeys.VIRTUAL_FILE)?.toNioPath() ?: return 24 | 25 | val rootDir = project.guessProjectDir()?.toNioPath() 26 | 27 | when { 28 | rootDir == clickedFolderPath -> { 29 | project.service().clearFocus(focusSettings, requireSync = true) 30 | } 31 | else -> { 32 | val focusModule = focusSettings.allModules.find { it.moduleDirPath == clickedFolderPath } ?: return 33 | project.service().focusOn(focusSettings, focusModule.gradleModulePath) 34 | } 35 | } 36 | } 37 | 38 | override fun update(event: AnActionEvent) { 39 | fun hide() { 40 | event.presentation.isVisible = false 41 | } 42 | 43 | val clickedFolderPath = event.getData(CommonDataKeys.VIRTUAL_FILE)?.toNioPath() ?: run { 44 | hide() 45 | return 46 | } 47 | 48 | val project = event.project 49 | val focusSettings = project?.service()?.getProjectFocusSettings() ?: run { 50 | hide() 51 | return 52 | } 53 | val rootDir = project.guessProjectDir()?.toNioPath() 54 | 55 | when { 56 | rootDir == clickedFolderPath -> { 57 | event.presentation.text = CLEAR_FOCUS_TEXT 58 | event.presentation.isEnabled = focusSettings.currentFocusGradleIncludeFile != null 59 | } 60 | focusSettings.allModules.any { it.moduleDirPath == clickedFolderPath } -> { 61 | event.presentation.text = FOCUS_ON_MODULE_TEXT 62 | } 63 | else -> hide() 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/extensions/FocusToolWindowFactory.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.extensions 2 | 3 | import androidx.compose.ui.awt.ComposePanel 4 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettingsReader 5 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusService 6 | import br.com.devsrsouza.intellij.dropboxfocus.ui.FocusSelection 7 | import com.intellij.openapi.application.ApplicationManager 8 | import com.intellij.openapi.components.service 9 | import com.intellij.openapi.project.Project 10 | import com.intellij.openapi.wm.ToolWindow 11 | import com.intellij.openapi.wm.ToolWindowFactory 12 | import java.awt.Dimension 13 | 14 | class FocusToolWindowFactory : ToolWindowFactory { 15 | override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { 16 | ApplicationManager.getApplication().invokeLater { 17 | toolWindow.component.add( 18 | ComposePanel().apply { 19 | val focusService = project.service() 20 | preferredSize = Dimension(300, 300) 21 | setContent { 22 | val gradleSettingsState = project.service() 23 | .focusGradleSettings 24 | FocusSelection( 25 | currentFocusGradleSettingsState = gradleSettingsState, 26 | isLoadingState = focusService.focusOperationState, 27 | syncGradle = focusService::syncGradle, 28 | selectModuleToFocus = { focusGradleSettings, focusModule -> 29 | focusService.focusOn(focusGradleSettings, focusModule.gradleModulePath) 30 | }, 31 | clearFocus = { 32 | focusService.clearFocus( 33 | focusSettings = gradleSettingsState.value!!, 34 | requireSync = true, 35 | ) 36 | }, 37 | withClearFocusButton = true, 38 | ) 39 | } 40 | } 41 | ) 42 | } 43 | } 44 | 45 | override fun isApplicable(project: Project): Boolean { 46 | return true 47 | } 48 | 49 | override fun shouldBeAvailable(project: Project): Boolean { 50 | return project.service().focusGradleSettings.value != null 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/listeners/FocusGradleSyncListener.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.listeners 2 | 3 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettingsReader 4 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusService 5 | import com.android.tools.idea.gradle.project.sync.GradleSyncListener 6 | import com.intellij.openapi.components.service 7 | import com.intellij.openapi.project.Project 8 | import java.lang.reflect.InvocationHandler 9 | import java.lang.reflect.Proxy 10 | 11 | // This is required because apparently, with the addiction of syncStarted, in the newer version 12 | // the bytecode got incompatible. 13 | fun createFocusGradleSyncListener(): GradleSyncListener { 14 | return Proxy.newProxyInstance( 15 | ThemeChangeListener::class.java.classLoader, 16 | arrayOf(GradleSyncListener::class.java), 17 | InvocationHandler { proxy, method, args -> 18 | fun project() = args.get(0) as Project 19 | fun finishOperation() { 20 | project().service()._focusOperationState.value = false 21 | } 22 | when (method.name) { 23 | "syncSucceeded" -> { 24 | finishOperation() 25 | project().service().reloadProjectFocusSettings() 26 | } 27 | "syncFailed" -> { 28 | finishOperation() 29 | } 30 | "syncSkipped" -> { 31 | finishOperation() 32 | } 33 | "syncStarted" -> { 34 | // Available since 2021.1 (if I recall, so we use it) 35 | project().service()._focusOperationState.value = true 36 | } 37 | } 38 | } 39 | ) as GradleSyncListener 40 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/listeners/FocusProjectOpenListener.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.listeners 2 | 3 | import br.com.devsrsouza.intellij.dropboxfocus.actions.logger 4 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettingsReader 5 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusService 6 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusSettings 7 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusToolWindowService 8 | import br.com.devsrsouza.intellij.dropboxfocus.ui.dialog.StartupFocusProjectDialog 9 | import com.android.tools.idea.gradle.project.sync.GradleSyncState 10 | import com.intellij.openapi.components.service 11 | import com.intellij.openapi.project.Project 12 | import com.intellij.openapi.project.ProjectManagerListener 13 | 14 | internal class FocusProjectOpenListener : ProjectManagerListener { 15 | 16 | override fun projectOpened(project: Project) { 17 | GradleSyncState.subscribe(project, createFocusGradleSyncListener()) 18 | project.service().init() 19 | 20 | val shouldShowDialog = project.service().shouldShowStartupDialog 21 | if (shouldShowDialog.not()) return 22 | 23 | val settingsService = project.service() 24 | 25 | val focusSettings = settingsService.getProjectFocusSettings() 26 | logger.debug("Founded Focus Settings in ${project.name}: $focusSettings") 27 | 28 | if (focusSettings != null) { 29 | val focusService = project.service() 30 | StartupFocusProjectDialog(project, focusSettings, focusService).show() 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/listeners/ThemeChangeListener.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.listeners 2 | 3 | import com.intellij.ide.ui.LafManager 4 | import com.intellij.ide.ui.LafManagerListener 5 | import io.kanro.compose.jetbrains.SwingColor 6 | 7 | class ThemeChangeListener : LafManagerListener { 8 | override fun lookAndFeelChanged(source: LafManager) { 9 | SwingColor.onThemeChange() 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/psi/GroovyPsiUtil.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.psi 2 | 3 | import com.intellij.psi.PsiElement 4 | import com.intellij.psi.PsiFile 5 | import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType 6 | import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement 7 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList 8 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall 9 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression 10 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral 11 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression 12 | 13 | internal fun PsiFile.findGroovyHighOrderFunction(functionName: String): GrMethodCallExpression? = 14 | findDescendantOfType { 15 | it.isFunctionName(functionName) 16 | } 17 | 18 | internal fun PsiElement.findGroovyMethodCall( 19 | functionName: String, 20 | callback: (arguments: Array) -> Boolean = { true } 21 | ): GrMethodCall? { 22 | // This will cover both GrMethodCallExpression or GrApplicationStatement 23 | // that difference by it format, for example 24 | // id("something") -> id 'something' 25 | // we cant use `children` here because if the declaration is something like: 26 | // id("something") version "version", then the GrMethodCall that we want 27 | // will be in a lower tree 28 | return findDescendantOfType { 29 | if (it.isFunctionName(functionName)) { 30 | val arguments = it.getFunctionArguments() 31 | 32 | if (arguments != null) { 33 | callback(arguments) 34 | } else false 35 | } else true 36 | } 37 | } 38 | 39 | internal fun GrMethodCall.getFunctionArguments(): Array? = 40 | children.asSequence().filterIsInstance() 41 | .firstOrNull()?.allArguments 42 | 43 | internal fun PsiElement.forEachGroovyMethodCall( 44 | functionName: String, 45 | callback: (arguments: Array) -> Unit 46 | ) { 47 | findGroovyMethodCall(functionName) { 48 | callback(it) 49 | false 50 | } 51 | } 52 | 53 | internal fun Array.getFirstArgumentAsLiteralString(): String? = 54 | firstOrNull()?.findDescendantOfType()?.text 55 | ?.removeSurroundingQuotes() 56 | 57 | internal fun Array.getAllArgumentAsLiteralString(): List = 58 | mapNotNull { it.findDescendantOfType()?.text?.removeSurroundingQuotes() } 59 | 60 | internal fun GrMethodCall.isFunctionName(functionName: String): Boolean = 61 | children.asSequence().filterIsInstance() 62 | .any { it.text == functionName } 63 | 64 | internal fun String.removeSurroundingQuotes(): String = removeSurrounding("\"") 65 | .removeSurrounding("'") -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/psi/KotlinPsiUtil.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.psi 2 | 3 | import br.com.devsrsouza.intellij.dropboxfocus.services.GRADLE_PROPERTY_SET_FUNCTION_NAME 4 | import com.intellij.psi.PsiElement 5 | import org.jetbrains.kotlin.psi.KtCallExpression 6 | import org.jetbrains.kotlin.psi.KtDotQualifiedExpression 7 | import org.jetbrains.kotlin.psi.KtReferenceExpression 8 | import org.jetbrains.kotlin.psi.KtValueArgument 9 | import org.jetbrains.kotlin.psi.KtValueArgumentList 10 | import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType 11 | 12 | internal fun PsiElement.findKotlinFunction( 13 | functionName: String, 14 | predicate: (KtCallExpression, arguments: List?) -> Boolean = { _, _ -> true } 15 | ): KtCallExpression? = findDescendantOfType { 16 | val arguments = it.children.asSequence().filterIsInstance() 17 | .firstOrNull()?.arguments 18 | it.isFunctionName(functionName) && predicate(it, arguments) 19 | } 20 | 21 | internal fun PsiElement.forEachKotlinFunction( 22 | functionName: String, 23 | predicate: (KtCallExpression, arguments: List?) -> Unit = { _, _ -> } 24 | ) { 25 | findKotlinFunction(functionName) { it, argument -> 26 | predicate(it, argument) 27 | false 28 | } 29 | } 30 | 31 | internal fun KtCallExpression.isFunctionName(functionName: String): Boolean { 32 | return children.asSequence().filterIsInstance() 33 | .any { it.text == functionName } 34 | } 35 | 36 | internal fun KtCallExpression.findGradlePropertySetValueOnCallback( 37 | propertyName: String 38 | ): String? { 39 | var result: String? = null 40 | // search for expression with a Dot ex: property.set() 41 | findDescendantOfType { 42 | // checks if the property name at the left is [propertyName] 43 | val isThePropertyWeAreLookingFor = it.children.asSequence().filterIsInstance() 44 | .any { it.text == propertyName } 45 | 46 | if (isThePropertyWeAreLookingFor) { 47 | // search for the set("") function call expression 48 | it.findKotlinFunction(GRADLE_PROPERTY_SET_FUNCTION_NAME) { it, arguments -> 49 | // If it is, we will get the first parameter value 50 | // ex: set("something") => something 51 | result = arguments?.getFirstArgumentAsLiteralString() 52 | 53 | true 54 | } != null 55 | } else false 56 | } 57 | 58 | return result 59 | } 60 | 61 | internal fun List.getFirstArgumentAsLiteralString(): String? = 62 | firstOrNull()?.text?.removeSurrounding("\"") 63 | 64 | internal fun List.getAllArgumentAsLiteralString(): List = 65 | map { it.text.removeSurrounding("\"") } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/services/FocusConfigurable.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.services 2 | 3 | import androidx.compose.foundation.layout.Column 4 | import androidx.compose.foundation.layout.Row 5 | import androidx.compose.foundation.layout.fillMaxSize 6 | import androidx.compose.foundation.layout.padding 7 | import androidx.compose.runtime.getValue 8 | import androidx.compose.runtime.mutableStateOf 9 | import androidx.compose.runtime.remember 10 | import androidx.compose.runtime.setValue 11 | import androidx.compose.ui.Modifier 12 | import androidx.compose.ui.awt.ComposePanel 13 | import androidx.compose.ui.unit.dp 14 | import br.com.devsrsouza.intellij.dropboxfocus.ui.Theme 15 | import com.intellij.openapi.components.service 16 | import com.intellij.openapi.options.SearchableConfigurable 17 | import com.intellij.openapi.project.Project 18 | import io.kanro.compose.jetbrains.control.CheckBox 19 | import io.kanro.compose.jetbrains.control.JPanel 20 | import io.kanro.compose.jetbrains.control.Text 21 | import javax.swing.JComponent 22 | 23 | class FocusConfigurable(private val project: Project) : SearchableConfigurable { 24 | 25 | private val settings = project.service() 26 | 27 | private val settingsPanel by lazy { 28 | ComposePanel().apply { 29 | setContent { 30 | Theme { 31 | JPanel(modifier = Modifier.fillMaxSize()) { 32 | Column( 33 | modifier = Modifier.padding(all = 16.dp) 34 | ) { 35 | Row { 36 | var checkState by remember { 37 | mutableStateOf(settings.shouldShowStartupDialog) 38 | } 39 | CheckBox( 40 | checked = checkState, 41 | onCheckedChange = { 42 | settings.shouldShowStartupDialog = !checkState 43 | checkState = !checkState 44 | } 45 | ) 46 | Text( 47 | text = "Show Focus startup dialog for this project", 48 | modifier = Modifier.padding(start = 8.dp) 49 | ) 50 | } 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } 57 | 58 | override fun createComponent(): JComponent = settingsPanel 59 | override fun isModified(): Boolean = false 60 | 61 | override fun apply() = Unit 62 | 63 | override fun getDisplayName(): String = "Dropbox Focus" 64 | 65 | override fun getId(): String = ID 66 | 67 | companion object { 68 | const val ID = "br.com.devsrsouza.intellij.dropboxfocus.configurable" 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/services/FocusGradleSettingsReader.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.services 2 | 3 | import br.com.devsrsouza.intellij.dropboxfocus.actions.logger 4 | import br.com.devsrsouza.intellij.dropboxfocus.psi.findGradlePropertySetValueOnCallback 5 | import br.com.devsrsouza.intellij.dropboxfocus.psi.findGroovyHighOrderFunction 6 | import br.com.devsrsouza.intellij.dropboxfocus.psi.findGroovyMethodCall 7 | import br.com.devsrsouza.intellij.dropboxfocus.psi.findKotlinFunction 8 | import br.com.devsrsouza.intellij.dropboxfocus.psi.forEachGroovyMethodCall 9 | import br.com.devsrsouza.intellij.dropboxfocus.psi.forEachKotlinFunction 10 | import br.com.devsrsouza.intellij.dropboxfocus.psi.getAllArgumentAsLiteralString 11 | import br.com.devsrsouza.intellij.dropboxfocus.psi.getFirstArgumentAsLiteralString 12 | import br.com.devsrsouza.intellij.dropboxfocus.psi.getFunctionArguments 13 | import br.com.devsrsouza.intellij.dropboxfocus.psi.removeSurroundingQuotes 14 | import com.android.tools.idea.util.toIoFile 15 | import com.intellij.openapi.components.Service 16 | import com.intellij.openapi.project.Project 17 | import com.intellij.openapi.project.guessProjectDir 18 | import com.intellij.psi.PsiFile 19 | import kotlinx.coroutines.flow.MutableStateFlow 20 | import kotlinx.coroutines.flow.StateFlow 21 | import org.jetbrains.kotlin.idea.core.util.toPsiFile 22 | import org.jetbrains.kotlin.psi.KtBinaryExpression 23 | import org.jetbrains.kotlin.psi.KtDotQualifiedExpression 24 | import org.jetbrains.kotlin.psi.KtNameReferenceExpression 25 | import org.jetbrains.kotlin.psi.KtOperationReferenceExpression 26 | import org.jetbrains.kotlin.psi.KtStringTemplateExpression 27 | import org.jetbrains.kotlin.psi.KtTypeArgumentList 28 | import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType 29 | import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType 30 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrAssignmentExpression 31 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression 32 | import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral 33 | import org.jetbrains.plugins.groovy.lang.psi.impl.stringValue 34 | import java.io.File 35 | import java.nio.file.Path 36 | import kotlin.io.path.ExperimentalPathApi 37 | import kotlin.io.path.div 38 | 39 | internal const val GRADLE_PROPERTY_SET_FUNCTION_NAME = "set" 40 | 41 | internal const val SETTINGS_KTS_FILE = "settings.gradle.kts" 42 | internal const val SETTINGS_FILE = "settings.gradle" 43 | internal const val MODULE_SETTINGS_FILE_DEFAULT = "settings-all.gradle" 44 | 45 | internal const val FOCUS_FILE_NAME_DEFAULT = ".focus" 46 | private const val FOCUS_GROOVY_CALLBACK_NAME = "focus" 47 | private const val KTS_CONFIGURE_CALLBACK_NAME = "configure" 48 | private const val FOCUS_EXTENSION_FQN_TYPE_NAME = "com.dropbox.focus.FocusExtension" 49 | private const val FOCUS_EXTENSION_SIMPLE_TYPE_NAME = "FocusExtension" 50 | private const val ALL_SETTINGS_FILE_NAME_ASSIGNMENT_NAME = "allSettingsFileName" 51 | private const val FOCUS_FILE_NAME_ASSIGNMENT_NAME = "focusFileName" 52 | private const val MODULE_INCLUDE_FUNCTION_NAME = "include" 53 | private const val PROJECT_FUNCTION_NAME = "project" 54 | private const val SET_PROJECT_DIR_PROPERTY_NAME = "projectDir" 55 | private const val GRADLE_PLUGINS_CALLBACK_NAME = "plugins" 56 | private const val GRADLE_PLUGINS_ID_FUNCTION_NAME = "id" 57 | private const val FOCUS_GRADLE_PLUGIN_ID = "com.dropbox.focus" 58 | 59 | private val FOCUS_EXTENSION_TYPE_NAMES = listOf(FOCUS_EXTENSION_FQN_TYPE_NAME, FOCUS_EXTENSION_SIMPLE_TYPE_NAME) 60 | 61 | data class FocusGradleSettings( 62 | val allModulesSettingsFile: String, 63 | val focusFileName: String, 64 | val currentFocusGradleIncludeFile: String?, 65 | val allModules: List, 66 | ) { 67 | val currentFocusModulePath: String? get() { 68 | val moduleDir = currentFocusGradleIncludeFile?.removeSuffix("/build/focus.settings.gradle") 69 | return allModules.find { it.moduleDirRelativeToRootProjectDir == moduleDir } 70 | ?.gradleModulePath 71 | } 72 | } 73 | 74 | data class FocusModule( 75 | val gradleModulePath: String, 76 | val moduleDirPath: Path, 77 | val moduleDirRelativeToRootProjectDir: String, 78 | ) 79 | 80 | @Service 81 | class FocusGradleSettingsReader(private val project: Project) { 82 | private val _focusGradleSettings: MutableStateFlow = MutableStateFlow(null) 83 | val focusGradleSettings: StateFlow = _focusGradleSettings 84 | 85 | fun getProjectFocusSettings(): FocusGradleSettings? { 86 | if (_focusGradleSettings.value == null) { 87 | reloadProjectFocusSettings() 88 | } 89 | 90 | return _focusGradleSettings.value 91 | } 92 | 93 | fun reloadProjectFocusSettings() { 94 | val dir = project.guessProjectDir() ?: run { 95 | _focusGradleSettings.value = null 96 | return 97 | } 98 | 99 | val gradleSettingsFile = File(dir.toIoFile(), SETTINGS_FILE).takeIf(File::exists) 100 | ?: File(dir.toIoFile(), SETTINGS_KTS_FILE).takeIf(File::exists) 101 | ?: run { 102 | _focusGradleSettings.value = null 103 | return 104 | } 105 | 106 | _focusGradleSettings.value = readSettings(gradleSettingsFile) 107 | } 108 | 109 | private fun readSettings(file: File): FocusGradleSettings? { 110 | val psiFile = file.toPsiFile(project) ?: return null 111 | 112 | return when (file.name) { 113 | SETTINGS_KTS_FILE -> readKotlinScriptSettings(psiFile) 114 | SETTINGS_FILE -> readGroovySettings(psiFile) 115 | else -> null 116 | } 117 | } 118 | 119 | fun readGroovySettings(psiFile: PsiFile): FocusGradleSettings? { 120 | logger.debug("Looking into settings.gradle (groovy) to find Focus configuration") 121 | val pluginsExtensionBlock = psiFile.findGroovyHighOrderFunction(GRADLE_PLUGINS_CALLBACK_NAME) ?: return null 122 | 123 | // We try to find in the plugins block a declaration for the Focus Plugin ID 124 | val isFocusPluginApplied = pluginsExtensionBlock.findGroovyMethodCall(GRADLE_PLUGINS_ID_FUNCTION_NAME) { 125 | it.getFirstArgumentAsLiteralString() == FOCUS_GRADLE_PLUGIN_ID 126 | } != null 127 | 128 | if (!isFocusPluginApplied) return null 129 | 130 | // The focus configuration block could not be present, meaning that the user is using the default 131 | // focus plugin setting resulting in focusExtensionBlock being null 132 | val focusExtensionBlock = psiFile.findGroovyHighOrderFunction(FOCUS_GROOVY_CALLBACK_NAME) 133 | 134 | val allSettingsFileName = focusExtensionBlock?.findDescendantOfType { 135 | it.lValue.text == ALL_SETTINGS_FILE_NAME_ASSIGNMENT_NAME 136 | }?.rValue?.stringValue() ?: MODULE_SETTINGS_FILE_DEFAULT 137 | 138 | val focusFileName = focusExtensionBlock?.findDescendantOfType { 139 | it.lValue.text == FOCUS_FILE_NAME_ASSIGNMENT_NAME 140 | }?.rValue?.stringValue() ?: FOCUS_FILE_NAME_DEFAULT 141 | 142 | return FocusGradleSettings( 143 | allModulesSettingsFile = allSettingsFileName, 144 | focusFileName = focusFileName, 145 | currentFocusGradleIncludeFile = getCurrentFocusOrNull(focusFileName), 146 | allModules = readAllModules(allSettingsFileName), 147 | ) 148 | } 149 | 150 | fun readKotlinScriptSettings(psiFile: PsiFile): FocusGradleSettings? { 151 | logger.debug("Looking into settings.gradle.kts (kotlin) to find Focus configuration") 152 | val pluginsExtensionBlock = psiFile.findKotlinFunction(GRADLE_PLUGINS_CALLBACK_NAME) ?: return null 153 | 154 | val isFocusPluginApplied = pluginsExtensionBlock 155 | .findKotlinFunction(GRADLE_PLUGINS_ID_FUNCTION_NAME) { _, arguments -> 156 | arguments?.getFirstArgumentAsLiteralString() == FOCUS_GRADLE_PLUGIN_ID 157 | } != null 158 | 159 | if (!isFocusPluginApplied) { 160 | return null 161 | } 162 | 163 | // The focus configuration block could not be present, meaning that the user is using the default 164 | // focus plugin setting resulting in focusExtensionBlock being null 165 | val focusConfigureExtensionBlock = psiFile.findKotlinFunction(KTS_CONFIGURE_CALLBACK_NAME) { it, _ -> 166 | // check if the generic type is FocusExtension or com.dropbox.focus.FocusExtension 167 | // for example: configure {} 168 | it.children.asSequence().filterIsInstance() 169 | .any { (it.arguments.firstOrNull()?.text ?: "") in FOCUS_EXTENSION_TYPE_NAMES } 170 | } 171 | 172 | val allSettingsFileName = focusConfigureExtensionBlock 173 | ?.findGradlePropertySetValueOnCallback(ALL_SETTINGS_FILE_NAME_ASSIGNMENT_NAME) 174 | ?: MODULE_SETTINGS_FILE_DEFAULT 175 | val focusFileName = focusConfigureExtensionBlock 176 | ?.findGradlePropertySetValueOnCallback(FOCUS_FILE_NAME_ASSIGNMENT_NAME) 177 | ?: FOCUS_FILE_NAME_DEFAULT 178 | 179 | return FocusGradleSettings( 180 | allModulesSettingsFile = allSettingsFileName, 181 | focusFileName = focusFileName, 182 | currentFocusGradleIncludeFile = getCurrentFocusOrNull(focusFileName), 183 | allModules = readAllModules(allSettingsFileName), 184 | ) 185 | } 186 | 187 | private fun readAllModules(allSettingsFileName: String): List { 188 | val dir = project.guessProjectDir() ?: return emptyList() 189 | 190 | val allSettingsFile = File(dir.toIoFile(), allSettingsFileName).takeIf(File::exists) ?: return emptyList() 191 | val psiFile = allSettingsFile.toPsiFile(project) ?: return emptyList() 192 | 193 | return when (allSettingsFile.extension) { 194 | "kts" -> readAllModulesFromKts(psiFile) 195 | "gradle" -> readAllModulesFromGroovy(psiFile) 196 | else -> emptyList() 197 | } 198 | } 199 | 200 | @OptIn(ExperimentalPathApi::class) 201 | private fun readAllModulesFromGroovy(psiFile: PsiFile): List { 202 | val rootProjectDir = project.guessProjectDir()!!.toNioPath() 203 | fun String.pathAsModuleDir() = replace(":", "/").removePrefix("/") 204 | 205 | val modules = mutableMapOf() 206 | psiFile.forEachGroovyMethodCall(MODULE_INCLUDE_FUNCTION_NAME) { 207 | val modulePaths = it.getAllArgumentAsLiteralString() 208 | for (modulePath in modulePaths) { 209 | modules += modulePath to modulePath.pathAsModuleDir() 210 | } 211 | } 212 | 213 | psiFile.forEachDescendantOfType { 214 | val modulePath = it.lValue.findGroovyMethodCall(PROJECT_FUNCTION_NAME) 215 | ?.getFunctionArguments() 216 | ?.getFirstArgumentAsLiteralString() 217 | ?: return@forEachDescendantOfType 218 | 219 | val isSetProjectDir = (it.lValue as? GrReferenceExpression)?.canonicalText == SET_PROJECT_DIR_PROPERTY_NAME 220 | 221 | if (isSetProjectDir) { 222 | val projectDirPath = it.rValue?.findDescendantOfType()?.stringValue() 223 | ?: return@forEachDescendantOfType 224 | 225 | modules += modulePath to projectDirPath 226 | } 227 | } 228 | 229 | return modules.map { (modulePath, moduleDir) -> 230 | FocusModule( 231 | gradleModulePath = modulePath, 232 | moduleDirPath = rootProjectDir / moduleDir, 233 | moduleDirRelativeToRootProjectDir = moduleDir, 234 | ) 235 | } 236 | } 237 | 238 | @OptIn(ExperimentalPathApi::class) 239 | private fun readAllModulesFromKts(psiFile: PsiFile): List { 240 | val rootProjectDir = project.guessProjectDir()!!.toNioPath() 241 | fun String.pathAsModuleDir() = replace(":", "/").removePrefix("/") 242 | val modules = mutableMapOf() 243 | 244 | psiFile.forEachKotlinFunction(MODULE_INCLUDE_FUNCTION_NAME) { it, arguments -> 245 | val modulePaths = arguments?.getAllArgumentAsLiteralString() 246 | if (modulePaths != null) { 247 | for (modulePath in modulePaths) { 248 | modules += modulePath to modulePath.pathAsModuleDir() 249 | } 250 | } 251 | } 252 | 253 | psiFile.forEachKotlinFunction(PROJECT_FUNCTION_NAME) { it, arguments -> 254 | val modulePath = arguments?.getFirstArgumentAsLiteralString() ?: return@forEachKotlinFunction 255 | if (modulePath !in modules.keys) return@forEachKotlinFunction 256 | 257 | val projectDirExpression = it.parent as? KtDotQualifiedExpression ?: return@forEachKotlinFunction 258 | 259 | val isProjectDir = projectDirExpression.children.filterIsInstance() 260 | .lastOrNull()?.text == SET_PROJECT_DIR_PROPERTY_NAME 261 | 262 | if (isProjectDir) { 263 | val setProjectDirExpression = projectDirExpression.parent as? KtBinaryExpression 264 | ?: return@forEachKotlinFunction 265 | 266 | val resultsPsiElements = setProjectDirExpression.children.dropWhile { 267 | it !is KtOperationReferenceExpression 268 | } 269 | 270 | val projectDirPath = resultsPsiElements.asSequence().mapNotNull { 271 | it.findDescendantOfType()?.text?.removeSurroundingQuotes() 272 | }.firstOrNull() ?: return@forEachKotlinFunction 273 | 274 | modules += modulePath to projectDirPath 275 | } 276 | } 277 | 278 | return modules.map { (modulePath, moduleDir) -> 279 | FocusModule( 280 | gradleModulePath = modulePath, 281 | moduleDirPath = rootProjectDir / moduleDir, 282 | moduleDirRelativeToRootProjectDir = moduleDir, 283 | ) 284 | } 285 | } 286 | 287 | private fun getCurrentFocusOrNull(focusFileName: String): String? { 288 | return project.guessProjectDir()?.toIoFile()?.let { 289 | File(it, focusFileName).takeIf(File::exists)?.readText() 290 | } 291 | } 292 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/services/FocusService.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.services 2 | 3 | import com.android.tools.idea.gradle.project.sync.GradleSyncInvoker 4 | import com.android.tools.idea.gradle.project.sync.GradleSyncListener 5 | import com.android.tools.idea.util.toIoFile 6 | import com.google.wireless.android.sdk.stats.GradleSyncStats 7 | import com.intellij.execution.executors.DefaultRunExecutor 8 | import com.intellij.openapi.components.Service 9 | import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings 10 | import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode 11 | import com.intellij.openapi.externalSystem.task.TaskCallback 12 | import com.intellij.openapi.externalSystem.util.ExternalSystemUtil 13 | import com.intellij.openapi.project.Project 14 | import com.intellij.openapi.project.guessProjectDir 15 | import kotlinx.coroutines.flow.MutableStateFlow 16 | import kotlinx.coroutines.flow.StateFlow 17 | import org.jetbrains.plugins.gradle.util.GradleConstants 18 | import java.io.File 19 | 20 | @Service 21 | class FocusService(private val project: Project) { 22 | internal val _focusOperationState = MutableStateFlow(false) 23 | val focusOperationState: StateFlow = _focusOperationState 24 | 25 | fun focusOn(focusSettings: FocusGradleSettings, focusModulePath: String) { 26 | _focusOperationState.value = true 27 | try { 28 | clearFocus(focusSettings, requireSync = false) 29 | 30 | runGradleTask("$focusModulePath:focus", onSuccess = { 31 | syncGradle() 32 | }) 33 | } catch (e: Exception) { 34 | _focusOperationState.value = false 35 | } 36 | } 37 | 38 | // RequireSync when used on Actions or on ClearFocus on the project startup clear focus selection 39 | fun clearFocus(focusSettings: FocusGradleSettings, requireSync: Boolean) { 40 | val dir = project.guessProjectDir()?.toIoFile() ?: return 41 | 42 | File(dir, focusSettings.focusFileName).takeIf(File::exists)?.delete() 43 | 44 | if (requireSync) { 45 | syncGradle() 46 | } 47 | } 48 | 49 | private fun runGradleTask( 50 | task: String, 51 | onSuccess: () -> Unit = {}, 52 | onFailure: () -> Unit = {}, 53 | ) { 54 | val settings = ExternalSystemTaskExecutionSettings().apply { 55 | externalProjectPath = project.basePath 56 | taskNames = listOf(task) 57 | vmOptions = "" 58 | externalSystemIdString = GradleConstants.SYSTEM_ID.id 59 | } 60 | 61 | ExternalSystemUtil.runTask( 62 | settings, 63 | DefaultRunExecutor.EXECUTOR_ID, 64 | project, 65 | GradleConstants.SYSTEM_ID, 66 | object : TaskCallback { 67 | override fun onSuccess() { 68 | onSuccess() 69 | } 70 | 71 | override fun onFailure() { 72 | onFailure() 73 | } 74 | }, 75 | ProgressExecutionMode.NO_PROGRESS_ASYNC, 76 | false, 77 | ) 78 | } 79 | 80 | private val gradleProjectImporterInstance by lazy { 81 | GradleSyncInvoker::class.java.getDeclaredMethod("getInstance").invoke(null) 82 | } 83 | 84 | private val requestProjectSyncMethod by lazy { 85 | GradleSyncInvoker::class.java.getDeclaredMethod( 86 | "requestProjectSync", 87 | Project::class.java, 88 | GradleSyncStats.Trigger::class.java, 89 | GradleSyncListener::class.java, 90 | ) 91 | } 92 | 93 | private val requestProjectSyncMethodWithRequest by lazy { 94 | GradleSyncInvoker::class.java.getDeclaredMethod( 95 | "requestProjectSync", 96 | Project::class.java, 97 | GradleSyncInvoker.Request::class.java, 98 | GradleSyncListener::class.java, 99 | ) 100 | } 101 | 102 | private val requestConstructor by lazy { 103 | GradleSyncInvoker.Request::class.java.getConstructor( 104 | GradleSyncStats.Trigger::class.java 105 | ) 106 | } 107 | 108 | fun syncGradle() { 109 | _focusOperationState.value = true 110 | 111 | runCatching { 112 | // Reflection required to fix bytecode incompatibility with AS 2021.3.1 Canary 7 113 | requestProjectSyncMethod.invoke( 114 | gradleProjectImporterInstance, 115 | project, 116 | GradleSyncStats.Trigger.TRIGGER_PROJECT_MODIFIED, 117 | null 118 | ) 119 | }.onFailure { 120 | // AS 2022.1 Canary 1 does not have a function with [Trigger] type 121 | try { 122 | requestProjectSyncMethodWithRequest.invoke( 123 | gradleProjectImporterInstance, 124 | project, 125 | requestConstructor.newInstance(GradleSyncStats.Trigger.TRIGGER_PROJECT_MODIFIED), 126 | null, 127 | ) 128 | } catch (e: Throwable) {} 129 | } 130 | } 131 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/services/FocusSettings.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.services 2 | 3 | import com.intellij.openapi.components.BaseState 4 | import com.intellij.openapi.components.SimplePersistentStateComponent 5 | import com.intellij.openapi.components.State 6 | import com.intellij.openapi.components.Storage 7 | import com.intellij.openapi.components.service 8 | import com.intellij.openapi.project.Project 9 | 10 | @State( 11 | name = "DropboxFocusSettings", 12 | storages = [Storage("dropbox-focus.xml")] 13 | ) 14 | class FocusSettings( 15 | internal val project: Project 16 | ) : SimplePersistentStateComponent(FocusSettingsState()) { 17 | var shouldShowStartupDialog 18 | get() = state.shouldShowStartupDialog 19 | set(value) { state.shouldShowStartupDialog = value } 20 | 21 | override fun noStateLoaded() { 22 | super.noStateLoaded() 23 | loadState(FocusSettingsState()) 24 | } 25 | 26 | companion object { 27 | @JvmStatic 28 | fun getInstance(project: Project): FocusGradleSettings = project.service() 29 | } 30 | } 31 | 32 | class FocusSettingsState : BaseState() { 33 | var shouldShowStartupDialog by property(true) 34 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/services/FocusToolWindowService.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.services 2 | 3 | import com.intellij.openapi.Disposable 4 | import com.intellij.openapi.components.Service 5 | import com.intellij.openapi.components.service 6 | import com.intellij.openapi.project.Project 7 | import com.intellij.openapi.wm.ToolWindowManager 8 | import kotlinx.coroutines.Dispatchers 9 | import kotlinx.coroutines.GlobalScope 10 | import kotlinx.coroutines.Job 11 | import kotlinx.coroutines.flow.collect 12 | import kotlinx.coroutines.launch 13 | import kotlinx.coroutines.swing.Swing 14 | import org.jetbrains.kotlin.idea.util.application.invokeLater 15 | 16 | @Service 17 | class FocusToolWindowService(private val project: Project) : Disposable { 18 | private val job = Job() 19 | 20 | fun init() { 21 | ToolWindowManager.getInstance(project).invokeLater { 22 | GlobalScope.launch(Dispatchers.Swing + job) { 23 | project.service().focusGradleSettings.collect { 24 | val toolWindow = ToolWindowManager.getInstance(project) 25 | .getToolWindow("Focus") 26 | 27 | toolWindow?.isAvailable = it != null 28 | } 29 | } 30 | } 31 | } 32 | override fun dispose() { 33 | job.cancel() 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/ui/FocusSelection.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.ui 2 | 3 | import androidx.compose.foundation.VerticalScrollbar 4 | import androidx.compose.foundation.layout.Arrangement 5 | import androidx.compose.foundation.layout.Box 6 | import androidx.compose.foundation.layout.Column 7 | import androidx.compose.foundation.layout.Row 8 | import androidx.compose.foundation.layout.Spacer 9 | import androidx.compose.foundation.layout.fillMaxHeight 10 | import androidx.compose.foundation.layout.fillMaxSize 11 | import androidx.compose.foundation.layout.fillMaxWidth 12 | import androidx.compose.foundation.layout.heightIn 13 | import androidx.compose.foundation.layout.padding 14 | import androidx.compose.foundation.lazy.LazyColumn 15 | import androidx.compose.foundation.lazy.items 16 | import androidx.compose.foundation.lazy.rememberLazyListState 17 | import androidx.compose.foundation.rememberScrollbarAdapter 18 | import androidx.compose.material.CircularProgressIndicator 19 | import androidx.compose.runtime.Composable 20 | import androidx.compose.runtime.collectAsState 21 | import androidx.compose.runtime.mutableStateOf 22 | import androidx.compose.runtime.remember 23 | import androidx.compose.ui.Alignment 24 | import androidx.compose.ui.Modifier 25 | import androidx.compose.ui.unit.dp 26 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettings 27 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusModule 28 | import io.kanro.compose.jetbrains.JBTheme 29 | import io.kanro.compose.jetbrains.color.LocalButtonColors 30 | import io.kanro.compose.jetbrains.control.Button 31 | import io.kanro.compose.jetbrains.control.JPanel 32 | import io.kanro.compose.jetbrains.control.Text 33 | import io.kanro.compose.jetbrains.control.TextField 34 | import kotlinx.coroutines.flow.StateFlow 35 | 36 | @OptIn(ExperimentalStdlibApi::class) 37 | @Composable 38 | fun FocusSelection( 39 | currentFocusGradleSettingsState: StateFlow, 40 | isLoadingState: StateFlow, 41 | syncGradle: () -> Unit, 42 | selectModuleToFocus: (FocusGradleSettings, FocusModule) -> Unit, 43 | clearFocus: () -> Unit, 44 | withClearFocusButton: Boolean, 45 | ) { 46 | Theme { 47 | JPanel( 48 | modifier = Modifier.fillMaxSize() 49 | ) { 50 | val currentFocusGradleSettings = currentFocusGradleSettingsState.collectAsState().value 51 | val isLoading = isLoadingState.collectAsState().value 52 | 53 | if (isLoading) { 54 | Column( 55 | modifier = Modifier.fillMaxSize(), 56 | verticalArrangement = Arrangement.Center, 57 | horizontalAlignment = Alignment.CenterHorizontally, 58 | ) { 59 | CircularProgressIndicator( 60 | color = LocalButtonColors.current.defaultStart 61 | ) 62 | } 63 | } else { 64 | if (currentFocusGradleSettings == null) { 65 | Column( 66 | modifier = Modifier.fillMaxSize(), 67 | verticalArrangement = Arrangement.Center, 68 | horizontalAlignment = Alignment.CenterHorizontally, 69 | ) { 70 | Text( 71 | text = "Focus plugin not present.", 72 | style = JBTheme.typography.h3Bold, 73 | ) 74 | Button( 75 | onClick = syncGradle, 76 | modifier = Modifier.padding(all = 32.dp) 77 | ) { 78 | Text( 79 | "Sync Gradle", 80 | modifier = Modifier.padding(start = 16.dp, end = 16.dp) 81 | ) 82 | } 83 | } 84 | } else { 85 | Column(modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp)) { 86 | if (currentFocusGradleSettings.currentFocusModulePath != null) { 87 | if (withClearFocusButton) { 88 | Row(modifier = Modifier.fillMaxWidth()) { 89 | Spacer(modifier = Modifier.weight(1f)) 90 | Button( 91 | onClick = clearFocus, 92 | modifier = Modifier.align(Alignment.CenterVertically) 93 | ) { 94 | Text("Clear Focus") 95 | } 96 | } 97 | } 98 | Text( 99 | text = "Current focus:", 100 | style = JBTheme.typography.h3Bold, 101 | ) 102 | Text( 103 | text = currentFocusGradleSettings.currentFocusModulePath ?: "None", 104 | style = JBTheme.typography.h3, 105 | color = JBTheme.textColors.success, 106 | ) 107 | } 108 | 109 | Text( 110 | text = "Search", 111 | style = JBTheme.typography.h3Bold, 112 | ) 113 | 114 | val (search, setSearch) = remember { 115 | mutableStateOf("") 116 | } 117 | 118 | TextField( 119 | value = search, 120 | onValueChange = setSearch, 121 | modifier = Modifier.fillMaxWidth() 122 | ) 123 | 124 | Text( 125 | text = "Choose a module to Focus", 126 | style = JBTheme.typography.h3Bold, 127 | modifier = Modifier.padding(top = 16.dp) 128 | ) 129 | 130 | Box( 131 | modifier = Modifier.fillMaxWidth().heightIn(min = 300.dp) 132 | ) { 133 | 134 | val state = rememberLazyListState() 135 | val modules = remember(search) { 136 | currentFocusGradleSettings.allModules.filter { 137 | search.isBlank() || 138 | search.lowercase() in it.gradleModulePath.lowercase() 139 | } 140 | } 141 | 142 | LazyColumn(Modifier.fillMaxSize().padding(end = 12.dp, top = 4.dp), state) { 143 | items(modules) { item -> 144 | Button( 145 | onClick = { selectModuleToFocus(currentFocusGradleSettings, item) }, 146 | modifier = Modifier.padding(bottom = 8.dp, start = 16.dp, end = 16.dp), 147 | ) { 148 | Text( 149 | text = item.gradleModulePath, 150 | modifier = Modifier.fillMaxWidth(), 151 | ) 152 | } 153 | } 154 | } 155 | VerticalScrollbar( 156 | modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(), 157 | adapter = rememberScrollbarAdapter( 158 | scrollState = state 159 | ) 160 | ) 161 | } 162 | } 163 | } 164 | } 165 | } 166 | } 167 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/ui/IntellIj.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.ui 2 | 3 | import androidx.compose.runtime.Composable 4 | import androidx.compose.runtime.remember 5 | import androidx.compose.ui.graphics.Color 6 | import androidx.compose.ui.text.TextStyle 7 | import androidx.compose.ui.unit.sp 8 | import com.intellij.ide.ui.LafManager 9 | import com.intellij.ide.ui.UITheme 10 | import com.intellij.ide.ui.laf.UIThemeBasedLookAndFeelInfo 11 | import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo 12 | import com.intellij.ui.scale.JBUIScale 13 | import io.kanro.compose.jetbrains.JBTypography 14 | import io.kanro.compose.jetbrains.SwingColor 15 | import io.kanro.compose.jetbrains.color.CheckBoxColors 16 | import io.kanro.compose.jetbrains.color.darkCheckBoxColors 17 | import io.kanro.compose.jetbrains.color.lightCheckBoxColors 18 | import javax.swing.UIManager 19 | 20 | @Composable 21 | fun intelliJTypography(): JBTypography { 22 | return remember(SwingColor.themeChangeState) { 23 | JBTypography().run { 24 | copy( 25 | h0 = h0.jbScale(), 26 | h1 = h1.jbScale(), 27 | h2 = h2.jbScale(), 28 | h2Bold = h2Bold.jbScale(), 29 | h3 = h3.jbScale(), 30 | h3Bold = h3Bold.jbScale(), 31 | default = default.jbScale(), 32 | defaultBold = defaultBold.jbScale(), 33 | defaultUnderlined = defaultUnderlined.jbScale(), 34 | paragraph = paragraph.jbScale(), 35 | medium = medium.jbScale(), 36 | mediumBold = mediumBold.jbScale(), 37 | small = small.jbScale(), 38 | smallUnderlined = smallUnderlined.jbScale(), 39 | ) 40 | } 41 | } 42 | } 43 | 44 | fun CheckBoxColors.updateIntelliJColorsFixed() { 45 | val fromTheme = when (val laf = LafManager.getInstance().currentLookAndFeel) { 46 | is DarculaLookAndFeelInfo -> darkCheckBoxColors() 47 | is UIThemeBasedLookAndFeelInfo -> { 48 | if (laf.theme.name == "IntelliJ Light") { 49 | lightCheckBoxColors() 50 | } else { 51 | val fallback = if (laf.theme.isDark) darkCheckBoxColors() else lightCheckBoxColors() 52 | val theme = laf.theme 53 | with(fallback) { 54 | CheckBoxColors( 55 | bg = theme.color("Checkbox.Background.Default") 56 | ?: bg, 57 | bgSelected = theme.color("Checkbox.Background.Selected") 58 | ?: theme.color("Checkbox.Background.Default") 59 | ?: bgSelected, 60 | bgDisabled = theme.color("Checkbox.Background.Default") 61 | ?: bgDisabled, 62 | border = theme.color("Checkbox.Border.Default") 63 | ?: border, // dont know 64 | borderSelected = theme.color("Checkbox.Border.Selected") 65 | ?: theme.color("Checkbox.Focus.Thin.Selected") 66 | ?: borderSelected, // dont know 67 | borderFocused = theme.color("Checkbox.Focus.Thin.Selected") 68 | ?: theme.color("Checkbox.Border.Default") 69 | ?: borderFocused, 70 | borderDisabled = theme.color("Checkbox.Border.Disabled") 71 | ?: borderDisabled 72 | ) 73 | } 74 | } 75 | } 76 | else -> null 77 | } 78 | 79 | bg = fromTheme?.bg ?: bg 80 | bgSelected = fromTheme?.bgSelected ?: bgSelected 81 | bgDisabled = fromTheme?.bgDisabled ?: bgDisabled 82 | border = fromTheme?.border ?: border 83 | borderSelected = fromTheme?.borderSelected ?: borderSelected 84 | borderFocused = fromTheme?.borderFocused ?: borderFocused 85 | borderDisabled = fromTheme?.borderDisabled ?: borderDisabled 86 | } 87 | 88 | private val iconsField by lazy { 89 | UITheme::class.java.getDeclaredField("icons") 90 | .apply { isAccessible = true } 91 | } 92 | 93 | internal val UITheme.icons: Map? get() = 94 | iconsField.get(this) as? Map? 95 | 96 | internal val UITheme.colorPalette: Map? get() = 97 | ((icons?.get("ColorPalette") as? Map?)?.filterValues { it is String }) 98 | as? Map? 99 | 100 | private fun TextStyle.jbScale(): TextStyle = copy( 101 | fontSize = (JBUIScale.scale(fontSize.value)).sp 102 | ) 103 | 104 | private fun UITheme.color(name: String): Color? = 105 | if (name.endsWith(".Dark")) { 106 | colorPalette?.get(name)?.hexToColor 107 | } else { 108 | colorPalette?.get(name)?.hexToColor ?: color("$name.Dark") 109 | } 110 | 111 | private val String.hexToColor: Color? get() = runCatching { 112 | java.awt.Color.decode( 113 | this.toUpperCase() 114 | .replaceBeforeLast("#", "") 115 | ).asComposeColor 116 | }.getOrNull() 117 | 118 | private val java.awt.Color.asComposeColor: Color get() = Color(red, green, blue, alpha) 119 | 120 | private fun getSwingColor(vararg key: String): Color? { 121 | return key.firstNotNullOfOrNull { UIManager.getColor(it) }?.asComposeColor 122 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/ui/Theme.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.ui 2 | 3 | import androidx.compose.runtime.Composable 4 | import androidx.compose.runtime.remember 5 | import io.kanro.compose.jetbrains.JBThemeFromIntelliJ 6 | import io.kanro.compose.jetbrains.SwingColor 7 | import io.kanro.compose.jetbrains.color.LocalCheckBoxColors 8 | 9 | @Composable 10 | fun Theme(content: @Composable () -> Unit) { 11 | JBThemeFromIntelliJ( 12 | typography = intelliJTypography() 13 | ) { 14 | val currentCheckboxColors = LocalCheckBoxColors.current 15 | remember(SwingColor.themeChangeState) { 16 | currentCheckboxColors.updateIntelliJColorsFixed() 17 | } 18 | content() 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/kotlin/br/com/devsrsouza/intellij/dropboxfocus/ui/dialog/StartupFocusProjectDialog.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus.ui.dialog 2 | 3 | import androidx.compose.ui.awt.ComposePanel 4 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusGradleSettings 5 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusService 6 | import br.com.devsrsouza.intellij.dropboxfocus.services.FocusSettings 7 | import br.com.devsrsouza.intellij.dropboxfocus.ui.FocusSelection 8 | import com.intellij.openapi.components.service 9 | import com.intellij.openapi.project.Project 10 | import com.intellij.openapi.ui.DialogWrapper 11 | import kotlinx.coroutines.flow.MutableStateFlow 12 | import java.awt.Dimension 13 | import javax.swing.Action 14 | import javax.swing.JComponent 15 | 16 | class StartupFocusProjectDialog( 17 | private val project: Project, 18 | private val focusSettings: FocusGradleSettings, 19 | private val focusService: FocusService, 20 | ) : DialogWrapper(true) { 21 | 22 | init { 23 | title = "Focus" 24 | setCancelButtonText("Clear focus") 25 | setOKButtonText("Don't change") 26 | doNotOpenOnStartupCheckBox() 27 | init() 28 | } 29 | 30 | override fun createCenterPanel(): JComponent? = swing() 31 | 32 | private fun swing() = 33 | ComposePanel().apply { 34 | size = Dimension(300, 300) 35 | setContent { 36 | FocusSelection( 37 | currentFocusGradleSettingsState = MutableStateFlow(focusSettings), 38 | isLoadingState = MutableStateFlow(false), 39 | syncGradle = {}, 40 | selectModuleToFocus = { settings, module -> 41 | focusService.focusOn(settings, module.gradleModulePath) 42 | close(0) 43 | }, 44 | clearFocus = {}, 45 | withClearFocusButton = false, 46 | ) 47 | } 48 | } 49 | 50 | override fun doCancelAction() { 51 | super.doCancelAction() 52 | if (cancelAction.isEnabled) { 53 | focusService.clearFocus(focusSettings, requireSync = true) 54 | } 55 | } 56 | 57 | override fun createActions(): Array { 58 | if (focusSettings.currentFocusModulePath != null) { 59 | return arrayOf(okAction, cancelAction) 60 | } else { 61 | return arrayOf(okAction) 62 | } 63 | } 64 | 65 | fun doNotOpenOnStartupCheckBox() { 66 | setDoNotAskOption(object : DoNotAskOption { 67 | override fun isToBeShown(): Boolean = project.service().shouldShowStartupDialog 68 | 69 | override fun setToBeShown(toBeShown: Boolean, exitCode: Int) { 70 | project.service().shouldShowStartupDialog = toBeShown 71 | } 72 | 73 | override fun canBeHidden(): Boolean = true 74 | 75 | override fun shouldSaveOptionsOnCancel(): Boolean = true 76 | 77 | override fun getDoNotShowMessage(): String = "Do not show for this project" 78 | }) 79 | } 80 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | br.com.devsrsouza.intellij.dropboxfocus 4 | Focus 5 | DevSrSouza 6 | 7 | com.intellij.modules.platform 8 | com.intellij.modules.java 9 | org.jetbrains.kotlin 10 | org.intellij.groovy 11 | com.intellij.gradle 12 | org.jetbrains.android 13 | com.intellij.modules.externalSystem 14 | 15 | 16 | 21 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 31 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/pluginIcon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/test/kotlin/br/com/devsrsouza/intellij/dropboxfocus/MyPluginTest.kt: -------------------------------------------------------------------------------- 1 | package br.com.devsrsouza.intellij.dropboxfocus 2 | 3 | import com.intellij.ide.highlighter.XmlFileType 4 | import com.intellij.psi.xml.XmlFile 5 | import com.intellij.testFramework.TestDataPath 6 | import com.intellij.testFramework.fixtures.BasePlatformTestCase 7 | import com.intellij.util.PsiErrorElementUtil 8 | 9 | @TestDataPath("\$CONTENT_ROOT/src/test/testData") 10 | class MyPluginTest : BasePlatformTestCase() { 11 | 12 | fun testXMLFile() { 13 | val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "bar") 14 | val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java) 15 | 16 | assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile)) 17 | 18 | assertNotNull(xmlFile.rootTag) 19 | 20 | xmlFile.rootTag?.let { 21 | assertEquals("foo", it.name) 22 | assertEquals("bar", it.value.text) 23 | } 24 | } 25 | 26 | override fun getTestDataPath() = "src/test/testData/rename" 27 | 28 | fun testRename() { 29 | myFixture.testRename("foo.xml", "foo_after.xml", "a2") 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/testData/rename/foo.xml: -------------------------------------------------------------------------------- 1 | 2 | 1>Foo 3 | 4 | -------------------------------------------------------------------------------- /src/test/testData/rename/foo_after.xml: -------------------------------------------------------------------------------- 1 | 2 | Foo 3 | 4 | --------------------------------------------------------------------------------