Skip to content

Commit

Permalink
Merge branch 'release/0.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
0legg committed Nov 22, 2017
2 parents 5df3eb7 + 259b9ea commit ee30eea
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 108 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.4

- bodylookin is now lottie-idea!
- Updated lottie-web to 5.0.2

## 0.0.3

- Added file loading from context menu
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bodylookin
# lottie-idea

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.
lottie-idea is a IntelliJ IDEA-based IDE viewer plugin for [Lottie Web](https://github.com/airbnb/lottie-web) and [Lottie Android](https://github.com/airbnb/lottie-android) libraries.

## Installation

Expand All @@ -10,8 +10,7 @@ Grab fresh copy from [releases page](https://github.com/0legg/bodylookin/release

- Oracle JDK 8 (plugin depends on JavaFX browser component).
- If you're getting message that your IDE runs unsupported JDK, follow instructions for
[IntellijJ IDEA](https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under) or [Android Studio](http://tools.android.com/tech-docs/configuration)
[IntelliJ IDEA](https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under) or [Android Studio](http://tools.android.com/tech-docs/configuration)
to set up proper JDK for your IDE.

This project uses source code of bodymovin library licensed under [MIT license](https://github.com/bodymovin/bodymovin/blob/master/LICENSE.md)

This project uses source code of lottie-web library licensed under [MIT license](https://github.com/bodymovin/bodymovin/blob/master/LICENSE.md)
34 changes: 0 additions & 34 deletions build.gradle

This file was deleted.

64 changes: 64 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import nu.studer.gradle.credentials.CredentialsPlugin
import nu.studer.gradle.credentials.domain.CredentialsContainer
import org.jetbrains.intellij.tasks.PublishTask
import org.jetbrains.kotlin.gradle.dsl.Coroutines
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
repositories {
jcenter()
}
}

plugins {
kotlin("jvm") version("1.1.60")
id("org.jetbrains.intellij") version("0.2.17")
id("nu.studer.credentials") version("1.0.3")
id("org.jmailen.kotlinter") version("1.5.0")
}

repositories {
jcenter()
}

dependencies {
compileOnly(kotlin("stdlib-jre8"))
compileOnly(kotlin("reflect"))
}

val publishPlugin: PublishTask by tasks
val credentials: CredentialsContainer by extra
val javaVersion = "1.8"

intellij {
version = "2016.1"
updateSinceUntilBuild = false
}

java {
setSourceCompatibility(javaVersion)
setTargetCompatibility(javaVersion)
}

kotlin {
experimental.coroutines = Coroutines.ENABLE
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = javaVersion
}

publishPlugin {
username(credentials["JETBRAINS_USERNAME"])
password(credentials["JETBRAINS_PASSWORD"])
}

apply {
from("gradle/hooks.gradle.kts")
}

group = "net.olegg"
version = "0.0.4"

inline operator fun <T : Task> T.invoke(a: T.() -> Unit): T = apply(a)
operator fun CredentialsContainer.get(key: String) = this.getProperty(key)
10 changes: 10 additions & 0 deletions gradle/hooks.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
val installHook = task<Copy>("installHook") {
from(File(rootProject.rootDir, "pre-commit"))
into(File(rootProject.rootDir, ".git/hooks").also { it.setExecutable(true) })
}

tasks {
"build" {
dependsOn(installHook)
}
}
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#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.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
28 changes: 28 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# script to run tests on what is to be committed

# First, stash index and work dir, keeping only the
# to-be-committed changes in the working directory.
old_stash=$(git rev-parse -q --verify refs/stash)
git stash save -q --keep-index
new_stash=$(git rev-parse -q --verify refs/stash)

# If there were no changes (e.g., `--amend` or `--allow-empty`)
# then nothing was stashed, and we should skip everything,
# including the tests themselves. (Presumably the tests passed
# on the previous commit, so there is no need to re-run them.)
if [ "$old_stash" = "$new_stash" ]; then
echo "pre-commit script: no changes to test"
sleep 1 # XXX hack, editor may erase message
exit 0
fi

# Run tests
./gradlew formatKotlin lintKotlin --daemon
status=$?

# Restore changes
git reset --hard -q && git stash apply --index -q && git stash drop -q

# Exit with status from test-run: nonzero prevents commit
exit $status
1 change: 0 additions & 1 deletion settings.gradle

This file was deleted.

3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gradle.rootProject {
setProperty("name", "lottie-idea")
}
9 changes: 0 additions & 9 deletions src/main/kotlin/net/olegg/bodylookin/Constants.kt

This file was deleted.

9 changes: 9 additions & 0 deletions src/main/kotlin/net/olegg/lottie/idea/Constants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.olegg.lottie.idea

/**
* Helper class to store constants.
*/
object Constants {
val ACTION_GROUP = "lottie-idea.ActionGroup"
val TOOL_WINDOW_ID = "lottie-idea"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package net.olegg.bodylookin
package net.olegg.lottie.idea

import com.intellij.openapi.util.IconLoader

/**
* Created by olegg on 2/19/17.
* Helper class to store icons.
*/
object Icons {
fun load(path: String) = IconLoader.getIcon(path)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package net.olegg.bodylookin
package net.olegg.lottie.idea

import com.intellij.json.JsonFileType
import com.intellij.openapi.components.ApplicationComponent
import com.intellij.openapi.vfs.VirtualFile

/**
* Created by olegg on 2/15/17.
* Root plugin class.
*/
class BodylookinPlugin : ApplicationComponent {
class LottieIdeaPlugin : ApplicationComponent {

override fun getComponentName() = javaClass.name

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package net.olegg.bodylookin.action
package net.olegg.lottie.idea.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
import net.olegg.lottie.idea.Constants
import net.olegg.lottie.idea.isJson
import net.olegg.lottie.idea.toolwindow.LottieIdeaView

/**
* Created by olegg on 2/21/17.
* Animation loading logic.
*/
class LoadAction : AnAction() {
override fun actionPerformed(event: AnActionEvent) {
Expand All @@ -24,15 +24,15 @@ class LoadAction : AnAction() {
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
val content = toolWindow.contentManager.getContent(0)?.component as? LottieIdeaView ?: 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
val content = toolWindow.contentManager.getContent(0)?.component as? LottieIdeaView ?: return@show
if (doc != null) {
content.loadJson(doc.text)
} else if (file != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.olegg.bodylookin.toolwindow
package net.olegg.lottie.idea.toolwindow

import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.project.Project
Expand All @@ -7,17 +7,17 @@ import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.ui.components.JBLabel
import com.intellij.ui.content.ContentFactory
import com.intellij.util.ui.UIUtil
import net.olegg.bodylookin.BodylookinPlugin
import net.olegg.lottie.idea.LottieIdeaPlugin
import javax.swing.JComponent

/**
* Created by olegg on 2/12/17.
* Tool window provider. Shows notification if user doesn't have JavaFX.
*/
class BodylookinFactory: ToolWindowFactory {
class LottieIdeaFactory : ToolWindowFactory {

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val view : JComponent = if (ApplicationManager.getApplication().getComponent(BodylookinPlugin::class.java).hasJavafx) {
BodylookinView()
val view: JComponent = if (ApplicationManager.getApplication().getComponent(LottieIdeaPlugin::class.java).hasJavafx) {
LottieIdeaView()
} else {
JBLabel("""<html>Unable to instantiate JavaFX.
<br/><br/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package net.olegg.bodylookin.toolwindow
package net.olegg.lottie.idea.toolwindow

import com.intellij.json.JsonFileType
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.openapi.actionSystem.Separator
import com.intellij.openapi.actionSystem.ToggleAction
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.fileChooser.FileChooserFactory
Expand All @@ -16,15 +22,15 @@ import javafx.embed.swing.JFXPanel
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 net.olegg.lottie.idea.Icons
import net.olegg.lottie.idea.isJson
import netscape.javascript.JSObject

/**
* Created by olegg on 2/12/17.
* UI logic and JS player controller.
*/
class BodylookinView : SimpleToolWindowPanel(true) {
val root: String = javaClass.classLoader.getResource("/bodylookin.html").toExternalForm()
class LottieIdeaView : SimpleToolWindowPanel(true) {
val root: String = javaClass.classLoader.getResource("/lottie-idea.html").toExternalForm()

val panel = JFXPanel()
lateinit var webview: WebView
Expand Down Expand Up @@ -136,15 +142,15 @@ class BodylookinView : SimpleToolWindowPanel(true) {
val script = """
bodymovin.destroy();
bodymovin.loadAnimation({
wrapper: document.getElementById('bodymovin'),
wrapper: document.getElementById('lottie'),
animType: 'svg',
loop: true,
prerender: true,
autoplay: true,
animationData: JSON.parse('$source')
});"""
if (engine.loadWorker.state != Worker.State.SUCCEEDED) {
engine.loadWorker.stateProperty().addListener { value, oldState, newState ->
engine.loadWorker.stateProperty().addListener { _, _, newState ->
if (newState == Worker.State.SUCCEEDED) {
js = engine.executeScript(script) as? JSObject
}
Expand Down
Loading

0 comments on commit ee30eea

Please sign in to comment.