├── VERSION ├── settings.gradle ├── travis.enc ├── website └── images │ ├── dnd.gif │ ├── edit.gif │ ├── sort.png │ ├── dndxml.gif │ ├── filter.png │ ├── normal.png │ ├── search.png │ ├── no_filter.png │ ├── no_sort.png │ ├── right_click.png │ └── search_color_code.png ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── kotlinc.xml ├── gradle.xml ├── modules.xml ├── modules │ ├── color-manager.iml │ ├── color-manager_main.iml │ └── color-manager_test.iml ├── runConfigurations │ ├── Android_Color_Manager__buildPlugin_.xml │ └── Android_Color_Manager__runIdea_.xml ├── compiler.xml ├── misc.xml └── uiDesigner.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── src └── main │ ├── kotlin │ └── com │ │ └── github │ │ └── shiraji │ │ └── colormanager │ │ ├── view │ │ ├── ColorManagerToolWindowCell.java │ │ ├── ColorManagerToolWindow.kt │ │ ├── ColorManagerToolWindowCell.form │ │ └── ColorManagerToolWindowPanel.kt │ │ └── data │ │ ├── ColorManagerCell.kt │ │ └── ColorManagerColorTag.kt │ └── resources │ └── META-INF │ └── plugin.xml ├── .travis ├── before_install.sh └── after_success.sh ├── RELEASING.md ├── .travis.yml ├── CHANGELOG.md ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /VERSION: -------------------------------------------------------------------------------- 1 | 1.1.7-SNAPSHOT 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'color-manager' 2 | 3 | -------------------------------------------------------------------------------- /travis.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/travis.enc -------------------------------------------------------------------------------- /website/images/dnd.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/dnd.gif -------------------------------------------------------------------------------- /website/images/edit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/edit.gif -------------------------------------------------------------------------------- /website/images/sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/sort.png -------------------------------------------------------------------------------- /website/images/dndxml.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/dndxml.gif -------------------------------------------------------------------------------- /website/images/filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/filter.png -------------------------------------------------------------------------------- /website/images/normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/normal.png -------------------------------------------------------------------------------- /website/images/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/search.png -------------------------------------------------------------------------------- /website/images/no_filter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/no_filter.png -------------------------------------------------------------------------------- /website/images/no_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/no_sort.png -------------------------------------------------------------------------------- /website/images/right_click.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/right_click.png -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /website/images/search_color_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shiraji/color-manager/HEAD/website/images/search_color_code.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | /.idea/dictionaries 6 | .DS_Store 7 | /build -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Aug 27 20:59:52 JST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip 7 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/shiraji/colormanager/view/ColorManagerToolWindowCell.java: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.colormanager.view; 2 | 3 | import javax.swing.*; 4 | 5 | public class ColorManagerToolWindowCell { 6 | JPanel rootPanel; 7 | JLabel colorCodeLabel; 8 | JLabel fileNameLabel; 9 | JLabel colorNameLabel; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/shiraji/colormanager/data/ColorManagerCell.kt: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.colormanager.data 2 | 3 | data class ColorManagerCell(val colorName: String, val colorCode: String) { 4 | 5 | companion object { 6 | const val SEPARATOR = ":::" 7 | } 8 | 9 | override fun toString(): String { 10 | return "$colorName$SEPARATOR$colorCode" 11 | } 12 | } -------------------------------------------------------------------------------- /.travis/before_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 6 | # Check how to run this script 7 | echo "It's pull request!" 8 | else 9 | # add Github ssh setting 10 | openssl aes-256-cbc -K $encrypted_db8923e9d877_key -iv $encrypted_db8923e9d877_iv -in travis.enc -out .travis.ssh -d 11 | chmod 600 .travis.ssh 12 | echo -e "Host github.com\n\tStrictHostKeyChecking no\nIdentityFile .travis.ssh\n" >> ~/.ssh/config 13 | fi -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/shiraji/colormanager/data/ColorManagerColorTag.kt: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.colormanager.data 2 | 3 | import com.intellij.psi.xml.XmlTag 4 | import java.awt.Color 5 | 6 | data class ColorManagerColorTag(val tag: XmlTag, 7 | var color: Color? = null, 8 | var colorCode: String? = null, 9 | var errorMessage: String? = null, 10 | val fileName: String, 11 | val isInProject: Boolean, 12 | val isInAndroidSdk: Boolean) -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | * `./gradlew prepareForRelease` (In case stop releasing after running this command, make sure removing `.travis/release`) 2 | * Add CHANGELOG.md to what changes for new version 3 | * Add plugin.xml change note 4 | ```xml 5 | 1.0.1

7 | 11 | ]]> 12 |
13 | ``` 14 | * Commit & push changes 15 | * Check [travis ci](https://travis-ci.org/shiraji/color-manager) to successfully release the module 16 | * Create Release Tag (Upload archive file as well) 17 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/shiraji/colormanager/view/ColorManagerToolWindow.kt: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.colormanager.view 2 | 3 | import com.intellij.openapi.project.Project 4 | import com.intellij.openapi.util.Disposer 5 | import com.intellij.openapi.wm.ToolWindow 6 | import com.intellij.openapi.wm.ToolWindowFactory 7 | 8 | class ColorManagerToolWindow : ToolWindowFactory { 9 | override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { 10 | val contentManager = toolWindow.contentManager 11 | val panel = ColorManagerToolWindowPanel(project) 12 | val content = contentManager.factory.createContent(panel, null, false) 13 | contentManager.addContent(content) 14 | Disposer.register(project, panel) 15 | } 16 | } -------------------------------------------------------------------------------- /.idea/modules/color-manager.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Android_Color_Manager__buildPlugin_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/runConfigurations/Android_Color_Manager__runIdea_.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | env: 3 | matrix: 4 | - IDEA_VERSION=LATEST-EAP-SNAPSHOT 5 | global: 6 | secure: R57DPuAx1cb+DGlmczdCQYxUl/R+uu3tpKaKmEexEn5Mq6e8nw/g4HhsX1/tlR6Jl1vrnh8C/RIcaSU3hTvWQ9N4y59/36LHL+w/v3lOVd9J8jBFxhthl5Oypj0LrcENgMJjT7BoRqBt60gTZ2T0DcWgBgiAMLLmJAVgGeU6RWVS92TNCe7rUkXRBo+pLGaFimjllpe7+qRuuyGO36vTgTGsPumAq2YY1Ep1wJiCXE8PACXfTMDMhDCdiQMdzI5Jz9Qp8JrNA/JBBy3wCHimZyIREpqXINmHbdmCRsPMlpYoc5dDGFFL1AbtV7wZ8zu+8vYucil2OY24a5i6rrM680rRNlcUIZOYAAZS5HIYbXs9nECVNW9RVswlPtu07c+2ZXVst0jTnLvdJba4Rf5HhQBEE4QxXHuZ/KQKQE5asgTttvBsmkKyAb6cGImidCSNkgafaJRy/S7qy++DFh8c16YcJlf5oj/hCmiMu2qlX8X+6YJOiEy94ZqiJdZxR6+6W4bzN+xJfmCYcv2M6o7ZVxQoYzqwer7DDmKsL9xiwHdpVqniRgUbxrET23ugcX1K+LgVieUepSa112Xa67aEgCmCQGFJ0Cj8Xd0QmDmivbXIXdSfFLgBQTbNuYCQawIbCmc/3q5KgNtfGllXaqu+9l1iSwedBP18Tgz9VutfJPQ= 7 | jdk: 8 | - oraclejdk8 9 | script: 10 | - ./gradlew test -PideaVersion=$IDEA_VERSION 11 | notifications: 12 | email: false 13 | cache: 14 | directories: 15 | - $HOME/.m2 16 | - $HOME/.gradle 17 | after_success: 18 | - .travis/after_success.sh 19 | before_install: 20 | - .travis/before_install.sh -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 1.8 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.travis/after_success.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Travis ci script for releasing gradle project 4 | # Adapted from http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ 5 | 6 | # Change this 7 | REPO="color-manager" 8 | 9 | # Change if necessary 10 | USER="shiraji" 11 | JDK="oraclejdk8" 12 | BRANCH="master" 13 | 14 | # Not handling errors 15 | set -e 16 | 17 | if [ "$TRAVIS_REPO_SLUG" != "$USER/$REPO" ]; then 18 | # Check repo 19 | echo "TRAVIS_REPO_SLUG: '$TRAVIS_REPO_SLUG' USER/REPO: '$USER/$REPO'" 20 | elif [ "$TRAVIS_JDK_VERSION" != "$JDK" ]; then 21 | # Check JDK 22 | echo "TRAVIS_JDK_VERSION: '$TRAVIS_JDK_VERSION' JDK: '$JDK" 23 | elif [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 24 | # Check how to run this script 25 | echo "It's pull request!" 26 | elif [ "$TRAVIS_BRANCH" != "$BRANCH" ]; then 27 | # Check branch 28 | echo "TRAVIS_BRANCH: '$TRAVIS_BRANCH' BRANCH: '$BRANCH'" 29 | elif [ "$IDEA_VERSION" != "LATEST-EAP-SNAPSHOT" ]; then 30 | # Check IDEA version 31 | echo "IDEA_VERSION: '$IDEA_VERSION'" 32 | else 33 | # Without snapshot 34 | if [ -f .travis/release ]; then 35 | echo "Start releasing..." 36 | ./gradlew publishPlugin 37 | git checkout master 38 | git config user.name "Travis CI" 39 | git config user.email "isogai.shiraji@gmail.com" 40 | git tag `cat VERSION` 41 | git push git@github.com:${USER}/${REPO}.git `cat VERSION` 42 | git rm .travis/release 43 | ./gradlew prepareForNextDevelopment 44 | git add VERSION 45 | git commit -m "[skip ci] prepare next development" 46 | git push git@github.com:${USER}/${REPO}.git $BRANCH 47 | else 48 | echo "No .travis/release file" 49 | fi 50 | fi 51 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ### [ver 1.1.6](https://github.com/shiraji/color-manager/releases/tag/1.1.6) 2 | 3 | * Support finding color by color code #40 4 | 5 | ### [ver 1.1.5](https://github.com/shiraji/color-manager/releases/tag/1.1.5) 6 | 7 | * Color file name #43 8 | 9 | ### [ver 1.1.4](https://github.com/shiraji/color-manager/releases/tag/1.1.4) 10 | 11 | * Change label color to white or black according to darkness of the background #41 12 | 13 | ### [ver 1.1.3](https://github.com/shiraji/color-manager/releases/tag/1.1.3) 14 | 15 | * Fix java.lang.ArrayIndexOutOfBoundsException: -1 #38 16 | 17 | ### [ver 1.1.2](https://github.com/shiraji/color-manager/releases/tag/1.1.2) 18 | 19 | * Support editing color code #2 #34 20 | 21 | ### [ver 1.1.1](https://github.com/shiraji/color-manager/releases/tag/1.1.1) 22 | 23 | * Support deleting color #6 24 | 25 | ### [ver 1.1.0](https://github.com/shiraji/color-manager/releases/tag/1.1.0) 26 | 27 | * Support Drag and Drop #11 28 | 29 | ### [ver 1.0.5](https://github.com/shiraji/color-manager/releases/tag/1.0.5) 30 | 31 | * Add copy as "@color/white" #29 32 | 33 | ### [ver 1.0.4](https://github.com/shiraji/color-manager/releases/tag/1.0.4) 34 | 35 | * Support double click to navigate #26 36 | 37 | ### [ver 1.0.3](https://github.com/shiraji/color-manager/releases/tag/1.0.3) 38 | 39 | * Support sorting #16 40 | * Change rendering #17 #20 41 | 42 | ### [ver 1.0.2](https://github.com/shiraji/color-manager/releases/tag/1.0.2) 43 | 44 | * Show loading #13 45 | * Support other color format #9 46 | 47 | ### [ver 1.0.1](https://github.com/shiraji/color-manager/releases/tag/1.0.1) 48 | 49 | * Support files are not colors.xml #3 50 | * Support filtering feature #10 51 | 52 | ### [ver 1.0.0](https://github.com/shiraji/color-manager/releases/tag/1.0.0) 53 | 54 | * Initial release 55 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/shiraji/colormanager/view/ColorManagerToolWindowCell.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Color Manager 2 | 3 | The Intellij plugin that manages Android colors. It makes easy to browse colors. 4 | 5 | # How to use 6 | 7 | Open "Color Manager" tool window. You will see all colors listed 8 | 9 | ![normal](website/images/normal.png) 10 | 11 | ## Drag and Drop 12 | 13 | From v1.1.0, this plugin support drag and drop feature. 14 | 15 | * Select a file where you want to drop 16 | * Drag the color panel 17 | * Drop where you want to copy the color name/tag 18 | 19 | If the selected file is not xml file, then the drop text format is `R.color.color_name` 20 | 21 | ![dnd](website/images/dnd.gif) 22 | 23 | If the selected file is xml, then the drop text format is `@color/color_name` 24 | 25 | ![dndxml](website/images/dndxml.gif) 26 | 27 | At this moment, there is no way to detect drop target file's type. So, if you select a xml file and drop text to a Java file, this plugin pastes `@color/color_name` not `R.color.color_name` 28 | 29 | ## Copy 30 | 31 | Right click a color listed on the tool window 32 | 33 | ![right_click](website/images/right_click.png) 34 | 35 | Click "Copy R.color.whatever_color_name" or "Copy @color/whatever_color_name" 36 | 37 | You can also copy color name ("R.color.whatever_color_name" style) by cmd+c (or ctrl+c) after selecting the color panel 38 | 39 | ## Move to the color definition 40 | 41 | Same as Copy. Right click and click "Go to R.color.whatever_color_name" 42 | 43 | Or just double click an item 44 | 45 | ## Edit the color code 46 | 47 | Click "Edit R.color.whatever_color_name" and choose new color 48 | 49 | ![edit](website/images/edit.gif) 50 | 51 | ## Delete a color 52 | 53 | Same as Copy and move. Right click and click "Delete R.color.whatever_color_name" 54 | 55 | It will show confirmation dialog before deleting the color tag. 56 | 57 | ## Search 58 | 59 | Just start typing after focusing tool window 60 | 61 | ![search](website/images/search.png) 62 | 63 | The plugin let it finds them by typing a color name and a color code. 64 | 65 | ![search_color_code](website/images/search_color_code.png) 66 | 67 | ## Show all colors 68 | 69 | As default, this plugin filter library's color because there are a lot. 70 | 71 | ![filter](website/images/filter.png) 72 | 73 | You can un-filter those by clicking "Filter" icon (It takes a few second to show all colors) 74 | 75 | ![no_filter](website/images/no_filter.png) 76 | 77 | ## Sort by color name 78 | 79 | You can sort by color name by clicking sort icon 80 | 81 | ![no_sort](website/images/no_sort.png) 82 | 83 | ![sort](website/images/sort.png) 84 | 85 | # How to install? 86 | 87 | Use the IDE's plugin manager to install the latest version of the plugin. 88 | 89 | # LICENSE 90 | 91 | ``` 92 | Copyright 2016 Yoshinori Isogai 93 | 94 | Licensed under the Apache License, Version 2.0 (the "License"); 95 | you may not use this file except in compliance with the License. 96 | You may obtain a copy of the License at 97 | 98 | http://www.apache.org/licenses/LICENSE-2.0 99 | 100 | Unless required by applicable law or agreed to in writing, software 101 | distributed under the License is distributed on an "AS IS" BASIS, 102 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 103 | See the License for the specific language governing permissions and 104 | limitations under the License. 105 | ``` 106 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | com.github.shiraji.colormanager 3 | Android Color Manager 4 | 1.0.1 5 | Shiraji 6 | 7 | The plugin that manages Android colors. This plugin create a tool windows.

