Skip to content

Commit

Permalink
Merge branch 'release/0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
0legg committed Feb 21, 2017
2 parents ca9f775 + bb83594 commit 5df3eb7
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ publishPlugin {
}

group 'net.olegg'
version '0.0.2'
version '0.0.3'
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion src/main/kotlin/net/olegg/bodylookin/BodylookinPlugin.kt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,4 +23,7 @@ class BodylookinPlugin : ApplicationComponent {
override fun initComponent() { }

override fun disposeComponent() { }
}
}

val VirtualFile?.isJson: Boolean
get() = (this?.fileType == JsonFileType.INSTANCE)
9 changes: 9 additions & 0 deletions src/main/kotlin/net/olegg/bodylookin/Constants.kt
Original file line number Diff line number Diff line change
@@ -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"
}
57 changes: 57 additions & 0 deletions src/main/kotlin/net/olegg/bodylookin/action/LoadAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.olegg.bodylookin.action

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
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() {
override fun actionPerformed(event: AnActionEvent) {
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)
if (toolWindow.isVisible) {
val content = toolWindow.contentManager.getContent(0)?.component as? BodylookinView ?: return
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 (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
}
}
37 changes: 35 additions & 2 deletions src/main/kotlin/net/olegg/bodylookin/toolwindow/BodylookinView.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
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
Expand All @@ -11,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

/**
Expand All @@ -29,7 +36,25 @@ 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.isJson
}
}
}

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)
}
}
}
Expand Down Expand Up @@ -84,6 +109,7 @@ class BodylookinView : SimpleToolWindowPanel(true) {
val group = DefaultActionGroup()
group.addAll(listOf(
lookAction,
openAction,
Separator(),
playAction,
pauseAction,
Expand All @@ -105,7 +131,7 @@ class BodylookinView : SimpleToolWindowPanel(true) {
}
}

fun loadAnimation(source: String) {
fun loadJson(source: String) {
Platform.runLater {
val script = """
bodymovin.destroy();
Expand All @@ -128,4 +154,11 @@ class BodylookinView : SimpleToolWindowPanel(true) {
}
}
}

fun loadFile(file: VirtualFile) {
ApplicationManager.getApplication().runReadAction {
val json = LoadTextUtil.loadText(file).toString()
loadJson(json)
}
}
}
22 changes: 21 additions & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
</description>

<change-notes><![CDATA[
<b>0.0.3</b>
<ul>
<li>Added file loading from context menu</li>
<li>Added file loading from filesystem</li>
<li>Limit supported files to JSON</li>
</ul>
<b>0.0.2</b>
<ul>
<li>Fixed plugin crash when JavaFX is not present</li>
Expand Down Expand Up @@ -40,4 +46,18 @@
factoryClass="net.olegg.bodylookin.toolwindow.BodylookinFactory"
/>
</extensions>
</idea-plugin>

<actions>
<action
class="net.olegg.bodylookin.action.LoadAction"
id="bodylookin.LoadAction"
text="bodylookin"
icon="/icons/wiggle.png"
>

<add-to-group group-id="EditorPopupMenu"/>
<add-to-group group-id="ProjectViewPopupMenu"/>
<add-to-group group-id="EditorTabPopupMenu"/>
</action>
</actions>
</idea-plugin>
12 changes: 0 additions & 12 deletions src/main/resources/bodylookin.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,5 @@
</head>
<body>
<div style="width:100%;height:100%;" id="bodymovin"></div>

<!--<script>
var animData = {
wrapper: document.getElementById('bodymovin'),
animType: 'html',
loop: true,
prerender: true,
autoplay: true,
path: './data.json'
};
var anim = bodymovin.loadAnimation(animData);
</script>-->
</body>
</html>

0 comments on commit 5df3eb7

Please sign in to comment.