From f4ea510ec6d4e32fd8432f782949410b3d255d92 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Mon, 20 Feb 2017 21:11:16 -0800 Subject: [PATCH 01/12] bump plugin version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7209087..33327f7 100644 --- a/build.gradle +++ b/build.gradle @@ -31,4 +31,4 @@ publishPlugin { } group 'net.olegg' -version '0.0.2' +version '0.0.3-SNAPSHOT' From e4b2bcd23d904c2c69cca8fc4a818e28f992228a Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Mon, 20 Feb 2017 21:14:19 -0800 Subject: [PATCH 02/12] update gradle to 3.4 --- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1ba7af9..2feeef9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Feb 11 19:35:25 PST 2017 +#Mon Feb 20 21:13:56 PST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip From 74cc64664d84f9aa0786b49c45e95da1bd1dd539 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Mon, 20 Feb 2017 23:51:58 -0800 Subject: [PATCH 03/12] restrict load to json files --- .../olegg/bodylookin/toolwindow/BodylookinView.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt b/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt index a73758b..8e33181 100644 --- a/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt +++ b/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt @@ -1,5 +1,6 @@ package net.olegg.bodylookin.toolwindow +import com.intellij.json.JsonFileType import com.intellij.openapi.actionSystem.* import com.intellij.openapi.fileEditor.FileEditorManager import com.intellij.openapi.ui.SimpleToolWindowPanel @@ -29,7 +30,15 @@ class BodylookinView : SimpleToolWindowPanel(true) { val project = e?.project ?: return val json = FileEditorManager.getInstance(project).selectedTextEditor?.document?.text if (json != null) { - loadAnimation(json) + loadJson(json) + } + } + + override fun update(e: AnActionEvent?) { + e?.presentation?.isEnabled = let { + val project = e?.project ?: return@let false + val file = FileEditorManager.getInstance(project).selectedFiles.getOrNull(0) + return@let file?.fileType == JsonFileType.INSTANCE } } } @@ -105,7 +114,7 @@ class BodylookinView : SimpleToolWindowPanel(true) { } } - fun loadAnimation(source: String) { + fun loadJson(source: String) { Platform.runLater { val script = """ bodymovin.destroy(); From 7a55ffc319bce7ef4b2a7717575ebd8110808ee7 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Mon, 20 Feb 2017 23:52:48 -0800 Subject: [PATCH 04/12] cleanup html wrapper --- src/main/resources/bodylookin.html | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/resources/bodylookin.html b/src/main/resources/bodylookin.html index 39d514f..7c95d41 100644 --- a/src/main/resources/bodylookin.html +++ b/src/main/resources/bodylookin.html @@ -4,17 +4,5 @@
- - \ No newline at end of file From a36e6715fd2fe3a5aabead2482554a2c5fce4c1e Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 00:15:54 -0800 Subject: [PATCH 05/12] add file loading --- .../bodylookin/toolwindow/BodylookinView.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt b/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt index 8e33181..f3bb8c3 100644 --- a/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt +++ b/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt @@ -2,8 +2,13 @@ package net.olegg.bodylookin.toolwindow import com.intellij.json.JsonFileType import com.intellij.openapi.actionSystem.* +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory +import com.intellij.openapi.fileChooser.FileChooserFactory import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.fileEditor.impl.LoadTextUtil import com.intellij.openapi.ui.SimpleToolWindowPanel +import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.ui.JBUI import javafx.application.Platform import javafx.concurrent.Worker @@ -43,6 +48,16 @@ class BodylookinView : SimpleToolWindowPanel(true) { } } + val openAction: AnAction = object : AnAction("Load file", "", Icons.OPEN) { + override fun actionPerformed(e: AnActionEvent?) { + val descriptor = FileChooserDescriptorFactory.createSingleFileDescriptor(JsonFileType.INSTANCE) + val file = FileChooserFactory.getInstance().createFileChooser(descriptor, null, null).choose(null).getOrNull(0) + if (file != null) { + loadFile(file) + } + } + } + val playAction: AnAction = object : AnAction("Play", "", Icons.PLAY) { override fun actionPerformed(e: AnActionEvent?) { Platform.runLater { @@ -93,6 +108,7 @@ class BodylookinView : SimpleToolWindowPanel(true) { val group = DefaultActionGroup() group.addAll(listOf( lookAction, + openAction, Separator(), playAction, pauseAction, @@ -137,4 +153,11 @@ class BodylookinView : SimpleToolWindowPanel(true) { } } } + + fun loadFile(file: VirtualFile) { + ApplicationManager.getApplication().runReadAction { + val json = LoadTextUtil.loadText(file).toString() + loadJson(json) + } + } } \ No newline at end of file From dc3318bc2bc5859038f502de49d6913b3771655e Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 00:28:42 -0800 Subject: [PATCH 06/12] restore LoadAction --- .../kotlin/net/olegg/bodylookin/Constants.kt | 9 +++++ .../net/olegg/bodylookin/action/LoadAction.kt | 34 +++++++++++++++++++ src/main/resources/META-INF/plugin.xml | 11 ++++++ 3 files changed, 54 insertions(+) create mode 100644 src/main/kotlin/net/olegg/bodylookin/Constants.kt create mode 100644 src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt diff --git a/src/main/kotlin/net/olegg/bodylookin/Constants.kt b/src/main/kotlin/net/olegg/bodylookin/Constants.kt new file mode 100644 index 0000000..3d2c110 --- /dev/null +++ b/src/main/kotlin/net/olegg/bodylookin/Constants.kt @@ -0,0 +1,9 @@ +package net.olegg.bodylookin + +/** + * Created by olegg on 2/21/17. + */ +object Constants { + val ACTION_GROUP = "bodylookin.ActionGroup" + val TOOL_WINDOW_ID = "bodylookin" +} diff --git a/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt b/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt new file mode 100644 index 0000000..a1d816e --- /dev/null +++ b/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt @@ -0,0 +1,34 @@ +package net.olegg.bodylookin.action + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.wm.ToolWindowManager +import net.olegg.bodylookin.Constants +import net.olegg.bodylookin.toolwindow.BodylookinView + +/** + * Created by olegg on 2/21/17. + */ +class LoadAction: AnAction() { + override fun actionPerformed(event: AnActionEvent) { + val project = event.project ?: return + val editor = FileEditorManager.getInstance(project).selectedTextEditor + val toolWindowManager = ToolWindowManager.getInstance(project) + val toolWindow = toolWindowManager.getToolWindow(Constants.TOOL_WINDOW_ID) + val json = editor?.document?.text + if (toolWindow.isVisible) { + val content = toolWindow.contentManager.getContent(0)?.component as? BodylookinView ?: return + if (json != null) { + content.loadJson(json) + } + } else { + toolWindow.show { + val content = toolWindow.contentManager.getContent(0)?.component as? BodylookinView ?: return@show + if (json != null) { + content.loadJson(json) + } + } + } + } +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 92d9b31..fa972ec 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -40,4 +40,15 @@ factoryClass="net.olegg.bodylookin.toolwindow.BodylookinFactory" /> + + + + + + \ No newline at end of file From a3bf87af4fa1c070be26bc939b6983f1ca20929a Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 00:38:24 -0800 Subject: [PATCH 07/12] add action to context menu --- src/main/resources/META-INF/plugin.xml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index fa972ec..6fdb2c5 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -42,13 +42,16 @@ - - - + + + + + + - \ No newline at end of file + From 438328edb1117b963a4a55224333ed9d2f7c4805 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 01:06:12 -0800 Subject: [PATCH 08/12] simplify json checks --- src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt | 7 ++++++- .../net/olegg/bodylookin/toolwindow/BodylookinView.kt | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt b/src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt index c65bfbd..cef8241 100644 --- a/src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt +++ b/src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt @@ -1,6 +1,8 @@ package net.olegg.bodylookin +import com.intellij.json.JsonFileType import com.intellij.openapi.components.ApplicationComponent +import com.intellij.openapi.vfs.VirtualFile /** * Created by olegg on 2/15/17. @@ -21,4 +23,7 @@ class BodylookinPlugin : ApplicationComponent { override fun initComponent() { } override fun disposeComponent() { } -} \ No newline at end of file +} + +val VirtualFile?.isJson: Boolean + get() = (this?.fileType == JsonFileType.INSTANCE) \ No newline at end of file diff --git a/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt b/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt index f3bb8c3..beb6391 100644 --- a/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt +++ b/src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt @@ -17,6 +17,7 @@ import javafx.scene.Scene import javafx.scene.web.WebEngine import javafx.scene.web.WebView import net.olegg.bodylookin.Icons +import net.olegg.bodylookin.isJson import netscape.javascript.JSObject /** @@ -43,7 +44,7 @@ class BodylookinView : SimpleToolWindowPanel(true) { e?.presentation?.isEnabled = let { val project = e?.project ?: return@let false val file = FileEditorManager.getInstance(project).selectedFiles.getOrNull(0) - return@let file?.fileType == JsonFileType.INSTANCE + return@let file.isJson } } } From e9c72f288757d2053156d868b44fa28ca4c8a1b3 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 01:08:39 -0800 Subject: [PATCH 09/12] add load action --- .../net/olegg/bodylookin/action/LoadAction.kt | 41 +++++++++++++++---- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt b/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt index a1d816e..5bdb228 100644 --- a/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt +++ b/src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt @@ -2,33 +2,56 @@ package net.olegg.bodylookin.action import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.wm.ToolWindowManager import net.olegg.bodylookin.Constants +import net.olegg.bodylookin.isJson import net.olegg.bodylookin.toolwindow.BodylookinView /** * Created by olegg on 2/21/17. */ -class LoadAction: AnAction() { +class LoadAction : AnAction() { override fun actionPerformed(event: AnActionEvent) { - val project = event.project ?: return - val editor = FileEditorManager.getInstance(project).selectedTextEditor + val project = event.project + if (project == null || project.isDefault || project.isDisposed) { + return + } + + val doc = event.getData(CommonDataKeys.EDITOR)?.document + val file = event.getData(CommonDataKeys.VIRTUAL_FILE) val toolWindowManager = ToolWindowManager.getInstance(project) val toolWindow = toolWindowManager.getToolWindow(Constants.TOOL_WINDOW_ID) - val json = editor?.document?.text if (toolWindow.isVisible) { val content = toolWindow.contentManager.getContent(0)?.component as? BodylookinView ?: return - if (json != null) { - content.loadJson(json) + if (doc != null) { + content.loadJson(doc.text) + } else if (file != null) { + content.loadFile(file) } } else { toolWindow.show { val content = toolWindow.contentManager.getContent(0)?.component as? BodylookinView ?: return@show - if (json != null) { - content.loadJson(json) + if (doc != null) { + content.loadJson(doc.text) + } else if (file != null) { + content.loadFile(file) } } } } + + override fun update(e: AnActionEvent) { + val project = e.getData(CommonDataKeys.PROJECT) + if (project == null || project.isDefault || project.isDisposed) { + e.presentation.isEnabledAndVisible = false + return + } + val doc = e.getData(CommonDataKeys.EDITOR)?.document + val file = e.getData(CommonDataKeys.VIRTUAL_FILE) + + val docJson = doc != null && doc.textLength > 0 && FileDocumentManager.getInstance().getFile(doc).isJson + e.presentation.isEnabledAndVisible = file.isJson || docJson + } } From a3957fe516863ae135e9a355ed66a632077d80f5 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 01:17:45 -0800 Subject: [PATCH 10/12] bump version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 33327f7..5684382 100644 --- a/build.gradle +++ b/build.gradle @@ -31,4 +31,4 @@ publishPlugin { } group 'net.olegg' -version '0.0.3-SNAPSHOT' +version '0.0.3' From e21f646bfea4295639d229fd54aa6e5e8b7b1496 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 01:19:07 -0800 Subject: [PATCH 11/12] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be57c86..d038c2d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bodylookin -bodylookin is a IntelliJ IDEA-based IDE viewer plugin for [bodymovin](https://github.com/bodymovin/bodymovin) library. +bodylookin is a IntelliJ IDEA-based IDE viewer plugin for [bodymovin](https://github.com/bodymovin/bodymovin) and [Lottie](https://github.com/airbnb/lottie-android) libraries. ## Installation From bb83594967cb5c0d61936469e548e5c3c6ba2514 Mon Sep 17 00:00:00 2001 From: Oleg Godovykh Date: Tue, 21 Feb 2017 01:21:57 -0800 Subject: [PATCH 12/12] update changelog --- CHANGELOG.md | 6 ++++++ src/main/resources/META-INF/plugin.xml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c87e8b..9d017a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.0.3 + +- Added file loading from context menu +- Added file loading from filesystem +- Limit supported files to JSON + ## 0.0.2 - Fixed plugin crash when JavaFX is not present diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 6fdb2c5..1ac8390 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -9,6 +9,12 @@ 0.0.3 +
    +
  • Added file loading from context menu
  • +
  • Added file loading from filesystem
  • +
  • Limit supported files to JSON
  • +
0.0.2
  • Fixed plugin crash when JavaFX is not present