9 |

Open "Color Manager" tool window. You will see all colors listed

10 |

normal

11 |

Drag and Drop

12 |

From v1.1.0, this plugin support drag and drop feature.

13 |
    14 |
  • Select a file where you want to drop
  • 15 |
  • Drag the color panel
  • 16 |
  • Drop where you want to copy the color name/tag
  • 17 |
18 |

If the selected file is not xml file, then the drop text format is R.color.color_name

19 |

dnd

20 |

If the selected file is xml, then the drop text format is @color/color_name

21 |

dndxml

22 |

At this moment, there is no way to detect drop target file's type. So, if you select a xml file and drop text to a Java file, this plugin pastes @color/color_name not R.color.color_name

23 |

Copy

24 |

Right click a color listed on the tool window

25 |

right_click

26 |

Click "Copy R.color.whatever_color_name" or "Copy @color/whatever_color_name"

27 |

You can also copy color name ("R.color.whatever_color_name" style) by cmd+c (or ctrl+c) after selecting the color panel

28 |

Move to the color definition

29 |

Same as Copy. Right click and click "Go to R.color.whatever_color_name"

30 |

Or just double click an item

31 |

Edit the color code

32 |

Click "Edit R.color.whatever_color_name" and choose new color

33 |

edit

34 |

Delete a color

35 |

Same as Copy and move. Right click and click "Delete R.color.whatever_color_name"

36 |

It will show confirmation dialog before deleting the color tag.

37 | 38 |

Just start typing after focusing tool window

39 |

search

40 |

Show all colors

41 |

As default, this plugin filter library's color because there are a lot.

42 |

filter

43 |

You can un-filter those by clicking "Filter" icon (It takes a few second to show all colors)

44 |

no_filter

45 |

Sort by color name

46 |

You can sort by color name by clicking sort icon

47 |

no_sort

48 |

sort

49 | 50 | ]]>
51 | 52 | 1.1.6

54 |
    55 |
  • Support finding color by color code #40
  • 56 |
57 |

Older version changes are listed on CHANGELOG.md

58 | ]]> 59 |
60 | 61 | 62 | 63 | 64 | 66 | 69 | 70 | 71 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | -------------------------------------------------------------------------------- /src/main/kotlin/com/github/shiraji/colormanager/view/ColorManagerToolWindowPanel.kt: -------------------------------------------------------------------------------- 1 | package com.github.shiraji.colormanager.view 2 | 3 | import com.github.shiraji.colormanager.data.ColorManagerCell 4 | import com.github.shiraji.colormanager.data.ColorManagerColorTag 5 | import com.intellij.icons.AllIcons 6 | import com.intellij.ide.dnd.DnDDragStartBean 7 | import com.intellij.ide.dnd.DnDImage 8 | import com.intellij.ide.dnd.DnDSupport 9 | import com.intellij.ide.highlighter.XmlFileType 10 | import com.intellij.openapi.Disposable 11 | import com.intellij.openapi.actionSystem.* 12 | import com.intellij.openapi.application.ApplicationManager 13 | import com.intellij.openapi.command.CommandProcessor 14 | import com.intellij.openapi.fileEditor.FileDocumentManager 15 | import com.intellij.openapi.fileEditor.FileEditorManager 16 | import com.intellij.openapi.ide.CopyPasteManager 17 | import com.intellij.openapi.project.Project 18 | import com.intellij.openapi.ui.SimpleToolWindowPanel 19 | import com.intellij.openapi.vfs.VirtualFile 20 | import com.intellij.psi.PsiManager 21 | import com.intellij.psi.impl.source.xml.XmlTagImpl 22 | import com.intellij.psi.search.FileTypeIndex 23 | import com.intellij.psi.search.ProjectScope 24 | import com.intellij.psi.xml.XmlFile 25 | import com.intellij.ui.ColorChooser 26 | import com.intellij.ui.ListSpeedSearch 27 | import com.intellij.ui.ScrollPaneFactory 28 | import com.intellij.ui.components.JBList 29 | import com.intellij.util.Alarm 30 | import com.intellij.util.ui.JBUI 31 | import com.intellij.util.ui.TextTransferable 32 | import com.intellij.util.ui.UIUtil 33 | import sun.swing.DefaultLookup 34 | import java.awt.* 35 | import java.awt.datatransfer.StringSelection 36 | import java.awt.event.MouseAdapter 37 | import java.awt.event.MouseEvent 38 | import java.awt.image.BufferedImage 39 | import javax.swing.* 40 | 41 | class ColorManagerToolWindowPanel(val project: Project) : SimpleToolWindowPanel(true, true), DataProvider, Disposable { 42 | 43 | val listModel: DefaultListModel = DefaultListModel() 44 | 45 | val colorMap: MutableMap = linkedMapOf() 46 | 47 | val FILTER_XML = listOf("AndroidManifest.xml", "strings.xml", "dimens.xml", "base_strings.xml", "pom.xml", "donottranslate-cldr.xml", "donottranslate-maps.xml", "common_strings.xml") 48 | 49 | var filterLibRes = true 50 | 51 | private val alarm = Alarm(Alarm.ThreadToUse.SHARED_THREAD) 52 | 53 | private val androidSdkPathRegex = Regex("platforms/android-\\d\\d*/data/res") 54 | 55 | var sortAsc = false 56 | 57 | init { 58 | setToolbar(createToolbarPanel()) 59 | setContent(createContentPanel()) 60 | } 61 | 62 | private fun createContentPanel(): JComponent { 63 | refreshListModel() 64 | val list = JBList(listModel) 65 | list.cellRenderer = object : DefaultListCellRenderer() { 66 | override fun getListCellRendererComponent(list: JList<*>?, value: Any?, index: Int, isSelected: Boolean, cellHasFocus: Boolean): Component { 67 | val cell = ColorManagerToolWindowCell() 68 | val element = list?.model?.getElementAt(index) as? ColorManagerCell ?: return cell.rootPanel 69 | val colorName = element.colorName 70 | cell.colorNameLabel.text = colorName 71 | setColor(cell, colorName) 72 | cell.rootPanel.border = 73 | if (cellHasFocus || isSelected) 74 | DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder") ?: DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder") 75 | else 76 | DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder") 77 | return cell.rootPanel 78 | } 79 | 80 | private fun setColor(cell: ColorManagerToolWindowCell, colorName: String) { 81 | val colorManagerColorTag = colorMap[colorName] 82 | if (colorManagerColorTag == null) { 83 | cell.colorCodeLabel.text = "$colorName not found" 84 | return 85 | } 86 | setFileName(cell, colorManagerColorTag) 87 | setBackgroundAndColorCode(cell, colorManagerColorTag) 88 | } 89 | 90 | private fun setBackgroundAndColorCode(cell: ColorManagerToolWindowCell, colorManagerColorTag: ColorManagerColorTag) { 91 | val backgroundColor = colorManagerColorTag.color 92 | if (backgroundColor == null) { 93 | cell.rootPanel.background = Color.WHITE 94 | cell.colorCodeLabel.text = colorManagerColorTag.errorMessage ?: "'${colorManagerColorTag.tag.value.trimmedText}' not found" 95 | } else { 96 | cell.rootPanel.background = backgroundColor 97 | cell.colorCodeLabel.text = colorManagerColorTag.colorCode ?: "???" 98 | val foregroundColor = if (isColorDark(backgroundColor)) Color.WHITE else Color.BLACK 99 | cell.colorNameLabel.foreground = foregroundColor 100 | cell.colorCodeLabel.foreground = foregroundColor 101 | cell.fileNameLabel.foreground = foregroundColor 102 | } 103 | } 104 | 105 | // luma is calculated with the formula Y′ = 0.299 R′ + 0.587 G′ + 0.114 B′. 106 | // https://en.wikipedia.org/wiki/Luma_%28video%29 107 | private fun isColorDark(color: Color) = 1 - ( 0.299 * color.red + 0.587 * color.green + 0.114 * color.blue) / 255 >= 0.5 108 | 109 | private fun setFileName(cell: ColorManagerToolWindowCell, colorManagerColorTag: ColorManagerColorTag) { 110 | val fileName = colorManagerColorTag.fileName 111 | cell.fileNameLabel.text = if (colorManagerColorTag.isInProject) fileName else "$fileName (in library)" 112 | } 113 | } 114 | // Google recommended height!!! 115 | list.fixedCellHeight = 48 116 | ListSpeedSearch(list) 117 | 118 | list.addMouseListener(object : MouseAdapter() { 119 | override fun mouseClicked(e: MouseEvent?) { 120 | super.mouseClicked(e) 121 | e ?: return 122 | if (list.isEmpty || listModel.isEmpty || colorMap.isEmpty()) return 123 | 124 | if (list.minSelectionIndex < 0 || listModel.size() < list.minSelectionIndex) return 125 | 126 | if (SwingUtilities.isRightMouseButton(e)) { 127 | handleRightClick(e) 128 | } else if (SwingUtilities.isLeftMouseButton(e) && e.clickCount == 2) { 129 | handleDoubleClick() 130 | } 131 | } 132 | 133 | private fun handleDoubleClick() { 134 | val selectedColor = listModel.get(list.minSelectionIndex).colorName 135 | (colorMap[selectedColor]?.tag as? XmlTagImpl)?.navigate(true) ?: return 136 | } 137 | 138 | private fun handleRightClick(e: MouseEvent) { 139 | val selectedColor = listModel.get(list.minSelectionIndex).colorName 140 | val copyMenu = JMenuItem("Copy $selectedColor").apply { 141 | addActionListener { 142 | CopyPasteManager.getInstance().setContents(TextTransferable(selectedColor)) 143 | } 144 | } 145 | 146 | val colorInfo = colorMap[selectedColor] ?: return 147 | val tag = colorInfo.tag 148 | val nameForXml = "${getXmlColorPrefix(colorInfo.isInAndroidSdk)}/${tag.getAttribute("name")?.value}" 149 | val copyMenuForXml = JMenuItem("Copy $nameForXml").apply { 150 | addActionListener { 151 | CopyPasteManager.getInstance().setContents(TextTransferable(nameForXml)) 152 | } 153 | } 154 | 155 | val gotoMenu = JMenuItem("Go to $selectedColor").apply { 156 | addActionListener { 157 | colorInfo.let { 158 | (it.tag as? XmlTagImpl)?.navigate(true) 159 | } 160 | } 161 | } 162 | 163 | val deleteMenu = JMenuItem("Delete $selectedColor").apply { 164 | addActionListener { 165 | val result = JOptionPane.showConfirmDialog(this@ColorManagerToolWindowPanel, 166 | "Delete $selectedColor?", 167 | "Delete Confirmation", 168 | JOptionPane.OK_CANCEL_OPTION, 169 | JOptionPane.QUESTION_MESSAGE) 170 | if (result != JOptionPane.YES_OPTION) return@addActionListener 171 | 172 | CommandProcessor.getInstance().executeCommand(project, { 173 | ApplicationManager.getApplication().runWriteAction { 174 | colorInfo.tag.delete() 175 | refreshListModel() 176 | } 177 | }, "Delete color", null) 178 | } 179 | } 180 | 181 | val editMenu = JMenuItem("Edit $selectedColor").apply { 182 | addActionListener { 183 | val newColor = ColorChooser.chooseColor(this@ColorManagerToolWindowPanel, "Edit Color", colorInfo.color, true) ?: return@addActionListener 184 | CommandProcessor.getInstance().executeCommand(project, { 185 | ApplicationManager.getApplication().runWriteAction { 186 | val alpha = newColor.alpha 187 | val colorCode = if (alpha != 255) 188 | "#%02X%02X%02X%02X".format(alpha, newColor.red, newColor.green, newColor.blue) 189 | else 190 | "#%02X%02X%02X".format(newColor.red, newColor.green, newColor.blue) 191 | colorInfo.tag.value.text = colorCode 192 | } 193 | refreshListModel() 194 | }, "Edit color", null) 195 | } 196 | } 197 | 198 | JPopupMenu().run { 199 | add(copyMenu) 200 | add(copyMenuForXml) 201 | add(gotoMenu) 202 | if (colorInfo.isInProject) { 203 | add(editMenu) 204 | add(deleteMenu) 205 | } 206 | show(e.component, e.x, e.y) 207 | } 208 | } 209 | }) 210 | 211 | installDnDAction(list) 212 | return ScrollPaneFactory.createScrollPane(list) 213 | } 214 | 215 | private fun installDnDAction(list: JBList) { 216 | DnDSupport.createBuilder(list).setBeanProvider { info -> 217 | if (list.minSelectionIndex < 0 || listModel.size() < list.minSelectionIndex) return@setBeanProvider null 218 | val file = getSelectedFile() ?: return@setBeanProvider null 219 | if (info.isMove) { 220 | if (file.fileType == XmlFileType.INSTANCE) { 221 | DnDDragStartBean(StringSelection(getNameForXml(list))) 222 | } else { 223 | DnDDragStartBean(StringSelection(listModel.get(list.minSelectionIndex).colorName)) 224 | } 225 | } else { 226 | null 227 | } 228 | }.setImageProvider { 229 | if (list.minSelectionIndex < 0 || listModel.size() < list.minSelectionIndex) return@setImageProvider null 230 | val file = getSelectedFile() ?: return@setImageProvider null 231 | val label = 232 | if (file.fileType == XmlFileType.INSTANCE) { 233 | JLabel(getNameForXml(list)) 234 | } else { 235 | JLabel(listModel.get(list.minSelectionIndex).colorName) 236 | } 237 | label.isOpaque = true 238 | label.size = label.preferredSize 239 | val image = UIUtil.createImage(label.width, label.height, BufferedImage.TYPE_INT_ARGB) 240 | val g2 = image.graphics as Graphics2D 241 | g2.composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f) 242 | label.paint(g2) 243 | g2.dispose() 244 | DnDImage(image, Point(-image.getWidth(null), -image.getHeight(null))) 245 | }.setDisposableParent(this).install() 246 | } 247 | 248 | private fun getNameForXml(list: JBList): String? { 249 | val selectedColor = listModel.get(list.minSelectionIndex).colorName 250 | val colorInfo = colorMap[selectedColor] ?: return null 251 | val tag = colorInfo.tag 252 | return "${getXmlColorPrefix(colorInfo.isInAndroidSdk)}/${tag.getAttribute("name")?.value}" 253 | } 254 | 255 | private fun getSelectedFile(): VirtualFile? { 256 | val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return null 257 | return FileDocumentManager.getInstance().getFile(editor.document) 258 | } 259 | 260 | private fun getXmlColorPrefix(isInAndroidSdk: Boolean): String { 261 | return if (isInAndroidSdk) "@android:color" else "@color" 262 | } 263 | 264 | private fun createToolbarPanel(): JComponent? { 265 | val group = DefaultActionGroup() 266 | group.add(RefreshAction()) 267 | group.add(FilterAction()) 268 | group.add(SortAscAction()) 269 | val actionToolBar = ActionManager.getInstance().createActionToolbar("ColorManager", group, true) 270 | return JBUI.Panels.simplePanel(actionToolBar.component) 271 | } 272 | 273 | override fun dispose() { 274 | } 275 | 276 | private fun initColorMap() { 277 | val psiManager = PsiManager.getInstance(project) 278 | 279 | FileTypeIndex.getFiles(XmlFileType.INSTANCE, ProjectScope.getProjectScope(project)).forEach { 280 | addToColorMap(psiManager, it, true, false) 281 | } 282 | 283 | if (!filterLibRes) { 284 | FileTypeIndex.getFiles(XmlFileType.INSTANCE, ProjectScope.getLibrariesScope(project)).forEach { 285 | addToColorMap(psiManager, it, isInProject = false, isInAndroidSdk = it.path.contains(androidSdkPathRegex)) 286 | } 287 | } 288 | 289 | generateColors() 290 | } 291 | 292 | private fun generateColors() { 293 | val colorTextList = mutableListOf() 294 | colorMap.keys.forEach { 295 | colorTextList.clear() 296 | val colorTag = colorMap[it] ?: return@forEach 297 | generateColorFromKey(colorTextList, colorTag, it) 298 | } 299 | } 300 | 301 | private fun generateColorFromKey(colorTextList: MutableList, target: ColorManagerColorTag, colorName: String) { 302 | val colorTag = colorMap[colorName] ?: return 303 | val colorText = colorTag.tag.value.trimmedText 304 | if (colorTextList.contains(colorText)) { 305 | target.errorMessage = "Loop detected..." 306 | return 307 | } 308 | colorTextList.add(colorText) 309 | if (colorText.startsWith("@android:color/")) { 310 | generateColorFromKey(colorTextList, target, "R.color.${colorText.replace("@android:color/", "")}") 311 | } else if (colorText.startsWith("@color/")) { 312 | generateColorFromKey(colorTextList, target, "R.color.${colorText.replace("@color/", "")}") 313 | } else if (colorText.startsWith("#")) { 314 | target.colorCode = colorText 315 | target.color = when (colorText.length) { 316 | 4 -> Color.decode("#${colorText[1]}${colorText[1]}${colorText[2]}${colorText[2]}${colorText[3]}${colorText[3]}") 317 | 7 -> Color.decode(colorText) 318 | 9 -> Color(java.lang.Long.decode(colorText).toInt(), true) 319 | else -> { 320 | target.errorMessage = "Invalid color code: $colorText" 321 | null 322 | } 323 | } 324 | } else { 325 | target.errorMessage = "Invalid format: $colorText" 326 | } 327 | } 328 | 329 | private fun addToColorMap(psiManager: PsiManager, virtualFile: VirtualFile, isInProject: Boolean, isInAndroidSdk: Boolean) { 330 | if (FILTER_XML.contains(virtualFile.name)) return 331 | val xmlFile = psiManager.findFile(virtualFile) as? XmlFile ?: return 332 | xmlFile.rootTag?.findSubTags("color")?.forEach { 333 | colorMap.put("R.color.${it.getAttribute("name")?.value}", 334 | ColorManagerColorTag( 335 | tag = it, 336 | fileName = virtualFile.name, 337 | isInProject = isInProject, 338 | isInAndroidSdk = isInAndroidSdk)) 339 | } 340 | } 341 | 342 | private fun refreshListModel() { 343 | try { 344 | setWaitCursor() 345 | resetColorMap() 346 | reloadListModel() 347 | } finally { 348 | restoreCursor() 349 | } 350 | } 351 | 352 | private fun resetColorMap() { 353 | colorMap.clear() 354 | initColorMap() 355 | } 356 | 357 | private fun reloadListModel() { 358 | listModel.removeAllElements() 359 | val keys = if (sortAsc) colorMap.keys.sorted() else colorMap.keys 360 | keys.forEach { 361 | val element = ColorManagerCell(it, colorMap[it]?.colorCode ?: "") 362 | listModel.addElement(element) 363 | } 364 | } 365 | 366 | private fun restoreCursor() { 367 | alarm.cancelAllRequests() 368 | cursor = Cursor.getDefaultCursor() 369 | } 370 | 371 | private fun setWaitCursor() { 372 | alarm.addRequest({ cursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR) }, 100) 373 | } 374 | 375 | inner class RefreshAction() : AnAction("Reload colors", "Reload colors", AllIcons.Actions.Refresh) { 376 | override fun actionPerformed(e: AnActionEvent?) { 377 | ApplicationManager.getApplication().invokeLater { 378 | refreshListModel() 379 | } 380 | } 381 | } 382 | 383 | inner class FilterAction() : ToggleAction("Filter library resource colors", "Filter library resource colors", AllIcons.General.Filter) { 384 | 385 | override fun isSelected(e: AnActionEvent?) = filterLibRes 386 | 387 | override fun setSelected(e: AnActionEvent?, state: Boolean) { 388 | filterLibRes = state 389 | refreshListModel() 390 | } 391 | } 392 | 393 | inner class SortAscAction() : ToggleAction("Sort alphabetically", "Sort alphabetically", AllIcons.ObjectBrowser.Sorted) { 394 | override fun isSelected(e: AnActionEvent?) = sortAsc 395 | 396 | override fun setSelected(e: AnActionEvent?, state: Boolean) { 397 | sortAsc = state 398 | reloadListModel() 399 | } 400 | } 401 | } 402 | -------------------------------------------------------------------------------- /.idea/modules/color-manager_main.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /.idea/modules/color-manager_test.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | --------------------------------------------------------------------------------